private void finishRequests(Job job, List<IResponseTO> responses) {

    RequestSpecification spec = null;
    for (Request request : job.getRequests()) {
      spec = request.getSpecification();
      String peerAddress = StringUtil.deploymentIDToAddress(request.getPeerID());

      FinishRequestResponseTO to = new FinishRequestResponseTO();
      to.setJobID(Integer.parseInt("" + spec.getJobId()));
      to.setJobSpec(spec.getJobSpecification());
      to.setMaxFails(spec.getMaxFails());
      to.setMaxReplicas(spec.getMaxReplicas());
      to.setPeerAddress(peerAddress);
      to.setRequestID(spec.getRequestId());
      to.setRequiredWorkers(spec.getRequiredWorkers());

      responses.add(to);
    }

    job.finishRequests();
  }
  /**
   * @param job
   * @param workerEntry
   */
  private void unwantWorker(Job job, WorkerEntry workerEntry, List<IResponseTO> responses) {

    responses.add(
        new LoggerResponseTO(
            "Worker unwanted: " + workerEntry.getWorkerID(), LoggerResponseTO.DEBUG));

    job.unwantWorker(workerEntry);
    workerEntry.unwant();

    RequestSpecification spec = workerEntry.getRequestSpecification();

    String peerAddress = StringUtil.deploymentIDToAddress(workerEntry.getPeerID());
    String workerAddress = StringUtil.deploymentIDToAddress(workerEntry.getWorkerID());
    Integer jobId = Integer.parseInt("" + spec.getJobId());

    JobSpecification jobSpec = BrokerDAOFactory.getInstance().getJobDAO().getJobSpec(jobId);

    UnwantWorkerResponseTO unwantWorkerTO = new UnwantWorkerResponseTO();
    unwantWorkerTO.setJobID(jobId);
    unwantWorkerTO.setJobSpec(jobSpec);
    unwantWorkerTO.setMaxFails(spec.getMaxFails());
    unwantWorkerTO.setMaxReplicas(spec.getMaxReplicas());
    unwantWorkerTO.setPeerAddress(peerAddress);
    unwantWorkerTO.setRequestID(spec.getRequestId());
    unwantWorkerTO.setRequiredWorkers(spec.getRequiredWorkers());

    unwantWorkerTO.setWorkerAddress(workerAddress);

    WorkerDAO workerDAO = BrokerDAOFactory.getInstance().getWorkerDAO();

    String workerPublicKey = workerDAO.getWorkerPublicKey(workerAddress);
    unwantWorkerTO.setWorkerPublicKey(workerPublicKey);

    responses.add(unwantWorkerTO);

    ReleaseResponseTO releaseTO = new ReleaseResponseTO();
    releaseTO.setStubAddress(workerAddress);

    responses.add(releaseTO);

    workerDAO.removeWorker(workerAddress);

    WorkerInfo.getInstance().removeWorker(workerEntry.getServiceID().getContainerID().toString());
  }
Exemple #3
0
  /**
   * Mark's this <code>GridProcess</code> as running, in other words this replica will change state
   * to <code>GridProcessState.RUNNING</code> if it is in <code>GridProcessState.UNSTARTED</code>.
   *
   * @param chosenWorker Spec of the worker that will run this replica.
   */
  public void allocate(WorkerEntry chosenWorker) {

    if (!GridProcessState.UNSTARTED.equals(this.state)) {
      throw new IllegalResultException(
          "This replica is already running or has already finished execution", replicaHandle);
    }

    this.workerEntry = chosenWorker;
    RequestSpecification requestSpec = workerEntry.getRequestSpecification();

    if (requestSpec != null) {
      this.replicaAccounting =
          new GridProcessAccounting(
              requestSpec.getRequestId(),
              requestSpec.getJobId(),
              requestSpec.getRequiredWorkers(),
              requestSpec.getMaxFails(),
              requestSpec.getMaxReplicas(),
              getWorkerEntry().getWorkerID(),
              getWorkerEntry().getWorkerPublicKey(),
              workerEntry.getWorkerSpecification());
    }
  }