use of com.netflix.spinnaker.halyard.config.model.v1.node.Node in project halyard by spinnaker.
the class ValidateService method recursiveValidate.
private void recursiveValidate(ConfigProblemSetBuilder psBuilder, Node node, NodeFilter filter) {
int runCount = validatorCollection.runAllValidators(psBuilder, node);
log.info("Ran " + runCount + " validators for node \"" + node.getNodeName() + "\" with class \"" + node.getClass().getSimpleName() + "\"");
NodeIterator children = node.getChildren();
Node recurse = children.getNext(filter);
while (recurse != null) {
recursiveValidate(psBuilder, recurse, filter);
recurse = children.getNext(filter);
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Node in project halyard by spinnaker.
the class FieldValidator method validateFieldForSpinnakerVersion.
private void validateFieldForSpinnakerVersion(ConfigProblemSetBuilder p, Node n) {
DeploymentConfiguration deploymentConfiguration = n.parentOfType(DeploymentConfiguration.class);
String spinnakerVersion = deploymentConfiguration.getVersion();
if (spinnakerVersion == null) {
return;
}
Class clazz = n.getClass();
while (clazz != Object.class) {
Class finalClazz = clazz;
Arrays.stream(clazz.getDeclaredFields()).forEach(field -> {
ValidForSpinnakerVersion annotation = field.getDeclaredAnnotation(ValidForSpinnakerVersion.class);
try {
field.setAccessible(true);
Object v = field.get(n);
boolean fieldNotValid = v != null && annotation != null && Versions.lessThan(spinnakerVersion, annotation.lowerBound());
// If the field was set to false, it's assumed it's not enabling a restricted feature
if (fieldNotValid && (v instanceof Boolean) && !((Boolean) v)) {
fieldNotValid = false;
}
if (fieldNotValid) {
p.addProblem(Problem.Severity.WARNING, "Field " + finalClazz.getSimpleName() + "." + field.getName() + " not supported for Spinnaker version " + spinnakerVersion + ": " + annotation.message()).setRemediation("Use at least " + annotation.lowerBound() + " (It may not have been released yet).");
}
} catch (NumberFormatException e) {
log.info("Nightly builds do not contain version information.");
} catch (IllegalAccessException e) {
log.warn("Error validating field " + finalClazz.getSimpleName() + "." + field.getName() + ": ", e);
}
});
clazz = clazz.getSuperclass();
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Node in project halyard by spinnaker.
the class Node method backupLocalFiles.
public List<String> backupLocalFiles(String outputPath) {
List<String> files = new ArrayList<>();
Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> {
try {
f.setAccessible(true);
String fPath = (String) f.get(n);
if (fPath == null) {
return null;
}
File fFile = new File(fPath);
String fName = fFile.getName();
// Hash the path to uniquely flatten all files into the output directory
Path newName = Paths.get(outputPath, Math.abs(fPath.hashCode()) + "-" + fName);
File parent = newName.toFile().getParentFile();
if (!parent.exists()) {
parent.mkdirs();
} else if (fFile.getParent().equals(parent.toString())) {
// Don't move paths that are already in the right folder
return fPath;
}
Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING);
f.set(n, newName.toString());
return newName.toString();
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e);
} catch (IOException e) {
throw new HalException(FATAL, "Failed to backup user file: " + e.getMessage(), e);
} finally {
f.setAccessible(false);
}
}).filter(Objects::nonNull).collect(Collectors.toList()));
recursiveConsume(fileFinder);
return files;
}
Aggregations