Skip to content

Commit

Permalink
Merge pull request #80 from eunbikim-inno/fix-trigger-time-format
Browse files Browse the repository at this point in the history
fix trigger date format UTC
  • Loading branch information
kyuengmanKim authored Oct 23, 2024
2 parents 958461f + 134e23f commit 29957dd
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public class TriggerHistoryInfo {
@JsonProperty("name")
private String name;

@ApiModelProperty(value = "The time when the history was inserted into the database", example = "2024-05-24 11:31:55")
@ApiModelProperty(value = "The time when the history was inserted into the database", example = "2024-05-24T11:31:55Z")
@JsonProperty("create_at")
private String createAt;

@ApiModelProperty(value = "The time when the history occurred")
@ApiModelProperty(value = "The time when the history occurred", example = "2024-05-24T11:31:55Z")
@JsonProperty("occur_time")
private String occurTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public class TriggerPolicyInfo {
@JsonProperty("tick_script")
private String tickScript;

@ApiModelProperty(value = "The time when the trigger policy was registered", example = "2024-05-24 11:31:55")
@ApiModelProperty(value = "The time when the trigger policy was registered", example = "2024-05-24T11:31:55Z")
@JsonProperty("create_at")
private String createAt;

@ApiModelProperty(value = "The time when the trigger policy was updated")
@ApiModelProperty(value = "The time when the trigger policy was updated", example = "2024-05-24T11:31:55Z")
@JsonProperty("update_at")
private String updateAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public class TriggerTargetInfo {
@JsonProperty("alias_name")
private String aliasName;

@ApiModelProperty(value = "The time when the trigger target was registered", example = "2024-05-24 11:31:55")
@ApiModelProperty(value = "The time when the trigger target was registered", example = "2024-05-24T11:31:55Z")
@JsonProperty("create_at")
private String createAt;

@ApiModelProperty(value = "The time when the trigger target was updated")
@ApiModelProperty(value = "The time when the trigger target was updated", example = "2024-05-24T11:31:55Z")
@JsonProperty("update_at")
private String updateAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TriggerTargetStorageInfo {
@JsonProperty("retention_policy")
private String retentionPolicy;

@ApiModelProperty(value = "The time when the trigger target storage was registered", example = "2024-05-24 11:31:55")
@ApiModelProperty(value = "The time when the trigger target storage was registered", example = "2024-05-24T11:31:55Z")
@JsonProperty("create_at")
private String createAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import mcmp.mc.observability.mco11yagent.trigger.mapper.TriggerPolicyMapper;
import mcmp.mc.observability.mco11yagent.trigger.model.TriggerHistoryInfo;
import mcmp.mc.observability.mco11yagent.trigger.model.TriggerPolicyInfo;
import mcmp.mc.observability.mco11yagent.trigger.util.TimeConverterUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -23,8 +25,9 @@ public List<TriggerHistoryInfo> getList(Long policySeq) {
TriggerPolicyInfo triggerPolicyInfo = triggerPolicyMapper.getDetail(policySeq);
if(triggerPolicyInfo == null)
throw new TriggerResultCodeException(ResultCode.INVALID_REQUEST, "Trigger Policy Sequence Error");

return triggerHistoryMapper.getList(policySeq);
return triggerHistoryMapper.getList(policySeq).stream()
.peek(this::formatTriggerPolicyHistoryInfo)
.collect(Collectors.toList());
}

public ResBody<TriggerHistoryInfo> getDetail(ResBody<TriggerHistoryInfo> ResBody, Long seq) {
Expand All @@ -40,6 +43,16 @@ public ResBody<TriggerHistoryInfo> getDetail(ResBody<TriggerHistoryInfo> ResBody

public TriggerHistoryInfo getDetail(Long seq) {
TriggerHistoryInfo info = triggerHistoryMapper.getDetail(seq);
formatTriggerPolicyHistoryInfo(info);
return info;
}

private void formatTriggerPolicyHistoryInfo(TriggerHistoryInfo policyHistory) {
if (policyHistory.getCreateAt() != null) {
policyHistory.setCreateAt(TimeConverterUtils.toUTCFormat(policyHistory.getCreateAt()));
}
if (policyHistory.getOccurTime() != null) {
policyHistory.setOccurTime(TimeConverterUtils.toUTCFormat(policyHistory.getOccurTime()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import mcmp.mc.observability.mco11yagent.trigger.model.TriggerPolicyInfo;
import mcmp.mc.observability.mco11yagent.trigger.model.dto.TriggerPolicyCreateDto;
import mcmp.mc.observability.mco11yagent.trigger.model.dto.TriggerPolicyUpdateDto;
import mcmp.mc.observability.mco11yagent.trigger.util.TimeConverterUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;


import java.util.*;
import java.util.stream.Collectors;


@Slf4j
@Service
Expand All @@ -35,12 +38,14 @@ public class TriggerPolicyService {
private String agentManagerIp;

public List<TriggerPolicyInfo> getList() {
return triggerPolicyMapper.getList();
return triggerPolicyMapper.getList().stream()
.peek(this::formatTriggerPolicyInfo)
.collect(Collectors.toList());
}

public ResBody<TriggerPolicyInfo> getDetail(ResBody<TriggerPolicyInfo> ResBody, Long seq) {
TriggerPolicyInfo triggerHistoryInfo = getDetail(seq);
if( triggerHistoryInfo == null ) {
if (triggerHistoryInfo == null) {
ResBody.setCode(ResultCode.INVALID_REQUEST);
return ResBody;
}
Expand All @@ -51,9 +56,19 @@ public ResBody<TriggerPolicyInfo> getDetail(ResBody<TriggerPolicyInfo> ResBody,

public TriggerPolicyInfo getDetail(Long seq) {
TriggerPolicyInfo info = triggerPolicyMapper.getDetail(seq);
formatTriggerPolicyInfo(info);
return info;
}

private void formatTriggerPolicyInfo(TriggerPolicyInfo policy) {
if (policy.getCreateAt() != null) {
policy.setCreateAt(TimeConverterUtils.toUTCFormat(policy.getCreateAt()));
}
if (policy.getUpdateAt() != null) {
policy.setUpdateAt(TimeConverterUtils.toUTCFormat(policy.getUpdateAt()));
}
}

public ResBody<Void> createPolicy(TriggerPolicyCreateDto dto) {
ResBody<Void> ResBody = new ResBody<>();
TriggerPolicyInfo info = new TriggerPolicyInfo();
Expand Down Expand Up @@ -90,12 +105,12 @@ public ResBody<Void> updatePolicy(TriggerPolicyUpdateDto dto) {
throw new TriggerResultCodeException(ResultCode.INVALID_ERROR, "Trigger Policy Update None");
}

if(hasNonNullFields(dto)) {
if (hasNonNullFields(dto)) {
List<ManageTriggerTargetStorageInfo> targetStorageInfoList = triggerTargetStorageMapper.getManageTriggerTargetStorageInfoList(Collections.singletonMap("policySeq", info.getSeq()));
if (CollectionUtils.isEmpty(targetStorageInfoList))
return ResBody;

for(ManageTriggerTargetStorageInfo targetStorageInfo : targetStorageInfoList) {
for (ManageTriggerTargetStorageInfo targetStorageInfo : targetStorageInfoList) {
kapacitorApiService.updateTask(info, targetStorageInfo);
}
}
Expand All @@ -122,11 +137,11 @@ private boolean hasNonNullFields(TriggerPolicyUpdateDto dto) {
public ResBody<Void> deletePolicy(Long seq) {
ResBody<Void> ResBody = new ResBody<>();
try {
if( seq <= 0 )
if (seq <= 0)
throw new TriggerResultCodeException(ResultCode.NOT_FOUND_REQUIRED, "Trigger Policy Sequence Error");

TriggerPolicyInfo policyInfo = getDetail(seq);
if(policyInfo == null)
if (policyInfo == null)
throw new TriggerResultCodeException(ResultCode.INVALID_REQUEST, "Trigger Policy Sequence Error");

List<ManageTriggerTargetStorageInfo> targetStorageInfoList = triggerTargetStorageMapper.getManageTriggerTargetStorageInfoList(Collections.singletonMap("policySeq", seq));
Expand All @@ -143,8 +158,7 @@ public ResBody<Void> deletePolicy(Long seq) {
triggerTargetStorageMapper.deleteTriggerTargetStorageByPolicySeq(seq);
triggerTargetMapper.deleteTriggerTargetByPolicySeq(seq);
triggerPolicyMapper.deletePolicy(seq);
}
catch (TriggerResultCodeException e) {
} catch (TriggerResultCodeException e) {
log.error(e.getMessage(), e.getObjects());
ResBody.setCode(e.getResultCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import mcmp.mc.observability.mco11yagent.trigger.model.TriggerTargetInfo;
import mcmp.mc.observability.mco11yagent.trigger.model.TriggerTargetStorageInfo;
import mcmp.mc.observability.mco11yagent.trigger.model.dto.ManageTriggerTargetDto;
import mcmp.mc.observability.mco11yagent.trigger.util.TimeConverterUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
Expand All @@ -36,7 +38,9 @@ public List<TriggerTargetInfo> getList(Long policySeq) {
if(triggerPolicyInfo == null)
throw new TriggerResultCodeException(ResultCode.INVALID_REQUEST, "Trigger Policy Sequence Error");

return triggerTargetMapper.getList(policySeq);
return triggerTargetMapper.getList(policySeq).stream()
.peek(this::formatTriggerTargetInfo)
.collect(Collectors.toList());
}

public ResBody<TriggerTargetInfo> getDetail(ResBody<TriggerTargetInfo> ResBody, Long seq) {
Expand All @@ -52,9 +56,19 @@ public ResBody<TriggerTargetInfo> getDetail(ResBody<TriggerTargetInfo> ResBody,

public TriggerTargetInfo getDetail(Long seq) {
TriggerTargetInfo info = triggerTargetMapper.getDetail(seq);
formatTriggerTargetInfo(info);
return info;
}

private void formatTriggerTargetInfo(TriggerTargetInfo target) {
if (target.getCreateAt() != null) {
target.setCreateAt(TimeConverterUtils.toUTCFormat(target.getCreateAt()));
}
if (target.getUpdateAt() != null) {
target.setUpdateAt(TimeConverterUtils.toUTCFormat(target.getUpdateAt()));
}
}

public ResBody<Void> setTargets(Long policySeq, List<ManageTriggerTargetDto> targets) {
ResBody<Void> ResBody = new ResBody<>();
TriggerPolicyInfo policyInfo = triggerPolicyMapper.getDetail(policySeq);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mcmp.mc.observability.mco11yagent.trigger.util;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class TimeConverterUtils {

public static final String toUTCFormat(String dateTimeStr){
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, inputFormatter);
return dateTime.toInstant(ZoneOffset.UTC).toString();
}
}

0 comments on commit 29957dd

Please sign in to comment.