Search in sources :

Example 6 with NamespaceBO

use of com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO in project apollo by ctripcorp.

the class ConfigsExportService method exportNamespaces.

private void exportNamespaces(final Env env, final App exportApp, final ClusterDTO exportCluster, ZipOutputStream zipOutputStream) {
    String clusterName = exportCluster.getName();
    List<NamespaceBO> namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName);
    if (CollectionUtils.isEmpty(namespaceBOS)) {
        return;
    }
    Stream<ConfigBO> configBOStream = namespaceBOS.stream().map(namespaceBO -> new ConfigBO(env, exportApp.getOwnerName(), exportApp.getAppId(), clusterName, namespaceBO));
    writeNamespacesToZip(configBOStream, zipOutputStream);
}
Also used : NamespaceBO(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO) ConfigBO(com.ctrip.framework.apollo.portal.entity.bo.ConfigBO)

Example 7 with NamespaceBO

use of com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO 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)

Example 8 with NamespaceBO

use of com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO in project apollo by ctripcorp.

the class ConfigsExportServiceTest method genNamespace.

private NamespaceBO genNamespace(App app, ClusterDTO clusterDTO, List<ItemBO> itemBOS, String namespaceName) {
    NamespaceBO namespaceBO = new NamespaceBO();
    NamespaceDTO baseInfo = new NamespaceDTO();
    baseInfo.setNamespaceName(namespaceName);
    baseInfo.setAppId(app.getAppId());
    baseInfo.setClusterName(clusterDTO.getName());
    namespaceBO.setBaseInfo(baseInfo);
    namespaceBO.setFormat(ConfigFileFormat.Properties.getValue());
    namespaceBO.setItems(itemBOS);
    return namespaceBO;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) NamespaceBO(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)

Aggregations

NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)8 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)3 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)3 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)2 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)2 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)2 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)2 ItemBO (com.ctrip.framework.apollo.portal.entity.bo.ItemBO)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)1 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)1 App (com.ctrip.framework.apollo.common.entity.App)1 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)1 BaseDtoUserInfoEnrichedAdapter (com.ctrip.framework.apollo.portal.enricher.adapter.BaseDtoUserInfoEnrichedAdapter)1 ConfigBO (com.ctrip.framework.apollo.portal.entity.bo.ConfigBO)1 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)1 Env (com.ctrip.framework.apollo.portal.environment.Env)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1