@Test void testAcquireLock() { SLException exception = assertThrows(SLException.class, this::tryToAcquireLock); assertEquals("Conflicting process \"test-process-id\" found for MTA \"test-mta-id\"", exception.getMessage()); }
public synchronized void acquireLock(String mtaId, String namespace, String spaceId, String processId) { LOGGER.info(format(Messages.ACQUIRING_LOCK, processId, mtaId)); validateNoConflictingOperationsExist(mtaId, namespace, spaceId); Operation currentOperation = getOperationByProcessId(processId); ImmutableOperation.Builder currentOperationWithAcquiredLock = ImmutableOperation.builder() .from(currentOperation) .mtaId(mtaId) .hasAcquiredLock(true); if (StringUtils.isNotEmpty(namespace)) { currentOperationWithAcquiredLock.namespace(namespace); } operationService.update(currentOperation, currentOperationWithAcquiredLock.build()); LOGGER.info(format(Messages.ACQUIRED_LOCK, processId, StepsUtil.getQualifiedMtaId(mtaId, namespace))); }
ProcessConflictPreventer { public synchronized void acquireLock(String mtaId, String namespace, String spaceId, String processId) { LOGGER.info(format(Messages.ACQUIRING_LOCK, processId, mtaId)); validateNoConflictingOperationsExist(mtaId, namespace, spaceId); Operation currentOperation = getOperationByProcessId(processId); ImmutableOperation.Builder currentOperationWithAcquiredLock = ImmutableOperation.builder() .from(currentOperation) .mtaId(mtaId) .hasAcquiredLock(true); if (StringUtils.isNotEmpty(namespace)) { currentOperationWithAcquiredLock.namespace(namespace); } operationService.update(currentOperation, currentOperationWithAcquiredLock.build()); LOGGER.info(format(Messages.ACQUIRED_LOCK, processId, StepsUtil.getQualifiedMtaId(mtaId, namespace))); } }
ProcessConflictPreventer { public synchronized void acquireLock(String mtaId, String namespace, String spaceId, String processId) { LOGGER.info(format(Messages.ACQUIRING_LOCK, processId, mtaId)); validateNoConflictingOperationsExist(mtaId, namespace, spaceId); Operation currentOperation = getOperationByProcessId(processId); ImmutableOperation.Builder currentOperationWithAcquiredLock = ImmutableOperation.builder() .from(currentOperation) .mtaId(mtaId) .hasAcquiredLock(true); if (StringUtils.isNotEmpty(namespace)) { currentOperationWithAcquiredLock.namespace(namespace); } operationService.update(currentOperation, currentOperationWithAcquiredLock.build()); LOGGER.info(format(Messages.ACQUIRED_LOCK, processId, StepsUtil.getQualifiedMtaId(mtaId, namespace))); } ProcessConflictPreventer(OperationService operationService); }
ProcessConflictPreventer { public synchronized void acquireLock(String mtaId, String namespace, String spaceId, String processId) { LOGGER.info(format(Messages.ACQUIRING_LOCK, processId, mtaId)); validateNoConflictingOperationsExist(mtaId, namespace, spaceId); Operation currentOperation = getOperationByProcessId(processId); ImmutableOperation.Builder currentOperationWithAcquiredLock = ImmutableOperation.builder() .from(currentOperation) .mtaId(mtaId) .hasAcquiredLock(true); if (StringUtils.isNotEmpty(namespace)) { currentOperationWithAcquiredLock.namespace(namespace); } operationService.update(currentOperation, currentOperationWithAcquiredLock.build()); LOGGER.info(format(Messages.ACQUIRED_LOCK, processId, StepsUtil.getQualifiedMtaId(mtaId, namespace))); } ProcessConflictPreventer(OperationService operationService); synchronized void acquireLock(String mtaId, String namespace, String spaceId, String processId); void releaseLock(String processInstanceId, Operation.State state); }
ProcessConflictPreventer { public synchronized void acquireLock(String mtaId, String namespace, String spaceId, String processId) { LOGGER.info(format(Messages.ACQUIRING_LOCK, processId, mtaId)); validateNoConflictingOperationsExist(mtaId, namespace, spaceId); Operation currentOperation = getOperationByProcessId(processId); ImmutableOperation.Builder currentOperationWithAcquiredLock = ImmutableOperation.builder() .from(currentOperation) .mtaId(mtaId) .hasAcquiredLock(true); if (StringUtils.isNotEmpty(namespace)) { currentOperationWithAcquiredLock.namespace(namespace); } operationService.update(currentOperation, currentOperationWithAcquiredLock.build()); LOGGER.info(format(Messages.ACQUIRED_LOCK, processId, StepsUtil.getQualifiedMtaId(mtaId, namespace))); } ProcessConflictPreventer(OperationService operationService); synchronized void acquireLock(String mtaId, String namespace, String spaceId, String processId); void releaseLock(String processInstanceId, Operation.State state);  }