Package org.apache.aries.application.management

Examples of org.apache.aries.application.management.ResolverException


    Document doc;
    try {
      doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

    } catch (ParserConfigurationException pce) {
      throw new ResolverException(pce);
    }
    Element root = doc.createElement("repository");

    root.setAttribute("name", repositoryName);
    doc.appendChild(root);
    for (ModelledResource mr : byValueBundles) {
      BundleResource bundleResource = new BundleResource(mr, repositoryAdmin);
      if (bundleResourceTransformers.size() > 0) {
        for (BundleResourceTransformer brt : bundleResourceTransformers) {
          bundleResource = brt.transform (bundleResource);
        }
      }
      writeResource (bundleResource, mr.getLocation(), doc, root);
    }

    try {
      Transformer trans = TransformerFactory.newInstance().newTransformer();
      trans.setOutputProperty(OutputKeys.INDENT, "yes");
      trans.transform(new DOMSource(doc), new StreamResult(os));
    } catch (TransformerException te) {
      logger.debug(LOG_EXIT, "generateRepository", te);
      throw new ResolverException(te);
    }
    logger.debug(LOG_EXIT, "generateRepository");
  }
View Full Code Here


            appRepository = repositoryAdmin.getHelper().repository(f.toURI().toURL());

            f.delete();
        } catch (Exception e) {
            throw new ResolverException(e);
        }

        List<Repository> appRepositories = new ArrayList<Repository>();
       
        // add system & local repositories
        appRepositories.add(repositoryAdmin.getSystemRepository());
        appRepositories.add(repositoryAdmin.getLocalRepository());
       
        // add application repository
        appRepositories.add(appRepository);
       
        // add user repositories
        Repository[] userRepositories = repositoryAdmin.listRepositories();
        for (Repository userRepository : userRepositories) {
            appRepositories.add(userRepository);
        }
       
        Resolver obrResolver = repositoryAdmin.resolver(appRepositories.toArray(new Repository[appRepositories.size()]));

        // add a resource describing the requirements of the application metadata.
        try {
            obrResolver.add(new ApplicationResourceImpl(repositoryAdmin, appName, appVersion, appContent));
        } catch (InvalidSyntaxException e) {
            throw new ResolverException(e);
        }

        if (obrResolver.resolve()) {
            Set<BundleInfo> result = new HashSet<BundleInfo>();
            for (Resource resource : obrResolver.getRequiredResources()) {
                BundleInfo bundleInfo = toBundleInfo(resource, false);
                result.add(bundleInfo);
            }
            if (includeOptional) {
                for (Resource resource : obrResolver.getOptionalResources()) {
                    BundleInfo bundleInfo = toBundleInfo(resource, true);
                    result.add(bundleInfo);
                }
            }
            return result;
        } else {
            throw new ResolverException("Could not resolve requirements: "
                                        + getUnsatisfiedRequirements(obrResolver));
        }

    }
View Full Code Here

      if (range == null) {
        _provisionSharedContent.add(dp);
      } else if (range.matches(info.getVersion())) {
        _deploymentContent.add(dp);
      } else {
        throw new ResolverException("Bundle " + info.getSymbolicName() + " at version " + info.getVersion() + " is not in the range " + range);
      }
    }
  }
View Full Code Here

    try {
      // find out blueprint information
      byValueBundles = getByValueBundles(app);
      // find out by value bundles and then by reference bundles
    } catch (Exception e) {
      throw new ResolverException (e);
    }

    Collection<Content> bundlesToResolve = new ArrayList<Content>();
    bundlesToResolve.addAll(appMetadata.getApplicationContents());   
    bundlesToResolve.addAll(app.getApplicationMetadata().getUseBundles());
