/** * Clears the state history. * * @throws ProvisioningException in case of a failure */ public void clearStateHistory() throws ProvisioningException { StateHistoryUtils.clearStateHistory(home, log); }
/** * Checks whether the provisioning state history is not empty and can be used to undo * the last provisioning operation. * * @return true if the provisioning state history is not empty, otherwise false * @throws ProvisioningException in case of an error checking the history state */ public boolean isUndoAvailable() throws ProvisioningException { return StateHistoryUtils.isUndoAvailable(home, log); }
/** * Returns the state history limit for the installation. * * @return state history limit * @throws ProvisioningException in case of a failure to read the value */ public int getStateHistoryLimit() throws ProvisioningException { return StateHistoryUtils.readStateHistoryLimit(home, log); }
public static void clearStateHistory(Path installDir, MessageWriter log) throws ProvisioningException { final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir); if (!Files.exists(installedHistoryDir)) { return; } int limit = readStateHistoryLimit(installDir, log); final Path installedHistoryList = installedHistoryDir.resolve(Constants.HISTORY_LIST); try (BufferedWriter writer = Files.newBufferedWriter(installedHistoryList)) { writer.write(String.valueOf(limit)); writer.newLine(); } catch (IOException e) { throw new ProvisioningException(Errors.writeFile(installedHistoryList), e); } deleteHistoryFiles(installedHistoryDir); }
public static void replaceDist(Path stagedDir, Path home, boolean asUndo, Map<String, Boolean> undoTasks, MessageWriter log) throws ProvisioningException { log.verbose("Moving the provisioned installation from the staged directory to %s", home); // copy from the staged to the target installation directory if (Files.exists(home)) { if(asUndo) { StateHistoryUtils.removeLastUndoConfig(home, stagedDir, log); } else { StateHistoryUtils.addNewUndoConfig(home, stagedDir, undoTasks, log); } IoUtils.recursiveDelete(home); } try { IoUtils.copy(stagedDir, home); } catch (IOException e) { throw new ProvisioningException(Errors.copyFile(stagedDir, home)); } } }
mkdirs(installedHistoryDir);
public static Map<String, Boolean> readUndoTasks(Path installDir, MessageWriter log) throws ProvisioningException { final Path stateDir = getUndoStateDir(installDir, log); if(stateDir == null) { return Collections.emptyMap(); } final Path undoTasksFile = stateDir.resolve(Constants.UNDO_TASKS); if(!Files.exists(undoTasksFile)) { return Collections.emptyMap(); } final Map<String, Boolean> tasks = new LinkedHashMap<>(); try(BufferedReader reader = Files.newBufferedReader(undoTasksFile)) { String line = reader.readLine(); while(line != null) { final String action = reader.readLine(); if(Constants.KEEP.equals(action)) { tasks.put(line, true); } else if(Constants.REMOVE.equals(action)) { tasks.put(line, false); } else { throw new ProvisioningException("Unexpected undo task '" + action + "' for " + line); } line = reader.readLine(); } } catch (IOException e) { throw new ProvisioningException(Errors.readFile(undoTasksFile), e); } return tasks; }
/** * Goes back to the previous provisioning state recorded in the provisioning state history. * If the history is empty, the method throws an exception. * * @throws ProvisioningException in case of a failure */ public void undo() throws ProvisioningException { try(ProvisioningLayout<FeaturePackRuntimeBuilder> layout = newConfigLayout(StateHistoryUtils.readUndoConfig(home, log), Collections.emptyMap())) { doProvision(layout, getFsDiff(), true); } }
final Map<String, Boolean> undoTasks = StateHistoryUtils.readUndoTasks(home, log); if (!undoTasks.isEmpty()) { final Path staged = runtime.getStagedDir();
mkdirs(stagedHistoryDir); final int historyLimit = installedHistory.isEmpty() ? STATE_HISTORY_LIMIT : Integer.parseInt(installedHistory.get(0)); try(BufferedWriter writer = Files.newBufferedWriter(stagedHistoryDir.resolve(Constants.HISTORY_LIST))) {
public static ProvisioningConfig readUndoConfig(Path installDir, MessageWriter log) throws ProvisioningException { final Path stateDir = getUndoStateDir(installDir, log); if(stateDir == null) { throw new ProvisioningException(Errors.historyIsEmpty()); } return ProvisioningXmlParser.parse(stateDir.resolve(Constants.PROVISIONING_XML)); }
mkdirs(stagedHistoryDir); final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir); List<String> installedHistory = Collections.emptyList();