Search in sources :

Example 6 with ModelledResource

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;
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) PackageRequirementMerger(org.apache.aries.application.modelling.internal.PackageRequirementMerger) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage)

Example 7 with ModelledResource

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;
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) Set(java.util.Set) HashSet(java.util.HashSet) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)

Example 8 with ModelledResource

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()));
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 9 with ModelledResource

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()));
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 10 with ModelledResource

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()));
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Aggregations

ModelledResource (org.apache.aries.application.modelling.ModelledResource)41 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ZipOutputStream (java.util.zip.ZipOutputStream)11 ResolverException (org.apache.aries.application.management.ResolverException)11 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)11 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)10 File (java.io.File)8 Content (org.apache.aries.application.Content)8 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)7 FileOutputStream (java.io.FileOutputStream)6 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 Manifest (java.util.jar.Manifest)5 AriesApplication (org.apache.aries.application.management.AriesApplication)5 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)5 HashMap (java.util.HashMap)4 Attributes (java.util.jar.Attributes)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4