Commit 2c20c9d8 by lepdou

cluster unique check

parent 22ac5b5c
......@@ -127,9 +127,21 @@ public class AdminServiceAPI {
return Arrays.asList(clusterDTOs);
}
public ClusterDTO createOrUpdate(Env env, ClusterDTO cluster){
public ClusterDTO loadCluster(String appId, Env env, String clusterName) {
return restTemplate.getForObject("{host}/apps/{appId}/clusters/{clusterName}", ClusterDTO.class,
getAdminServiceHost(env), appId, clusterName);
}
public boolean isClusterUnique(String appId, Env env, String clusterName) {
return restTemplate
.getForObject("{host}/apps/{appId}/cluster/{clusterName}/unique", Boolean.class, getAdminServiceHost(env),
appId, clusterName);
}
public ClusterDTO createOrUpdate(Env env, ClusterDTO cluster) {
return restTemplate.postForObject("{host}/apps/{appId}/clusters", cluster, ClusterDTO.class,
getAdminServiceHost(env), cluster.getAppId());
getAdminServiceHost(env), cluster.getAppId());
}
}
......@@ -172,9 +184,10 @@ public class AdminServiceAPI {
CommitDTO[]
commitDTOs =
restTemplate.getForObject("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}",
CommitDTO[].class,
getAdminServiceHost(env), appId, clusterName, namespaceName, page, size);
restTemplate.getForObject(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}",
CommitDTO[].class,
getAdminServiceHost(env), appId, clusterName, namespaceName, page, size);
return Arrays.asList(commitDTOs);
}
......
......@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.service;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.dto.ClusterDTO;
import com.ctrip.framework.apollo.core.exception.BadRequestException;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -20,6 +21,9 @@ public class ClusterService {
}
public ClusterDTO createCluster(Env env, ClusterDTO cluster){
if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())){
throw new BadRequestException(String.format("cluster %s already exist.", cluster.getName()));
}
return clusterAPI.createOrUpdate(env, cluster);
}
......
......@@ -24,19 +24,26 @@ cluster_module.controller('ClusterController',
};
$scope.create = function () {
var noEnvChecked = true;
$scope.envs.forEach(function (env) {
ClusterService.create_cluster($scope.appId, env.name,
{
name: $scope.clusterName,
appId: $scope.appId
}).then(function (result) {
toastr.success(env.name, "集群创建成功");
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "集群创建失败");
})
if (env.checked) {
noEnvChecked = false;
ClusterService.create_cluster($scope.appId, env.name,
{
name: $scope.clusterName,
appId: $scope.appId
}).then(function (result) {
toastr.success(env.name, "集群创建成功");
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "集群创建失败");
})
}
})
if (noEnvChecked){
toastr.warning("请选择环境");
}
};
}]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment