Merge "Optimize cm-handle registration with CPS-DMI Plugin to upload yang model"
[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 / 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;
23
24 import java.time.Instant;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
28 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class ORanRegistrationToVESpnfRegistrationMapper {
34
35     @SuppressWarnings("unused")
36     private static final Logger LOG = LoggerFactory.getLogger(ORanFaultToVESFaultMapper.class);
37     //CommonEventHeader fields
38     private static final String VES_EVENT_DOMAIN = "pnfRegistration";
39     private static final String VES_EVENTTYPE = "NetConf Callhome Registration";
40     private static final String VES_EVENT_PRIORITY = "Normal";
41
42     private final VESCollectorService vesProvider;
43     private final NetconfAccessor netconfAccessor;
44
45     private Integer sequenceNo;
46
47
48     public ORanRegistrationToVESpnfRegistrationMapper(NetconfAccessor netconfAccessor,
49             VESCollectorService vesCollectorService) {
50         this.netconfAccessor = netconfAccessor;
51         this.vesProvider = vesCollectorService;
52
53         this.sequenceNo = 0;
54     }
55
56     public VESCommonEventHeaderPOJO mapCommonEventHeader(Component component) {
57         VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
58         vesCEH.setDomain(VES_EVENT_DOMAIN);
59         vesCEH.setEventId(netconfAccessor.getNodeId().getValue());
60         vesCEH.setEventName(netconfAccessor.getNodeId().getValue());
61         vesCEH.setEventType(VES_EVENTTYPE);
62         vesCEH.setPriority(VES_EVENT_PRIORITY);
63
64         vesCEH.setStartEpochMicrosec(Instant.now().toEpochMilli() * 1000);
65         vesCEH.setLastEpochMicrosec(Instant.now().toEpochMilli() * 1000);
66         vesCEH.setNfVendorName(component.getMfgName());
67         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
68         vesCEH.setSequence(sequenceNo++);
69         vesCEH.setSourceId(component.getUuid() != null ? component.getUuid().toString():netconfAccessor.getNodeId().getValue());
70         vesCEH.setSourceName(netconfAccessor.getNodeId().getValue());
71
72         return vesCEH;
73     }
74
75     public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(Component component) {
76         VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO();
77         vesPnfFields.setModelNumber(component.getModelName());
78         vesPnfFields.setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address()!=null?netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address().getValue():null);
79         vesPnfFields.setOamV6IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address()!=null?netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address().getValue():null);
80         vesPnfFields.setSerialNumber(component.getSerialNum());
81         vesPnfFields.setVendorName(component.getMfgName());
82         vesPnfFields.setSoftwareVersion(component.getSoftwareRev());
83         vesPnfFields.setUnitType(component.getAlias());
84         vesPnfFields.setUnitFamily(component.getXmlClass().toString());
85         vesPnfFields.setManufactureDate(component.getMfgDate()!=null?component.getMfgDate().toString():"Unknown");
86         //vesPnfFields.setLastServiceDate(component.getLastChange());
87
88         return vesPnfFields;
89     }
90 }