Search in sources :

Example 21 with Cluster

use of com.ctrip.framework.apollo.biz.entity.Cluster in project apollo by ctripcorp.

the class AppNamespaceService method createNamespaceForAppNamespaceInAllCluster.

public void createNamespaceForAppNamespaceInAllCluster(String appId, String namespaceName, String createBy) {
    List<Cluster> clusters = clusterService.findParentClusters(appId);
    for (Cluster cluster : clusters) {
        // in case there is some dirty data, e.g. public namespace deleted in other app and now created in this app
        if (!namespaceService.isNamespaceUnique(appId, cluster.getName(), namespaceName)) {
            continue;
        }
        Namespace namespace = new Namespace();
        namespace.setClusterName(cluster.getName());
        namespace.setAppId(appId);
        namespace.setNamespaceName(namespaceName);
        namespace.setDataChangeCreatedBy(createBy);
        namespace.setDataChangeLastModifiedBy(createBy);
        namespaceService.save(namespace);
    }
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 22 with Cluster

use of com.ctrip.framework.apollo.biz.entity.Cluster in project apollo by ctripcorp.

the class ClusterService method saveWithoutInstanceOfAppNamespaces.

@Transactional
public Cluster saveWithoutInstanceOfAppNamespaces(Cluster entity) {
    if (!isClusterNameUnique(entity.getAppId(), entity.getName())) {
        throw new BadRequestException("cluster not unique");
    }
    // protection
    entity.setId(0);
    Cluster cluster = clusterRepository.save(entity);
    auditService.audit(Cluster.class.getSimpleName(), cluster.getId(), Audit.OP.INSERT, cluster.getDataChangeCreatedBy());
    return cluster;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Cluster

use of com.ctrip.framework.apollo.biz.entity.Cluster in project apollo by ctripcorp.

the class ClusterService method delete.

@Transactional
public void delete(long id, String operator) {
    Cluster cluster = clusterRepository.findById(id).orElse(null);
    if (cluster == null) {
        throw new BadRequestException("cluster not exist");
    }
    // delete linked namespaces
    namespaceService.deleteByAppIdAndClusterName(cluster.getAppId(), cluster.getName(), operator);
    cluster.setDeleted(true);
    cluster.setDataChangeLastModifiedBy(operator);
    clusterRepository.save(cluster);
    auditService.audit(Cluster.class.getSimpleName(), id, Audit.OP.DELETE, operator);
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Cluster

use of com.ctrip.framework.apollo.biz.entity.Cluster in project apollo by ctripcorp.

the class ClusterService method createDefaultCluster.

@Transactional
public void createDefaultCluster(String appId, String createBy) {
    if (!isClusterNameUnique(appId, ConfigConsts.CLUSTER_NAME_DEFAULT)) {
        throw new ServiceException("cluster not unique");
    }
    Cluster cluster = new Cluster();
    cluster.setName(ConfigConsts.CLUSTER_NAME_DEFAULT);
    cluster.setAppId(appId);
    cluster.setDataChangeCreatedBy(createBy);
    cluster.setDataChangeLastModifiedBy(createBy);
    clusterRepository.save(cluster);
    auditService.audit(Cluster.class.getSimpleName(), cluster.getId(), Audit.OP.INSERT, createBy);
}
Also used : ServiceException(com.ctrip.framework.apollo.common.exception.ServiceException) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) 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