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();
}
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);
}
}
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();
}
Aggregations