Search in sources :

Example 1 with Deployer

use of org.apache.karaf.features.internal.service.Deployer in project karaf by apache.

the class Builder method resolve.

private Map<String, Integer> resolve(DownloadManager manager, Resolver resolver, Collection<Features> repositories, Collection<String> features, Collection<String> bundles, Collection<String> overrides, Collection<String> optionals) throws Exception {
    BundleRevision systemBundle = getSystemBundle();
    AssemblyDeployCallback callback = new AssemblyDeployCallback(manager, this, systemBundle, repositories);
    Deployer deployer = new Deployer(manager, resolver, callback, callback);
    // Install framework
    Deployer.DeploymentRequest request = createDeploymentRequest();
    // Add overrides
    request.overrides.addAll(overrides);
    // Add optional resources
    final List<Resource> resources = new ArrayList<>();
    Downloader downloader = manager.createDownloader();
    for (String optional : optionals) {
        downloader.download(optional, provider -> {
            Resource resource = ResourceBuilder.build(provider.getUrl(), getHeaders(provider));
            synchronized (resources) {
                resources.add(resource);
            }
        });
    }
    downloader.await();
    request.globalRepository = new BaseRepository(resources);
    // Install features
    for (String feature : features) {
        MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, feature);
    }
    for (String bundle : bundles) {
        MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, "bundle:" + bundle);
    }
    Set<String> prereqs = new HashSet<>();
    while (true) {
        try {
            deployer.deploy(callback.getDeploymentState(), request);
            break;
        } catch (Deployer.PartialDeploymentException e) {
            if (!prereqs.containsAll(e.getMissing())) {
                prereqs.addAll(e.getMissing());
            } else {
                throw new Exception("Deployment aborted due to loop in missing prerequisites: " + e.getMissing());
            }
        }
    }
    return callback.getStartupBundles();
}
Also used : ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) BaseRepository(org.apache.karaf.features.internal.repository.BaseRepository) Downloader(org.apache.karaf.features.internal.download.Downloader) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BundleRevision(org.osgi.framework.wiring.BundleRevision) Deployer(org.apache.karaf.features.internal.service.Deployer) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with Deployer

use of org.apache.karaf.features.internal.service.Deployer in project karaf by apache.

the class VerifyMojo method verifyResolution.

private void verifyResolution(DownloadManager manager, final Map<String, Features> repositories, Set<String> features, Hashtable<String, String> properties) throws MojoExecutionException {
    try {
        Bundle systemBundle = getSystemBundle(getMetadata(properties, "metadata#"));
        DummyDeployCallback callback = new DummyDeployCallback(systemBundle, repositories.values());
        Deployer deployer = new Deployer(manager, new ResolverImpl(new MavenResolverLog()), callback);
        // Install framework
        Deployer.DeploymentRequest request = Deployer.DeploymentRequest.defaultDeploymentRequest();
        for (String fmwk : framework) {
            MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, fmwk);
        }
        try {
            deployer.deploy(callback.getDeploymentState(), request);
        } catch (Exception e) {
            throw new MojoExecutionException("Unable to resolve framework features", e);
        }
        // Install features
        for (String feature : features) {
            MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, feature);
        }
        try {
            deployer.deployFully(callback.getDeploymentState(), request);
        // TODO: find unused resources ?
        } catch (Exception e) {
            throw new MojoExecutionException("Feature resolution failed for " + features + "\nMessage: " + (e instanceof ResolutionException ? e.getMessage() : e.toString()) + "\nRepositories: " + toString(new TreeSet<>(repositories.keySet())) + "\nResources: " + toString(new TreeSet<>(manager.getProviders().keySet())), e);
        }
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Error verifying feature " + features + "\nMessage: " + e.getMessage(), e);
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Bundle(org.osgi.framework.Bundle) TreeSet(java.util.TreeSet) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Deployer(org.apache.karaf.features.internal.service.Deployer) MultiException(org.apache.karaf.features.internal.util.MultiException) BundleException(org.osgi.framework.BundleException) ResolutionException(org.osgi.service.resolver.ResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 3 with Deployer

use of org.apache.karaf.features.internal.service.Deployer in project karaf by apache.

the class Builder method resolve.

/**
 * <p>Resolves set of features and bundles using OSGi resolver to calculate startup stage bundles.</p>
 * <p>Startup stage means that <em>current</em> state of the OSGi framework is just single system bundle installed
 * and bundles+features are being resolved against this single <em>bundle 0</em>.</p>
 *
 * @param manager {@link DownloadManager} to help downloading bundles and resources
 * @param resolver OSGi resolver which will resolve features and bundles in framework with only system bundle installed
 * @param repositories all available (not only to-be-installed) features
 * @param features feature identifiers to resolve
 * @param bundles bundle locations to resolve
 * @param optionals optional URI locations that'll be available through {@link org.osgi.service.repository.Repository},
 * used in resolution process
 * @param processor {@link FeaturesProcessor} to process repositories/features/bundles
 * @return map from bundle URI to bundle start-level
 * @throws Exception
 */
private Map<String, Integer> resolve(DownloadManager manager, Resolver resolver, Collection<Features> repositories, Collection<String> features, Collection<String> bundles, Collection<String> optionals, FeaturesProcessor processor) throws Exception {
    // System bundle will be single bundle installed with bundleId == 0
    BundleRevision systemBundle = getSystemBundle();
    // Static distribution building callback and deployer that's used to deploy/collect startup-stage artifacts
    AssemblyDeployCallback callback = new AssemblyDeployCallback(manager, this, systemBundle, repositories, processor);
    Deployer deployer = new Deployer(manager, resolver, callback);
    // Install framework
    Deployer.DeploymentRequest request = Deployer.DeploymentRequest.defaultDeploymentRequest();
    // Add optional resources available through OSGi resource repository
    request.globalRepository = repositoryOfOptionalResources(manager, optionals);
    // Specify feature requirements
    for (String feature : features) {
        // KARAF-5273: feature may be a pattern
        for (String featureName : FeatureSelector.getMatchingFeatures(feature, repositories)) {
            MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, featureName);
        }
    }
    // Specify bundle requirements
    for (String bundle : bundles) {
        MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, "bundle:" + bundle);
    }
    deployer.deployFully(callback.getDeploymentState(), request);
    return callback.getStartupBundles();
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision) Deployer(org.apache.karaf.features.internal.service.Deployer)

Aggregations

Deployer (org.apache.karaf.features.internal.service.Deployer)3 IOException (java.io.IOException)2 BundleRevision (org.osgi.framework.wiring.BundleRevision)2 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 TreeSet (java.util.TreeSet)1 ResolverImpl (org.apache.felix.resolver.ResolverImpl)1 Downloader (org.apache.karaf.features.internal.download.Downloader)1 BaseRepository (org.apache.karaf.features.internal.repository.BaseRepository)1 MultiException (org.apache.karaf.features.internal.util.MultiException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Bundle (org.osgi.framework.Bundle)1 BundleException (org.osgi.framework.BundleException)1 Resource (org.osgi.resource.Resource)1 ResolutionException (org.osgi.service.resolver.ResolutionException)1