use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class PatchInspect method displayPatchBundleXml.
private void displayPatchBundleXml(CommandContext ctx, List<BundledPatch.BundledPatchEntry> patches, ZipFile patchZip) throws CommandException {
if (patches.isEmpty()) {
return;
}
for (BundledPatch.BundledPatchEntry bundledPatch : patches) {
final ZipEntry bundledZip = patchZip.getEntry(bundledPatch.getPatchPath());
if (bundledZip == null) {
throw new CommandException("Patch file not found in the bundle: " + bundledPatch.getPatchPath());
}
InputStream is = null;
ZipInputStream bundledPatchIs = null;
try {
is = patchZip.getInputStream(bundledZip);
bundledPatchIs = new ZipInputStream(is);
ZipEntry bundledPatchXml = bundledPatchIs.getNextEntry();
while (bundledPatchXml != null) {
if (PatchXml.PATCH_XML.equals(bundledPatchXml.getName())) {
break;
}
bundledPatchXml = bundledPatchIs.getNextEntry();
}
if (bundledPatchXml == null) {
throw new CommandLineException("Failed to locate " + PatchXml.PATCH_XML + " in bundled patch " + bundledPatch.getPatchPath());
}
final Patch patch = PatchXml.parse(bundledPatchIs).resolvePatch(null, null);
if (verbose) {
// to make the separation better in the verbose mode
ctx.printLine("CONTENT OF " + bundledPatch.getPatchPath() + ':' + Util.LINE_SEPARATOR);
}
displayPatchXml(ctx, patch);
ctx.printLine("");
} catch (Exception e) {
throw new CommandException("Failed to inspect " + bundledPatch.getPatchPath(), e);
} finally {
IoUtils.safeClose(bundledPatchIs);
IoUtils.safeClose(is);
}
}
}
use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class PatchInfoHandler method patchIdInfo.
private ModelNode patchIdInfo(final OperationContext context, final String patchId, final boolean verbose, final PatchingHistory.Iterator i) {
while (i.hasNext()) {
final Entry entry = i.next();
if (patchId.equals(entry.getPatchId())) {
final ModelNode result = new ModelNode();
result.get(Constants.PATCH_ID).set(entry.getPatchId());
result.get(Constants.TYPE).set(entry.getType().getName());
result.get(Constants.DESCRIPTION).set(entry.getMetadata().getDescription());
final String link = entry.getMetadata().getLink();
if (link != null) {
result.get(Constants.LINK).set(link);
}
final Identity identity = entry.getMetadata().getIdentity();
result.get(Constants.IDENTITY_NAME).set(identity.getName());
result.get(Constants.IDENTITY_VERSION).set(identity.getVersion());
if (verbose) {
final ModelNode list = result.get(Constants.ELEMENTS).setEmptyList();
final Patch metadata = entry.getMetadata();
for (PatchElement e : metadata.getElements()) {
final ModelNode element = new ModelNode();
element.get(Constants.PATCH_ID).set(e.getId());
element.get(Constants.TYPE).set(e.getProvider().isAddOn() ? Constants.ADD_ON : Constants.LAYER);
element.get(Constants.NAME).set(e.getProvider().getName());
element.get(Constants.DESCRIPTION).set(e.getDescription());
list.add(element);
}
}
return result;
}
}
return null;
}
use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class PatchBundleTestCase method createNextCumulativePatchAddingRandomModule.
private File createNextCumulativePatchAddingRandomModule(String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception {
String layerPatchID = "layer" + patchID;
File cpPatchDir = mkdir(tempDir, patchID);
final String moduleName = "org.wildfly.test." + randomString();
// Create the version module
final String versionModuleName = ProductInfo.getVersionModule();
final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
// Calculate the target hash of the currently active module
final String currentLayerPatchID = "layer" + currentPatch;
File originalVersionModulePath = new File(tempDir, currentPatch);
originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
assert patchedAsVersionHash != null;
final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8));
final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8));
Module newModule = new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();
ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(cpPatchDir, cpPatch);
return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class PatchBundleTestCase method createOneOffPatchAddingMiscFile.
private File createOneOffPatchAddingMiscFile(String patchID, String asVersion) throws Exception {
File oneOffPatchDir = mkdir(tempDir, patchID);
ContentModification miscFileAdded = ContentModificationUtils.addMisc(oneOffPatchDir, patchID, "test content", "awesomeDirectory", "awesomeFile");
ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch adding a misc file.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(miscFileAdded).build();
createPatchXMLFile(oneOffPatchDir, oneOffPatch);
return createZippedPatchFile(oneOffPatchDir, patchID);
}
use of org.jboss.as.patching.metadata.Patch 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();
}
Aggregations