use of com.ctrip.framework.apollo.biz.entity.Cluster in project apollo by ctripcorp.
the class AdminServiceTest method testCreateNewApp.
@Test
public void testCreateNewApp() {
String appId = "someAppId";
App app = new App();
app.setAppId(appId);
app.setName("someAppName");
String owner = "someOwnerName";
app.setOwnerName(owner);
app.setOwnerEmail("someOwnerName@ctrip.com");
app.setDataChangeCreatedBy(owner);
app.setDataChangeLastModifiedBy(owner);
app.setDataChangeCreatedTime(new Date());
app = adminService.createNewApp(app);
Assert.assertEquals(appId, app.getAppId());
List<Cluster> clusters = clusterService.findParentClusters(app.getAppId());
Assert.assertEquals(1, clusters.size());
Assert.assertEquals(ConfigConsts.CLUSTER_NAME_DEFAULT, clusters.get(0).getName());
List<Namespace> namespaces = namespaceService.findNamespaces(appId, clusters.get(0).getName());
Assert.assertEquals(1, namespaces.size());
Assert.assertEquals(ConfigConsts.NAMESPACE_APPLICATION, namespaces.get(0).getNamespaceName());
List<Audit> audits = auditService.findByOwner(owner);
Assert.assertEquals(4, audits.size());
}
use of com.ctrip.framework.apollo.biz.entity.Cluster in project apollo by ctripcorp.
the class NamespacePublishInfoTest method createCluster.
private Cluster createCluster(String clusterName) {
Cluster cluster = new Cluster();
cluster.setAppId(testApp);
cluster.setName(clusterName);
cluster.setParentClusterId(0);
return cluster;
}
use of com.ctrip.framework.apollo.biz.entity.Cluster 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.Cluster in project apollo by ctripcorp.
the class NamespaceBranchService method createChildCluster.
private Cluster createChildCluster(String appId, Cluster parentCluster, String namespaceName, String operator) {
Cluster childCluster = new Cluster();
childCluster.setAppId(appId);
childCluster.setParentClusterId(parentCluster.getId());
childCluster.setName(UniqueKeyGenerator.generate(appId, parentCluster.getName(), namespaceName));
childCluster.setDataChangeCreatedBy(operator);
childCluster.setDataChangeLastModifiedBy(operator);
return childCluster;
}
use of com.ctrip.framework.apollo.biz.entity.Cluster in project apollo by ctripcorp.
the class NamespaceBranchService method deleteBranch.
@Transactional
public void deleteBranch(String appId, String clusterName, String namespaceName, String branchName, int branchStatus, String operator) {
Cluster toDeleteCluster = clusterService.findOne(appId, branchName);
if (toDeleteCluster == null) {
return;
}
Release latestBranchRelease = releaseService.findLatestActiveRelease(appId, branchName, namespaceName);
long latestBranchReleaseId = latestBranchRelease != null ? latestBranchRelease.getId() : 0;
// update branch rules
GrayReleaseRule deleteRule = new GrayReleaseRule();
deleteRule.setRules("[]");
deleteRule.setAppId(appId);
deleteRule.setClusterName(clusterName);
deleteRule.setNamespaceName(namespaceName);
deleteRule.setBranchName(branchName);
deleteRule.setBranchStatus(branchStatus);
deleteRule.setDataChangeLastModifiedBy(operator);
deleteRule.setDataChangeCreatedBy(operator);
doUpdateBranchGrayRules(appId, clusterName, namespaceName, branchName, deleteRule, false, -1);
// delete branch cluster
clusterService.delete(toDeleteCluster.getId(), operator);
int releaseOperation = branchStatus == NamespaceBranchStatus.MERGED ? ReleaseOperation.GRAY_RELEASE_DELETED_AFTER_MERGE : ReleaseOperation.ABANDON_GRAY_RELEASE;
releaseHistoryService.createReleaseHistory(appId, clusterName, namespaceName, branchName, latestBranchReleaseId, latestBranchReleaseId, releaseOperation, null, operator);
auditService.audit("Branch", toDeleteCluster.getId(), Audit.OP.DELETE, operator);
}
Aggregations