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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf;
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;
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.
48 public class ONFCoreNetworkElementFactory {
50 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementFactory.class);
52 @SuppressWarnings("deprecation")
53 public static @Nonnull ONFCoreNetworkElementRepresentation create(String mountPointNodeName, DataBroker dataBroker,
54 WebSocketServiceClient webSocketService, HtDatabaseEventsService databaseService,
55 InstanceIdentifier<Node> instanceIdentifier, DataBroker mountpointDataBroker, ProviderClient dcaeProvider,
56 @Nullable ProviderClient aotsmClient, MaintenanceService maintenanceService,
57 NotificationDelayService<ProblemNotificationXml> notificationDelayService) {
59 ONFCoreNetworkElementRepresentation res = null;
60 try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();){
61 CheckedFuture<Optional<Node>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
62 Optional<Node> nodeOption = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet();
63 if (nodeOption.isPresent()) {
64 Node node = nodeOption.get();
65 NetconfNode nnode = node.augmentation(NetconfNode.class);
67 ConnectionStatus csts = nnode.getConnectionStatus();
68 if (csts == ConnectionStatus.Connected) {
69 Capabilities capabilities = Capabilities.getAvailableCapabilities(nnode);
70 LOG.info("Mountpoint {} capabilities {}", mountPointNodeName, capabilities);
71 res = ONFCoreNetworkElement12.build(mountPointNodeName, capabilities, mountpointDataBroker,
72 webSocketService, databaseService, dcaeProvider, aotsmClient, maintenanceService,
73 notificationDelayService);
74 LOG.info("ONFCoreNetworkElementRepresentation12 value is not null? " + (res != null));
79 } catch (ReadFailedException | IllegalArgumentException e) {
80 LOG.warn("Can not generate specific NE Version representation. ", e);
83 res = new ONFCoreEmpty(mountPointNodeName);
85 LOG.info("Mointpoint {} started as {}", mountPointNodeName, res.getClass().getSimpleName());