693ae07c0b8963775b1525145caa0800e2b6d5d3
[oam/oam-controller.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.setReportingEntityId(vesProvider.getConfig().getReportingEntityId());
72         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
73         vesCEH.setSequence(sequenceNo++);
74         vesCEH.setSourceId(
75                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) != null
76                         ? ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID)
77                         : netconfAccessor.getNodeId().getValue());
78         vesCEH.setSourceName(netconfAccessor.getNodeId().getValue());
79
80         return vesCEH;
81     }
82
83     public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(MapEntryNode component) {
84         VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO();
85
86         vesPnfFields.setModelNumber(
87                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
88         vesPnfFields
89                 .setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address() != null
90                         ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address().getValue()
91                         : null);
92         vesPnfFields
93                 .setOamV6IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address() != null
94                         ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address().getValue()
95                         : null);
96         vesPnfFields.setSerialNumber(
97                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SER_NUM));
98         vesPnfFields.setVendorName(
99                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
100         vesPnfFields.setSoftwareVersion(
101                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SW_REV));
102         vesPnfFields.setUnitType(
103                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_ALIAS));
104         vesPnfFields.setUnitFamily(
105                 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_CLASS));
106         vesPnfFields
107                 .setManufactureDate(
108                         ORanDMDOMUtility.getLeafValue(component,
109                                 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE) != null
110                                         ? ORanDMDOMUtility.getLeafValue(component,
111                                                 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE)
112                                         : "Unknown");
113         //vesPnfFields.setLastServiceDate(component.getLastChange());
114
115         return vesPnfFields;
116     }
117 }