use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ValidationUtilTest method validateLeafNode.
@Test
public void validateLeafNode() {
var rootsNode = new SuperRoot(key -> null, Map.of(ValidatedRootConfiguration.KEY, root));
Validator<LeafValidation, String> validator = new Validator<>() {
@Override
public void validate(LeafValidation annotation, ValidationContext<String> ctx) {
assertEquals("root.child.str", ctx.currentKey());
assertEquals("foo", ctx.getOldValue());
assertEquals("foo", ctx.getNewValue());
ctx.addIssue(new ValidationIssue("bar"));
}
};
Map<Class<? extends Annotation>, Set<Validator<?, ?>>> validators = Map.of(LeafValidation.class, Set.of(validator));
List<ValidationIssue> issues = ValidationUtil.validate(rootsNode, rootsNode, null, new HashMap<>(), validators);
assertEquals(1, issues.size());
assertEquals("bar", issues.get(0).message());
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ValidationUtilTest method validateInnerNode.
@Test
public void validateInnerNode() throws Exception {
var rootsNode = new SuperRoot(key -> null, Map.of(ValidatedRootConfiguration.KEY, root));
Validator<InnerValidation, ValidatedChildView> validator = new Validator<>() {
@Override
public void validate(InnerValidation annotation, ValidationContext<ValidatedChildView> ctx) {
assertEquals("root.child", ctx.currentKey());
assertEquals("foo", ctx.getOldValue().str());
assertEquals("foo", ctx.getNewValue().str());
ctx.addIssue(new ValidationIssue("bar"));
}
};
Map<Class<? extends Annotation>, Set<Validator<?, ?>>> validators = Map.of(InnerValidation.class, Set.of(validator));
List<ValidationIssue> issues = ValidationUtil.validate(rootsNode, rootsNode, null, new HashMap<>(), validators);
assertEquals(1, issues.size());
assertEquals("bar", issues.get(0).message());
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ColumnTypeValidatorImpl method validate.
/**
* {@inheritDoc}
*/
@Override
public void validate(ColumnTypeValidator annotation, ValidationContext<ColumnTypeView> ctx) {
ColumnTypeView newType = ctx.getNewValue();
ColumnTypeView oldType = ctx.getOldValue();
try {
SchemaConfigurationConverter.convert(newType);
} catch (IllegalArgumentException ex) {
ctx.addIssue(new ValidationIssue(ctx.currentKey() + ": " + ex.getMessage()));
return;
}
if (oldType == null) {
// Nothing to do.
return;
}
if (!Objects.deepEquals(newType.type(), oldType.type()) || newType.precision() != oldType.precision() || newType.scale() != oldType.scale() || newType.length() != oldType.length()) {
ctx.addIssue(new ValidationIssue("Unsupported column type change: " + ctx.currentKey()));
}
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class TableValidatorImpl method validateDataRegion.
/**
* Checks that data region configuration is valid. Check involves data region existence and region type preservation if it's updated.
*
* @param oldTable Previous configuration, maybe {@code null}.
* @param newTable New configuration.
* @param ctx Validation context.
*/
private static void validateDataRegion(@Nullable TableView oldTable, TableView newTable, ValidationContext<?> ctx) {
DataStorageView oldDbCfg = ctx.getOldRoot(DataStorageConfiguration.KEY);
DataStorageView newDbCfg = ctx.getNewRoot(DataStorageConfiguration.KEY);
if (oldTable != null && Objects.equals(oldTable.dataRegion(), newTable.dataRegion())) {
return;
}
DataRegionView newRegion = dataRegion(newDbCfg, newTable.dataRegion());
if (newRegion == null) {
ctx.addIssue(new ValidationIssue(String.format("Data region '%s' configured for table '%s' isn't found", newTable.dataRegion(), newTable.name())));
return;
}
if (oldDbCfg == null || oldTable == null) {
return;
}
DataRegionView oldRegion = dataRegion(oldDbCfg, oldTable.dataRegion());
if (!oldRegion.type().equalsIgnoreCase(newRegion.type())) {
ctx.addIssue(new ValidationIssue(String.format("Unable to move table '%s' from region '%s' to region '%s' because it has different type (old=%s, new=%s)", newTable.name(), oldTable.dataRegion(), newTable.dataRegion(), oldRegion.type(), newRegion.type())));
}
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class TableValidatorImpl method validateNamedListKeys.
/**
* Checks that columns and indices are stored under their names in the corresponding Named Lists, i.e. their Named List keys and names
* are the same.
*
* @param table Table configuration view.
* @param ctx Validation context.
*/
private static void validateNamedListKeys(TableView table, ValidationContext<NamedListView<TableView>> ctx) {
NamedListView<? extends ColumnView> columns = table.columns();
for (String key : columns.namedListKeys()) {
ColumnView column = columns.get(key);
if (!column.name().equals(key)) {
var issue = new ValidationIssue(String.format("Column name \"%s\" does not match its Named List key: \"%s\"", column.name(), key));
ctx.addIssue(issue);
}
}
NamedListView<? extends TableIndexView> indices = table.indices();
for (String key : indices.namedListKeys()) {
TableIndexView index = indices.get(key);
if (!index.name().equals(key)) {
var issue = new ValidationIssue(String.format("Index name \"%s\" does not match its Named List key: \"%s\"", index.name(), key));
ctx.addIssue(issue);
}
}
}
Aggregations