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);
}
}
}
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);
}
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());
}
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);
}
}
}
Aggregations