Search in sources :

Example 1 with ConfigurationChangeException

use of org.apache.ignite.configuration.ConfigurationChangeException in project ignite-3 by apache.

the class ConfigurationChanger method start.

/**
 * Start component.
 */
// ConfigurationChangeException, really?
public void start() throws ConfigurationChangeException {
    Data data;
    try {
        data = storage.readAll();
    } catch (StorageException e) {
        throw new ConfigurationChangeException("Failed to initialize configuration: " + e.getMessage(), e);
    }
    SuperRoot superRoot = new SuperRoot(rootCreator());
    Map<String, ?> dataValuesPrefixMap = toPrefixMap(data.values());
    for (RootKey<?, ?> rootKey : rootKeys.values()) {
        Map<String, ?> rootPrefixMap = (Map<String, ?>) dataValuesPrefixMap.get(rootKey.key());
        InnerNode rootNode = createRootNode(rootKey);
        if (rootPrefixMap != null) {
            fillFromPrefixMap(rootNode, rootPrefixMap);
        }
        superRoot.addRoot(rootKey, rootNode);
    }
    // Workaround for distributed configuration.
    addDefaults(superRoot);
    storageRoots = new StorageRoots(superRoot, data.changeId());
    storage.registerConfigurationListener(this::updateFromListener);
}
Also used : ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) Data(org.apache.ignite.internal.configuration.storage.Data) StorageException(org.apache.ignite.internal.configuration.storage.StorageException) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfigurationUtil.fillFromPrefixMap(org.apache.ignite.internal.configuration.util.ConfigurationUtil.fillFromPrefixMap) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) HashMap(java.util.HashMap) ConfigurationUtil.toPrefixMap(org.apache.ignite.internal.configuration.util.ConfigurationUtil.toPrefixMap) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode)

Example 2 with ConfigurationChangeException

use of org.apache.ignite.configuration.ConfigurationChangeException 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)

Aggregations

ConfigurationChangeException (org.apache.ignite.configuration.ConfigurationChangeException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 ConfigurationValidationException (org.apache.ignite.configuration.validation.ConfigurationValidationException)1 Data (org.apache.ignite.internal.configuration.storage.Data)1 StorageException (org.apache.ignite.internal.configuration.storage.StorageException)1 ConfigurationSource (org.apache.ignite.internal.configuration.tree.ConfigurationSource)1 ConstructableTreeNode (org.apache.ignite.internal.configuration.tree.ConstructableTreeNode)1 InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)1 ConfigurationFlattener.createFlattenedUpdatesMap (org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap)1 ConfigurationUtil.fillFromPrefixMap (org.apache.ignite.internal.configuration.util.ConfigurationUtil.fillFromPrefixMap)1 ConfigurationUtil.toPrefixMap (org.apache.ignite.internal.configuration.util.ConfigurationUtil.toPrefixMap)1