[ server] [ agent ] - 版本信息全流程-完成
This commit is contained in:
@@ -70,6 +70,21 @@ public class TimeUtils {
|
|||||||
return LocalDateTime.now(SYSTEM_TIME_ZONE_ID);
|
return LocalDateTime.now(SYSTEM_TIME_ZONE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 格式化 去掉时间中的毫秒数
|
||||||
|
*/
|
||||||
|
public static LocalDateTime currentFormatTime() {
|
||||||
|
|
||||||
|
DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
String format = LocalDateTime
|
||||||
|
.now(SYSTEM_TIME_ZONE_ID)
|
||||||
|
.format(ofPattern);
|
||||||
|
|
||||||
|
return LocalDateTime.parse(format, ofPattern);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static LocalDateTime cvFromDate(Date date) {
|
public static LocalDateTime cvFromDate(Date date) {
|
||||||
|
|
||||||
// fix bug
|
// fix bug
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_LIST;
|
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
||||||
import static io.wdd.rpc.message.handler.OctopusMessageHandler.AGENT_LATEST_VERSION;
|
import static io.wdd.rpc.message.handler.OctopusMessageHandler.AGENT_LATEST_VERSION;
|
||||||
import static io.wdd.rpc.message.handler.OctopusMessageHandler.OCTOPUS_MESSAGE_FROM_AGENT;
|
import static io.wdd.rpc.message.handler.OctopusMessageHandler.OCTOPUS_MESSAGE_FROM_AGENT;
|
||||||
@@ -57,25 +56,34 @@ public class OctopusAgentServiceImpl implements OctopusAgentService {
|
|||||||
// 发送OctopusMessage-Agent
|
// 发送OctopusMessage-Agent
|
||||||
// 从OctopusToServer中收集到所有Agent的版本信息
|
// 从OctopusToServer中收集到所有Agent的版本信息
|
||||||
// 组装信息至集合中
|
// 组装信息至集合中
|
||||||
LocalDateTime currentTime = TimeUtils.currentTime();
|
LocalDateTime currentTime = TimeUtils.currentFormatTime();
|
||||||
|
|
||||||
buildAndSendToAllAgent(
|
buildAndSendToAllAgent(
|
||||||
AgentOperationType.VERSION,
|
AgentOperationType.VERSION,
|
||||||
currentTime
|
currentTime
|
||||||
);
|
);
|
||||||
|
|
||||||
waitCollectAllAgentVersionInfo(
|
CountDownLatch countDownLatch = new CountDownLatch(ALL_HEALTHY_AGENT_TOPIC_NAME_LIST.size());
|
||||||
|
|
||||||
|
CompletableFuture<Void> getAllAgentVersionInfoFuture = waitCollectAllAgentVersionInfo(
|
||||||
result,
|
result,
|
||||||
currentTime
|
currentTime,
|
||||||
|
countDownLatch
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TimeUnit.SECONDS.sleep(5);
|
// 超时等待5秒钟, 或者所有的Agent均已经完成上报
|
||||||
|
countDownLatch.await(
|
||||||
|
5,
|
||||||
|
TimeUnit.SECONDS
|
||||||
|
);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
log.warn("存在部分Agent没有上报 版本信息!");
|
||||||
|
} finally {
|
||||||
|
// 必须关闭释放线程
|
||||||
|
getAllAgentVersionInfoFuture.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("result = " + result);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,15 +109,12 @@ public class OctopusAgentServiceImpl implements OctopusAgentService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitCollectAllAgentVersionInfo(HashMap<String, String> result, LocalDateTime startTime) {
|
private CompletableFuture<Void> waitCollectAllAgentVersionInfo(HashMap<String, String> result, LocalDateTime startTime, CountDownLatch countDownLatch) {
|
||||||
|
|
||||||
CompletableFuture<Void> getAllAgentVersionInfo = new CompletableFuture<>();
|
|
||||||
try {
|
|
||||||
ExecutorService pool = ServerCommonPool.pool;
|
ExecutorService pool = ServerCommonPool.pool;
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(ALL_HEALTHY_AGENT_TOPIC_NAME_LIST.size());
|
|
||||||
|
|
||||||
// 从OCTOPUS_MESSAGE_FROM_AGENT中获取符合条件的信息
|
// 从OCTOPUS_MESSAGE_FROM_AGENT中获取符合条件的信息
|
||||||
getAllAgentVersionInfo = CompletableFuture.runAsync(
|
return CompletableFuture.runAsync(
|
||||||
() -> {
|
() -> {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (OCTOPUS_MESSAGE_FROM_AGENT.isEmpty()) {
|
if (OCTOPUS_MESSAGE_FROM_AGENT.isEmpty()) {
|
||||||
@@ -119,6 +124,8 @@ public class OctopusAgentServiceImpl implements OctopusAgentService {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
// 返回,继续死循环
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
OctopusMessage message = OCTOPUS_MESSAGE_FROM_AGENT.poll();
|
OctopusMessage message = OCTOPUS_MESSAGE_FROM_AGENT.poll();
|
||||||
@@ -130,13 +137,15 @@ public class OctopusAgentServiceImpl implements OctopusAgentService {
|
|||||||
message,
|
message,
|
||||||
startTime
|
startTime
|
||||||
)) {
|
)) {
|
||||||
|
|
||||||
// 不是当前应用需要的的OM,将信息放置与Cache队列的末尾
|
// 不是当前应用需要的的OM,将信息放置与Cache队列的末尾
|
||||||
try {
|
try {
|
||||||
OCTOPUS_MESSAGE_FROM_AGENT.put(message);
|
OCTOPUS_MESSAGE_FROM_AGENT.put(message);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return;
|
// 返回,继续死循环
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是当前需要的消息信息
|
// 是当前需要的消息信息
|
||||||
@@ -144,20 +153,12 @@ public class OctopusAgentServiceImpl implements OctopusAgentService {
|
|||||||
message.getUuid(),
|
message.getUuid(),
|
||||||
(String) message.getResult()
|
(String) message.getResult()
|
||||||
);
|
);
|
||||||
|
countDownLatch.countDown();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pool
|
pool
|
||||||
);
|
);
|
||||||
|
|
||||||
// 超时等待5秒钟
|
|
||||||
countDownLatch.await(
|
|
||||||
5,
|
|
||||||
TimeUnit.SECONDS
|
|
||||||
);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("存在部分Agent没有上报 版本信息!");
|
|
||||||
getAllAgentVersionInfo.cancel(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class OctopusMessageHandler {
|
|||||||
|
|
||||||
// todo what to do after received the result
|
// todo what to do after received the result
|
||||||
log.debug("cache the octopus message to inner cache list !");
|
log.debug("cache the octopus message to inner cache list !");
|
||||||
OCTOPUS_MESSAGE_FROM_AGENT.add(octopusMessage);
|
OCTOPUS_MESSAGE_FROM_AGENT.offer(octopusMessage);
|
||||||
|
|
||||||
// collect all message from agent and log to somewhere
|
// collect all message from agent and log to somewhere
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ public class ServerCommonPool {
|
|||||||
|
|
||||||
public static ExecutorService pool;
|
public static ExecutorService pool;
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
ThreadFactory threadFactory = new ThreadFactoryBuilder()
|
ThreadFactory threadFactory = new ThreadFactoryBuilder()
|
||||||
|
|||||||
Reference in New Issue
Block a user