[ Status ] optimize the code

This commit is contained in:
IceDerce
2023-06-15 17:03:22 +08:00
parent 4b3f7be1dd
commit 54569cc41b
17 changed files with 123 additions and 157 deletions

View File

@@ -1,10 +1,17 @@
package io.wdd.rpc.status;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.wdd.rpc.message.OctopusMessage;
import io.wdd.rpc.message.OctopusMessageType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import javax.annotation.Resource;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
@@ -19,6 +26,9 @@ public class OctopusStatusMessage {
public static final String METRIC_STATUS_MESSAGE_TYPE = "METRIC";
public static final String APP_STATUS_MESSAGE_TYPE = "APP";
@Resource
ObjectMapper objectMapper;
/**
* which kind of status should be return
* metric => short time message
@@ -31,4 +41,28 @@ public class OctopusStatusMessage {
int metricRepeatPinch;
public OctopusMessage ConstructAgentStatusMessage(String statusType, String agentTopicName, LocalDateTime currentTime) {
OctopusStatusMessage statusMessage = OctopusStatusMessage
.builder()
.statusType(statusType)
.build();
String ops;
try {
ops = objectMapper.writeValueAsString(statusMessage);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return OctopusMessage
.builder()
.type(OctopusMessageType.STATUS)
.uuid(agentTopicName)
.init_time(currentTime)
.content(ops)
.build();
}
}

View File

@@ -1,7 +1,5 @@
package io.wdd.rpc.status.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.message.OctopusMessage;
import io.wdd.rpc.message.OctopusMessageType;
@@ -33,7 +31,7 @@ public class AsyncStatusServiceImpl implements AsyncStatusService {
OMessageToAgentSender oMessageToAgentSender;
@Resource
ObjectMapper objectMapper;
OctopusStatusMessage octopusStatusMessage;
@Resource
AsyncWaitOctopusMessageResultService asyncWaitOctopusMessageResultService;
@@ -107,7 +105,7 @@ public class AsyncStatusServiceImpl implements AsyncStatusService {
List<OctopusMessage> octopusStatusMessageList = ALL_AGENT_TOPIC_NAME_LIST
.stream()
.map(
agentTopicName -> ConstructAgentStatusMessage(
agentTopicName -> octopusStatusMessage.ConstructAgentStatusMessage(
HEALTHY_STATUS_MESSAGE_TYPE,
agentTopicName,
currentTime
@@ -120,27 +118,5 @@ public class AsyncStatusServiceImpl implements AsyncStatusService {
}
private OctopusMessage ConstructAgentStatusMessage(String statusType, String agentTopicName, LocalDateTime currentTime) {
OctopusStatusMessage statusMessage = OctopusStatusMessage
.builder()
.statusType(statusType)
.build();
String ops;
try {
ops = objectMapper.writeValueAsString(statusMessage);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return OctopusMessage
.builder()
.type(CurrentAppOctopusMessageType)
.uuid(agentTopicName)
.init_time(currentTime)
.content(ops)
.build();
}
}