Search in sources :

Example 6 with PatchingException

use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.

the class AbstractPatchingTest method writePatch.

protected static void writePatch(final File patchRoot, final Patch patch) throws PatchingException {
    FileOutputStream os = null;
    try {
        os = new FileOutputStream(new File(patchRoot, PatchXml.PATCH_XML));
        PatchXml.marshal(os, patch);
    } catch (Exception e) {
        throw new PatchingException(e);
    } finally {
        IoUtils.safeClose(os);
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException)

Example 7 with PatchingException

use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.

the class AbstractPatchingTest method apply.

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;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) InstallationManagerImpl(org.jboss.as.patching.installation.InstallationManagerImpl) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) Patch(org.jboss.as.patching.metadata.Patch) File(java.io.File)

Example 8 with PatchingException

use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.

the class AbstractPatchingTest method rollback.

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;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Patch(org.jboss.as.patching.metadata.Patch) File(java.io.File)

Example 9 with PatchingException

use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.

the class IdentityPatchRunner method applyPatch.

/**
 * Apply a patch.
 *
 * @param patchId the patch id
 * @param patch   the patch metadata
 * @param context the patch context
 * @throws PatchingException
 * @throws IOException
 * @throws XMLStreamException
 */
private PatchingResult applyPatch(final String patchId, final Patch patch, final IdentityPatchContext context) throws PatchingException, IOException, XMLStreamException {
    final Identity identity = patch.getIdentity();
    final Patch.PatchType patchType = identity.getPatchType();
    final InstallationManager.InstallationModification modification = context.getModification();
    if (patchType == Patch.PatchType.CUMULATIVE) {
        // Invalidate all installed patches (one-off, cumulative) - we never need to invalidate the release base
        final List<String> invalidation = new ArrayList<String>(modification.getPatchIDs());
        if (!invalidation.isEmpty()) {
            try {
                // Before rolling back the one-off patches, validate that the state until that point is consistent
                validateRollbackState(invalidation.get(invalidation.size() - 1), modification.getUnmodifiedInstallationState());
            } catch (PatchingException e) {
                throw e;
            } catch (Exception e) {
                throw new PatchingException(e);
            }
            // Invalidate the installed patches first
            for (final String rollback : invalidation) {
                rollback(rollback, context);
            }
        }
    }
    // Add to installed patches list
    modification.addInstalledPatch(patchId);
    // Then apply the current patch
    for (final PatchElement element : patch.getElements()) {
        // Apply the content modifications
        final IdentityPatchContext.PatchEntry target = context.resolveForElement(element);
        final PatchElementProvider provider = element.getProvider();
        final Patch.PatchType elementPatchType = provider.getPatchType();
        final String elementPatchId = element.getId();
        // See if we can skip this element
        if (target.isApplied(elementPatchId)) {
            // This needs some further testing, maybe we need to compare our history with the patch if they are consistent
            throw PatchLogger.ROOT_LOGGER.alreadyApplied(elementPatchId);
        }
        // Check upgrade conditions
        checkUpgradeConditions(provider, target);
        apply(elementPatchId, element.getModifications(), target);
        target.apply(elementPatchId, elementPatchType);
    }
    // Apply the patch to the identity
    final IdentityPatchContext.PatchEntry identityEntry = context.getIdentityEntry();
    apply(patchId, patch.getModifications(), identityEntry);
    identityEntry.apply(patchId, patchType);
    // Port forward missing module changes
    if (patchType == Patch.PatchType.CUMULATIVE) {
        portForward(patch, context);
    }
    // We need the resulting version for rollback
    if (patchType == Patch.PatchType.CUMULATIVE) {
        final Identity.IdentityUpgrade upgrade = identity.forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
        identityEntry.setResultingVersion(upgrade.getResultingVersion());
    }
    // Execute the tasks
    final IdentityApplyCallback callback = new IdentityApplyCallback(patch, identityEntry.getDirectoryStructure());
    try {
        return executeTasks(context, callback);
    } catch (Exception e) {
        context.cancel(callback);
        throw rethrowException(e);
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) ArrayList(java.util.ArrayList) PatchElement(org.jboss.as.patching.metadata.PatchElement) XMLStreamException(javax.xml.stream.XMLStreamException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) Identity(org.jboss.as.patching.metadata.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchType(org.jboss.as.patching.metadata.Patch.PatchType) Patch(org.jboss.as.patching.metadata.Patch) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch) PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)

Example 10 with PatchingException

use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.

the class PatchToolImpl method rollback.

@Override
public PatchingResult rollback(final String streamName, final String patchId, final ContentVerificationPolicy contentPolicy, final boolean rollbackTo, final boolean resetConfiguration) throws PatchingException {
    InstalledIdentity targetIdentity = null;
    if (streamName == null) {
        for (InstalledIdentity identity : manager.getInstalledIdentities()) {
            if (identity.getAllInstalledPatches().contains(patchId)) {
                if (targetIdentity != null) {
                    throw new PatchingException(PatchLogger.ROOT_LOGGER.patchIdFoundInMoreThanOneStream(patchId, targetIdentity.getIdentity().getName(), identity.getIdentity().getName()));
                }
                targetIdentity = identity;
            }
        }
        if (targetIdentity == null) {
            throw PatchLogger.ROOT_LOGGER.patchNotFoundInHistory(patchId);
        }
    } else {
        targetIdentity = manager.getInstalledIdentity(streamName, null);
    }
    // Rollback the patch
    final InstallationManager.InstallationModification modification = targetIdentity.modifyInstallation(runner);
    try {
        return runner.rollbackPatch(patchId, contentPolicy, rollbackTo, resetConfiguration, modification);
    } catch (Exception e) {
        modification.cancel();
        throw rethrowException(e);
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) XMLStreamException(javax.xml.stream.XMLStreamException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException)

Aggregations

PatchingException (org.jboss.as.patching.PatchingException)39 File (java.io.File)20 IOException (java.io.IOException)19 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 XMLStreamException (javax.xml.stream.XMLStreamException)9 Patch (org.jboss.as.patching.metadata.Patch)9 PatchTool (org.jboss.as.patching.tool.PatchTool)8 PatchingResult (org.jboss.as.patching.tool.PatchingResult)8 InstallationManager (org.jboss.as.patching.installation.InstallationManager)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)5 InputStream (java.io.InputStream)4 BundledPatch (org.jboss.as.patching.metadata.BundledPatch)4 PatchElement (org.jboss.as.patching.metadata.PatchElement)4 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)4 ModelNode (org.jboss.dmr.ModelNode)4 OperationContext (org.jboss.as.controller.OperationContext)3 ContentModification (org.jboss.as.patching.metadata.ContentModification)3 Identity (org.jboss.as.patching.metadata.Identity)3