提交 75199e3b 编写于 作者: L lepdou

fix when namespace.lock.switch off

上级 41bfee44
......@@ -7,7 +7,7 @@ import com.ctrip.framework.apollo.biz.entity.NamespaceLock;
import com.ctrip.framework.apollo.biz.service.ItemService;
import com.ctrip.framework.apollo.biz.service.NamespaceLockService;
import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.biz.service.ServerConfigService;
import com.ctrip.framework.apollo.biz.utils.ApolloSwitcher;
import com.ctrip.framework.apollo.core.dto.ItemChangeSets;
import com.ctrip.framework.apollo.core.dto.ItemDTO;
import com.ctrip.framework.apollo.core.exception.BadRequestException;
......@@ -30,16 +30,15 @@ import org.springframework.stereotype.Component;
public class NamespaceLockAspect {
private static final Logger logger = LoggerFactory.getLogger(NamespaceLockAspect.class);
private static final String NAMESPACE_LOCK_SWITCH_CONFIG_KEY = "namespace.lock.switch";
@Autowired
private ServerConfigService serverConfigService;
@Autowired
private NamespaceLockService namespaceLockService;
@Autowired
private NamespaceService namespaceService;
@Autowired
private ItemService itemService;
@Autowired
private ApolloSwitcher apolloSwitcher;
@Before("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, item, ..)")
......@@ -61,7 +60,7 @@ public class NamespaceLockAspect {
}
private void acquireLock(String appId, String clusterName, String namespaceName, String currentUser) {
if (isNamespaceLockSwitchOff()) {
if (apolloSwitcher.isNamespaceLockSwitchOff()) {
return;
}
......@@ -122,8 +121,6 @@ public class NamespaceLockAspect {
throw new BadRequestException("namespace:" + namespace.getNamespaceName() + " is modifying by " + lockOwner);
}
private boolean isNamespaceLockSwitchOff() {
return !"true".equals(serverConfigService.getValue(NAMESPACE_LOCK_SWITCH_CONFIG_KEY, "false"));
}
}
......@@ -4,6 +4,7 @@ import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.entity.NamespaceLock;
import com.ctrip.framework.apollo.biz.service.NamespaceLockService;
import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.biz.utils.ApolloSwitcher;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.dto.NamespaceLockDTO;
import com.ctrip.framework.apollo.core.exception.BadRequestException;
......@@ -17,23 +18,29 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class NamespaceLockController {
@Autowired
private NamespaceLockService namespaceLockService;
@Autowired
private NamespaceService namespaceService;
@Autowired
private ApolloSwitcher apolloSwitcher;
@RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathVariable String clusterName,
@PathVariable String namespaceName){
@PathVariable String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null){
if (namespace == null) {
throw new BadRequestException("namespace not exist.");
}
if (apolloSwitcher.isNamespaceLockSwitchOff()) {
throw new NotFoundException(namespaceName + " is not locked");
}
NamespaceLock lock = namespaceLockService.findLock(namespace.getId());
if (lock == null){
if (lock == null) {
throw new NotFoundException(namespaceName + " is not locked");
}
......
package com.ctrip.framework.apollo.biz.utils;
import com.ctrip.framework.apollo.biz.service.ServerConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ApolloSwitcher {
private static final String NAMESPACE_LOCK_SWITCH_CONFIG_KEY = "namespace.lock.switch";
@Autowired
private ServerConfigService serverConfigService;
public boolean isNamespaceLockSwitchOff() {
return !"true".equals(serverConfigService.getValue(NAMESPACE_LOCK_SWITCH_CONFIG_KEY, "false"));
}
}
......@@ -617,8 +617,8 @@
<script type="application/javascript" src="scripts/directive.js"></script>
<!--controller-->
<script type="application/javascript" src="scripts/controller/app/ConfigNamespaceController.js"></script>
<script type="application/javascript" src="scripts/controller/app/ConfigBaseInfoController.js"></script>
<script type="application/javascript" src="scripts/controller/config/ConfigNamespaceController.js"></script>
<script type="application/javascript" src="scripts/controller/config/ConfigBaseInfoController.js"></script>
<script type="application/javascript" src="scripts/PageCommon.js"></script>
......
......@@ -209,7 +209,7 @@
<script type="application/javascript" src="../scripts/services/ConfigService.js"></script>
<script type="application/javascript" src="../scripts/services/UserService.js"></script>
<script type="application/javascript" src="../scripts/AppUtils.js"></script>
<script type="application/javascript" src="../scripts/controller/app/SyncConfigController.js"></script>
<script type="application/javascript" src="../scripts/controller/config/SyncConfigController.js"></script>
<script type="application/javascript" src="../scripts/PageCommon.js"></script>
<script type="application/javascript" src="../scripts/directive.js"></script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册