View Full Code Here

    Collection<ModelledResource> byValueBundles = new ArrayList<ModelledResource>(provideByValueBundles);
    ModelledResource fakeBundleResource;
    try {
      fakeBundleResource = createFakeBundle(appMetadata.getApplicationImportServices());
    } catch (InvalidAttributeException iax) {
      ResolverException rx = new ResolverException (iax);
      _logger.debug(LOG_EXIT, "generateDeploymentManifest", new Object[] {rx});

      throw rx;
    }
    byValueBundles.add(fakeBundleResource);
   
    Collection<ModelledResource> fakeResources = new ArrayList<ModelledResource>();
    for (PreResolveHook hook : preResolveHooks) {
      hook.collectFakeResources(fakeResources);
    }
   
    byValueBundles.addAll(fakeResources);
   
    String appSymbolicName = appMetadata.getApplicationSymbolicName();
    String appVersion = appMetadata.getApplicationVersion().toString();
    String uniqueName = appSymbolicName + "_" + appVersion;
   
    DeployedBundles deployedBundles = modellingHelper.createDeployedBundles(appSymbolicName, appContentIB, useBundleIB, Arrays.asList(fakeBundleResource));
    Collection<ModelledResource> bundlesToBeProvisioned = resolver.resolve(
        appSymbolicName, appVersion, byValueBundles, bundlesToResolve);
    pruneFakeBundlesFromResults (bundlesToBeProvisioned, fakeResources);

    if (bundlesToBeProvisioned.isEmpty()) {
      throw new ResolverException(MessageUtil.getMessage("EMPTY_DEPLOYMENT_CONTENT",uniqueName));
    }
    for (ModelledResource rbm : bundlesToBeProvisioned)
    {
      deployedBundles.addBundle(rbm);
    }
    Collection<ModelledResource> requiredUseBundle = deployedBundles.getRequiredUseBundle();
    if (requiredUseBundle.size() < useBundleSet.size())
    {
      // Some of the use-bundle entries were redundant so resolve again with just the good ones.
      deployedBundles = modellingHelper.createDeployedBundles(appSymbolicName, appContentIB, useBundleIB, Arrays.asList(fakeBundleResource));
      bundlesToResolve.clear();
      bundlesToResolve.addAll(appContent);
      Collection<ImportedBundle> slimmedDownUseBundle = narrowUseBundles(useBundleIB, requiredUseBundle);
      bundlesToResolve.addAll(toContent(slimmedDownUseBundle));
      bundlesToBeProvisioned = resolver.resolve(appSymbolicName, appVersion,
          byValueBundles, bundlesToResolve);
       pruneFakeBundlesFromResults (bundlesToBeProvisioned, fakeResources);
      for (ModelledResource rbm : bundlesToBeProvisioned)
      {
        deployedBundles.addBundle(rbm);
      }
    }

    // Check for circular dependencies. No shared bundle can depend on any
    // isolated bundle.
    Collection<ModelledResource> sharedBundles = new HashSet<ModelledResource>();
    sharedBundles.addAll (deployedBundles.getDeployedProvisionBundle());
    sharedBundles.addAll (deployedBundles.getRequiredUseBundle());

    Collection<ModelledResource> appContentBundles = deployedBundles.getDeployedContent();
    Collection<Content> requiredSharedBundles = new ArrayList<Content>();
    for (ModelledResource mr : sharedBundles) {
      String version = mr.getExportedBundle().getVersion();
      String exactVersion = "[" + version + "," + version + "]";

      Content ib = ContentFactory.parseContent(mr.getExportedBundle().getSymbolicName(),
          exactVersion);
      requiredSharedBundles.add(ib);

    }
    // This will throw a ResolverException if the shared content does not resolve
    Collection<ModelledResource> resolvedSharedBundles = resolver.resolve(appSymbolicName, appVersion
        , byValueBundles, requiredSharedBundles);

    // we need to find out whether any shared bundles depend on the isolated bundles
    List<String> suspects = findSuspects (resolvedSharedBundles, sharedBundles, appContentBundles);
    // If we have differences, it means that we have shared bundles trying to import packages
    // from isolated bundles. We need to build up the error message and throw a ResolverException
    if (!suspects.isEmpty()) {
     
     
      StringBuilder msgs = new StringBuilder();
      List<String> unsatisfiedRequirements = new ArrayList<String>();

      Map<String, List<String>> isolatedBundles = new HashMap<String, List<String>>();
      // Find the isolated bundles and store all the packages that they export in a map.
      for (ModelledResource mr : resolvedSharedBundles) {
        String mrName = mr.getSymbolicName() + "_" + mr.getExportedBundle().getVersion();
        if (suspects.contains(mrName)) {
          List<String> exportedPackages = new ArrayList<String>();
          isolatedBundles.put(mrName, exportedPackages);
          for (ExportedPackage ep : mr.getExportedPackages()) {
            exportedPackages.add(ep.getPackageName());
          }
        }
      }
      // Now loop through the shared bundles, reading the imported packages, and find which ones
      // are exported from the isolated bundles.
      for (ModelledResource mr : resolvedSharedBundles) {
        String mrName = mr.getSymbolicName() + "_" + mr.getExportedBundle().getVersion();
        // if current resource isn't an isolated bundle check it's requirements
        if (!!! suspects.contains(mrName)) {
          // Iterate through the imported packages of the current shared bundle.
          for (ImportedPackage ip : mr.getImportedPackages()) {
            String packageName = ip.getPackageName();
            List<String> bundlesExportingPackage = new ArrayList<String>();
            // Loop through each exported package of each isolated bundle, and if we
            // get a match store the info away.
            for (Map.Entry<String, List<String>> currBundle : isolatedBundles.entrySet()) {

              List<String> exportedPackages = currBundle.getValue();
              if (exportedPackages != null && exportedPackages.contains(packageName)) {
                bundlesExportingPackage.add(currBundle.getKey());
              }
            }
            // If we have found at least one matching entry, we construct the sub message for the
            // exception.
            if (!!! bundlesExportingPackage.isEmpty()) {
              String newMsg;
              if (bundlesExportingPackage.size() > 1) {
                newMsg = MessageUtil.getMessage("SHARED_BUNDLE_IMPORTING_FROM_ISOLATED_BUNDLES",
                    new Object[] {mrName, packageName, bundlesExportingPackage});
              } else {
                newMsg = MessageUtil.getMessage("SHARED_BUNDLE_IMPORTING_FROM_ISOLATED_BUNDLE",
                    new Object[] {mrName, packageName, bundlesExportingPackage});
              }
              msgs.append("\n");
              msgs.append(newMsg);
              unsatisfiedRequirements.add(newMsg);
            }
          }
        }
      }
      // Once we have iterated over all bundles and have got our translated submessages,
      // throw the exception.
      // Well! if the msgs is empty, no need to throw an exception
      if (msgs.length() !=0) {
        String message = MessageUtil.getMessage(
            "SUSPECTED_CIRCULAR_DEPENDENCIES", new Object[] {appSymbolicName, msgs});
        ResolverException rx = new ResolverException (message);
        rx.setUnsatisfiedRequirements(unsatisfiedRequirements);
        _logger.debug(LOG_EXIT, "generateDeploymentManifest", new Object[] {rx});
        throw (rx);
      }
    }
   
