use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceService method findChildNamespace.
public Namespace findChildNamespace(String appId, String parentClusterName, String namespaceName) {
List<Namespace> namespaces = findByAppIdAndNamespaceName(appId, namespaceName);
if (CollectionUtils.isEmpty(namespaces) || namespaces.size() == 1) {
return null;
}
List<Cluster> childClusters = clusterService.findChildClusters(appId, parentClusterName);
if (CollectionUtils.isEmpty(childClusters)) {
return null;
}
Set<String> childClusterNames = childClusters.stream().map(Cluster::getName).collect(Collectors.toSet());
// the child namespace is the intersection of the child clusters and child namespaces
for (Namespace namespace : namespaces) {
if (childClusterNames.contains(namespace.getClusterName())) {
return namespace;
}
}
return null;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceService method deleteNamespace.
@Transactional
public Namespace deleteNamespace(Namespace namespace, String operator) {
String appId = namespace.getAppId();
String clusterName = namespace.getClusterName();
String namespaceName = namespace.getNamespaceName();
itemService.batchDelete(namespace.getId(), operator);
commitService.batchDelete(appId, clusterName, namespace.getNamespaceName(), operator);
// histories need them
if (!isChildNamespace(namespace)) {
releaseService.batchDelete(appId, clusterName, namespace.getNamespaceName(), operator);
}
// delete child namespace
Namespace childNamespace = findChildNamespace(namespace);
if (childNamespace != null) {
namespaceBranchService.deleteBranch(appId, clusterName, namespaceName, childNamespace.getClusterName(), NamespaceBranchStatus.DELETED, operator);
// delete child namespace's releases. Notice: delete child namespace will not delete child namespace's releases
releaseService.batchDelete(appId, childNamespace.getClusterName(), namespaceName, operator);
}
releaseHistoryService.batchDelete(appId, clusterName, namespaceName, operator);
instanceService.batchDeleteInstanceConfig(appId, clusterName, namespaceName);
namespaceLockService.unlock(namespace.getId());
namespace.setDeleted(true);
namespace.setDataChangeLastModifiedBy(operator);
auditService.audit(Namespace.class.getSimpleName(), namespace.getId(), Audit.OP.DELETE, operator);
Namespace deleted = namespaceRepository.save(namespace);
// Publish release message to do some clean up in config service, such as updating the cache
messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, clusterName, namespaceName), Topics.APOLLO_RELEASE_TOPIC);
return deleted;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceService method save.
@Transactional
public Namespace save(Namespace entity) {
if (!isNamespaceUnique(entity.getAppId(), entity.getClusterName(), entity.getNamespaceName())) {
throw new ServiceException("namespace not unique");
}
// protection
entity.setId(0);
Namespace namespace = namespaceRepository.save(entity);
auditService.audit(Namespace.class.getSimpleName(), namespace.getId(), Audit.OP.INSERT, namespace.getDataChangeCreatedBy());
return namespace;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceService method instanceOfAppNamespaces.
@Transactional
public void instanceOfAppNamespaces(String appId, String clusterName, String createBy) {
List<AppNamespace> appNamespaces = appNamespaceService.findByAppId(appId);
for (AppNamespace appNamespace : appNamespaces) {
Namespace ns = new Namespace();
ns.setAppId(appId);
ns.setClusterName(clusterName);
ns.setNamespaceName(appNamespace.getName());
ns.setDataChangeCreatedBy(createBy);
ns.setDataChangeLastModifiedBy(createBy);
namespaceRepository.save(ns);
auditService.audit(Namespace.class.getSimpleName(), ns.getId(), Audit.OP.INSERT, createBy);
}
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ConfigFileControllerIntegrationTest method testConfigChanged.
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testConfigChanged() throws Exception {
ResponseEntity<String> response = restTemplate.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class, getHostUrl(), someAppId, someCluster, someNamespace);
String result = response.getBody();
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue(result.contains("k2=v2"));
String someReleaseName = "someReleaseName";
String someReleaseComment = "someReleaseComment";
Namespace namespace = new Namespace();
namespace.setAppId(someAppId);
namespace.setClusterName(someCluster);
namespace.setNamespaceName(someNamespace);
String someOwner = "someOwner";
Map<String, String> newConfigurations = ImmutableMap.of("k1", "v1-changed", "k2", "v2-changed");
buildRelease(someReleaseName, someReleaseComment, namespace, newConfigurations, someOwner);
ResponseEntity<String> anotherResponse = restTemplate.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class, getHostUrl(), someAppId, someCluster, someNamespace);
assertEquals(response.getBody(), anotherResponse.getBody());
List<String> keys = Lists.newArrayList(someAppId, someCluster, someNamespace);
String message = Strings.join(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR, keys.iterator());
sendReleaseMessage(message);
TimeUnit.MILLISECONDS.sleep(500);
ResponseEntity<String> newResponse = restTemplate.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class, getHostUrl(), someAppId, someCluster, someNamespace);
result = newResponse.getBody();
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue(result.contains("k1=v1-changed"));
assertTrue(result.contains("k2=v2-changed"));
}
Aggregations