Search in sources :

Example 1 with NamespaceLock

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);
}
Also used : NamespaceLock(com.ctrip.framework.apollo.biz.entity.NamespaceLock) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with NamespaceLock

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);
    }
}
Also used : NamespaceLock(com.ctrip.framework.apollo.biz.entity.NamespaceLock) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) ServiceException(com.ctrip.framework.apollo.common.exception.ServiceException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 3 with NamespaceLock

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);
}
Also used : NamespaceLock(com.ctrip.framework.apollo.biz.entity.NamespaceLock)

Example 4 with NamespaceLock

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;
}
Also used : NamespaceLock(com.ctrip.framework.apollo.biz.entity.NamespaceLock)

Aggregations

NamespaceLock (com.ctrip.framework.apollo.biz.entity.NamespaceLock)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)2 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)1 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1