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;
}
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;
}
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;
}
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");
}
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);
}
Aggregations