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 {
private ClusterService clusterService;
@Autowired
private AuditService auditService;
@Autowired
private ServerConfigService serverConfigService;
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
Objects.requireNonNull(appId, "AppId must not be null");
......@@ -80,23 +82,12 @@ public class AppNamespaceService {
appNamespace.setDataChangeCreatedBy(createBy);
appNamespace.setDataChangeLastModifiedBy(createBy);
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,
createBy);
return appNamespace;
......@@ -111,4 +102,17 @@ public class AppNamespaceService {
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;
import com.ctrip.framework.apollo.portal.service.AppNamespaceService;
import com.ctrip.framework.apollo.portal.service.AppService;
import com.ctrip.framework.apollo.portal.service.NamespaceService;
import com.ctrip.framework.apollo.portal.service.RoleInitializationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -50,6 +51,8 @@ public class NamespaceController {
private NamespaceService namespaceService;
@Autowired
private AppNamespaceService appNamespaceService;
@Autowired
private RoleInitializationService roleInitializationService;
@RequestMapping("/appnamespaces/public")
public List<AppNamespace> findPublicAppNamespaces() {
......@@ -62,6 +65,7 @@ public class NamespaceController {
@RequestBody List<NamespaceCreationModel> models) {
checkModel(!CollectionUtils.isEmpty(models));
roleInitializationService.initNamespaceRoles(appId, models.get(0).getNamespace().getNamespaceName());
for (NamespaceCreationModel model : models) {
NamespaceDTO namespace = model.getNamespace();
......
......@@ -43,8 +43,7 @@ public class NamespaceService {
@Autowired
private AdminServiceAPI.NamespaceAPI namespaceAPI;
@Autowired
private RoleInitializationService roleInitializationService;
@Autowired
private AppNamespaceService appNamespaceService;
......@@ -57,7 +56,6 @@ public class NamespaceService {
namespace.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
NamespaceDTO createdNamespace = namespaceAPI.createNamespace(env, namespace);
roleInitializationService.initNamespaceRoles(namespace.getAppId(), namespace.getNamespaceName());
return createdNamespace;
}
......
......@@ -144,23 +144,24 @@ application_module.controller("ConfigNamespaceController",
$scope.tableViewOperType = '', $scope.item = {};
var toOperationNamespace;
//查看配置
function retrieveItem(namespace, item, oldValue) {
switchTableViewOperType(TABLE_VIEW_OPER_TYPE.RETRIEVE);
$scope.item = item;
$scope.item.oldValue = oldValue;
toOperationNamespaceName = namespace.namespace.namespaceName;
toOperationNamespace = namespace;
$scope.hasModifyPermission = namespace.hasModifyPermission;
}
var toDeleteItemId = 0, toDeleteNamespace = {};
var toDeleteItemId = 0;
function preDeleteItem(namespace, itemId) {
if (!lockCheck(namespace)){
return;
}
toDeleteNamespace = namespace;
toOperationNamespace = namespace;
toDeleteItemId = itemId;
$("#deleteConfirmDialog").modal("show");
......@@ -170,7 +171,7 @@ application_module.controller("ConfigNamespaceController",
ConfigService.delete_item($rootScope.pageContext.appId,
$rootScope.pageContext.env,
$rootScope.pageContext.clusterName,
toDeleteNamespace.namespace.namespaceName,
toOperationNamespace.namespace.namespaceName,
toDeleteItemId).then(
function (result) {
toastr.success("删除成功!");
......@@ -180,7 +181,6 @@ application_module.controller("ConfigNamespaceController",
});
}
var toOperationNamespaceName = '';
//修改配置
function editItem(namespace, item) {
if (!lockCheck(namespace)){
......@@ -188,7 +188,7 @@ application_module.controller("ConfigNamespaceController",
}
switchTableViewOperType(TABLE_VIEW_OPER_TYPE.UPDATE);
$scope.item = item;
toOperationNamespaceName = namespace.namespace.namespaceName;
toOperationNamespace = namespace;
$("#itemModal").modal("show");
}
......@@ -201,7 +201,7 @@ application_module.controller("ConfigNamespaceController",
switchTableViewOperType(TABLE_VIEW_OPER_TYPE.CREATE);
$scope.item = {};
toOperationNamespaceName = namespace.namespace.namespaceName;
toOperationNamespace = namespace;
$('#itemModal').modal('show');
}
......@@ -225,11 +225,23 @@ application_module.controller("ConfigNamespaceController",
}
selectedClusters.forEach(function (cluster) {
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,
cluster.env,
cluster.name,
toOperationNamespaceName,
toOperationNamespace.namespace.namespaceName,
$scope.item).then(
function (result) {
toastr.success(cluster.env + " , " + $scope.item.key,
......@@ -248,7 +260,7 @@ application_module.controller("ConfigNamespaceController",
ConfigService.update_item($rootScope.pageContext.appId,
cluster.env,
cluster.name,
toOperationNamespaceName,
toOperationNamespace.namespace.namespaceName,
$scope.item).then(
function (result) {
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