Ejemplo n.º 1
0
  private String getStaticValueOfAssignedSetting(
      RequestedFederationScenario scenario,
      ResourceRequest resReq,
      ResourceSettingInstance assignedSetting) {
    if ((assignedSetting.getStaticValue() != null)
        && assignedSetting.getAssignSetting().size()
            == 0) // if there is available only the static value
    return assignedSetting
          .getStaticValue(); // we currently search only for the next assigned resource
    else if ((resReq.getRuntimeInfo() != null)
        && (resReq.getRuntimeInfo().getStatus() == RuntimeElementStatus.ONLINE)) {
      // ask resource proxy, if it is possible to update its values and then return the value!
      String officeName =
          ((Office) resReq.getRefOfferedResource().getImplOfferedService().eContainer()).getName();

      for (IProvisionResource p : Activator.getDefault().getProvisionPlugins()) {
        if (p.supportsOffice(officeName)) {
          String val = p.readResource(officeName, scenario, resReq, assignedSetting, true);
          assignedSetting.setStaticValue(val);
          return val;
        }
      }
    }
    //		else { //else dig further to the next setting
    //			for (SettingInstance s : assignedSetting.getAssignSetting() ) {
    //				return getStaticValueOfAssignedSetting(s);
    //			}
    //		}

    return null;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  public boolean resourceRequestHasAllAssignementsResolved(
      RequestedFederationScenario scenario, ResourceRequest resReq) {

    for (ResourceSettingInstance s : resReq.getReqResourceSettings()) {
      if (s.getAssignSetting().size() > 0) {
        String value = null;
        for (SettingInstance assignedSetting : s.getAssignSetting()) {
          ResourceRequest assignedResource =
              (ResourceRequest) ((ResourceSettingInstance) assignedSetting).eContainer();
          value =
              getStaticValueOfAssignedSetting(
                  scenario, assignedResource, (ResourceSettingInstance) assignedSetting);
          if ((value == null)) {
            System.out.println(
                "Setting:"
                    + s.getName()
                    + " of resource "
                    + resReq.getName()
                    + " has assigned value to:"
                    + assignedSetting.getName()
                    + " which cannot be resolved yet!");
            return false; // exit immediately. We currently cannot resolve this
          }
          value = value + ",";
        }

        value = value.substring(0, value.length() - 1); // to cut the last comma
        s.setStaticValue(value);
        s.getAssignSetting().clear(); // if came here then it is ok and everything assigned
      }
    }

    // check now if everything is OK to go
    for (ResourceSettingInstance s : resReq.getReqResourceSettings()) {
      if (s.getRefResourceSetting().isWritable())
        if ((s.getStaticValue() == null) || (s.getAssignSetting().size() > 0)) {
          System.out.println(
              "Setting:"
                  + s.getName()
                  + " of resource "
                  + resReq.getName()
                  + " cannot be resolved yet!");
          return false;
        }
    }

    return true; // everything is resolved..so go
  }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
0
 @Override
 public boolean belongsTo(Object family) {
   return resourceReq.eContainer().equals(family);
 }
Ejemplo n.º 7
0
  private void broadcastResourceStatus(RuntimeElementStatus status) {

    resourceReq.getRuntimeInfo().setStatus(status);
    ProvisioningJobBroadcaster.getInstance().eventOccuredOnResource(resourceReq);
  }
Ejemplo n.º 8
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection =
        HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (selection != null & selection instanceof IStructuredSelection) {
      IStructuredSelection strucSelection = (IStructuredSelection) selection;

      for (Object obj : strucSelection.toArray()) {
        System.out.println("Object =" + obj.toString());
        if (obj instanceof ui_TaxonomyTreeItem) {
          if ((((ui_TaxonomyTreeItem) obj).getOfficeElement()
              instanceof RequestedFederationScenario)) {
            // http://nam.ece.upatras.gr/fstoolkit/utils/resourcesmap.php?x[0]=38.288291,21.788884
            String req = "";
            RequestedFederationScenario scenario =
                (RequestedFederationScenario) ((ui_TaxonomyTreeItem) obj).getOfficeElement();

            ArrayList<myMarker> sitelist = new ArrayList<myMarker>();
            for (ResourceRequest resReq :
                scenario.getInfrastructureRequest().getReqOfferedResources()) {
              if (resReq.getRefOfferedResource() != null) {
                System.out.println(
                    "resReq.getRefOfferedResource() = " + resReq.getRefOfferedResource().getName());

                Site site = (Site) resReq.getRefOfferedResource().eContainer();

                if ((site != null) && (!sitelist.contains(site))) {
                  myMarker mymarker = null;
                  for (myMarker m : sitelist) {
                    if (m.site.equals(site)) mymarker = m;
                  }
                  if (mymarker == null) {
                    mymarker = new myMarker();
                    mymarker.site = site;
                    mymarker.descriptions = "";
                    sitelist.add(mymarker);
                  }
                  mymarker.descriptions +=
                      resReq.getName()
                          + " : <i>"
                          + resReq.getRefOfferedResource().getName()
                          + "</i></br>";
                }
              }
            }
            int i = 0;
            for (myMarker mymarker : sitelist) {
              if (mymarker.site.getLocatedAt() != null) {
                ResourcesProvider r = (ResourcesProvider) mymarker.site.eContainer();
                req = req + "x[" + i + "]=" + mymarker.site.getLocatedAt().getGeocoords() + "&";
                req =
                    req
                        + "c["
                        + i
                        + "]=<b>"
                        + r.getName()
                        + "</b><br>"
                        + "<small>"
                        + mymarker.descriptions
                        + "</small>"
                        + "&";
              }
              i++;
            }

            req = req.substring(0, req.length() - 1);
            req = "http://nam.ece.upatras.gr/fstoolkit/utils/resourcesmap.php?" + req;
            System.out.println("req = " + req);

            IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
            IWebBrowser browser;
            try {

              browser =
                  support.createBrowser(
                      IWorkbenchBrowserSupport.AS_VIEW,
                      ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName()
                          + ".webbrowser.fstoolkit",
                      "Map for " + ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName(),
                      "A world map for "
                          + ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName());

              browser.openURL(new URL(req));

            } catch (PartInitException e) {
              e.printStackTrace();
            } catch (MalformedURLException e) {
              e.printStackTrace();
            }
          }
        }
      }
    }
    return null;
  }
Ejemplo n.º 9
0
 String text(ResourceRequest sr) {
   //		return "Request "+ sr.getNumOfServices()+", "+sr.getName();
   return sr.getName() + " of " + sr.getRefOfferedResource().getName();
 }