[ Server ] [ Harbor ] - accomplish harbor create function

This commit is contained in:
zeaslity
2023-11-13 11:13:14 +08:00
parent 3f06350089
commit ccffd8eea2
6 changed files with 181 additions and 26 deletions

View File

@@ -22,4 +22,11 @@ public class ProjectDeployContext {
List<ServerInfoPO> agentNodeList; List<ServerInfoPO> agentNodeList;
boolean masterBaseProcedureAccomplished;
boolean agentBaseProcedureAccomplished;
boolean harborSynchronized;
} }

View File

@@ -48,8 +48,8 @@ public class BaseFuncScheduler {
.getMasterNode() .getMasterNode()
.getTopicName(); .getTopicName();
if (!MasterNodeProcedure(masterTopicName)) { if (!MasterNodeBaseProcedure(masterTopicName)) {
log.error("初始化过程错误! 即将终止!"); log.error("Master 初始化过程错误! 即将终止!");
} }
@@ -63,7 +63,7 @@ public class BaseFuncScheduler {
.collect(Collectors.toList()); .collect(Collectors.toList());
if (!AgentNodeProcedure(agentTopicNameList)) { if (!AgentNodeProcedure(agentTopicNameList)) {
log.error("初始化过程错误! 即将终止!"); log.error("Agent 初始化过程错误! 即将终止!");
} }
} }
@@ -83,18 +83,18 @@ public class BaseFuncScheduler {
} }
private boolean MasterNodeProcedure(String masterTopicName) { private boolean MasterNodeBaseProcedure(String masterTopicName) {
List<BaseFunctionEnum> masterNodeProcedureList = List.of( List<BaseFunctionEnum> masterNodeProcedureList = List.of(
// BaseFunctionEnum.DISABLE_SWAP, // Object.DISABLE_SWAP,
// BaseFunctionEnum.SHUTDOWN_FIREWALL, // Object.SHUTDOWN_FIREWALL,
// BaseFunctionEnum.INSTALL_CHRONY, // Object.INSTALL_CHRONY,
// BaseFunctionEnum.CHRONY_TO_PUBLIC_NTP, // Object.CHRONY_TO_PUBLIC_NTP,
// BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY, // Object.INSTALL_DEFAULT_SSH_KEY,
// BaseFunctionEnum.INSTALL_DOCKER, // Object.INSTALL_DOCKER,
// BaseFunctionEnum.INSTALL_DOCKER_COMPOSE // Object.INSTALL_DOCKER_COMPOSE
// BaseFunctionEnum.INSTALL_HARBOR, // Object.INSTALL_HARBOR,
// BaseFunctionEnum.INSTALL_ZSH // Object.INSTALL_ZSH
); );

View File

@@ -2,7 +2,9 @@ package io.wdd.func.auto.service;
import io.wdd.func.auto.beans.BaseFunctionEnum; import io.wdd.func.auto.beans.BaseFunctionEnum;
import io.wdd.func.auto.beans.HarborFunctionEnum;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -23,4 +25,5 @@ public interface FuncService {
*/ */
boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask); boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask);
boolean callHarborFuncAndJudge(String agentTopicName, HarborFunctionEnum harborFunctionEnum, ArrayList<String> funcArgs);
} }

View File

