Search in sources :

Example 1 with AppNamespaceDTO

use of com.ctrip.framework.apollo.common.dto.AppNamespaceDTO in project apollo by ctripcorp.

the class CreationListener method onAppNamespaceCreationEvent.

@EventListener
public void onAppNamespaceCreationEvent(AppNamespaceCreationEvent event) {
    AppNamespaceDTO appNamespace = BeanUtils.transform(AppNamespaceDTO.class, event.getAppNamespace());
    List<Env> envs = portalSettings.getActiveEnvs();
    for (Env env : envs) {
        try {
            namespaceAPI.createAppNamespace(env, appNamespace);
        } catch (Throwable e) {
            LOGGER.error("Create appNamespace failed. appId = {}, env = {}", appNamespace.getAppId(), env, e);
            Tracer.logError(String.format("Create appNamespace failed. appId = %s, env = %s", appNamespace.getAppId(), env), e);
        }
    }
}
Also used : AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) Env(com.ctrip.framework.apollo.portal.environment.Env) EventListener(org.springframework.context.event.EventListener)

Example 2 with AppNamespaceDTO

use of com.ctrip.framework.apollo.common.dto.AppNamespaceDTO in project apollo by ctripcorp.

the class NamespaceController method findMissingNamespaceNames.

private Set<String> findMissingNamespaceNames(String appId, String env, String clusterName) {
    List<AppNamespaceDTO> configDbAppNamespaces = namespaceAPI.getAppNamespaces(appId, Env.valueOf(env));
    List<NamespaceDTO> configDbNamespaces = namespaceService.findNamespaces(appId, Env.valueOf(env), clusterName);
    List<AppNamespace> portalDbAppNamespaces = appNamespaceService.findByAppId(appId);
    Set<String> configDbAppNamespaceNames = configDbAppNamespaces.stream().map(AppNamespaceDTO::getName).collect(Collectors.toSet());
    Set<String> configDbNamespaceNames = configDbNamespaces.stream().map(NamespaceDTO::getNamespaceName).collect(Collectors.toSet());
    Set<String> portalDbAllAppNamespaceNames = Sets.newHashSet();
    Set<String> portalDbPrivateAppNamespaceNames = Sets.newHashSet();
    for (AppNamespace appNamespace : portalDbAppNamespaces) {
        portalDbAllAppNamespaceNames.add(appNamespace.getName());
        if (!appNamespace.isPublic()) {
            portalDbPrivateAppNamespaceNames.add(appNamespace.getName());
        }
    }
    // AppNamespaces should be the same
    Set<String> missingAppNamespaceNames = Sets.difference(portalDbAllAppNamespaceNames, configDbAppNamespaceNames);
    // Private namespaces should all exist
    Set<String> missingNamespaceNames = Sets.difference(portalDbPrivateAppNamespaceNames, configDbNamespaceNames);
    return Sets.union(missingAppNamespaceNames, missingNamespaceNames);
}
Also used : AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 3 with AppNamespaceDTO

use of com.ctrip.framework.apollo.common.dto.AppNamespaceDTO in project apollo by ctripcorp.

the class AppNamespaceControllerTest method testCreate.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreate() {
    String appId = "6666";
    String name = "testnamespace";
    String comment = "comment";
    AppNamespaceDTO dto = new AppNamespaceDTO();
    dto.setAppId(appId);
    dto.setName(name);
    dto.setComment(comment);
    dto.setDataChangeCreatedBy("apollo");
    AppNamespaceDTO resultDto = restTemplate.postForEntity(String.format("http://localhost:%d/apps/%s/appnamespaces", port, appId), dto, AppNamespaceDTO.class).getBody();
    Assert.assertEquals(appId, resultDto.getAppId());
    Assert.assertTrue(resultDto.getId() > 0);
    AppNamespace savedAppNs = namespaceRepository.findByAppIdAndName(appId, name);
    Assert.assertNotNull(savedAppNs);
    Assert.assertNotNull(savedAppNs.getDataChangeCreatedTime());
    Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedTime());
    Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedBy());
    Assert.assertNotNull(savedAppNs.getDataChangeCreatedBy());
}
Also used : AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 4 with AppNamespaceDTO

use of com.ctrip.framework.apollo.common.dto.AppNamespaceDTO in project apollo by ctripcorp.

the class DeletionListener method onAppNamespaceDeletionEvent.

@EventListener
public void onAppNamespaceDeletionEvent(AppNamespaceDeletionEvent event) {
    AppNamespaceDTO appNamespace = BeanUtils.transform(AppNamespaceDTO.class, event.getAppNamespace());
    List<Env> envs = portalSettings.getActiveEnvs();
    String appId = appNamespace.getAppId();
    String namespaceName = appNamespace.getName();
    String operator = appNamespace.getDataChangeLastModifiedBy();
    for (Env env : envs) {
        try {
            namespaceAPI.deleteAppNamespace(env, appId, namespaceName, operator);
        } catch (Throwable e) {
            logger.error("Delete appNamespace failed. appId = {}, namespace = {}, env = {}", appId, namespaceName, env, e);
            Tracer.logError(String.format("Delete appNamespace failed. appId = %s, namespace = %s, env = %s", appId, namespaceName, env), e);
        }
    }
}
Also used : AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) Env(com.ctrip.framework.apollo.portal.environment.Env) EventListener(org.springframework.context.event.EventListener)

Aggregations

AppNamespaceDTO (com.ctrip.framework.apollo.common.dto.AppNamespaceDTO)4 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)2 Env (com.ctrip.framework.apollo.portal.environment.Env)2 EventListener (org.springframework.context.event.EventListener)2 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)1 Test (org.junit.Test)1 Sql (org.springframework.test.context.jdbc.Sql)1