Search in sources :

Example 6 with DatastoreLockTarget

use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget 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)

Example 7 with DatastoreLockTarget

use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget 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 8 with DatastoreLockTarget

use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget 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 9 with DatastoreLockTarget

use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget 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 10 with DatastoreLockTarget

use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget 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)

Aggregations

DatastoreLockTarget (com.b2international.snowowl.core.internal.locks.DatastoreLockTarget)16 DatastoreLockContext (com.b2international.snowowl.core.internal.locks.DatastoreLockContext)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 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1 RevisionBranch (com.b2international.index.revision.RevisionBranch)1 Repository (com.b2international.snowowl.core.Repository)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)1 Locks (com.b2international.snowowl.core.locks.Locks)1 OverridingMethodsMustInvokeSuper (javax.annotation.OverridingMethodsMustInvokeSuper)1