Search in sources :

Example 6 with ReleaseDTO

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;
}
Also used : ReleaseHistoryDTO(com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO)

Example 7 with ReleaseDTO

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;
}
Also used : ReleaseHistoryDTO(com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO) ReleaseHistoryBO(com.ctrip.framework.apollo.portal.entity.bo.ReleaseHistoryBO) ArrayList(java.util.ArrayList) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO)

Example 8 with ReleaseDTO

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);
}
Also used : ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO)

Example 9 with ReleaseDTO

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LinkedList(java.util.LinkedList) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) KVEntity(com.ctrip.framework.apollo.portal.entity.bo.KVEntity) ReleaseBO(com.ctrip.framework.apollo.portal.entity.bo.ReleaseBO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with ReleaseDTO

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());
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) NamespaceBO(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Aggregations

ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ReleaseHistoryDTO (com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO)4 ConfigPublishEvent (com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent)4 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)3 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)2 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Instance (com.ctrip.framework.apollo.biz.entity.Instance)1 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)1 Release (com.ctrip.framework.apollo.biz.entity.Release)1 InstanceService (com.ctrip.framework.apollo.biz.service.InstanceService)1 ReleaseService (com.ctrip.framework.apollo.biz.service.ReleaseService)1 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)1 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)1 InstanceConfigDTO (com.ctrip.framework.apollo.common.dto.InstanceConfigDTO)1 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)1