1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Huawei Canada Limited.
6 * ==============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 *******************************************************************************/
22 package org.onap.slice.analysis.ms.dmaap;
24 import com.fasterxml.jackson.core.type.TypeReference;
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.onap.slice.analysis.ms.models.Configuration;
28 import org.onap.slice.analysis.ms.models.vesnotification.NotificationFields;
30 import org.onap.slice.analysis.ms.service.ccvpn.CCVPNPmDatastore;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
36 import javax.annotation.PostConstruct;
37 import java.io.IOException;
40 * Handles Notification on dmaap for ves notification events
43 public class VesNotificationCallback implements NotificationCallback {
45 private Configuration configuration;
46 private String NOTIFICATIONFIELDS = "notificationFields";
47 private String EVENT = "event";
48 private String vesNotifChangeIdentifier;
49 private String vesNotfiChangeType;
52 CCVPNPmDatastore ccvpnPmDatastore;
54 private static Logger log = LoggerFactory.getLogger(VesNotificationCallback.class);
57 * init ves callback; load configuration.
61 configuration = Configuration.getInstance();
62 vesNotifChangeIdentifier = configuration.getVesNotifChangeIdentifier();
63 vesNotfiChangeType = configuration.getVesNotifChangeType();
67 * Triggers on handleNofitication method
68 * @param msg incoming message
71 public void activateCallBack(String msg) {
72 handleNotification(msg);
76 * Parse Performance dmaap notification and save to DB
77 * @param msg incoming message
79 private void handleNotification(String msg) {
80 log.info("Message received from VES : {}" ,msg);
81 ObjectMapper obj = new ObjectMapper();
82 NotificationFields output = null;
83 String notifChangeIdentifier = "";
84 String notifChangeType = "";
89 JsonNode node = obj.readTree(msg);
90 JsonNode notificationNode = node.get(EVENT).get(NOTIFICATIONFIELDS);
91 output = obj.treeToValue(notificationNode, NotificationFields.class);
93 //Filter out target notification changeIdentifier and changeType
94 notifChangeIdentifier = output.getChangeIdentifier();
95 notifChangeType = output.getChangeType();
96 if (notifChangeType.equals(vesNotfiChangeType)
97 && notifChangeIdentifier.equals(vesNotifChangeIdentifier)) {
98 cllId = output.getArrayOfNamedHashMap().get(0).getHashMap().getCllId();
99 uniId = output.getArrayOfNamedHashMap().get(0).getHashMap().getUniId();
100 bw = output.getArrayOfNamedHashMap().get(0).getHashMap().getBandwidthValue();
103 catch (IOException e) {
104 log.error("Error converting VES msg to object, {}", e.getMessage());
106 if (cllId != null && uniId != null && bw != null){
107 log.info("Saving new CCVPN service usage data into ccvpnPmDatastore");
108 log.debug("new bandwidth data -- serviceId: {}, uniId: {}, bw: {}", cllId, uniId, bw);
109 ccvpnPmDatastore.addUsedBwToEndpoint(cllId, uniId, bw);