Search in sources :

Example 31 with PatchingException

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

the class LocalPatchRollbackLastHandler method execute.

@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstallationManager installationManager, final String patchStream) throws OperationFailedException {
    if (installationManager.requiresRestart()) {
        throw PatchLogger.ROOT_LOGGER.serverRequiresRestart();
    }
    final boolean resetConfiguration = PatchResourceDefinition.RESET_CONFIGURATION.resolveModelAttribute(context, operation).asBoolean();
    final PatchTool runner = PatchTool.Factory.create(installationManager);
    final ContentVerificationPolicy policy = PatchTool.Factory.create(operation);
    try {
        // Rollback
        final PatchingResult result = runner.rollbackLast(patchStream, policy, resetConfiguration);
        installationManager.restartRequired();
        context.restartRequired();
        context.completeStep(new OperationContext.ResultHandler() {

            @Override
            public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
                if (resultAction == OperationContext.ResultAction.KEEP) {
                    result.commit();
                } else {
                    installationManager.clearRestartRequired();
                    context.revertRestartRequired();
                    result.rollback();
                }
            }
        });
    } catch (PatchingException e) {
        final ModelNode failureDescription = context.getFailureDescription();
        PatchOperationTarget.formatFailedResponse(e, failureDescription);
        installationManager.clearRestartRequired();
    } finally {
    // 
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) ContentVerificationPolicy(org.jboss.as.patching.tool.ContentVerificationPolicy) ModelNode(org.jboss.dmr.ModelNode)

Example 32 with PatchingException

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

the class LocalAgeoutHistoryHandler method execute.

@Override
protected void execute(OperationContext context, ModelNode operation, InstallationManager instMgr, String patchStream) throws OperationFailedException {
    try {
        if (patchStream != null) {
            final InstalledIdentity installedIdentity = instMgr.getInstalledIdentity(patchStream, null);
            ageOutHistory(installedIdentity);
        } else {
            for (InstalledIdentity installedIdentity : instMgr.getInstalledIdentities()) {
                ageOutHistory(installedIdentity);
            }
        }
    } catch (PatchingException e) {
        throw new IllegalStateException(PatchLogger.ROOT_LOGGER.failedToLoadIdentity(), e);
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException)

Example 33 with PatchingException

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

the class PatchMerger method copyModificationContent.

private static void copyModificationContent(final File srcPatchDir, final String srcElementId, final File targetPatchDir, final String targetElementId, final ContentModification mod) throws PatchingException {
    final ModificationType type = mod.getType();
    if (type.equals(ModificationType.REMOVE)) {
        return;
    }
    File modSrcDir = new File(srcPatchDir, srcElementId);
    File modTrgDir = new File(targetPatchDir, targetElementId);
    final ContentType contentType = mod.getItem().getContentType();
    if (ContentType.MISC.equals(contentType)) {
        modSrcDir = new File(modSrcDir, Constants.MISC);
        modTrgDir = new File(modTrgDir, Constants.MISC);
        for (final String path : ((MiscContentItem) mod.getItem()).getPath()) {
            modSrcDir = new File(modSrcDir, path);
            modTrgDir = new File(modTrgDir, path);
        }
        copyDir(modSrcDir, modTrgDir);
    } else {
        final String slot;
        if (contentType.equals(ContentType.MODULE)) {
            modSrcDir = new File(modSrcDir, Constants.MODULES);
            modTrgDir = new File(modTrgDir, Constants.MODULES);
            slot = ((ModuleItem) mod.getItem()).getSlot();
        } else if (contentType.equals(ContentType.BUNDLE)) {
            modSrcDir = new File(modSrcDir, Constants.BUNDLES);
            modTrgDir = new File(modTrgDir, Constants.BUNDLES);
            slot = ((BundleItem) mod.getItem()).getSlot();
        } else {
            throw new PatchingException("Unexpected content type " + contentType);
        }
        for (String name : mod.getItem().getName().split("\\.")) {
            modSrcDir = new File(modSrcDir, name);
            modTrgDir = new File(modTrgDir, name);
        }
        modSrcDir = new File(modSrcDir, slot);
        modTrgDir = new File(modTrgDir, slot);
        copyDir(modSrcDir, modTrgDir);
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) File(java.io.File)

Example 34 with PatchingException

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

the class PatchMerger method expandContent.

private static File expandContent(File patchFile, final File workDir, final String expandDirName) throws PatchingException {
    final File patchDir;
    try {
        if (!patchFile.isDirectory()) {
            patchDir = new File(workDir, expandDirName);
            // Save the content
            final File cachedContent = new File(patchDir, "content");
            IoUtils.copy(patchFile, cachedContent);
            // Unpack to the work dir
            ZipUtils.unzip(cachedContent, patchDir);
        } else {
            patchDir = patchFile;
        }
    } catch (IOException e) {
        throw new PatchingException("Failed to unzip " + patchFile.getAbsolutePath());
    }
    return patchDir;
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) File(java.io.File)

Example 35 with PatchingException

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

the class PatchStepAssertions method assertNotApplied.

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());
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement)

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