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);
}
}
}
}
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;
}
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"));
}
}
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);
}
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());
}
}
Aggregations