[ server ] [ status ]- update some code - 2

This commit is contained in:
zeaslity
2023-02-03 14:58:10 +08:00
parent fd5f2607b9
commit 487e808c58
4 changed files with 35 additions and 23 deletions

View File

@@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder;
public class OctopusStatusMessage { public class OctopusStatusMessage {
// below two will be used by both server and agent // below two will be used by both server and agent
// 存储所有Agent的实时健康状态 1代表健康 0代表失败
public static final String ALL_AGENT_STATUS_REDIS_KEY = "ALL_AGENT_HEALTHY_STATUS"; public static final String ALL_AGENT_STATUS_REDIS_KEY = "ALL_AGENT_HEALTHY_STATUS";
public static final String HEALTHY_STATUS_MESSAGE_TYPE = "ping"; public static final String HEALTHY_STATUS_MESSAGE_TYPE = "ping";
public static final String ALL_STATUS_MESSAGE_TYPE = "all"; public static final String ALL_STATUS_MESSAGE_TYPE = "all";

View File

@@ -6,9 +6,9 @@ import io.wdd.common.utils.TimeUtils;
import io.wdd.server.beans.vo.ServerInfoVO; import io.wdd.server.beans.vo.ServerInfoVO;
import io.wdd.server.coreService.CoreServerService; import io.wdd.server.coreService.CoreServerService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -56,7 +56,7 @@ public class ServerBootUpEnvironment {
/** /**
* 保存所有健康运行的Agent Topic Name * 保存所有健康运行的Agent Topic Name
*/ */
public static List<String> ALL_HEALTHY_AGENT_TOPIC_NAME_LIST; public static final List<String> ALL_HEALTHY_AGENT_TOPIC_NAME_LIST = new ArrayList<>();
@Resource @Resource
CoreServerService coreServerService; CoreServerService coreServerService;
@@ -68,21 +68,21 @@ public class ServerBootUpEnvironment {
public void GenerateAllCache() { public void GenerateAllCache() {
//所有Agent的TopicName ALL_AGENT_TOPIC_NAME_SET //所有Agent的TopicName ALL_AGENT_TOPIC_NAME_SET
updateAllAgentTopicNameSetCache(); updateAllAgentTopicNameCache();
// Agent状态信息的两个Map // Agent状态信息的两个Map
updateAgentStatusMapCache(); updateAgentStatusMapCache();
} }
public void updateAllAgentTopicNameSetCache() { public void updateAllAgentTopicNameCache() {
List<ServerInfoVO> allAgentInfo = coreServerService.serverGetAll(); List<ServerInfoVO> allAgentInfo = coreServerService.serverGetAll();
Assert.notEmpty( if (CollectionUtils.isEmpty(allAgentInfo)) {
allAgentInfo, log.warn("[Serer Boot Up] Octopus Serer First Boot Up ! No Agent Registered Ever!");
"not agent registered ! skip the agent healthy status check !" return;
); }
ALL_AGENT_TOPIC_NAME_LIST.clear(); ALL_AGENT_TOPIC_NAME_LIST.clear();
ALL_AGENT_TOPIC_NAME_SET.clear(); ALL_AGENT_TOPIC_NAME_SET.clear();
@@ -101,13 +101,23 @@ public class ServerBootUpEnvironment {
public void updateAgentStatusMapCache() { public void updateAgentStatusMapCache() {
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
log.warn("[Serer Boot Up] Octopus Serer First Boot Up ! No Agent Registered Ever!");
return;
}
List statusList = redisTemplate List statusList = redisTemplate
.opsForHash() .opsForHash()
.multiGet( .multiGet(
ALL_AGENT_STATUS_REDIS_KEY, ALL_AGENT_STATUS_REDIS_KEY,
ALL_AGENT_TOPIC_NAME_LIST ALL_AGENT_TOPIC_NAME_LIST
); );
// current log to console is ok
// 初始话 还没有状态的情况直接return
if (CollectionUtils.isEmpty(statusList)) {
log.warn("agent status from redis is empty !");
return;
}
// 结构保存为agentStatusMap ==> agent-topic-name : STATUS(healthy, failed, unknown) // 结构保存为agentStatusMap ==> agent-topic-name : STATUS(healthy, failed, unknown)
HashMap<String, String> agentStatusMap = new HashMap<>(32); HashMap<String, String> agentStatusMap = new HashMap<>(32);

View File

@@ -1,15 +1,14 @@
package io.wdd.rpc.scheduler.service.status; package io.wdd.rpc.scheduler.service.status;
import io.wdd.common.beans.status.AgentHealthyStatusEnum;
import io.wdd.common.beans.status.OctopusStatusMessage; import io.wdd.common.beans.status.OctopusStatusMessage;
import io.wdd.common.utils.TimeUtils; import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.init.ServerBootUpEnvironment; import io.wdd.rpc.init.ServerBootUpEnvironment;
import io.wdd.rpc.scheduler.service.BuildStatusScheduleTask; import io.wdd.rpc.scheduler.service.BuildStatusScheduleTask;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
@@ -20,7 +19,6 @@ import java.util.stream.Collectors;
import static io.wdd.common.beans.status.OctopusStatusMessage.ALL_AGENT_STATUS_REDIS_KEY; import static io.wdd.common.beans.status.OctopusStatusMessage.ALL_AGENT_STATUS_REDIS_KEY;
import static io.wdd.common.beans.status.OctopusStatusMessage.HEALTHY_STATUS_MESSAGE_TYPE; import static io.wdd.common.beans.status.OctopusStatusMessage.HEALTHY_STATUS_MESSAGE_TYPE;
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_LIST; import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_LIST;
import static io.wdd.rpc.init.ServerBootUpEnvironment.STATUS_AGENT_LIST_MAP;
/** /**
* 更新频率被类 BuildStatusScheduleTask.class控制 * 更新频率被类 BuildStatusScheduleTask.class控制
@@ -59,6 +57,12 @@ public class MonitorAllAgentStatus {
try { try {
// 1. 获取所有注册的Agent 手动更新 // 1. 获取所有注册的Agent 手动更新
serverBootUpEnvironment.updateAllAgentTopicNameCache();
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
log.warn("[Scheduler] No Agent Registered ! End Up Status Monitor !");
return;
}
// 1.1 检查 Agent状态保存数据结构是否正常 // 1.1 检查 Agent状态保存数据结构是否正常
checkOrCreateRedisHealthyKey(); checkOrCreateRedisHealthyKey();
@@ -126,6 +130,7 @@ public class MonitorAllAgentStatus {
) )
.collect(Collectors.toList()); .collect(Collectors.toList());
// 发送信息
collectAgentStatus.statusMessageToAgent(collect); collectAgentStatus.statusMessageToAgent(collect);
} }
@@ -139,17 +144,13 @@ public class MonitorAllAgentStatus {
// 执行Metric上报定时任务 // 执行Metric上报定时任务
buildStatusScheduleTask.buildAgentMetricScheduleTask(); buildStatusScheduleTask.buildAgentMetricScheduleTask();
// update time // 这里仅仅是更新时间
AGENT_HEALTHY_INIT_MAP.put(
"updateTime",
currentTimeString
);
redisTemplate redisTemplate
.opsForHash() .opsForHash()
.putAll( .put(
ALL_AGENT_STATUS_REDIS_KEY, ALL_AGENT_STATUS_REDIS_KEY,
AGENT_HEALTHY_INIT_MAP "updateTime",
currentTimeString
); );
} }

View File

@@ -138,9 +138,9 @@ tmp () {
gcloud compute instances create octopus-agent-2c-4g-1 --project=compact-lacing-371804 --zone=asia-northeast1-b --machine-type=n2d-custom-2-4096 --network-interface=network-tier=PREMIUM,subnet=default --metadata=startup-script=wget\ https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/main/java/io/wdd/source/shell/agent-bootup.sh\ \&\&\ chmod\ \+x\ agent-bootup.sh\ \&\&\ /bin/bash\ agent-bootup.sh --can-ip-forward --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=172889627951-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=octopus-agent-2c-4g,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221213,mode=rw,size=20,type=projects/compact-lacing-371804/zones/us-west4-b/diskTypes/pd1-ssd --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any gcloud compute instances create octopus-agent-2c-4g-1 --project=compact-lacing-371804 --zone=asia-northeast1-b --machine-type=n2d-custom-2-4096 --network-interface=network-tier=PREMIUM,subnet=default --metadata=startup-script=wget\ https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/main/java/io/wdd/source/shell/agent-bootup.sh\ \&\&\ chmod\ \+x\ agent-bootup.sh\ \&\&\ /bin/bash\ agent-bootup.sh --can-ip-forward --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=172889627951-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=octopus-agent-2c-4g,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221213,mode=rw,size=20,type=projects/compact-lacing-371804/zones/us-west4-b/diskTypes/pd1-ssd --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
gcloud compute instances create tokyo-amd64-03 --project=compact-lacing-371804 --zone=asia-northeast1-b --machine-type=n2d-custom-2-4096 --network-interface=network-tier=PREMIUM,subnet=default --can-ip-forward --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=172889627951-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=octopus-agent-2c-4g,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221213,mode=rw,size=20,type=projects/compact-lacing-371804/zones/us-west4-b/diskTypes/pd-ssd --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any gcloud compute instances create tokyo-amd64-13 --project=compact-lacing-371804 --zone=asia-northeast1-b --machine-type=n2d-custom-2-4096 --network-interface=network-tier=PREMIUM,subnet=default --can-ip-forward --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=172889627951-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=octopus-agent-2c-4g,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221213,mode=rw,size=20,type=projects/compact-lacing-371804/zones/us-west4-b/diskTypes/pd-ssd --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
gcloud compute ssh --zone "asia-northeast1-b" "tokyo-amd64-03" --project "compact-lacing-371804" gcloud compute ssh --zone "asia-northeast1-b" "tokyo-amd64-13" --project "compact-lacing-371804"
gcloud compute instances list --project "compact-lacing-371804" gcloud compute instances list --project "compact-lacing-371804"
@@ -149,7 +149,7 @@ wget https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/m
echo "y echo "y
" | gcloud compute instances delete tokyo-amd64-03 --project=compact-lacing-371804 --zone=asia-northeast1-b " | gcloud compute instances delete tokyo-amd64-13 --project=compact-lacing-371804 --zone=asia-northeast1-b
apt-cache madison openjdk-11-jdk | head -n 1 | awk '{print$3}' apt-cache madison openjdk-11-jdk | head -n 1 | awk '{print$3}'