Search in sources :

Example 6 with Resolver

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

the class ObrMBeanImpl method deployBundle.

public void deployBundle(String bundle, boolean start, boolean deployOptional) throws MBeanException {
    try {
        Resolver resolver = repositoryAdmin.resolver();
        String[] target = getTarget(bundle);
        Resource resource = selectNewestVersion(searchRepository(repositoryAdmin, target[0], target[1]));
        if (resource == null) {
            throw new IllegalArgumentException("Unknown bundle " + target[0]);
        }
        resolver.add(resource);
        if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
            if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
                try {
                    resolver.deploy(start ? Resolver.START : 0);
                } catch (IllegalStateException ex) {
                    throw new IllegalStateException("Can't deploy using OBR", ex);
                }
            }
        }
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MBeanException(javax.management.MBeanException)

Example 7 with Resolver

use of org.apache.felix.bundlerepository.Resolver 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 8 with Resolver

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

the class ResolveCommand method doExecute.

protected void doExecute(RepositoryAdmin admin) throws Exception {
    List<Repository> repositories = new ArrayList<>();
    repositories.add(admin.getSystemRepository());
    if (!noLocal) {
        repositories.add(admin.getLocalRepository());
    }
    if (!noRemote) {
        repositories.addAll(Arrays.asList(admin.listRepositories()));
    }
    Resolver resolver = admin.resolver(repositories.toArray(new Repository[repositories.size()]));
    for (Requirement requirement : parseRequirements(admin, requirements)) {
        resolver.add(requirement);
    }
    if (resolver.resolve(optional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
        Resource[] resources;
        resources = resolver.getRequiredResources();
        if ((resources != null) && (resources.length > 0)) {
            System.out.println("Required resource(s):");
            printUnderline(System.out, 21);
            for (Resource resource : resources) {
                System.out.println("   " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
                if (why) {
                    Reason[] req = resolver.getReason(resource);
                    for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
                        if (!req[reqIdx].getRequirement().isOptional()) {
                            Resource r = req[reqIdx].getResource();
                            if (r != null) {
                                System.out.println("      - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                            } else {
                                System.out.println("      - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                            }
                        }
                    }
                }
            }
        }
        resources = resolver.getOptionalResources();
        if ((resources != null) && (resources.length > 0)) {
            System.out.println();
            System.out.println("Optional resource(s):");
            printUnderline(System.out, 21);
            for (Resource resource : resources) {
                System.out.println("   " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
                if (why) {
                    Reason[] req = resolver.getReason(resource);
                    for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
                        if (!req[reqIdx].getRequirement().isOptional()) {
                            Resource r = req[reqIdx].getResource();
                            if (r != null) {
                                System.out.println("      - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                            } else {
                                System.out.println("      - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                            }
                        }
                    }
                }
            }
        }
        if (deploy || start) {
            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().getName() + ":" + req.getRequirement().getFilter());
                System.out.println("      " + req.getResource().getPresentationName());
            }
        } else {
            System.out.println("Could not resolve targets.");
        }
    }
}
Also used : Requirement(org.apache.felix.bundlerepository.Requirement) Repository(org.apache.felix.bundlerepository.Repository) Resolver(org.apache.felix.bundlerepository.Resolver) ArrayList(java.util.ArrayList) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason)

Aggregations

Resolver (org.apache.felix.bundlerepository.Resolver)8 ArrayList (java.util.ArrayList)4 AriesApplicationResolver (org.apache.aries.application.management.spi.resolve.AriesApplicationResolver)4 Reason (org.apache.felix.bundlerepository.Reason)4 Resource (org.apache.felix.bundlerepository.Resource)4 ResolverException (org.apache.aries.application.management.ResolverException)2 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)2 Repository (org.apache.felix.bundlerepository.Repository)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MBeanException (javax.management.MBeanException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)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