From 8df9da82cc3f778a6b312ae88b80c3c53e47aed9 Mon Sep 17 00:00:00 2001 From: jaroslawmalekcodete Date: Mon, 2 Dec 2024 09:10:34 +0100 Subject: [PATCH] feat(sdk): kraken-792 - adjust scheduler to use /callback/agent/events endpoint from kraken-mgmt (#249) --- .../operator/core/client/ClientEventTypeEnum.java | 3 ++- .../service/push/PushAPIActivityLogScheduler.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/client/ClientEventTypeEnum.java b/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/client/ClientEventTypeEnum.java index ca1e9a41..a61497bc 100644 --- a/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/client/ClientEventTypeEnum.java +++ b/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/client/ClientEventTypeEnum.java @@ -8,5 +8,6 @@ public enum ClientEventTypeEnum { CLIENT_TEMPLATE_UPGRADE_RESULT, CLIENT_SYSTEM_INFO, CLIENT_MAPPER_VERSION, - CLIENT_APP_VERSION_UPGRADE_RESULT + CLIENT_APP_VERSION_UPGRADE_RESULT, + CLIENT_PUSH_API_ACTIVITY_LOG } diff --git a/kraken-java-sdk/kraken-java-sdk-sync/src/main/java/com/consoleconnect/kraken/operator/sync/service/push/PushAPIActivityLogScheduler.java b/kraken-java-sdk/kraken-java-sdk-sync/src/main/java/com/consoleconnect/kraken/operator/sync/service/push/PushAPIActivityLogScheduler.java index a9f05afa..5cd373e6 100644 --- a/kraken-java-sdk/kraken-java-sdk-sync/src/main/java/com/consoleconnect/kraken/operator/sync/service/push/PushAPIActivityLogScheduler.java +++ b/kraken-java-sdk/kraken-java-sdk-sync/src/main/java/com/consoleconnect/kraken/operator/sync/service/push/PushAPIActivityLogScheduler.java @@ -1,9 +1,11 @@ package com.consoleconnect.kraken.operator.sync.service.push; +import static com.consoleconnect.kraken.operator.core.client.ClientEventTypeEnum.CLIENT_PUSH_API_ACTIVITY_LOG; import static com.consoleconnect.kraken.operator.core.toolkit.JsonToolkit.fromJson; import static com.consoleconnect.kraken.operator.core.toolkit.PagingHelper.toPageNoSubList; import static java.util.Collections.emptyList; +import com.consoleconnect.kraken.operator.core.client.ClientEvent; import com.consoleconnect.kraken.operator.core.dto.ApiActivityLog; import com.consoleconnect.kraken.operator.core.dto.ComposedHttpRequest; import com.consoleconnect.kraken.operator.core.entity.AbstractHttpEntity; @@ -16,6 +18,7 @@ import com.consoleconnect.kraken.operator.core.model.HttpResponse; import com.consoleconnect.kraken.operator.core.repo.ApiActivityLogRepository; import com.consoleconnect.kraken.operator.core.repo.MgmtEventRepository; +import com.consoleconnect.kraken.operator.core.toolkit.AssetsConstants; import com.consoleconnect.kraken.operator.sync.model.SyncProperty; import com.consoleconnect.kraken.operator.sync.service.KrakenServerConnector; import jakarta.persistence.criteria.CriteriaBuilder; @@ -36,6 +39,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Scheduled; @@ -111,7 +115,9 @@ private List pushLogsInBatches( while (true) { var pageable = PageRequest.of( - page, getAppProperty().getControlPlane().getPushActivityLogExternal().getBatchSize()); + page, + getAppProperty().getControlPlane().getPushActivityLogExternal().getBatchSize(), + Sort.by(Sort.Direction.DESC, AssetsConstants.FIELD_CREATE_AT)); var entities = getApiActivityLogRequestIds(logInfo, pageable); var composedLogs = getComposedHttpRequests(entities.get()); if (composedLogs.isEmpty()) { @@ -129,7 +135,9 @@ private List pushLogsInBatches( entities.getNumber(), entities.getSize(), entities.getTotalElements())); - var res = sendLogsToExternalSystem(payload); + var res = + sendLogsToExternalSystem( + ClientEvent.of(CLIENT_ID, CLIENT_PUSH_API_ACTIVITY_LOG, payload)); if (res.getCode() != 200) { throw new KrakenException( 400, "Pushing logs to external system filed with status: " + res.getCode()); @@ -140,7 +148,7 @@ private List pushLogsInBatches( return sent; } - private HttpResponse sendLogsToExternalSystem(PushExternalSystemPayload payload) { + private HttpResponse sendLogsToExternalSystem(ClientEvent payload) { return blockCurl( HttpMethod.POST, UriBuilder::build, payload, new ParameterizedTypeReference<>() {}); }