X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=networkmodel%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnetworkmodel%2Fservice%2FNetworkModelServiceImpl.java;h=0d45a835aa37da7b096eae45cc6409aeda64f705;hb=1f9f09e6578a5500de469f9bdb4e05ae0970c711;hp=81079870e9022d32b1f09b69195f0d44c0880612;hpb=4ef19c0a7cddd25efa5c74c402b5f6b46bb73739;p=transportpce.git diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java index 81079870e..0d45a835a 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java @@ -9,17 +9,21 @@ package org.opendaylight.transportpce.networkmodel.service; import java.util.HashMap; import java.util.concurrent.ExecutionException; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.transportpce.common.NetworkUtils; import org.opendaylight.transportpce.common.device.DeviceTransactionManager; import org.opendaylight.transportpce.common.mapping.PortMapping; +import org.opendaylight.transportpce.common.network.NetworkTransactionService; import org.opendaylight.transportpce.networkmodel.R2RLinkDiscovery; import org.opendaylight.transportpce.networkmodel.dto.TopologyShard; import org.opendaylight.transportpce.networkmodel.util.ClliNetwork; +import org.opendaylight.transportpce.networkmodel.util.OpenRoadmFactory; import org.opendaylight.transportpce.networkmodel.util.OpenRoadmNetwork; -import org.opendaylight.transportpce.networkmodel.util.OpenRoadmTopology; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.Nodes.OpenroadmVersion; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.Network; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NetworkId; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NetworkKey; @@ -38,20 +42,22 @@ public class NetworkModelServiceImpl implements NetworkModelService { private static final Logger LOG = LoggerFactory.getLogger(NetworkModelServiceImpl.class); private static final boolean CREATE_MISSING_PARENTS = true; - private final DataBroker dataBroker; + private NetworkTransactionService networkTransactionService; + //private final R2RLinkDiscoveryFactoryMethod linkDiscovery; private final R2RLinkDiscovery linkDiscovery; private final DeviceTransactionManager deviceTransactionManager; - private final OpenRoadmTopology openRoadmTopology; + private final OpenRoadmFactory openRoadmFactory; private final PortMapping portMapping; private HashMap topologyShardMountedDevice; - public NetworkModelServiceImpl(final DataBroker dataBroker, final R2RLinkDiscovery linkDiscovery, - DeviceTransactionManager deviceTransactionManager, - OpenRoadmTopology openRoadmTopology, PortMapping portMapping) { - this.dataBroker = dataBroker; + public NetworkModelServiceImpl(final NetworkTransactionService networkTransactionService, + final R2RLinkDiscovery linkDiscovery, DeviceTransactionManager deviceTransactionManager, + OpenRoadmFactory openRoadmFactory, PortMapping portMapping) { + + this.networkTransactionService = networkTransactionService; this.linkDiscovery = linkDiscovery; this.deviceTransactionManager = deviceTransactionManager; - this.openRoadmTopology = openRoadmTopology; + this.openRoadmFactory = openRoadmFactory; this.portMapping = portMapping; this.topologyShardMountedDevice = new HashMap(); } @@ -64,77 +70,89 @@ public class NetworkModelServiceImpl implements NetworkModelService { } @Override - public void createOpenROADMnode(String nodeId) { + public void createOpenROADMnode(String nodeId, String openRoadmVersion) { try { LOG.info("createOpenROADMNode: {} ", nodeId); - this.portMapping.createMappingData(nodeId); - this.linkDiscovery.readLLDP(new NodeId(nodeId)); + if (!portMapping.createMappingData(nodeId, openRoadmVersion)) { + LOG.warn("Could not generate port mapping for {} skipping network model creation", nodeId); + return; + } + this.linkDiscovery.readLLDP(new NodeId(nodeId), openRoadmVersion); - Node clliNode = ClliNetwork.createNode(this.deviceTransactionManager, nodeId); + Node clliNode = ClliNetwork.createNode(this.deviceTransactionManager, nodeId, openRoadmVersion); if (clliNode == null) { LOG.error("Unable to create clli node! Node id: {}", nodeId); return; } - Node openRoadmNode = OpenRoadmNetwork.createNode(nodeId, this.deviceTransactionManager); + InstanceIdentifier iiClliNode = InstanceIdentifier + .builder(Network.class, new NetworkKey(new + NetworkId(NetworkUtils.CLLI_NETWORK_ID))) + .child(Node.class, clliNode.key()) + .build(); + + + LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID); + networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode, + CREATE_MISSING_PARENTS); + + Node openRoadmNode = OpenRoadmNetwork.createNode(nodeId, this.deviceTransactionManager, openRoadmVersion); if (openRoadmNode == null) { LOG.error("Unable to create OpenRoadm node! Node id: {}", nodeId); return; } + InstanceIdentifier iiOpenRoadmNode = InstanceIdentifier + .builder(Network.class, new NetworkKey(new + NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))) + .child(Node.class, openRoadmNode.key()) + .build(); + + LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID); + networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmNode, openRoadmNode, + CREATE_MISSING_PARENTS); + + + TopologyShard topologyShard = openRoadmFactory.createTopologyShardVersionControl(nodeId); - TopologyShard topologyShard = this.openRoadmTopology.createTopologyShard(nodeId); if (topologyShard == null) { LOG.error("Unable to create topology shard for node {}!", nodeId); return; } this.topologyShardMountedDevice.put(nodeId, topologyShard); - WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction(); - LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID); - InstanceIdentifier iiClliNode = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID))) - .child(Node.class, clliNode.key()) - .build(); - writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode, - CREATE_MISSING_PARENTS); - LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID); - InstanceIdentifier iiOpenRoadmNode = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))) - .child(Node.class, openRoadmNode.key()) - .build(); - writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmNode, openRoadmNode, - CREATE_MISSING_PARENTS); for (Node openRoadmTopologyNode: topologyShard.getNodes()) { LOG.info("creating node {} in {}", openRoadmTopologyNode.getNodeId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID); InstanceIdentifier iiOpenRoadmTopologyNode = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) - .child(Node.class, openRoadmTopologyNode.key()) - .build(); - writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode, - openRoadmTopologyNode, CREATE_MISSING_PARENTS); + .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) + .child(Node.class, openRoadmTopologyNode.key()) + .build(); + networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode, + openRoadmTopologyNode, CREATE_MISSING_PARENTS); } for (Link openRoadmTopologyLink: topologyShard.getLinks()) { LOG.info("creating link {} in {}", openRoadmTopologyLink.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID); InstanceIdentifier iiOpenRoadmTopologyLink = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) - .augmentation(Network1.class) - .child(Link.class, openRoadmTopologyLink.key()) - .build(); - writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink, - openRoadmTopologyLink, CREATE_MISSING_PARENTS); + .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) + .augmentation(Network1.class) + .child(Link.class, openRoadmTopologyLink.key()) + .build(); + networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink, + openRoadmTopologyLink, CREATE_MISSING_PARENTS); } - writeTransaction.submit().get(); + networkTransactionService.submit().get(); + //linkDiscovery.readLLDP(nodeId); LOG.info("all nodes and links created"); } catch (InterruptedException | ExecutionException e) { LOG.error("ERROR: ", e); } + } @Override - public void setOpenROADMnodeStatus(String nodeId, NetconfNodeConnectionStatus.ConnectionStatus connectionStatus) { + public void setOpenRoadmNodeStatus(String nodeId, NetconfNodeConnectionStatus.ConnectionStatus connectionStatus) { LOG.info("setOpenROADMNodeStatus: {} {}", nodeId, connectionStatus.name()); /* TODO: set connection status of the device in model, @@ -147,26 +165,33 @@ public class NetworkModelServiceImpl implements NetworkModelService { /* (non-Javadoc) * @see org.opendaylight.transportpce.networkmodel.service.NetworkModelService#deleteOpenROADMnode(java.lang.String) */ + + + @Override - public void deleteOpenROADMnode(String nodeId) { + public void deleteOpenRoadmnode(String nodeId) { try { - LOG.info("deleteOpenROADMnode: {} ", nodeId); + @Nullable + OpenroadmVersion deviceVersion = this.portMapping.getNode(nodeId).getOpenroadmVersion(); + LOG.info("deleteOpenROADMnode: {} version {}", nodeId, deviceVersion.getName()); this.portMapping.deleteMappingData(nodeId); NodeKey nodeIdKey = new NodeKey(new NodeId(nodeId)); - WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction(); + LOG.info("deleting node in {}", NetworkUtils.CLLI_NETWORK_ID); InstanceIdentifier iiClliNode = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID))) - .child(Node.class, nodeIdKey) - .build(); - writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, iiClliNode); + .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID))) + .child(Node.class, nodeIdKey) + .build(); + this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiClliNode); + LOG.info("deleting node in {}", NetworkUtils.UNDERLAY_NETWORK_ID); InstanceIdentifier iiOpenRoadmNode = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))) - .child(Node.class, nodeIdKey) - .build(); - writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmNode); + .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))) + .child(Node.class, nodeIdKey) + .build(); + this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmNode); + TopologyShard topologyShard = this.topologyShardMountedDevice.get(nodeId); if (topologyShard != null) { LOG.info("TopologyShard for node '{}' is present", nodeId); @@ -174,27 +199,27 @@ public class NetworkModelServiceImpl implements NetworkModelService { LOG.info("deleting node {} in {}", openRoadmTopologyNode.getNodeId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID); InstanceIdentifier iiOpenRoadmTopologyNode = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) - .child(Node.class, openRoadmTopologyNode.key()) - .build(); - writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode); + .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) + .child(Node.class, openRoadmTopologyNode.key()) + .build(); + this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode); } for (Link openRoadmTopologyLink: topologyShard.getLinks()) { LOG.info("deleting link {} in {}", openRoadmTopologyLink.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID); InstanceIdentifier iiOpenRoadmTopologyLink = InstanceIdentifier - .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) - .augmentation(Network1.class) - .child(Link.class, openRoadmTopologyLink.key()) - .build(); - writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink); + .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))) + .augmentation(Network1.class) + .child(Link.class, openRoadmTopologyLink.key()) + .build(); + this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink); } } else { LOG.warn("TopologyShard for node '{}' is not present", nodeId); } - writeTransaction.submit().get(); + this.networkTransactionService.submit().get(1, TimeUnit.SECONDS); LOG.info("all nodes and links deleted ! "); - } catch (InterruptedException | ExecutionException e) { + } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.error("Error when trying to delete node : {}", nodeId, e); } }