summaryrefslogtreecommitdiffstats
path: root/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap
diff options
context:
space:
mode:
Diffstat (limited to 'components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap')
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java112
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java65
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java28
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumer.java63
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationProducer.java53
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java58
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java68
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java49
8 files changed, 496 insertions, 0 deletions
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java
new file mode 100644
index 00000000..6e0ea401
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+import com.att.nsa.cambria.client.CambriaConsumer;
+
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.PostConstruct;
+
+import org.onap.slice.analysis.ms.beans.Configuration;
+import org.onap.slice.analysis.ms.utils.DmaapUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class initializes and starts the dmaap client
+ * to listen on application required dmaap events
+ */
+@Component
+public class DmaapClient {
+
+ private Configuration configuration;
+ private static Logger log = LoggerFactory.getLogger(DmaapClient.class);
+
+ private DmaapUtils dmaapUtils;
+
+ /**
+ * init dmaap client.
+ */
+ @PostConstruct
+ public void initClient() {
+ log.debug("initializing client");
+ dmaapUtils = new DmaapUtils();
+ configuration = Configuration.getInstance();
+ if (log.isDebugEnabled()) {
+ log.debug(configuration.toString());
+ }
+
+ startClient();
+ }
+
+ /**
+ * start dmaap client.
+ */
+ @SuppressWarnings("unchecked")
+ public synchronized void startClient() {
+
+ Map<String, Object> streamSubscribes = Configuration.getInstance().getStreamsSubscribes();
+
+ String pmTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes
+ .get("performance_management_topic")).get("dmaap_info")).get("topic_url");
+ String[] pmTopicSplit = pmTopicUrl.split("\\/");
+ String pmTopic = pmTopicSplit[pmTopicSplit.length - 1];
+ log.debug("pm topic : {}", pmTopic);
+ String policyResponseTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes
+ .get("dcae_cl_response_topic")).get("dmaap_info")).get("topic_url");
+ String[] policyResponseTopicUrlSplit = policyResponseTopicUrl.split("\\/");
+ String policyResponseTopic = policyResponseTopicUrlSplit[policyResponseTopicUrlSplit.length - 1];
+ log.debug("policyResponse Topic : {}", policyResponseTopic);
+ CambriaConsumer pmNotifCambriaConsumer = null;
+ CambriaConsumer policyResponseCambriaConsumer = null;
+
+ pmNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, pmTopic);
+ policyResponseCambriaConsumer = dmaapUtils.buildConsumer(configuration, policyResponseTopic);
+
+ ScheduledExecutorService executorPool;
+
+ // create notification consumers for PM
+ NotificationConsumer pmNotificationConsumer = new NotificationConsumer(pmNotifCambriaConsumer,
+ new PmNotificationCallback());
+ // start pm notification consumer threads
+ executorPool = Executors.newScheduledThreadPool(10);
+ executorPool.scheduleAtFixedRate(pmNotificationConsumer, 0, configuration.getPollingInterval(),
+ TimeUnit.SECONDS);
+
+ // create notification consumers for Policy
+ NotificationConsumer policyNotificationConsumer = new NotificationConsumer(policyResponseCambriaConsumer,
+ new PolicyNotificationCallback());
+ // start policy notification consumer threads
+ executorPool = Executors.newScheduledThreadPool(10);
+ executorPool.scheduleAtFixedRate(policyNotificationConsumer, 0, configuration.getPollingInterval(),
+ TimeUnit.SECONDS);
+
+
+
+ }
+
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java
new file mode 100644
index 00000000..5c1f496b
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * This class indicates whether new pm notification
+ * is set for the slice-analysis-ms
+ */
+@Component
+public class NewPmNotification {
+
+ private Boolean newNotif;
+
+ /**
+ * Initialize new pm Notification flag
+ */
+ @PostConstruct
+ public void init() {
+ newNotif = false;
+ }
+
+ public Boolean getNewNotif() {
+ return newNotif;
+ }
+
+ public void setNewNotif(Boolean newNotif) {
+ this.newNotif = newNotif;
+ }
+
+ public NewPmNotification(Boolean newNotif) {
+ super();
+ this.newNotif = newNotif;
+ }
+
+ /**
+ * Default constructor
+ */
+ public NewPmNotification() {
+
+ }
+
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java
new file mode 100644
index 00000000..427b4048
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+public abstract class NotificationCallback {
+
+ public abstract void activateCallBack(String msg);
+
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumer.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumer.java
new file mode 100644
index 00000000..b605264c
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumer.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+import com.att.nsa.cambria.client.CambriaConsumer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Consume Notifications from DMAAP events
+ */
+public class NotificationConsumer implements Runnable {
+
+ private static Logger log = LoggerFactory.getLogger(NotificationConsumer.class);
+ private CambriaConsumer cambriaConsumer;
+ private NotificationCallback notificationCallback;
+
+ /**
+ * Parameterized Constructor.
+ */
+ public NotificationConsumer(CambriaConsumer cambriaConsumer, NotificationCallback notificationCallback) {
+ super();
+ this.cambriaConsumer = cambriaConsumer;
+ this.notificationCallback = notificationCallback;
+ }
+
+ /**
+ * starts fetching msgs from dmaap events
+ */
+ @Override
+ public void run() {
+ try {
+ Iterable<String> msgs = cambriaConsumer.fetch();
+ for (String msg : msgs) {
+ log.debug(msg);
+ notificationCallback.activateCallBack(msg);
+ }
+ } catch (Exception e) {
+ log.debug("exception when fetching msgs from dmaap", e);
+ }
+
+ }
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationProducer.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationProducer.java
new file mode 100644
index 00000000..03e1c238
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationProducer.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+
+import java.io.IOException;
+
+/**
+ * Produces Notification on DMAAP events
+ */
+public class NotificationProducer {
+
+ private CambriaBatchingPublisher cambriaBatchingPublisher;
+
+
+ /**
+ * Parameterized constructor.
+ */
+ public NotificationProducer(CambriaBatchingPublisher cambriaBatchingPublisher) {
+ super();
+ this.cambriaBatchingPublisher = cambriaBatchingPublisher;
+ }
+
+ /**
+ * sends notification to dmaap.
+ */
+ public int sendNotification(String msg) throws IOException {
+
+ return cambriaBatchingPublisher.send("", msg);
+
+ }
+
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java
new file mode 100644
index 00000000..17e50aca
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+import org.onap.slice.analysis.ms.data.beans.PerformanceNotifications;
+import org.onap.slice.analysis.ms.data.repository.PerformanceNotificationsRepository;
+import org.onap.slice.analysis.ms.utils.BeanUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handles Notification on dmaap for Performance events
+ */
+public class PmNotificationCallback extends NotificationCallback {
+
+ private static Logger log = LoggerFactory.getLogger(PmNotificationCallback.class);
+
+ @Override
+ public void activateCallBack(String msg) {
+ handleNotification(msg);
+ }
+
+ /**
+ * Parse Performance dmaap notification and save to DB
+ * @param msg
+ */
+ private void handleNotification(String msg) {
+
+ PerformanceNotificationsRepository performanceNotificationsRepository = BeanUtil
+ .getBean(PerformanceNotificationsRepository.class);
+ PerformanceNotifications performanceNotification = new PerformanceNotifications();
+ performanceNotification.setNotification(msg);
+ log.info("Performance notification {}", performanceNotification);
+ NewPmNotification newNotification = BeanUtil.getBean(NewPmNotification.class);
+ performanceNotificationsRepository.save(performanceNotification);
+ newNotification.setNewNotif(true);
+ }
+
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java
new file mode 100644
index 00000000..81ca9ef1
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import java.io.IOException;
+import java.util.Map;
+
+import org.onap.slice.analysis.ms.beans.Configuration;
+import org.onap.slice.analysis.ms.utils.DmaapUtils;
+
+/**
+ * Client class to handle Policy interactions
+ */
+public class PolicyDmaapClient {
+
+ private DmaapUtils dmaapUtils;
+
+ private Configuration configuration;
+
+ public PolicyDmaapClient(DmaapUtils dmaapUtils, Configuration configuration) {
+ this.dmaapUtils = dmaapUtils;
+ this.configuration = configuration;
+ }
+
+ /**
+ * Method stub for sending notification to policy.
+ */
+ @SuppressWarnings("unchecked")
+ public boolean sendNotificationToPolicy(String msg) {
+ Map<String, Object> streamsPublishes = configuration.getStreamsPublishes();
+ String policyTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamsPublishes.get("CL_topic"))
+ .get("dmaap_info")).get("topic_url");
+ String[] policyTopicSplit = policyTopicUrl.split("\\/");
+ String policyTopic = policyTopicSplit[policyTopicSplit.length - 1];
+ CambriaBatchingPublisher cambriaBatchingPublisher;
+ try {
+
+ cambriaBatchingPublisher = dmaapUtils.buildPublisher(configuration, policyTopic);
+
+ NotificationProducer notificationProducer = new NotificationProducer(cambriaBatchingPublisher);
+ notificationProducer.sendNotification(msg);
+ } catch (IOException e) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java
new file mode 100644
index 00000000..57aadd18
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.slice.analysis.ms.dmaap;
+
+import org.slf4j.Logger;
+
+/**
+ * Handles Notification on dmaap for Policy events
+ */
+public class PolicyNotificationCallback extends NotificationCallback {
+
+ private static final Logger log = org.slf4j.LoggerFactory.getLogger(PolicyNotificationCallback.class);
+
+ /**
+ * Trigger on Notification from policy component
+ */
+ @Override
+ public void activateCallBack(String msg) {
+ handlePolicyNotification(msg);
+ }
+
+ /**
+ * Parse and take actions on reception of Notification from Policy
+ * @param msg
+ */
+ private void handlePolicyNotification(String msg) {
+ log.info("Message received from policy: " +msg);
+ //TBD - actions to perform on reception of notification from policy
+ }
+}