Fixed issue where component configuration would not propagate on node restart.
Change-Id: I431ce444025cc9a8021dd68fa23c6e8c29fa6c19
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java b/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java
index 5a82a8a..85e826f 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.store.cfg;
+import com.google.common.collect.ImmutableSet;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -31,8 +32,12 @@
import org.onosproject.store.service.MapEventListener;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.Versioned;
import org.slf4j.Logger;
+import java.util.Objects;
+import java.util.Set;
+
import static org.onosproject.cfg.ComponentConfigEvent.Type.PROPERTY_SET;
import static org.onosproject.cfg.ComponentConfigEvent.Type.PROPERTY_UNSET;
import static org.onosproject.store.service.MapEvent.Type.INSERT;
@@ -59,7 +64,7 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
- InternalPropertiesListener propertiesListener = new InternalPropertiesListener();
+ private InternalPropertiesListener propertiesListener = new InternalPropertiesListener();
@Activate
public void activate() {
@@ -90,6 +95,22 @@
properties.remove(key(componentName, name));
}
+ @Override
+ public Set<String> getProperties(String componentName) {
+ ImmutableSet.Builder<String> names = ImmutableSet.builder();
+ properties.keySet().stream()
+ .filter((String k) -> Objects.equals(componentName, k.substring(0, k.indexOf(SEP))))
+ .map((String k) -> k.substring(k.indexOf(SEP) + 1))
+ .forEach(names::add);
+ return names.build();
+ }
+
+ @Override
+ public String getProperty(String componentName, String name) {
+ Versioned<String> v = properties.get(key(componentName, name));
+ return v != null ? v.value() : null;
+ }
+
/**
* Listener to component configuration properties distributed map changes.
*/
diff --git a/core/store/dist/src/test/java/org/onosproject/store/cfg/DistributedComponentConfigStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/cfg/DistributedComponentConfigStoreTest.java
new file mode 100644
index 0000000..ddefb02
--- /dev/null
+++ b/core/store/dist/src/test/java/org/onosproject/store/cfg/DistributedComponentConfigStoreTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.store.cfg;
+
+import com.google.common.collect.ImmutableSet;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.cfg.ComponentConfigEvent;
+import org.onosproject.store.service.TestStorageService;
+
+import static org.junit.Assert.*;
+
+public class DistributedComponentConfigStoreTest {
+
+ private static final String C1 = "c1";
+ private static final String C2 = "c2";
+
+ private TestStore store;
+ private ComponentConfigEvent event;
+
+ /**
+ * Sets up the device key store and the storage service test harness.
+ */
+ @Before
+ public void setUp() {
+ store = new TestStore();
+ store.storageService = new TestStorageService();
+ store.setDelegate(e -> this.event = e);
+ store.activate();
+ }
+
+ /**
+ * Tears down the device key store.
+ */
+ @After
+ public void tearDown() {
+ store.deactivate();
+ }
+
+ @Test
+ public void basics() {
+ assertNull("property should not be found", store.getProperty(C1, "bar"));
+ store.setProperty(C1, "foo", "yo");
+ store.setProperty(C1, "bar", "true");
+ store.setProperty(C2, "goo", "6.28");
+ assertEquals("incorrect event", ComponentConfigEvent.Type.PROPERTY_SET, event.type());
+ assertEquals("incorrect event key", "goo", event.name());
+ assertEquals("incorrect event value", "6.28", event.value());
+
+ assertEquals("incorrect property value", "true", store.getProperty(C1, "bar"));
+ assertEquals("incorrect property count", ImmutableSet.of("foo", "bar"),
+ store.getProperties(C1));
+
+ store.unsetProperty(C1, "bar");
+ assertEquals("incorrect event", ComponentConfigEvent.Type.PROPERTY_UNSET, event.type());
+ assertEquals("incorrect event key", "bar", event.name());
+ assertNull("incorrect event value", event.value());
+
+ assertNull("property should not be found", store.getProperty(C1, "bar"));
+ assertEquals("incorrect property count", ImmutableSet.of("foo"),
+ store.getProperties(C1));
+ }
+
+ class TestStore extends DistributedComponentConfigStore {
+ }
+}
\ No newline at end of file