catalog: Add catalog validation to verify plan shapes don't change across versions
@@ -358,9 +358,48 @@ public class DefaultVersionedCatalog extends ValidatingConfig<DefaultVersionedCa
}
errors.addAll(c.validate(c, errors));
}
+
+ validateUniformPlanShapeAcrossVersions(errors);
+
return errors;
}
+ private void validateUniformPlanShapeAcrossVersions(final ValidationErrors errors) {
+ for (int i = 0; i < versions.size(); i++) {
+ final StandaloneCatalog c = versions.get(i);
+ for (final Plan plan : c.getPlans()) {
+
+ for (int j = i+1; j < versions.size(); j++) {
+ final StandaloneCatalog next = versions.get(j);
+ final Plan targetPlan = next.getPlans().findByName(plan.getName());
+ if (targetPlan != null) {
+ validatePlanShape(plan, targetPlan, errors);
+ }
+ // We don't break if null , targetPlan could be re-defined on a subsequent version
+ // TODO enforce that we can't skip versions?
+ }
+ }
+ }
+ }
+
+ private void validatePlanShape(final Plan plan, final Plan targetPlan, final ValidationErrors errors) {
+ if (plan.getAllPhases().length != targetPlan.getAllPhases().length) {
+ errors.add(new ValidationError(String.format("Number of phases for plan '%s' differs between version '%s' and '%s'",
+ plan.getName(), plan.getCatalog().getEffectiveDate(), targetPlan.getCatalog().getEffectiveDate()),
+ VersionedCatalog.class, ""));
+ }
+
+ for (int i = 0; i < plan.getAllPhases().length; i++) {
+ final PlanPhase cur = plan.getAllPhases()[i];
+ final PlanPhase target = targetPlan.getAllPhases()[i];
+ if (!cur.getName().equals(target.getName())) {
+ errors.add(new ValidationError(String.format("Phase '%s'for plan '%s' in version '%s' does not exist in version '%s'",
+ cur.getName(), plan.getName(), plan.getCatalog().getEffectiveDate(), targetPlan.getCatalog().getEffectiveDate()),
+ VersionedCatalog.class, ""));
+ }
+ }
+ }
+
@Override
public Plan getNextPlanVersion(final Plan curPlan) {
