Search in sources :

Example 6 with ValidationIssue

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());
}
Also used : Set(java.util.Set) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) Annotation(java.lang.annotation.Annotation) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) Validator(org.apache.ignite.configuration.validation.Validator) Test(org.junit.jupiter.api.Test)

Example 7 with ValidationIssue

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());
}
Also used : Set(java.util.Set) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) Annotation(java.lang.annotation.Annotation) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) Validator(org.apache.ignite.configuration.validation.Validator) Test(org.junit.jupiter.api.Test)

Example 8 with ValidationIssue

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()));
    }
}
Also used : ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) ColumnTypeView(org.apache.ignite.configuration.schemas.table.ColumnTypeView)

Example 9 with ValidationIssue

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())));
    }
}
Also used : DataRegionView(org.apache.ignite.configuration.schemas.store.DataRegionView) DataStorageView(org.apache.ignite.configuration.schemas.store.DataStorageView) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue)

Example 10 with ValidationIssue

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);
        }
    }
}
Also used : ColumnView(org.apache.ignite.configuration.schemas.table.ColumnView) TableIndexView(org.apache.ignite.configuration.schemas.table.TableIndexView) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue)

Aggregations

ValidationIssue (org.apache.ignite.configuration.validation.ValidationIssue)15 ValidationContext (org.apache.ignite.configuration.validation.ValidationContext)7 Test (org.junit.jupiter.api.Test)6 Validator (org.apache.ignite.configuration.validation.Validator)5 Set (java.util.Set)4 NamedListView (org.apache.ignite.configuration.NamedListView)4 Annotation (java.lang.annotation.Annotation)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 DataStorageView (org.apache.ignite.configuration.schemas.store.DataStorageView)3 TableView (org.apache.ignite.configuration.schemas.table.TableView)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Matchers.nullValue (org.hamcrest.Matchers.nullValue)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 TimeUnit (java.util.concurrent.TimeUnit)2 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)2 PageMemoryDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfigurationSchema)2 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)2 UnsafeMemoryAllocatorConfigurationSchema (org.apache.ignite.configuration.schemas.store.UnsafeMemoryAllocatorConfigurationSchema)2 HashIndexChange (org.apache.ignite.configuration.schemas.table.HashIndexChange)2 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)2