|
|
@@ -1,13 +1,12 @@
|
|
|
package cn.reghao.autodop.dagent.rpc.impl;
|
|
|
|
|
|
-import cn.reghao.autodop.common.dagent.app.AppStatus;
|
|
|
-import cn.reghao.autodop.common.dagent.app.DeployResult;
|
|
|
-import cn.reghao.autodop.common.dagent.app.DeployParam;
|
|
|
-import cn.reghao.autodop.common.dagent.app.PackType;
|
|
|
-import cn.reghao.autodop.common.docker.exception.DockerException;
|
|
|
-import cn.reghao.autodop.common.node.rpc.JsonRpc;
|
|
|
-import cn.reghao.autodop.common.node.rpc.RpcResult;
|
|
|
-import cn.reghao.autodop.common.node.rpc.clazz.AppClazz;
|
|
|
+import cn.reghao.autodop.common.dagent.app.log.AppLogArgs;
|
|
|
+import cn.reghao.autodop.common.dagent.app.log.LogConfig;
|
|
|
+import cn.reghao.autodop.common.dagent.app.log.LogFile;
|
|
|
+import cn.reghao.autodop.common.msg.rpc.dto.app.*;
|
|
|
+import cn.reghao.autodop.common.msg.rpc.RpcPayload;
|
|
|
+import cn.reghao.autodop.common.msg.rpc.RpcResult;
|
|
|
+import cn.reghao.autodop.common.msg.rpc.clazz.AppClazz;
|
|
|
import cn.reghao.autodop.common.util.ExceptionUtil;
|
|
|
import cn.reghao.autodop.dagent.app.AppService;
|
|
|
import cn.reghao.autodop.dagent.app.DockerAppServiceImpl;
|
|
|
@@ -18,6 +17,8 @@ import cn.reghao.jdkutil.result.ResultStatus;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2020-12-30 10:26:47
|
|
|
@@ -33,58 +34,194 @@ public class AppClazzImpl {
|
|
|
this.zipAppServiceImpl = new ZipAppServiceImpl();
|
|
|
}
|
|
|
|
|
|
- public RpcResult<?> process(JsonRpc jsonRpc) throws DockerException {
|
|
|
- String method = jsonRpc.getMethod();
|
|
|
- Object param = jsonRpc.getParam();
|
|
|
+ public RpcResult<?> process(RpcPayload rpcPayload) {
|
|
|
+ String method = rpcPayload.getMethod();
|
|
|
+ Object param = rpcPayload.getParam();
|
|
|
switch (AppClazz.valueOf(method)) {
|
|
|
case deploy:
|
|
|
if (!(param instanceof DeployParam)) {
|
|
|
- return RpcResult.error("不是 AppDeployArgs 对象");
|
|
|
+ return RpcResult.error("不是 DeployParam 对象");
|
|
|
}
|
|
|
return deploy(param);
|
|
|
case status:
|
|
|
- break;
|
|
|
+ if (!(param instanceof AppIdParam)) {
|
|
|
+ return RpcResult.error("不是 AppIdParam 对象");
|
|
|
+ }
|
|
|
+ return status(param);
|
|
|
case start:
|
|
|
- break;
|
|
|
+ if (!(param instanceof AppIdParam)) {
|
|
|
+ return RpcResult.error("不是 AppIdParam 对象");
|
|
|
+ }
|
|
|
+ return start(param);
|
|
|
case stop:
|
|
|
- break;
|
|
|
+ if (!(param instanceof AppIdParam)) {
|
|
|
+ return RpcResult.error("不是 AppIdParam 对象");
|
|
|
+ }
|
|
|
+ return stop(param);
|
|
|
case restart:
|
|
|
- break;
|
|
|
+ if (!(param instanceof AppIdParam)) {
|
|
|
+ return RpcResult.error("不是 AppIdParam 对象");
|
|
|
+ }
|
|
|
+ return restart(param);
|
|
|
default:
|
|
|
- ;
|
|
|
+ String err = String.format("找不到 %s 方法", method);
|
|
|
+ return RpcResult.error(err);
|
|
|
}
|
|
|
-
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
- private RpcResult<?> deploy(Object param) throws DockerException {
|
|
|
- DeployParam deployArgs = (DeployParam) param;
|
|
|
- String buildLogId = deployArgs.getBuildLogId();
|
|
|
- String packType = deployArgs.getPackType();
|
|
|
+ private RpcResult<?> deploy(Object param) {
|
|
|
+ DeployParam deployParam = (DeployParam) param;
|
|
|
+ String buildLogId = deployParam.getBuildLogId();
|
|
|
+ String packType = deployParam.getPackType();
|
|
|
|
|
|
AppStatus appStatus;
|
|
|
- DeployResult deployResult = new DeployResult(buildLogId,
|
|
|
- DagentLifecycle.MACHINE_ID, DagentLifecycle.MACHINE_IPV4);
|
|
|
- switch (PackType.valueOf(packType)) {
|
|
|
- case docker:
|
|
|
- try {
|
|
|
- appStatus = dockerAppServiceImpl.deploy(deployArgs);
|
|
|
+ DeployResult deployResult = new DeployResult(buildLogId, DagentLifecycle.MACHINE_ID, DagentLifecycle.MACHINE_IPV4);
|
|
|
+ try {
|
|
|
+ switch (PackType.valueOf(packType)) {
|
|
|
+ case docker:
|
|
|
+ appStatus = dockerAppServiceImpl.deploy(deployParam);
|
|
|
deployResult.setResult(Result.result(ResultStatus.SUCCESS));
|
|
|
deployResult.setAppStatus(appStatus);
|
|
|
- } catch (DockerException e) {
|
|
|
- deployResult.setResult(Result.result(ResultStatus.FAIL, ExceptionUtil.errorMsg(e)));
|
|
|
- }
|
|
|
- break;
|
|
|
- case zip:
|
|
|
- appStatus = zipAppServiceImpl.deploy(deployArgs);
|
|
|
- deployResult.setResult(Result.result(ResultStatus.SUCCESS));
|
|
|
- deployResult.setAppStatus(appStatus);
|
|
|
- break;
|
|
|
- default:
|
|
|
- String msg = "打包类型 " + deployArgs.getPackType() + " 不存在";
|
|
|
- deployResult.setResult(Result.result(ResultStatus.ERROR, msg));
|
|
|
+ break;
|
|
|
+ case zip:
|
|
|
+ appStatus = zipAppServiceImpl.deploy(deployParam);
|
|
|
+ deployResult.setResult(Result.result(ResultStatus.SUCCESS));
|
|
|
+ deployResult.setAppStatus(appStatus);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ String msg = "打包类型 " + deployParam.getPackType() + " 不存在";
|
|
|
+ deployResult.setResult(Result.result(ResultStatus.ERROR, msg));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ deployResult.setResult(Result.result(ResultStatus.FAIL, ExceptionUtil.errorMsg(e)));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return RpcResult.success(deployResult);
|
|
|
}
|
|
|
+
|
|
|
+ public RpcResult<?> status(Object param) {
|
|
|
+ AppIdParam appIdParam = (AppIdParam) param;
|
|
|
+ String appId = appIdParam.getAppId();
|
|
|
+ String packerType = appIdParam.getPackerType();
|
|
|
+
|
|
|
+ AppStatus appStatus;
|
|
|
+ try {
|
|
|
+ switch (PackType.valueOf(packerType)) {
|
|
|
+ case docker:
|
|
|
+ appStatus = dockerAppServiceImpl.status(appId);
|
|
|
+ break;
|
|
|
+ case zip:
|
|
|
+ appStatus = zipAppServiceImpl.status(appId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return RpcResult.error("打包类型 " + appIdParam.getPackerType() + " 不存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return RpcResult.fail(ExceptionUtil.errorMsg(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ return RpcResult.success(appStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RpcResult<AppStatus> restart(Object param) {
|
|
|
+ AppIdParam appIdParam = (AppIdParam) param;
|
|
|
+ String appId = appIdParam.getAppId();
|
|
|
+ String packerType = appIdParam.getPackerType();
|
|
|
+
|
|
|
+ AppStatus appStatus;
|
|
|
+ try {
|
|
|
+ switch (PackType.valueOf(packerType)) {
|
|
|
+ case docker:
|
|
|
+ appStatus = dockerAppServiceImpl.restart(appId);
|
|
|
+ break;
|
|
|
+ case zip:
|
|
|
+ appStatus = zipAppServiceImpl.restart(appId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return RpcResult.error("打包类型 " + appIdParam.getPackerType() + " 不存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return RpcResult.fail(ExceptionUtil.errorMsg(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ return RpcResult.success(appStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RpcResult<AppStatus> stop(Object param) {
|
|
|
+ AppIdParam appIdParam = (AppIdParam) param;
|
|
|
+ String appId = appIdParam.getAppId();
|
|
|
+ String packerType = appIdParam.getPackerType();
|
|
|
+
|
|
|
+ AppStatus appStatus;
|
|
|
+ try {
|
|
|
+ switch (PackType.valueOf(packerType)) {
|
|
|
+ case docker:
|
|
|
+ appStatus = dockerAppServiceImpl.stop(appId);
|
|
|
+ break;
|
|
|
+ case zip:
|
|
|
+ appStatus = zipAppServiceImpl.stop(appId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return RpcResult.error("打包类型 " + appIdParam.getPackerType() + " 不存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return RpcResult.fail(ExceptionUtil.errorMsg(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ return RpcResult.success(appStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RpcResult<AppStatus> start(Object param) {
|
|
|
+ AppIdParam appIdParam = (AppIdParam) param;
|
|
|
+ String appId = appIdParam.getAppId();
|
|
|
+ String packerType = appIdParam.getPackerType();
|
|
|
+
|
|
|
+ AppStatus appStatus;
|
|
|
+ try {
|
|
|
+ switch (PackType.valueOf(packerType)) {
|
|
|
+ case docker:
|
|
|
+ appStatus = dockerAppServiceImpl.start(appId);
|
|
|
+ break;
|
|
|
+ case zip:
|
|
|
+ appStatus = zipAppServiceImpl.start(appId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return RpcResult.error("打包类型 " + appIdParam.getPackerType() + " 不存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return RpcResult.fail(ExceptionUtil.errorMsg(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ return RpcResult.success(appStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RpcResult<?> log(Object param) {
|
|
|
+ AppLogArgs appLogArgs = (AppLogArgs) param;
|
|
|
+ String packerType = appLogArgs.getPackerType();
|
|
|
+ long count = appLogArgs.getLogConfigs().stream().filter(LogConfig::getIsDir).count();
|
|
|
+ try {
|
|
|
+ switch (PackType.valueOf(packerType)) {
|
|
|
+ case docker:
|
|
|
+ if (count > 0) {
|
|
|
+ List<LogFile> logFiles = dockerAppServiceImpl.logFiles(appLogArgs);
|
|
|
+ return RpcResult.success(logFiles);
|
|
|
+ } else {
|
|
|
+ List<String> logContent = dockerAppServiceImpl.logContent(appLogArgs);
|
|
|
+ return RpcResult.success(logContent);
|
|
|
+ }
|
|
|
+ case zip:
|
|
|
+ if (count > 0) {
|
|
|
+ List<LogFile> logFiles = zipAppServiceImpl.logFiles(appLogArgs);
|
|
|
+ return RpcResult.success(logFiles);
|
|
|
+ } else {
|
|
|
+ List<String> logContent = zipAppServiceImpl.logContent(appLogArgs);
|
|
|
+ return RpcResult.success(logContent);
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return RpcResult.error("打包类型 " + appLogArgs.getPackerType() + " 不存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return RpcResult.fail(ExceptionUtil.errorMsg(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|