Search in sources :

Example 6 with DatastoreLockContext

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

the class RepositoryRestService method lockGlobal.

@Operation(summary = "Lock all repositories", description = "Places a global lock, which prevents other users from making changes to any of the repositories " + "while a backup is created. The call may block up to the specified timeout to acquire the lock; " + "if timeoutMillis is set to 0, it returns immediately.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Lock successful"), @ApiResponse(responseCode = "409", description = "Conflicting lock already taken"), @ApiResponse(responseCode = "400", description = "Illegal timeout value, or locking-related issue") })
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/lock")
public void lockGlobal(@Parameter(description = "lock timeout in milliseconds") @RequestParam(value = "timeoutMillis", defaultValue = "5000", required = false) final int timeoutMillis) {
    checkValidTimeout(timeoutMillis);
    final DatastoreLockContext context = new DatastoreLockContext(User.SYSTEM.getUsername(), DatastoreLockContextDescriptions.CREATE_BACKUP);
    final DatastoreLockTarget target = DatastoreLockTarget.ALL;
    doLock(timeoutMillis, 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)

Example 7 with DatastoreLockContext

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

the class RepositoryRestService method lockRepository.

@Operation(summary = "Lock single repository", description = "Places a repository-level lock, which prevents other users from making changes to the specified repository. " + "The call may block up to the specified timeout to acquire the lock; if timeoutMillis is set to 0, " + "it returns immediately.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Lock successful"), @ApiResponse(responseCode = "409", description = "Conflicting lock already taken"), @ApiResponse(responseCode = "404", description = "Repository not found"), @ApiResponse(responseCode = "400", description = "Illegal timeout value, or locking-related issue") })
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/{id}/lock")
public void lockRepository(@PathVariable(value = "id") @Parameter(description = "The repository id") final String id, @Parameter(description = "lock timeout in milliseconds") @RequestParam(value = "timeoutMillis", defaultValue = "5000", required = false) final int timeoutMillis) {
    checkValidRepositoryUuid(id);
    checkValidTimeout(timeoutMillis);
    final DatastoreLockContext context = new DatastoreLockContext(User.SYSTEM.getUsername(), DatastoreLockContextDescriptions.CREATE_REPOSITORY_BACKUP, DatastoreLockContextDescriptions.CREATE_BACKUP);
    final DatastoreLockTarget target = new DatastoreLockTarget(id, null);
    doLock(timeoutMillis, 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)

Example 8 with DatastoreLockContext

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

the class VersionCreateRequest method acquireLocks.

private void acquireLocks(ServiceProvider context, String user, Collection<TerminologyResource> codeSystems) {
    this.lockTargetsByContext = HashMultimap.create();
    final DatastoreLockContext lockContext = new DatastoreLockContext(user, CREATE_VERSION);
    for (TerminologyResource codeSystem : codeSystems) {
        final DatastoreLockTarget lockTarget = new DatastoreLockTarget(codeSystem.getToolingId(), codeSystem.getBranchPath());
        context.service(IOperationLockManager.class).lock(lockContext, IOperationLockManager.IMMEDIATE, lockTarget);
        lockTargetsByContext.put(lockContext, lockTarget);
    }
}
Also used : IOperationLockManager(com.b2international.snowowl.core.locks.IOperationLockManager) DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext)

Example 9 with DatastoreLockContext

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

the class DatastoreLockTests method testLockAll.

@Test
public void testLockAll() {
    final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.MAINTENANCE);
    final DatastoreLockTarget allLockTarget = DatastoreLockTarget.ALL;
    manager.lock(context, TIMEOUT, allLockTarget);
    checkIfLockExists(context, true, allLockTarget);
    manager.unlockAll();
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Test(org.junit.Test)

Example 10 with DatastoreLockContext

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

the class DatastoreLockTests method testUnlockAll.

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

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