Search in sources :

Example 1 with ContentVerificationPolicy

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

the class LocalPatchOperationStepHandler method executeRuntime.

private void executeRuntime(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    // Acquire the lock and check the write permissions for this operation
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final InstallationManager installationManager = (InstallationManager) registry.getRequiredService(InstallationManagerService.NAME).getValue();
    if (installationManager.requiresRestart()) {
        throw PatchLogger.ROOT_LOGGER.serverRequiresRestart();
    }
    try {
        final PatchTool runner = PatchTool.Factory.create(installationManager);
        final ContentVerificationPolicy policy = PatchTool.Factory.create(operation);
        final int index = operation.get(ModelDescriptionConstants.INPUT_STREAM_INDEX).asInt(0);
        final InputStream is = context.getAttachmentStream(index);
        installationManager.restartRequired();
        final PatchingResult result = runner.applyPatch(is, policy);
        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();
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PatchingException(org.jboss.as.patching.PatchingException) InputStream(java.io.InputStream) InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) ContentVerificationPolicy(org.jboss.as.patching.tool.ContentVerificationPolicy) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with ContentVerificationPolicy

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

the class LocalPatchRollbackHandler 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 String patchId = PatchResourceDefinition.PATCH_ID.resolveModelAttribute(context, operation).asString();
    final boolean rollbackTo = PatchResourceDefinition.ROLLBACK_TO.resolveModelAttribute(context, operation).asBoolean();
    final boolean restoreConfiguration = 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.rollback(patchStream, patchId, policy, rollbackTo, restoreConfiguration);
        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 3 with ContentVerificationPolicy

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

Aggregations

OperationContext (org.jboss.as.controller.OperationContext)3 PatchingException (org.jboss.as.patching.PatchingException)3 ContentVerificationPolicy (org.jboss.as.patching.tool.ContentVerificationPolicy)3 PatchTool (org.jboss.as.patching.tool.PatchTool)3 PatchingResult (org.jboss.as.patching.tool.PatchingResult)3 ModelNode (org.jboss.dmr.ModelNode)3 InputStream (java.io.InputStream)1 InstallationManager (org.jboss.as.patching.installation.InstallationManager)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1