Commit 1b7a4aa0 by Jason Song Committed by GitHub

Merge pull request #319 from lepdou/bugfix_0711

Bugfix
parents 2aa333d8 5395c802
...@@ -31,6 +31,8 @@ public class AppNamespaceService { ...@@ -31,6 +31,8 @@ public class AppNamespaceService {
private ClusterService clusterService; private ClusterService clusterService;
@Autowired @Autowired
private AuditService auditService; private AuditService auditService;
@Autowired
private ServerConfigService serverConfigService;
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) { public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(appId, "AppId must not be null");
...@@ -80,23 +82,12 @@ public class AppNamespaceService { ...@@ -80,23 +82,12 @@ public class AppNamespaceService {
appNamespace.setDataChangeCreatedBy(createBy); appNamespace.setDataChangeCreatedBy(createBy);
appNamespace.setDataChangeLastModifiedBy(createBy); appNamespace.setDataChangeLastModifiedBy(createBy);
appNamespace = appNamespaceRepository.save(appNamespace); appNamespace = appNamespaceRepository.save(appNamespace);
//所有的cluster下面link新建的appnamespace
if (!appNamespace.isPublic()){
String appId = appNamespace.getAppId();
String namespaceName = appNamespace.getName();
List<Cluster> clusters = clusterService.findClusters(appId);
for (Cluster cluster: clusters){
Namespace namespace = new Namespace();
namespace.setClusterName(cluster.getName());
namespace.setAppId(appId);
namespace.setNamespaceName(namespaceName);
namespace.setDataChangeCreatedBy(createBy);
namespace.setDataChangeLastModifiedBy(createBy);
namespaceService.save(namespace);
}
//// TODO: 16/7/11 上线完删除开关逻辑
if ("true".equals(serverConfigService.getValue("appnamespace.private.enable", "false")) && !appNamespace.isPublic()) {
linkPrivateAppNamespaceInAllCluster(appNamespace.getAppId(), appNamespace.getName(), createBy);
} }
auditService.audit(AppNamespace.class.getSimpleName(), appNamespace.getId(), Audit.OP.INSERT, auditService.audit(AppNamespace.class.getSimpleName(), appNamespace.getId(), Audit.OP.INSERT,
createBy); createBy);
return appNamespace; return appNamespace;
...@@ -111,4 +102,17 @@ public class AppNamespaceService { ...@@ -111,4 +102,17 @@ public class AppNamespaceService {
return managedNs; return managedNs;
} }
private void linkPrivateAppNamespaceInAllCluster(String appId, String namespaceName, String createBy) {
List<Cluster> clusters = clusterService.findClusters(appId);
for (Cluster cluster : clusters) {
Namespace namespace = new Namespace();
namespace.setClusterName(cluster.getName());
namespace.setAppId(appId);
namespace.setNamespaceName(namespaceName);
namespace.setDataChangeCreatedBy(createBy);
namespace.setDataChangeLastModifiedBy(createBy);
namespaceService.save(namespace);
}
}
} }
...@@ -15,6 +15,7 @@ import com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent; ...@@ -15,6 +15,7 @@ import com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent;
import com.ctrip.framework.apollo.portal.service.AppNamespaceService; import com.ctrip.framework.apollo.portal.service.AppNamespaceService;
import com.ctrip.framework.apollo.portal.service.AppService; import com.ctrip.framework.apollo.portal.service.AppService;
import com.ctrip.framework.apollo.portal.service.NamespaceService; import com.ctrip.framework.apollo.portal.service.NamespaceService;
import com.ctrip.framework.apollo.portal.service.RoleInitializationService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -50,6 +51,8 @@ public class NamespaceController { ...@@ -50,6 +51,8 @@ public class NamespaceController {
private NamespaceService namespaceService; private NamespaceService namespaceService;
@Autowired @Autowired
private AppNamespaceService appNamespaceService; private AppNamespaceService appNamespaceService;
@Autowired
private RoleInitializationService roleInitializationService;
@RequestMapping("/appnamespaces/public") @RequestMapping("/appnamespaces/public")
public List<AppNamespace> findPublicAppNamespaces() { public List<AppNamespace> findPublicAppNamespaces() {
...@@ -62,6 +65,7 @@ public class NamespaceController { ...@@ -62,6 +65,7 @@ public class NamespaceController {
@RequestBody List<NamespaceCreationModel> models) { @RequestBody List<NamespaceCreationModel> models) {
checkModel(!CollectionUtils.isEmpty(models)); checkModel(!CollectionUtils.isEmpty(models));
roleInitializationService.initNamespaceRoles(appId, models.get(0).getNamespace().getNamespaceName());
for (NamespaceCreationModel model : models) { for (NamespaceCreationModel model : models) {
NamespaceDTO namespace = model.getNamespace(); NamespaceDTO namespace = model.getNamespace();
......
...@@ -43,8 +43,7 @@ public class NamespaceService { ...@@ -43,8 +43,7 @@ public class NamespaceService {
@Autowired @Autowired
private AdminServiceAPI.NamespaceAPI namespaceAPI; private AdminServiceAPI.NamespaceAPI namespaceAPI;
@Autowired
private RoleInitializationService roleInitializationService;
@Autowired @Autowired
private AppNamespaceService appNamespaceService; private AppNamespaceService appNamespaceService;
...@@ -57,7 +56,6 @@ public class NamespaceService { ...@@ -57,7 +56,6 @@ public class NamespaceService {
namespace.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId()); namespace.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
NamespaceDTO createdNamespace = namespaceAPI.createNamespace(env, namespace); NamespaceDTO createdNamespace = namespaceAPI.createNamespace(env, namespace);
roleInitializationService.initNamespaceRoles(namespace.getAppId(), namespace.getNamespaceName());
return createdNamespace; return createdNamespace;
} }
......
...@@ -144,23 +144,24 @@ application_module.controller("ConfigNamespaceController", ...@@ -144,23 +144,24 @@ application_module.controller("ConfigNamespaceController",
$scope.tableViewOperType = '', $scope.item = {}; $scope.tableViewOperType = '', $scope.item = {};
var toOperationNamespace;
//查看配置 //查看配置
function retrieveItem(namespace, item, oldValue) { function retrieveItem(namespace, item, oldValue) {
switchTableViewOperType(TABLE_VIEW_OPER_TYPE.RETRIEVE); switchTableViewOperType(TABLE_VIEW_OPER_TYPE.RETRIEVE);
$scope.item = item; $scope.item = item;
$scope.item.oldValue = oldValue; $scope.item.oldValue = oldValue;
toOperationNamespaceName = namespace.namespace.namespaceName; toOperationNamespace = namespace;
$scope.hasModifyPermission = namespace.hasModifyPermission; $scope.hasModifyPermission = namespace.hasModifyPermission;
} }
var toDeleteItemId = 0, toDeleteNamespace = {}; var toDeleteItemId = 0;
function preDeleteItem(namespace, itemId) { function preDeleteItem(namespace, itemId) {
if (!lockCheck(namespace)){ if (!lockCheck(namespace)){
return; return;
} }
toDeleteNamespace = namespace; toOperationNamespace = namespace;
toDeleteItemId = itemId; toDeleteItemId = itemId;
$("#deleteConfirmDialog").modal("show"); $("#deleteConfirmDialog").modal("show");
...@@ -170,7 +171,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -170,7 +171,7 @@ application_module.controller("ConfigNamespaceController",
ConfigService.delete_item($rootScope.pageContext.appId, ConfigService.delete_item($rootScope.pageContext.appId,
$rootScope.pageContext.env, $rootScope.pageContext.env,
$rootScope.pageContext.clusterName, $rootScope.pageContext.clusterName,
toDeleteNamespace.namespace.namespaceName, toOperationNamespace.namespace.namespaceName,
toDeleteItemId).then( toDeleteItemId).then(
function (result) { function (result) {
toastr.success("删除成功!"); toastr.success("删除成功!");
...@@ -180,7 +181,6 @@ application_module.controller("ConfigNamespaceController", ...@@ -180,7 +181,6 @@ application_module.controller("ConfigNamespaceController",
}); });
} }
var toOperationNamespaceName = '';
//修改配置 //修改配置
function editItem(namespace, item) { function editItem(namespace, item) {
if (!lockCheck(namespace)){ if (!lockCheck(namespace)){
...@@ -188,7 +188,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -188,7 +188,7 @@ application_module.controller("ConfigNamespaceController",
} }
switchTableViewOperType(TABLE_VIEW_OPER_TYPE.UPDATE); switchTableViewOperType(TABLE_VIEW_OPER_TYPE.UPDATE);
$scope.item = item; $scope.item = item;
toOperationNamespaceName = namespace.namespace.namespaceName; toOperationNamespace = namespace;
$("#itemModal").modal("show"); $("#itemModal").modal("show");
} }
...@@ -201,7 +201,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -201,7 +201,7 @@ application_module.controller("ConfigNamespaceController",
switchTableViewOperType(TABLE_VIEW_OPER_TYPE.CREATE); switchTableViewOperType(TABLE_VIEW_OPER_TYPE.CREATE);
$scope.item = {}; $scope.item = {};
toOperationNamespaceName = namespace.namespace.namespaceName; toOperationNamespace = namespace;
$('#itemModal').modal('show'); $('#itemModal').modal('show');
} }
...@@ -225,11 +225,23 @@ application_module.controller("ConfigNamespaceController", ...@@ -225,11 +225,23 @@ application_module.controller("ConfigNamespaceController",
} }
selectedClusters.forEach(function (cluster) { selectedClusters.forEach(function (cluster) {
if ($scope.tableViewOperType == TABLE_VIEW_OPER_TYPE.CREATE) { if ($scope.tableViewOperType == TABLE_VIEW_OPER_TYPE.CREATE) {
//check key unique
var hasRepeatKey = false;
toOperationNamespace.items.forEach(function (item) {
if ($scope.item.key == item.item.key){
toastr.error("key=" + $scope.item.key + " 已存在");
hasRepeatKey = true;
return;
}
});
if (hasRepeatKey){
return;
}
ConfigService.create_item($rootScope.pageContext.appId, ConfigService.create_item($rootScope.pageContext.appId,
cluster.env, cluster.env,
cluster.name, cluster.name,
toOperationNamespaceName, toOperationNamespace.namespace.namespaceName,
$scope.item).then( $scope.item).then(
function (result) { function (result) {
toastr.success(cluster.env + " , " + $scope.item.key, toastr.success(cluster.env + " , " + $scope.item.key,
...@@ -248,7 +260,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -248,7 +260,7 @@ application_module.controller("ConfigNamespaceController",
ConfigService.update_item($rootScope.pageContext.appId, ConfigService.update_item($rootScope.pageContext.appId,
cluster.env, cluster.env,
cluster.name, cluster.name,
toOperationNamespaceName, toOperationNamespace.namespace.namespaceName,
$scope.item).then( $scope.item).then(
function (result) { function (result) {
toastr.success("更新成功, 如需生效请发布"); toastr.success("更新成功, 如需生效请发布");
......
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