Search in sources :

Example 1 with ResolveConstraint

use of org.apache.aries.application.management.ResolveConstraint 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 2 with ResolveConstraint

use of org.apache.aries.application.management.ResolveConstraint in project aries by apache.

the class IsolatedRuntimeTest method testAppWithGlobalRepositoryBundle.

@Test
@Ignore
public void testAppWithGlobalRepositoryBundle() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
    IsolationTestUtils.prepareSampleBundleV2(bundleContext, context().getService(RepositoryGenerator.class), context().getService(RepositoryAdmin.class), context().getService(ModellingManager.class));
    AriesApplication newApp = manager.resolve(app, new ResolveConstraint() {

        @Override
        public String getBundleName() {
            return "org.apache.aries.isolated.sample";
        }

        @Override
        public VersionRange getVersionRange() {
            return ManifestHeaderProcessor.parseVersionRange("[2.0.0,2.0.0]", true);
        }
    });
    AriesApplicationContext ctx = manager.install(newApp);
    ctx.start();
    assertHelloWorldService("org.apache.aries.sample2", "hello brave new world");
    manager.uninstall(ctx);
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) ModellingManager(org.apache.aries.application.modelling.ModellingManager) VersionRange(org.apache.aries.util.VersionRange) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 3 with ResolveConstraint

use of org.apache.aries.application.management.ResolveConstraint in project aries by apache.

the class UpdateAppTest method updateApp.

private AriesApplicationContext updateApp(AriesApplicationManager manager, AriesApplication app) throws Exception {
    IsolationTestUtils.prepareSampleBundleV2(bundleContext, context().getService(RepositoryGenerator.class), context().getService(RepositoryAdmin.class), context().getService(ModellingManager.class));
    AriesApplication newApp = manager.resolve(app, new ResolveConstraint() {

        public String getBundleName() {
            return "org.apache.aries.isolated.sample";
        }

        public VersionRange getVersionRange() {
            return ManifestHeaderProcessor.parseVersionRange("[2.0.0,2.0.0]", true);
        }
    });
    return manager.update(app, newApp.getDeploymentMetadata());
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) ModellingManager(org.apache.aries.application.modelling.ModellingManager) AriesApplication(org.apache.aries.application.management.AriesApplication) VersionRange(org.apache.aries.util.VersionRange)

Example 4 with ResolveConstraint

use of org.apache.aries.application.management.ResolveConstraint in project aries by apache.

the class DeploymentManifestManagerImpl method generateDeploymentManifest.

/**
   * Perform provisioning to work out the 'freeze dried list' of the eba
   * @param app - Aries application
   * @param ResolveConstraint - resolver constraint for limiting the resolving results
   * @return manifest the generated deployment manifest
   * @throws ResolverException
   */
@Override
public Manifest generateDeploymentManifest(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
    _logger.debug(LOG_ENTRY, "generateDeploymentManifest", new Object[] { app, constraints });
    ApplicationMetadata appMetadata = app.getApplicationMetadata();
    Collection<ModelledResource> byValueBundles = null;
    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());
    //If we pass in provision bundles (e.g. import deployment manifest sanity check), we add them into our bundlesToResolve set.
    // This is because we want to make sure all bundles we passed into resolver the same as what we are going to get from resolver. 
    List<Content> restrictedReqs = new ArrayList<Content>();
    for (ResolveConstraint constraint : constraints) {
        Content content = ContentFactory.parseContent(constraint.getBundleName(), constraint.getVersionRange().toString());
        restrictedReqs.add(content);
    }
    DeployedBundles deployedBundles = generateDeployedBundles(appMetadata, byValueBundles, restrictedReqs);
    Manifest man = generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    _logger.debug(LOG_EXIT, "generateDeploymentManifest", new Object[] { man });
    return man;
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) ResolverException(org.apache.aries.application.management.ResolverException) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Manifest(java.util.jar.Manifest) ResolverException(org.apache.aries.application.management.ResolverException) IOException(java.io.IOException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) ServiceUnavailableException(org.osgi.service.blueprint.container.ServiceUnavailableException) ModellerException(org.apache.aries.application.modelling.ModellerException) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Aggregations

ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)4 ArrayList (java.util.ArrayList)2 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)2 Content (org.apache.aries.application.Content)2 AriesApplication (org.apache.aries.application.management.AriesApplication)2 ResolverException (org.apache.aries.application.management.ResolverException)2 RepositoryGenerator (org.apache.aries.application.management.spi.repository.RepositoryGenerator)2 ModelledResource (org.apache.aries.application.modelling.ModelledResource)2 ModellingManager (org.apache.aries.application.modelling.ModellingManager)2 VersionRange (org.apache.aries.util.VersionRange)2 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)2 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Manifest (java.util.jar.Manifest)1 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)1 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)1 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)1 BundleInfo (org.apache.aries.application.management.BundleInfo)1