Exemplo n.º 1
0
  private IStatus runProvisionJob(IProgressMonitor monitor) {
    RuntimeElement rtInfo = resourceReq.getRuntimeInfo();

    broadcastResourceStatus(RuntimeElementStatus.OFFLINE);
    Random r1 = new Random();
    ScenarioSolver solver = new ScenarioSolver();
    if (!solver.resourceRequestHasAllAssignementsResolved(
        scenario, resourceReq)) { // r1.nextInt(20)>5 ){//ResourceSettingsAreNotOK ){	
      broadcastResourceStatus(RuntimeElementStatus.WAITING);

      Random r = new Random();
      this.schedule(1000 * r.nextInt(60) + 1000); // reschedule the job in 60random seconds
      System.out.println("RESCHEDULED : " + resourceReq.getName());
      return Status.OK_STATUS;
    }

    monitor.beginTask("Provisioning " + resourceReq.getName(), 1);
    if (monitor.isCanceled()) {
      parentJob.NotifyResJobFinished(this);
      System.out.println("ProvisionResourceJob, Cancel provisioning : " + resourceReq.getName());
      broadcastResourceStatus(RuntimeElementStatus.UNKNOWN);
      return Status.CANCEL_STATUS;
    }

    String guid = "";
    String officeName =
        ((Office) resourceReq.getRefOfferedResource().getImplOfferedService().eContainer())
            .getName();
    for (IProvisionResource p : Activator.getDefault().getProvisionPlugins()) {
      if (p.supportsOffice(officeName)) {
        broadcastResourceStatus(RuntimeElementStatus.STARTING);
        guid = p.provisionResource(officeName, scenario, resourceReq);
        rtInfo.setGUID(guid);
      }
    }

    //		try {
    //			Random r = new Random();
    //			Thread.sleep(1000 * r.nextInt(10) );
    //			guid="temp";
    //			rtInfo.setGUID(guid+"."+resourceReq.getName());
    //		} catch (InterruptedException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}

    if ("".equals(guid)) broadcastResourceStatus(RuntimeElementStatus.ERROR);
    else broadcastResourceStatus(RuntimeElementStatus.ONLINE);

    monitor.worked(1);

    monitor.done();
    parentJob.NotifyResJobFinished(this);

    return Status.OK_STATUS;
  }
Exemplo n.º 2
0
  private IStatus runShutDownResourceJob(IProgressMonitor monitor) {
    RuntimeElement rtInfo = resourceReq.getRuntimeInfo();

    monitor.beginTask("Shutting down " + resourceReq.getName(), 1);
    if (monitor.isCanceled()) {
      parentJob.NotifyResJobFinished(this);
      System.out.println("ProvisionResourceJob, Cancel provisioning : " + resourceReq.getName());
      broadcastResourceStatus(RuntimeElementStatus.UNKNOWN);
      ;
      return Status.CANCEL_STATUS;
    }

    String guid = "";
    String officeName =
        ((Office) resourceReq.getRefOfferedResource().getImplOfferedService().eContainer())
            .getName();
    for (IProvisionResource p : Activator.getDefault().getProvisionPlugins()) {
      if (p.supportsOffice(officeName)) {
        if ((rtInfo.getStatus() != RuntimeElementStatus.NOT_EXISTS)) {

          try {
            Random r = new Random();
            Thread.sleep(1000 * r.nextInt(60)); // sleep randomly..shutdown to avoid collisions.
          } catch (InterruptedException e) {
            e.printStackTrace();
          }

          guid = p.deleteResource(officeName, scenario, resourceReq);
        }
        rtInfo.setGUID(guid);
      }
    }

    broadcastResourceStatus(RuntimeElementStatus.NOT_EXISTS);

    monitor.worked(1);

    monitor.done();
    System.out.println("ProvisionResourceJob, OK Provisioning : " + resourceReq.getName());
    parentJob.NotifyResJobFinished(this);

    return Status.OK_STATUS;
  }
Exemplo n.º 3
0
  /**
   * It will create a new scenario based on the given one, if the given one is not already saved.
   * The returned scenario will have some (or all if possible) assignments on resource settings
   * resolved. The method calls internally {@link #resolveAssignments(RequestedFederationScenario)}
   *
   * @param The requested scenario
   * @return a new scenario based on the requested, with resolved dependencies (if possible at first
   *     pass)
   */
  public RequestedFederationScenario prepareScenarioRequest(RequestedFederationScenario scenario) {

    RequestedFederationScenario newScenario;
    if (scenario.getRuntimeInfo() == null) {
      newScenario = FederationscenariosFactory.eINSTANCE.createRequestedFederationScenario();
      newScenario = (RequestedFederationScenario) EcoreUtil.copy(scenario);
      RuntimeElement rtinfo = ExperimentRuntimeFactory.eINSTANCE.createRuntimeElement();
      rtinfo.setDescription(
          "Scenario is based on request by:" + scenario.eResource().getURI().path());
      newScenario.setRuntimeInfo(rtinfo);
      for (ResourceRequest resReq :
          newScenario.getInfrastructureRequest().getReqOfferedResources()) {
        RuntimeElement rtInfo = ExperimentRuntimeFactory.eINSTANCE.createRuntimeElement();
        resReq.setRuntimeInfo(rtInfo);
        rtInfo.setStatus(RuntimeElementStatus.NOT_EXISTS);
      }

    } else {
      newScenario = scenario;
    }

    resolveAssignments(newScenario);
    return newScenario;
  }