Search in sources :

Example 1 with DatastoreLockContext

use of com.b2international.snowowl.core.internal.locks.DatastoreLockContext in project snow-owl by b2ihealthcare.

the class DefaultOperationLockManager method unlock.

@Override
public void unlock(final DatastoreLockContext context, final Iterable<DatastoreLockTarget> targets) throws IllegalArgumentException {
    final Map<DatastoreLockTarget, DatastoreLockContext> notUnlockedTargets = Maps.newHashMap();
    synchronized (syncObject) {
        for (final DatastoreLockTarget targetToUnlock : targets) {
            for (final IOperationLock existingLock : getExistingLocks()) {
                if (existingLock.targetEquals(targetToUnlock) && !canContextUnlock(context, existingLock)) {
                    notUnlockedTargets.put(existingLock.getTarget(), existingLock.getContext());
                }
            }
        }
        if (!notUnlockedTargets.isEmpty()) {
            LOG.warn(buildMessage(RELEASE_FAILED_MESSAGE, context, notUnlockedTargets));
        }
        for (final DatastoreLockTarget targetToUnlock : targets) {
            final IOperationLock existingLock = getOrCreateLock(context, targetToUnlock);
            try {
                existingLock.release(context);
                fireTargetReleased(existingLock.getTarget(), context);
            } finally {
                if (!existingLock.isLocked()) {
                    removeLock(existingLock);
                }
            }
        }
        syncObject.notifyAll();
    }
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext)

Example 2 with DatastoreLockContext

use of com.b2international.snowowl.core.internal.locks.DatastoreLockContext in project snow-owl by b2ihealthcare.

the class DatastoreLockTests method testUnlock.

@Test
public void testUnlock() {
    final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.MAINTENANCE);
    final DatastoreLockTarget target = new DatastoreLockTarget("snomedStore", "MAIN");
    manager.lock(context, TIMEOUT, target);
    checkIfLockExists(context, true, target);
    manager.unlock(context, target);
    checkIfLockExists(context, false, target);
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Test(org.junit.Test)

Example 3 with DatastoreLockContext

use of com.b2international.snowowl.core.internal.locks.DatastoreLockContext in project snow-owl by b2ihealthcare.

the class DatastoreLockTests method testLockBranchAndRepository.

@Test
public void testLockBranchAndRepository() {
    final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.CREATE_VERSION);
    final DatastoreLockTarget target = new DatastoreLockTarget("snomedStore", "MAIN");
    manager.lock(context, 10_000L, target);
    checkIfLockExists(context, true, target);
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Test(org.junit.Test)

Example 4 with DatastoreLockContext

use of com.b2international.snowowl.core.internal.locks.DatastoreLockContext in project snow-owl by b2ihealthcare.

the class DatastoreLockTests method testLockAllNotAbleToLockAnother.

@Test(expected = LockedException.class)
public void testLockAllNotAbleToLockAnother() {
    final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.MAINTENANCE);
    final DatastoreLockTarget allLockTarget = DatastoreLockTarget.ALL;
    manager.lock(context, 1_000L, allLockTarget);
    manager.lock(context, 1_000L, allLockTarget);
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Test(org.junit.Test)

Example 5 with DatastoreLockContext

use of com.b2international.snowowl.core.internal.locks.DatastoreLockContext in project snow-owl by b2ihealthcare.

the class RepositoryRestService method unlockRepository.

@Operation(summary = "Unlock single repository", description = "Releases a previously acquired repository-level lock on the specified repository.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Unlock successful"), @ApiResponse(responseCode = "404", description = "Repository not found"), @ApiResponse(responseCode = "400", description = "Unspecified unlock-related issue") })
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/{id}/unlock")
public void unlockRepository(@Parameter(description = "The repository id") @PathVariable(value = "id") final String repositoryUuid) {
    checkValidRepositoryUuid(repositoryUuid);
    final DatastoreLockContext context = new DatastoreLockContext(User.SYSTEM.getUsername(), DatastoreLockContextDescriptions.CREATE_REPOSITORY_BACKUP, DatastoreLockContextDescriptions.CREATE_BACKUP);
    final DatastoreLockTarget target = new DatastoreLockTarget(repositoryUuid, null);
    doUnlock(context, target);
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

DatastoreLockContext (com.b2international.snowowl.core.internal.locks.DatastoreLockContext)15 DatastoreLockTarget (com.b2international.snowowl.core.internal.locks.DatastoreLockTarget)14 Test (org.junit.Test)5 Operation (io.swagger.v3.oas.annotations.Operation)4 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)4 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)2 IOperationLockManager (com.b2international.snowowl.core.locks.IOperationLockManager)2 CycleDetectedException (com.b2international.commons.exceptions.CycleDetectedException)1 IndexException (com.b2international.index.IndexException)1 Locks (com.b2international.snowowl.core.locks.Locks)1 OverridingMethodsMustInvokeSuper (javax.annotation.OverridingMethodsMustInvokeSuper)1