View Full Code Here

    Map<String,String> result = new HashMap<String, String>();
    String content = deployedBundles.getContent();
    if (!content.isEmpty()) {
      result.put(AppConstants.DEPLOYMENT_CONTENT, content);
    } else {
      throw new ResolverException(MessageUtil.getMessage("EMPTY_DEPLOYMENT_CONTENT", appSymbolicName));
    }

    String useBundle = deployedBundles.getUseBundle();
    if (!useBundle.isEmpty()) {
      result.put(AppConstants.DEPLOYMENT_USE_BUNDLE, useBundle);
View Full Code Here

    for (ModelledResource isolatedBundle : db.getDeployedContent()) {
      for (ModelledResource provisionBundle : db.getDeployedProvisionBundle()) {
        if (isolatedBundle.getSymbolicName().equals(provisionBundle.getSymbolicName())
            && providesPackage(provisionBundle, db.getImportPackage())) {
         
          throw new ResolverException(
              MessageUtil.getMessage("ISOLATED_CONTENT_PROVISIONED",
                  applicationSymbolicName,
                  isolatedBundle.getSymbolicName(),
                  isolatedBundle.getVersion(),
                  provisionBundle.getVersion()));
View Full Code Here

    Set<ImportedBundle> result = new HashSet<ImportedBundle>();
    for (Content c : content) {
      try {
        result.add(modellingManager.getImportedBundle(c.getContentName(), c.getVersion().toString()));
      } catch (InvalidAttributeException iax) {
        ResolverException rx = new ResolverException (iax);
        _logger.debug(LOG_EXIT, "toImportedBundle", new Object[]{rx});
        throw rx;
      }
    }
View Full Code Here

      }

      int buffLen = buff.length();
      String pkgString = (buffLen > 0 ? buff.substring(0, buffLen - 2) : "");

      ResolverException re = new ResolverException(MessageUtil.getMessage(
          "INCOMPATIBLE_PACKAGE_VERSION_REQUIREMENTS", new Object[] { assetName, pkgString }));
      re.setUnsatisfiedRequirements(pkgNames);
      logger.debug(LOG_EXIT,"getExternalPackageRequirements", re);
     
      throw re;
    }
   
View Full Code Here

      for (String name : req.getAttributes().keySet())
      {
        if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(name)
            || Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name))
        {
          ResolverException re = new ResolverException(MessageUtil.getMessage(
              "INVALID_PACKAGE_REQUIREMENT_ATTRIBUTES", new Object[] { assetName, name, pkgName }));
          re.setUnsatisfiedRequirements(Arrays.asList(pkgName));
          logger.debug(LOG_EXIT, "validateOtherImports", re);
          throw re;
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.aries.application.management.ResolverException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.