forked from thoughtworks/HeartBeat
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADM-733[backend]refactor: divide AsyncMetricsDataHandler from AsyncRe…
…portRequestHandler
- Loading branch information
Showing
11 changed files
with
119 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
backend/src/main/java/heartbeat/handler/AsyncMetricsDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package heartbeat.handler; | ||
|
||
import com.google.gson.Gson; | ||
import heartbeat.controller.report.dto.response.MetricsDataCompleted; | ||
import heartbeat.exception.GenerateReportException; | ||
import heartbeat.handler.base.AsyncDataBaseHandler; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static heartbeat.handler.base.FIleType.METRICS_DATA_COMPLETED; | ||
import static heartbeat.service.report.scheduler.DeleteExpireCSVScheduler.EXPORT_CSV_VALIDITY_TIME; | ||
|
||
@Log4j2 | ||
@Component | ||
@RequiredArgsConstructor | ||
public class AsyncMetricsDataHandler extends AsyncDataBaseHandler { | ||
|
||
private final Map<String, MetricsDataCompleted> metricsDataCompletedMap = new ConcurrentHashMap<>(); | ||
|
||
public void putMetricsDataCompleted(String timeStamp, MetricsDataCompleted metricsDataCompleted) { | ||
createDirToConvertData(METRICS_DATA_COMPLETED); | ||
creatFileByType(METRICS_DATA_COMPLETED, timeStamp, new Gson().toJson(metricsDataCompleted)); | ||
metricsDataCompletedMap.put(timeStamp, metricsDataCompleted); | ||
} | ||
|
||
public MetricsDataCompleted getMetricsDataCompleted(String timeStamp) { | ||
return metricsDataCompletedMap.get(timeStamp); | ||
} | ||
|
||
public boolean isReportReady(String timeStamp) { | ||
MetricsDataCompleted metricsDataCompleted = getMetricsDataCompleted(timeStamp); | ||
if (metricsDataCompleted == null) { | ||
throw new GenerateReportException("Failed to locate the report using this report ID."); | ||
} | ||
|
||
List<Boolean> metricsReady = Stream | ||
.of(metricsDataCompleted.boardMetricsCompleted(), metricsDataCompleted.pipelineMetricsCompleted(), | ||
metricsDataCompleted.sourceControlMetricsCompleted()) | ||
.filter(Objects::nonNull) | ||
.toList(); | ||
|
||
return metricsReady.stream().allMatch(Boolean::valueOf); | ||
} | ||
|
||
public void deleteExpireMetricsDataCompleted(long currentTimeStamp) { | ||
long exportTime = currentTimeStamp - EXPORT_CSV_VALIDITY_TIME; | ||
Set<String> keys = metricsDataCompletedMap.keySet() | ||
.stream() | ||
.filter(timeStamp -> Long.parseLong(timeStamp) < exportTime) | ||
.collect(Collectors.toSet()); | ||
metricsDataCompletedMap.keySet().removeAll(keys); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../heartbeat/handler/AsyncExceptionDTO.java → ...tbeat/handler/base/AsyncExceptionDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package heartbeat.handler; | ||
package heartbeat.handler.base; | ||
|
||
import heartbeat.exception.BaseException; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...main/java/heartbeat/handler/FIleType.java → ...java/heartbeat/handler/base/FIleType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.