[ Agent ] [ Initialization ] - add harbor func - 1

This commit is contained in:
zeaslity
2023-11-09 13:58:58 +08:00
parent aae4b7a286
commit cdfa4b5d04
8 changed files with 120 additions and 101 deletions

View File

@@ -1,7 +1,6 @@
package executor package executor
import ( import (
"agent-go/g"
"agent-go/register" "agent-go/register"
"fmt" "fmt"
"strings" "strings"
@@ -802,7 +801,7 @@ func (op *AgentOsOperator) installHelm() [][]string {
{ {
"wget", "wget",
"--no-check-certificate", "--no-check-certificate",
g.BaseFuncOssUrlPrefix + "helm-v3.12.1-linux-amd64.tar.gz", op.OssOfflinePrefix + "helm-v3.12.1-linux-amd64.tar.gz",
"-O", "-O",
"/root/wdd/helm-v3.12.1-linux-amd64.tar.gz", "/root/wdd/helm-v3.12.1-linux-amd64.tar.gz",
}, },
@@ -873,7 +872,7 @@ func (op *AgentOsOperator) modifyDockerConfig(args []string) [][]string {
}, },
{ {
"wget", "wget",
g.BaseFuncOssUrlPrefix + "daemon-config.json", op.OssOfflinePrefix + "daemon-config.json",
"-O", "-O",
"/etc/docker/daemon.json", "/etc/docker/daemon.json",
}, },
@@ -913,7 +912,7 @@ func (op *AgentOsOperator) installHarbor() [][]string {
//{ //{
// "wget", // "wget",
// "--no-check-certificate", // "--no-check-certificate",
// g.BaseFuncOssUrlPrefix + "harbor-offline-installer-v2.1.0.tgz", // op.OssOfflinePrefix + "harbor-offline-installer-v2.1.0.tgz",
// "-O", // "-O",
// "/root/wdd/harbor-offline-installer-v2.1.0.tgz", // "/root/wdd/harbor-offline-installer-v2.1.0.tgz",
//}, //},
@@ -932,7 +931,7 @@ func (op *AgentOsOperator) installHarbor() [][]string {
{ {
"wget", "wget",
"--no-check-certificate", "--no-check-certificate",
g.BaseFuncOssUrlPrefix + "harbor-config-template.yml", op.OssOfflinePrefix + "harbor-config-template.yml",
"-O", "-O",
"/root/wdd/harbor/harbor.yml", "/root/wdd/harbor/harbor.yml",
}, },
@@ -1009,7 +1008,8 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
} }
// download offline file // download offline file
log.Info("[install harbor] - start to download harbor offline installer !") harborOfflineFileURL := op.OssOfflinePrefix + "harbor-offline-installer-v2.1.0.tgz"
log.InfoF("[install harbor] - start to download harbor offline installer from => %s !", harborOfflineFileURL)
resultOk, resultLog := AllCompleteExecutor([][]string{ resultOk, resultLog := AllCompleteExecutor([][]string{
{ {
"mkdir", "mkdir",
@@ -1029,7 +1029,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
{ {
"wget", "wget",
"--no-check-certificate", "--no-check-certificate",
g.BaseFuncOssUrlPrefix + "harbor-offline-installer-v2.1.0.tgz", harborOfflineFileURL,
"-qO", "-qO",
"/root/wdd/harbor-offline-installer-v2.1.0.tgz", "/root/wdd/harbor-offline-installer-v2.1.0.tgz",
}}, }},
@@ -1063,7 +1063,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
AllCommandExecutor([]string{ AllCommandExecutor([]string{
"wget", "wget",
"--no-check-certificate", "--no-check-certificate",
g.BaseFuncOssUrlPrefix + "harbor-config-template.yml", op.OssOfflinePrefix + "harbor-config-template.yml",
"-qO", "-qO",
"/root/wdd/harbor/harbor.yml", "/root/wdd/harbor/harbor.yml",
}) })

View File

@@ -1,6 +1,9 @@
package executor package executor
import "strings" import (
"strconv"
"strings"
)
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator { func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
@@ -84,8 +87,6 @@ func detectByOsType(os *AgentOsOperator, osInfo string) {
func detectByInternet(os *AgentOsOperator) { func detectByInternet(os *AgentOsOperator) {
log.Info("开始检测Agent的网络连通情况!")
outsideTestUrl := "www.google.com" outsideTestUrl := "www.google.com"
innerTestUrl := "www.baidu.com" innerTestUrl := "www.baidu.com"
@@ -109,4 +110,6 @@ func detectByInternet(os *AgentOsOperator) {
os.IsAgentInnerWall = true os.IsAgentInnerWall = true
} }
log.InfoF("[Agent Network Status] - Can Access Internet => %s Inner CN => %s", strconv.FormatBool(os.CanAccessInternet), strconv.FormatBool(os.IsAgentInnerWall))
} }

View File

@@ -92,10 +92,9 @@ public class BaseFuncScheduler {
// BaseFunctionEnum.CHRONY_TO_PUBLIC_NTP, // BaseFunctionEnum.CHRONY_TO_PUBLIC_NTP,
// BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY, // BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY,
// BaseFunctionEnum.INSTALL_DOCKER, // BaseFunctionEnum.INSTALL_DOCKER,
// BaseFunctionEnum.INSTALL_DOCKER_COMPOSE, // BaseFunctionEnum.INSTALL_DOCKER_COMPOSE
// BaseFunctionEnum.INSTALL_HARBOR, // BaseFunctionEnum.INSTALL_HARBOR,
// BaseFunctionEnum.INSTALL_ZSH // BaseFunctionEnum.INSTALL_ZSH
BaseFunctionEnum.INSTALL_HARBOR
); );
@@ -103,7 +102,8 @@ public class BaseFuncScheduler {
if (!funcService.callBaseFuncAndJudge( if (!funcService.callBaseFuncAndJudge(
masterTopicName, masterTopicName,
procedure, procedure,
null null,
false
)) { )) {
log.error( 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; return true;
} }

View File

@@ -18,8 +18,9 @@ public interface FuncService {
* *
* @param baseFunctionEnum * @param baseFunctionEnum
* @param funcArgs * @param funcArgs
* @param durationTask
* @return * @return
*/ */
boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs); boolean callBaseFuncAndJudge(String agentTopicName, BaseFunctionEnum baseFunctionEnum, List<String> funcArgs, boolean durationTask);
} }

View File

@@ -26,7 +26,8 @@ public class FuncServiceImpl implements FuncService {
agentTopicName, agentTopicName,
ExecutionMessageType.BASE, ExecutionMessageType.BASE,
baseFunctionName, baseFunctionName,
funcArgs funcArgs,
false
); );
} }
@@ -37,12 +38,13 @@ public class FuncServiceImpl implements FuncService {
agentTopicName, agentTopicName,
ExecutionMessageType.APP, ExecutionMessageType.APP,
appFunctionName, appFunctionName,
funcArgs funcArgs,
false
); );
} }
@Override @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( log.debug(
"调用基本脚本 => {}", "调用基本脚本 => {}",
@@ -53,7 +55,8 @@ public class FuncServiceImpl implements FuncService {
agentTopicName, agentTopicName,
ExecutionMessageType.BASE, ExecutionMessageType.BASE,
baseFunctionEnum.getFuncName(), baseFunctionEnum.getFuncName(),
funcArgs funcArgs,
durationTask
); );
if (CollectionUtils.isEmpty(syncResultLog)) { 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 // 重新构造内容增加Function Name
if (CollectionUtils.isEmpty(funcArgs)) { if (CollectionUtils.isEmpty(funcArgs)) {
@@ -103,7 +106,7 @@ public class FuncServiceImpl implements FuncService {
null, null,
null, null,
true, true,
false durationTask
); );
return resultLog; return resultLog;

View File

@@ -76,7 +76,13 @@ public class ExecutionServiceImpl implements ExecutionService {
); );
// 需要返回结果 // 需要返回结果
if (!durationTask) {
// 超时等待时间,默认为 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会合并多行命令的结果一并返回 // countDownLatch的个数约定为1, agent会合并多行命令的结果一并返回
OMessageReplayContent replayContent = WaitFromAgent( OMessageReplayContent replayContent = WaitFromAgent(
@@ -90,7 +96,6 @@ public class ExecutionServiceImpl implements ExecutionService {
try { try {
// 2023年10月8日 根据执行的命令数量设定超时等待时间 // 2023年10月8日 根据执行的命令数量设定超时等待时间
int commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT;
if (!CollectionUtils.isEmpty(commandListComplete)) { if (!CollectionUtils.isEmpty(commandListComplete)) {
commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT * commandListComplete.size(); commandMaxWaitTimeout = COMMAND_MAX_WAIT_TIMEOUT * commandListComplete.size();
} }
@@ -122,7 +127,6 @@ public class ExecutionServiceImpl implements ExecutionService {
executionContent = executionMessage.getMultiLineCommand(); executionContent = executionMessage.getMultiLineCommand();
} }
// debug // debug
log.debug( log.debug(
"执行命令 {} {} 在规定时间内结束, 结果为 {} 返回内容为 {}", "执行命令 {} {} 在规定时间内结束, 结果为 {} 返回内容为 {}",
@@ -134,7 +138,6 @@ public class ExecutionServiceImpl implements ExecutionService {
} }
}
return commandResultLog; return commandResultLog;
} }

View File

@@ -1,6 +1,5 @@
package io.wdd.server.coreService.impl; 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.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -88,14 +87,17 @@ public class CoreServerServiceImpl implements CoreServerService {
public Page<ServerInfoPO> serverGetByPage(ServerQueryEntity serverQueryEntity) { public Page<ServerInfoPO> serverGetByPage(ServerQueryEntity serverQueryEntity) {
// 默认数值处理 // 默认数值处理
if (serverQueryEntity == null || serverQueryEntity.getPageSize() == null || serverQueryEntity.getPageNumber() == null) { if (serverQueryEntity == null) {
serverQueryEntity = ServerQueryEntity serverQueryEntity = ServerQueryEntity
.builder() .builder()
.pageNumber(1) .pageNumber(1)
.pageSize(10) .pageSize(10)
.build(); .build();
} else { }
if (serverQueryEntity.getPageSize() == null || serverQueryEntity.getPageNumber() == null) {
serverQueryEntity.setPageSize(10);
serverQueryEntity.setPageNumber(1);
} }
Page<ServerInfoPO> serverInfoPOPage = new Page<>( Page<ServerInfoPO> serverInfoPOPage = new Page<>(
@@ -104,29 +106,23 @@ public class CoreServerServiceImpl implements CoreServerService {
); );
// 查询Page会直接写入到serverInfoPOPage中 // 查询Page会直接写入到serverInfoPOPage中
serverInfoService new LambdaQueryChainWrapper<ServerInfoPO>(serverInfoService.getBaseMapper())
.getBaseMapper() .likeRight(
.selectPage( StringUtils.isNotEmpty(serverQueryEntity.getServerName()),
serverInfoPOPage, ServerInfoPO::getServerName,
new QueryWrapper<ServerInfoPO>()
.like(
StringUtils.isNoneEmpty(serverQueryEntity.getServerName()),
"server_name",
serverQueryEntity.getServerName() serverQueryEntity.getServerName()
) )
.likeRight( .likeRight(
StringUtils.isNoneEmpty(serverQueryEntity.getServerIPv4()), StringUtils.isNotEmpty(serverQueryEntity.getServerIPv4()),
"server_ip_pb_v4", ServerInfoPO::getServerIpPbV4,
serverQueryEntity.getServerIPv4() serverQueryEntity.getServerIPv4()
) )
.likeRight( .likeRight(
StringUtils.isNoneEmpty(serverQueryEntity.getServerLocation()), StringUtils.isNotEmpty(serverQueryEntity.getServerLocation()),
"location", ServerInfoPO::getLocation,
serverQueryEntity.getServerLocation() serverQueryEntity.getServerLocation()
) )
.orderByAsc("server_id") .page(serverInfoPOPage);
);
// 将查询结果中的User对象转换为UserVO对象 // 将查询结果中的User对象转换为UserVO对象
/*Page<ServerInfoVO> serverInfoVOPage = new Page<>( /*Page<ServerInfoVO> serverInfoVOPage = new Page<>(

View File

@@ -24,10 +24,12 @@ public class TestBaseFuncScheduler {
ProjectDeployContext projectDeployContext = new ProjectDeployContext(); ProjectDeployContext projectDeployContext = new ProjectDeployContext();
projectDeployContext.setProjectId(1716372290994155522L); // projectDeployContext.setProjectId(1716372290994155522L); // vultr
projectDeployContext.setProjectId(1722453318596550657L); // lappro
ServerQueryEntity serverQueryEntity = new ServerQueryEntity(); ServerQueryEntity serverQueryEntity = new ServerQueryEntity();
serverQueryEntity.setServerName("Paripark"); serverQueryEntity.setServerName("Chengdu");
ServerInfoPO serverInfoPO = serverService ServerInfoPO serverInfoPO = serverService
.serverGetByPage(serverQueryEntity) .serverGetByPage(serverQueryEntity)
.getRecords() .getRecords()