Use DOM API for ORAN Devicemanager
[ccsdk/features.git] / sdnr / wt / devicemanager-o-ran-sc / o-ran / ru-fh / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / oran / impl / dom / ORanRegistrationToVESpnfRegistrationMapper.java
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.impl.dom;
23
24 import java.time.Instant;
25
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
30 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class ORanRegistrationToVESpnfRegistrationMapper {
35
36     @SuppressWarnings("unused")
37     private static final Logger LOG = LoggerFactory.getLogger(ORanRegistrationToVESpnfRegistrationMapper.class);
38     //CommonEventHeader fields
39     private static final String VES_EVENT_DOMAIN = "pnfRegistration";
40     private static final String VES_EVENTTYPE = "NetConf Callhome Registration";
41     private static final String VES_EVENT_PRIORITY = "Normal";
42
43     private final VESCollectorService vesProvider;
44     private final NetconfAccessor netconfAccessor;
45
46     private Integer sequenceNo;
47
48
49     public ORanRegistrationToVESpnfRegistrationMapper(NetconfAccessor netconfAccessor,
50             VESCollectorService vesCollectorService) {
51         this.netconfAccessor = netconfAccessor;
52         this.vesProvider = vesCollectorService;
53
54         this.sequenceNo = 0;
55     }
56
57     public VESCommonEventHeaderPOJO mapCommonEventHeader(MapEntryNode component) {
58         VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
59         vesCEH.setDomain(VES_EVENT_DOMAIN);
60         vesCEH.setEventId(netconfAccessor.getNodeId().getValue());
61         vesCEH.setEventName(netconfAccessor.getNodeId().getValue());
62         vesCEH.setEventType(VES_EVENTTYPE);
63         vesCEH.setPriority(VES_EVENT_PRIORITY);
64
65         vesCEH.setStartEpochMicrosec(Instant.now().toEpochMilli() * 1000);
66         vesCEH.setLastEpochMicrosec(Instant.now().toEpochMilli() * 1000);
67         vesCEH.setNfVendorName(
68                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
69         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
70         vesCEH.setSequence(sequenceNo++);
71         vesCEH.setSourceId(
72                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) != null
73                         ? ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID)
74                         : netconfAccessor.getNodeId().getValue());
75         vesCEH.setSourceName(netconfAccessor.getNodeId().getValue());
76
77         return vesCEH;
78     }
79
80     public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(MapEntryNode component) {
81         VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO();
82         vesPnfFields.setModelNumber(
83                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
84         vesPnfFields
85                 .setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address() != null
86                         ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address().getValue()
87                         : null);
88         vesPnfFields
89                 .setOamV6IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address() != null
90                         ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address().getValue()
91                         : null);
92         vesPnfFields.setSerialNumber(
93                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SER_NUM));
94         vesPnfFields.setVendorName(
95                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
96         vesPnfFields.setSoftwareVersion(
97                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SW_REV));
98         vesPnfFields.setUnitType(
99                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_ALIAS));
100         vesPnfFields.setUnitFamily(
101                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_CLASS));
102         vesPnfFields
103                 .setManufactureDate(
104                         ORanDMDOMUtility.getLeafValue(component,
105                                 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE) != null
106                                         ? ORanDMDOMUtility.getLeafValue(component,
107                                                 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE)
108                                         : "Unknown");
109         //vesPnfFields.setLastServiceDate(component.getLastChange());
110
111         return vesPnfFields;
112     }
113 }