Search in sources :

Example 1 with Cluster

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());
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) Audit(com.ctrip.framework.apollo.biz.entity.Audit) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Date(java.util.Date) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest)

Example 2 with Cluster

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;
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster)

Example 3 with 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);
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Cluster

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;
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster)

Example 5 with Cluster

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);
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Release(com.ctrip.framework.apollo.biz.entity.Release) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)24 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)10 Transactional (org.springframework.transaction.annotation.Transactional)8 Test (org.junit.Test)7 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)6 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)5 Item (com.ctrip.framework.apollo.biz.entity.Item)4 Release (com.ctrip.framework.apollo.biz.entity.Release)4 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)3 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Audit (com.ctrip.framework.apollo.biz.entity.Audit)1 Commit (com.ctrip.framework.apollo.biz.entity.Commit)1 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)1 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)1 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)1 App (com.ctrip.framework.apollo.common.entity.App)1 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)1 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)1 Date (java.util.Date)1