Search in sources :

Example 1 with PatchBuilder

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

the class ConfigurationBackupTestCase method testOneOffPatch.

@Test
public void testOneOffPatch() throws Exception {
    // build a one-off patch for the base installation
    // with 1 added module
    String patchID = randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    final PatchBuilder builder = PatchBuilder.create();
    builder.setPatchId(patchID).setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded);
    Patch patch = builder.build();
    checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) HashUtils.bytesToHexString(org.jboss.as.patching.HashUtils.bytesToHexString) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) 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 PatchBuilder

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

the class PatchInfoTestBase method applyPatch.

protected byte[] applyPatch(String product, String version, String newVersion, String patchID, String layer, String layerPatchId, byte[] targetHash) throws Exception {
    final File patchDir = mkdir(tempDir, patchID);
    final Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))).build();
    // create the patch with the updated module
    final ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, layerPatchId, targetHash, module);
    PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(patchID).setDescription(randomString());
    if (newVersion != null) {
        patchBuilder = patchBuilder.upgradeIdentity(product, version, newVersion).getParent().upgradeElement(layerPatchId, layer, false).addContentModification(moduleModified).getParent();
    } else {
        patchBuilder = patchBuilder.oneOffPatchIdentity(product, version).getParent().oneOffPatchElement(layerPatchId, layer, false).addContentModification(moduleModified).getParent();
    }
    final Patch patch = patchBuilder.build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    final File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch and check if server is in restart-required mode
    controller.start();
    try {
        Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
        Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    } finally {
        controller.stop();
    }
    return moduleModified.getItem().getContentHash();
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) Module(org.jboss.as.test.patching.util.module.Module) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 3 with PatchBuilder

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

the class BootLoggingPatchingStateTestCase method applyPatch.

protected void applyPatch(String product, String version, String patchId, boolean oneOff) throws Exception {
    final File patchDir = mkdir(tempDir, patchId);
    final ContentModification miscFileAdded = ContentModificationUtils.addMisc(patchDir, patchId, patchId + " content", product + patchId);
    final PatchBuilder builder = PatchBuilder.create().setPatchId(patchId);
    if (oneOff) {
        builder.oneOffPatchIdentity(product, version);
    } else {
        builder.upgradeIdentity(product, version, version);
    }
    final Patch patch = builder.addContentModification(miscFileAdded).build();
    createPatchXMLFile(patchDir, patch);
    applyPatch(createZippedPatchFile(patchDir, patchId));
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 4 with PatchBuilder

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

the class AgeOutHistoryUnitTestCase method applyPatch.

protected byte[] applyPatch(String patchID, byte[] targetHash, boolean cp) throws Exception {
    String moduleName = "module-test";
    String patchElementId = randomString();
    File patchDir = mkdir(tempDir, patchID);
    Module module = new Module.Builder(moduleName).miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))).build();
    // create the patch with the updated module
    ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, targetHash, module);
    PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(patchID).setDescription(randomString());
    if (cp) {
        patchBuilder = patchBuilder.upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), PatchingTestUtil.AS_VERSION + "_CP" + patchID).getParent().upgradeElement(patchElementId, "base", false).addContentModification(moduleModified).getParent();
    } else {
        patchBuilder = patchBuilder.oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElementId, "base", false).addContentModification(moduleModified).getParent();
    }
    Patch patch = patchBuilder.build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch and check if server is in restart-required mode
    controller.start();
    try {
        Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
        Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
        if (cp) {
            productConfig = new ProductConfig(PatchingTestUtil.PRODUCT, PatchingTestUtil.AS_VERSION + "_CP" + patchID, "main");
        }
    } finally {
        controller.stop();
    }
    return moduleModified.getItem().getContentHash();
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 5 with PatchBuilder

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

the class LayerTestCase method duplicateElementId.

@Test
public void duplicateElementId() throws Exception {
    // add a layer
    String layerName = "layer1";
    String layer2Name = "layer2";
    installLayers(layerName, layer2Name);
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    PatchableTarget.TargetInfo identityInfo = installedIdentity.getIdentity().loadTargetInfo();
    assertEquals(BASE, identityInfo.getCumulativePatchID());
    assertTrue(identityInfo.getPatchIDs().isEmpty());
    // build a one-off patch for the layer with 1 added module
    // and 1 added file
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String layerPatchId = "mylayerPatchID";
    String moduleName = "module1";
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchId, moduleName);
    final PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(patchID).oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()).getParent().oneOffPatchElement(layerPatchId, layerName, false).addContentModification(moduleAdded).getParent();
    try {
        patchBuilder.oneOffPatchElement(layerPatchId, layer2Name, false);
        fail("duplicate element patch-id error expected");
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) 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) Test(org.junit.Test)

Aggregations

PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)8 File (java.io.File)7 ContentModification (org.jboss.as.patching.metadata.ContentModification)7 Patch (org.jboss.as.patching.metadata.Patch)5 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)4 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)4 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)4 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)3 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)3 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)3 Test (org.junit.Test)3 HashUtils.bytesToHexString (org.jboss.as.patching.HashUtils.bytesToHexString)2 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)2 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)2 Module (org.jboss.as.test.patching.util.module.Module)2 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)1 PatchElementBuilder (org.jboss.as.patching.metadata.PatchElementBuilder)1 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)1 ProductConfig (org.jboss.as.version.ProductConfig)1 Before (org.junit.Before)1