Search in sources :

Example 26 with InstalledIdentity

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

the class RollbackTargetArtifact method process.

@Override
public boolean process(PatchingXmlArtifact.XmlArtifactState<RollbackPatch> parent, PatchingArtifactProcessor processor) {
    final RollbackPatch patch = parent.getPatch();
    final PatchingArtifacts.PatchID patchID = processor.getParentArtifact(PatchingArtifacts.HISTORY_RECORD);
    final InstalledIdentity identity = patch.getIdentityState();
    processor.getValidationContext().setCurrentPatchIdentity(identity);
    final State state = new State(identity, patchID);
    if (identity == null) {
        processor.getValidationContext().getErrorHandler().addMissing(PatchingArtifacts.ROLLBACK_TARGET, state);
        return false;
    } else {
        return processor.process(this, state);
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch)

Example 27 with InstalledIdentity

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

the class IdentityPatchContext method createRollbackPatch.

/**
 * Create a rollback patch based on the recorded actions.
 *
 * @param patchId   the new patch id, depending on release or one-off
 * @param patchType the current patch identity
 * @return the rollback patch
 */
protected RollbackPatch createRollbackPatch(final String patchId, final Patch.PatchType patchType) {
    // Process elements
    final List<PatchElement> elements = new ArrayList<PatchElement>();
    // Process layers
    for (final PatchEntry entry : getLayers()) {
        final PatchElement element = createRollbackElement(entry);
        elements.add(element);
    }
    // Process add-ons
    for (final PatchEntry entry : getAddOns()) {
        final PatchElement element = createRollbackElement(entry);
        elements.add(element);
    }
    final InstalledIdentity installedIdentity = modification.getUnmodifiedInstallationState();
    final String name = installedIdentity.getIdentity().getName();
    final IdentityImpl identity = new IdentityImpl(name, modification.getVersion());
    if (patchType == Patch.PatchType.CUMULATIVE) {
        identity.setPatchType(Patch.PatchType.CUMULATIVE);
        identity.setResultingVersion(installedIdentity.getIdentity().getVersion());
    } else if (patchType == Patch.PatchType.ONE_OFF) {
        identity.setPatchType(Patch.PatchType.ONE_OFF);
    }
    final List<ContentModification> modifications = identityEntry.rollbackActions;
    final Patch delegate = new PatchImpl(patchId, "rollback patch", identity, elements, modifications);
    return new PatchImpl.RollbackPatchImpl(delegate, installedIdentity);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) ArrayList(java.util.ArrayList) IdentityImpl(org.jboss.as.patching.metadata.impl.IdentityImpl) PatchElement(org.jboss.as.patching.metadata.PatchElement) PatchImpl(org.jboss.as.patching.metadata.PatchImpl) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch)

Example 28 with InstalledIdentity

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

the class PatchableTargetsArtifact method process.

@Override
public boolean process(PatchingXmlArtifact.XmlArtifactState<Patch> parent, PatchingArtifactProcessor processor) {
    final InstalledIdentity identity = processor.getValidationContext().getInstalledIdentity();
    final Patch patch = parent.getPatch();
    if (Constants.BASE.equals(patch.getPatchId())) {
        return true;
    }
    final List<PatchElement> elements = patch.getElements();
    boolean valid = true;
    if (elements != null && !elements.isEmpty()) {
        for (final PatchElement element : elements) {
            final String patchID = element.getId();
            final PatchElementProvider provider = element.getProvider();
            final String layerName = provider.getName();
            final PatchableTarget target = provider.isAddOn() ? identity.getAddOn(layerName) : identity.getLayer(layerName);
            boolean modules = false;
            boolean bundles = false;
            for (final ContentModification modification : element.getModifications()) {
                if (modules && bundles) {
                    break;
                }
                if (modification.getItem().getContentType() == ContentType.BUNDLE) {
                    bundles = true;
                } else if (modification.getItem().getContentType() == ContentType.MODULE) {
                    modules = true;
                }
            }
            final PatchableTargetState state = new PatchableTargetState(patchID, layerName, target, bundles, modules);
            if (!processor.process(PatchingArtifacts.LAYER, state)) {
                valid = false;
            }
        }
    }
    // In case there are misc content modifications also validate that misc backup exists
    for (final ContentModification modification : patch.getModifications()) {
        if (modification.getType() != ModificationType.ADD && modification.getItem().getContentType() == ContentType.MISC) {
            final PatchingHistoryDirArtifact.DirectoryArtifactState history = processor.getParentArtifact(PatchingArtifacts.HISTORY_DIR);
            PatchingArtifacts.MISC_BACKUP.process(history, processor);
            break;
        }
    }
    return valid;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 29 with InstalledIdentity

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

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

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