public Halconfig getConfig() { return halconfigParser.getHalconfig(); }
/** * Parse Halyard's config for inmemory usage. HalConfigs parsed with this function will NOT be written to disk for * persistence. * * @param is is the input stream to read from. * @return the fully parsed halconfig. * @see Halconfig */ public Halconfig setInmemoryHalConfig(ByteArrayInputStream is) throws IllegalArgumentException { Halconfig halconfig = parseHalconfig(is); DaemonTaskHandler.setContext(halconfig); return halconfig; }
public void backupConfig() { // It's possible we are asked to backup the halconfig without having loaded it first. boolean backup = useBackup; useBackup = false; getHalconfig(); useBackup = backup; saveConfigTo(halconfigDirectoryStructure.getBackupConfigPath()); }
public String create() { String halconfigDir = directoryStructure.getHalconfigDirectory(); halconfigParser.backupConfig(); Halconfig halconfig = halconfigParser.getHalconfig(); halconfig.backupLocalFiles(directoryStructure.getBackupConfigDependenciesPath().toString()); halconfig.makeLocalFilesRelative(halconfigDir); halconfigParser.saveConfig(); String tarOutputName = String.format("halbackup-%s.tar", new Date()).replace(" ", "_").replace(":", "-"); String halconfigTar = Paths.get(System.getProperty("user.home"), tarOutputName).toString(); try { tarHalconfig(halconfigDir, halconfigTar); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Unable to safely backup halconfig " + e.getMessage(), e); } finally { halconfigParser.switchToBackupConfig(); halconfigParser.getHalconfig(); halconfigParser.saveConfig(); halconfigParser.switchToPrimaryConfig(); } return halconfigTar; }
public NodeDiff configDiff(String deploymentName) { try { DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); halconfigParser.switchToBackupConfig(); DeploymentConfiguration oldDeploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); return deploymentConfiguration.diff(oldDeploymentConfiguration); } finally { halconfigParser.switchToPrimaryConfig(); } }
public void restore(String backupTar) { String halconfigDir = directoryStructure.getHalconfigDirectory(); untarHalconfig(halconfigDir, backupTar); Halconfig halconfig = halconfigParser.getHalconfig(); halconfig.makeLocalFilesAbsolute(halconfigDir); halconfigParser.saveConfig(); }
/** * Returns the current halconfig stored at the halconfigPath. * * @return the fully parsed halconfig. * @see Halconfig */ public Halconfig getHalconfig() { Halconfig local = (Halconfig) DaemonTaskHandler.getContext(); if (local == null) { try { InputStream is = getHalconfigStream(); local = parseHalconfig(is); } catch (FileNotFoundException ignored) { // leave res as `null` } catch (ParserException e) { throw new ParseConfigException(e); } catch (ScannerException e) { throw new ParseConfigException(e); } catch (IllegalArgumentException e) { throw new ParseConfigException(e); } } local = transformHalconfig(local); DaemonTaskHandler.setContext(local); return local; }
halconfigParser.backupConfig();
/** * Write your halconfig object to the halconfigPath. */ public void saveConfig() { saveConfigTo(Paths.get(halconfigPath)); }
public String create() { String halconfigDir = directoryStructure.getHalconfigDirectory(); halconfigParser.backupConfig(); Halconfig halconfig = halconfigParser.getHalconfig(); halconfig.backupLocalFiles(directoryStructure.getBackupConfigDependenciesPath().toString()); halconfig.makeLocalFilesRelative(halconfigDir); halconfigParser.saveConfig(); String tarOutputName = String.format("halbackup-%s.tar", new Date()).replace(" ", "_").replace(":", "-"); String halconfigTar = Paths.get(System.getProperty("user.home"), tarOutputName).toString(); try { tarHalconfig(halconfigDir, halconfigTar); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Unable to safely backup halconfig " + e.getMessage(), e); } finally { halconfigParser.switchToBackupConfig(); halconfigParser.getHalconfig(); halconfigParser.saveConfig(); halconfigParser.switchToPrimaryConfig(); } return halconfigTar; }
public NodeDiff configDiff(String deploymentName) { try { DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); halconfigParser.switchToBackupConfig(); DeploymentConfiguration oldDeploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); return deploymentConfiguration.diff(oldDeploymentConfiguration); } finally { halconfigParser.switchToPrimaryConfig(); } }
public void restore(String backupTar) { String halconfigDir = directoryStructure.getHalconfigDirectory(); untarHalconfig(halconfigDir, backupTar); Halconfig halconfig = halconfigParser.getHalconfig(); halconfig.makeLocalFilesAbsolute(halconfigDir); halconfigParser.saveConfig(); }
/** * Returns the current halconfig stored at the halconfigPath. * * @return the fully parsed halconfig. * @see Halconfig */ public Halconfig getHalconfig() { Halconfig local = (Halconfig) DaemonTaskHandler.getContext(); if (local == null) { try { InputStream is = getHalconfigStream(); local = parseHalconfig(is); } catch (FileNotFoundException ignored) { // leave res as `null` } catch (ParserException e) { throw new ParseConfigException(e); } catch (ScannerException e) { throw new ParseConfigException(e); } catch (IllegalArgumentException e) { throw new ParseConfigException(e); } } local = transformHalconfig(local); DaemonTaskHandler.setContext(local); return local; }
halconfigParser.backupConfig();
/** * Write your halconfig object to the halconfigPath. */ public void saveConfig() { saveConfigTo(Paths.get(halconfigPath)); }
public Halconfig getConfig() { return halconfigParser.getHalconfig(); }
public void backupConfig() { // It's possible we are asked to backup the halconfig without having loaded it first. boolean backup = useBackup; useBackup = false; getHalconfig(); useBackup = backup; saveConfigTo(halconfigDirectoryStructure.getBackupConfigPath()); }
/** * Parse Halyard's config for inmemory usage. HalConfigs parsed with this function will NOT be written to disk for * persistence. * * @param is is the input stream to read from. * @return the fully parsed halconfig. * @see Halconfig */ public Halconfig setInmemoryHalConfig(ByteArrayInputStream is) throws IllegalArgumentException { Halconfig halconfig = parseHalconfig(is); DaemonTaskHandler.setContext(halconfig); return halconfig; }
/** * Given a node filter and a node type, find all nodes that match both the filter and the type of the Node. * @param filter is the filter to lookup by. * @param clazz is the class of the node type we want to find. * @return the nodes matching the filter and clazz. */ public <T extends Node> List<T> getMatchingNodesOfType(NodeFilter filter, Class<T> clazz) { Halconfig halconfig = parser.getHalconfig(); return getMatchingNodes(halconfig, filter) .stream() .filter(clazz::isInstance) .map(n -> (T) n) .collect(Collectors.toList()); }
/** * Given a node filter and a node type, find all nodes that match both the filter and the type of the Node. * @param filter is the filter to lookup by. * @param clazz is the class of the node type we want to find. * @return the nodes matching the filter and clazz. */ public <T extends Node> List<T> getMatchingNodesOfType(NodeFilter filter, Class<T> clazz) { Halconfig halconfig = parser.getHalconfig(); return getMatchingNodes(halconfig, filter) .stream() .filter(clazz::isInstance) .map(n -> (T) n) .collect(Collectors.toList()); }