@Override public List<String> getPatchStreams() throws PatchingException { final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities(); if(installedIdentities.size() == 1) { return Collections.singletonList(installedIdentities.get(0).getIdentity().getName()); } final List<String> result = new ArrayList<String>(installedIdentities.size()); for(InstalledIdentity ii : installedIdentities) { result.add(ii.getIdentity().getName()); } return result; }
@Override public List<String> getPatchStreams() throws PatchingException { final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities(); if(installedIdentities.size() == 1) { return Collections.singletonList(installedIdentities.get(0).getIdentity().getName()); } final List<String> result = new ArrayList<String>(installedIdentities.size()); for(InstalledIdentity ii : installedIdentities) { result.add(ii.getIdentity().getName()); } return result; }
@Override public Set<String> children() { final InstallationManager manager = getInstallationManager(); if (manager == null) { return Collections.emptySet(); } List<InstalledIdentity> installedIdentities; try { installedIdentities = manager.getInstalledIdentities(); } catch (PatchingException e) { throw new IllegalStateException(e); } if(installedIdentities.size() == 1) { return Collections.singleton(installedIdentities.get(0).getIdentity().getName()); } final Set<String> set = new HashSet<String>(installedIdentities.size()); for(InstalledIdentity identity : installedIdentities) { set.add(identity.getIdentity().getName()); } return set; } }
@Override public Set<String> children() { final InstallationManager manager = getInstallationManager(); if (manager == null) { return Collections.emptySet(); } List<InstalledIdentity> installedIdentities; try { installedIdentities = manager.getInstalledIdentities(); } catch (PatchingException e) { throw new IllegalStateException(e); } if(installedIdentities.size() == 1) { return Collections.singleton(installedIdentities.get(0).getIdentity().getName()); } final Set<String> set = new HashSet<String>(installedIdentities.size()); for(InstalledIdentity identity : installedIdentities) { set.add(identity.getIdentity().getName()); } return set; } }
@Override public void complete() { try { // Update the state updateState(identity.getName(), this, internalComplete()); writable.set(true); } catch (Exception e) { cancel(); throw new RuntimeException(e); } if (callback != null) { callback.completed(); } }
@Override public void complete() { try { // Update the state updateState(identity.getName(), this, internalComplete()); writable.set(true); } catch (Exception e) { cancel(); throw new RuntimeException(e); } if (callback != null) { callback.completed(); } }
private static void assertExistsOnDisk(IteratorImpl i, String id) throws NoSuchElementException { final File historyDir = i.mgr.getInstalledImage().getPatchHistoryDir(id); if(!historyDir.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.noPatchHistory(historyDir.getAbsolutePath())); } // TODO parsed xml can be cached final File rollbackXml = new File(historyDir, "rollback.xml"); if(!rollbackXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(rollbackXml.getAbsolutePath())); } try { PatchXml.parse(rollbackXml); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(rollbackXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } final File patchXml = new File(historyDir, "patch.xml"); if(!patchXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(patchXml.getAbsolutePath())); } final Patch patchMetaData; try { patchMetaData = PatchXml.parse(patchXml).resolvePatch(i.mgr.getIdentity().getName(), i.mgr.getIdentity().getVersion()); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(patchXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } if(i.excludeAgedOut && isAgedOut(i.mgr, patchMetaData)) { throw new NoSuchElementException("Patch " + patchMetaData.getPatchId() + " was aged out"); } }
@Override public ModelNode getHistory(boolean excludeAgedOut) throws PatchingException { try { return getHistory(installedIdentity.getIdentity().loadTargetInfo(), excludeAgedOut); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } }
@Override protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException { final ModelNode result = context.getResult(); final Identity info = installedIdentity.getIdentity(); try { handle(result, info); } catch (IOException e) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(info.getName()), e); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
@Override public Iterator iterator(boolean excludeAgedOut) throws PatchingException { try { return iterator(installedIdentity.getIdentity().loadTargetInfo(), excludeAgedOut); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } }
@Override public ModelNode getHistory(boolean excludeAgedOut) throws PatchingException { try { return getHistory(installedIdentity.getIdentity().loadTargetInfo(), excludeAgedOut); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } }
@Override public Iterator iterator(boolean excludeAgedOut) throws PatchingException { try { return iterator(installedIdentity.getIdentity().loadTargetInfo(), excludeAgedOut); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } }
@Override protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException { final ModelNode result = context.getResult(); final Identity info = installedIdentity.getIdentity(); try { handle(result, info); } catch (IOException e) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(info.getName()), e); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
@Override public PatchingResult rollback(final String streamName, final String patchId, final ContentVerificationPolicy contentPolicy, final boolean rollbackTo, final boolean resetConfiguration) throws PatchingException { InstalledIdentity targetIdentity = null; if (streamName == null) { for (InstalledIdentity identity : manager.getInstalledIdentities()) { if (identity.getAllInstalledPatches().contains(patchId)) { if (targetIdentity != null) { throw new PatchingException(PatchLogger.ROOT_LOGGER.patchIdFoundInMoreThanOneStream(patchId, targetIdentity.getIdentity().getName(), identity.getIdentity().getName())); } targetIdentity = identity; } } if(targetIdentity == null) { throw PatchLogger.ROOT_LOGGER.patchNotFoundInHistory(patchId); } } else { targetIdentity = manager.getInstalledIdentity(streamName, null); } // Rollback the patch final InstallationManager.InstallationModification modification = targetIdentity.modifyInstallation(runner); try { return runner.rollbackPatch(patchId, contentPolicy, rollbackTo, resetConfiguration, modification); } catch (Exception e) { modification.cancel(); throw rethrowException(e); } }
@Override protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException { String patchId = PatchResourceDefinition.PATCH_ID_OPTIONAL.resolveModelAttribute(context, operation).asStringOrNull(); assert patchId != null; // the overridden execute(OperationContext context, ModelNode operation) ensures not final boolean verbose = PatchResourceDefinition.VERBOSE.resolveModelAttribute(context, operation).asBoolean(); final PatchableTarget.TargetInfo info; try { info = installedIdentity.getIdentity().loadTargetInfo(); } catch (Exception e) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } final PatchingHistory.Iterator i = PatchingHistory.Factory.iterator(installedIdentity, info); final ModelNode result = patchIdInfo(context, patchId, verbose, i); if (result == null) { context.getFailureDescription().set(PatchLogger.ROOT_LOGGER.patchNotFoundInHistory(patchId).getLocalizedMessage()); } else { context.getResult().set(result); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
@Override protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException { String patchId = PatchResourceDefinition.PATCH_ID_OPTIONAL.resolveModelAttribute(context, operation).asStringOrNull(); assert patchId != null; // the overridden execute(OperationContext context, ModelNode operation) ensures not final boolean verbose = PatchResourceDefinition.VERBOSE.resolveModelAttribute(context, operation).asBoolean(); final PatchableTarget.TargetInfo info; try { info = installedIdentity.getIdentity().loadTargetInfo(); } catch (Exception e) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } final PatchingHistory.Iterator i = PatchingHistory.Factory.iterator(installedIdentity, info); final ModelNode result = patchIdInfo(context, patchId, verbose, i); if (result == null) { context.getFailureDescription().set(PatchLogger.ROOT_LOGGER.patchNotFoundInHistory(patchId).getLocalizedMessage()); } else { context.getResult().set(result); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
@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 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 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()); }