Search in sources :

Example 16 with InstalledIdentity

use of org.jboss.as.patching.installation.InstalledIdentity 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)

Example 17 with InstalledIdentity

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

the class PatchToolImpl method applyPatchBundle.

protected PatchingResult applyPatchBundle(final File workDir, final BundledPatch bundledPatch, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException {
    final List<BundledPatchEntry> patches = bundledPatch.getPatches();
    if (patches.isEmpty()) {
        throw new PatchingException(PatchLogger.ROOT_LOGGER.patchBundleIsEmpty());
    }
    PatchingResult result = null;
    BundledPatchEntry lastCommittedEntry = null;
    final List<BundledPatch.BundledPatchEntry> results = new ArrayList<BundledPatch.BundledPatchEntry>(patches.size());
    final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities();
    for (BundledPatchEntry entry : patches) {
        // TODO this has to be checked against the specific one targeted by the patch
        boolean alreadyApplied = false;
        for (InstalledIdentity identity : installedIdentities) {
            if (identity.getAllInstalledPatches().contains(entry.getPatchId())) {
                alreadyApplied = true;
                break;
            }
        }
        if (alreadyApplied) {
            continue;
        }
        if (result != null) {
            result.commit();
            results.add(0, lastCommittedEntry);
        }
        final File patch = new File(workDir, entry.getPatchPath());
        final FileInputStream is = new FileInputStream(patch);
        PatchingResult currentResult = null;
        try {
            currentResult = applyPatch(workDir, is, contentPolicy);
        } catch (PatchingException e) {
            // Undo the changes included as part of this patch
            for (BundledPatch.BundledPatchEntry committed : results) {
                try {
                    rollback(committed.getPatchId(), contentPolicy, false, false).commit();
                } catch (PatchingException oe) {
                    PatchLogger.ROOT_LOGGER.debugf(oe, "failed to rollback patch '%s'", committed.getPatchId());
                }
            }
            throw e;
        } finally {
            safeClose(is);
        }
        if (currentResult != null) {
            result = currentResult;
            lastCommittedEntry = entry;
        }
    }
    if (result == null) {
        throw new PatchingException();
    }
    return new WrappedMultiInstallPatch(result, contentPolicy, results);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) ArrayList(java.util.ArrayList) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) FileInputStream(java.io.FileInputStream) BundledPatchEntry(org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry) PatchingResult(org.jboss.as.patching.tool.PatchingResult) File(java.io.File)

Example 18 with InstalledIdentity

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

the class RollbackPatchXml_1_0 method handleRootElement.

@Override
protected void handleRootElement(String localName, XMLExtendedStreamReader reader, PatchBuilder patch, InstalledIdentity originalIdentity) throws XMLStreamException {
    final RollbackPatchBuilder builder = (RollbackPatchBuilder) patch;
    final Element element = Element.forName(localName);
    if (element == Element.INSTALLATION) {
        final InstalledIdentity identity = processInstallation(reader, originalIdentity);
        builder.setIdentity(identity);
    } else {
        throw unexpectedElement(reader);
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)

Example 19 with InstalledIdentity

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

the class PatchAttributeReadHandler method execute.

@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException {
    final ModelNode result = context.getResult();
    final Identity info = installedIdentity.getIdentity();
    try {
        handle(result, info);
    } catch (IOException e) {
        throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(info.getName()), e);
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : OperationFailedException(org.jboss.as.controller.OperationFailedException) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) Identity(org.jboss.as.patching.installation.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity)

Example 20 with InstalledIdentity

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

the class PatchStreamResourceOperationStepHandler method execute.

protected void execute(OperationContext context, ModelNode operation, InstallationManager instMgr, String patchStream) throws OperationFailedException {
    final InstalledIdentity installedIdentity;
    if (patchStream != null) {
        try {
            installedIdentity = instMgr.getInstalledIdentity(patchStream, null);
        } catch (PatchingException e) {
            throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(patchStream), e);
        }
    } else {
        installedIdentity = instMgr.getDefaultIdentity();
    }
    execute(context, operation, installedIdentity);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)44 File (java.io.File)23 Patch (org.jboss.as.patching.metadata.Patch)19 Test (org.junit.Test)19 ContentModification (org.jboss.as.patching.metadata.ContentModification)17 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)17 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)17 PatchingResult (org.jboss.as.patching.tool.PatchingResult)16 PatchingException (org.jboss.as.patching.PatchingException)15 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)15 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)14 IOException (java.io.IOException)8 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)8 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)8 PatchElement (org.jboss.as.patching.metadata.PatchElement)5 Identity (org.jboss.as.patching.installation.Identity)4 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)4 ArrayList (java.util.ArrayList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 InstallationManager (org.jboss.as.patching.installation.InstallationManager)3