diff --git a/server/src/main/java/io/wdd/func/auto/beans/BaseFunctionEnum.java b/server/src/main/java/io/wdd/func/auto/beans/BaseFunctionEnum.java new file mode 100644 index 0000000..bd08fed --- /dev/null +++ b/server/src/main/java/io/wdd/func/auto/beans/BaseFunctionEnum.java @@ -0,0 +1,81 @@ +package io.wdd.func.auto.beans; + +public enum BaseFunctionEnum { + + SHUTDOWN_FIREWALL( + "shutdownFirewall", + "关闭防火墙" + ), + + + DISABLE_SWAP( + "disableSwap", + "关闭虚拟内存" + ), + + + MODIFY_HOSTNAME( + "modifyHostname", + "修改主机名称, args 主机名" + ), + + INSTALL_DEFAULT_SSH_KEY( + "installDefaultSSHKey ", + "安装默认SSH-Key" + ), + + DISTRIBUTE_SSH_KEY( + "distributeSSHKey", + "分发SSH-Key" + ), + + INSTALL_DOCKER( + "installDocker", + "安装Docker, args固定为19或20" + ), + + INSTALL_DOCKER_COMPOSE( + "installDockerCompose", + "安装Docker Compose, 默认为2.18.0版本" + ), + + INSTALL_HARBOR( + "installHarbor", + "安装Harbor, 默认为2.1.0版本" + ), + + + CHRONY_TO_PUBLIC_NTP( + "chronyToPublicNTP", + "时间同步至公网NTP服务器" + ), + + INSTALL_ZSH( + "installZSH", + "安装配置ZSH" + ), + + CHRONY_TO_MASTER( + "chronyToMaster", + "时间同步至Master, args为 Master节点IP" + ); + + String funcName; + + String desc; + + + BaseFunctionEnum(String funcName, String desc) { + this.funcName = funcName; + this.desc = desc; + } + + public String getFuncName() { + return funcName; + } + + public String getDesc() { + return desc; + } + +} diff --git a/server/src/main/java/io/wdd/func/auto/beans/ProjectDeployContext.java b/server/src/main/java/io/wdd/func/auto/beans/ProjectDeployContext.java new file mode 100644 index 0000000..88bc801 --- /dev/null +++ b/server/src/main/java/io/wdd/func/auto/beans/ProjectDeployContext.java @@ -0,0 +1,25 @@ +package io.wdd.func.auto.beans; + +import io.swagger.annotations.ApiModel; +import io.wdd.server.beans.po.ServerInfoPO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder(toBuilder = true) +@ApiModel("项目实施阶段的上下文实体类") +public class ProjectDeployContext { + + Long projectId; + + ServerInfoPO masterNode; + + List agentNodeList; + +} diff --git a/server/src/main/java/io/wdd/func/auto/service/BaseFuncScheduler.java b/server/src/main/java/io/wdd/func/auto/service/BaseFuncScheduler.java new file mode 100644 index 0000000..4fd5034 --- /dev/null +++ b/server/src/main/java/io/wdd/func/auto/service/BaseFuncScheduler.java @@ -0,0 +1,125 @@ +package io.wdd.func.auto.service; + +import io.wdd.func.auto.beans.BaseFunctionEnum; +import io.wdd.func.auto.beans.ProjectDeployContext; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class BaseFuncScheduler { + + @Resource + FuncService funcService; + + public boolean runProcedure(ProjectDeployContext projectDeployContext) { + + // before run + // check base requirement + beforeRunProcedure(projectDeployContext); + + + // during run + doRunProcedure(projectDeployContext); + + + // after run + afterRunProcedure(); + + + return true; + } + + private void afterRunProcedure() { + + // 检查是否安装完成, 对安装环境进行判定 + + } + + private void doRunProcedure(ProjectDeployContext projectDeployContext) { + + // 执行 基础功能施工的内容 + String masterTopicName = projectDeployContext + .getMasterNode() + .getTopicName(); + + List agentTopicNameList = projectDeployContext + .getAgentNodeList() + .stream() + .map(agentNode -> agentNode.getTopicName()) + .collect(Collectors.toList()); + + + if (!MasterNodeProcedure(masterTopicName)) { + log.error("初始化过程错误! 即将终止!"); + } + + if (!AgentNodeProcedure(agentTopicNameList)) { + log.error("初始化过程错误! 即将终止!"); + } + + + log.info("初始化过程完成!"); + } + + + private void beforeRunProcedure(ProjectDeployContext projectDeployContext) { + + // 检查是否符合规定 + + // 检查每一个Agent是否能够连通,调用命令返回结果 + + // 打印施工信息 + + } + + private boolean MasterNodeProcedure(String masterTopicName) { + + List masterNodeProcedureList = List.of( + BaseFunctionEnum.DISABLE_SWAP, + BaseFunctionEnum.SHUTDOWN_FIREWALL, + BaseFunctionEnum.CHRONY_TO_PUBLIC_NTP, + BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY, + BaseFunctionEnum.INSTALL_DOCKER, + BaseFunctionEnum.INSTALL_DOCKER_COMPOSE, + BaseFunctionEnum.INSTALL_HARBOR, + BaseFunctionEnum.INSTALL_ZSH + ); + + /*funcService.callBaseFuncAndJudge( + masterTopicName, + BaseFunctionEnum.MODIFY_HOSTNAME, + List.of("master-node") + );*/ + + for (BaseFunctionEnum procedure : masterNodeProcedureList) { + if (funcService.callBaseFuncAndJudge( + masterTopicName, + procedure, + null + )) { + + log.error( + "MasterNode初始化错误 => {}", + procedure + ); + + return false; + } + } + + + return true; + } + + + private boolean AgentNodeProcedure(List agentTopicNameList) { + + return true; + } + +} diff --git a/server/src/main/java/io/wdd/func/auto/service/FuncService.java b/server/src/main/java/io/wdd/func/auto/service/FuncService.java index 1543092..60a5462 100644 --- a/server/src/main/java/io/wdd/func/auto/service/FuncService.java +++ b/server/src/main/java/io/wdd/func/auto/service/FuncService.java @@ -1,6 +1,8 @@ package io.wdd.func.auto.service; +import io.wdd.func.auto.beans.BaseFunctionEnum; + import java.util.List; @@ -11,4 +13,13 @@ public interface FuncService { List callAppFuncService(String agentTopicName, String appFunctionName, List funcArgs); + /** + * 调用基本脚本,返回正确或者错误的结果 + * + * @param baseFunctionEnum + * @param funcArgs + * @return + */ + boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List funcArgs); + } diff --git a/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java b/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java index 1a3817b..aaf4ba7 100644 --- a/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java +++ b/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java @@ -1,9 +1,11 @@ package io.wdd.func.auto.service; +import io.wdd.func.auto.beans.BaseFunctionEnum; import io.wdd.rpc.execute.ExecutionMessageType; import io.wdd.rpc.execute.service.ExecutionService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.ArrayList; @@ -39,6 +41,45 @@ public class FuncServiceImpl implements FuncService { ); } + @Override + public boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List funcArgs) { + + log.debug( + "调用基本脚本 => {}", + baseFunctionEnum.getDesc() + ); + + List syncResultLog = syncCallFunction( + agentTopicName, + ExecutionMessageType.BASE, + baseFunctionEnum.getFuncName(), + funcArgs + ); + + if (CollectionUtils.isEmpty(syncResultLog)) { + log.error("基本脚本调用失败!"); + return false; + } + + if (syncResultLog + .get(0) + .endsWith("true")) { + log.debug( + "基本脚本调用成功 => {}", + syncResultLog + ); + + return true; + } + + log.error( + "基本脚本调用失败 !! => {}", + syncResultLog + ); + + return false; + } + // 归一化调用 private List syncCallFunction(String agentTopicName, ExecutionMessageType emType, String funcName, List funcArgs) { diff --git a/server/src/main/java/io/wdd/server/controller/ProjectController.java b/server/src/main/java/io/wdd/server/controller/ProjectController.java index 74bd56c..ecde584 100644 --- a/server/src/main/java/io/wdd/server/controller/ProjectController.java +++ b/server/src/main/java/io/wdd/server/controller/ProjectController.java @@ -70,7 +70,7 @@ public class ProjectController { @PostMapping("/delete") @ApiOperation("项目-删除一个项目") public R projectDelete( - @RequestParam(value = "projectId", name = "项目的Id") @ApiParam(value = "项目的Id") Long projectId + @RequestParam(value = "projectId", name = "projectId") @ApiParam(name = "projectId", value = "projectId") Long projectId ) { String result = "删除项目成功!"; diff --git a/server/src/main/java/io/wdd/server/controller/RoleController.java b/server/src/main/java/io/wdd/server/controller/RoleController.java index 6d55666..f7f3dba 100644 --- a/server/src/main/java/io/wdd/server/controller/RoleController.java +++ b/server/src/main/java/io/wdd/server/controller/RoleController.java @@ -56,7 +56,7 @@ public class RoleController { @PostMapping("/delete") @ApiOperation("角色-删除一个角色") public R roleDelete( - @RequestParam(value = "roleId", name = "角色的Id") @ApiParam(value = "角色的Id") Long roleId + @RequestParam(value = "roleId", name = "roleId") @ApiParam(value = "roleId") Long roleId ) { String result = "删除角色成功!"; diff --git a/server/src/main/resources/application-octopus.yml b/server/src/main/resources/application-dev.yml similarity index 97% rename from server/src/main/resources/application-octopus.yml rename to server/src/main/resources/application-dev.yml index de88b42..7bd166a 100644 --- a/server/src/main/resources/application-octopus.yml +++ b/server/src/main/resources/application-dev.yml @@ -6,7 +6,7 @@ spring: allow-circular-references: true allow-bean-definition-overriding: true rabbitmq: - host: 42.192.52.227 + host: 192.168.35.71 port: 20672 username: boge password: boge8tingH @@ -21,7 +21,7 @@ spring: max-interval: 65000 initial-interval: 65000 redis: - host: 42.192.52.227 + host: 192.168.35.71 port: 21370 database: 0 password: boge8tingH @@ -50,7 +50,7 @@ spring: time-between-eviction-runs: 50000 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://42.192.52.227:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:mysql://192.168.35.71:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: boge password: boge8tingH type: com.zaxxer.hikari.HikariDataSource diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index dce6514..de88b42 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -6,7 +6,7 @@ spring: allow-circular-references: true allow-bean-definition-overriding: true rabbitmq: - host: 192.168.35.71 + host: 42.192.52.227 port: 20672 username: boge password: boge8tingH @@ -21,7 +21,7 @@ spring: max-interval: 65000 initial-interval: 65000 redis: - host: 192.168.35.71 + host: 42.192.52.227 port: 21370 database: 0 password: boge8tingH @@ -33,7 +33,7 @@ spring: # - 43.154.83.213:21373 # - 43.154.83.213:21374 # - 43.154.83.213:21375 - # # 获取失败 最大重定向次数 + # # 获取失败 最大重定向次数 # max-redirects: 3 # timeout: 50000 #如果用以前的jedis,可以把下面的lettuce换成jedis即可 @@ -50,7 +50,7 @@ spring: time-between-eviction-runs: 50000 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.35.71:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:mysql://42.192.52.227:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: boge password: boge8tingH type: com.zaxxer.hikari.HikariDataSource