@RunWithCustomExecutor @Test(expected = WorkerExecutorException.class) public void test_worker_task_get_then_third_checkStatus_ok_thenWorkerExecutorException() throws Exception { DescriptionStep descriptionStep = getDescriptionStep("familyId"); WorkerInformation.getWorkerThreadLocal().get().setWorkerBean(WORKER_DESCRIPTION); final WorkerTask task = new WorkerTask(descriptionStep, 0, "requestId", "contractId", "contextId", "applicationId", workerClientFactory); when(workerClient.submitStep(eq(descriptionStep))) .thenThrow(new WorkerServerClientException("Unreachable server")); doThrow(new UnresolvedAddressException(), new UnresolvedAddressException()).doNothing().when(workerClient).checkStatus(); task.get(); }
@Override public ItemStatus get() { VitamThreadUtils.getVitamSession().setRequestId(requestId); VitamThreadUtils.getVitamSession().setTenantId(tenantId); VitamThreadUtils.getVitamSession().setContractId(contractId); VitamThreadUtils.getVitamSession().setContextId(contextId); VitamThreadUtils.getVitamSession().setApplicationSessionId(applicationId); final WorkerBean workerBean = WorkerInformation.getWorkerThreadLocal().get().getWorkerBean(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Start executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } try { final WorkerClientConfiguration configuration = new WorkerClientConfiguration( workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); WorkerClientFactory.changeMode(configuration); WorkerClient workerClient; if (null == workerClientFactory) { workerClient = WorkerClientFactory.getInstance(configuration).getClient(); } else { workerClient = workerClientFactory.getClient(); } try { switch (getStep().getPauseOrCancelAction()) { case ACTION_RUN: case ACTION_RECOVER: case ACTION_REPLAY: workerTaskState = WorkerTaskState.RUNNING; return workerClient.submitStep(descriptionStep); case ACTION_PAUSE: workerTaskState = WorkerTaskState.PAUSE; return new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .setItemsStatus(PauseOrCancelAction.ACTION_PAUSE.name(), new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .increment(StatusCode.UNKNOWN)); case ACTION_CANCEL: workerTaskState = WorkerTaskState.CANCEL; return new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .setItemsStatus(PauseOrCancelAction.ACTION_CANCEL.name(), new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .increment(StatusCode.UNKNOWN)); case ACTION_COMPLETE: throw new WorkerExecutorException(workerBean.getWorkerId(), "Step id: " + getStep().getId() + " and name :" + getStep().getStepName() + " already completed"); default: throw new WorkerExecutorException(workerBean.getWorkerId(), "The default case should not be handled"); } } catch (WorkerNotFoundClientException | WorkerServerClientException e) { boolean checkStatus = false; int numberCallCheckStatus = 0; while (!checkStatus && numberCallCheckStatus < GlobalDataRest.STATUS_CHECK_RETRY) { checkStatus = checkStatusWorker(workerClient, workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); numberCallCheckStatus++; if (!checkStatus) { try { TimeUnit.MILLISECONDS.sleep(1000); } catch (final InterruptedException e1) { LOGGER.warn(e); Thread.currentThread().interrupt(); } } } if (!checkStatus) { throw new WorkerUnreachableException(workerBean.getWorkerId(), e); } throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { workerClient.close(); } } catch (WorkerExecutorException e) { throw e; } catch (Exception e) { throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { if (!WorkerTaskState.PAUSE.equals(workerTaskState) && !WorkerTaskState.CANCEL.equals(workerTaskState)) { workerTaskState = WorkerTaskState.COMPLETED; } if (LOGGER.isDebugEnabled()) { LOGGER .debug("End executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } } }
WorkerTask implements Supplier<ItemStatus> { @Override public ItemStatus get() { VitamThreadUtils.getVitamSession().setRequestId(requestId); VitamThreadUtils.getVitamSession().setTenantId(tenantId); VitamThreadUtils.getVitamSession().setContractId(contractId); VitamThreadUtils.getVitamSession().setContextId(contextId); VitamThreadUtils.getVitamSession().setApplicationSessionId(applicationId); final WorkerBean workerBean = WorkerInformation.getWorkerThreadLocal().get().getWorkerBean(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Start executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } try { final WorkerClientConfiguration configuration = new WorkerClientConfiguration( workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); WorkerClientFactory.changeMode(configuration); WorkerClient workerClient; if (null == workerClientFactory) { workerClient = WorkerClientFactory.getInstance(configuration).getClient(); } else { workerClient = workerClientFactory.getClient(); } try { switch (getStep().getPauseOrCancelAction()) { case ACTION_RUN: case ACTION_RECOVER: case ACTION_REPLAY: workerTaskState = WorkerTaskState.RUNNING; return workerClient.submitStep(descriptionStep); case ACTION_PAUSE: workerTaskState = WorkerTaskState.PAUSE; return new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .setItemsStatus(PauseOrCancelAction.ACTION_PAUSE.name(), new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .increment(StatusCode.UNKNOWN)); case ACTION_CANCEL: workerTaskState = WorkerTaskState.CANCEL; return new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .setItemsStatus(PauseOrCancelAction.ACTION_CANCEL.name(), new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .increment(StatusCode.UNKNOWN)); case ACTION_COMPLETE: throw new WorkerExecutorException(workerBean.getWorkerId(), "Step id: " + getStep().getId() + " and name :" + getStep().getStepName() + " already completed"); default: throw new WorkerExecutorException(workerBean.getWorkerId(), "The default case should not be handled"); } } catch (WorkerNotFoundClientException | WorkerServerClientException e) { boolean checkStatus = false; int numberCallCheckStatus = 0; while (!checkStatus && numberCallCheckStatus < GlobalDataRest.STATUS_CHECK_RETRY) { checkStatus = checkStatusWorker(workerClient, workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); numberCallCheckStatus++; if (!checkStatus) { try { TimeUnit.MILLISECONDS.sleep(1000); } catch (final InterruptedException e1) { LOGGER.warn(e); Thread.currentThread().interrupt(); } } } if (!checkStatus) { throw new WorkerUnreachableException(workerBean.getWorkerId(), e); } throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { workerClient.close(); } } catch (WorkerExecutorException e) { throw e; } catch (Exception e) { throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { if (!WorkerTaskState.PAUSE.equals(workerTaskState) && !WorkerTaskState.CANCEL.equals(workerTaskState)) { workerTaskState = WorkerTaskState.COMPLETED; } if (LOGGER.isDebugEnabled()) { LOGGER .debug("End executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } } } }
WorkerTask implements Supplier<ItemStatus> { @Override public ItemStatus get() { VitamThreadUtils.getVitamSession().setRequestId(requestId); VitamThreadUtils.getVitamSession().setTenantId(tenantId); VitamThreadUtils.getVitamSession().setContractId(contractId); VitamThreadUtils.getVitamSession().setContextId(contextId); VitamThreadUtils.getVitamSession().setApplicationSessionId(applicationId); final WorkerBean workerBean = WorkerInformation.getWorkerThreadLocal().get().getWorkerBean(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Start executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } try { final WorkerClientConfiguration configuration = new WorkerClientConfiguration( workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); WorkerClientFactory.changeMode(configuration); WorkerClient workerClient; if (null == workerClientFactory) { workerClient = WorkerClientFactory.getInstance(configuration).getClient(); } else { workerClient = workerClientFactory.getClient(); } try { switch (getStep().getPauseOrCancelAction()) { case ACTION_RUN: case ACTION_RECOVER: case ACTION_REPLAY: workerTaskState = WorkerTaskState.RUNNING; return workerClient.submitStep(descriptionStep); case ACTION_PAUSE: workerTaskState = WorkerTaskState.PAUSE; return new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .setItemsStatus(PauseOrCancelAction.ACTION_PAUSE.name(), new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .increment(StatusCode.UNKNOWN)); case ACTION_CANCEL: workerTaskState = WorkerTaskState.CANCEL; return new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .setItemsStatus(PauseOrCancelAction.ACTION_CANCEL.name(), new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .increment(StatusCode.UNKNOWN)); case ACTION_COMPLETE: throw new WorkerExecutorException(workerBean.getWorkerId(), "Step id: " + getStep().getId() + " and name :" + getStep().getStepName() + " already completed"); default: throw new WorkerExecutorException(workerBean.getWorkerId(), "The default case should not be handled"); } } catch (WorkerNotFoundClientException | WorkerServerClientException e) { boolean checkStatus = false; int numberCallCheckStatus = 0; while (!checkStatus && numberCallCheckStatus < GlobalDataRest.STATUS_CHECK_RETRY) { checkStatus = checkStatusWorker(workerClient, workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); numberCallCheckStatus++; if (!checkStatus) { try { TimeUnit.MILLISECONDS.sleep(1000); } catch (final InterruptedException e1) { LOGGER.warn(e); Thread.currentThread().interrupt(); } } } if (!checkStatus) { throw new WorkerUnreachableException(workerBean.getWorkerId(), e); } throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { workerClient.close(); } } catch (WorkerExecutorException e) { throw e; } catch (Exception e) { throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { if (!WorkerTaskState.PAUSE.equals(workerTaskState) && !WorkerTaskState.CANCEL.equals(workerTaskState)) { workerTaskState = WorkerTaskState.COMPLETED; } if (LOGGER.isDebugEnabled()) { LOGGER .debug("End executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } } } WorkerTask(DescriptionStep descriptionStep, int tenantId, String requestId, String contractId,
        String contextId, String applicationId);  WorkerTask(DescriptionStep descriptionStep, int tenantId, String requestId, String contractId,
        String contextId, String applicationId, WorkerClientFactory workerClientFactory); }
WorkerTask implements Supplier<ItemStatus> { @Override public ItemStatus get() { VitamThreadUtils.getVitamSession().setRequestId(requestId); VitamThreadUtils.getVitamSession().setTenantId(tenantId); VitamThreadUtils.getVitamSession().setContractId(contractId); VitamThreadUtils.getVitamSession().setContextId(contextId); VitamThreadUtils.getVitamSession().setApplicationSessionId(applicationId); final WorkerBean workerBean = WorkerInformation.getWorkerThreadLocal().get().getWorkerBean(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Start executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } try { final WorkerClientConfiguration configuration = new WorkerClientConfiguration( workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); WorkerClientFactory.changeMode(configuration); WorkerClient workerClient; if (null == workerClientFactory) { workerClient = WorkerClientFactory.getInstance(configuration).getClient(); } else { workerClient = workerClientFactory.getClient(); } try { switch (getStep().getPauseOrCancelAction()) { case ACTION_RUN: case ACTION_RECOVER: case ACTION_REPLAY: workerTaskState = WorkerTaskState.RUNNING; return workerClient.submitStep(descriptionStep); case ACTION_PAUSE: workerTaskState = WorkerTaskState.PAUSE; return new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .setItemsStatus(PauseOrCancelAction.ACTION_PAUSE.name(), new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .increment(StatusCode.UNKNOWN)); case ACTION_CANCEL: workerTaskState = WorkerTaskState.CANCEL; return new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .setItemsStatus(PauseOrCancelAction.ACTION_CANCEL.name(), new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .increment(StatusCode.UNKNOWN)); case ACTION_COMPLETE: throw new WorkerExecutorException(workerBean.getWorkerId(), "Step id: " + getStep().getId() + " and name :" + getStep().getStepName() + " already completed"); default: throw new WorkerExecutorException(workerBean.getWorkerId(), "The default case should not be handled"); } } catch (WorkerNotFoundClientException | WorkerServerClientException e) { boolean checkStatus = false; int numberCallCheckStatus = 0; while (!checkStatus && numberCallCheckStatus < GlobalDataRest.STATUS_CHECK_RETRY) { checkStatus = checkStatusWorker(workerClient, workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); numberCallCheckStatus++; if (!checkStatus) { try { TimeUnit.MILLISECONDS.sleep(1000); } catch (final InterruptedException e1) { LOGGER.warn(e); Thread.currentThread().interrupt(); } } } if (!checkStatus) { throw new WorkerUnreachableException(workerBean.getWorkerId(), e); } throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { workerClient.close(); } } catch (WorkerExecutorException e) { throw e; } catch (Exception e) { throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { if (!WorkerTaskState.PAUSE.equals(workerTaskState) && !WorkerTaskState.CANCEL.equals(workerTaskState)) { workerTaskState = WorkerTaskState.COMPLETED; } if (LOGGER.isDebugEnabled()) { LOGGER .debug("End executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } } } WorkerTask(DescriptionStep descriptionStep, int tenantId, String requestId, String contractId,
        String contextId, String applicationId);  WorkerTask(DescriptionStep descriptionStep, int tenantId, String requestId, String contractId,
        String contextId, String applicationId, WorkerClientFactory workerClientFactory); @Override ItemStatus get(); Step getStep(); String getObjectName(); List<String> getObjectNameList(); boolean isCompleted(); }
WorkerTask implements Supplier<ItemStatus> { @Override public ItemStatus get() { VitamThreadUtils.getVitamSession().setRequestId(requestId); VitamThreadUtils.getVitamSession().setTenantId(tenantId); VitamThreadUtils.getVitamSession().setContractId(contractId); VitamThreadUtils.getVitamSession().setContextId(contextId); VitamThreadUtils.getVitamSession().setApplicationSessionId(applicationId); final WorkerBean workerBean = WorkerInformation.getWorkerThreadLocal().get().getWorkerBean(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Start executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } try { final WorkerClientConfiguration configuration = new WorkerClientConfiguration( workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); WorkerClientFactory.changeMode(configuration); WorkerClient workerClient; if (null == workerClientFactory) { workerClient = WorkerClientFactory.getInstance(configuration).getClient(); } else { workerClient = workerClientFactory.getClient(); } try { switch (getStep().getPauseOrCancelAction()) { case ACTION_RUN: case ACTION_RECOVER: case ACTION_REPLAY: workerTaskState = WorkerTaskState.RUNNING; return workerClient.submitStep(descriptionStep); case ACTION_PAUSE: workerTaskState = WorkerTaskState.PAUSE; return new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .setItemsStatus(PauseOrCancelAction.ACTION_PAUSE.name(), new ItemStatus(PauseOrCancelAction.ACTION_PAUSE.name()) .increment(StatusCode.UNKNOWN)); case ACTION_CANCEL: workerTaskState = WorkerTaskState.CANCEL; return new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .setItemsStatus(PauseOrCancelAction.ACTION_CANCEL.name(), new ItemStatus(PauseOrCancelAction.ACTION_CANCEL.name()) .increment(StatusCode.UNKNOWN)); case ACTION_COMPLETE: throw new WorkerExecutorException(workerBean.getWorkerId(), "Step id: " + getStep().getId() + " and name :" + getStep().getStepName() + " already completed"); default: throw new WorkerExecutorException(workerBean.getWorkerId(), "The default case should not be handled"); } } catch (WorkerNotFoundClientException | WorkerServerClientException e) { boolean checkStatus = false; int numberCallCheckStatus = 0; while (!checkStatus && numberCallCheckStatus < GlobalDataRest.STATUS_CHECK_RETRY) { checkStatus = checkStatusWorker(workerClient, workerBean.getConfiguration().getServerHost(), workerBean.getConfiguration().getServerPort()); numberCallCheckStatus++; if (!checkStatus) { try { TimeUnit.MILLISECONDS.sleep(1000); } catch (final InterruptedException e1) { LOGGER.warn(e); Thread.currentThread().interrupt(); } } } if (!checkStatus) { throw new WorkerUnreachableException(workerBean.getWorkerId(), e); } throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { workerClient.close(); } } catch (WorkerExecutorException e) { throw e; } catch (Exception e) { throw new WorkerExecutorException(workerBean.getWorkerId(), e); } finally { if (!WorkerTaskState.PAUSE.equals(workerTaskState) && !WorkerTaskState.CANCEL.equals(workerTaskState)) { workerTaskState = WorkerTaskState.COMPLETED; } if (LOGGER.isDebugEnabled()) { LOGGER .debug("End executing of task number :" + descriptionStep.getStep().getStepName() + " on worker: " + workerBean.getWorkerId()); } } } WorkerTask(DescriptionStep descriptionStep, int tenantId, String requestId, String contractId,
        String contextId, String applicationId);  WorkerTask(DescriptionStep descriptionStep, int tenantId, String requestId, String contractId,
        String contextId, String applicationId, WorkerClientFactory workerClientFactory); @Override ItemStatus get(); Step getStep(); String getObjectName(); List<String> getObjectNameList(); boolean isCompleted();  }