Search in sources :

Example 1 with PatchException

use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.

the class PatchServiceImpl method applyChanges.

private void applyChanges(Map<Bundle, String> toUpdate) throws BundleException, IOException {
    List<Bundle> toStop = new ArrayList<Bundle>();
    Map<Bundle, String> lessToUpdate = new HashMap<>();
    for (Bundle b : toUpdate.keySet()) {
        if (b.getState() != Bundle.UNINSTALLED) {
            toStop.add(b);
            lessToUpdate.put(b, toUpdate.get(b));
        }
    }
    while (!toStop.isEmpty()) {
        List<Bundle> bs = getBundlesToDestroy(toStop);
        for (Bundle bundle : bs) {
            String hostHeader = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
            if (hostHeader == null && (bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STARTING)) {
                if (!"org.ops4j.pax.url.mvn".equals(bundle.getSymbolicName())) {
                    bundle.stop();
                }
            }
            toStop.remove(bundle);
        }
    }
    // eagerly load some classes
    try {
        getClass().getClassLoader().loadClass(Parser.class.getName());
        getClass().getClassLoader().loadClass(Clause.class.getName());
        getClass().getClassLoader().loadClass(Attribute.class.getName());
        getClass().getClassLoader().loadClass(Directive.class.getName());
        getClass().getClassLoader().loadClass(RefreshListener.class.getName());
    } catch (Exception ignored) {
    }
    Set<Bundle> toRefresh = new HashSet<Bundle>();
    Set<Bundle> toStart = new HashSet<Bundle>();
    for (Map.Entry<Bundle, String> e : lessToUpdate.entrySet()) {
        Bundle bundle = e.getKey();
        if (!"org.ops4j.pax.url.mvn".equals(bundle.getSymbolicName())) {
            System.out.println("updating: " + bundle.getSymbolicName());
            try {
                update(bundle, new URL(e.getValue()));
            } catch (BundleException ex) {
                System.err.println("Failed to update: " + bundle.getSymbolicName() + ", due to: " + e);
            }
            toStart.add(bundle);
            toRefresh.add(bundle);
        }
    }
    findBundlesWithOptionalPackagesToRefresh(toRefresh);
    findBundlesWithFragmentsToRefresh(toRefresh);
    if (!toRefresh.isEmpty()) {
        final CountDownLatch l = new CountDownLatch(1);
        FrameworkListener listener = new RefreshListener(l);
        FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        wiring.refreshBundles(toRefresh, listener);
        try {
            l.await();
        } catch (InterruptedException e) {
            throw new PatchException("Bundle refresh interrupted", e);
        }
    }
    for (Bundle bundle : toStart) {
        String hostHeader = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
        if (hostHeader == null) {
            try {
                bundle.start();
            } catch (BundleException e) {
                System.err.println("Failed to start: " + bundle.getSymbolicName() + ", due to: " + e);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Attribute(org.apache.felix.utils.manifest.Attribute) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) CountDownLatch(java.util.concurrent.CountDownLatch) URISyntaxException(java.net.URISyntaxException) PatchException(org.jboss.fuse.patch.management.PatchException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) URL(java.net.URL) Parser(org.apache.felix.utils.manifest.Parser) Clause(org.apache.felix.utils.manifest.Clause) BundleException(org.osgi.framework.BundleException) PatchException(org.jboss.fuse.patch.management.PatchException) FrameworkListener(org.osgi.framework.FrameworkListener) Directive(org.apache.felix.utils.manifest.Directive) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with PatchException

use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.

the class PatchServiceImpl method checkConsistency.

/**
 * Check if the set of patches mixes P and R patches. We can install several {@link PatchKind#NON_ROLLUP}
 * patches at once, but only one {@link PatchKind#ROLLUP} patch.
 * @param patches
 * @return kind of patches in the set
 */
private PatchKind checkConsistency(Collection<Patch> patches) throws PatchException {
    boolean hasP = false;
    boolean hasR = false;
    for (Patch patch : patches) {
        if (patch.getPatchData().isRollupPatch()) {
            if (hasR) {
                throw new PatchException("Can't install more than one rollup patch at once");
            }
            hasR = true;
        } else {
            hasP = true;
        }
    }
    if (hasR && hasP) {
        throw new PatchException("Can't install both rollup and non-rollup patches in single run");
    }
    return hasR ? PatchKind.ROLLUP : PatchKind.NON_ROLLUP;
}
Also used : PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch)

Example 3 with PatchException

use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.

the class PatchServiceImplTest method testCheckPrerequisitesMissing.

@Test
public void testCheckPrerequisitesMissing() throws IOException {
    PatchServiceImpl service = createMockServiceImpl(getDirectoryForResource("prereq/patch1.patch"));
    Patch patch = service.getPatch("patch1");
    assertNotNull(patch);
    try {
        service.checkPrerequisites(patch);
        fail("Patch will missing prerequisites should not pass check");
    } catch (PatchException e) {
        assertTrue(e.getMessage().toLowerCase().contains("required patch 'prereq1' is missing"));
    }
}
Also used : PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch) Test(org.junit.Test)

Example 4 with PatchException

use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.

the class RollbackCommand method doExecute.

@Override
protected void doExecute(PatchService service) throws Exception {
    Patch patch = service.getPatch(patchId);
    if (patch == null) {
        throw new PatchException("Patch '" + patchId + "' not found");
    }
    if (!patch.isInstalled()) {
        throw new PatchException("Patch '" + patchId + "' is not installed");
    }
    if (patch.getPatchData().getMigratorBundle() != null) {
        throw new PatchException("Patch '" + patchId + "' does not support rollback");
    }
    service.rollback(patch, simulation, false);
}
Also used : PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch)

