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 java.time.Instant;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.json.JSONObject;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class MountpointStateVESMessageFormatter {
37 private static final Logger LOG = LoggerFactory.getLogger(MountpointStateVESMessageFormatter.class);
39 private final @NonNull VESCollectorCfgService vesCfg;
40 private final @NonNull VESCollectorService vesCollectorService;
41 static long sequenceNo = 0;
43 public MountpointStateVESMessageFormatter(VESCollectorCfgService vesCfg, VESCollectorService vesCollectorService) {
45 this.vesCollectorService = vesCollectorService;
48 private static void incrSequenceNo() {
52 private long getSequenceNo() {
56 public VESMessage createVESMessage(JSONObject obj) {
57 if (LOG.isDebugEnabled()) {
58 LOG.debug("JSON Object to format to VES is - {0}", obj);
61 MountpointStateVESMessageFormatter.incrSequenceNo();
63 VESCommonEventHeaderPOJO vesCommonEventHeader = createVESCommonEventHeader(obj);
64 VESNotificationFieldsPOJO vesNotificationFields = createVESNotificationFields(obj);
66 VESMessage vesMsg = null;
68 vesMsg = vesCollectorService.generateVESEvent(vesCommonEventHeader, vesNotificationFields);
69 LOG.debug("VES Message is - {}", vesMsg.getMessage());
70 } catch (JsonProcessingException e) {
71 LOG.error("Exception while generating VES Event - ", e);
78 private VESNotificationFieldsPOJO createVESNotificationFields(JSONObject obj) {
79 VESNotificationFieldsPOJO vesNotificationFields = new VESNotificationFieldsPOJO();
81 vesNotificationFields.setChangeIdentifier(obj.getString(Constants.NODEID));
82 vesNotificationFields.setChangeType(Constants.VES_CHANGETYPE);
83 vesNotificationFields.setNewState(obj.getString(Constants.NETCONFNODESTATE));
85 return vesNotificationFields;
88 private VESCommonEventHeaderPOJO createVESCommonEventHeader(JSONObject obj) {
89 VESCommonEventHeaderPOJO vesCommonEventHeader = new VESCommonEventHeaderPOJO();
91 vesCommonEventHeader.setDomain(Constants.VES_DOMAIN);
93 .setEventId(obj.getString(Constants.NODEID) + "_" + obj.getString(Constants.NETCONFNODESTATE) + "_" + getSequenceNo());
95 .setEventName(obj.getString(Constants.NODEID) + "_" + obj.getString(Constants.NETCONFNODESTATE) + "_" + getSequenceNo());
96 vesCommonEventHeader.setSourceName(obj.getString(Constants.NODEID));
97 vesCommonEventHeader.setPriority(Constants.VES_PRIORITY);
98 vesCommonEventHeader.setReportingEntityName(this.vesCfg.getReportingEntityName());
99 vesCommonEventHeader.setSequence(getSequenceNo());
101 Instant time = (Instant) obj.get(Constants.TIMESTAMP);
102 vesCommonEventHeader.setLastEpochMicrosec(time.toEpochMilli() * 100);
103 vesCommonEventHeader.setStartEpochMicrosec(time.toEpochMilli() * 100);
105 return vesCommonEventHeader;