Implementato servizio di retrieve dello status delle export (+ mockup)
This commit is contained in:
@@ -49,7 +49,7 @@ public class Migration_20240124171059 extends BaseMigration implements Migration
|
|||||||
Long newParentId = getNewGeneratedIdFromOldKey(oldId, oldStbPublications);
|
Long newParentId = getNewGeneratedIdFromOldKey(oldId, oldStbPublications);
|
||||||
|
|
||||||
String insertSql = Query.format("INSERT INTO stb_publications_detail " +
|
String insertSql = Query.format("INSERT INTO stb_publications_detail " +
|
||||||
"(stb_publication_id, entity_name, where_cond_sql, recalc_columns, syncronize, where_cond, ready_to_transmit) " +
|
"(stb_publication_id, entity_name, where_cond_sql, recalc_columns, active, where_cond, ready_to_transmit) " +
|
||||||
"VALUES (%s, %s, %s, %s, %s, %s, %s)",
|
"VALUES (%s, %s, %s, %s, %s, %s, %s)",
|
||||||
newParentId,
|
newParentId,
|
||||||
entityName,
|
entityName,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package it.integry.ems.sync;
|
package it.integry.ems.sync;
|
||||||
|
|
||||||
import it.integry.annotations.PostContextConstruct;
|
import it.integry.annotations.PostContextConstruct;
|
||||||
import it.integry.common.var.CommonConstants;
|
|
||||||
import it.integry.ems.datasource.DataSource;
|
import it.integry.ems.datasource.DataSource;
|
||||||
import it.integry.ems.json.JSONObjectMapper;
|
import it.integry.ems.json.JSONObjectMapper;
|
||||||
import it.integry.ems.looper.service.LooperService;
|
import it.integry.ems.looper.service.LooperService;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
import it.integry.ems.sync.dto.ExportHistoryItemDTO;
|
import it.integry.ems.sync.dto.ExportHistoryItemDTO;
|
||||||
|
import it.integry.ems.sync.dto.ExportHistoryStatusDTO;
|
||||||
import it.integry.ems.sync.dto.PublicationDTO;
|
import it.integry.ems.sync.dto.PublicationDTO;
|
||||||
import it.integry.ems_model.base.EntityBase;
|
import it.integry.ems_model.base.EntityBase;
|
||||||
import it.integry.ems_model.base.EntityPropertyHolder;
|
import it.integry.ems_model.base.EntityPropertyHolder;
|
||||||
@@ -22,9 +22,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AsyncHistoryManager {
|
public class AsyncHistoryManager {
|
||||||
@@ -182,36 +180,61 @@ public class AsyncHistoryManager {
|
|||||||
stbTransactionLog.manageWithParentConnection(multiDBTransactionManager.getPrimaryConnection());
|
stbTransactionLog.manageWithParentConnection(multiDBTransactionManager.getPrimaryConnection());
|
||||||
entityToExport.setSyncronizedItemCount(entityToExport.getSyncronizedItemCount() + 1);
|
entityToExport.setSyncronizedItemCount(entityToExport.getSyncronizedItemCount() + 1);
|
||||||
|
|
||||||
final long inExecutionMinues = ChronoUnit.MINUTES.between(entityToExport.getStartDate(),UtilityLocalDate.getNowTime());
|
final long inExecutionMinues = ChronoUnit.MINUTES.between(entityToExport.getStartDate(), UtilityLocalDate.getNowTime());
|
||||||
if(inExecutionMinues > 0)
|
if (inExecutionMinues > 0)
|
||||||
entityToExport.setSyncronizedItemsPerMinute((int) (entityToExport.getSyncronizedItemCount() / inExecutionMinues));
|
entityToExport.setSyncronizedItemsPerMinute((int) (entityToExport.getSyncronizedItemCount() / inExecutionMinues));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public HashMap<Long, HashMap<String, Object>> getStatus() {
|
public List<ExportHistoryStatusDTO> getStatus() {
|
||||||
|
|
||||||
|
List<ExportHistoryStatusDTO> statusList = new ArrayList<>();
|
||||||
|
|
||||||
HashMap<Long, HashMap<String, Object>> total = new HashMap<>();
|
HashMap<Long, HashMap<String, Object>> total = new HashMap<>();
|
||||||
|
|
||||||
for(Long key : currentlyInExecution.keySet()) {
|
for (Long key : currentlyInExecution.keySet()) {
|
||||||
|
|
||||||
for(ExportHistoryItemDTO item : currentlyInExecution.get(key)) {
|
final LocalDateTime startDate = currentlyInExecution.get(key).stream()
|
||||||
|
.map(ExportHistoryItemDTO::getStartDate)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.min(Comparator.naturalOrder())
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
LocalDateTime endDate = item.getStartDate().plusMinutes(item.getTotalItemCount() / item.getSyncronizedItemsPerMinute());
|
long totalCount = 0;
|
||||||
|
long processedCount = 0;
|
||||||
|
long speedPerSec = 0;
|
||||||
|
LocalDateTime estimatedEnd = null;
|
||||||
|
|
||||||
HashMap<String, Object> value = new HashMap<>();
|
if (startDate != null) {
|
||||||
value.put("started_at", CommonConstants.DATETIME_YMD_DASHED_FORMATTER.format(item.getStartDate()));
|
totalCount = currentlyInExecution.get(key).stream()
|
||||||
value.put("enstimated_end", CommonConstants.DATETIME_YMD_DASHED_FORMATTER.format(endDate));
|
.map(ExportHistoryItemDTO::getTotalItemCount)
|
||||||
value.put("speed", item.getSyncronizedItemsPerMinute());
|
.reduce(0L, Long::sum);
|
||||||
value.put("total", item.getTotalItemCount());
|
|
||||||
value.put("processed", item.getSyncronizedItemCount());
|
|
||||||
|
|
||||||
total.put(key, value);
|
processedCount = currentlyInExecution.get(key).stream()
|
||||||
|
.map(ExportHistoryItemDTO::getSyncronizedItemCount)
|
||||||
|
.reduce(0L, Long::sum);
|
||||||
|
|
||||||
|
final long secondsBetween = ChronoUnit.SECONDS.between(startDate, UtilityLocalDate.getNowTime());
|
||||||
|
speedPerSec = processedCount / secondsBetween;
|
||||||
|
|
||||||
|
estimatedEnd = startDate.plusMinutes((totalCount / speedPerSec) / 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statusList.add(new ExportHistoryStatusDTO()
|
||||||
|
.setPublicationGroupId(key)
|
||||||
|
.setStartedAt(startDate)
|
||||||
|
.setTotalCount(totalCount)
|
||||||
|
.setProcessedCount(processedCount)
|
||||||
|
.setSpeedPerMinute(((int) (totalCount / speedPerSec)) * 60)
|
||||||
|
.setEstimatedEnd(estimatedEnd));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
return statusList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ public class MultiDBTransactionManager implements AutoCloseable{
|
|||||||
} else if (enableLog) {
|
} else if (enableLog) {
|
||||||
logger.debug("Closing manually: " + advancedDataSource.getDataSource().getProfile() + " (#" + advancedDataSource.getDataSource().getSessionID() + ")");
|
logger.debug("Closing manually: " + advancedDataSource.getDataSource().getProfile() + " (#" + advancedDataSource.getDataSource().getSessionID() + ")");
|
||||||
}
|
}
|
||||||
|
advancedDataSource.commit();
|
||||||
advancedDataSource.close();
|
advancedDataSource.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ public class RemoteSyncronizationController {
|
|||||||
return ServiceRestResponse.createPositiveResponse();
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "publications/{groupId}/status", method = RequestMethod.GET)
|
@RequestMapping(value = "publications/status", method = RequestMethod.GET)
|
||||||
public ServiceRestResponse statusPublication(@PathVariable long groupId) throws Exception {
|
public ServiceRestResponse statusPublication() {
|
||||||
return ServiceRestResponse.createPositiveResponse(remoteSyncronizationService.getPublicationStatus(groupId));
|
return ServiceRestResponse.createPositiveResponse(remoteSyncronizationService.getPublicationStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package it.integry.ems.sync.dto;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class ExportHistoryStatusDTO {
|
||||||
|
|
||||||
|
private long publicationGroupId;
|
||||||
|
private long processedCount;
|
||||||
|
private long totalCount;
|
||||||
|
private LocalDateTime startedAt;
|
||||||
|
private LocalDateTime estimatedEnd;
|
||||||
|
private int speedPerMinute;
|
||||||
|
|
||||||
|
|
||||||
|
public long getPublicationGroupId() {
|
||||||
|
return publicationGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportHistoryStatusDTO setPublicationGroupId(long publicationGroupId) {
|
||||||
|
this.publicationGroupId = publicationGroupId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getProcessedCount() {
|
||||||
|
return processedCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportHistoryStatusDTO setProcessedCount(long processedCount) {
|
||||||
|
this.processedCount = processedCount;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTotalCount() {
|
||||||
|
return totalCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportHistoryStatusDTO setTotalCount(long totalCount) {
|
||||||
|
this.totalCount = totalCount;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartedAt() {
|
||||||
|
return startedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportHistoryStatusDTO setStartedAt(LocalDateTime startedAt) {
|
||||||
|
this.startedAt = startedAt;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEstimatedEnd() {
|
||||||
|
return estimatedEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportHistoryStatusDTO setEstimatedEnd(LocalDateTime estimatedEnd) {
|
||||||
|
this.estimatedEnd = estimatedEnd;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpeedPerMinute() {
|
||||||
|
return speedPerMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportHistoryStatusDTO setSpeedPerMinute(int speedPerMinute) {
|
||||||
|
this.speedPerMinute = speedPerMinute;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,19 +2,21 @@ package it.integry.ems.sync.service;
|
|||||||
|
|
||||||
import it.integry.ems.sync.AsyncHistoryManager;
|
import it.integry.ems.sync.AsyncHistoryManager;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems.sync.dto.ExportHistoryStatusDTO;
|
||||||
import it.integry.ems.sync.dto.PublicationDTO;
|
import it.integry.ems.sync.dto.PublicationDTO;
|
||||||
import it.integry.ems.utility.UtilityEntity;
|
import it.integry.ems.utility.UtilityEntity;
|
||||||
import it.integry.ems_model.base.EntityBase;
|
import it.integry.ems_model.base.EntityBase;
|
||||||
import it.integry.ems_model.base.EntityPropertyHolder;
|
import it.integry.ems_model.base.EntityPropertyHolder;
|
||||||
import it.integry.ems_model.entity.StbPublicationsDetail;
|
import it.integry.ems_model.entity.StbPublicationsDetail;
|
||||||
import it.integry.ems_model.utility.Query;
|
import it.integry.ems_model.utility.Query;
|
||||||
|
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -47,7 +49,15 @@ public class RemoteSyncronizationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Long, HashMap<String, Object>> getPublicationStatus(long groupId) {
|
public List<ExportHistoryStatusDTO> getPublicationStatus() {
|
||||||
return asyncHistoryManager.getStatus();
|
return Collections.singletonList(new ExportHistoryStatusDTO()
|
||||||
|
.setPublicationGroupId(1)
|
||||||
|
.setProcessedCount(125786)
|
||||||
|
.setTotalCount(150000)
|
||||||
|
.setStartedAt(UtilityLocalDate.getNowTime().minusMinutes(10))
|
||||||
|
.setEstimatedEnd(UtilityLocalDate.getNowTime().plusMinutes(15))
|
||||||
|
.setSpeedPerMinute(500));
|
||||||
|
|
||||||
|
// return asyncHistoryManager.getStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user