Search in sources :

Example 1 with Reason

use of org.apache.felix.bundlerepository.Reason in project karaf by apache.

the class ObrCommandSupport method doDeploy.

protected void doDeploy(RepositoryAdmin admin, List<String> bundles, boolean start, boolean deployOptional) throws Exception {
    Resolver resolver = admin.resolver();
    for (String bundle : bundles) {
        String[] target = getTarget(bundle);
        Resource resource = selectNewestVersion(searchRepository(admin, target[0], target[1]));
        if (resource != null) {
            resolver.add(resource);
        } else {
            System.err.println("Unknown bundle - " + target[0]);
        }
    }
    if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
        if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
            System.out.println("Target resource(s):");
            printUnderline(System.out, 19);
            Resource[] resources = resolver.getAddedResources();
            for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
                System.out.println("   " + getResourceId(resources[resIdx]) + " (" + resources[resIdx].getVersion() + ")");
            }
            resources = resolver.getRequiredResources();
            if ((resources != null) && (resources.length > 0)) {
                System.out.println("\nRequired resource(s):");
                printUnderline(System.out, 21);
                for (Resource resource : resources) {
                    System.out.println("   " + getResourceId(resource) + " (" + resource.getVersion() + ")");
                }
            }
            if (deployOptional) {
                resources = resolver.getOptionalResources();
                if ((resources != null) && (resources.length > 0)) {
                    System.out.println("\nOptional resource(s):");
                    printUnderline(System.out, 21);
                    for (Resource resource : resources) {
                        System.out.println("   " + getResourceId(resource) + " (" + resource.getVersion() + ")");
                    }
                }
            }
            try {
                System.out.print("\nDeploying...");
                resolver.deploy(start ? Resolver.START : 0);
                System.out.println("done.");
            } catch (IllegalStateException ex) {
                System.err.println(ex);
            }
        } else {
            Reason[] reqs = resolver.getUnsatisfiedRequirements();
            if ((reqs != null) && (reqs.length > 0)) {
                System.out.println("Unsatisfied requirement(s):");
                printUnderline(System.out, 27);
                for (Reason req : reqs) {
                    System.out.println("   " + req.getRequirement().getFilter());
                    System.out.println("      " + getResourceId(req.getResource()));
                }
            } else {
                System.out.println("Could not resolve targets.");
            }
        }
    }
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason)

Example 2 with Reason

use of org.apache.felix.bundlerepository.Reason in project felix by apache.

the class ResolverWrapper method getUnsatisfiedRequirementsMap.

private Map getUnsatisfiedRequirementsMap() {
    Reason[] reasons = resolver.getUnsatisfiedRequirements();
    Map map = new HashMap();
    for (int i = 0; i < reasons.length; i++) {
        org.osgi.service.obr.Requirement req = Wrapper.wrap(reasons[i].getRequirement());
        org.osgi.service.obr.Resource res = Wrapper.wrap(reasons[i].getResource());
        List l = (List) map.get(req);
        if (l == null) {
            l = new ArrayList();
            map.put(req, l);
        }
        l.add(res);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Reason(org.apache.felix.bundlerepository.Reason)

Example 3 with Reason

use of org.apache.felix.bundlerepository.Reason in project felix by apache.

the class ObrCommandImpl method _deploy.

private void _deploy(ParsedCommand pc, String command, PrintStream out, PrintStream err) throws IOException, InvalidSyntaxException {
    org.apache.felix.bundlerepository.Resolver resolver = m_repoAdmin.resolver();
    for (int i = 0; (pc != null) && (i < pc.getTargetCount()); i++) {
        // Find the target's bundle resource.
        Resource resource = selectNewestVersion(searchRepository(pc.getTargetId(i), pc.getTargetVersion(i)));
        if (resource != null) {
            resolver.add(resource);
        } else {
            err.println("Unknown bundle - " + pc.getTargetId(i));
        }
    }
    if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
        if (resolver.resolve()) {
            out.println("Target resource(s):");
            printUnderline(out, 19);
            Resource[] resources = resolver.getAddedResources();
            for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
                out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
            }
            resources = resolver.getRequiredResources();
            if ((resources != null) && (resources.length > 0)) {
                out.println("\nRequired resource(s):");
                printUnderline(out, 21);
                for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                    out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                }
            }
            resources = resolver.getOptionalResources();
            if ((resources != null) && (resources.length > 0)) {
                out.println("\nOptional resource(s):");
                printUnderline(out, 21);
                for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                    out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                }
            }
            try {
                out.print("\nDeploying...");
                resolver.deploy(command.equals(START_CMD) ? Resolver.START : 0);
                out.println("done.");
            } catch (IllegalStateException ex) {
                err.println(ex);
            }
        } else {
            Reason[] reqs = resolver.getUnsatisfiedRequirements();
            if ((reqs != null) && (reqs.length > 0)) {
                out.println("Unsatisfied requirement(s):");
                printUnderline(out, 27);
                for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
                    out.println("   " + reqs[reqIdx].getRequirement().getFilter());
                    out.println("      " + reqs[reqIdx].getResource().getPresentationName());
                }
            } else {
                out.println("Could not resolve targets.");
            }
        }
    }
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason)

Example 4 with Reason

use of org.apache.felix.bundlerepository.Reason in project aries by apache.

the class OBRAriesResolver method satisfiesAll.

protected boolean satisfiesAll(Resource res, Reason[] reasons) {
    log.debug(LOG_ENTRY, "satisfiesAll", new Object[] { res, Arrays.toString(reasons) });
    // Let's convert the reason to requirement
    List<Requirement> reqs = new ArrayList<Requirement>();
    for (Reason reason : reasons) {
        reqs.add(reason.getRequirement());
    }
    boolean result = true;
    outer: for (Requirement r : reqs) {
        boolean found = false;
        inner: for (Capability c : res.getCapabilities()) {
            if (r.isSatisfied(c)) {
                found = true;
                break inner;
            }
        }
        if (!!!found && !!!r.isOptional()) {
            result = false;
            break outer;
        }
    }
    log.debug(LOG_EXIT, "satisfiesAll", result);
    return result;
}
Also used : Requirement(org.apache.felix.bundlerepository.Requirement) Capability(org.apache.felix.bundlerepository.Capability) ArrayList(java.util.ArrayList) Reason(org.apache.felix.bundlerepository.Reason)

Example 5 with Reason

use of org.apache.felix.bundlerepository.Reason 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;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ResolverException(org.apache.aries.application.management.ResolverException) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) 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) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) BundleInfo(org.apache.aries.application.management.BundleInfo) OBRBundleInfo(org.apache.aries.application.resolver.obr.impl.OBRBundleInfo) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) HashSet(java.util.HashSet)

Aggregations

Reason (org.apache.felix.bundlerepository.Reason)11 Resolver (org.apache.felix.bundlerepository.Resolver)7 Resource (org.apache.felix.bundlerepository.Resource)7 ArrayList (java.util.ArrayList)6 Requirement (org.apache.felix.bundlerepository.Requirement)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ModelledResource (org.apache.aries.application.modelling.ModelledResource)3 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)3 Capability (org.apache.felix.bundlerepository.Capability)3 Map (java.util.Map)2 ResolverException (org.apache.aries.application.management.ResolverException)2 Version (org.osgi.framework.Version)2 List (java.util.List)1 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)1 Content (org.apache.aries.application.Content)1 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)1 BundleInfo (org.apache.aries.application.management.BundleInfo)1 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)1