use of com.netflix.spinnaker.halyard.config.model.v1.node.ValidForSpinnakerVersion 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();
}
}
Aggregations