Search in sources :

Example 1 with Resolver

use of org.apache.felix.bundlerepository.Resolver in project aries by apache.

the class RepositoryGenerator method resolve.

public List<Resource> resolve(List<Resource> subsystemContent, List<Resource> subsystemResources) throws SubsystemException {
    generateOBR();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Attempt to resolve subsystem content {} subsystem resource {}", subsystemContent.toString(), subsystemResources.toString());
    }
    Resolver obrResolver = this.repositoryAdmin.resolver();
    // add subsystem content to the resolver
    for (Resource res : subsystemContent) {
        //            org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
        //            obrResolver.add(obrRes);
        obrResolver.add(new OsgiResourceAdapter(res));
    }
    // add subsystem resource to the resolver
    for (Resource res : subsystemResources) {
        //            org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
        //            obrResolver.add(obrRes);
        obrResolver.add(new OsgiResourceAdapter(res));
    }
    // Question: do we need to create the repository.xml for the subsystem and add the repo to RepoAdmin?
    List<Resource> resources = new ArrayList<Resource>();
    if (obrResolver.resolve()) {
        for (org.apache.felix.bundlerepository.Resource res : obrResolver.getRequiredResources()) {
            //                resources.add(toResource(res));
            resources.add(new FelixResourceAdapter(res));
        }
        // Question: should we handle optional resource differently?
        for (org.apache.felix.bundlerepository.Resource res : obrResolver.getOptionalResources()) {
            //                resources.add(toResource(res));
            resources.add(new FelixResourceAdapter(res));
        }
    } else {
        // log the unsatisfied requirement
        Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
        StringBuilder builder = new StringBuilder("Failed to resolve subsystem").append(System.getProperty("line.separator"));
        for (Reason reason : reasons) {
            LOGGER.warn("Unable to resolve subsystem content {} subsystem resource {} because of unsatisfied requirement {}", new Object[] { subsystemContent.toString(), subsystemResources.toString(), reason.getRequirement().getName() });
            builder.append("resource = ").append(reason.getResource().getSymbolicName()).append(", requirement = ").append(reason.getRequirement().getName()).append(System.getProperty("line.separator"));
        }
        throw new SubsystemException(builder.toString());
    }
    return resources;
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) SubsystemException(org.osgi.service.subsystem.SubsystemException) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) FelixResourceAdapter(org.apache.aries.subsystem.util.felix.FelixResourceAdapter) Reason(org.apache.felix.bundlerepository.Reason) OsgiResourceAdapter(org.apache.aries.subsystem.util.felix.OsgiResourceAdapter)

Example 2 with Resolver

use of org.apache.felix.bundlerepository.Resolver in project aries by apache.

the class OBRAriesResolver method getConfiguredObrResolver.

private Resolver getConfiguredObrResolver(String appName, String appVersion, Collection<ModelledResource> byValueBundles, boolean noExtraRepositories) throws ResolverException {
    log.debug(LOG_ENTRY, "getConfiguredObrResolver", new Object[] { appName, appVersion, byValueBundles });
    DataModelHelper helper = repositoryAdmin.getHelper();
    Repository appRepo;
    try {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        RepositoryGeneratorImpl.generateRepository(repositoryAdmin, appName + "_" + appVersion, byValueBundles, bytesOut);
        appRepo = helper.readRepository(new InputStreamReader(new ByteArrayInputStream(bytesOut.toByteArray())));
    } catch (Exception e) {
        throw new ResolverException(e);
    }
    List<Repository> resolveRepos = new ArrayList<Repository>();
    // add system repository
    resolveRepos.add(repositoryAdmin.getSystemRepository());
    // add application repository
    resolveRepos.add(appRepo);
    if (!!!noExtraRepositories) {
        // add local repository if configured
        if (!(excludeLocalRuntime())) {
            resolveRepos.add(getLocalRepository(repositoryAdmin));
        }
        // Need to refresh the repositories added to repository admin 
        // add user-defined repositories
        Repository[] repos = repositoryAdmin.listRepositories();
        for (Repository r : repos) {
            resolveRepos.add(r);
        }
    }
    Resolver obrResolver = repositoryAdmin.resolver(resolveRepos.toArray(new Repository[resolveRepos.size()]));
    addPlatformRepositories(obrResolver, appName, platformRepository);
    log.debug(LOG_EXIT, "getConfiguredObrResolver", obrResolver);
    return obrResolver;
}
Also used : PlatformRepository(org.apache.aries.application.management.spi.repository.PlatformRepository) Repository(org.apache.felix.bundlerepository.Repository) ResolverException(org.apache.aries.application.management.ResolverException) InputStreamReader(java.io.InputStreamReader) Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResolverException(org.apache.aries.application.management.ResolverException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException)

Example 3 with Resolver

use of org.apache.felix.bundlerepository.Resolver in project aries by apache.

the class OBRAriesResolver method resolve.

/**
   * Resolve a list of resources from the OBR bundle repositories by OBR
   * resolver.
   * 
   * @param appName - application name
   * @param appVersion - application version
   * @param byValueBundles - by value bundles
   * @param inputs - other constraints
   * @param platformRepository - a platform repository to use instead of the one provided as a service
   * @return a collection of modelled resources required by this application
   * @throws ResolverException
   */
