1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Huawei Canada Limited.
6 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
7 * ==============================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 *******************************************************************************/
23 package org.onap.slice.analysis.ms.dmaap;
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.ObjectMapper;
28 import org.onap.slice.analysis.ms.aai.AaiService;
29 import org.onap.slice.analysis.ms.models.Configuration;
30 import org.onap.slice.analysis.ms.models.vesnotification.NotificationFields;
32 import org.onap.slice.analysis.ms.service.ccvpn.CCVPNPmDatastore;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
38 import javax.annotation.PostConstruct;
39 import java.io.IOException;
42 * Handles Notification on dmaap for ves notification events
45 public class VesNotificationCallback implements NotificationCallback {
47 private Configuration configuration;
48 private String NOTIFICATIONFIELDS = "notificationFields";
49 private String EVENT = "event";
50 private String vesNotifChangeIdentifier;
51 private String vesNotfiChangeType;
54 CCVPNPmDatastore ccvpnPmDatastore;
57 AaiService aaiService;
59 private static Logger log = LoggerFactory.getLogger(VesNotificationCallback.class);
62 * init ves callback; load configuration.
66 configuration = Configuration.getInstance();
67 vesNotifChangeIdentifier = configuration.getVesNotifChangeIdentifier();
68 vesNotfiChangeType = configuration.getVesNotifChangeType();
72 * Triggers on handleNofitication method
73 * @param msg incoming message
76 public void activateCallBack(String msg) {
77 handleNotification(msg);
81 * Parse Performance dmaap notification and save to DB
82 * @param msg incoming message
84 private void handleNotification(String msg) {
85 log.info("Message received from VES : {}" ,msg);
86 ObjectMapper obj = new ObjectMapper();
87 NotificationFields output = null;
88 String notifChangeIdentifier = "";
89 String notifChangeType = "";
95 JsonNode node = obj.readTree(msg);
96 JsonNode notificationNode = node.get(EVENT).get(NOTIFICATIONFIELDS);
97 output = obj.treeToValue(notificationNode, NotificationFields.class);
99 //Filter out target notification changeIdentifier and changeType
100 notifChangeIdentifier = output.getChangeIdentifier();
101 notifChangeType = output.getChangeType();
102 if (notifChangeType.equals(vesNotfiChangeType)
103 && notifChangeIdentifier.equals(vesNotifChangeIdentifier)) {
104 cllId = output.getArrayOfNamedHashMap().get(0).getHashMap().getCllId();
105 uniId = output.getArrayOfNamedHashMap().get(0).getHashMap().getUniId();
106 bw = output.getArrayOfNamedHashMap().get(0).getHashMap().getBandwidthValue();
109 catch (IOException e) {
110 log.error("Error converting VES msg to object, {}", e.getMessage());
112 if (cllId != null && uniId != null && bw != null){
113 log.debug("new bandwidth data -- serviceId: {}, uniId: {}, bw: {}", cllId, uniId, bw);
114 ccvpnPmDatastore.addUsedBwToEndpoint(cllId, uniId, bw);
119 * Get latest services list, and update local related variables.
121 public void updateCllInstance(){
122 Set<String> instances = aaiService.fetchAllCllInstances();
123 log.error("instances {}", instances);
124 ccvpnPmDatastore.updateCllInstances(instances);