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);
35 private VESCollectorCfgService vesCfg;
36 static long sequenceNo = 0;
38 public MountpointStateVESMessageFormatter(VESCollectorCfgService vesCfg) {
42 private static void incrSequenceNo() {
46 private long getSequenceNo() {
50 public String createVESMessage(JSONObject obj) {
51 if (LOG.isDebugEnabled()) {
52 LOG.debug("JSON Object to format to VES is - {0}", obj);
55 MountpointStateVESMessageFormatter.incrSequenceNo();
57 VESCommonEventHeaderPOJO vesCommonEventHeader = createVESCommonEventHeader(obj);
58 VESNotificationFieldsPOJO vesNotificationFields = createVESNotificationFields(obj);
60 VESEvent vesEvent = new VESEvent();
61 vesEvent.addEventObjects(vesCommonEventHeader);
62 vesEvent.addEventObjects(vesNotificationFields);
65 ObjectMapper objMapper = new ObjectMapper();
66 vesMsg = objMapper.writeValueAsString(vesEvent);
67 LOG.debug("VES message to be published - {}", vesMsg);
68 } catch (JsonProcessingException e) {
69 LOG.warn("Exception {} while processing JSON Message - {}", e, obj);
76 private VESNotificationFieldsPOJO createVESNotificationFields(JSONObject obj) {
77 VESNotificationFieldsPOJO vesNotificationFields = new VESNotificationFieldsPOJO();
79 vesNotificationFields.setChangeIdentifier(obj.getString(Constants.NODEID));
80 vesNotificationFields.setChangeType(Constants.VES_CHANGETYPE);
81 vesNotificationFields.setNewState(obj.getString(Constants.NETCONFNODESTATE));
83 return vesNotificationFields;
86 private VESCommonEventHeaderPOJO createVESCommonEventHeader(JSONObject obj) {
87 VESCommonEventHeaderPOJO vesCommonEventHeader = new VESCommonEventHeaderPOJO();
89 vesCommonEventHeader.setDomain(Constants.VES_DOMAIN);
91 .setEventId(obj.getString(Constants.NODEID) + "_" + obj.getString(Constants.NETCONFNODESTATE) + "_" + getSequenceNo());
93 .setEventName(obj.getString(Constants.NODEID) + "_" + obj.getString(Constants.NETCONFNODESTATE) + "_" + getSequenceNo());
94 vesCommonEventHeader.setSourceName(obj.getString(Constants.NODEID));
95 vesCommonEventHeader.setPriority(Constants.VES_PRIORITY);
96 vesCommonEventHeader.setReportingEntityName(this.vesCfg.getReportingEntityName());
97 vesCommonEventHeader.setSequence(getSequenceNo());
99 Instant time = (Instant) obj.get(Constants.TIMESTAMP);
100 vesCommonEventHeader.setLastEpochMicrosec(time.toEpochMilli() * 100);
101 vesCommonEventHeader.setStartEpochMicrosec(time.toEpochMilli() * 100);
103 return vesCommonEventHeader;