Add legacy-config new feature

This feature makes the legacy configuration optional.
It was used by brmsgw and other tooling to provision
via its DMaaP channel.   The capability to configure
via PdpConfiguration object is kept in the core
preserving backwards compatibility, but the DMaaP
provisioning channel(s) are optional.

Issue-ID: POLICY-2618
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Ia7198ac3b2810d85133c06ba5217a9c28e07ac4c
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
diff --git a/feature-legacy-config/src/main/feature/config/feature-legacy-config.properties b/feature-legacy-config/src/main/feature/config/feature-legacy-config.properties
new file mode 100644
index 0000000..fad3224
--- /dev/null
+++ b/feature-legacy-config/src/main/feature/config/feature-legacy-config.properties
@@ -0,0 +1,28 @@
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# 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.
+# ============LICENSE_END=========================================================
+
+dmaap.source.topics=PDPD-CONFIGURATION
+
+dmaap.source.topics.PDPD-CONFIGURATION.servers=${envd:DMAAP_SERVERS}
+dmaap.source.topics.PDPD-CONFIGURATION.effectiveTopic=${envd:PDPD_CONFIGURATION_TOPIC}
+dmaap.source.topics.PDPD-CONFIGURATION.apiKey=${envd:PDPD_CONFIGURATION_API_KEY}
+dmaap.source.topics.PDPD-CONFIGURATION.apiSecret=${envd:PDPD_CONFIGURATION_API_SECRET}
+dmaap.source.topics.PDPD-CONFIGURATION.consumerGroup=${envd:PDPD_CONFIGURATION_CONSUMER_GROUP}
+dmaap.source.topics.PDPD-CONFIGURATION.consumerInstance=${envd:PDPD_CONFIGURATION_CONSUMER_INSTANCE}
+dmaap.source.topics.PDPD-CONFIGURATION.managed=false
+dmaap.source.topics.PDPD-CONFIGURATION.https=true
diff --git a/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfig.java b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfig.java
new file mode 100644
index 0000000..01cc3b3
--- /dev/null
+++ b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfig.java
@@ -0,0 +1,93 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.legacy.config;
+
+import java.util.List;
+import java.util.Properties;
+import lombok.Getter;
+import org.onap.policy.common.capabilities.Startable;
+import org.onap.policy.common.endpoints.event.comm.Topic;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.event.comm.TopicListener;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Legacy Configurator.
+ */
+public class LegacyConfig implements Startable, TopicListener {
+
+    private static final Logger logger = LoggerFactory.getLogger(LegacyConfig.class);
+    private static final String CONFIGURATION_PROPERTIES_NAME = "feature-legacy-config";
+
+    @Getter
+    private final Properties properties;
+
+    @Getter
+    private TopicSource source;
+
+    /**
+     * Constructor.
+     */
+    public LegacyConfig() {
+        properties = SystemPersistenceConstants.getManager().getProperties(CONFIGURATION_PROPERTIES_NAME);
+        List<TopicSource> sources = TopicEndpointManager.getManager().addTopicSources(properties);
+        if (sources.isEmpty()) {
+            throw new IllegalStateException("LegacyConfig cannot be instantiated, no sources");
+        }
+
+        this.source = sources.get(0);
+        if (sources.size() != 1) {
+            logger.warn("LegacyConfig: more than one source is configured ({}), using {}",
+                    sources.size(), this.source);
+        }
+
+        source.register(this);
+    }
+
+    @Override
+    public boolean start() {
+        return source.start();
+    }
+
+    @Override
+    public boolean stop() {
+        return source.stop();
+    }
+
+    @Override
+    public void shutdown() {
+        source.shutdown();
+    }
+
+    @Override
+    public boolean isAlive() {
+        return source.isAlive();
+    }
+
+    @Override
+    public void onTopicEvent(Topic.CommInfrastructure comm, String topic, String event) {
+        PolicyEngineConstants.getManager().onTopicEvent(comm, topic, event);
+    }
+}
diff --git a/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfigFeature.java b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfigFeature.java
new file mode 100644
index 0000000..640c32a
--- /dev/null
+++ b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfigFeature.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.legacy.config;
+
+import lombok.Getter;
+import org.onap.policy.drools.features.PolicyEngineFeatureApi;
+import org.onap.policy.drools.system.PolicyEngine;
+
+/**
+ * The LegacyConfigFeature enables legacy configuration mechanisms
+ * in the PDP-D.
+ */
+public class LegacyConfigFeature implements PolicyEngineFeatureApi {
+
+    protected static final int SEQNO = 1;
+
+    @Getter
+    private static final LegacyConfig legacyConfig = new LegacyConfig();
+
+    @Override
+    public int getSequenceNumber() {
+        return SEQNO;
+    }
+
+    @Override
+    public boolean afterOpen(PolicyEngine engine) {
+        getLegacyConfig().start();
+        return false;
+    }
+
+    @Override
+    public boolean beforeShutdown(PolicyEngine engine) {
+        getLegacyConfig().shutdown();
+        return false;
+    }
+
+}
diff --git a/feature-legacy-config/src/main/java/org/onap/policy/drools/server/restful/RestLegacyConfigManager.java b/feature-legacy-config/src/main/java/org/onap/policy/drools/server/restful/RestLegacyConfigManager.java
new file mode 100644
index 0000000..e8d9153
--- /dev/null
+++ b/feature-legacy-config/src/main/java/org/onap/policy/drools/server/restful/RestLegacyConfigManager.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.server.restful;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import java.util.Properties;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
+import org.onap.policy.drools.legacy.config.LegacyConfigFeature;
+
+/**
+ * REST Legacy Configuration Manager.
+ */
+
+@Path("/policy/pdp/engine/legacy/config")
+@Produces({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
+@Consumes({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
+@Api
+public class RestLegacyConfigManager {
+
+    /**
+     * GET properties.
+     */
+    @GET
+    @Path("properties")
+    @ApiOperation(value = "Retrieves the legacy configuration properties",
+            notes = "Legacy Configuration Properties", response = Properties.class)
+    public Response properties() {
+        return Response.status(Response.Status.OK)
+                       .entity(LegacyConfigFeature.getLegacyConfig().getProperties()).build();
+    }
+
+    /**
+     * GET the topic source.
+     */
+    @GET
+    @Path("topic/source")
+    @ApiOperation(value = "Retrieves the legacy configuration topic source",
+            notes = "Legacy Configuration Source", response = TopicSource.class)
+    public Response source() {
+        return Response.status(Response.Status.OK)
+                       .entity(LegacyConfigFeature.getLegacyConfig().getSource()).build();
+    }
+}
diff --git a/feature-legacy-config/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi b/feature-legacy-config/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
new file mode 100644
index 0000000..c18510e
--- /dev/null
+++ b/feature-legacy-config/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
@@ -0,0 +1 @@
+org.onap.policy.drools.legacy.config.LegacyConfigFeature