@@ -1,10 +1,12 @@
package io.wdd.func.auto.service; package io.wdd.func.auto.service;
import io.wdd.func.auto.beans.BaseFunctionEnum; import io.wdd.func.auto.beans.BaseFunctionEnum;
import io.wdd.func.auto.beans.HarborFunctionEnum;
import io.wdd.rpc.execute.ExecutionMessageType; import io.wdd.rpc.execute.ExecutionMessageType;
import io.wdd.rpc.execute.service.ExecutionService; import io.wdd.rpc.execute.service.ExecutionService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -25,7 +27,6 @@ public class FuncServiceImpl implements FuncService {
return this.syncCallFunction( return this.syncCallFunction(
agentTopicName, agentTopicName,
ExecutionMessageType.BASE, ExecutionMessageType.BASE,
baseFunctionName,
funcArgs, funcArgs,
false false
); );
@@ -37,7 +38,6 @@ public class FuncServiceImpl implements FuncService {
return this.syncCallFunction( return this.syncCallFunction(
agentTopicName, agentTopicName,
ExecutionMessageType.APP, ExecutionMessageType.APP,
appFunctionName,
funcArgs, funcArgs,
false false
); );
@@ -45,20 +45,43 @@ public class FuncServiceImpl implements FuncService {
@Override @Override
public boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask) { public boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask) {
log.debug( log.debug(
"调用基本脚本 => {}", "调用基本脚本 => {}",
baseFunctionEnum.getDesc() baseFunctionEnum.getDesc()
); );
// 重新构造内容增加Function Name
if (CollectionUtils.isEmpty(funcArgs)) {
funcArgs = new ArrayList<>();
}
funcArgs.add(
0,
baseFunctionEnum.getFuncName()
);
List<String> syncResultLog = syncCallFunction( List<String> syncResultLog = syncCallFunction(
agentTopicName, agentTopicName,
ExecutionMessageType.BASE, ExecutionMessageType.BASE,
baseFunctionEnum.getFuncName(),
funcArgs, funcArgs,
durationTask durationTask
); );
return JudgeSyncBaseCommandResult(syncResultLog);
}
@Override
public boolean callHarborFuncAndJudge(String agentTopicName, HarborFunctionEnum harborFunctionEnum, ArrayList<String> funcArgs) {
List<String> syncResultLog = syncCallFunction(
agentTopicName,
ExecutionMessageType.HARBOR,
funcArgs,
true
);
return JudgeSyncBaseCommandResult(syncResultLog);
}
private boolean JudgeSyncBaseCommandResult(List<String> syncResultLog) {
if (CollectionUtils.isEmpty(syncResultLog)) { if (CollectionUtils.isEmpty(syncResultLog)) {
log.error("基本脚本调用失败!"); log.error("基本脚本调用失败!");
return false; return false;
@@ -86,15 +109,11 @@ public class FuncServiceImpl implements FuncService {
// 归一化调用 // 归一化调用
private List<String> syncCallFunction(String agentTopicName, ExecutionMessageType emType, String funcName, List<String> funcArgs, boolean durationTask) { private List<String> syncCallFunction(String agentTopicName, ExecutionMessageType emType, List<String> funcArgs, boolean durationTask) {
// 重新构造内容增加Function Name Assert.notNull(
if (CollectionUtils.isEmpty(funcArgs)) { funcArgs,
funcArgs = new ArrayList<>(); "syncCallFunction funArgs can not be null! "
}
funcArgs.add(
0,
funcName
); );
// 调用 // 调用

View File

@@ -0,0 +1,121 @@
package io.wdd.func.auto.service;
import io.wdd.func.auto.beans.HarborFunctionEnum;
import io.wdd.func.auto.beans.ProjectDeployContext;
import io.wdd.server.beans.po.ServerInfoPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
public class HarborFuncScheduler {
@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() {
// 检查是否安装完成, 对安装环境进行判定
log.debug("afterRunProcedure complete!");
}
private void doRunProcedure(ProjectDeployContext projectDeployContext) {
// 执行 基础功能施工的内容
String masterTopicName = projectDeployContext
.getMasterNode()
.getTopicName();
// create harbor project
if (!CreateHarborProject(projectDeployContext)) {
log.error("create harbor project failed !");
}
// 1 - sync harbor
// 1 - load image from tar.gz
// check harbor project
log.info("Harbor Image Synchronized Succeed !");
}
private boolean CreateHarborProject(ProjectDeployContext projectDeployContext) {
// use master node as harbor server
ServerInfoPO masterNode = projectDeployContext.getMasterNode();
ArrayList<String> createProjectArgZList = new ArrayList<>();
createProjectArgZList.add(HarborFunctionEnum.CREATE_PROJECT.getOpName());
createProjectArgZList.add(masterNode.getServerIpInV4());
// send harbor create message
boolean createProjectOK = funcService.callHarborFuncAndJudge(
masterNode.getTopicName(),
HarborFunctionEnum.CREATE_PROJECT,
createProjectArgZList
);
if (!createProjectOK) {
log.error(
"[CreateHarborProject] - project create failed ! => {}",
createProjectArgZList
);
return false;
}
// check harbor project exists
return true;
}
private void beforeRunProcedure(ProjectDeployContext projectDeployContext) {
// 检查是否符合规定
// 检查每一个Agent是否能够连通,调用命令返回结果
// 打印施工信息
log.debug("beforeRunProcedure complete!");
}
private boolean MasterNodeBaseProcedure(String masterTopicName) {
return true;
}
private boolean AgentNodeProcedure(List<String> agentTopicNameList) {
return true;
}
}

View File

@@ -2,6 +2,7 @@ package io.wdd.server.func;
import io.wdd.func.auto.beans.ProjectDeployContext; import io.wdd.func.auto.beans.ProjectDeployContext;
import io.wdd.func.auto.service.BaseFuncScheduler; import io.wdd.func.auto.service.BaseFuncScheduler;
import io.wdd.func.auto.service.HarborFuncScheduler;
import io.wdd.server.beans.po.ServerInfoPO; import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.beans.request.ServerQueryEntity; import io.wdd.server.beans.request.ServerQueryEntity;
import io.wdd.server.coreService.CoreServerService; import io.wdd.server.coreService.CoreServerService;
@@ -16,6 +17,9 @@ public class TestBaseFuncScheduler {
@Resource @Resource
BaseFuncScheduler baseFuncScheduler; BaseFuncScheduler baseFuncScheduler;
@Resource
HarborFuncScheduler harborFuncScheduler;
@Resource @Resource
CoreServerService serverService; CoreServerService serverService;
@@ -40,8 +44,9 @@ public class TestBaseFuncScheduler {
projectDeployContext.setMasterNode(serverInfoPO); projectDeployContext.setMasterNode(serverInfoPO);
baseFuncScheduler.runProcedure(projectDeployContext); // baseFuncScheduler.runProcedure(projectDeployContext);
harborFuncScheduler.runProcedure(projectDeployContext);
} }
} }