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 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.netconf.wrapperc.OnfMicrowaveModel;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperMicrowaveModelRev170324;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperMicrowaveModelRev180907;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperMicrowaveModelRev181010;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.ProviderClient;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
34 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
35 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
36 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
37 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * Create a Network Element representation according to the capability
48 * information. The capabilities are more than an ODL-QName. After the ? other
49 * terms than "revision" are provided.
52 @SuppressWarnings("deprecation")
53 public class ONFCoreNetworkElementFactory {
55 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementFactory.class);
57 public static @Nonnull ONFCoreNetworkElementRepresentation create(String mountPointNodeName, DataBroker dataBroker,
58 WebSocketServiceClient webSocketService, HtDatabaseEventsService databaseService,
59 InstanceIdentifier<Node> instanceIdentifier, DataBroker mountpointDataBroker, ProviderClient dcaeProvider,
60 @Nullable ProviderClient aotsmClient, MaintenanceService maintenanceService,
61 NotificationDelayService<ProblemNotificationXml> notificationDelayService) {
63 ONFCoreNetworkElementRepresentation res = null;
64 try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();){
65 Optional<Node> nodeOption = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet();
66 if (nodeOption.isPresent()) {
67 Node node = nodeOption.get();
68 NetconfNode nnode = node.augmentation(NetconfNode.class);
70 ConnectionStatus csts = nnode.getConnectionStatus();
71 if (csts == ConnectionStatus.Connected) {
72 Capabilities capabilities = Capabilities.getAvailableCapabilities(nnode);
73 LOG.info("Mountpoint {} capabilities {}", mountPointNodeName, capabilities);
74 res = build(mountPointNodeName, capabilities, mountpointDataBroker,
75 webSocketService, databaseService, dcaeProvider, aotsmClient, maintenanceService,
76 notificationDelayService);
77 LOG.info("ONFCoreNetworkElementRepresentation12 value is not null? " + (res != null));
82 } catch (ReadFailedException | IllegalArgumentException e) {
83 LOG.warn("Can not generate specific NE Version representation. ", e);
86 res = new ONFCoreNetworkElementEmpty(mountPointNodeName);
88 LOG.info("Mointpoint {} started as {}", mountPointNodeName, res.getClass().getSimpleName());
92 public static @Nonnull ONFCoreNetworkElementRepresentation getEmpty(String mountPointNodeName) {
93 return new ONFCoreNetworkElementEmpty(mountPointNodeName);
97 * Check capabilities are matching the this specific implementation and create network element
98 * representation if so.
100 * @param mountPointNodeName as String
101 * @param capabilities of the specific network element
102 * @param netconfNodeDataBroker for the network element specific data
103 * @param webSocketService to forward event notifications
104 * @param databaseService to access the database
105 * @param dcaeProvider to forward problem / change notifications
106 * @return created Object if conditions are OK or null if not.
108 private static @Nullable ONFCoreNetworkElementRepresentation build(String mountPointNodeName, Capabilities capabilities,
109 DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
110 HtDatabaseEventsService databaseService, ProviderClient dcaeProvider, @Nullable ProviderClient aotsmClient,
111 MaintenanceService maintenanceService,
112 NotificationDelayService<ProblemNotificationXml> notificationDelayService) {
114 if (capabilities.isSupportingNamespaceAndRevision(NetworkElement.QNAME)) {
115 OnfMicrowaveModel onfMicrowaveModel = null;
117 if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev170324.QNAME)) {
118 onfMicrowaveModel = new WrapperMicrowaveModelRev170324();
119 } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev180907.QNAME)) {
120 onfMicrowaveModel = new WrapperMicrowaveModelRev180907();
121 } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev181010.QNAME)) {
122 onfMicrowaveModel = new WrapperMicrowaveModelRev181010();
125 if (onfMicrowaveModel != null) {
126 return new ONFCoreNetworkElement12Microwave(mountPointNodeName, capabilities, netconfNodeDataBroker,
127 webSocketService, databaseService, dcaeProvider, aotsmClient, maintenanceService,
128 notificationDelayService, onfMicrowaveModel);
130 return new ONFCoreNetworkElement12(mountPointNodeName, capabilities, netconfNodeDataBroker,
131 webSocketService, databaseService, dcaeProvider, aotsmClient, maintenanceService,
132 notificationDelayService);