final File backupConfigurationDir = new File(installedImage.getPatchHistoryDir(rollingBackPatchID), Constants.CONFIGURATION); final File ba = new File(backupConfigurationDir, Constants.APP_CLIENT); final File bd = new File(backupConfigurationDir, Constants.DOMAIN); final File a = new File(installedImage.getAppClientDir(), configuration); backupDirectory(ba, a); final File d = new File(installedImage.getDomainDir(), configuration); backupDirectory(bd, d); final File s = new File(installedImage.getStandaloneDir(), configuration); backupDirectory(bs, s);
private InstallationManager loadInstallationManager() throws IOException { List<File> moduleRoots = new ArrayList<File>(); moduleRoots.add(env.getInstalledImage().getModulesDir()); List<File> bundleRoots = new ArrayList<File>(); bundleRoots.add(env.getInstalledImage().getBundlesDir()); return new InstallationManagerImpl(env.getInstalledImage(), moduleRoots, bundleRoots, productConfig); }
IdentityPatchContext(final File backup, final PatchContentProvider contentProvider, final ContentVerificationPolicy contentPolicy, final InstallationManager.InstallationModification modification, final PatchingTaskContext.Mode mode, final InstalledImage installedImage) { this.miscTargetRoot = installedImage.getJbossHome(); this.mode = mode; this.contentProvider = contentProvider; this.contentPolicy = contentPolicy; this.modification = modification; this.installedImage = installedImage; this.history = PatchingHistory.Factory.getHistory(modification.getUnmodifiedInstallationState()); if (backup != null) { this.miscBackup = new File(backup, PatchContentLoader.MISC); this.configBackup = new File(backup, Constants.CONFIGURATION); } else { this.miscBackup = null; // This will trigger a failure when the root is actually needed this.configBackup = null; } this.identityEntry = new IdentityEntry(modification, null); }
/** * Backup the current configuration as part of the patch history. * * @throws IOException for any error */ void backupConfiguration() throws IOException { final String configuration = Constants.CONFIGURATION; final File a = new File(installedImage.getAppClientDir(), configuration); final File d = new File(installedImage.getDomainDir(), configuration); final File s = new File(installedImage.getStandaloneDir(), configuration); if (a.exists()) { final File ab = new File(configBackup, Constants.APP_CLIENT); backupDirectory(a, ab); } if (d.exists()) { final File db = new File(configBackup, Constants.DOMAIN); backupDirectory(d, db); } if (s.exists()) { final File sb = new File(configBackup, Constants.STANDALONE); backupDirectory(s, sb); } }
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); final File modulesDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); if(!modulesDir.exists()) { modulesDir.mkdirs();
static Patch loadPatchInformation(final String patchId, final InstalledImage installedImage) throws PatchingException, IOException, XMLStreamException { final File patchDir = installedImage.getPatchHistoryDir(patchId); final File patchXml = new File(patchDir, PatchXml.PATCH_XML); return PatchXml.parse(patchXml).resolvePatch(null, null); }
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); String moduleName = "module-test"; File moduleDir = createModule0(baseModuleDir, moduleName); File baseBundleDir = newFile(env.getInstalledImage().getBundlesDir(), SYSTEM, LAYERS, BASE); String bundleName = "bundle-test"; ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome()); ctx.handle("patch apply " + zippedPatch2.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome()); ctx.handle("patch info --patch-id=" + patchID + " --distribution=" + env.getInstalledImage().getJbossHome()); CLIPatchInfoUtil.assertPatchInfo(bytesOs.toByteArray(), patchID, "http://test.one", true, productConfig.getProductName(), productConfig.getProductVersion(), patchIDDescr); element.put("Description", oneOffElementDescr); bytesOs.reset(); ctx.handle("patch info --patch-id=" + patchID + " --verbose" + " --distribution=" + env.getInstalledImage().getJbossHome()); CLIPatchInfoUtil.assertPatchInfo(bytesOs.toByteArray(), patchID, "http://test.one", true, productConfig.getProductName(), productConfig.getProductVersion(), patchIDDescr, Collections.singletonList(element)); ctx.handle("patch info " + patchID2 + " --distribution=" + env.getInstalledImage().getJbossHome()); // w/o argument name --patch-id CLIPatchInfoUtil.assertPatchInfo(bytesOs.toByteArray(), patchID2, "http://test.two", false, productConfig.getProductName(), productConfig.getProductVersion(), patchID2Descr); element.put("Description", cpElementDescr); bytesOs.reset(); ctx.handle("patch info " + patchID2 + " --verbose" + " --distribution=" + env.getInstalledImage().getJbossHome()); // w/o argument name --patch-id CLIPatchInfoUtil.assertPatchInfo(bytesOs.toByteArray(), patchID2, "http://test.two", false,
@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); }
/** * Get the inactive history directories. * * @return the inactive history */ public List<File> getInactiveHistory() throws PatchingException { if (validHistory == null) { walk(); } final File[] inactiveDirs = installedIdentity.getInstalledImage().getPatchesDir().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !validHistory.contains(pathname.getName()); } }); return inactiveDirs == null ? Collections.<File>emptyList() : Arrays.asList(inactiveDirs); }
private static List<File> getModulePath(final InstalledImage image) { final Set<File> path = new LinkedHashSet<>(); final String modulePath = SecurityActions.getSystemProperty(MODULE_PATH, SecurityActions.getEnv("JAVA_MODULEPATH")); if (modulePath != null) { final String[] paths = modulePath.split(Pattern.quote(File.pathSeparator)); for (final String s : paths) { final File file = new File(s); path.add(file); } } else { path.add(image.getModulesDir()); } return new ArrayList<>(path); }
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))); }
InstalledConfiguration(final InstalledImage installedImage) { this.metadata = installedImage.getInstallationMetadata(); this.installedImage = installedImage; }
private static List<File> getBundlePath(final InstalledImage image) { final String prop = SecurityActions.getSystemProperty(BUNDLES_DIR); final File bundleRoots = prop != null ? new File(prop) : image.getBundlesDir(); return Collections.singletonList(bundleRoots); }
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, ""); } } } }
InstalledIdentity patchedInstalledIdentity = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir()); assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo()); assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); tree(env.getInstalledImage().getJbossHome());
/** * Backup the current configuration as part of the patch history. * * @throws IOException for any error */ void backupConfiguration() throws IOException { final String configuration = Constants.CONFIGURATION; final File a = new File(installedImage.getAppClientDir(), configuration); final File d = new File(installedImage.getDomainDir(), configuration); final File s = new File(installedImage.getStandaloneDir(), configuration); if (a.exists()) { final File ab = new File(configBackup, Constants.APP_CLIENT); backupDirectory(a, ab); } if (d.exists()) { final File db = new File(configBackup, Constants.DOMAIN); backupDirectory(d, db); } if (s.exists()) { final File sb = new File(configBackup, Constants.STANDALONE); backupDirectory(s, sb); } }
static RollbackPatch loadRollbackInformation(final String patchId, final InstalledImage installedImage) throws PatchingException, IOException, XMLStreamException { final File historyDir = installedImage.getPatchHistoryDir(patchId); final File patchXml = new File(historyDir, Constants.ROLLBACK_XML); return (RollbackPatch) PatchXml.parse(patchXml).resolvePatch(null, null); }
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); String fileName = "standalone.sh"; File standaloneShellFile = touch(binDir, fileName); assertFileContent(fileModified.getItem().getContentHash(), standaloneShellFile); File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patchID), "misc", "bin", fileName); assertFileContent(fileModified.getTargetHash(), backupFile);
/** * Get the inactive history directories. * * @return the inactive history */ public List<File> getInactiveHistory() throws PatchingException { if (validHistory == null) { walk(); } final File[] inactiveDirs = installedIdentity.getInstalledImage().getPatchesDir().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !validHistory.contains(pathname.getName()); } }); return inactiveDirs == null ? Collections.<File>emptyList() : Arrays.asList(inactiveDirs); }
private static List<File> getModulePath(final InstalledImage image) { final Set<File> path = new LinkedHashSet<>(); final String modulePath = SecurityActions.getSystemProperty(MODULE_PATH, SecurityActions.getEnv("JAVA_MODULEPATH")); if (modulePath != null) { final String[] paths = modulePath.split(Pattern.quote(File.pathSeparator)); for (final String s : paths) { final File file = new File(s); path.add(file); } } else { path.add(image.getModulesDir()); } return new ArrayList<>(path); }