2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import java.time.Instant;
27 import org.json.JSONObject;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class MountpointStateVESMessageFormatter {
33 private static final Logger LOG = LoggerFactory.getLogger(MountpointStateVESMessageFormatter.class);
34 private static final String VES_DOMAIN = "notification";
35 private static final String VES_PRIORITY = "Normal";
36 private static final String VES_CHANGETYPE = "ConnectionState";
38 private VESCollectorCfgService vesCfg;
39 static long sequenceNo = 0;
41 public MountpointStateVESMessageFormatter(VESCollectorCfgService vesCfg) {
45 public String createVESMessage(JSONObject obj) {
46 LOG.debug("JSON Object to format to VES is - {}", obj.toString());
50 VESCommonEventHeaderPOJO vesCommonEventHeader = createVESCommonEventHeader(obj);
51 VESNotificationFieldsPOJO vesNotificationFields = createVESNotificationFields(obj);
53 VESEvent vesEvent = new VESEvent();
54 vesEvent.addEventObjects(vesCommonEventHeader);
55 vesEvent.addEventObjects(vesNotificationFields);
58 ObjectMapper objMapper = new ObjectMapper();
59 vesMsg = objMapper.writeValueAsString(vesEvent);
60 LOG.debug("VES message to be published - {}", vesMsg);
61 } catch (JsonProcessingException e) {
69 private VESNotificationFieldsPOJO createVESNotificationFields(JSONObject obj) {
70 VESNotificationFieldsPOJO vesNotificationFields = new VESNotificationFieldsPOJO();
72 vesNotificationFields.setChangeIdentifier(obj.getString("NodeId"));
73 vesNotificationFields.setChangeType(VES_CHANGETYPE);
74 vesNotificationFields.setNewState(obj.getString("NetConfNodeState"));
76 return vesNotificationFields;
79 private VESCommonEventHeaderPOJO createVESCommonEventHeader(JSONObject obj) {
80 VESCommonEventHeaderPOJO vesCommonEventHeader = new VESCommonEventHeaderPOJO();
82 vesCommonEventHeader.setDomain(VES_DOMAIN);
84 .setEventId(obj.getString("NodeId") + "_" + obj.getString("NetConfNodeState") + "_" + sequenceNo);
86 .setEventName(obj.getString("NodeId") + "_" + obj.getString("NetConfNodeState") + "_" + sequenceNo);
87 vesCommonEventHeader.setSourceName(obj.getString("NodeId"));
88 vesCommonEventHeader.setPriority(VES_PRIORITY);
89 vesCommonEventHeader.setReportingEntityName(this.vesCfg.getReportingEntityName());
90 vesCommonEventHeader.setSequence(sequenceNo);
92 Instant time = (Instant) obj.get("TimeStamp");
93 vesCommonEventHeader.setLastEpochMicrosec(time.toEpochMilli() * 100);
94 vesCommonEventHeader.setStartEpochMicrosec(time.toEpochMilli() * 100);
96 return vesCommonEventHeader;