示例#1
0
  public int compare(Resource res1, Resource res2) {
    int diff;

    diff = ComparatorUtils.safeCompare(res1.getSymbolicName(), res2.getSymbolicName());
    if (diff != 0) return diff;

    diff = ComparatorUtils.safeCompare(res1.getVersion(), res2.getVersion());

    return diff;
  }
示例#2
0
  private static void toXml(XmlWriter w, Resource resource) throws IOException {
    w.element(RepositoryParser.RESOURCE)
        .attribute(Resource.ID, resource.getId())
        .attribute(Resource.SYMBOLIC_NAME, resource.getSymbolicName())
        .attribute(Resource.PRESENTATION_NAME, resource.getPresentationName())
        .attribute(Resource.URI, getRelativeUri(resource, Resource.URI))
        .attribute(Resource.VERSION, resource.getVersion().toString());

    w.textElement(Resource.DESCRIPTION, resource.getProperties().get(Resource.DESCRIPTION))
        .textElement(Resource.SIZE, resource.getProperties().get(Resource.SIZE))
        .textElement(
            Resource.DOCUMENTATION_URI, getRelativeUri(resource, Resource.DOCUMENTATION_URI))
        .textElement(Resource.SOURCE_URI, getRelativeUri(resource, Resource.SOURCE_URI))
        .textElement(Resource.JAVADOC_URI, getRelativeUri(resource, Resource.JAVADOC_URI))
        .textElement(Resource.LICENSE_URI, getRelativeUri(resource, Resource.LICENSE_URI));

    String[] categories = resource.getCategories();
    for (int i = 0; categories != null && i < categories.length; i++) {
      w.element(RepositoryParser.CATEGORY).attribute(RepositoryParser.ID, categories[i]).end();
    }
    Capability[] capabilities = resource.getCapabilities();
    for (int i = 0; capabilities != null && i < capabilities.length; i++) {
      toXml(w, capabilities[i]);
    }
    Requirement[] requirements = resource.getRequirements();
    for (int i = 0; requirements != null && i < requirements.length; i++) {
      toXml(w, requirements[i]);
    }
    w.end();
  }
  @Override
  public Object doExecute() throws Exception {
    // check if the group exists
    Group group = groupManager.findGroupByName(groupName);
    if (group == null) {
      System.err.println("Cluster group " + groupName + " doesn't exist");
      return null;
    }

    // check if the producer is ON
    if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
      System.err.println("Cluster event producer is OFF");
      return null;
    }

    // check if the URL is allowed
    if (!isAllowed(group, Constants.URLS_CONFIG_CATEGORY, url, EventType.OUTBOUND)) {
      System.err.println("OBR URL " + url + " is blocked outbound for cluster group " + groupName);
      return null;
    }

    // update the OBR URLs in the cluster group
    Set<String> clusterUrls =
        clusterManager.getSet(
            Constants.URLS_DISTRIBUTED_SET_NAME + Configurations.SEPARATOR + groupName);
    clusterUrls.add(url);
    // update the OBR bundles in the cluster group
    Set<ObrBundleInfo> clusterBundles =
        clusterManager.getSet(
            Constants.BUNDLES_DISTRIBUTED_SET_NAME + Configurations.SEPARATOR + groupName);
    synchronized (obrService) {
      Repository repository = obrService.addRepository(url);
      Resource[] resources = repository.getResources();
      for (Resource resource : resources) {
        ObrBundleInfo info =
            new ObrBundleInfo(
                resource.getPresentationName(),
                resource.getSymbolicName(),
                resource.getVersion().toString());
        clusterBundles.add(info);
      }
      obrService.removeRepository(url);
    }

    // broadcast a cluster event
    ClusterObrUrlEvent event = new ClusterObrUrlEvent(url, Constants.URL_ADD_EVENT_TYPE);
    event.setSourceGroup(group);
    eventProducer.produce(event);

    return null;
  }