use of com.ctrip.framework.apollo.biz.entity.NamespaceLock in project apollo by ctripcorp.
the class NamespaceLockController method getNamespaceLockOwner.
@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathVariable String clusterName, @PathVariable String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new BadRequestException("namespace not exist.");
}
if (bizConfig.isNamespaceLockSwitchOff()) {
return null;
}
NamespaceLock lock = namespaceLockService.findLock(namespace.getId());
if (lock == null) {
return null;
}
return BeanUtils.transform(NamespaceLockDTO.class, lock);
}
use of com.ctrip.framework.apollo.biz.entity.NamespaceLock in project apollo by ctripcorp.
the class NamespaceAcquireLockAspect method acquireLock.
private void acquireLock(Namespace namespace, String currentUser) {
if (namespace == null) {
throw new BadRequestException("namespace not exist.");
}
long namespaceId = namespace.getId();
NamespaceLock namespaceLock = namespaceLockService.findLock(namespaceId);
if (namespaceLock == null) {
try {
tryLock(namespaceId, currentUser);
// lock success
} catch (DataIntegrityViolationException e) {
// lock fail
namespaceLock = namespaceLockService.findLock(namespaceId);
checkLock(namespace, namespaceLock, currentUser);
} catch (Exception e) {
logger.error("try lock error", e);
throw e;
}
} else {
// check lock owner is current user
checkLock(namespace, namespaceLock, currentUser);
}
}
use of com.ctrip.framework.apollo.biz.entity.NamespaceLock in project apollo by ctripcorp.
the class NamespaceAcquireLockAspect method tryLock.
private void tryLock(long namespaceId, String user) {
NamespaceLock lock = new NamespaceLock();
lock.setNamespaceId(namespaceId);
lock.setDataChangeCreatedBy(user);
lock.setDataChangeLastModifiedBy(user);
namespaceLockService.tryLock(lock);
}
use of com.ctrip.framework.apollo.biz.entity.NamespaceLock in project apollo by ctripcorp.
the class NamespaceLockTest method mockNamespaceLock.
private NamespaceLock mockNamespaceLock(String locedUser) {
NamespaceLock lock = new NamespaceLock();
lock.setNamespaceId(NAMESPACE_ID);
lock.setDataChangeCreatedBy(locedUser);
return lock;
}
Aggregations