Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / base / netconf / ONFCoreNetworkElementFactory.java
1 package org.opendaylight.mwtn.base.netconf;
2
3 import javax.annotation.Nullable;
4
5 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
6 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
7 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
8 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
9 import org.opendaylight.mwtn.devicemanager.impl.ProviderClient;
10 import org.opendaylight.mwtn.devicemanager.impl.database.service.HtDatabaseEventsService;
11 import org.opendaylight.mwtn.devicemanager.impl.xml.WebSocketServiceClient;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 import com.google.common.base.Optional;
20
21 /**
22  * Create a Network Element representation according to the capability information.
23  * The capabilities are more than an ODL-QName. After the ? other terms than "revision" are provided.
24  *
25  */
26 public class ONFCoreNetworkElementFactory {
27
28     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementFactory.class);
29
30     public static ONFCoreNetworkElementRepresentation create( String mountPointNodeName,
31             DataBroker dataBroker, WebSocketServiceClient webSocketService, HtDatabaseEventsService databaseService, InstanceIdentifier<Node> instanceIdentifier,
32             DataBroker mountpointDataBroker, ProviderClient dcaeProvider, @Nullable ProviderClient aotsmClient ) {
33
34         ReadTransaction tx=dataBroker.newReadOnlyTransaction();
35         ONFCoreNetworkElementRepresentation res = null;
36
37         try {
38             Optional<Node> nodeOption = tx.read(LogicalDatastoreType.OPERATIONAL,instanceIdentifier).checkedGet();
39             if (nodeOption.isPresent()) {
40                 Node node = nodeOption.get();
41                 NetconfNode nnode=node.getAugmentation(NetconfNode.class);
42                 if (nnode != null) {
43                     ConnectionStatus csts=nnode.getConnectionStatus();
44                     if (csts == ConnectionStatus.Connected) {
45                         Capabilities capabilities = new Capabilities(nnode);
46                         LOG.info("Mountpoint {} capabilities {}",mountPointNodeName, capabilities);
47
48                         res = ONFCoreNetworkElement10.build(mountPointNodeName, capabilities, mountpointDataBroker, webSocketService, databaseService, dcaeProvider,aotsmClient);
49                         if (res == null) {
50                             res = ONFCoreNetworkElement12.build(mountPointNodeName, capabilities, mountpointDataBroker, webSocketService, databaseService, dcaeProvider,aotsmClient);
51                         }
52                     }
53                 }
54             }
55         } catch (ReadFailedException | IllegalArgumentException e) {
56             LOG.warn("Can not generate specific NE Version representation. ", e);
57         }
58         if (res == null) {
59             res = new ONFCoreEmpty(mountPointNodeName);
60         }
61
62         LOG.info("Mointpoint {} started as {}", mountPointNodeName,res.getClass().getSimpleName() );
63
64         return res;
65     }
66
67
68 }