示例#1
0
  /**
   * Calculates the number of services of the specified type running on each of the specified
   * Cybernodes.
   *
   * @param cybernodes the Cybernodes to consider
   * @param type the service type to look for
   * @return the resulting array. Every element of this array stores the number of services of the
   *     specified type running on a specific Cybernode. The order of elements corresponds to the
   *     one of services in the <code>cybernodes</code> parameter.
   * @throws RemoteException if there was a communication failure while attempting to access one of
   *     the Cybernodes from the specified list.
   */
  public static int[] calcServices(Cybernode[] cybernodes, Class type) throws RemoteException {

    int[] res = new int[cybernodes.length];
    for (int i = 0; i < cybernodes.length; i++) {
      Cybernode cybernode = cybernodes[i];
      ServiceRecord[] records = cybernode.getServiceRecords(ServiceRecord.ACTIVE_SERVICE_RECORD);
      for (ServiceRecord record : records) {
        ServiceElement element = record.getServiceElement();
        ClassBundle[] exportBundles = element.getExportBundles();
        for (ClassBundle bundle : exportBundles) {
          if (bundle.getClassName().equals(type.getName())) {
            res[i]++;
            break;
          }
        }
      }
    }
    return res;
  }
示例#2
0
 /** Override toString */
 public String toString() {
   StringBuilder buffer = new StringBuilder();
   if (interfaceNames != null) {
     for (int i = 0; i < interfaceNames.length; i++) {
       if (i > 0) buffer.append(", ");
       buffer.append(interfaceNames[i]);
     }
   } else {
     buffer.append("<null>");
   }
   String iFaces = buffer.toString();
   buffer.delete(0, buffer.length());
   if (groups == null) {
     buffer.append("<null>");
   } else {
     for (int i = 0; i < groups.length; i++) {
       if (i > 0) buffer.append(", ");
       buffer.append(groups[i]);
     }
   }
   String gps = buffer.toString();
   String fdh = "<null>";
   if (fdhBundle != null) fdh = fdhBundle.getClassName();
   String ops = "<null>";
   if (opStringName != null) ops = opStringName;
   return ("Type="
       + type.toString()
       + ", "
       + "Name="
       + getName()
       + ", "
       + "Interfaces="
       + iFaces
       + ", "
       + "Groups="
       + gps
       + ", "
       + "Version="
       + version
       + ", "
       + "MatchOnName="
       + matchOnName
       + ", "
       + "OperationalString="
       + ops
       + ", "
       + "Property="
       + propertyName
       + ", "
       + "associationMatchFilter="
       + associationMatchFilter
       + ", "
       + "proxyClass="
       + proxyClass
       + ", "
       + "serviceStrategyClass="
       + serviceStrategyClass
       + ", "
       + "lazyInject="
       + lazyInject
       + ", "
       + "serviceDiscoveryTimeout="
       + serviceDiscoveryTimeout
       + ", "
       + "serviceDiscoveryTimeUnits="
       + serviceDiscoveryTimeUnits
       + ", "
       + "FDH="
       + fdh);
 }
  static ServiceElement create(
      final ServiceDetails serviceDetails, final ServiceDeployment deployment) throws IOException {
    ServiceElement service = new ServiceElement();

    String websterUrl;
    if (serviceDetails.webster == null) {
      if (deployment.getWebsterUrl() == null) {
        websterUrl = Sorcer.getWebsterUrl();
        if (logger.isDebugEnabled())
          logger.debug("Set code base derived from Sorcer.getWebsterUrl: " + websterUrl);
      } else {
        websterUrl = deployment.getWebsterUrl();
        if (logger.isDebugEnabled())
          logger.debug("Set code base derived from Deployment: " + websterUrl);
      }
    } else {
      websterUrl = serviceDetails.webster;
    }
    /* Create client (export) ClassBundle */
    List<ClassBundle> exports = new ArrayList<ClassBundle>();
    for (String s : serviceDetails.interfaces) {
      ClassBundle export = new ClassBundle(s);
      if (serviceDetails.codebaseJars.length == 1
          && Artifact.isArtifact(serviceDetails.codebaseJars[0])) {
        export.setArtifact(serviceDetails.codebaseJars[0]);
      } else {
        export.setJARs(appendJars(commonDLJars, serviceDetails.codebaseJars));
        export.setCodebase(websterUrl);
      }
      exports.add(export);
    }

    /* Create service implementation ClassBundle */
    ClassBundle main =
        new ClassBundle(
            serviceDetails.providerClass == null
                ? deployment.getImpl()
                : serviceDetails.providerClass);
    if (serviceDetails.implJars.length == 1 && Artifact.isArtifact(serviceDetails.implJars[0])) {
      main.setArtifact(serviceDetails.implJars[0]);
    } else {
      main.setJARs(serviceDetails.implJars);
      main.setCodebase(websterUrl);
    }

    /* Set ClassBundles to ServiceElement */
    service.setComponentBundle(main);
    service.setExportBundles(exports.toArray(new ClassBundle[exports.size()]));

    String serviceName;
    if (serviceDetails.name == null) {
      /* Get the (simple) name from the fully qualified interface */
      if (deployment.getName() == null) {
        StringBuilder nameBuilder = new StringBuilder();
        for (String s : serviceDetails.interfaces) {
          String value;
          int ndx = s.lastIndexOf(".");
          if (ndx > 0) {
            value = s.substring(ndx + 1);
          } else {
            value = s;
          }
          if (nameBuilder.length() > 0) {
            nameBuilder.append(" | ");
          }
          nameBuilder.append(value);
        }
        serviceName = nameBuilder.toString();
      } else {
        serviceName = deployment.getName();
      }
    } else {
      serviceName = serviceDetails.name;
    }

    if (serviceDetails.maxPerNode > 0) {
      service.setMaxPerMachine(serviceDetails.maxPerNode);
    }
    if (serviceDetails.architecture != null || serviceDetails.operatingSystems.length > 0) {
      ServiceLevelAgreements slas = new ServiceLevelAgreements();
      SystemRequirements systemRequirements = new SystemRequirements();
      if (serviceDetails.architecture != null) {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        attributeMap.put(ProcessorArchitecture.ARCHITECTURE, serviceDetails.architecture);
        SystemComponent systemComponent =
            new SystemComponent("Processor", ProcessorArchitecture.class.getName(), attributeMap);
        systemRequirements.addSystemComponent(systemComponent);
      }
      for (String s : serviceDetails.operatingSystems) {
        String opSys = checkAndMaybeFixOpSys(s);
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        attributeMap.put(OperatingSystem.NAME, opSys);
        SystemComponent operatingSystem =
            new SystemComponent("OperatingSystem", OperatingSystem.class.getName(), attributeMap);
        systemRequirements.addSystemComponent(operatingSystem);
      }
      slas.setServiceRequirements(systemRequirements);
      service.setServiceLevelAgreements(slas);
    }
    if (serviceDetails.ips.length > 0) {
      SystemRequirements systemRequirements =
          service.getServiceLevelAgreements().getSystemRequirements();
      systemRequirements.addSystemComponent(getSystemComponentAddresses(false, serviceDetails.ips));
    }

    if (serviceDetails.excludeIps.length > 0) {
      SystemRequirements systemRequirements =
          service.getServiceLevelAgreements().getSystemRequirements();
      systemRequirements.addSystemComponent(
          getSystemComponentAddresses(true, serviceDetails.excludeIps));
    }

    /* Create simple ServiceBeanConfig */
    Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(ServiceBeanConfig.NAME, serviceName);
    configMap.put(ServiceBeanConfig.GROUPS, Sorcer.getLookupGroups());
    ServiceBeanConfig sbc = new ServiceBeanConfig(configMap, new String[] {deployment.getConfig()});
    sbc.addAdditionalEntries(
        new DeployInfo(
            deployment.getType().name(), deployment.getUnique().name(), deployment.getIdle()));
    service.setServiceBeanConfig(sbc);
    service.setPlanned(deployment.getMultiplicity());

    /* If the service is to be forked, create an ExecDescriptor */
    if (serviceDetails.fork) {
      service.setFork(true);
      if (serviceDetails.jvmArgs != null) {
        ExecDescriptor execDescriptor = new ExecDescriptor();
        execDescriptor.setInputArgs(serviceDetails.jvmArgs);
        service.setExecDescriptor(execDescriptor);
      }
    }
    if (logger.isDebugEnabled()) logger.debug("Generated Service Element :" + service);
    return service;
  }