@Override
public Collection<ModelledResource> resolve(String appName, String appVersion, Collection<ModelledResource> byValueBundles, Collection<Content> inputs) throws ResolverException {
    log.debug(LOG_ENTRY, "resolve", new Object[] { appName, appVersion, byValueBundles, inputs });
    Collection<ImportedBundle> importedBundles = toImportedBundle(inputs);
    Resolver obrResolver = getConfiguredObrResolver(appName, appVersion, byValueBundles, false);
    // add a resource describing the requirements of the application metadata.
    obrResolver.add(createApplicationResource(appName, appVersion, importedBundles));
    log.debug(LOG_EXIT, "resolve");
    return doResolve(obrResolver, appName);
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) ImportedBundle(org.apache.aries.application.modelling.ImportedBundle)

Example 4 with Resolver

use of org.apache.felix.bundlerepository.Resolver in project aries by apache.

the class OBRAriesResolver method resolve.

@Deprecated
@Override
public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
    log.trace("resolving {}", app);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    String appName = appMeta.getApplicationSymbolicName();
    Version appVersion = appMeta.getApplicationVersion();
    List<Content> appContent = appMeta.getApplicationContents();
    Collection<Content> useBundleContent = appMeta.getUseBundles();
    List<Content> contents = new ArrayList<Content>();
    contents.addAll(appContent);
    contents.addAll(useBundleContent);
    if ((constraints != null) && (constraints.length > 0)) {
        for (ResolveConstraint con : constraints) {
            contents.add(ContentFactory.parseContent(con.getBundleName(), con.getVersionRange().toString()));
        }
    }
    Resolver obrResolver = getConfiguredObrResolver(appName, appVersion.toString(), toModelledResource(app.getBundleInfo()), false);
    // add a resource describing the requirements of the application metadata.
    obrResolver.add(createApplicationResource(appName, appVersion, contents));
    if (obrResolver.resolve()) {
        Set<BundleInfo> result = new HashSet<BundleInfo>();
        List<Resource> requiredResources = retrieveRequiredResources(obrResolver);
        for (Resource resource : requiredResources) {
            BundleInfo bundleInfo = toBundleInfo(resource, false);
            result.add(bundleInfo);
        }
        if (returnOptionalResources) {
            for (Resource resource : obrResolver.getOptionalResources()) {
                BundleInfo bundleInfo = toBundleInfo(resource, true);
                result.add(bundleInfo);
            }
        }
        return result;
    } else {
        Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
        //refine the list by removing the indirect unsatisfied bundles that are caused by unsatisfied packages or other bundles
        Map<String, Set<String>> refinedReqs = refineUnsatisfiedRequirements(obrResolver, reasons);
        StringBuffer reqList = new StringBuffer();
        Map<String, String> unsatisfiedRequirements = extractConsumableMessageInfo(refinedReqs);
        for (String reason : unsatisfiedRequirements.keySet()) {
            reqList.append('\n');
            reqList.append(reason);
        }
        ResolverException re = new ResolverException(MessageUtil.getMessage("RESOLVER_UNABLE_TO_RESOLVE", new Object[] { app.getApplicationMetadata().getApplicationName(), reqList }));
        re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
        log.debug(LOG_EXIT, "resolve", re);
        throw re;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ResolverException(org.apache.aries.application.management.ResolverException) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) ArrayList(java.util.ArrayList) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) BundleInfo(org.apache.aries.application.management.BundleInfo) OBRBundleInfo(org.apache.aries.application.resolver.obr.impl.OBRBundleInfo) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) HashSet(java.util.HashSet)

Example 5 with Resolver

use of org.apache.felix.bundlerepository.Resolver in project aries by apache.

the class OBRAriesResolver method resolveInIsolation.

@Override
public Collection<ModelledResource> resolveInIsolation(String appName, String appVersion, Collection<ModelledResource> byValueBundles, Collection<Content> inputs) throws ResolverException {
    log.debug(LOG_ENTRY, "resolve", new Object[] { appName, appVersion, byValueBundles, inputs });
    Collection<ImportedBundle> importedBundles = toImportedBundle(inputs);
    Resolver obrResolver = getConfiguredObrResolver(appName, appVersion, byValueBundles, true);
    // add a resource describing the requirements of the application metadata.
    obrResolver.add(createApplicationResource(appName, appVersion, importedBundles));
    log.debug(LOG_EXIT, "resolve");
    return doResolve(obrResolver, appName);
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) ImportedBundle(org.apache.aries.application.modelling.ImportedBundle)

Aggregations

Resolver (org.apache.felix.bundlerepository.Resolver)8 ArrayList (java.util.ArrayList)4 AriesApplicationResolver (org.apache.aries.application.management.spi.resolve.AriesApplicationResolver)4 Reason (org.apache.felix.bundlerepository.Reason)4 Resource (org.apache.felix.bundlerepository.Resource)4 ResolverException (org.apache.aries.application.management.ResolverException)2 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)2 Repository (org.apache.felix.bundlerepository.Repository)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MBeanException (javax.management.MBeanException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)1 Content (org.apache.aries.application.Content)1 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)1 BundleInfo (org.apache.aries.application.management.BundleInfo)1