@Override public PatchingHistory getPatchingHistory(String streamName) throws PatchingException { final InstalledIdentity identity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); return PatchingHistory.Factory.getHistory(identity); }
@Override public PatchingHistory getPatchingHistory(String streamName) throws PatchingException { final InstalledIdentity identity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); return PatchingHistory.Factory.getHistory(identity); }
@Override public Set<String> children() { final InstallationManager manager = getInstallationManager(); if (manager == null) { return Collections.emptySet(); } final Collection<? extends PatchableTarget> targets = getChildTargets(manager.getDefaultIdentity()); if (targets.isEmpty()) { return Collections.emptySet(); } if (targets.size() == 1) { final PatchableTarget target = targets.iterator().next(); return Collections.singleton(target.getName()); } final Set<String> names = new HashSet<String>(targets.size()); for (PatchableTarget target : targets) { names.add(target.getName()); } return names; } }
@Override public Set<String> children() { final InstallationManager manager = getInstallationManager(); if (manager == null) { return Collections.emptySet(); } final Collection<? extends PatchableTarget> targets = getChildTargets(manager.getDefaultIdentity()); if (targets.isEmpty()) { return Collections.emptySet(); } if (targets.size() == 1) { final PatchableTarget target = targets.iterator().next(); return Collections.singleton(target.getName()); } final Set<String> names = new HashSet<String>(targets.size()); for (PatchableTarget target : targets) { names.add(target.getName()); } return names; } }
PatchableTarget getLayer(final String layerName) { return installationManager.getDefaultIdentity().getLayer(layerName); }
public InstalledIdentity loadInstalledIdentity() throws IOException { return loadInstallationManager().getDefaultIdentity(); }
protected void execute(OperationContext context, ModelNode operation, InstallationManager instMgr, String patchStream) throws OperationFailedException { final InstalledIdentity installedIdentity; if(patchStream != null) { try { installedIdentity = instMgr.getInstalledIdentity(patchStream, null); } catch (PatchingException e) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(patchStream), e); } } else { installedIdentity = instMgr.getDefaultIdentity(); } execute(context, operation, installedIdentity); }
protected void execute(OperationContext context, ModelNode operation, InstallationManager instMgr, String patchStream) throws OperationFailedException { final InstalledIdentity installedIdentity; if(patchStream != null) { try { installedIdentity = instMgr.getInstalledIdentity(patchStream, null); } catch (PatchingException e) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(patchStream), e); } } else { installedIdentity = instMgr.getDefaultIdentity(); } execute(context, operation, installedIdentity); }
@Override public PatchingResult rollbackLast(final String streamName, final ContentVerificationPolicy contentPolicy, final boolean resetConfiguration) throws PatchingException { final InstalledIdentity targetIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); final InstallationManager.InstallationModification modification = targetIdentity.modifyInstallation(runner); try { return runner.rollbackLast(contentPolicy, resetConfiguration, modification); } catch (Exception e) { modification.cancel(); throw rethrowException(e); } }
@Override public PatchingResult rollbackLast(final String streamName, final ContentVerificationPolicy contentPolicy, final boolean resetConfiguration) throws PatchingException { final InstalledIdentity targetIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); final InstallationManager.InstallationModification modification = targetIdentity.modifyInstallation(runner); try { return runner.rollbackLast(contentPolicy, resetConfiguration, modification); } catch (Exception e) { modification.cancel(); throw rethrowException(e); } }
protected void cannotRollbackPatch(final String patchID) throws Exception { try { validateRollbackState(patchID, updateInstallationManager().getDefaultIdentity()); Assert.fail("should not be able to rollback " + patchID); } catch (PatchingException e) { // ok } catch (Exception e) { throw e; } }
protected void assertNoGarbage() throws Exception { final PatchingGarbageLocator garbageLocator = PatchingGarbageLocator.getIninitialized(loadInstallationManager().getDefaultIdentity()); List<File> inactiveHistory = garbageLocator.getInactiveHistory(); assertTrue(inactiveHistory.toString(), inactiveHistory.isEmpty()); assertTrue(garbageLocator.getInactiveOverlays().toString(), garbageLocator.getInactiveOverlays().isEmpty()); }
protected String getExpectedOverlayDir(String layerName, final String patchId) throws IOException { final Layer layer = updateInstallationManager().getDefaultIdentity().getLayer(layerName); if(layer == null) { fail("No layer " + layerName); } return layer.getDirectoryStructure().getModulePatchDirectory(layerName + "-" + patchId).getAbsolutePath(); }
@Test public void testSimpleValidRollbackOneOff() throws Exception { installOneOff(); validateRollbackState(ONE_OFF_1_ID, updateInstallationManager().getDefaultIdentity()); }
@Test public void testRemovedCPRollbackXml() throws Exception { installOneOffCpOneOff(); removeRollbackXml(CP_1_ID); final PatchingGarbageLocator garbageLocator = PatchingGarbageLocator.getIninitialized(updateInstallationManager().getDefaultIdentity()); final List<File> inactiveHistory = garbageLocator.getInactiveHistory(); assertEquals(1, inactiveHistory.size()); assertEquals(getExpectedHistoryDir(ONE_OFF_1_ID), inactiveHistory.get(0).getAbsolutePath()); final List<File> inactiveOverlays = garbageLocator.getInactiveOverlays(); assertEquals(1, inactiveOverlays.size()); assertEquals(getExpectedOverlayDir("base", ONE_OFF_1_ID), inactiveOverlays.get(0).getAbsolutePath()); }
@Test public void testMissingHistoryOneOff() throws Exception { final PatchingTestBuilder builder = installOneOffCpOneOff(); // Can rollback incl. the first one off validateRollbackState(ONE_OFF_1_ID, updateInstallationManager().getDefaultIdentity()); // Remove one off history final File oneOffHistory = getHistory(builder, ONE_OFF_1_ID); IoUtils.recursiveDelete(oneOffHistory); cannotRollbackPatch(ONE_OFF_1_ID); // Can rollback CP1 validateRollbackState(CP_1_ID, updateInstallationManager().getDefaultIdentity()); // Remove cp1 history final File cpHistory = getHistory(builder, CP_1_ID); IoUtils.recursiveDelete(cpHistory); cannotRollbackPatch(CP_1_ID); // Could still rollback 2nd one off validateRollbackState(ONE_OFF_2_ID, updateInstallationManager().getDefaultIdentity()); }
@Test public void testRemovedLastOneOffRollbackXml() throws Exception { installOneOffCpOneOff(); removeRollbackXml(ONE_OFF_2_ID); PatchingGarbageLocator garbageLocator = PatchingGarbageLocator.getIninitialized(updateInstallationManager().getDefaultIdentity()); final List<File> inactiveHistory = garbageLocator.getInactiveHistory(); List<String> inactivePaths = Arrays.asList(new String[] { getExpectedHistoryDir(ONE_OFF_1_ID) }); assertEqualPaths(inactivePaths, inactiveHistory); final List<File> inactiveOverlays = garbageLocator.getInactiveOverlays(); inactivePaths = Arrays.asList(new String[]{getExpectedOverlayDir("base", ONE_OFF_1_ID)}); assertEqualPaths(inactivePaths, inactiveOverlays); // test cleaning garbageLocator.deleteInactiveContent(); garbageLocator.reset(); assertTrue(garbageLocator.getInactiveHistory().isEmpty()); assertTrue(garbageLocator.getInactiveOverlays().isEmpty()); assertTrue(new File(getExpectedOverlayDir("base", ONE_OFF_2_ID)).exists()); }
@Test public void testMissingOverlay() throws Exception { final PatchingTestBuilder builder = installOneOffCpOneOff(); // Can rollback incl. the first one off validateRollbackState(ONE_OFF_1_ID, updateInstallationManager().getDefaultIdentity()); final File overlays = getOverlays(builder, "base", "base-" + ONE_OFF_1_ID); IoUtils.recursiveDelete(overlays); cannotRollbackPatch(ONE_OFF_1_ID); cannotRollbackPatch(CP_1_ID); }
@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); } }
@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); } }