private GridProcessStatusInfo fillProcess(GridProcess process) {

    WorkerStatusInfo workerInfo =
        new WorkerStatusInfo(
            process.getWorkerEntry().getWorkerSpecification(),
            process.getHandle(),
            process.getWorkerEntry().getWorkerID(),
            process.getState().toString());

    GridProcessStatusInfoResult result = null;

    if (process.getResult() != null) {

      String error = "";
      String errorCause = null;

      GridProcessError executionError = process.getResult().getExecutionError();
      if (executionError != null) {
        error = executionError.getType().getName();

        if (executionError.getErrorCause() != null) {
          errorCause = executionError.getErrorCause().getMessage();
        }
      }

      result =
          new GridProcessStatusInfoResult(
              error,
              errorCause,
              process.getResult().getInitData().getElapsedTimeInMillis(),
              process.getResult().getRemoteData().getElapsedTimeInMillis(),
              process.getResult().getFinalData().getElapsedTimeInMillis(),
              process.getResult().getExecutorResult());

      SabotageCheckResult sabotageCheckResult = process.getResult().getSabotageCheckResult();
      if (sabotageCheckResult != null) {
        result.setSabotageCheck(sabotageCheckResult.toString());
      }
    }

    GridProcessStatusInfo info =
        new GridProcessStatusInfo(
            process.getId(),
            process.getTaskId(),
            process.getJobId(),
            process.getState().toString(),
            process.getCurrentPhase().toString(),
            workerInfo,
            result,
            process.getHandle());

    info.setCreationTime(process.getCreationTime());
    info.setFinalizationTime(process.getFinalizationTime());

    return info;
  }
  private GridProcessAccounting setAccountingFields(GridProcess process) {

    GridProcessAccounting accounting = process.getReplicaAccounting();
    GridProcessExecutionResult result = process.getResult();

    GridProcessPhasesData phasesData = new GridProcessPhasesData();
    phasesData.setInitBeginning(result.getInitData().getStartTime());
    phasesData.setInitEnd(result.getInitData().getEndTime());
    phasesData.setRemoteBeginning(result.getRemoteData().getStartTime());
    phasesData.setRemoteEnd(result.getRemoteData().getEndTime());
    phasesData.setFinalBeginning(result.getFinalData().getStartTime());
    phasesData.setFinalEnd(result.getFinalData().getEndTime());
    phasesData.setInitOperations(result.getInitOperations());
    phasesData.setGetOperations(result.getGetOperations());

    accounting.setPhasesData(phasesData);

    GridProcessResultInfo resultInfo = new GridProcessResultInfo();

    GridProcessError error = result.getExecutionError();
    if (error != null && error.getErrorCause() != null) {
      resultInfo.setErrorCause(error.getErrorCause().getMessage());
      resultInfo.setExecutionErrorType(error.getType().getName());
    }

    ExecutorResult executorResult = result.getExecutorResult();
    if (executorResult != null) {
      resultInfo.setExitValue(executorResult.getExitValue());
      resultInfo.setStderr(executorResult.getStderr());
      resultInfo.setStdout(executorResult.getStdout());
    }
    accounting.setResultInfo(resultInfo);

    accounting.setCreationTime(process.getCreationTime());
    accounting.setLatestPhase(process.getState().toString());

    SabotageCheckResult sabotageCheckResult = result.getSabotageCheckResult();
    String sabotageCheck = sabotageCheckResult == null ? null : sabotageCheckResult.toString();
    accounting.setSabotageCheck(sabotageCheck);

    accounting.setTaskSequenceNumber(process.getSpec().getTaskSequenceNumber());
    accounting.setGridProcessSequenceNumber(process.getId());

    accounting.setState(process.getState());

    return accounting;
  }
  private void reportReplicaAccounting(GridProcess process, List<IResponseTO> responses) {

    GridProcessAccounting accounting = setAccountingFields(process);
    accounting.setTransfersProgress(convertTransfer(process.getTransfersProgress()));
    String peerID = process.getWorkerProviderID();

    String peerAddress = StringUtil.deploymentIDToAddress(peerID);

    ReportReplicaAccountingResponseTO to = new ReportReplicaAccountingResponseTO();
    to.setCreationTime(accounting.getCreationTime());
    to.setErrorCause(accounting.getErrorCause());
    to.setExecutionErrorType(accounting.getExecutionErrorType());
    to.setExitValue(accounting.getExitValue());
    to.setFinalBeginning(accounting.getFinalBeginning());
    to.setFinalEnd(accounting.getFinalEnd());
    to.setInitBeginning(accounting.getInitBeginning());
    to.setInitEnd(accounting.getInitEnd());
    to.setJobID(process.getJobId());

    to.setLatestPhase(accounting.getLatestPhase());
    to.setMaxFails(accounting.getMaxFails());
    to.setMaxReplicas(accounting.getMaxReplicas());
    to.setPeerAddress(peerAddress);
    to.setRemoteBeginning(accounting.getRemoteBeginning());
    to.setRemoteEnd(accounting.getRemoteEnd());
    to.setRequestID(accounting.getRequestId());
    to.setRequiredWorkers(accounting.getRequiredWorkers());
    to.setSabotageCheck(accounting.getSabotageCheck());
    to.setState(accounting.getState().name());
    to.setStderr(accounting.getStderr());
    to.setStdout(accounting.getStdout());
    to.setTaskSequenceNumber(accounting.getTaskSequenceNumber());
    to.setGridProcessSequenceNumber(accounting.getGridProcessSequenceNumber());
    to.setWorkerID(accounting.getWorkerID());
    to.setWorkerPK(accounting.getWorkerPublicKey());

    String workerAddress = StringUtil.deploymentIDToAddress(accounting.getWorkerID());
    WorkerSpecification workerSpec =
        BrokerDAOFactory.getInstance().getWorkerDAO().getWorkerSpec(workerAddress);
    to.setWorkerSpec(workerSpec);

    to.setGetOperationsList(
        fillFinalGetOperations(
            accounting.getFinalCommands(),
            process.getTask(),
            process.getId(),
            process.getWorkerEntry().getWorkerID(),
            accounting.getRequestId()));
    to.setInitOperationsList(
        fillInitGetOperations(
            accounting.getInitCommands(),
            process.getTask(),
            process.getId(),
            process.getWorkerEntry().getWorkerID(),
            accounting.getRequestId()));
    to.setPeerBalancesList(fillPeerBalances(accounting.getAccountings().getBalances()));
    to.setTransferProgressList(
        fillTransferProgress(accounting.getTransfersProgress(), "" + process.getId()));

    responses.add(to);
  }