use of org.apache.aries.application.InvalidAttributeException in project aries by apache.
the class ImportedServiceImpl method generateAttributeFilter.
private Filter generateAttributeFilter(Map<String, String> attrsToPopulate) throws InvalidAttributeException {
logger.debug(LOG_ENTRY, "generateAttributeFilter", new Object[] { attrsToPopulate });
Filter result = null;
try {
attrsToPopulate.put(ModellingConstants.OBR_SERVICE, ModellingConstants.OBR_SERVICE);
if (_blueprintFilter != null) {
// We may get blueprint filters of the form (&(a=b)(c=d)). We can't put these in 'whole' because we'll
// end up generating a filter of the form (&(objectClass=foo)(&(a=b)(c=d)) which subsequent calls to
// parseFilter will choke on. So as an interim fix we'll strip off a leading &( and trailing ) if present.
String reducedBlueprintFilter;
if (_blueprintFilter.startsWith("(&")) {
reducedBlueprintFilter = _blueprintFilter.substring(2, _blueprintFilter.length() - 1);
} else {
reducedBlueprintFilter = _blueprintFilter;
}
attrsToPopulate.put(ManifestHeaderProcessor.NESTED_FILTER_ATTRIBUTE, reducedBlueprintFilter);
}
if (_componentName != null) {
attrsToPopulate.put("osgi.service.blueprint.compname", _componentName);
}
if (_iface != null) {
attrsToPopulate.put(Constants.OBJECTCLASS, _iface);
}
_attribFilterString = ManifestHeaderProcessor.generateFilter(_attributes);
if (!"".equals(_attribFilterString)) {
result = FrameworkUtil.createFilter(FilterUtils.removeMandatoryFilterToken(_attribFilterString));
}
} catch (InvalidSyntaxException isx) {
InvalidAttributeException iax = new InvalidAttributeException("A syntax error occurred attempting to parse the blueprint filter string '" + _blueprintFilter + "' for element with id " + _id + ": " + isx.getLocalizedMessage(), isx);
logger.debug(LOG_EXIT, "generateAttributeFilter", new Object[] { isx });
throw iax;
}
logger.debug(LOG_EXIT, "generateAttributeFilter", new Object[] { result });
return result;
}
use of org.apache.aries.application.InvalidAttributeException in project aries by apache.
the class DeploymentManifestManagerImpl method generateDeployedBundles.
/**
* Perform provisioning to work out the 'freeze dried list' of the eba
* @param appContent - the application content in the application.mf
* @param useBundleContent - use bundle entry in the application.mf
* @param providedByValueBundles - bundles contained in the eba
* @return
* @throws ResolverException
*/
@Override
public DeployedBundles generateDeployedBundles(ApplicationMetadata appMetadata, Collection<ModelledResource> provideByValueBundles, Collection<Content> otherBundles) throws ResolverException {
Collection<Content> useBundleSet = appMetadata.getUseBundles();
Collection<Content> appContent = appMetadata.getApplicationContents();
Collection<Content> bundlesToResolve = new ArrayList<Content>();
Set<ImportedBundle> appContentIB = toImportedBundle(appContent);
Set<ImportedBundle> useBundleIB = toImportedBundle(useBundleSet);
bundlesToResolve.addAll(useBundleSet);
bundlesToResolve.addAll(appContent);
bundlesToResolve.addAll(otherBundles);
Collection<ModelledResource> byValueBundles = new ArrayList<ModelledResource>(provideByValueBundles);
ModelledResource fakeBundleResource;
try {
fakeBundleResource = createFakeBundle(appMetadata.getApplicationImportServices());
} catch (InvalidAttributeException iax) {
ResolverException rx = new ResolverException(iax);
_logger.debug(LOG_EXIT, "generateDeploymentManifest", new Object[] { rx });
throw rx;
}
byValueBundles.add(fakeBundleResource);
Collection<ModelledResource> fakeResources = new ArrayList<ModelledResource>();
for (PreResolveHook hook : preResolveHooks) {
hook.collectFakeResources(fakeResources);
}
byValueBundles.addAll(fakeResources);
String appSymbolicName = appMetadata.getApplicationSymbolicName();
String appVersion = appMetadata.getApplicationVersion().toString();
String uniqueName = appSymbolicName + "_" + appVersion;
DeployedBundles deployedBundles = modellingHelper.createDeployedBundles(appSymbolicName, appContentIB, useBundleIB, Arrays.asList(fakeBundleResource));
Collection<ModelledResource> bundlesToBeProvisioned = resolver.resolve(appSymbolicName, appVersion, byValueBundles, bundlesToResolve);
pruneFakeBundlesFromResults(bundlesToBeProvisioned, fakeResources);
if (bundlesToBeProvisioned.isEmpty()) {
throw new ResolverException(MessageUtil.getMessage("EMPTY_DEPLOYMENT_CONTENT", uniqueName));
}
for (ModelledResource rbm : bundlesToBeProvisioned) {
deployedBundles.addBundle(rbm);
}
Collection<ModelledResource> requiredUseBundle = deployedBundles.getRequiredUseBundle();
if (requiredUseBundle.size() < useBundleSet.size()) {
// Some of the use-bundle entries were redundant so resolve again with just the good ones.
deployedBundles = modellingHelper.createDeployedBundles(appSymbolicName, appContentIB, useBundleIB, Arrays.asList(fakeBundleResource));
bundlesToResolve.clear();
bundlesToResolve.addAll(appContent);
Collection<ImportedBundle> slimmedDownUseBundle = narrowUseBundles(useBundleIB, requiredUseBundle);
bundlesToResolve.addAll(toContent(slimmedDownUseBundle));
bundlesToBeProvisioned = resolver.resolve(appSymbolicName, appVersion, byValueBundles, bundlesToResolve);
pruneFakeBundlesFromResults(bundlesToBeProvisioned, fakeResources);
for (ModelledResource rbm : bundlesToBeProvisioned) {
deployedBundles.addBundle(rbm);
}
requiredUseBundle = deployedBundles.getRequiredUseBundle();
}
// Check for circular dependencies. No shared bundle can depend on any
// isolated bundle.
Collection<ModelledResource> sharedBundles = new HashSet<ModelledResource>();
sharedBundles.addAll(deployedBundles.getDeployedProvisionBundle());
sharedBundles.addAll(requiredUseBundle);
Collection<ModelledResource> appContentBundles = deployedBundles.getDeployedContent();
Collection<Content> requiredSharedBundles = new ArrayList<Content>();
for (ModelledResource mr : sharedBundles) {
String version = mr.getExportedBundle().getVersion();
String exactVersion = "[" + version + "," + version + "]";
Content ib = ContentFactory.parseContent(mr.getExportedBundle().getSymbolicName(), exactVersion);
requiredSharedBundles.add(ib);
}
// This will throw a ResolverException if the shared content does not resolve
Collection<ModelledResource> resolvedSharedBundles = resolver.resolve(appSymbolicName, appVersion, byValueBundles, requiredSharedBundles);
// we need to find out whether any shared bundles depend on the isolated bundles
List<String> suspects = findSuspects(resolvedSharedBundles, sharedBundles, appContentBundles);
// from isolated bundles. We need to build up the error message and throw a ResolverException
if (!suspects.isEmpty()) {
StringBuilder msgs = new StringBuilder();
List<String> unsatisfiedRequirements = new ArrayList<String>();
Map<String, List<String>> isolatedBundles = new HashMap<String, List<String>>();
// Find the isolated bundles and store all the packages that they export in a map.
for (ModelledResource mr : resolvedSharedBundles) {
String mrName = mr.getSymbolicName() + "_" + mr.getExportedBundle().getVersion();
if (suspects.contains(mrName)) {
List<String> exportedPackages = new ArrayList<String>();
isolatedBundles.put(mrName, exportedPackages);
for (ExportedPackage ep : mr.getExportedPackages()) {
exportedPackages.add(ep.getPackageName());
}
}
}
// are exported from the isolated bundles.
for (ModelledResource mr : resolvedSharedBundles) {
String mrName = mr.getSymbolicName() + "_" + mr.getExportedBundle().getVersion();
// if current resource isn't an isolated bundle check it's requirements
if (!!!suspects.contains(mrName)) {
// Iterate through the imported packages of the current shared bundle.
for (ImportedPackage ip : mr.getImportedPackages()) {
String packageName = ip.getPackageName();
List<String> bundlesExportingPackage = new ArrayList<String>();
// get a match store the info away.
for (Map.Entry<String, List<String>> currBundle : isolatedBundles.entrySet()) {
List<String> exportedPackages = currBundle.getValue();
if (exportedPackages != null && exportedPackages.contains(packageName)) {
bundlesExportingPackage.add(currBundle.getKey());
}
}
// exception.
if (!!!bundlesExportingPackage.isEmpty()) {
String newMsg;
if (bundlesExportingPackage.size() > 1) {
newMsg = MessageUtil.getMessage("SHARED_BUNDLE_IMPORTING_FROM_ISOLATED_BUNDLES", new Object[] { mrName, packageName, bundlesExportingPackage });
} else {
newMsg = MessageUtil.getMessage("SHARED_BUNDLE_IMPORTING_FROM_ISOLATED_BUNDLE", new Object[] { mrName, packageName, bundlesExportingPackage });
}
msgs.append("\n");
msgs.append(newMsg);
unsatisfiedRequirements.add(newMsg);
}
}
}
}
// Well! if the msgs is empty, no need to throw an exception
if (msgs.length() != 0) {
String message = MessageUtil.getMessage("SUSPECTED_CIRCULAR_DEPENDENCIES", new Object[] { appSymbolicName, msgs });
ResolverException rx = new ResolverException(message);
rx.setUnsatisfiedRequirements(unsatisfiedRequirements);
_logger.debug(LOG_EXIT, "generateDeploymentManifest", new Object[] { rx });
throw (rx);
}
}
checkForIsolatedContentInProvisionBundle(appSymbolicName, deployedBundles);
if (postResolveTransformer != null)
try {
deployedBundles = postResolveTransformer.postResolveProcess(appMetadata, deployedBundles);
} catch (ServiceUnavailableException e) {
_logger.debug(MessageUtil.getMessage("POST_RESOLVE_TRANSFORMER_UNAVAILABLE", e));
}
return deployedBundles;
}
use of org.apache.aries.application.InvalidAttributeException in project aries by apache.
the class ModellingHelperImpl method intersectPackage_.
public static ImportedPackage intersectPackage_(ImportedPackage p1, ImportedPackage p2) {
logger.debug(LOG_ENTRY, "intersectPackage_", new Object[] { p1, p2 });
ImportedPackage result = null;
if (p1.getPackageName().equals(p2.getPackageName())) {
Map<String, String> att1 = new HashMap<String, String>(p1.getAttributes());
Map<String, String> att2 = new HashMap<String, String>(p2.getAttributes());
// Get the versions, we remove them so that the remaining attributes can be matched.
String rangeStr1 = att1.remove(Constants.VERSION_ATTRIBUTE);
String rangeStr2 = att2.remove(Constants.VERSION_ATTRIBUTE);
// Also remove the optional directive as we don't care about that either
att1.remove(OPTIONAL_KEY);
att2.remove(OPTIONAL_KEY);
// If identical take either, otherwise null!
Map<String, String> mergedAttribs = (att1.equals(att2) ? att1 : null);
if (mergedAttribs == null) {
// Cannot intersect requirements if attributes are not identical.
result = null;
} else {
boolean isIntersectSuccessful = true;
if (rangeStr1 != null && rangeStr2 != null) {
// Both requirements have a version constraint so check for an intersection between them.
VersionRange range1 = ManifestHeaderProcessor.parseVersionRange(rangeStr1);
VersionRange range2 = ManifestHeaderProcessor.parseVersionRange(rangeStr2);
VersionRange intersectRange = range1.intersect(range2);
if (intersectRange == null) {
// No intersection possible.
isIntersectSuccessful = false;
} else {
// Use the intersected version range.
mergedAttribs.put(Constants.VERSION_ATTRIBUTE, intersectRange.toString());
}
} else if (rangeStr1 != null) {
mergedAttribs.put(Constants.VERSION_ATTRIBUTE, rangeStr1);
} else if (rangeStr2 != null) {
mergedAttribs.put(Constants.VERSION_ATTRIBUTE, rangeStr2);
}
// If both optional, we are optional, otherwise use the default
if (p1.isOptional() && p2.isOptional()) {
mergedAttribs.put(OPTIONAL_KEY, Constants.RESOLUTION_OPTIONAL);
}
try {
result = (isIntersectSuccessful ? new ImportedPackageImpl(p1.getPackageName(), mergedAttribs) : null);
} catch (InvalidAttributeException iax) {
logger.error(iax.getMessage());
}
}
}
logger.debug(LOG_EXIT, "intersectPackage_", result);
return result;
}
use of org.apache.aries.application.InvalidAttributeException in project aries by apache.
the class OBRAriesResolver method doResolve.
private Collection<ModelledResource> doResolve(Resolver obrResolver, String appName) throws ResolverException {
log.debug(LOG_ENTRY, "doResolve");
Collection<ModelledResource> toReturn = new ArrayList<ModelledResource>();
if (obrResolver.resolve()) {
List<Resource> requiredResources = retrieveRequiredResources(obrResolver);
if (requiredResources == null) {
log.debug("resolver.getRequiredResources() returned null");
} else {
for (Resource r : requiredResources) {
Map<String, String> attribs = new HashMap<String, String>();
attribs.put(Constants.VERSION_ATTRIBUTE, "[" + r.getVersion() + ',' + r.getVersion() + "]");
ModelledResource modelledResourceForThisMatch = null;
// list of packages available in the target runtime environment. If the resource has no symbolic name, we can ignore it
if (r.getSymbolicName() != null) {
try {
modelledResourceForThisMatch = new ModelledBundleResource(r, modellingManager, modellingHelper);
} catch (InvalidAttributeException iax) {
ResolverException re = new ResolverException("Internal error occurred: " + iax);
log.debug(LOG_EXIT, "doResolve", re);
throw re;
}
toReturn.add(modelledResourceForThisMatch);
}
}
}
log.debug(LOG_EXIT, toReturn);
return toReturn;
} else {
Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
// let's 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[] { appName, reqList }));
re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
log.debug(LOG_EXIT, "doResolve", re);
throw re;
}
}
use of org.apache.aries.application.InvalidAttributeException in project aries by apache.
the class SharedFrameworkPreResolveHook method collectFakeResources.
@Override
public void collectFakeResources(Collection<ModelledResource> resources) {
Bundle b = fwMgr.getSharedBundleFramework().getIsolatedBundleContext().getBundle(1);
BundleInfo info = new BundleInfoImpl(b);
Collection<ImportedService> serviceImports = Collections.emptySet();
Collection<ExportedService> serviceExports = Collections.emptySet();
try {
resources.add(mgr.getModelledResource(info.getLocation(), info, serviceImports, serviceExports));
} catch (InvalidAttributeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations