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.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 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(VESCollectorService vesCollectorService) {
44 this.vesCfg = vesCollectorService.getConfig();
45 this.vesCollectorService = vesCollectorService;
48 private static void incrSequenceNo() {
52 private long getSequenceNo() {
56 public VESMessage createVESMessage(String nodeId, String connectionStatus,
58 if (LOG.isDebugEnabled()) {
59 LOG.debug("format to VES from {}, {}, {}", nodeId, connectionStatus, timestamp);
62 MountpointStateVESMessageFormatter.incrSequenceNo();
64 VESCommonEventHeaderPOJO vesCommonEventHeader = createVESCommonEventHeader(nodeId, connectionStatus, timestamp);
65 VESNotificationFieldsPOJO vesNotificationFields = createVESNotificationFields(nodeId, connectionStatus);
67 VESMessage vesMsg = null;
69 vesMsg = vesCollectorService.generateVESEvent(vesCommonEventHeader, vesNotificationFields);
70 LOG.debug("VES Message is - {}", vesMsg.getMessage());
71 } catch (JsonProcessingException e) {
72 LOG.error("Exception while generating VES Event - ", e);
79 private VESNotificationFieldsPOJO createVESNotificationFields(String nodeId, String connectionStatus) {
80 VESNotificationFieldsPOJO vesNotificationFields = new VESNotificationFieldsPOJO();
82 vesNotificationFields.setChangeIdentifier(nodeId);
83 vesNotificationFields.setChangeType(Constants.VES_CHANGETYPE);
84 vesNotificationFields.setNewState(connectionStatus);
86 return vesNotificationFields;
89 private VESCommonEventHeaderPOJO createVESCommonEventHeader(String nodeId, String connectionStatus,
91 VESCommonEventHeaderPOJO vesCommonEventHeader = new VESCommonEventHeaderPOJO();
93 vesCommonEventHeader.setDomain(Constants.VES_DOMAIN);
94 vesCommonEventHeader.setEventId(nodeId + "_" + connectionStatus + "_" + getSequenceNo());
95 vesCommonEventHeader.setEventName(nodeId + "_" + connectionStatus + "_" + getSequenceNo());
96 vesCommonEventHeader.setSourceName(nodeId);
97 vesCommonEventHeader.setPriority(Constants.VES_PRIORITY);
98 vesCommonEventHeader.setReportingEntityId(this.vesCfg.getReportingEntityId());
99 vesCommonEventHeader.setReportingEntityName(this.vesCfg.getReportingEntityName());
100 vesCommonEventHeader.setSequence(getSequenceNo());
101 vesCommonEventHeader.setLastEpochMicrosec(timestamp.toEpochMilli() * 1000);
102 vesCommonEventHeader.setStartEpochMicrosec(timestamp.toEpochMilli() * 1000);
104 return vesCommonEventHeader;