|
|
@@ -2,6 +2,7 @@ package cn.reghao.autodop.dagent.mqttsub.impl;
|
|
|
|
|
|
import cn.reghao.autodop.common.machine.Machine;
|
|
|
import cn.reghao.autodop.common.msg.rpc.clazz.IAppRpcClazz;
|
|
|
+import cn.reghao.autodop.common.msg.rpc.constant.AppRpcClazz;
|
|
|
import cn.reghao.autodop.common.msg.rpc.dto.app.*;
|
|
|
import cn.reghao.autodop.common.util.ExceptionUtil;
|
|
|
import cn.reghao.autodop.dagent.app.AppService;
|
|
|
@@ -47,147 +48,77 @@ public class AppRpcClazzImpl implements IAppRpcClazz {
|
|
|
deployResult.setAppStatus(appStatus);
|
|
|
break;
|
|
|
default:
|
|
|
- String msg = "打包类型 " + deployParam.getPackType() + " 不存在";
|
|
|
+ String msg = String.format("应用包类型 %s 不存在", deployParam.getPackType());
|
|
|
deployResult.setResult(Result.result(ResultStatus.ERROR, msg));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
deployResult.setResult(Result.result(ResultStatus.FAIL, ExceptionUtil.errorMsg(e)));
|
|
|
}
|
|
|
-
|
|
|
- //return RpcResultMsg.success(JsonConverter.objectToJson(deployResult));
|
|
|
return deployResult;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StatusResult status(StatusParam statusParam) {
|
|
|
+ public StatusResult restart(StatusParam statusParam) throws Exception {
|
|
|
String appId = statusParam.getAppId();
|
|
|
- String packerType = statusParam.getPackerType();
|
|
|
-
|
|
|
- StatusResult statusResult;
|
|
|
- try {
|
|
|
- switch (PackType.valueOf(packerType)) {
|
|
|
- case docker:
|
|
|
- statusResult = dockerAppServiceImpl.status(appId);
|
|
|
- break;
|
|
|
- case zip:
|
|
|
- statusResult = zipAppServiceImpl.status(appId);
|
|
|
- break;
|
|
|
- default:
|
|
|
- return null;
|
|
|
- //return RpcResultMsg.error("打包类型 " + statusParam.getPackerType() + " 不存在");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- return null;
|
|
|
- //return RpcResultMsg.fail(ExceptionUtil.errorMsg(e));
|
|
|
- }
|
|
|
-
|
|
|
- //return RpcResultMsg.success(JsonConverter.objectToJson(appStatus));
|
|
|
- return statusResult;
|
|
|
+ String packType = statusParam.getPackType();
|
|
|
+ return appOps(appId, AppRpcClazz.restart.name(), packType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StatusResult restart(StatusParam statusParam) {
|
|
|
+ public StatusResult stop(StatusParam statusParam) throws Exception {
|
|
|
String appId = statusParam.getAppId();
|
|
|
- String packerType = statusParam.getPackerType();
|
|
|
-
|
|
|
- /*StatusResult appStatus;
|
|
|
- try {
|
|
|
- switch (PackType.valueOf(packerType)) {
|
|
|
- case docker:
|
|
|
- appStatus = dockerAppServiceImpl.restart(appId);
|
|
|
- break;
|
|
|
- case zip:
|
|
|
- appStatus = zipAppServiceImpl.restart(appId);
|
|
|
- break;
|
|
|
- default:
|
|
|
- return RpcResultMsg.error("打包类型 " + statusParam.getPackerType() + " 不存在");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- return RpcResultMsg.fail(ExceptionUtil.errorMsg(e));
|
|
|
- }
|
|
|
-
|
|
|
- return RpcResultMsg.success(JsonConverter.objectToJson(appStatus));*/
|
|
|
- return null;
|
|
|
+ String packType = statusParam.getPackType();
|
|
|
+ return appOps(appId, AppRpcClazz.stop.name(), packType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StatusResult stop(StatusParam statusParam) {
|
|
|
+ public StatusResult start(StatusParam statusParam) throws Exception {
|
|
|
String appId = statusParam.getAppId();
|
|
|
- String packerType = statusParam.getPackerType();
|
|
|
-
|
|
|
- /*StatusResult appStatus;
|
|
|
- try {
|
|
|
- switch (PackType.valueOf(packerType)) {
|
|
|
- case docker:
|
|
|
- appStatus = dockerAppServiceImpl.stop(appId);
|
|
|
- break;
|
|
|
- case zip:
|
|
|
- appStatus = zipAppServiceImpl.stop(appId);
|
|
|
- break;
|
|
|
- default:
|
|
|
- return RpcResultMsg.error("打包类型 " + statusParam.getPackerType() + " 不存在");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- return RpcResultMsg.fail(ExceptionUtil.errorMsg(e));
|
|
|
- }
|
|
|
-
|
|
|
- return RpcResultMsg.success(JsonConverter.objectToJson(appStatus));*/
|
|
|
- return null;
|
|
|
+ String packType = statusParam.getPackType();
|
|
|
+ return appOps(appId, AppRpcClazz.start.name(), packType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StatusResult start(StatusParam statusParam) {
|
|
|
+ public StatusResult status(StatusParam statusParam) throws Exception {
|
|
|
String appId = statusParam.getAppId();
|
|
|
- String packerType = statusParam.getPackerType();
|
|
|
+ String packType = statusParam.getPackType();
|
|
|
+ return appOps(appId, AppRpcClazz.status.name(), packType);
|
|
|
+ }
|
|
|
|
|
|
- /*StatusResult appStatus;
|
|
|
- try {
|
|
|
- switch (PackType.valueOf(packerType)) {
|
|
|
- case docker:
|
|
|
- appStatus = dockerAppServiceImpl.start(appId);
|
|
|
- break;
|
|
|
- case zip:
|
|
|
- appStatus = zipAppServiceImpl.start(appId);
|
|
|
- break;
|
|
|
- default:
|
|
|
- return RpcResultMsg.error("打包类型 " + statusParam.getPackerType() + " 不存在");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- return RpcResultMsg.fail(ExceptionUtil.errorMsg(e));
|
|
|
+ private StatusResult appOps(String appId, String ops, String packType) throws Exception {
|
|
|
+ switch (AppRpcClazz.valueOf(ops)) {
|
|
|
+ case restart:
|
|
|
+ if (packType.equals(PackType.docker.name())) {
|
|
|
+ return dockerAppServiceImpl.restart(appId);
|
|
|
+ } else {
|
|
|
+ return zipAppServiceImpl.restart(appId);
|
|
|
+ }
|
|
|
+ case stop:
|
|
|
+ if (packType.equals(PackType.docker.name())) {
|
|
|
+ return dockerAppServiceImpl.stop(appId);
|
|
|
+ } else {
|
|
|
+ return zipAppServiceImpl.stop(appId);
|
|
|
+ }
|
|
|
+ case start:
|
|
|
+ if (packType.equals(PackType.docker.name())) {
|
|
|
+ return dockerAppServiceImpl.start(appId);
|
|
|
+ } else {
|
|
|
+ return zipAppServiceImpl.start(appId);
|
|
|
+ }
|
|
|
+ case status:
|
|
|
+ if (packType.equals(PackType.docker.name())) {
|
|
|
+ return dockerAppServiceImpl.status(appId);
|
|
|
+ } else {
|
|
|
+ return zipAppServiceImpl.status(appId);
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ String msg = String.format("应用状态操作类型 %s 不存在", ops);
|
|
|
+ throw new Exception(msg);
|
|
|
}
|
|
|
-
|
|
|
- return RpcResultMsg.success(JsonConverter.objectToJson(appStatus));*/
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void log() {
|
|
|
- /*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 RpcResultMsg.success(JsonConverter.objectToJson(logFiles));
|
|
|
- } else {
|
|
|
- List<String> logContent = dockerAppServiceImpl.logContent(appLogArgs);
|
|
|
- return RpcResultMsg.success(JsonConverter.objectToJson(logContent));
|
|
|
- }
|
|
|
- case zip:
|
|
|
- if (count > 0) {
|
|
|
- List<LogFile> logFiles = zipAppServiceImpl.logFiles(appLogArgs);
|
|
|
- return RpcResultMsg.success(JsonConverter.objectToJson(logFiles));
|
|
|
- } else {
|
|
|
- List<String> logContent = zipAppServiceImpl.logContent(appLogArgs);
|
|
|
- return RpcResultMsg.success(JsonConverter.objectToJson(logContent));
|
|
|
- }
|
|
|
- default:
|
|
|
- return RpcResultMsg.error("打包类型 " + appLogArgs.getPackerType() + " 不存在");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- return RpcResultMsg.fail(ExceptionUtil.errorMsg(e));
|
|
|
- }*/
|
|
|
+ // TODO 应用日志待实现
|
|
|
}
|
|
|
}
|