[ Server ] [ Executor ] - 添加基础初始化的核心部分
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ServerInfoPO> agentNodeList;
|
||||
|
||||
}
|
||||
@@ -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<String> 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<BaseFunctionEnum> 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<String> agentTopicNameList) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> callAppFuncService(String agentTopicName, String appFunctionName, List<String> funcArgs);
|
||||
|
||||
/**
|
||||
* 调用基本脚本,返回正确或者错误的结果
|
||||
*
|
||||
* @param baseFunctionEnum
|
||||
* @param funcArgs
|
||||
* @return
|
||||
*/
|
||||
boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs);
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String> funcArgs) {
|
||||
|
||||
log.debug(
|
||||
"调用基本脚本 => {}",
|
||||
baseFunctionEnum.getDesc()
|
||||
);
|
||||
|
||||
List<String> 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<String> syncCallFunction(String agentTopicName, ExecutionMessageType emType, String funcName, List<String> funcArgs) {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ProjectController {
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("项目-删除一个项目")
|
||||
public R<String> 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 = "删除项目成功!";
|
||||
|
||||
@@ -56,7 +56,7 @@ public class RoleController {
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("角色-删除一个角色")
|
||||
public R<String> roleDelete(
|
||||
@RequestParam(value = "roleId", name = "角色的Id") @ApiParam(value = "角色的Id") Long roleId
|
||||
@RequestParam(value = "roleId", name = "roleId") @ApiParam(value = "roleId") Long roleId
|
||||
) {
|
||||
|
||||
String result = "删除角色成功!";
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user