[ Agent ] [ Initialization ] - add harbor func - 1
This commit is contained in:
@@ -92,10 +92,9 @@ public class BaseFuncScheduler {
|
||||
// BaseFunctionEnum.CHRONY_TO_PUBLIC_NTP,
|
||||
// BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY,
|
||||
// BaseFunctionEnum.INSTALL_DOCKER,
|
||||
// BaseFunctionEnum.INSTALL_DOCKER_COMPOSE,
|
||||
// BaseFunctionEnum.INSTALL_DOCKER_COMPOSE
|
||||
// BaseFunctionEnum.INSTALL_HARBOR,
|
||||
// BaseFunctionEnum.INSTALL_ZSH
|
||||
BaseFunctionEnum.INSTALL_HARBOR
|
||||
);
|
||||
|
||||
|
||||
@@ -103,7 +102,8 @@ public class BaseFuncScheduler {
|
||||
if (!funcService.callBaseFuncAndJudge(
|
||||
masterTopicName,
|
||||
procedure,
|
||||
null
|
||||
null,
|
||||
false
|
||||
)) {
|
||||
|
||||
log.error(
|
||||
@@ -115,6 +115,17 @@ public class BaseFuncScheduler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!funcService.callBaseFuncAndJudge(
|
||||
masterTopicName,
|
||||
BaseFunctionEnum.INSTALL_HARBOR,
|
||||
null,
|
||||
true
|
||||
)) {
|
||||
log.error("Master Install Harbor Failed !");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@ public interface FuncService {
|
||||
*
|
||||
* @param baseFunctionEnum
|
||||
* @param funcArgs
|
||||
* @param durationTask
|
||||
* @return
|
||||
*/
|
||||
boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs);
|
||||
boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ public class FuncServiceImpl implements FuncService {
|
||||
agentTopicName,
|
||||
ExecutionMessageType.BASE,
|
||||
baseFunctionName,
|
||||
funcArgs
|
||||
funcArgs,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -37,12 +38,13 @@ public class FuncServiceImpl implements FuncService {
|
||||
agentTopicName,
|
||||
ExecutionMessageType.APP,
|
||||
appFunctionName,
|
||||
funcArgs
|
||||
funcArgs,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs) {
|
||||
public boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask) {
|
||||
|
||||
log.debug(
|
||||
"调用基本脚本 => {}",
|
||||
@@ -53,7 +55,8 @@ public class FuncServiceImpl implements FuncService {
|
||||
agentTopicName,
|
||||
ExecutionMessageType.BASE,
|
||||
baseFunctionEnum.getFuncName(),
|
||||
funcArgs
|
||||
funcArgs,
|
||||
durationTask
|
||||
);
|
||||
|
||||
if (CollectionUtils.isEmpty(syncResultLog)) {
|
||||
@@ -83,7 +86,7 @@ public class FuncServiceImpl implements FuncService {
|
||||
|
||||
|
||||
// 归一化调用
|
||||
private List<String> syncCallFunction(String agentTopicName, ExecutionMessageType emType, String funcName, List<String> funcArgs) {
|
||||
private List<String> syncCallFunction(String agentTopicName, ExecutionMessageType emType, String funcName, List<String> funcArgs, boolean durationTask) {
|
||||
|
||||
// 重新构造内容,增加Function Name
|
||||
if (CollectionUtils.isEmpty(funcArgs)) {
|
||||
@@ -103,7 +106,7 @@ public class FuncServiceImpl implements FuncService {
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
false
|
||||
durationTask
|
||||
);
|
||||
|
||||
return resultLog;
|
||||
|
||||
@@ -76,66 +76,69 @@ public class ExecutionServiceImpl implements ExecutionService {
|
||||
);
|
||||
|
||||
// 需要返回结果
|
||||
if (!durationTask) {
|
||||
// 等待结果
|
||||
// countDownLatch的个数约定为1, agent会合并多行命令的结果一并返回
|
||||
OMessageReplayContent replayContent = WaitFromAgent(
|
||||
octopusMessage,
|
||||
1
|
||||
);
|
||||
|
||||
CountDownLatch replayLatch = replayContent.getCountDownLatch();
|
||||
boolean waitOK = false;
|
||||
// 超时等待时间,默认为 COMMAND_MAX_WAIT_TIMEOUT
|
||||
int commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT;
|
||||
if (durationTask) {
|
||||
// 2023年11月9日 超长的任务时间设置为5分钟
|
||||
commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT * 5;
|
||||
}
|
||||
// 等待结果
|
||||
// countDownLatch的个数约定为1, agent会合并多行命令的结果一并返回
|
||||
OMessageReplayContent replayContent = WaitFromAgent(
|
||||
octopusMessage,
|
||||
1
|
||||
);
|
||||
|
||||
try {
|
||||
CountDownLatch replayLatch = replayContent.getCountDownLatch();
|
||||
boolean waitOK = false;
|
||||
|
||||
// 2023年10月8日 根据执行的命令数量设定超时等待时间
|
||||
int commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT;
|
||||
if (!CollectionUtils.isEmpty(commandListComplete)) {
|
||||
commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT * commandListComplete.size();
|
||||
}
|
||||
|
||||
waitOK = replayLatch.await(
|
||||
commandMaxWaitTimeout,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
||||
// 释放等待队列
|
||||
StopWaitingResult(octopusMessage);
|
||||
|
||||
// 转换结果
|
||||
commandResultLog = (ArrayList<String>) octopusMessage.getResult();
|
||||
|
||||
|
||||
Object executionContent;
|
||||
if (executionMessage
|
||||
.getExecutionType()
|
||||
.equals("BASE")) {
|
||||
executionContent = executionMessage.getExecutionType() + "==" + executionMessage.getFuncContent();
|
||||
} else if (executionMessage.getSingleLineCommand() != null) {
|
||||
executionContent = executionMessage.getSingleLineCommand();
|
||||
} else {
|
||||
executionContent = executionMessage.getMultiLineCommand();
|
||||
}
|
||||
|
||||
|
||||
// debug
|
||||
log.debug(
|
||||
"执行命令 {} {} 在规定时间内结束, 结果为 {} 返回内容为 {}",
|
||||
executionContent,
|
||||
waitOK ? "已经" : "未",
|
||||
octopusMessage.getResultCode(),
|
||||
commandResultLog
|
||||
);
|
||||
try {
|
||||
|
||||
// 2023年10月8日 根据执行的命令数量设定超时等待时间
|
||||
if (!CollectionUtils.isEmpty(commandListComplete)) {
|
||||
commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT * commandListComplete.size();
|
||||
}
|
||||
|
||||
waitOK = replayLatch.await(
|
||||
commandMaxWaitTimeout,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
||||
// 释放等待队列
|
||||
StopWaitingResult(octopusMessage);
|
||||
|
||||
// 转换结果
|
||||
commandResultLog = (ArrayList<String>) octopusMessage.getResult();
|
||||
|
||||
|
||||
Object executionContent;
|
||||
if (executionMessage
|
||||
.getExecutionType()
|
||||
.equals("BASE")) {
|
||||
executionContent = executionMessage.getExecutionType() + "==" + executionMessage.getFuncContent();
|
||||
} else if (executionMessage.getSingleLineCommand() != null) {
|
||||
executionContent = executionMessage.getSingleLineCommand();
|
||||
} else {
|
||||
executionContent = executionMessage.getMultiLineCommand();
|
||||
}
|
||||
|
||||
// debug
|
||||
log.debug(
|
||||
"执行命令 {} {} 在规定时间内结束, 结果为 {} 返回内容为 {}",
|
||||
executionContent,
|
||||
waitOK ? "已经" : "未",
|
||||
octopusMessage.getResultCode(),
|
||||
commandResultLog
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return commandResultLog;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.wdd.server.coreService.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -88,14 +87,17 @@ public class CoreServerServiceImpl implements CoreServerService {
|
||||
public Page<ServerInfoPO> serverGetByPage(ServerQueryEntity serverQueryEntity) {
|
||||
|
||||
// 默认数值处理
|
||||
if (serverQueryEntity == null || serverQueryEntity.getPageSize() == null || serverQueryEntity.getPageNumber() == null) {
|
||||
if (serverQueryEntity == null) {
|
||||
serverQueryEntity = ServerQueryEntity
|
||||
.builder()
|
||||
.pageNumber(1)
|
||||
.pageSize(10)
|
||||
.build();
|
||||
} else {
|
||||
}
|
||||
|
||||
if (serverQueryEntity.getPageSize() == null || serverQueryEntity.getPageNumber() == null) {
|
||||
serverQueryEntity.setPageSize(10);
|
||||
serverQueryEntity.setPageNumber(1);
|
||||
}
|
||||
|
||||
Page<ServerInfoPO> serverInfoPOPage = new Page<>(
|
||||
@@ -104,29 +106,23 @@ public class CoreServerServiceImpl implements CoreServerService {
|
||||
);
|
||||
|
||||
// 查询Page,会直接写入到serverInfoPOPage中
|
||||
serverInfoService
|
||||
.getBaseMapper()
|
||||
.selectPage(
|
||||
serverInfoPOPage,
|
||||
new QueryWrapper<ServerInfoPO>()
|
||||
.like(
|
||||
StringUtils.isNoneEmpty(serverQueryEntity.getServerName()),
|
||||
"server_name",
|
||||
serverQueryEntity.getServerName()
|
||||
)
|
||||
.likeRight(
|
||||
StringUtils.isNoneEmpty(serverQueryEntity.getServerIPv4()),
|
||||
"server_ip_pb_v4",
|
||||
serverQueryEntity.getServerIPv4()
|
||||
)
|
||||
.likeRight(
|
||||
StringUtils.isNoneEmpty(serverQueryEntity.getServerLocation()),
|
||||
"location",
|
||||
serverQueryEntity.getServerLocation()
|
||||
)
|
||||
.orderByAsc("server_id")
|
||||
);
|
||||
|
||||
new LambdaQueryChainWrapper<ServerInfoPO>(serverInfoService.getBaseMapper())
|
||||
.likeRight(
|
||||
StringUtils.isNotEmpty(serverQueryEntity.getServerName()),
|
||||
ServerInfoPO::getServerName,
|
||||
serverQueryEntity.getServerName()
|
||||
)
|
||||
.likeRight(
|
||||
StringUtils.isNotEmpty(serverQueryEntity.getServerIPv4()),
|
||||
ServerInfoPO::getServerIpPbV4,
|
||||
serverQueryEntity.getServerIPv4()
|
||||
)
|
||||
.likeRight(
|
||||
StringUtils.isNotEmpty(serverQueryEntity.getServerLocation()),
|
||||
ServerInfoPO::getLocation,
|
||||
serverQueryEntity.getServerLocation()
|
||||
)
|
||||
.page(serverInfoPOPage);
|
||||
|
||||
// 将查询结果中的User对象转换为UserVO对象
|
||||
/*Page<ServerInfoVO> serverInfoVOPage = new Page<>(
|
||||
|
||||
@@ -24,10 +24,12 @@ public class TestBaseFuncScheduler {
|
||||
|
||||
ProjectDeployContext projectDeployContext = new ProjectDeployContext();
|
||||
|
||||
projectDeployContext.setProjectId(1716372290994155522L);
|
||||
// projectDeployContext.setProjectId(1716372290994155522L); // vultr
|
||||
projectDeployContext.setProjectId(1722453318596550657L); // lappro
|
||||
|
||||
|
||||
ServerQueryEntity serverQueryEntity = new ServerQueryEntity();
|
||||
serverQueryEntity.setServerName("Paripark");
|
||||
serverQueryEntity.setServerName("Chengdu");
|
||||
ServerInfoPO serverInfoPO = serverService
|
||||
.serverGetByPage(serverQueryEntity)
|
||||
.getRecords()
|
||||
|
||||
Reference in New Issue
Block a user