Search in sources :

Example 1 with Identity

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

the class CumulativePatchTestCase method testApplyReleasePatchAndRollback.

@Test
public void testApplyReleasePatchAndRollback() throws Exception {
    // start from a base installation
    // create an existing file in the AS7 installation
    File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
    String fileName = "standalone.sh";
    File standaloneShellFile = touch(binDir, fileName);
    dump(standaloneShellFile, "original script to run standalone AS7");
    byte[] existingHash = hashFile(standaloneShellFile);
    // build a Release patch for the base installation
    // with 1 added module
    // and 1 updated file
    String patchID = randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileModified).build();
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patchID);
    Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    assertFileExists(standaloneShellFile);
    assertFileContent(fileModified.getItem().getContentHash(), standaloneShellFile);
    InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
    File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
    assertDirExists(modulePatchDirectory);
    assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
    // rollback the patch based on the updated PatchInfo
    PatchingResult rollbackResult = rollback(patchID);
    tree(env.getInstalledImage().getJbossHome());
    assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
    assertFileExists(standaloneShellFile);
    assertFileContent(existingHash, standaloneShellFile);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Identity(org.jboss.as.patching.installation.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 2 with Identity

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

the class ConfigurationBackupTestCase method checkApplyPatchAndRollbackRestoresBackupConfiguration.

private void checkApplyPatchAndRollbackRestoresBackupConfiguration(File patchDir, Patch patch) throws Exception {
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    // check the AS7 config files have been backed up
    File backupAppclientXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "appclient", "appclient.xml");
    assertFileContent(originalAppClientHash, backupAppclientXmlFile);
    File backupStandaloneXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "standalone", "standalone.xml");
    assertFileContent(originalStandaloneHash, backupStandaloneXmlFile);
    File backupDomainXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "domain", "domain.xml");
    assertFileContent(originalDomainHash, backupDomainXmlFile);
    // let's change the standalone.xml file
    dump(standaloneXmlFile, "<updated standalone configuration with changes from the added module>");
    byte[] updatedStandaloneXmlFile = hashFile(standaloneXmlFile);
    tree(tempDir);
    PatchingResult rollbackResult = rollback(patch.getPatchId());
    assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
    File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml");
    assertEquals("updated content was " + bytesToHexString(updatedStandaloneXmlFile), bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile)));
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) Identity(org.jboss.as.patching.installation.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)

Example 3 with Identity

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

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

the class OneOffPatchTestCase method testApplyOneOffPatchAndRollback.

@Test
public void testApplyOneOffPatchAndRollback() throws Exception {
    // create an existing file in the AS7 installation
    File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
    String fileName = "standalone.sh";
    File standaloneShellFile = touch(binDir, fileName);
    dump(standaloneShellFile, "original script to run standalone AS7");
    byte[] existingHash = hashFile(standaloneShellFile);
    // build a one-off patch for the base installation
    // with 1 added module
    // and 1 updated file
    String patchID = randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    ContentModification fileUpdated = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
    Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileUpdated).build();
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patchID);
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    assertFileExists(standaloneShellFile);
    assertFileContent(fileUpdated.getItem().getContentHash(), standaloneShellFile);
    InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
    File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
    assertDirExists(modulePatchDirectory);
    assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
    // rollback the patch based on the updated PatchInfo
    PatchingResult rollbackResult = rollback(patchID);
    assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
    assertFileExists(standaloneShellFile);
    assertFileContent(existingHash, standaloneShellFile);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Identity(org.jboss.as.patching.installation.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 5 with Identity

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

the class OneOffPatchTestCase method apply2OneOffPatchesAndRollbackTheFirstOne.

@Test
public void apply2OneOffPatchesAndRollbackTheFirstOne() throws Exception {
    // create two files in the AS7 installation
    File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
    String standaloneFileName = "standalone.sh";
    File standaloneShellFile = touch(binDir, standaloneFileName);
    dump(standaloneShellFile, "original script to run standalone AS7");
    byte[] existingHashForStandaloneShell = hashFile(standaloneShellFile);
    String domainFileName = "domain.sh";
    File domainShellFile = touch(binDir, domainFileName);
    dump(domainShellFile, "original script to run domain AS7");
    byte[] existingHashForDomainShell = hashFile(domainShellFile);
    // build a one-off patch for the base installation
    // with 1 added module
    // and 1 updated file
    String patchID = "patch-1-" + randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    ContentModification fileUpdated = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
    Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileUpdated).build();
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patchID);
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    assertFileExists(standaloneShellFile);
    assertFileContent(fileUpdated.getItem().getContentHash(), standaloneShellFile);
    InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
    File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
    assertDirExists(modulePatchDirectory);
    assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
    // build a 2nd one-off patch for the base installation
    // with 1 updated file
    String patchID_2 = "patch-2-" + randomString();
    File patchDir_2 = mkdir(tempDir, patchID_2);
    ContentModification otherFileUpdated = ContentModificationUtils.modifyMisc(patchDir_2, patchID_2, "updated domain script", domainShellFile, "bin", "domain.sh");
    Patch patch_2 = PatchBuilder.create().setPatchId(patchID_2).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(otherFileUpdated).build();
    createPatchXMLFile(patchDir_2, patch_2);
    File zippedPatch_2 = createZippedPatchFile(patchDir_2, patchID_2);
    PatchingResult result_2 = executePatch(zippedPatch_2);
    assertPatchHasBeenApplied(result_2, patch_2);
    assertFileExists(domainShellFile);
    assertFileContent(otherFileUpdated.getItem().getContentHash(), domainShellFile);
    // rollback the *first* patch based on the updated PatchInfo
    PatchingResult rollbackResult = rollback(patchID, true);
    // both patches must be rolled back
    assertFileExists(standaloneShellFile);
    assertFileContent(existingHashForStandaloneShell, standaloneShellFile);
    assertFileExists(domainShellFile);
    assertFileContent(existingHashForDomainShell, domainShellFile);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Identity(org.jboss.as.patching.installation.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Aggregations

Identity (org.jboss.as.patching.installation.Identity)6 File (java.io.File)5 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)5 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)5 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)5 PatchingResult (org.jboss.as.patching.tool.PatchingResult)5 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)4 ContentModification (org.jboss.as.patching.metadata.ContentModification)4 Patch (org.jboss.as.patching.metadata.Patch)4 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)4 Test (org.junit.Test)4 IOException (java.io.IOException)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)1 ModelNode (org.jboss.dmr.ModelNode)1