Skip to content

Commit

Permalink
Merge branch 'main' into zywang/fix/check-mapper-completed-when-stage…
Browse files Browse the repository at this point in the history
…-upgrade
  • Loading branch information
kuangxiang20240501 authored Nov 12, 2024
2 parents 733c630 + aab5eeb commit 6631789
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.consoleconnect.kraken.operator.controller.mapper;

import com.consoleconnect.kraken.operator.controller.entity.SystemInfoEntity;
import com.consoleconnect.kraken.operator.controller.model.SystemInfo;
import com.consoleconnect.kraken.operator.core.entity.SystemInfoEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.consoleconnect.kraken.operator.controller.service;

import com.consoleconnect.kraken.operator.controller.entity.EnvironmentEntity;
import com.consoleconnect.kraken.operator.controller.entity.SystemInfoEntity;
import com.consoleconnect.kraken.operator.controller.enums.SystemStateEnum;
import com.consoleconnect.kraken.operator.controller.mapper.SystemInfoMapper;
import com.consoleconnect.kraken.operator.controller.model.MgmtProperty;
import com.consoleconnect.kraken.operator.controller.model.SystemInfo;
import com.consoleconnect.kraken.operator.controller.repo.EnvironmentRepository;
import com.consoleconnect.kraken.operator.controller.repo.SystemInfoRepository;
import com.consoleconnect.kraken.operator.core.dto.Tuple2;
import com.consoleconnect.kraken.operator.core.dto.UnifiedAssetDto;
import com.consoleconnect.kraken.operator.core.entity.SystemInfoEntity;
import com.consoleconnect.kraken.operator.core.entity.UnifiedAssetEntity;
import com.consoleconnect.kraken.operator.core.enums.AssetKindEnum;
import com.consoleconnect.kraken.operator.core.enums.EnvNameEnum;
import com.consoleconnect.kraken.operator.core.event.PlatformSettingCompletedEvent;
import com.consoleconnect.kraken.operator.core.exception.KrakenException;
import com.consoleconnect.kraken.operator.core.model.Metadata;
import com.consoleconnect.kraken.operator.core.repo.SystemInfoRepository;
import com.consoleconnect.kraken.operator.core.repo.UnifiedAssetRepository;
import com.consoleconnect.kraken.operator.core.service.UnifiedAssetService;
import com.consoleconnect.kraken.operator.core.toolkit.AssetsConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum ClientEventTypeEnum {
CLIENT_DEPLOYMENT,
CLIENT_SERVER_API,
CLIENT_TEMPLATE_UPGRADE_RESULT,
CLIENT_SYSTEM_INFO,
CLIENT_MAPPER_VERSION
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.consoleconnect.kraken.operator.controller.entity;
package com.consoleconnect.kraken.operator.core.entity;

import com.consoleconnect.kraken.operator.core.entity.AbstractEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum MgmtEventType {
RESET,
CLIENT_HEART_BEAT,
CLIENT_SYSTEM_INFO,
TEMPLATE_UPGRADE_RESULT;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.consoleconnect.kraken.operator.controller.repo;
package com.consoleconnect.kraken.operator.core.repo;

import com.consoleconnect.kraken.operator.controller.entity.SystemInfoEntity;
import com.consoleconnect.kraken.operator.core.entity.SystemInfoEntity;
import java.util.Optional;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public class PushMgmtEventService extends KrakenServerConnector {
}

protected static final List<MgmtEventType> QUERY_EVENT_TYPES =
List.of(MgmtEventType.TEMPLATE_UPGRADE_RESULT, MgmtEventType.CLIENT_HEART_BEAT);
List.of(
MgmtEventType.TEMPLATE_UPGRADE_RESULT,
MgmtEventType.CLIENT_HEART_BEAT,
MgmtEventType.CLIENT_SYSTEM_INFO);

public PushMgmtEventService(
SyncProperty appProperty, WebClient webClient, EventSinkService eventSinkService) {
Expand Down
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());
}
}

0 comments on commit 6631789

Please sign in to comment.