Example 5 with PatchException

use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.

the class ShowCommand method doExecute.

@Override
protected void doExecute(PatchService service) throws Exception {
    Patch patch = patchManagement.loadPatch(new PatchDetailsRequest(patchId, bundles, files, diff));
    if (patch == null) {
        throw new PatchException("Patch '" + patchId + "' not found");
    }
    System.out.println(String.format("Patch ID: %s", patch.getPatchData().getId()));
    if (patch.getManagedPatch() != null) {
        System.out.println(String.format("Patch Commit ID: %s", patch.getManagedPatch().getCommitId()));
    }
    if (bundles) {
        System.out.println(String.format("#### %d Bundles%s", patch.getPatchData().getBundles().size(), patch.getPatchData().getBundles().size() == 0 ? "" : ":"));
        iterate(patch.getPatchData().getBundles());
    }
    if (files) {
        ManagedPatch details = patch.getManagedPatch();
        System.out.println(String.format("#### %d Files added%s", details.getFilesAdded().size(), details.getFilesAdded().size() == 0 ? "" : ":"));
        iterate(details.getFilesAdded());
        System.out.println(String.format("#### %d Files modified%s", details.getFilesModified().size(), details.getFilesModified().size() == 0 ? "" : ":"));
        iterate(details.getFilesModified());
        System.out.println(String.format("#### %d Files removed%s", details.getFilesRemoved().size(), details.getFilesRemoved().size() == 0 ? "" : ":"));
        iterate(details.getFilesRemoved());
    }
    if (diff) {
        System.out.println("#### Patch changes:\n" + patch.getManagedPatch().getUnifiedDiff());
    }
}
Also used : ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch) ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) PatchDetailsRequest(org.jboss.fuse.patch.management.PatchDetailsRequest)

Aggregations

PatchException (org.jboss.fuse.patch.management.PatchException)25 IOException (java.io.IOException)14 Patch (org.jboss.fuse.patch.management.Patch)14 File (java.io.File)12 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)8 Git (org.eclipse.jgit.api.Git)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 LinkedList (java.util.LinkedList)6 URISyntaxException (java.net.URISyntaxException)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 BundleException (org.osgi.framework.BundleException)5 Map (java.util.Map)4 RevTag (org.eclipse.jgit.revwalk.RevTag)4 ManagedPatch (org.jboss.fuse.patch.management.ManagedPatch)4 LinkedHashSet (java.util.LinkedHashSet)3 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)3