private Map<String, Node> serializedNodeFields() { Map<String, Node> res = new HashMap<>(); NodeIterator iterator = this.getChildren(); Node next = iterator.getNext(); while (next != null) { res.put(next.getNodeName(), next); next = iterator.getNext(); } return res; }
/** * @param node is the node to find required files in. * @param deploymentName is the current deployment of Spinnaker being backed up. * @return the list of files required by the node to function. */ protected List<String> backupRequiredFiles(Node node, String deploymentName) { return node.backupLocalFiles(halconfigDirectoryStructure.getStagingDependenciesPath(deploymentName).toString()); }
public NodeDiff setNode(Node node) { location = node.getNameToClass(DeploymentConfiguration.class); return this; }
/** * Checks if the filter matches this node all the way to the root. * * @param filter the filter being checked. * @return true iff the filter accepts this node, as a part of its full context (yaml tree ending at this node). */ @JsonIgnore public boolean matchesToRoot(NodeFilter filter) { boolean result = matchesLocally(filter); if (parent == null || !result) { return result; } return parent.matchesToRoot(filter); }
@JsonIgnore public String getNameToClass(Class<?> clazz) { String name = getNodeName(); if (parent == null || clazz.isAssignableFrom(parent.getClass())) { return name; } else { return parent.getNameToRoot() + "." + name; } }
private void swapLocalFilePrefixes(String to, String from) { Consumer<Node> fileFinder = n -> n.localFiles().forEach(f -> { try { f.setAccessible(true); String fPath = (String) f.get(n); if (fPath == null) { return; } if (fPath.startsWith(to)) { log.info("File " + f.getName() + " was already in correct format " + fPath); return; } if (!fPath.startsWith(from)) { throw new HalException(FATAL, "Local file: " + fPath + " has incorrect prefix - must match " + from); } fPath = to + fPath.substring(from.length()); f.set(n, fPath); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e); } finally { f.setAccessible(false); } }); recursiveConsume(fileFinder); }
String nnt = this.getNodeName(); String nno = other.getNodeName(); if (!nnt.equals(nno)) { throw new RuntimeException( Map<String, Object> fts = this.serializedNonNodeFields(); Map<String, Object> fos = other.serializedNonNodeFields(); Map<String, Node> nts = this.serializedNodeFields(); Map<String, Node> nos = other.serializedNodeFields(); NodeDiff diff = nt.diff(no);
public String debugName() { return "[" + getClass().getSimpleName() + ":" + getNodeName() + "]"; }
public void recursiveConsume(Consumer<Node> consumer) { consumer.accept(this); NodeIterator children = getChildren(); Node child = children.getNext(); while (child != null) { child.recursiveConsume(consumer); child = children.getNext(); } }
@JsonIgnore public void parentify() { NodeIterator children = getChildren(); Node child = children.getNext(); while (child != null) { child.parent = this; child.parentify(); child = children.getNext(); } }
public void stageLocalFiles(Path outputPath) { if (!GlobalApplicationOptions.getInstance().isUseRemoteDaemon()) { return; } localFiles().forEach(f -> { try { f.setAccessible(true); String fContent = (String) f.get(this); if (fContent != null) { CRC32 crc = new CRC32(); crc.update(fContent.getBytes()); String fPath = Paths .get(outputPath.toAbsolutePath().toString(), Long.toHexString(crc.getValue())) .toString(); FileUtils.writeStringToFile(new File(fPath), fContent); f.set(this, fPath); } } catch (IllegalAccessException | IOException e) { throw new RuntimeException("Failed to get local files for node " + this.getNodeName(), e); } finally { f.setAccessible(false); } }); }
private void validateClusters(final ConfigProblemSetBuilder problems, final DCOSAccount account) { final NodeIterator children = account.getParent().getChildren();
public ConfigProblemBuilder addProblem(Severity severity, String message, String field) { ConfigProblemBuilder problemBuilder = new ConfigProblemBuilder(severity, message); if (node != null) { problemBuilder.setNode(node); if (field != null && !field.isEmpty()) { problemBuilder.setOptions(node.fieldOptions(new ConfigProblemSetBuilder(context), field)); } } builders.add(problemBuilder); return problemBuilder; }
public Problem build() { String location = "Global"; if (node != null) { location = node.getNameToRoot(); } return new Problem(message, remediation, options, severity, location); } }
Consumer<Node> fileFinder = n -> referencedFiles.addAll(n.localFiles().stream().map(f -> { try { f.setAccessible(true);
private void swapLocalFilePrefixes(String to, String from) { Consumer<Node> fileFinder = n -> n.localFiles().forEach(f -> { try { f.setAccessible(true); String fPath = (String) f.get(n); if (fPath == null) { return; } if (fPath.startsWith(to)) { log.info("File " + f.getName() + " was already in correct format " + fPath); return; } if (!fPath.startsWith(from)) { throw new HalException(FATAL, "Local file: " + fPath + " has incorrect prefix - must match " + from); } fPath = to + fPath.substring(from.length()); f.set(n, fPath); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e); } finally { f.setAccessible(false); } }); recursiveConsume(fileFinder); }
String nnt = this.getNodeName(); String nno = other.getNodeName(); if (!nnt.equals(nno)) { throw new RuntimeException( Map<String, Object> fts = this.serializedNonNodeFields(); Map<String, Object> fos = other.serializedNonNodeFields(); Map<String, Node> nts = this.serializedNodeFields(); Map<String, Node> nos = other.serializedNodeFields(); NodeDiff diff = nt.diff(no);
public String debugName() { return "[" + getClass().getSimpleName() + ":" + getNodeName() + "]"; }
public void recursiveConsume(Consumer<Node> consumer) { consumer.accept(this); NodeIterator children = getChildren(); Node child = children.getNext(); while (child != null) { child.recursiveConsume(consumer); child = children.getNext(); } }