[ Status ] optimize the code
This commit is contained in:
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user