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