bda77f223d6c6ab3e983561cc29af9a0db2dd6c4
[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 com.google.common.util.concurrent.CheckedFuture;
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayService;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.ProviderClient;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
31 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
32 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
33 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
34 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 /**
43  * Create a Network Element representation according to the capability
44  * information. The capabilities are more than an ODL-QName. After the ? other
45  * terms than "revision" are provided.
46  *
47  */
48 @SuppressWarnings("deprecation")
49 public class ONFCoreNetworkElementFactory {
50
51     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementFactory.class);
52
53     @SuppressWarnings("deprecation")
54     public static @Nonnull ONFCoreNetworkElementRepresentation create(String mountPointNodeName, DataBroker dataBroker,
55             WebSocketServiceClient webSocketService, HtDatabaseEventsService databaseService,
56             InstanceIdentifier<Node> instanceIdentifier, DataBroker mountpointDataBroker, ProviderClient dcaeProvider,
57             @Nullable ProviderClient aotsmClient, MaintenanceService maintenanceService,
58             NotificationDelayService<ProblemNotificationXml> notificationDelayService) {
59
60         ONFCoreNetworkElementRepresentation res = null;
61         try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();){
62             CheckedFuture<Optional<Node>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
63             Optional<Node> nodeOption = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet();
64             if (nodeOption.isPresent()) {
65                 Node node = nodeOption.get();
66                 NetconfNode nnode = node.augmentation(NetconfNode.class);
67                 if (nnode != null) {
68                     ConnectionStatus csts = nnode.getConnectionStatus();
69                     if (csts == ConnectionStatus.Connected) {
70                         Capabilities capabilities = Capabilities.getAvailableCapabilities(nnode);
71                         LOG.info("Mountpoint {} capabilities {}", mountPointNodeName, capabilities);
72                         res = ONFCoreNetworkElement12.build(mountPointNodeName, capabilities, mountpointDataBroker,
73                                 webSocketService, databaseService, dcaeProvider, aotsmClient, maintenanceService,
74                                 notificationDelayService);
75                         LOG.info("ONFCoreNetworkElementRepresentation12 value is not null? " + (res != null));
76                     }
77                 }
78             }
79             tx.close();
80         } catch (ReadFailedException | IllegalArgumentException e) {
81             LOG.warn("Can not generate specific NE Version representation. ", e);
82         }
83         if (res == null) {
84             res = new ONFCoreEmpty(mountPointNodeName);
85         }
86         LOG.info("Mointpoint {} started as {}", mountPointNodeName, res.getClass().getSimpleName());
87         return res;
88     }
89
90 }