9cbb45d55562413d52027757adaf63d0942fb84d
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.vesmapper;
23
24 import java.time.Instant;
25
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDMDOMUtility;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
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.VESPNFRegistrationFieldsPOJO;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
32 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class ORanRegistrationToVESpnfRegistrationMapper {
37
38     @SuppressWarnings("unused")
39     private static final Logger LOG = LoggerFactory.getLogger(ORanRegistrationToVESpnfRegistrationMapper.class);
40     //CommonEventHeader fields
41     private static final String VES_EVENT_DOMAIN = "pnfRegistration";
42     private static final String VES_EVENTTYPE = "NetConf Callhome Registration";
43     private static final String VES_EVENT_PRIORITY = "Normal";
44
45     private final VESCollectorService vesProvider;
46     private final NetconfAccessor netconfAccessor;
47
48     private Integer sequenceNo;
49
50
51     public ORanRegistrationToVESpnfRegistrationMapper(NetconfAccessor netconfAccessor,
52             VESCollectorService vesCollectorService) {
53         this.netconfAccessor = netconfAccessor;
54         this.vesProvider = vesCollectorService;
55
56         this.sequenceNo = 0;
57     }
58
59     public VESCommonEventHeaderPOJO mapCommonEventHeader(MapEntryNode component) {
60         VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
61         vesCEH.setDomain(VES_EVENT_DOMAIN);
62         vesCEH.setEventId(netconfAccessor.getNodeId().getValue());
63         vesCEH.setEventName(netconfAccessor.getNodeId().getValue());
64         vesCEH.setEventType(VES_EVENTTYPE);
65         vesCEH.setPriority(VES_EVENT_PRIORITY);
66
67         vesCEH.setStartEpochMicrosec(Instant.now().toEpochMilli() * 1000);
68         vesCEH.setLastEpochMicrosec(Instant.now().toEpochMilli() * 1000);
69         vesCEH.setNfVendorName(
70                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
71         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
72         vesCEH.setSequence(sequenceNo++);
73         vesCEH.setSourceId(
74                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) != null
75                         ? ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID)
76                         : netconfAccessor.getNodeId().getValue());
77         vesCEH.setSourceName(netconfAccessor.getNodeId().getValue());
78
79         return vesCEH;
80     }
81
82     public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(MapEntryNode component) {
83         VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO();
84         vesPnfFields.setModelNumber(
85                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
86         vesPnfFields
87                 .setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address() != null
88                         ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address().getValue()
89                         : null);
90         vesPnfFields
91                 .setOamV6IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address() != null
92                         ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address().getValue()
93                         : null);
94         vesPnfFields.setSerialNumber(
95                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SER_NUM));
96         vesPnfFields.setVendorName(
97                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
98         vesPnfFields.setSoftwareVersion(
99                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SW_REV));
100         vesPnfFields.setUnitType(
101                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_ALIAS));
102         vesPnfFields.setUnitFamily(
103                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_CLASS));
104         vesPnfFields
105                 .setManufactureDate(
106                         ORanDMDOMUtility.getLeafValue(component,
107                                 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE) != null
108                                         ? ORanDMDOMUtility.getLeafValue(component,
109                                                 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE)
110                                         : "Unknown");
111         //vesPnfFields.setLastServiceDate(component.getLastChange());
112
113         return vesPnfFields;
114     }
115 }