Skip to content

Commit

Permalink
fix(sdk): improvement on sync kraken version (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyaoPCCW authored and james-tran-3005 committed Nov 20, 2024
1 parent e7b2142 commit 44e9660
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
import com.consoleconnect.kraken.operator.core.repo.MgmtEventRepository;
import com.consoleconnect.kraken.operator.core.repo.SystemInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

@Service
@RequiredArgsConstructor
public class PushKrakenVersionService {
private static final String KEY = "CONTROL_PLANE";
private final SystemInfoRepository systemInfoRepository;
private final MgmtEventRepository eventRepository;
private final MgmtEventRepository mgmtEventRepository;

@Scheduled(cron = "${app.cron-job.sync-system-info-from-control-plane:-}")
public void runIt() {
Expand All @@ -23,12 +27,24 @@ public void runIt() {
.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);
Page<MgmtEventEntity> mgmtEventEntities =
mgmtEventRepository.search(
MgmtEventType.CLIENT_SYSTEM_INFO.name(), null, Pageable.ofSize(1));
if (CollectionUtils.isEmpty(mgmtEventEntities.getContent())) {
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);
} else {
// if sync system info event exists, update state to wait_to_send to re-active the
// event
MgmtEventEntity eventEntity = mgmtEventEntities.getContent().get(0);
eventEntity.setStatus(EventStatusType.WAIT_TO_SEND.name());
eventEntity.setPayload(systemInfoEntity);
eventRepository.save(eventEntity);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void givenSystemInfoEvent_whenRun_thenPushSuccessfully() {
systemInfoRepository.save(entity);
// when
pushKrakenVersionService.runIt();
entity.setStageAppVersion("2.0.0");
systemInfoRepository.save(entity);
pushKrakenVersionService.runIt();
// then
Page<MgmtEventEntity> eventEntities =
mgmtEventRepository.findByEventTypeInAndStatus(
Expand Down

0 comments on commit 44e9660

Please sign in to comment.