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);
}
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();
}
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));
}
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();
}
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
}
}
Aggregations