-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into zywang/fix/check-mapper-completed-when-stage…
…-upgrade
- Loading branch information
Showing
9 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../src/main/java/com/consoleconnect/kraken/operator/controller/mapper/SystemInfoMapper.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
4 changes: 2 additions & 2 deletions
4
...rc/main/java/com/consoleconnect/kraken/operator/controller/service/SystemInfoService.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
3 changes: 1 addition & 2 deletions
3
...r/controller/entity/SystemInfoEntity.java → ...perator/core/entity/SystemInfoEntity.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
public enum MgmtEventType { | ||
RESET, | ||
CLIENT_HEART_BEAT, | ||
CLIENT_SYSTEM_INFO, | ||
TEMPLATE_UPGRADE_RESULT; | ||
} |
4 changes: 2 additions & 2 deletions
4
...controller/repo/SystemInfoRepository.java → ...rator/core/repo/SystemInfoRepository.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
34 changes: 34 additions & 0 deletions
34
...c/main/java/com/consoleconnect/kraken/operator/sync/service/PushKrakenVersionService.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,34 @@ | ||
package com.consoleconnect.kraken.operator.sync.service; | ||
|
||
import com.consoleconnect.kraken.operator.core.entity.MgmtEventEntity; | ||
import com.consoleconnect.kraken.operator.core.enums.EventStatusType; | ||
import com.consoleconnect.kraken.operator.core.enums.MgmtEventType; | ||
import com.consoleconnect.kraken.operator.core.repo.MgmtEventRepository; | ||
import com.consoleconnect.kraken.operator.core.repo.SystemInfoRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PushKrakenVersionService { | ||
private static final String KEY = "CONTROL_PLANE"; | ||
private final SystemInfoRepository systemInfoRepository; | ||
private final MgmtEventRepository eventRepository; | ||
|
||
@Scheduled(cron = "${app.cron-job.sync-system-info-from-control-plane:-}") | ||
public void runIt() { | ||
// produce sync kraken info event | ||
systemInfoRepository | ||
.findOneByKey(KEY) | ||
.ifPresent( | ||
systemInfoEntity -> { | ||
MgmtEventEntity entity = new MgmtEventEntity(); | ||
entity.setStatus(EventStatusType.WAIT_TO_SEND.name()); | ||
entity.setPayload(systemInfoEntity); | ||
entity.setResourceId(systemInfoEntity.getId().toString()); | ||
entity.setEventType(MgmtEventType.CLIENT_SYSTEM_INFO.name()); | ||
eventRepository.save(entity); | ||
}); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...st/java/com/consoleconnect/kraken/operator/sync/service/PushKrakenVersionServiceTest.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,54 @@ | ||
package com.consoleconnect.kraken.operator.sync.service; | ||
|
||
import static com.consoleconnect.kraken.operator.core.enums.MgmtEventType.CLIENT_SYSTEM_INFO; | ||
|
||
import com.consoleconnect.kraken.operator.core.entity.MgmtEventEntity; | ||
import com.consoleconnect.kraken.operator.core.entity.SystemInfoEntity; | ||
import com.consoleconnect.kraken.operator.core.enums.EventStatusType; | ||
import com.consoleconnect.kraken.operator.core.repo.MgmtEventRepository; | ||
import com.consoleconnect.kraken.operator.core.repo.SystemInfoRepository; | ||
import com.consoleconnect.kraken.operator.sync.CustomConfig; | ||
import com.consoleconnect.kraken.operator.test.AbstractIntegrationTest; | ||
import com.consoleconnect.kraken.operator.test.MockIntegrationTest; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@MockIntegrationTest | ||
@ContextConfiguration(classes = {CustomConfig.class}) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class PushKrakenVersionServiceTest extends AbstractIntegrationTest { | ||
|
||
@Autowired private PushKrakenVersionService pushKrakenVersionService; | ||
@Autowired private SystemInfoRepository systemInfoRepository; | ||
@Autowired private MgmtEventRepository mgmtEventRepository; | ||
|
||
@Test | ||
void givenSystemInfoEvent_whenRun_thenPushSuccessfully() { | ||
|
||
// given exist event | ||
SystemInfoEntity entity = new SystemInfoEntity(); | ||
entity.setKey("CONTROL_PLANE"); | ||
entity.setControlProductVersion("1.0.0"); | ||
entity.setProductKey("Grace"); | ||
entity.setStageAppVersion("1.0.0"); | ||
entity.setProductionAppVersion("1.0.0"); | ||
systemInfoRepository.save(entity); | ||
// when | ||
pushKrakenVersionService.runIt(); | ||
// then | ||
Page<MgmtEventEntity> eventEntities = | ||
mgmtEventRepository.findByEventTypeInAndStatus( | ||
List.of(CLIENT_SYSTEM_INFO.name()), | ||
EventStatusType.WAIT_TO_SEND.name(), | ||
Pageable.ofSize(1)); | ||
Assertions.assertEquals( | ||
eventEntities.getContent().get(0).getResourceId(), entity.getId().toString()); | ||
} | ||
} |