use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeployedBundlesImpl method getExternalPackageRequirements.
/**
* Get all the requirements of bundles in deployed content that are not satisfied
* by other bundles in deployed content.
* @return a collection of package requirements.
* @throws ResolverException if the requirements could not be resolved.
*/
private Collection<ImportedPackage> getExternalPackageRequirements() throws ResolverException {
logger.debug(LOG_ENTRY, "getExternalPackageRequirements");
Collection<ImportedPackage> result = cachedExternalRequirements;
if (result == null) {
// Get all the internal requirements.
Collection<ImportedPackage> requirements = new ArrayList<ImportedPackage>();
Collection<ExportedPackage> internalExports = new ArrayList<ExportedPackage>();
for (ModelledResource bundle : deployedContent) {
requirements.addAll(bundle.getImportedPackages());
internalExports.addAll(bundle.getExportedPackages());
}
// Filter out requirements satisfied by internal capabilities.
result = new ArrayList<ImportedPackage>();
for (ImportedPackage req : requirements) {
boolean satisfied = false;
for (ExportedPackage export : internalExports) {
if (req.isSatisfied(export)) {
satisfied = true;
break;
}
}
//If we didn't find a match then it must come from outside
if (!satisfied)
result.add(req);
}
PackageRequirementMerger merger = new PackageRequirementMerger(result);
if (!merger.isMergeSuccessful()) {
List<String> pkgNames = new ArrayList<String>(merger.getInvalidRequirements());
StringBuilder buff = new StringBuilder();
for (String pkgName : merger.getInvalidRequirements()) {
buff.append(pkgName).append(", ");
}
int buffLen = buff.length();
String pkgString = (buffLen > 0 ? buff.substring(0, buffLen - 2) : "");
ResolverException re = new ResolverException(MessageUtil.getMessage("INCOMPATIBLE_PACKAGE_VERSION_REQUIREMENTS", new Object[] { assetName, pkgString }));
re.setUnsatisfiedRequirements(pkgNames);
logger.debug(LOG_EXIT, "getExternalPackageRequirements", re);
throw re;
}
result = merger.getMergedRequirements();
cachedExternalRequirements = result;
}
logger.debug(LOG_EXIT, "getExternalPackageRequirements", result);
return result;
}
use of org.apache.aries.application.modelling.ModelledResource 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.modelling.ModelledResource in project aries by apache.
the class AbstractEJBModellerTest method testEJBJARAndAnnotatedNotOnClasspathInZip.
@Test
public void testEJBJARAndAnnotatedNotOnClasspathInZip() throws Exception {
ModelledResource mr = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
addToZip(zos, "MANIFEST_2.MF", "META-INF/MANIFEST.MF");
addToZip(zos, "ejb-jar.xml", "META-INF/ejb-jar.xml");
addToZip(zos, "beans/StatelessSessionBean.class", "no/beans/StatelessSessionBean.class");
addToZip(zos, "beans/StatefulSessionBean.class", "no/beans/StatefulSessionBean.class");
zos.close();
mr = model(baos.toByteArray());
Collection<? extends ExportedService> services = mr.getExportedServices();
assertEquals("Wrong number of services", 2, services.size());
assertTrue(services.containsAll(getXMLservices()));
assertTrue(Collections.disjoint(services, getAnnotatedservices()));
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class AbstractEJBModellerTest method testEJBJARAndAnnotatedOnClasspathInZip.
@Test
public void testEJBJARAndAnnotatedOnClasspathInZip() throws Exception {
ModelledResource mr = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
addToZip(zos, "MANIFEST_2.MF", "META-INF/MANIFEST.MF");
addToZip(zos, "ejb-jar.xml", "META-INF/ejb-jar.xml");
addToZip(zos, "beans/StatelessSessionBean.class", "yes/beans/StatelessSessionBean.class");
addToZip(zos, "beans/StatefulSessionBean.class", "yes/beans/StatefulSessionBean.class");
zos.close();
mr = model(baos.toByteArray());
Collection<? extends ExportedService> services = mr.getExportedServices();
assertEquals("Wrong number of services", 3, services.size());
assertTrue(services.containsAll(getXMLservices()));
assertTrue(services.containsAll(getAnnotatedservices()));
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class AbstractEJBModellerTest method testEJBJARAndAnnotatedNotOnClasspathInWebZip.
@Test
public void testEJBJARAndAnnotatedNotOnClasspathInWebZip() throws Exception {
ModelledResource mr = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
addToZip(zos, "MANIFEST_4.MF", "META-INF/MANIFEST.MF");
addToZip(zos, "ejb-jar.xml", "WEB-INF/ejb-jar.xml");
addToZip(zos, "beans/StatelessSessionBean.class", "no/beans/StatelessSessionBean.class");
addToZip(zos, "beans/StatefulSessionBean.class", "no/beans/StatefulSessionBean.class");
zos.close();
mr = model(baos.toByteArray());
Collection<? extends ExportedService> services = mr.getExportedServices();
assertEquals("Wrong number of services", 2, services.size());
assertTrue(services.containsAll(getXMLservices()));
assertTrue(Collections.disjoint(services, getAnnotatedservices()));
}
Aggregations