Search in sources :

Example 1 with Data

use of org.apache.ignite.internal.configuration.storage.Data 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 Data

use of org.apache.ignite.internal.configuration.storage.Data in project ignite-3 by apache.

the class ConfigurationChangerTest method testFailedToWrite.

/**
 * Test that change fails with right exception if storage is inaccessible.
 */
@Test
public void testFailedToWrite() {
    ConfigurationChanger changer = createChanger(KEY);
    storage.fail(true);
    assertThrows(ConfigurationChangeException.class, changer::start);
    storage.fail(false);
    changer.start();
    storage.fail(true);
    assertThrows(ExecutionException.class, () -> changer.change(source(KEY, (FirstChange parent) -> parent.changeChild(child -> child.changeIntCfg(1).changeStrCfg("1")))).get(1, SECONDS));
    storage.fail(false);
    Data dataFromStorage = storage.readAll();
    Map<String, ? extends Serializable> dataMap = dataFromStorage.values();
    assertEquals(0, dataMap.size());
    FirstView newRoot = (FirstView) changer.getRootNode(KEY);
    assertNotNull(newRoot.child());
    assertNull(newRoot.child().strCfg());
}
Also used : Data(org.apache.ignite.internal.configuration.storage.Data) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

Data (org.apache.ignite.internal.configuration.storage.Data)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 ConfigurationChangeException (org.apache.ignite.configuration.ConfigurationChangeException)1 StorageException (org.apache.ignite.internal.configuration.storage.StorageException)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 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.jupiter.api.Test)1