use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ReleaseKeyGeneratorTest method testGenerateReleaseKey.
@Test
public void testGenerateReleaseKey() throws Exception {
String someAppId = "someAppId";
String someCluster = "someCluster";
String someNamespace = "someNamespace";
String anotherAppId = "anotherAppId";
Namespace namespace = MockBeanFactory.mockNamespace(someAppId, someCluster, someNamespace);
Namespace anotherNamespace = MockBeanFactory.mockNamespace(anotherAppId, someCluster, someNamespace);
int generateTimes = 50000;
Set<String> releaseKeys = Sets.newConcurrentHashSet();
ExecutorService executorService = Executors.newFixedThreadPool(2);
CountDownLatch latch = new CountDownLatch(1);
executorService.submit(generateReleaseKeysTask(namespace, releaseKeys, generateTimes, latch));
executorService.submit(generateReleaseKeysTask(anotherNamespace, releaseKeys, generateTimes, latch));
latch.countDown();
executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.SECONDS);
// make sure keys are unique
assertEquals(generateTimes * 2, releaseKeys.size());
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceBranchService method createBranch.
@Transactional
public Namespace createBranch(String appId, String parentClusterName, String namespaceName, String operator) {
Namespace childNamespace = findBranch(appId, parentClusterName, namespaceName);
if (childNamespace != null) {
throw new BadRequestException("namespace already has branch");
}
Cluster parentCluster = clusterService.findOne(appId, parentClusterName);
if (parentCluster == null || parentCluster.getParentClusterId() != 0) {
throw new BadRequestException("cluster not exist or illegal cluster");
}
// create child cluster
Cluster childCluster = createChildCluster(appId, parentCluster, namespaceName, operator);
Cluster createdChildCluster = clusterService.saveWithoutInstanceOfAppNamespaces(childCluster);
// create child namespace
childNamespace = createNamespaceBranch(appId, createdChildCluster.getName(), namespaceName, operator);
return namespaceService.save(childNamespace);
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceBranchService method createNamespaceBranch.
private Namespace createNamespaceBranch(String appId, String clusterName, String namespaceName, String operator) {
Namespace childNamespace = new Namespace();
childNamespace.setAppId(appId);
childNamespace.setClusterName(clusterName);
childNamespace.setNamespaceName(namespaceName);
childNamespace.setDataChangeLastModifiedBy(operator);
childNamespace.setDataChangeCreatedBy(operator);
return childNamespace;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class AppNamespaceService method deleteAppNamespace.
@Transactional
public void deleteAppNamespace(AppNamespace appNamespace, String operator) {
String appId = appNamespace.getAppId();
String namespaceName = appNamespace.getName();
logger.info("{} is deleting AppNamespace, appId: {}, namespace: {}", operator, appId, namespaceName);
// 1. delete namespaces
List<Namespace> namespaces = namespaceService.findByAppIdAndNamespaceName(appId, namespaceName);
if (namespaces != null) {
for (Namespace namespace : namespaces) {
namespaceService.deleteNamespace(namespace, operator);
}
}
// 2. delete app namespace
appNamespaceRepository.delete(appId, namespaceName, operator);
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceService method findPublicNamespaceForAssociatedNamespace.
public Namespace findPublicNamespaceForAssociatedNamespace(String clusterName, String namespaceName) {
AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName);
if (appNamespace == null) {
throw new BadRequestException("namespace not exist");
}
String appId = appNamespace.getAppId();
Namespace namespace = findOne(appId, clusterName, namespaceName);
// default cluster's namespace
if (Objects.equals(clusterName, ConfigConsts.CLUSTER_NAME_DEFAULT)) {
return namespace;
}
// return default cluster's namespace
if (namespace == null) {
return findOne(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName);
}
// custom cluster's namespace exist and has published.
// return custom cluster's namespace
Release latestActiveRelease = releaseService.findLatestActiveRelease(namespace);
if (latestActiveRelease != null) {
return namespace;
}
Namespace defaultNamespace = findOne(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName);
// return custom cluster's namespace
if (defaultNamespace == null) {
return namespace;
}
// custom cluster's namespace exist but never published.
// and default cluster's namespace exist and has published.
// return default cluster's namespace
Release defaultNamespaceLatestActiveRelease = releaseService.findLatestActiveRelease(defaultNamespace);
if (defaultNamespaceLatestActiveRelease != null) {
return defaultNamespace;
}
// return custom cluster's namespace
return namespace;
}
Aggregations