Commit 99a2cf04 by Jason Song Committed by GitHub

Merge pull request #290 from lepdou/0620_27

cluster unique check
parents 083ed49b cafa690b
...@@ -127,9 +127,21 @@ public class AdminServiceAPI { ...@@ -127,9 +127,21 @@ public class AdminServiceAPI {
return Arrays.asList(clusterDTOs); 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, 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 { ...@@ -172,9 +184,10 @@ public class AdminServiceAPI {
CommitDTO[] CommitDTO[]
commitDTOs = commitDTOs =
restTemplate.getForObject("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}", restTemplate.getForObject(
CommitDTO[].class, "{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}",
getAdminServiceHost(env), appId, clusterName, namespaceName, page, size); CommitDTO[].class,
getAdminServiceHost(env), appId, clusterName, namespaceName, page, size);
return Arrays.asList(commitDTOs); return Arrays.asList(commitDTOs);
} }
......
...@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.service; ...@@ -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.enums.Env;
import com.ctrip.framework.apollo.core.dto.ClusterDTO; 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 com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -20,6 +21,9 @@ public class ClusterService { ...@@ -20,6 +21,9 @@ public class ClusterService {
} }
public ClusterDTO createCluster(Env env, ClusterDTO cluster){ public ClusterDTO createCluster(Env env, ClusterDTO cluster){
if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())){
throw new BadRequestException(String.format("cluster %s already exists.", cluster.getName()));
}
return clusterAPI.createOrUpdate(env, cluster); return clusterAPI.createOrUpdate(env, cluster);
} }
......
...@@ -24,19 +24,26 @@ cluster_module.controller('ClusterController', ...@@ -24,19 +24,26 @@ cluster_module.controller('ClusterController',
}; };
$scope.create = function () { $scope.create = function () {
var noEnvChecked = true;
$scope.envs.forEach(function (env) { $scope.envs.forEach(function (env) {
ClusterService.create_cluster($scope.appId, env.name, if (env.checked) {
{ noEnvChecked = false;
name: $scope.clusterName, ClusterService.create_cluster($scope.appId, env.name,
appId: $scope.appId {
}).then(function (result) { name: $scope.clusterName,
toastr.success(env.name, "集群创建成功"); appId: $scope.appId
}, function (result) { }).then(function (result) {
toastr.error(AppUtil.errorMsg(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