Search in sources :

Example 11 with InnerNode

use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.

the class DynamicConfiguration method change.

/**
 * {@inheritDoc}
 */
@Override
public final CompletableFuture<Void> change(Consumer<CHANGET> change) {
    Objects.requireNonNull(change, "Configuration consumer cannot be null.");
    if (listenOnly) {
        throw listenOnlyException();
    }
    assert keys instanceof RandomAccess;
    ConfigurationSource src = new ConfigurationSource() {

        /**
         * Current index in the {@code keys}.
         */
        private int level = 0;

        /**
         * {@inheritDoc}
         */
        @Override
        public void descend(ConstructableTreeNode node) {
            if (level == keys.size()) {
                if (node instanceof InnerNode) {
                    // To support polymorphic configuration.
                    change.accept(((InnerNode) node).specificNode());
                } else {
                    // To support namedList configuration.
                    change.accept((CHANGET) node);
                }
            } else {
                node.construct(keys.get(level++), this, true);
            }
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void reset() {
            level = 0;
        }
    };
    // Use resulting tree as update request for the storage.
    return changer.change(src);
}
Also used : ConfigurationSource(org.apache.ignite.internal.configuration.tree.ConfigurationSource) RandomAccess(java.util.RandomAccess) ConstructableTreeNode(org.apache.ignite.internal.configuration.tree.ConstructableTreeNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode)

Example 12 with InnerNode

use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.

the class ConfigurationUtilTest method fillFromPrefixMapSuccessfullyWithRemove.

/**
 * Tests that patching of configuration node with a prefix map works fine when prefix map is valid.
 */
@Test
public void fillFromPrefixMapSuccessfullyWithRemove() {
    InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
    ParentChange parentChange = (ParentChange) parentNode;
    parentChange.changeElements(elements -> elements.createOrUpdate("name", element -> element.changeChild(child -> {
    })));
    UUID internalId = ((InnerNode) ((ParentView) parentNode).elements().get("name")).internalId();
    ConfigurationUtil.fillFromPrefixMap(parentNode, Map.of("elements", singletonMap(internalId.toString(), null)));
    assertNull(parentChange.elements().get("node"));
}
Also used : PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Arrays(java.util.Arrays) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) DISTRIBUTED(org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ConfigurationUtil.addDefaults(org.apache.ignite.internal.configuration.util.ConfigurationUtil.addDefaults) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) UUID(java.util.UUID) RootKey(org.apache.ignite.configuration.RootKey) Serializable(java.io.Serializable) ConfigurationUtil.removeLastKey(org.apache.ignite.internal.configuration.util.ConfigurationUtil.removeLastKey) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) List(java.util.List) NAME(org.apache.ignite.internal.configuration.tree.NamedListNode.NAME) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) ConfigurationUtil.checkConfigurationType(org.apache.ignite.internal.configuration.util.ConfigurationUtil.checkConfigurationType) ConfigurationUtil.collectSchemas(org.apache.ignite.internal.configuration.util.ConfigurationUtil.collectSchemas) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Config(org.apache.ignite.configuration.annotation.Config) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) EMPTY_CFG_SRC(org.apache.ignite.internal.configuration.util.ConfigurationUtil.EMPTY_CFG_SRC) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) ORDER_IDX(org.apache.ignite.internal.configuration.tree.NamedListNode.ORDER_IDX) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) ConfigurationUtil.internalSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.internalSchemaExtensions) TraversableTreeNode(org.apache.ignite.internal.configuration.tree.TraversableTreeNode) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) ConfigurationUtil.extensionsFields(org.apache.ignite.internal.configuration.util.ConfigurationUtil.extensionsFields) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ConfigurationUtil.compressDeletedEntries(org.apache.ignite.internal.configuration.util.ConfigurationUtil.compressDeletedEntries) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Consumer(java.util.function.Consumer) ConverterToMapVisitor(org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationUtil.find(org.apache.ignite.internal.configuration.util.ConfigurationUtil.find) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ConfigurationUtil.polymorphicSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.polymorphicSchemaExtensions) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Value(org.apache.ignite.configuration.annotation.Value) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) UUID(java.util.UUID) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Test(org.junit.jupiter.api.Test)

Example 13 with InnerNode

use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.

the class ConfigurationUtilTest method findNulls.

/**
 * Tests that {@link ConfigurationUtil#find(List, TraversableTreeNode, boolean)} returns null when path points to nonexistent named list
 * element.
 */
