@Override public Identity getIdentity() { return patch.getIdentity(); }
@Override public Identity getIdentity() { return patch.getIdentity(); }
/** * Create a patch representing what we actually processed. This may contain some fixed content hashes for removed * modules. * * @param original the original * @return the processed patch */ protected Patch createProcessedPatch(final Patch original) { // Process elements final List<PatchElement> elements = new ArrayList<PatchElement>(); // Process layers for (final PatchEntry entry : getLayers()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Process add-ons for (final PatchEntry entry : getAddOns()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Swap the patch element modifications, keep the identity ones since we don't need to fix the misc modifications return new PatchImpl(original.getPatchId(), original.getDescription(), original.getLink(), original.getIdentity(), elements, identityEntry.modifications); }
/** * Create a patch representing what we actually processed. This may contain some fixed content hashes for removed * modules. * * @param original the original * @return the processed patch */ protected Patch createProcessedPatch(final Patch original) { // Process elements final List<PatchElement> elements = new ArrayList<PatchElement>(); // Process layers for (final PatchEntry entry : getLayers()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Process add-ons for (final PatchEntry entry : getAddOns()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Swap the patch element modifications, keep the identity ones since we don't need to fix the misc modifications return new PatchImpl(original.getPatchId(), original.getDescription(), original.getLink(), original.getIdentity(), elements, identityEntry.modifications); }
protected PatchingResult apply(final PatchMetadataResolver patchResolver, final PatchContentProvider contentProvider, final ContentVerificationPolicy contentPolicy) throws PatchingException { // Apply the patch final org.jboss.as.patching.metadata.Identity identity = patchResolver.resolvePatch(null, null).getIdentity(); final InstallationManager.InstallationModification modification = ((InstallationManagerImpl)manager). getInstalledIdentity(identity.getName(), identity.getVersion()).modifyInstallation(callback); try { return runner.applyPatch(patchResolver, contentProvider, contentPolicy, modification); } catch (Exception e) { modification.cancel(); throw rethrowException(e); } }
protected PatchingResult apply(final PatchMetadataResolver patchResolver, final PatchContentProvider contentProvider, final ContentVerificationPolicy contentPolicy) throws PatchingException { // Apply the patch final org.jboss.as.patching.metadata.Identity identity = patchResolver.resolvePatch(null, null).getIdentity(); final InstallationManager.InstallationModification modification = ((InstallationManagerImpl)manager). getInstalledIdentity(identity.getName(), identity.getVersion()).modifyInstallation(callback); try { return runner.applyPatch(patchResolver, contentProvider, contentPolicy, modification); } catch (Exception e) { modification.cancel(); throw rethrowException(e); } }
public static void assertInstallationIsPatched(Patch patch, PatchableTarget.TargetInfo targetInfo) { if (CUMULATIVE == patch.getIdentity().getPatchType()) { assertEquals(patch.getPatchId(), targetInfo.getCumulativePatchID()); } else { Assert.assertTrue(targetInfo.getPatchIDs().contains(patch.getPatchId())); // applied one-off patch is at the top of the patchIDs assertEquals(patch.getPatchId(), targetInfo.getPatchIDs().get(0)); } } }
@Test public void testParseOneOff() throws Exception { final InputStream is = getResource("patch-02-ONE-OFF.xml"); final Patch patch = PatchXml.parse(is).resolvePatch(null, null); // One-off Patch assertNotNull(patch); assertNotNull(patch.getPatchId()); assertNotNull(patch.getDescription()); final Identity identity = patch.getIdentity(); assertNotNull(identity); assertNotNull(patch.getIdentity().getVersion()); }
public static void assertPatchHasBeenApplied(PatchingResult result, Patch patch) { if (CUMULATIVE == patch.getIdentity().getPatchType()) { assertEquals(patch.getPatchId(), result.getPatchInfo().getCumulativePatchID()); assertTrue(result.getPatchInfo().getPatchIDs().isEmpty()); assertEquals(patch.getIdentity().forType(CUMULATIVE, org.jboss.as.patching.metadata.Identity.IdentityUpgrade.class).getResultingVersion(), result.getPatchInfo().getVersion()); } else { assertTrue(result.getPatchInfo().getPatchIDs().contains(patch.getPatchId())); // applied one-off patch is at the top of the patchIDs assertEquals(patch.getPatchId(), result.getPatchInfo().getPatchIDs().get(0)); } }
protected PatchingResult rollback(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions, boolean rollbackTo) throws PatchingException { final Patch patch = builder.build(); final File installation = new File(tempDir, JBOSS_INSTALLATION); try { assertions.before(installation, patch, installationManager); } catch (IOException e) { throw new PatchingException(e); } final String patchId = patch.getPatchId(); final PatchTool patchTool = PatchTool.Factory.create(installationManager); final PatchingResult result = patchTool.rollback(patchId, verificationPolicy, rollbackTo, false); result.commit(); final InstalledIdentity identity = installationManager.getInstalledIdentity(patch.getIdentity().getName(), null); Assert.assertFalse(identity.getAllInstalledPatches().contains(patch.getPatchId())); try { assertions.after(installation, patch, installationManager); } catch (IOException e) { throw new PatchingException(e); } return result; }
static void assertNotApplied(final Patch patch, InstallationManager manager) throws IOException { InstalledIdentity installedIdentity = null; try { installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), patch.getIdentity().getVersion()); } catch (PatchingException e) { Assert.fail(e.getLocalizedMessage()); } final PatchableTarget.TargetInfo identity = installedIdentity.getIdentity().loadTargetInfo(); assertNotApplied(patch.getIdentity().getPatchType(), patch.getPatchId(), identity); assertDoesNotExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patch.getPatchId())); for (final PatchElement element : patch.getElements()) { final PatchElementProvider provider = element.getProvider(); final PatchableTarget target = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName()); Assert.assertNotNull(target); assertNotApplied(provider.getPatchType(), element.getId(), target.loadTargetInfo()); } }
protected PatchingResult apply(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions) throws PatchingException { final Patch patch = builder.build(); final File installation = new File(tempDir, JBOSS_INSTALLATION); try { assertions.before(installation, patch, installationManager); } catch (IOException e) { throw new PatchingException(e); } // Write patch writePatch(builder.getPatchDir(), patch); // Create the patch tool and apply the patch final PatchTool patchTool = PatchTool.Factory.create(installationManager); final PatchingResult result = patchTool.applyPatch(builder.getPatchDir(), verificationPolicy); result.commit(); final InstalledIdentity identity = ((InstallationManagerImpl)installationManager).getInstalledIdentity(patch.getIdentity().getName(), null); Assert.assertTrue(identity.getAllInstalledPatches().contains(patch.getPatchId())); try { assertions.after(installation, patch, installationManager); } catch (IOException e) { throw new PatchingException(e); } return result; }
@Test public void testAddRemove() throws Exception { final Patch cp1 = generateCP("base", "cp1", ModificationType.ADD); final Patch cp2 = generateCP("cp1", "cp2", ModificationType.REMOVE); final Patch merged = PatchMerger.merge(cp1, cp2); assertEquals("cp2", merged.getPatchId()); assertEquals("cp2" + " description", merged.getDescription()); final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class); assertEquals("base", identity.getVersion()); assertEquals("cp2", identity.getResultingVersion()); assertEquals(PatchType.CUMULATIVE, identity.getPatchType()); final List<PatchElement> elements = merged.getElements(); assertEquals(1, elements.size()); final PatchElement e = elements.get(0); assertEquals("base-" + "cp2", e.getId()); final PatchElementProvider provider = e.getProvider(); assertEquals("base", provider.getName()); assertEquals(PatchType.CUMULATIVE, provider.getPatchType()); assertEquals(LayerType.Layer, provider.getLayerType()); //assertEquals(0, e.getModifications().size()); // for modules remove is effectively a modify which changes the module xml to indicate an absent module // so, it will remain an add of an absent module assertEquals(1, e.getModifications().size()); final ContentModification mod = e.getModifications().iterator().next(); assertEquals(ModificationType.ADD, mod.getType()); Assert.assertArrayEquals(PatchUtils.getAbsentModuleContentHash((ModuleItem) mod.getItem()), mod.getItem().getContentHash()); }
static void assertApplied(final Patch patch, InstallationManager manager) throws IOException { final String patchID = patch.getPatchId(); InstalledIdentity installedIdentity = null; try { installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null); } catch (PatchingException e) { Assert.fail(e.getLocalizedMessage()); } final PatchableTarget target = installedIdentity.getIdentity(); final PatchableTarget.TargetInfo identity = target.loadTargetInfo(); assertIsApplied(patch.getIdentity().getPatchType(), patchID, identity); assertExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patchID)); assertContentItems(patchID, target, patch.getModifications()); for (final PatchElement element : patch.getElements()) { final PatchElementProvider provider = element.getProvider(); final PatchableTarget targetElement = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName()); assertIsApplied(provider.getPatchType(), element.getId(), targetElement.loadTargetInfo()); assertContentItems(element.getId(), targetElement, element.getModifications()); } }
@Test public void testParseCP() throws Exception { final InputStream is = getResource("patch-01-CP.xml"); final Patch patch = PatchXml.parse(is).resolvePatch(null, null); // Cumulative Patch assertNotNull(patch); assertNotNull(patch.getPatchId()); assertNotNull(patch.getDescription()); final Identity identity = patch.getIdentity(); assertNotNull(identity); assertEquals(Patch.PatchType.CUMULATIVE, identity.getPatchType()); assertNotNull(identity.forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class).getResultingVersion()); assertNotNull(identity.getVersion()); }
private void displayPatchXml(CommandContext ctx, Patch patch) throws CommandException { final Identity identity = patch.getIdentity(); SimpleTable table = new SimpleTable(2, ctx.getTerminalWidth()); table.addLine(new String[]{"Patch ID:", patch.getPatchId()}); table.addLine(new String[]{"Type:", identity.getPatchType().getName()}); table.addLine(new String[]{"Identity name:", identity.getName()}); table.addLine(new String[]{"Identity version:", identity.getVersion()}); table.addLine(new String[]{"Description:", patch.getDescription() == null ? "n/a" : patch.getDescription()}); if (patch.getLink() != null) { table.addLine(new String[]{"Link:", patch.getLink()}); } ctx.printLine(table.toString(false)); if (verbose) { ctx.printLine(""); ctx.printLine("ELEMENTS"); for (PatchElement e : patch.getElements()) { table = new SimpleTable(2, ctx.getTerminalWidth()); table.addLine(new String[]{"Patch ID:", e.getId()}); table.addLine(new String[]{"Name:", e.getProvider().getName()}); table.addLine(new String[]{"Type:", e.getProvider().isAddOn() ? Constants.ADD_ON : Constants.LAYER}); table.addLine(new String[]{"Description:", e.getDescription()}); ctx.printLine(""); ctx.printLine(table.toString(false)); } } } }
private void displayPatchXml(CommandContext ctx, Patch patch) throws CommandException { final Identity identity = patch.getIdentity(); SimpleTable table = new SimpleTable(2, ctx.getTerminalWidth()); table.addLine(new String[]{"Patch ID:", patch.getPatchId()}); table.addLine(new String[]{"Type:", identity.getPatchType().getName()}); table.addLine(new String[]{"Identity name:", identity.getName()}); table.addLine(new String[]{"Identity version:", identity.getVersion()}); table.addLine(new String[]{"Description:", patch.getDescription() == null ? "n/a" : patch.getDescription()}); if (patch.getLink() != null) { table.addLine(new String[]{"Link:", patch.getLink()}); } ctx.printLine(table.toString(false)); if (verbose) { ctx.printLine(""); ctx.printLine("ELEMENTS"); for (PatchElement e : patch.getElements()) { table = new SimpleTable(2, ctx.getTerminalWidth()); table.addLine(new String[]{"Patch ID:", e.getId()}); table.addLine(new String[]{"Name:", e.getProvider().getName()}); table.addLine(new String[]{"Type:", e.getProvider().isAddOn() ? Constants.ADD_ON : Constants.LAYER}); table.addLine(new String[]{"Description:", e.getDescription()}); ctx.printLine(""); ctx.printLine(table.toString(false)); } } } }
private void displayPatchXml(CommandContext ctx, Patch patch) throws CommandLineException { final Identity identity = patch.getIdentity(); SimpleTable table = new SimpleTable(2, ctx.getTerminalWidth()); table.addLine(new String[]{"Patch ID:", patch.getPatchId()}); table.addLine(new String[]{"Type:", identity.getPatchType().getName()}); table.addLine(new String[]{"Identity name:", identity.getName()}); table.addLine(new String[]{"Identity version:", identity.getVersion()}); table.addLine(new String[]{"Description:", patch.getDescription() == null ? "n/a" : patch.getDescription()}); if (patch.getLink() != null) { table.addLine(new String[]{"Link:", patch.getLink()}); } ctx.printLine(table.toString(false)); if(verbose.isPresent(ctx.getParsedCommandLine())) { ctx.printLine(""); ctx.printLine("ELEMENTS"); for(PatchElement e : patch.getElements()) { table = new SimpleTable(2, ctx.getTerminalWidth()); table.addLine(new String[]{"Patch ID:", e.getId()}); table.addLine(new String[]{"Name:", e.getProvider().getName()}); table.addLine(new String[]{"Type:", e.getProvider().isAddOn() ? Constants.ADD_ON : Constants.LAYER}); table.addLine(new String[]{"Description:", e.getDescription()}); ctx.printLine(""); ctx.printLine(table.toString(false)); } } }
assertEquals("cp2" + " description", merged.getDescription()); final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class); assertEquals("base", identity.getVersion()); assertEquals("cp2", identity.getResultingVersion());
assertEquals("cp2" + " description", merged.getDescription()); final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class); assertEquals("base", identity.getVersion()); assertEquals("cp2", identity.getResultingVersion());