@Override protected Collection<? extends PatchableTarget> getChildTargets(InstalledIdentity identity) { return identity.getLayers(); } }
@Override protected Collection<? extends PatchableTarget> getChildTargets(InstalledIdentity identity) { return identity.getLayers(); } }
/** * Get the inactive overlay directories. * * @return the inactive overlay directories */ public List<File> getInactiveOverlays() throws PatchingException { if (referencedOverlayDirectories == null) { walk(); } List<File> inactiveDirs = null; for (Layer layer : installedIdentity.getLayers()) { final File overlaysDir = new File(layer.getDirectoryStructure().getModuleRoot(), Constants.OVERLAYS); final File[] inactiveLayerDirs = overlaysDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !referencedOverlayDirectories.contains(pathname); } }); if (inactiveLayerDirs != null && inactiveLayerDirs.length > 0) { if (inactiveDirs == null) { inactiveDirs = new ArrayList<File>(); } inactiveDirs.addAll(Arrays.asList(inactiveLayerDirs)); } } return inactiveDirs == null ? Collections.<File>emptyList() : inactiveDirs; }
/** * Get the inactive overlay directories. * * @return the inactive overlay directories */ public List<File> getInactiveOverlays() throws PatchingException { if (referencedOverlayDirectories == null) { walk(); } List<File> inactiveDirs = null; for (Layer layer : installedIdentity.getLayers()) { final File overlaysDir = new File(layer.getDirectoryStructure().getModuleRoot(), Constants.OVERLAYS); final File[] inactiveLayerDirs = overlaysDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !referencedOverlayDirectories.contains(pathname); } }); if (inactiveLayerDirs != null && inactiveLayerDirs.length > 0) { if (inactiveDirs == null) { inactiveDirs = new ArrayList<File>(); } inactiveDirs.addAll(Arrays.asList(inactiveLayerDirs)); } } return inactiveDirs == null ? Collections.<File>emptyList() : inactiveDirs; }
/** * Load the installation state based on the identity * * @param installedIdentity the installed identity * @return the installation state * @throws IOException */ protected static InstallationModificationImpl.InstallationState load(final InstalledIdentity installedIdentity) throws IOException { final InstallationModificationImpl.InstallationState state = new InstallationModificationImpl.InstallationState(); for (final Layer layer : installedIdentity.getLayers()) { state.putLayer(layer); } for (final AddOn addOn : installedIdentity.getAddOns()) { state.putAddOn(addOn); } return state; }
/** * Load the installation state based on the identity * * @param installedIdentity the installed identity * @return the installation state * @throws IOException */ protected static InstallationModificationImpl.InstallationState load(final InstalledIdentity installedIdentity) throws IOException { final InstallationModificationImpl.InstallationState state = new InstallationModificationImpl.InstallationState(); for (final Layer layer : installedIdentity.getLayers()) { state.putLayer(layer); } for (final AddOn addOn : installedIdentity.getAddOns()) { state.putAddOn(addOn); } return state; }
static void writeInstallation(final XMLExtendedStreamWriter writer, final InstalledIdentity identity) throws XMLStreamException { writer.writeStartElement(Element.INSTALLATION.name); // identity writeTargetInfo(writer, Element.IDENTITY, identity.getIdentity()); // layers for (final Layer layer : identity.getLayers()) { writeTargetInfo(writer, Element.LAYER, layer); } // addons for (final AddOn addOn : identity.getAddOns()) { writeTargetInfo(writer, Element.ADD_ON, addOn); } writer.writeEndElement(); }
static void writeInstallation(final XMLExtendedStreamWriter writer, final InstalledIdentity identity) throws XMLStreamException { writer.writeStartElement(Element.INSTALLATION.name); // identity writeTargetInfo(writer, Element.IDENTITY, identity.getIdentity()); // layers for (final Layer layer : identity.getLayers()) { writeTargetInfo(writer, Element.LAYER, layer); } // addons for (final AddOn addOn : identity.getAddOns()) { writeTargetInfo(writer, Element.ADD_ON, addOn); } writer.writeEndElement(); }
@Test public void layerNotInLayersConf() throws Exception { String layerName = randomString(); installLayers(false, layerName); InstalledIdentity installedIdentity = loadInstalledIdentity(); // if the layer name is not in layers.conf, it's not part of the installed identity List<Layer> layers = installedIdentity.getLayers(); assertEquals(1, layers.size()); assertEquals(BASE, layers.get(0).getName()); // only the base layer is installled }
protected static InstalledIdentity copy(InstalledIdentity original) throws IOException { final InstalledIdentityImpl copy = new InstalledIdentityImpl(original.getIdentity(), original.getAllInstalledPatches(), original.getInstalledImage()); for (final Layer layer : original.getLayers()) { copy.putLayer(layer.getName(), new LayerInfo(layer.getName(), layer.loadTargetInfo(), layer.getDirectoryStructure())); } for (final AddOn addOn : original.getAddOns()) { copy.putAddOn(addOn.getName(), new LayerInfo(addOn.getName(), addOn.loadTargetInfo(), addOn.getDirectoryStructure())); } return copy; }
@Override public PatchInfo getPatchInfo(String streamName) throws PatchingException { try { final InstalledIdentity installedIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); final PatchableTarget.TargetInfo info = installedIdentity.getIdentity().loadTargetInfo(); final VerbosePatchInfo.Builder infoBuilder = VerbosePatchInfo.builder() .setVersion(installedIdentity.getIdentity().getVersion()) .setCumulativePatchId(info.getCumulativePatchID()) .setPatchIds(info.getPatchIDs()); for(Layer layer : installedIdentity.getLayers()) { infoBuilder.addLayerInfo(layer.getName(), layer.loadTargetInfo()); } for(AddOn addon : installedIdentity.getAddOns()) { infoBuilder.addAddOnInfo(addon.getName(), addon.loadTargetInfo()); } return infoBuilder.build(); } catch (IOException e) { // why throw a rethrowException(e) ? throw new RuntimeException(e); } }
protected static InstalledIdentity copy(InstalledIdentity original) throws IOException { final InstalledIdentityImpl copy = new InstalledIdentityImpl(original.getIdentity(), original.getAllInstalledPatches(), original.getInstalledImage()); for (final Layer layer : original.getLayers()) { copy.putLayer(layer.getName(), new LayerInfo(layer.getName(), layer.loadTargetInfo(), layer.getDirectoryStructure())); } for (final AddOn addOn : original.getAddOns()) { copy.putAddOn(addOn.getName(), new LayerInfo(addOn.getName(), addOn.loadTargetInfo(), addOn.getDirectoryStructure())); } return copy; }
@Override public PatchInfo getPatchInfo(String streamName) throws PatchingException { try { final InstalledIdentity installedIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); final PatchableTarget.TargetInfo info = installedIdentity.getIdentity().loadTargetInfo(); final VerbosePatchInfo.Builder infoBuilder = VerbosePatchInfo.builder() .setVersion(installedIdentity.getIdentity().getVersion()) .setCumulativePatchId(info.getCumulativePatchID()) .setPatchIds(info.getPatchIDs()); for(Layer layer : installedIdentity.getLayers()) { infoBuilder.addLayerInfo(layer.getName(), layer.loadTargetInfo()); } for(AddOn addon : installedIdentity.getAddOns()) { infoBuilder.addAddOnInfo(addon.getName(), addon.loadTargetInfo()); } return infoBuilder.build(); } catch (IOException e) { // why throw a rethrowException(e) ? throw new RuntimeException(e); } }
@Test public void baseLayerIsAlwaysInstalled() throws Exception { tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); List<Layer> layers = installedIdentity.getLayers(); assertEquals(1, layers.size()); Layer layer = layers.get(0); assertEquals(BASE, layer.getName()); PatchableTarget.TargetInfo targetInfo = layer.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getBundleRepositoryRoot(), "system", LAYERS, BASE), directoryStructure.getBundleRepositoryRoot()); assertEquals(newFile(env.getModuleRoot(), "system", LAYERS, BASE), directoryStructure.getModuleRoot()); }
@Test public void installedLayer() throws Exception { String layerName = randomString(); installLayers(layerName); TestUtils.tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); Identity identity = installedIdentity.getIdentity(); assertEquals(productConfig.getProductName(), identity.getName()); assertEquals(productConfig.resolveVersion(), identity.getVersion()); List<Layer> layers = installedIdentity.getLayers(); assertEquals(2, layers.size()); Layer layer = layers.get(0); assertEquals(layerName, layer.getName()); assertEquals(BASE, layers.get(1).getName()); // base layer is always appended PatchableTarget.TargetInfo targetInfo = layer.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getModuleRoot(), "system", "layers", layerName), directoryStructure.getModuleRoot()); assertNull(directoryStructure.getBundleRepositoryRoot()); }
@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 testApplyReleasePatch() throws Exception { // build a Release 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(); Patch patch = PatchBuilder.create() .setPatchId(patchID) .setDescription(randomString()) .upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1") .getParent() .upgradeElement(layerPatchID, 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(layerPatchID); assertDirExists(modulePatchDirectory); assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash()); }
@Test public void testRemoveModule() throws Exception { String moduleName = randomString(); // create an empty module in the AS7 installation File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); File moduleDir = createModule0(baseModuleDir, moduleName); // build a one-off patch for the installation base layer // with 1 module removed String baseLayerPatchID = randomString(); Patch patch = PatchBuilder.create() .setPatchId(randomString()) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .oneOffPatchElement(baseLayerPatchID, BASE, false) .addContentModification(ContentModificationUtils.removeModule(moduleDir)) .getParent() .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); InstalledIdentity installedIdentity = loadInstalledIdentity(); File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID); assertDirExists(modulesPatchDir); assertDefinedAbsentModule(modulesPatchDir, moduleName); }
File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID); assertDirExists(modulesPatchDir);