private static void installAddOn(File baseDir, String... addOns) throws Exception { for (String addOn : addOns) { IoUtils.mkdir(baseDir, "system", ADD_ONS, addOn); } } }
public static void writeRef(final File file, final String ref) throws IOException { mkdir(file.getParentFile()); final OutputStream os = new FileOutputStream(file); try { writeLine(os, ref); os.flush(); os.close(); } finally { safeClose(os); } }
public static void writeRef(final File file, final String ref) throws IOException { mkdir(file.getParentFile()); final OutputStream os = new FileOutputStream(file); try { writeLine(os, ref); os.flush(); os.close(); } finally { safeClose(os); } }
public static void writeRefs(final File file, final List<String> refs, boolean append) throws IOException { mkdir(file.getParentFile()); final OutputStream os = new FileOutputStream(file, append); try { writeRefs(os, refs); os.flush(); os.close(); } finally { safeClose(os); } }
public static void writeRefs(final File file, final List<String> refs, boolean append) throws IOException { mkdir(file.getParentFile()); final OutputStream os = new FileOutputStream(file, append); try { writeRefs(os, refs); os.flush(); os.close(); } finally { safeClose(os); } }
@Before public void setUp() throws IOException { tempDir = mkdir(new File(SYSTEM_TEMP_DIR), randomString()); final File jbossHome = mkdir(tempDir, JBOSS_INSTALLATION); mkdir(jbossHome, MODULES, "system", LAYERS, BASE); mkdir(jbossHome, BUNDLES, "system", LAYERS, BASE); productConfig = new ProductConfig(PRODUCT_NAME, PRODUCT_VERSION, "main"); }
protected void persist(final String cumulativeID, final List<String> patches, final Properties properties) throws IOException { assert cumulativeID != null; // Create the parent IoUtils.mkdir(structure.getInstallationInfo().getParentFile()); final List<String> consolidate = new ArrayList<String>(); consolidate.addAll(patches); if (!Constants.BASE.equals(cumulativeID)) { consolidate.add(cumulativeID); } if (structure.getModuleRoot() != null) { final File overlays = new File(structure.getModuleRoot(), Constants.OVERLAYS); final File refs = new File(overlays, Constants.OVERLAYS); PatchUtils.writeRefs(refs, consolidate); } // Update the properties properties.put(Constants.CUMULATIVE, cumulativeID); properties.put(Constants.PATCHES, PatchUtils.asString(patches)); if(version != null) { properties.put(Constants.CURRENT_VERSION, version); } // Write layer.conf PatchUtils.writeProperties(structure.getInstallationInfo(), properties); }
protected void persist(final String cumulativeID, final List<String> patches, final Properties properties) throws IOException { assert cumulativeID != null; // Create the parent IoUtils.mkdir(structure.getInstallationInfo().getParentFile()); final List<String> consolidate = new ArrayList<String>(); consolidate.addAll(patches); if (!Constants.BASE.equals(cumulativeID)) { consolidate.add(cumulativeID); } if (structure.getModuleRoot() != null) { final File overlays = new File(structure.getModuleRoot(), Constants.OVERLAYS); final File refs = new File(overlays, Constants.OVERLAYS); PatchUtils.writeRefs(refs, consolidate); } // Update the properties properties.put(Constants.CUMULATIVE, cumulativeID); properties.put(Constants.PATCHES, PatchUtils.asString(patches)); if(version != null) { properties.put(Constants.CURRENT_VERSION, version); } // Write layer.conf PatchUtils.writeProperties(structure.getInstallationInfo(), properties); }
@Before public void setup() throws Exception { tempDir = mkdir(new File(System.getProperty("java.io.tmpdir")), "patching-" + randomString()); File jbossHome = mkdir(tempDir, "jboss-installation"); mkdir(jbossHome, MODULES, "system", LAYERS, BASE); mkdir(jbossHome, BUNDLES, "system", LAYERS, BASE); env = TestUtils.createLegacyTestStructure(jbossHome); productConfig = new ProductConfig("product", "version", "consoleSlot"); }
private static void installLayer(File baseDir, File layerConf, boolean excludeBase, String... layers) throws IOException { for (String layer : layers) { IoUtils.mkdir(baseDir, "system", "layers", layer); } if (layerConf != null) { Properties props = new Properties(); StringBuilder str = new StringBuilder(); for (int i = 0; i < layers.length; i++) { if (i > 0) { str.append(','); } str.append(layers[i]); } props.put(Constants.LAYERS, str.toString()); props.put(Constants.EXCLUDE_LAYER_BASE, String.valueOf(excludeBase)); final FileOutputStream os = new FileOutputStream(layerConf); try { props.store(os, ""); } finally { IoUtils.safeClose(os); } } } }
protected void installLayers(boolean reflectInConf, String... layers) throws Exception { final File baseDir = env.getModuleRoot(); for (String layer : layers) { IoUtils.mkdir(baseDir, "system", "layers", layer); } if (reflectInConf) { final File layerConf = env.getInstalledImage().getLayersConf(); Properties props = new Properties(); StringBuilder str = new StringBuilder(); for (int i = 0; i < layers.length; i++) { if (i > 0) { str.append(','); } str.append(layers[i]); } props.put(Constants.LAYERS, str.toString()); try (final FileOutputStream os = new FileOutputStream(layerConf)){ props.store(os, ""); } } } }
@Before public void init() throws Exception { installLayers("layer1", "layer2"); final File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); standaloneSh = touch(binDir, "standalone.sh"); dump(standaloneSh, "original script to run standalone server"); originalStandaloneHash = hashFile(standaloneSh); addedByCP1 = new File(binDir, "added-by-cp1.txt"); addedByCP1RemovedByCP3 = new File(binDir, "added-by-cp1-removed-by-cp3.txt"); addedByCP2 = new File(binDir, "added-by-cp2.txt"); tool = newPatchTool(); }
@Test public void testAddDirectory() throws Exception { final ContentItem item = new MiscContentItem("dir", new String[] { "test"}, NO_CONTENT, true, false); final ContentModification addDir = new ContentModification(item, NO_CONTENT, ModificationType.ADD); final String patchID = randomString(); final Patch patch = PatchBuilder.create() .setPatchId(patchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(addDir) .build(); // create the patch final File patchDir = mkdir(tempDir, patch.getPatchId()); createPatchXMLFile(patchDir, patch); final File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); // Apply PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); final File test = new File(env.getInstalledImage().getJbossHome(), "test"); assertTrue(test.exists()); assertTrue(test.isDirectory()); final File dir = new File(test, "dir"); assertTrue(dir.exists()); assertTrue(dir.isDirectory()); rollback(patchID); }
private void prepareCP3(final InstalledIdentity installedIdentity) throws IOException, Exception { final String cp3ID = "CP3"; final File cp3Dir = mkdir(tempDir, cp3ID); cp3StandaloneModified = ContentModificationUtils.modifyMisc(cp3Dir, cp3ID, "updated by cp3", standaloneSh, "bin", standaloneSh.getName()); cp3BaseModuleModified = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName, cp2BaseModuleModified.getItem().getContentHash(), "cp3 content"); // cp3BaseModule2Added = ContentModificationUtils.addModule(cp3Dir, baseCP3ID, moduleName + "2"); the patchgen tool // would generate an update instead final File absentModuleXml = IoUtils.newFile(installedIdentity.getLayer("base").loadTargetInfo() .getDirectoryStructure().getModulePatchDirectory(baseCP2ID), "org", "jboss", "test2", "main", "module.xml"); cp3BaseModule2Added = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName + "2", HashUtils.hashFile(absentModuleXml), "cp3 content"); final ContentModification cp3AddedByCP1RemovedByCP3Removed = ContentModificationUtils.removeMisc(addedByCP1RemovedByCP3, "bin", addedByCP1RemovedByCP3.getName()); cp3 = PatchBuilder.create() .setPatchId(cp3ID) .setDescription(randomString()) .upgradeIdentity(installedIdentity.getIdentity().getName(), productConfig.getProductVersion() + "_CP2", productConfig.getProductVersion() + "_CP3") .getParent() .upgradeElement(baseCP3ID, BASE, false) .addContentModification(cp3BaseModuleModified) .addContentModification(cp3BaseModule2Added) .getParent() .addContentModification(cp3StandaloneModified) .addContentModification(cp3AddedByCP1RemovedByCP3Removed) .build(); createPatchXMLFile(cp3Dir, cp3); cp3Zip = createZippedPatchFile(cp3Dir, cp3ID); }
@Test public void testCumulativePatch() throws Exception { // build a cumulative 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) .setDescription(randomString()) .upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-CP1") .getParent() .upgradeElement(layerPatchID, BASE, false) .addContentModification(moduleAdded); Patch patch = builder.build(); checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch); }
@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); }
@Test public void testApplyOneOffPatch() throws Exception { // build a one-off patch for the base installation // with 1 added module String oneOffPatchID = randomString(); String oneOffLayerPatchID = randomString(); File oneOffPatchDir = mkdir(tempDir, oneOffPatchID); String moduleName = randomString(); ContentModification moduleAdded = ContentModificationUtils.addModule(oneOffPatchDir, oneOffLayerPatchID, moduleName); Patch oneOffPatch = PatchBuilder.create() .setPatchId(oneOffPatchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .oneOffPatchElement(oneOffLayerPatchID, BASE, false) .addContentModification(moduleAdded) .getParent() .build(); createPatchXMLFile(oneOffPatchDir, oneOffPatch); File zippedPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, oneOffPatch); InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity(); File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID); assertDirExists(modulePatchDirectory); assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash()); }
@Test public void testAddModule() throws Exception { // build a one-off patch for the base installation // with 1 added module String patchID = randomString(); File patchDir = mkdir(tempDir, patchID); String baseLayerPatchID = randomString(); String moduleName = randomString(); ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, baseLayerPatchID, moduleName); Patch patch = PatchBuilder.create() .setPatchId(patchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .oneOffPatchElement(baseLayerPatchID, BASE, false) .addContentModification(moduleAdded) .getParent() .build(); createPatchXMLFile(patchDir, patch); File zippedPatch = createZippedPatchFile(patchDir, patchID); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity(); File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID); assertDirExists(modulePatchDirectory); assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash()); }
@Test public void testAddFile() throws Exception { // build a one-off patch for the base installation // with 1 added file String patchID = randomString(); File patchDir = mkdir(tempDir, patchID); ContentModification fileAdded = ContentModificationUtils.addMisc(patchDir, patchID, "new file resource", "bin", "my-new-standalone.sh"); Patch patch = PatchBuilder.create() .setPatchId(patchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(fileAdded) .build(); assertFileDoesNotExist(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); createPatchXMLFile(patchDir, patch); File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); }
@Test public void testRemoveFile() throws Exception { // start from a base installation // with a file in it String fileName = "standalone.sh"; File standaloneShellFile = touch(env.getInstalledImage().getJbossHome(), "bin", fileName ); dump(standaloneShellFile, "original script to run standalone AS7"); // build a one-off patch for the base installation // with 1 removed file ContentModification fileRemoved = ContentModificationUtils.removeMisc(standaloneShellFile, "bin", fileName); Patch patch = PatchBuilder.create() .setPatchId(randomString()) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(fileRemoved) .build(); // create the patch File patchDir = mkdir(tempDir, patch.getPatchId()); createPatchXMLFile(patchDir, patch); File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); /// file has been removed from the AS7 installation assertFileDoesNotExist(standaloneShellFile); // but it's been backed up assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", fileName); }