@Test
public void findNulls() {
    InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
    ParentChange parentChange = (ParentChange) parentNode;
    assertNull(ConfigurationUtil.find(List.of("elements", "name"), parentNode, true));
    parentChange.changeElements(elements -> elements.createOrUpdate("name", element -> {
    }));
    assertNull(ConfigurationUtil.find(List.of("elements", "name", "child", "str"), parentNode, true));
}
Also used : PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Arrays(java.util.Arrays) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) DISTRIBUTED(org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ConfigurationUtil.addDefaults(org.apache.ignite.internal.configuration.util.ConfigurationUtil.addDefaults) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) UUID(java.util.UUID) RootKey(org.apache.ignite.configuration.RootKey) Serializable(java.io.Serializable) ConfigurationUtil.removeLastKey(org.apache.ignite.internal.configuration.util.ConfigurationUtil.removeLastKey) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) List(java.util.List) NAME(org.apache.ignite.internal.configuration.tree.NamedListNode.NAME) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) ConfigurationUtil.checkConfigurationType(org.apache.ignite.internal.configuration.util.ConfigurationUtil.checkConfigurationType) ConfigurationUtil.collectSchemas(org.apache.ignite.internal.configuration.util.ConfigurationUtil.collectSchemas) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Config(org.apache.ignite.configuration.annotation.Config) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) EMPTY_CFG_SRC(org.apache.ignite.internal.configuration.util.ConfigurationUtil.EMPTY_CFG_SRC) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) ORDER_IDX(org.apache.ignite.internal.configuration.tree.NamedListNode.ORDER_IDX) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) ConfigurationUtil.internalSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.internalSchemaExtensions) TraversableTreeNode(org.apache.ignite.internal.configuration.tree.TraversableTreeNode) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) ConfigurationUtil.extensionsFields(org.apache.ignite.internal.configuration.util.ConfigurationUtil.extensionsFields) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ConfigurationUtil.compressDeletedEntries(org.apache.ignite.internal.configuration.util.ConfigurationUtil.compressDeletedEntries) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Consumer(java.util.function.Consumer) ConverterToMapVisitor(org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationUtil.find(org.apache.ignite.internal.configuration.util.ConfigurationUtil.find) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ConfigurationUtil.polymorphicSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.polymorphicSchemaExtensions) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Value(org.apache.ignite.configuration.annotation.Value) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Test(org.junit.jupiter.api.Test)

Example 14 with InnerNode

use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.

the class ConfigurationUtilTest method fillFromPrefixMapSuccessfully.

/**
 * Tests that patching of configuration node with a prefix map works fine when prefix map is valid.
 */
@Test
public void fillFromPrefixMapSuccessfully() {
    InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
    ParentChange parentChange = (ParentChange) parentNode;
    ConfigurationUtil.fillFromPrefixMap(parentNode, Map.of("elements", Map.of("01234567-89ab-cdef-0123-456789abcdef", Map.of("child", Map.of("str", "value2"), ORDER_IDX, 1, NAME, "name2"), "12345678-9abc-def0-1234-56789abcdef0", Map.of("child", Map.of("str", "value1"), ORDER_IDX, 0, NAME, "name1"))));
    assertEquals("value1", parentChange.elements().get("name1").child().str());
    assertEquals("value2", parentChange.elements().get("name2").child().str());
}
Also used : RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Test(org.junit.jupiter.api.Test)

Example 15 with InnerNode

use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.

the class ConfigurationUtilTest method testFindInternalConfigs.

@Test
void testFindInternalConfigs() {
    Map<Class<?>, Set<Class<?>>> internalExtensions = internalSchemaExtensions(List.of(InternalFirstRootConfigurationSchema.class, InternalSecondRootConfigurationSchema.class, InternalFirstConfigurationSchema.class, InternalSecondConfigurationSchema.class));
    ConfigurationAsmGenerator generator = new ConfigurationAsmGenerator();
    generator.compileRootSchema(InternalRootConfigurationSchema.class, internalExtensions, Map.of());
    InnerNode innerNode = generator.instantiateNode(InternalRootConfigurationSchema.class);
    addDefaults(innerNode);
    // Check that no internal configuration will be found.
    assertThrows(KeyNotFoundException.class, () -> find(List.of("str2"), innerNode, false));
    assertThrows(KeyNotFoundException.class, () -> find(List.of("str3"), innerNode, false));
    assertThrows(KeyNotFoundException.class, () -> find(List.of("subCfg1"), innerNode, false));
    assertThrows(KeyNotFoundException.class, () -> find(List.of("subCfg", "str01"), innerNode, false));
    assertThrows(KeyNotFoundException.class, () -> find(List.of("subCfg", "str02"), innerNode, false));
    // Check that internal configuration will be found.
    assertNull(find(List.of("str2"), innerNode, true));
    assertEquals("foo", find(List.of("str3"), innerNode, true));
    assertNotNull(find(List.of("subCfg1"), innerNode, true));
    assertEquals("foo", find(List.of("subCfg", "str01"), innerNode, true));
    assertEquals("foo", find(List.of("subCfg", "str02"), innerNode, true));
}
Also used : Set(java.util.Set) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Test(org.junit.jupiter.api.Test)

Aggregations

InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)20 HashMap (java.util.HashMap)13 Serializable (java.io.Serializable)12 List (java.util.List)12 Map (java.util.Map)12 NoSuchElementException (java.util.NoSuchElementException)11 Set (java.util.Set)11 NamedListNode (org.apache.ignite.internal.configuration.tree.NamedListNode)11 Collectors.toList (java.util.stream.Collectors.toList)10 RootKey (org.apache.ignite.configuration.RootKey)10 RootInnerNode (org.apache.ignite.internal.configuration.RootInnerNode)10 Test (org.junit.jupiter.api.Test)10 Arrays (java.util.Arrays)9 UUID (java.util.UUID)9 Consumer (java.util.function.Consumer)9 Config (org.apache.ignite.configuration.annotation.Config)9 ConfigurationRoot (org.apache.ignite.configuration.annotation.ConfigurationRoot)9 InternalConfiguration (org.apache.ignite.configuration.annotation.InternalConfiguration)9 NamedConfigValue (org.apache.ignite.configuration.annotation.NamedConfigValue)9 PolymorphicConfig (org.apache.ignite.configuration.annotation.PolymorphicConfig)9