Search in sources :

Example 16 with Cluster

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

the class NamespaceService method namespacePublishInfo.

public Map<String, Boolean> namespacePublishInfo(String appId) {
    List<Cluster> clusters = clusterService.findParentClusters(appId);
    if (CollectionUtils.isEmpty(clusters)) {
        throw new BadRequestException("app not exist");
    }
    Map<String, Boolean> clusterHasNotPublishedItems = Maps.newHashMap();
    for (Cluster cluster : clusters) {
        String clusterName = cluster.getName();
        List<Namespace> namespaces = findNamespaces(appId, clusterName);
        for (Namespace namespace : namespaces) {
            boolean isNamespaceNotPublished = isNamespaceNotPublished(namespace);
            if (isNamespaceNotPublished) {
                clusterHasNotPublishedItems.put(clusterName, true);
                break;
            }
        }
        clusterHasNotPublishedItems.putIfAbsent(clusterName, false);
    }
    return clusterHasNotPublishedItems;
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 17 with Cluster

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

the class NamespaceService method findParentNamespace.

public Namespace findParentNamespace(Namespace namespace) {
    String appId = namespace.getAppId();
    String namespaceName = namespace.getNamespaceName();
    Cluster cluster = clusterService.findOne(appId, namespace.getClusterName());
    if (cluster != null && cluster.getParentClusterId() > 0) {
        Cluster parentCluster = clusterService.findOne(cluster.getParentClusterId());
        return findOne(appId, parentCluster.getName(), namespaceName);
    }
    return null;
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster)

Example 18 with Cluster

use of com.ctrip.framework.apollo.biz.entity.Cluster 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;
}
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 19 with Cluster

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

the class ClusterControllerTest method testDeleteDefaultFail.

@Test(expected = BadRequestException.class)
public void testDeleteDefaultFail() {
    Cluster cluster = new Cluster();
    cluster.setName(ConfigConsts.CLUSTER_NAME_DEFAULT);
    when(clusterService.findOne(any(String.class), any(String.class))).thenReturn(cluster);
    clusterController.delete("1", "2", "d");
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 20 with Cluster

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

the class ClusterController method delete.

@DeleteMapping("/apps/{appId}/clusters/{clusterName:.+}")
public void delete(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @RequestParam String operator) {
    Cluster entity = clusterService.findOne(appId, clusterName);
    if (entity == null) {
        throw new NotFoundException("cluster not found for clusterName " + clusterName);
    }
    if (ConfigConsts.CLUSTER_NAME_DEFAULT.equals(entity.getName())) {
        throw new BadRequestException("can not delete default cluster!");
    }
    clusterService.delete(entity.getId(), operator);
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

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