Enable MapperConfig to be reconfigurable
Change-Id: Ifa4a186e85cb85758d70a9eb5437d9893f236427
Issue-ID: DCAEGEN2-1357
Signed-off-by: emartin <ephraim.martin@est.tech>
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java
index 03d42d5..b213a45 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java
@@ -95,6 +95,7 @@
dataRouterSubscriber.start();
ArrayList<Configurable> configurables = new ArrayList<>();
configurables.add(dataRouterSubscriber);
+ configurables.add(mapperConfig);
DynamicConfiguration dynamicConfiguration = new DynamicConfiguration(configurables, mapperConfig);
Undertow.builder()
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java
index ffb09ba..bd4eafb 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java
@@ -22,6 +22,7 @@
import java.net.MalformedURLException;
import java.net.URL;
+import org.onap.dcaegen2.services.pmmapper.config.Configurable;
import org.onap.dcaegen2.services.pmmapper.utils.GSONRequired;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
@@ -32,7 +33,7 @@
@Getter
@EqualsAndHashCode
@NoArgsConstructor
-public class MapperConfig {
+public class MapperConfig implements Configurable{
public static final String CLIENT_NAME = "pm-mapper";
@@ -161,4 +162,15 @@
@SerializedName("pm-mapper-filter")
MeasFilterConfig filterConfig;
+
+ @Override
+ public void reconfigure(MapperConfig mapperConfig) {
+ if(!this.equals(mapperConfig)) {
+ this.streamsSubscribes = mapperConfig.getStreamsSubscribes();
+ this.streamsPublishes = mapperConfig.getStreamsPublishes();
+ this.busControllerSubscriptionEndpoint = mapperConfig.getBusControllerSubscriptionEndpoint();
+ this.dmaapDRFeedId = mapperConfig.getDmaapDRFeedId();
+ this.dmaapDRDeleteEndpoint = mapperConfig.getDmaapDRDeleteEndpoint();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java
index 67510da..8840825 100644
--- a/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java
+++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java
@@ -150,4 +150,20 @@
verify(configurable, times(1)).reconfigure(modifiedMapperConfig);
}
+
+ @Test
+ public void testMapperConfigReconfiguration() throws Exception {
+ ConfigHandler configHandler = new ConfigHandler(sender);
+ JsonObject modifiedConfigJson = new JsonParser().parse(config).getAsJsonObject();
+ modifiedConfigJson.addProperty("dmaap_dr_delete_endpoint","http://modified-delete-endpoint/1");
+ String newConfig = modifiedConfigJson.toString();
+
+ when(sender.send(any())).thenReturn(config,newConfig);
+
+ MapperConfig originalConfig = configHandler.getMapperConfig();
+ MapperConfig modifiedConfig = configHandler.getMapperConfig();
+
+ originalConfig.reconfigure(modifiedConfig);
+ assertEquals(originalConfig, modifiedConfig);
+ }
}