Commit 75199e3b by lepdou

fix when namespace.lock.switch off

parent 41bfee44
...@@ -7,7 +7,7 @@ import com.ctrip.framework.apollo.biz.entity.NamespaceLock; ...@@ -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.ItemService;
import com.ctrip.framework.apollo.biz.service.NamespaceLockService; import com.ctrip.framework.apollo.biz.service.NamespaceLockService;
import com.ctrip.framework.apollo.biz.service.NamespaceService; 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.ItemChangeSets;
import com.ctrip.framework.apollo.core.dto.ItemDTO; import com.ctrip.framework.apollo.core.dto.ItemDTO;
import com.ctrip.framework.apollo.core.exception.BadRequestException; import com.ctrip.framework.apollo.core.exception.BadRequestException;
...@@ -30,16 +30,15 @@ import org.springframework.stereotype.Component; ...@@ -30,16 +30,15 @@ import org.springframework.stereotype.Component;
public class NamespaceLockAspect { public class NamespaceLockAspect {
private static final Logger logger = LoggerFactory.getLogger(NamespaceLockAspect.class); private static final Logger logger = LoggerFactory.getLogger(NamespaceLockAspect.class);
private static final String NAMESPACE_LOCK_SWITCH_CONFIG_KEY = "namespace.lock.switch";
@Autowired @Autowired
private ServerConfigService serverConfigService;
@Autowired
private NamespaceLockService namespaceLockService; private NamespaceLockService namespaceLockService;
@Autowired @Autowired
private NamespaceService namespaceService; private NamespaceService namespaceService;
@Autowired @Autowired
private ItemService itemService; private ItemService itemService;
@Autowired
private ApolloSwitcher apolloSwitcher;
@Before("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, item, ..)") @Before("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, item, ..)")
...@@ -61,7 +60,7 @@ public class NamespaceLockAspect { ...@@ -61,7 +60,7 @@ public class NamespaceLockAspect {
} }
private void acquireLock(String appId, String clusterName, String namespaceName, String currentUser) { private void acquireLock(String appId, String clusterName, String namespaceName, String currentUser) {
if (isNamespaceLockSwitchOff()) { if (apolloSwitcher.isNamespaceLockSwitchOff()) {
return; return;
} }
...@@ -122,8 +121,6 @@ public class NamespaceLockAspect { ...@@ -122,8 +121,6 @@ public class NamespaceLockAspect {
throw new BadRequestException("namespace:" + namespace.getNamespaceName() + " is modifying by " + lockOwner); 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; ...@@ -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.entity.NamespaceLock;
import com.ctrip.framework.apollo.biz.service.NamespaceLockService; import com.ctrip.framework.apollo.biz.service.NamespaceLockService;
import com.ctrip.framework.apollo.biz.service.NamespaceService; 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.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.dto.NamespaceLockDTO; import com.ctrip.framework.apollo.core.dto.NamespaceLockDTO;
import com.ctrip.framework.apollo.core.exception.BadRequestException; import com.ctrip.framework.apollo.core.exception.BadRequestException;
...@@ -17,23 +18,29 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -17,23 +18,29 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class NamespaceLockController { public class NamespaceLockController {
@Autowired @Autowired
private NamespaceLockService namespaceLockService; private NamespaceLockService namespaceLockService;
@Autowired @Autowired
private NamespaceService namespaceService; private NamespaceService namespaceService;
@Autowired
private ApolloSwitcher apolloSwitcher;
@RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock") @RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathVariable String clusterName, public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathVariable String clusterName,
@PathVariable String namespaceName){ @PathVariable String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName); Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null){ if (namespace == null) {
throw new BadRequestException("namespace not exist."); throw new BadRequestException("namespace not exist.");
} }
if (apolloSwitcher.isNamespaceLockSwitchOff()) {
throw new NotFoundException(namespaceName + " is not locked");
}
NamespaceLock lock = namespaceLockService.findLock(namespace.getId()); NamespaceLock lock = namespaceLockService.findLock(namespace.getId());
if (lock == null){ if (lock == null) {
throw new NotFoundException(namespaceName + " is not locked"); 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 @@ ...@@ -617,8 +617,8 @@
<script type="application/javascript" src="scripts/directive.js"></script> <script type="application/javascript" src="scripts/directive.js"></script>
<!--controller--> <!--controller-->
<script type="application/javascript" src="scripts/controller/app/ConfigNamespaceController.js"></script> <script type="application/javascript" src="scripts/controller/config/ConfigNamespaceController.js"></script>
<script type="application/javascript" src="scripts/controller/app/ConfigBaseInfoController.js"></script> <script type="application/javascript" src="scripts/controller/config/ConfigBaseInfoController.js"></script>
<script type="application/javascript" src="scripts/PageCommon.js"></script> <script type="application/javascript" src="scripts/PageCommon.js"></script>
......
...@@ -209,7 +209,7 @@ ...@@ -209,7 +209,7 @@
<script type="application/javascript" src="../scripts/services/ConfigService.js"></script> <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/services/UserService.js"></script>
<script type="application/javascript" src="../scripts/AppUtils.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/PageCommon.js"></script>
<script type="application/javascript" src="../scripts/directive.js"></script> <script type="application/javascript" src="../scripts/directive.js"></script>
......
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