|
|
@@ -1,14 +1,20 @@
|
|
|
package cn.reghao.autodop.dmaster.app.service;
|
|
|
|
|
|
-import cn.reghao.autodop.common.dockerc.DockerException;
|
|
|
+import cn.reghao.autodop.common.deploy.AppStatus;
|
|
|
+import cn.reghao.autodop.common.deploy.DeployResult;
|
|
|
+import cn.reghao.autodop.common.dockerc.exception.DockerException;
|
|
|
import cn.reghao.autodop.common.grpc.client.GrpcClientProxy;
|
|
|
-import cn.reghao.autodop.common.grpc.facade.AppService;
|
|
|
+import cn.reghao.autodop.common.grpc.facade.app.AppLogService;
|
|
|
+import cn.reghao.autodop.common.grpc.facade.app.AppStatusService;
|
|
|
+import cn.reghao.autodop.common.utils.JsonUtil;
|
|
|
import cn.reghao.autodop.dmaster.app.caching.OrchestrationCaching;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.deploy.AppLog;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -26,18 +32,25 @@ public class AppManager {
|
|
|
this.caching = caching;
|
|
|
}
|
|
|
|
|
|
- public void run(String appId, String version) {
|
|
|
+ public void run(String appId, String commitId) throws DockerException {
|
|
|
+ AppOrchestration app = caching.findByAppId(appId);
|
|
|
+ String[] hosts = app.getAppDeploy().getHosts().split(",");
|
|
|
+ for (String host : hosts) {
|
|
|
+ AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
|
|
|
+ .getProxy(host, GRPC_PORT, AppStatusService.class);
|
|
|
|
|
|
+ appStatusService.run(appId, commitId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void start(String appId) throws DockerException {
|
|
|
AppOrchestration app = caching.findByAppId(appId);
|
|
|
String[] hosts = app.getAppDeploy().getHosts().split(",");
|
|
|
for (String host : hosts) {
|
|
|
- AppService appService = (AppService) new GrpcClientProxy<AppService>()
|
|
|
- .getProxy(host, GRPC_PORT, AppService.class);
|
|
|
+ AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
|
|
|
+ .getProxy(host, GRPC_PORT, AppStatusService.class);
|
|
|
|
|
|
- appService.start(appId);
|
|
|
+ appStatusService.start(appId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -45,10 +58,10 @@ public class AppManager {
|
|
|
AppOrchestration app = caching.findByAppId(appId);
|
|
|
String[] hosts = app.getAppDeploy().getHosts().split(",");
|
|
|
for (String host : hosts) {
|
|
|
- AppService appService = (AppService) new GrpcClientProxy<AppService>()
|
|
|
- .getProxy(host, GRPC_PORT, AppService.class);
|
|
|
+ AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
|
|
|
+ .getProxy(host, GRPC_PORT, AppStatusService.class);
|
|
|
|
|
|
- appService.stop(appId);
|
|
|
+ appStatusService.stop(appId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -56,13 +69,39 @@ public class AppManager {
|
|
|
AppOrchestration app = caching.findByAppId(appId);
|
|
|
String[] hosts = app.getAppDeploy().getHosts().split(",");
|
|
|
for (String host : hosts) {
|
|
|
- AppService appService = (AppService) new GrpcClientProxy<AppService>()
|
|
|
- .getProxy(host, GRPC_PORT, AppService.class);
|
|
|
+ AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
|
|
|
+ .getProxy(host, GRPC_PORT, AppStatusService.class);
|
|
|
|
|
|
- appService.restart(appId);
|
|
|
+ appStatusService.restart(appId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public List<AppStatus> status() throws DockerException {
|
|
|
+ List<AppStatus> appStatusList = new ArrayList<>();
|
|
|
+ // TODO 查找所有已部署的应用
|
|
|
+ /*caching.findByAppId("appId");
|
|
|
+ List<AppOrchestration> apps = new ArrayList<>();
|
|
|
+ AppOrchestration app = apps.get(0);
|
|
|
+
|
|
|
+ String[] hosts = app.getAppDeploy().getHosts().split(",");
|
|
|
+ for (String host : hosts) {
|
|
|
+ AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
|
|
|
+ .getProxy(host, GRPC_PORT, AppStatusService.class);
|
|
|
+
|
|
|
+ AppStatus status = appStatusService.status(app.getAppId());
|
|
|
+ appStatusList.add(status);
|
|
|
+ }*/
|
|
|
+ AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
|
|
|
+ .getProxy("localhost", GRPC_PORT, AppStatusService.class);
|
|
|
+
|
|
|
+ Object object = appStatusService.status("timuke");
|
|
|
+ JSONObject jsonObject = (JSONObject) object;
|
|
|
+ AppStatus status = jsonObject.toJavaObject(AppStatus.class);
|
|
|
+ appStatusList.add(status);
|
|
|
+
|
|
|
+ return appStatusList;
|
|
|
+ }
|
|
|
+
|
|
|
public List<String> log(String appId, String logType, String logLevel) throws Exception {
|
|
|
AppOrchestration app = caching.findByAppId(appId);
|
|
|
AppDeploy appDeploy = app.getAppDeploy();
|
|
|
@@ -78,12 +117,12 @@ public class AppManager {
|
|
|
|
|
|
String[] hosts = app.getAppDeploy().getHosts().split(",");
|
|
|
for (String host : hosts) {
|
|
|
- AppService appService = (AppService) new GrpcClientProxy<AppService>()
|
|
|
- .getProxy(host, GRPC_PORT, AppService.class);
|
|
|
+ AppLogService logService = (AppLogService) new GrpcClientProxy<AppLogService>()
|
|
|
+ .getProxy(host, GRPC_PORT, AppLogService.class);
|
|
|
|
|
|
// TODO logs 为 null 表示没有日志
|
|
|
- List<String> logs = appService.log(appId, logType, logLevel, logdirPath);
|
|
|
- return logs;
|
|
|
+ List<String> logFiles = logService.logFiles(appId, logType, logLevel, logdirPath);
|
|
|
+ return logFiles;
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
@@ -104,11 +143,12 @@ public class AppManager {
|
|
|
|
|
|
String[] hosts = app.getAppDeploy().getHosts().split(",");
|
|
|
for (String host : hosts) {
|
|
|
- AppService appService = (AppService) new GrpcClientProxy<AppService>()
|
|
|
- .getProxy(host, GRPC_PORT, AppService.class);
|
|
|
+ AppLogService logService = (AppLogService) new GrpcClientProxy<AppLogService>()
|
|
|
+ .getProxy(host, GRPC_PORT, AppLogService.class);
|
|
|
|
|
|
- List<String> logs = appService.logcontent(appId, logType, logLevel, logfilePath);
|
|
|
- return logs;
|
|
|
+ // TODO logs 为 null 表示没有日志
|
|
|
+ List<String> logContent = logService.logContent(appId, logType, logLevel, logfilePath);
|
|
|
+ return logContent;
|
|
|
}
|
|
|
|
|
|
return null;
|