81605e450ddbeb6eb9935508abf370854c21631d
[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.impl;
23
24 import java.time.Instant;
25 import org.eclipse.jdt.annotation.NonNull;
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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class ORanRegistrationToVESpnfRegistrationMapper {
35
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 @NonNull Component component;
44     private final NetconfAccessor netconfAccessor;
45
46     public ORanRegistrationToVESpnfRegistrationMapper(NetconfAccessor netconfAccessor,
47             VESCollectorService vesCollectorService, Component component) {
48         this.netconfAccessor = netconfAccessor;
49         this.vesProvider = vesCollectorService;
50         this.component = component;
51     }
52
53     public VESCommonEventHeaderPOJO mapCommonEventHeader(int sequenceNo) {
54         VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
55         vesCEH.setDomain(VES_EVENT_DOMAIN);
56         vesCEH.setEventId(netconfAccessor.getNodeId().getValue());
57         vesCEH.setEventName(netconfAccessor.getNodeId().getValue());
58         vesCEH.setEventType(VES_EVENTTYPE);
59         vesCEH.setPriority(VES_EVENT_PRIORITY);
60
61         vesCEH.setStartEpochMicrosec(Instant.now().toEpochMilli() * 1000);
62         vesCEH.setLastEpochMicrosec(Instant.now().toEpochMilli() * 1000);
63         vesCEH.setNfVendorName(component.getMfgName());
64         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
65         vesCEH.setSequence(sequenceNo);
66         vesCEH.setSourceId(component.getUuid().toString());
67         vesCEH.setSourceName(netconfAccessor.getNodeId().getValue());
68
69         return vesCEH;
70     }
71
72     public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields() {
73         VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO();
74         vesPnfFields.setModelNumber(component.getModelName());
75         vesPnfFields.setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().toString());
76         //vesPnfFields.setOamV6IpAddress(oamV6IpAddress); // Check if IP address in V6 format and then include it. Same with v4 address also
77         vesPnfFields.setSerialNumber(component.getSerialNum());
78         vesPnfFields.setVendorName(component.getMfgName());
79         vesPnfFields.setSoftwareVersion(component.getSoftwareRev());
80         vesPnfFields.setUnitType(component.getAlias());
81         vesPnfFields.setUnitFamily(component.getXmlClass().toString());
82         vesPnfFields.setManufactureDate(component.getMfgDate().toString());
83         //vesPnfFields.setLastServiceDate(component.getLastChange());
84
85         return vesPnfFields;
86     }
87 }