@Test public void execute_GivenConcurrentProcessFoundThenExpectKO() throws Exception { ProcessDetail concurrentProcessDetail = new ProcessDetail(); concurrentProcessDetail.setOperationId("SomeOtherProcessId"); concurrentProcessDetail.setGlobalState("PAUSE"); concurrentProcessDetail.setStepStatus("FATAL"); doReturn(Collections.singletonList(concurrentProcessDetail)).when(lightweightWorkflowLock) .listConcurrentWorkflows( eq(Arrays.asList(Contexts.RECLASSIFICATION.getEventType(), Contexts.ELIMINATION_ACTION.getEventType())), eq(VitamThreadUtils.getVitamSession().getRequestId())); doReturn("RECLASSIFICATION,ELIMINATION_ACTION").when(handlerIO).getInput(0); ItemStatus itemStatus = checkConcurrentWorkflowLockHandler.execute(parameters, handlerIO); assertThat(itemStatus.getGlobalStatus()).isEqualTo(StatusCode.KO); assertThat( JsonHandler.getFromString(itemStatus.getEvDetailData(), ReclassificationEventDetails.class).getError()) .isEqualTo(CONCURRENT_PROCESSES_FOUND); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String workflowIdsStr = (String) handler.getInput(WORKFLOW_IDS_RANK); List<String> workflowIds = Arrays.stream(workflowIdsStr.split(",")) .map(String::trim) .collect(Collectors.toList()); List<ProcessDetail> concurrentWorkflows = lightweightWorkflowLock .listConcurrentWorkflows(workflowIds, param.getContainerName()); if (!concurrentWorkflows.isEmpty()) { LOGGER.error("Concurrent process(es) found " + concurrentWorkflows.stream().map( i -> i.getProcessType() + " " + i.getOperationId() + "(" + i.getGlobalState() + "/" + i.getStepStatus() + ")") .collect(Collectors.joining(", ", "[", "]"))); ObjectNode eventDetails = JsonHandler.createObjectNode(); eventDetails.put("error", CONCURRENT_PROCESSES_FOUND); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.KO, eventDetails); } } catch (VitamClientException e) { LOGGER.error("Concurrent workflow lock check failed", e); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.FATAL, null); } LOGGER.info("Concurrent workflow lock check succeeded"); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.OK, null); }
CheckConcurrentWorkflowLockHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String workflowIdsStr = (String) handler.getInput(WORKFLOW_IDS_RANK); List<String> workflowIds = Arrays.stream(workflowIdsStr.split(",")) .map(String::trim) .collect(Collectors.toList()); List<ProcessDetail> concurrentWorkflows = lightweightWorkflowLock .listConcurrentWorkflows(workflowIds, param.getContainerName()); if (!concurrentWorkflows.isEmpty()) { LOGGER.error("Concurrent process(es) found " + concurrentWorkflows.stream().map( i -> i.getProcessType() + " " + i.getOperationId() + "(" + i.getGlobalState() + "/" + i.getStepStatus() + ")") .collect(Collectors.joining(", ", "[", "]"))); ObjectNode eventDetails = JsonHandler.createObjectNode(); eventDetails.put("error", CONCURRENT_PROCESSES_FOUND); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.KO, eventDetails); } } catch (VitamClientException e) { LOGGER.error("Concurrent workflow lock check failed", e); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.FATAL, null); } LOGGER.info("Concurrent workflow lock check succeeded"); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.OK, null); } }
CheckConcurrentWorkflowLockHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String workflowIdsStr = (String) handler.getInput(WORKFLOW_IDS_RANK); List<String> workflowIds = Arrays.stream(workflowIdsStr.split(",")) .map(String::trim) .collect(Collectors.toList()); List<ProcessDetail> concurrentWorkflows = lightweightWorkflowLock .listConcurrentWorkflows(workflowIds, param.getContainerName()); if (!concurrentWorkflows.isEmpty()) { LOGGER.error("Concurrent process(es) found " + concurrentWorkflows.stream().map( i -> i.getProcessType() + " " + i.getOperationId() + "(" + i.getGlobalState() + "/" + i.getStepStatus() + ")") .collect(Collectors.joining(", ", "[", "]"))); ObjectNode eventDetails = JsonHandler.createObjectNode(); eventDetails.put("error", CONCURRENT_PROCESSES_FOUND); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.KO, eventDetails); } } catch (VitamClientException e) { LOGGER.error("Concurrent workflow lock check failed", e); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.FATAL, null); } LOGGER.info("Concurrent workflow lock check succeeded"); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.OK, null); } CheckConcurrentWorkflowLockHandler(); @VisibleForTesting  CheckConcurrentWorkflowLockHandler(LightweightWorkflowLock lightweightWorkflowLock); }
CheckConcurrentWorkflowLockHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String workflowIdsStr = (String) handler.getInput(WORKFLOW_IDS_RANK); List<String> workflowIds = Arrays.stream(workflowIdsStr.split(",")) .map(String::trim) .collect(Collectors.toList()); List<ProcessDetail> concurrentWorkflows = lightweightWorkflowLock .listConcurrentWorkflows(workflowIds, param.getContainerName()); if (!concurrentWorkflows.isEmpty()) { LOGGER.error("Concurrent process(es) found " + concurrentWorkflows.stream().map( i -> i.getProcessType() + " " + i.getOperationId() + "(" + i.getGlobalState() + "/" + i.getStepStatus() + ")") .collect(Collectors.joining(", ", "[", "]"))); ObjectNode eventDetails = JsonHandler.createObjectNode(); eventDetails.put("error", CONCURRENT_PROCESSES_FOUND); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.KO, eventDetails); } } catch (VitamClientException e) { LOGGER.error("Concurrent workflow lock check failed", e); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.FATAL, null); } LOGGER.info("Concurrent workflow lock check succeeded"); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.OK, null); } CheckConcurrentWorkflowLockHandler(); @VisibleForTesting  CheckConcurrentWorkflowLockHandler(LightweightWorkflowLock lightweightWorkflowLock); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); static String getId(); }
CheckConcurrentWorkflowLockHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String workflowIdsStr = (String) handler.getInput(WORKFLOW_IDS_RANK); List<String> workflowIds = Arrays.stream(workflowIdsStr.split(",")) .map(String::trim) .collect(Collectors.toList()); List<ProcessDetail> concurrentWorkflows = lightweightWorkflowLock .listConcurrentWorkflows(workflowIds, param.getContainerName()); if (!concurrentWorkflows.isEmpty()) { LOGGER.error("Concurrent process(es) found " + concurrentWorkflows.stream().map( i -> i.getProcessType() + " " + i.getOperationId() + "(" + i.getGlobalState() + "/" + i.getStepStatus() + ")") .collect(Collectors.joining(", ", "[", "]"))); ObjectNode eventDetails = JsonHandler.createObjectNode(); eventDetails.put("error", CONCURRENT_PROCESSES_FOUND); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.KO, eventDetails); } } catch (VitamClientException e) { LOGGER.error("Concurrent workflow lock check failed", e); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.FATAL, null); } LOGGER.info("Concurrent workflow lock check succeeded"); return buildItemStatus(CHECK_CONCURRENT_WORKFLOW_LOCK, StatusCode.OK, null); } CheckConcurrentWorkflowLockHandler(); @VisibleForTesting  CheckConcurrentWorkflowLockHandler(LightweightWorkflowLock lightweightWorkflowLock); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); static String getId();  }