use of com.ctrip.framework.apollo.common.dto.ReleaseDTO in project apollo by ctripcorp.
the class ReleaseHistoryService method findLatestByPreviousReleaseIdAndOperation.
public ReleaseHistoryBO findLatestByPreviousReleaseIdAndOperation(Env env, long previousReleaseId, int operation) {
PageDTO<ReleaseHistoryDTO> pageDTO = releaseHistoryAPI.findByPreviousReleaseIdAndOperation(env, previousReleaseId, operation, 0, 1);
if (pageDTO != null && pageDTO.hasContent()) {
ReleaseHistoryDTO releaseHistory = pageDTO.getContent().get(0);
ReleaseDTO release = releaseService.findReleaseById(env, releaseHistory.getReleaseId());
return transformReleaseHistoryDTO2BO(releaseHistory, release);
}
return null;
}
use of com.ctrip.framework.apollo.common.dto.ReleaseDTO in project apollo by ctripcorp.
the class ReleaseHistoryService method transformReleaseHistoryDTO2BO.
private List<ReleaseHistoryBO> transformReleaseHistoryDTO2BO(List<ReleaseHistoryDTO> source, List<ReleaseDTO> releases) {
Map<Long, ReleaseDTO> releasesMap = BeanUtils.mapByKey("id", releases);
List<ReleaseHistoryBO> bos = new ArrayList<>(source.size());
for (ReleaseHistoryDTO dto : source) {
ReleaseDTO release = releasesMap.get(dto.getReleaseId());
bos.add(transformReleaseHistoryDTO2BO(dto, release));
}
return bos;
}
use of com.ctrip.framework.apollo.common.dto.ReleaseDTO in project apollo by ctripcorp.
the class ReleaseService method compare.
public ReleaseCompareResult compare(Env env, long baseReleaseId, long toCompareReleaseId) {
ReleaseDTO baseRelease = null;
ReleaseDTO toCompareRelease = null;
if (baseReleaseId != 0) {
baseRelease = releaseAPI.loadRelease(env, baseReleaseId);
}
if (toCompareReleaseId != 0) {
toCompareRelease = releaseAPI.loadRelease(env, toCompareReleaseId);
}
return compare(baseRelease, toCompareRelease);
}
use of com.ctrip.framework.apollo.common.dto.ReleaseDTO in project apollo by ctripcorp.
the class ReleaseService method findAllReleases.
public List<ReleaseBO> findAllReleases(String appId, Env env, String clusterName, String namespaceName, int page, int size) {
List<ReleaseDTO> releaseDTOs = releaseAPI.findAllReleases(appId, env, clusterName, namespaceName, page, size);
if (CollectionUtils.isEmpty(releaseDTOs)) {
return Collections.emptyList();
}
List<ReleaseBO> releases = new LinkedList<>();
for (ReleaseDTO releaseDTO : releaseDTOs) {
ReleaseBO release = new ReleaseBO();
release.setBaseInfo(releaseDTO);
Set<KVEntity> kvEntities = new LinkedHashSet<>();
Map<String, String> configurations = gson.fromJson(releaseDTO.getConfigurations(), GsonType.CONFIG);
Set<Map.Entry<String, String>> entries = configurations.entrySet();
for (Map.Entry<String, String> entry : entries) {
kvEntities.add(new KVEntity(entry.getKey(), entry.getValue()));
}
release.setItems(kvEntities);
// 为了减少数据量
releaseDTO.setConfigurations("");
releases.add(release);
}
return releases;
}
use of com.ctrip.framework.apollo.common.dto.ReleaseDTO in project apollo by ctripcorp.
the class NamespaceServiceTest method testFindNamespace.
@Test
public void testFindNamespace() {
AppNamespace applicationAppNamespace = mock(AppNamespace.class);
AppNamespace hermesAppNamespace = mock(AppNamespace.class);
NamespaceDTO application = new NamespaceDTO();
application.setId(1);
application.setClusterName(testClusterName);
application.setAppId(testAppId);
application.setNamespaceName(testNamespaceName);
NamespaceDTO hermes = new NamespaceDTO();
hermes.setId(2);
hermes.setClusterName("default");
hermes.setAppId(testAppId);
hermes.setNamespaceName("hermes");
List<NamespaceDTO> namespaces = Arrays.asList(application, hermes);
ReleaseDTO someRelease = new ReleaseDTO();
someRelease.setConfigurations("{\"a\":\"123\",\"b\":\"123\"}");
ItemDTO i1 = new ItemDTO("a", "123", "", 1);
ItemDTO i2 = new ItemDTO("b", "1", "", 2);
ItemDTO i3 = new ItemDTO("", "", "#dddd", 3);
ItemDTO i4 = new ItemDTO("c", "1", "", 4);
List<ItemDTO> someItems = Arrays.asList(i1, i2, i3, i4);
when(applicationAppNamespace.getFormat()).thenReturn(ConfigFileFormat.Properties.getValue());
when(hermesAppNamespace.getFormat()).thenReturn(ConfigFileFormat.XML.getValue());
when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(applicationAppNamespace);
when(appNamespaceService.findPublicAppNamespace("hermes")).thenReturn(hermesAppNamespace);
when(namespaceAPI.findNamespaceByCluster(testAppId, Env.DEV, testClusterName)).thenReturn(namespaces);
when(releaseService.loadLatestRelease(testAppId, Env.DEV, testClusterName, testNamespaceName)).thenReturn(someRelease);
when(releaseService.loadLatestRelease(testAppId, Env.DEV, testClusterName, "hermes")).thenReturn(someRelease);
when(itemService.findItems(testAppId, Env.DEV, testClusterName, testNamespaceName)).thenReturn(someItems);
List<NamespaceBO> namespaceVOs = namespaceService.findNamespaceBOs(testAppId, Env.DEV, testClusterName);
assertEquals(2, namespaceVOs.size());
NamespaceBO namespaceVO = namespaceVOs.get(0);
assertEquals(4, namespaceVO.getItems().size());
assertEquals("a", namespaceVO.getItems().get(0).getItem().getKey());
assertEquals(2, namespaceVO.getItemModifiedCnt());
assertEquals(testAppId, namespaceVO.getBaseInfo().getAppId());
assertEquals(testClusterName, namespaceVO.getBaseInfo().getClusterName());
assertEquals(testNamespaceName, namespaceVO.getBaseInfo().getNamespaceName());
}
Aggregations