[ Server ] [ Harbor ] - accomplish harbor create function
This commit is contained in:
@@ -22,4 +22,11 @@ public class ProjectDeployContext {
|
||||
|
||||
List<ServerInfoPO> agentNodeList;
|
||||
|
||||
boolean masterBaseProcedureAccomplished;
|
||||
|
||||
boolean agentBaseProcedureAccomplished;
|
||||
|
||||
boolean harborSynchronized;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public class BaseFuncScheduler {
|
||||
.getMasterNode()
|
||||
.getTopicName();
|
||||
|
||||
if (!MasterNodeProcedure(masterTopicName)) {
|
||||
log.error("初始化过程错误! 即将终止!");
|
||||
if (!MasterNodeBaseProcedure(masterTopicName)) {
|
||||
log.error("Master 初始化过程错误! 即将终止!");
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class BaseFuncScheduler {
|
||||
.collect(Collectors.toList());
|
||||
|
||||
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(
|
||||
// BaseFunctionEnum.DISABLE_SWAP,
|
||||
// BaseFunctionEnum.SHUTDOWN_FIREWALL,
|
||||
// BaseFunctionEnum.INSTALL_CHRONY,
|
||||
// BaseFunctionEnum.CHRONY_TO_PUBLIC_NTP,
|
||||
// BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY,
|
||||
// BaseFunctionEnum.INSTALL_DOCKER,
|
||||
// BaseFunctionEnum.INSTALL_DOCKER_COMPOSE
|
||||
// BaseFunctionEnum.INSTALL_HARBOR,
|
||||
// BaseFunctionEnum.INSTALL_ZSH
|
||||
// Object.DISABLE_SWAP,
|
||||
// Object.SHUTDOWN_FIREWALL,
|
||||
// Object.INSTALL_CHRONY,
|
||||
// Object.CHRONY_TO_PUBLIC_NTP,
|
||||
// Object.INSTALL_DEFAULT_SSH_KEY,
|
||||
// Object.INSTALL_DOCKER,
|
||||
// Object.INSTALL_DOCKER_COMPOSE
|
||||
// Object.INSTALL_HARBOR,
|
||||
// Object.INSTALL_ZSH
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package io.wdd.func.auto.service;
|
||||
|
||||
|
||||
import io.wdd.func.auto.beans.BaseFunctionEnum;
|
||||
import io.wdd.func.auto.beans.HarborFunctionEnum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -23,4 +25,5 @@ public interface FuncService {
|
||||
*/
|
||||
boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask);
|
||||
|
||||
boolean callHarborFuncAndJudge(String agentTopicName, HarborFunctionEnum harborFunctionEnum, ArrayList<String> funcArgs);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package io.wdd.func.auto.service;
|
||||
|
||||
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.service.ExecutionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -25,7 +27,6 @@ public class FuncServiceImpl implements FuncService {
|
||||
return this.syncCallFunction(
|
||||
agentTopicName,
|
||||
ExecutionMessageType.BASE,
|
||||
baseFunctionName,
|
||||
funcArgs,
|
||||
false
|
||||
);
|
||||
@@ -37,7 +38,6 @@ public class FuncServiceImpl implements FuncService {
|
||||
return this.syncCallFunction(
|
||||
agentTopicName,
|
||||
ExecutionMessageType.APP,
|
||||
appFunctionName,
|
||||
funcArgs,
|
||||
false
|
||||
);
|
||||
@@ -45,20 +45,43 @@ public class FuncServiceImpl implements FuncService {
|
||||
|
||||
@Override
|
||||
public boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask) {
|
||||
|
||||
log.debug(
|
||||
"调用基本脚本 => {}",
|
||||
baseFunctionEnum.getDesc()
|
||||
);
|
||||
// 重新构造内容,增加Function Name
|
||||
if (CollectionUtils.isEmpty(funcArgs)) {
|
||||
funcArgs = new ArrayList<>();
|
||||
}
|
||||
funcArgs.add(
|
||||
0,
|
||||
baseFunctionEnum.getFuncName()
|
||||
);
|
||||
|
||||
List<String> syncResultLog = syncCallFunction(
|
||||
agentTopicName,
|
||||
ExecutionMessageType.BASE,
|
||||
baseFunctionEnum.getFuncName(),
|
||||
funcArgs,
|
||||
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)) {
|
||||
log.error("基本脚本调用失败!");
|
||||
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
|
||||
if (CollectionUtils.isEmpty(funcArgs)) {
|
||||
funcArgs = new ArrayList<>();
|
||||
}
|
||||
funcArgs.add(
|
||||
0,
|
||||
funcName
|
||||
Assert.notNull(
|
||||
funcArgs,
|
||||
"syncCallFunction funArgs can not be null! "
|
||||
);
|
||||
|
||||
// 调用
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.wdd.server.func;
|
||||
|
||||
import io.wdd.func.auto.beans.ProjectDeployContext;
|
||||
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.request.ServerQueryEntity;
|
||||
import io.wdd.server.coreService.CoreServerService;
|
||||
@@ -16,6 +17,9 @@ public class TestBaseFuncScheduler {
|
||||
@Resource
|
||||
BaseFuncScheduler baseFuncScheduler;
|
||||
|
||||
@Resource
|
||||
HarborFuncScheduler harborFuncScheduler;
|
||||
|
||||
@Resource
|
||||
CoreServerService serverService;
|
||||
|
||||
@@ -40,8 +44,9 @@ public class TestBaseFuncScheduler {
|
||||
projectDeployContext.setMasterNode(serverInfoPO);
|
||||
|
||||
|
||||
baseFuncScheduler.runProcedure(projectDeployContext);
|
||||
// baseFuncScheduler.runProcedure(projectDeployContext);
|
||||
|
||||
harborFuncScheduler.runProcedure(projectDeployContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user