3fc8b133f9949345dd6bb49a4559f63a7e4a8029
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf;
19
20 import com.google.common.base.Optional;
21 import javax.annotation.Nonnull;
22 import javax.annotation.Nullable;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayService;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.ProviderClient;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
32 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
33 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * Create a Network Element representation according to the capability
43  * information. The capabilities are more than an ODL-QName. After the ? other
44  * terms than "revision" are provided.
45  *
46  */
47 public class ONFCoreNetworkElementFactory {
48
49     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementFactory.class);
50
51     @SuppressWarnings("deprecation")
52     public static @Nonnull ONFCoreNetworkElementRepresentation create(String mountPointNodeName, DataBroker dataBroker,
53             WebSocketServiceClient webSocketService, HtDatabaseEventsService databaseService,
54             InstanceIdentifier<Node> instanceIdentifier, DataBroker mountpointDataBroker, ProviderClient dcaeProvider,
55             @Nullable ProviderClient aotsmClient, MaintenanceService maintenanceService,
56             NotificationDelayService<ProblemNotificationXml> notificationDelayService) {
57
58         ONFCoreNetworkElementRepresentation res = null;
59         try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();){
60             Optional<Node> nodeOption = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet();
61             if (nodeOption.isPresent()) {
62                 Node node = nodeOption.get();
63                 NetconfNode nnode = node.augmentation(NetconfNode.class);
64                 if (nnode != null) {
65                     ConnectionStatus csts = nnode.getConnectionStatus();
66                     if (csts == ConnectionStatus.Connected) {
67                         Capabilities capabilities = new Capabilities(nnode);
68                         LOG.info("Mountpoint {} capabilities {}", mountPointNodeName, capabilities);
69                         res = ONFCoreNetworkElement12.build(mountPointNodeName, capabilities, mountpointDataBroker,
70                                 webSocketService, databaseService, dcaeProvider, aotsmClient, maintenanceService,
71                                 notificationDelayService);
72                         LOG.info("ONFCoreNetworkElementRepresentation12 value is not null? " + (res != null));
73                     }
74                 }
75             }
76             tx.close();
77         } catch (ReadFailedException | IllegalArgumentException e) {
78             LOG.warn("Can not generate specific NE Version representation. ", e);
79         }
80         if (res == null) {
81             res = new ONFCoreEmpty(mountPointNodeName);
82         }
83         LOG.info("Mointpoint {} started as {}", mountPointNodeName, res.getClass().getSimpleName());
84         return res;
85     }
86
87 }