Search in sources :

Example 1 with ConstructableTreeNode

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

the class ConfigurationChanger method initializeDefaults.

/**
 * Initializes the configuration storage - reads data and sets default values for missing configuration properties.
 *
 * @throws ConfigurationValidationException If configuration validation failed.
 * @throws ConfigurationChangeException If configuration framework failed to add default values and save them to storage.
 */
public void initializeDefaults() throws ConfigurationValidationException, ConfigurationChangeException {
    try {
        ConfigurationSource defaultsCfgSource = new ConfigurationSource() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void descend(ConstructableTreeNode node) {
                addDefaults((InnerNode) node);
            }
        };
        changeInternally(defaultsCfgSource).get(5, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof ConfigurationValidationException) {
            throw (ConfigurationValidationException) cause;
        }
        if (cause instanceof ConfigurationChangeException) {
            throw (ConfigurationChangeException) cause;
        }
        throw new ConfigurationChangeException("Failed to write default configuration values into the storage " + storage.getClass(), e);
    } catch (InterruptedException | TimeoutException e) {
        throw new ConfigurationChangeException("Failed to initialize configuration storage " + storage.getClass(), e);
    }
}
Also used : ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) ConfigurationSource(org.apache.ignite.internal.configuration.tree.ConfigurationSource) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) ConstructableTreeNode(org.apache.ignite.internal.configuration.tree.ConstructableTreeNode) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ConstructableTreeNode

use of org.apache.ignite.internal.configuration.tree.ConstructableTreeNode 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 3 with ConstructableTreeNode

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

the class ConfigurationChangerTest method source.

private static <CHANGET> ConfigurationSource source(RootKey<?, ? super CHANGET> rootKey, Consumer<CHANGET> changer) {
    return new ConfigurationSource() {

        @Override
        public void descend(ConstructableTreeNode node) {
            ConfigurationSource changerSrc = new ConfigurationSource() {

                @Override
                public void descend(ConstructableTreeNode node) {
                    changer.accept((CHANGET) node);
                }
            };
            node.construct(rootKey.key(), changerSrc, true);
        }
    };
}
Also used : ConfigurationSource(org.apache.ignite.internal.configuration.tree.ConfigurationSource) ConstructableTreeNode(org.apache.ignite.internal.configuration.tree.ConstructableTreeNode)

Example 4 with ConstructableTreeNode

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

the class DynamicProperty method update.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<Void> update(T newValue) {
    Objects.requireNonNull(newValue, "Configuration value cannot be null.");
    if (listenOnly) {
        throw listenOnlyException();
    }
    if (readOnly) {
        throw new ConfigurationReadOnlyException("Read only mode: " + keys);
    }
    assert keys instanceof RandomAccess;
    assert !keys.isEmpty();
    ConfigurationSource src = new ConfigurationSource() {

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

        /**
         * {@inheritDoc}
         */
        @Override
        public void descend(ConstructableTreeNode node) {
            assert level < keys.size();
            node.construct(keys.get(level++), this, true);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public <T> T unwrap(Class<T> clazz) {
            assert level == keys.size();
            assert clazz.isInstance(newValue);
            return clazz.cast(newValue);
        }

        /**
         * {@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) ConfigurationReadOnlyException(org.apache.ignite.configuration.ConfigurationReadOnlyException) RandomAccess(java.util.RandomAccess) ConstructableTreeNode(org.apache.ignite.internal.configuration.tree.ConstructableTreeNode)

Aggregations

ConfigurationSource (org.apache.ignite.internal.configuration.tree.ConfigurationSource)4 ConstructableTreeNode (org.apache.ignite.internal.configuration.tree.ConstructableTreeNode)4 RandomAccess (java.util.RandomAccess)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConfigurationChangeException (org.apache.ignite.configuration.ConfigurationChangeException)1 ConfigurationReadOnlyException (org.apache.ignite.configuration.ConfigurationReadOnlyException)1 ConfigurationValidationException (org.apache.ignite.configuration.validation.ConfigurationValidationException)1 InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)1