コード例 #1
0
  public void TranformModel() {
    InitModel();

    String rspec = client.ListResources();

    System.out.println(rspec);
    System.out.println("=======================================================================");
    if (rspec.equals("")) return;

    Document resourceSpecDocument = xmlutl.getXMLDocFromString(rspec);

    // NodeList aggregates = xmlutl.getNodeListFromObject(resourceSpecDocument, "//aggregate");

    NodeList networks = xmlutl.getNodeListFromObject(resourceSpecDocument, "//network");

    if (networks == null) return;

    for (int ixOrgan = 0; ixOrgan < networks.getLength(); ixOrgan++) {
      Node network = networks.item(ixOrgan);
      // String organName = xmlutl.getNodeValueFromObject( item, "name/text()" );
      // String organID = xmlutl.getNodeValueFromObject( organisationSpecNodes.item(ixOrgan), "@id"
      // );
      String organName = xmlutl.getNodeValueFromObject(network, "@name");
      String organID = organName; // will be the same
      System.out.println(organName);

      ResourcesProvider resourcesProvider;
      Site partnerSite;
      // create the partner
      resourcesProvider = UsersFactory.eINSTANCE.createResourcesProvider();
      broker.getRegisteredUsers().add(resourcesProvider);
      log("officePartner organID: " + organID);
      resourcesProvider.setId(ixOrgan);
      resourcesProvider.setUniqueID("rp" + organID);
      organName = organName.trim();
      log("resourcesProvider organName: " + organName);
      resourcesProvider.setName(
          organName); // we set the name also later in the ptm Name, to have something shorter!
      resourcesProvider.setDescription(organName);
      resourcesProvider.setOrganization(organName);
      partnerSite = ProvidersiteFactory.eINSTANCE.createSite();
      partnerSite.setId(0);
      partnerSite.setUniqueID(resourcesProvider.getUniqueID() + "_s" + organID);
      partnerSite.setName("site");
      resourcesProvider.getOfferedSiteList().add(partnerSite);
      partnerSite.setBelongsToProvider(resourcesProvider);

      // Add now the PTM for the site
      DomainManager ptm = ProvidersiteFactory.eINSTANCE.createDomainManager();
      partnerSite.setDomainManager(ptm);

      ptm.setBelongsToSite(partnerSite);
      NodeList resourceSpecNodes =
          xmlutl.getNodeListFromObject(
              resourceSpecDocument, "//network[@name=\"" + organName + "\"]/node");

      // String organName = xmlutl.getNodeValueFromObject( item, "name/text()" );
      // String organID = xmlutl.getNodeValueFromObject( organisationSpecNodes.item(ixOrgan), "@id"
      // );
      for (int ixNode = 0; ixNode < resourceSpecNodes.getLength(); ixNode++) {

        Node resNode = resourceSpecNodes.item(ixNode);
        // SFA mainly offers nodes?!
        CreateOfferedService_Resource_Contract(
            "node",
            partnerSite,
            resNode,
            true); // we can toggle this false if we will create OfferedResources only from ptmInfo
      }
    }

    // slices should be also added as resources/offered services.
    // And each node will have a setting called sliver that the user can
    // assign the slice name..
    // Slices can be added to a different taxonomy

  }
コード例 #2
0
  private void CreateOfferedService_Resource_Contract(
      String serviceName, Site partnerSite, Node resNode, Boolean createResource) {

    String resourceName = xmlutl.getNodeValueFromObject(resNode, "@component_name");
    log("resourceName : " + resourceName);
    String resourceSpecID = xmlutl.getNodeValueFromObject(resNode, "@component_id");

    if (resourceName.equals("")) {
      resourceName = xmlutl.getNodeValueFromObject(resNode, "hostname/text()");
    }

    //		NodeList resourceSpecNodes = xmlutl.getNodeListFromObject( resourceSpecDocument,
    // "//resourceSpec [@id="+resourceSpecID+"]");
    String offeredServiceName = serviceName;

    log("offeredService offeredServiceName: " + offeredServiceName);
    String offeredServiceDescr = "sfa " + offeredServiceName;
    //		//add back these for the service settings
    //		String configParamCompositeId = xmlutl.getNodeValueFromObject(resourceSpecNodes.item(0),
    // "configurationParameters/@id");
    //		log("configParamCompositeId offServ="+offeredServiceName+", configParamCompositeId
    // ="+configParamCompositeId);
    //
    //		//before creating the service, check if exists
    Boolean newServiceCreated = false;

    //		OfferedService offService = FindOfferedServiceFromID(  resourceSpecID );
    //		if (offService==null)
    OfferedService offService = FindOfferedServiceFromName(offeredServiceName);

    if (offService == null) {
      offService = ServicesFactory.eINSTANCE.createOfferedService();
      offService.setId(0); // not used in SFA?!
      //			offService.setUniqueID("os"+Integer.parseInt(resourceSpecID));
      offService.setUniqueID("os" + offeredServiceName);
      offService.setName(offeredServiceName);

      // offService.setDefaultValue();
      offService.setDescription(offeredServiceDescr);
      log("offeredService offeredServiceDescr: " + offeredServiceDescr);
      broker.getOfferedServices().add(offService);
      newServiceCreated = true;
    }

    // IF <configParamType>reference</configParamType> can be assigned

    // add the service as offered Resource also of Partner...a Contract must be also created here!
    OfferedResource offeredResource = null;
    if (createResource) {
      offeredResource = ResourcesFactory.eINSTANCE.createOfferedResource();
      partnerSite.getOfferedResourcesList().add(offeredResource);
      offeredResource.setBelongsToSite(partnerSite);
      offeredResource.setId(0); // not used in SFA?!
      offeredResource.setUniqueID(resourceName);
      //			String prefix="";
      //			if ((partnerSite.getPtm() != null) && (partnerSite.getPtm().getName() != null))
      //				prefix = partnerSite.getPtm().getName();
      offeredResource.setName(
          resourceName); // in SFA seems node names are unique//Will replace . with _
      offeredResource.setDescription(offeredServiceDescr);
      offeredResource.setImplOfferedService(offService);
      offeredResource.setMultitonMaxOccur(
          1); // we have atleast one of these resources to be reserved

      int prefix = partnerSite.getBelongsToProvider().getId();

      offeredResource.setGeocoords("-170, 50");

      CreateResourceContract(offeredResource);
    }

    CreateSetting(
        "hostname",
        "defvalHostNameSet",
        "node hostname",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        false,
        true);
    CreateSetting(
        "vsys",
        "",
        "request access to a vsys script on the selected node",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        true,
        true);
    CreateSetting(
        "initscript",
        "",
        "initscript on the selected node",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        true,
        true);
    CreateSetting(
        "vsys_vnet",
        "",
        "initscript on the selected node",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        true,
        true);

    // Finally add service to the general ServiceCategories
    generalTaxonomy.getTaxonomies().get(0).getHasServices().add(offService);
  }