Junit tests for new TAPI module
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / utils / TapiContext.java
1 /*
2  * Copyright © 2021 Nokia, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.utils;
9
10 import java.nio.charset.Charset;
11 import java.util.HashMap;
12 import java.util.Map;
13 import java.util.Optional;
14 import java.util.UUID;
15 import java.util.concurrent.ExecutionException;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ContextBuilder;
20 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
21 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
22 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
23 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePoint;
24 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointKey;
25 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1;
26 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1Builder;
27 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.OwnedNodeEdgePoint1;
28 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.OwnedNodeEdgePoint1Builder;
29 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPoint;
30 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityService;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityServiceKey;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContextBuilder;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.topology.context.topology.node.owned.node.edge.point.CepList;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.topology.context.topology.node.owned.node.edge.point.CepListBuilder;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContextBuilder;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointBuilder;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointKey;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.NwTopologyServiceBuilder;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey;
51 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 public class TapiContext {
56
57     private static final Logger LOG = LoggerFactory.getLogger(TapiContext.class);
58     public static final String TAPI_CONTEXT = "T-API context";
59     public static final String NODE_NOT_PRESENT = "Node is not present in datastore";
60     private final NetworkTransactionService networkTransactionService;
61
62     public TapiContext(NetworkTransactionService networkTransactionService) {
63         this.networkTransactionService = networkTransactionService;
64         createTapiContext();
65     }
66
67     private void createTapiContext() {
68         try {
69             // Augmenting tapi context to include topology and connectivity contexts
70             Name contextName = new NameBuilder().setValue(TAPI_CONTEXT).setValueName("TAPI Context Name").build();
71
72             Context1 connectivityContext =
73                 new Context1Builder()
74                     .setConnectivityContext(
75                         new ConnectivityContextBuilder()
76                             .setConnection(new HashMap<>())
77                             .setConnectivityService(new HashMap<>())
78                             .build())
79                     .build();
80
81             Name nwTopoServiceName =
82                 new NameBuilder()
83                     .setValue("Network Topo Service")
84                     .setValueName("Network Topo Service Name")
85                     .build();
86
87             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1 topologyContext
88                 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1Builder()
89                     .setTopologyContext(new TopologyContextBuilder()
90                         .setNwTopologyService(new NwTopologyServiceBuilder()
91                             .setTopology(new HashMap<>())
92                             .setUuid(
93                                 new Uuid(
94                                     UUID.nameUUIDFromBytes("Network Topo Service".getBytes(Charset.forName("UTF-8")))
95                                         .toString()))
96                             .setName(Map.of(nwTopoServiceName.key(), nwTopoServiceName))
97                             .build())
98                         .setTopology(new HashMap<>())
99                         .build())
100                     .build();
101
102             ContextBuilder contextBuilder = new ContextBuilder()
103                     .setName(Map.of(contextName.key(), contextName))
104                     .setUuid(
105                         new Uuid(UUID.nameUUIDFromBytes(TAPI_CONTEXT.getBytes(Charset.forName("UTF-8"))).toString()))
106                     .setServiceInterfacePoint(new HashMap<>())
107                     .addAugmentation(connectivityContext)
108                     .addAugmentation(topologyContext);
109
110             // todo: add notification context
111             InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
112             // put in datastore
113             this.networkTransactionService.put(LogicalDatastoreType.OPERATIONAL, contextIID, contextBuilder.build());
114             this.networkTransactionService.commit().get();
115             LOG.info("TAPI context created successfully.");
116         } catch (InterruptedException | ExecutionException e) {
117             LOG.error("Failed to create TAPI context", e);
118         }
119     }
120
121     public Context getTapiContext() {
122         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
123         //  There is no Identifiable in Context model
124         InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
125         try {
126             Optional<Context> optionalContext = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL,
127                     contextIID).get();
128             if (!optionalContext.isPresent()) {
129                 LOG.error("Tapi context is not present in datastore");
130                 return null;
131             }
132             return optionalContext.get();
133         } catch (InterruptedException | ExecutionException e) {
134             LOG.error("Couldnt read tapi context from datastore", e);
135             return null;
136         }
137     }
138
139     public void deleteTapiContext() {
140
141     }
142
143     public void updateTopologyContext(Map<TopologyKey, Topology> topologyMap) {
144         // TODO: solve error when merging: Topology is not a valid child of topology context?
145         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
146         try {
147             TopologyContext topologyContext = new TopologyContextBuilder()
148                     //.setNwTopologyService(new NwTopologyServiceBuilder().build())
149                     .setTopology(topologyMap)
150                     .build();
151             InstanceIdentifier<TopologyContext> topologycontextIID =
152                     InstanceIdentifier.builder(Context.class).augmentation(org.opendaylight.yang.gen.v1.urn
153                             .onf.otcc.yang.tapi.topology.rev181210.Context1.class)
154                             .child(TopologyContext.class)
155                             .build();
156             // merge in datastore
157             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topologycontextIID,
158                     topologyContext);
159             this.networkTransactionService.commit().get();
160             LOG.info("TAPI topology merged successfully.");
161         } catch (InterruptedException | ExecutionException e) {
162             LOG.error("Failed to merge TAPI topology", e);
163         }
164     }
165
166     public void updateSIPContext(Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap) {
167         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
168         try {
169             ContextBuilder contextBuilder = new ContextBuilder().setServiceInterfacePoint(sipMap);
170             InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
171             // merge in datastore
172             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, contextIID,
173                     contextBuilder.build());
174             this.networkTransactionService.commit().get();
175             LOG.info("TAPI SIPs merged successfully.");
176         } catch (InterruptedException | ExecutionException e) {
177             LOG.error("Failed to merge TAPI SIPs", e);
178         }
179     }
180
181     public void updateConnectivityContext(Map<ConnectivityServiceKey, ConnectivityService> connServMap,
182                                           Map<ConnectionKey, Connection> connectionFullMap) {
183         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
184         try {
185             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext
186                 connectivityContext = new ConnectivityContextBuilder()
187                 .setConnectivityService(connServMap)
188                 .setConnection(connectionFullMap)
189                 .build();
190             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn
191                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> connectivitycontextIID =
192                     InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
193                         .child(org.opendaylight.yang.gen.v1.urn
194                             .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
195                         .build();
196             // merge in datastore
197             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, connectivitycontextIID,
198                 connectivityContext);
199             this.networkTransactionService.commit().get();
200             LOG.info("TAPI connectivity merged successfully.");
201         } catch (InterruptedException | ExecutionException e) {
202             LOG.error("Failed to merge TAPI connectivity", e);
203         }
204     }
205
206     public void updateTopologyWithCep(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid, ConnectionEndPoint cep) {
207         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
208         InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
209             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
210             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
211             .child(Topology.class, new TopologyKey(topoUuid))
212             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
213                     new NodeKey(nodeUuid))
214             .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid))
215             .build();
216         try {
217             Optional<OwnedNodeEdgePoint> optionalOnep = this.networkTransactionService.read(
218                     LogicalDatastoreType.OPERATIONAL, onepIID).get();
219             if (!optionalOnep.isPresent()) {
220                 LOG.error("ONEP is not present in datastore");
221                 return;
222             }
223             OwnedNodeEdgePoint onep = optionalOnep.get();
224             LOG.info("ONEP found = {}", onep);
225             // TODO -> If cep exists -> skip merging to datasore
226             OwnedNodeEdgePoint1 onep1 = onep.augmentation(OwnedNodeEdgePoint1.class);
227             if (onep1 != null && onep1.getCepList() != null && onep1.getCepList().getConnectionEndPoint() != null
228                     && onep1.getCepList().getConnectionEndPoint().containsKey(new ConnectionEndPointKey(cep.key()))) {
229                 LOG.info("CEP already in topology, skipping merge");
230                 return;
231             }
232             // Updated ONEP
233             CepList cepList = new CepListBuilder().setConnectionEndPoint(Map.of(cep.key(), cep)).build();
234             OwnedNodeEdgePoint1 onep1Bldr = new OwnedNodeEdgePoint1Builder().setCepList(cepList).build();
235             OwnedNodeEdgePoint newOnep = new OwnedNodeEdgePointBuilder(onep)
236                     .addAugmentation(onep1Bldr)
237                     .build();
238             LOG.info("New ONEP is {}", newOnep);
239             // merge in datastore
240             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, onepIID,
241                     newOnep);
242             this.networkTransactionService.commit().get();
243             LOG.info("CEP added successfully.");
244         } catch (InterruptedException | ExecutionException e) {
245             LOG.error("Couldnt update cep in topology", e);
246         }
247     }
248
249     public Node getTapiNode(Uuid topoUuid, Uuid nodeUuid) {
250         InstanceIdentifier<Node> nodeIID = InstanceIdentifier.builder(Context.class)
251             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
252             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
253             .child(Topology.class, new TopologyKey(topoUuid))
254             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
255                         new NodeKey(nodeUuid)).build();
256         try {
257             Optional<Node> optNode = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, nodeIID)
258                     .get();
259             if (!optNode.isPresent()) {
260                 LOG.error(NODE_NOT_PRESENT);
261                 return null;
262             }
263             // TODO -> Need to remove CEPs from NEPs. If not error from get Topology details output
264             Node node = optNode.get();
265             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
266             for (OwnedNodeEdgePoint onep: node.getOwnedNodeEdgePoint().values()) {
267                 if (onep.augmentation(OwnedNodeEdgePoint1.class) == null) {
268                     onepMap.put(onep.key(), onep);
269                     continue;
270                 }
271                 OwnedNodeEdgePointBuilder newOnepBuilder = new OwnedNodeEdgePointBuilder()
272                     .setUuid(onep.getUuid())
273                     .setLayerProtocolName(onep.getLayerProtocolName())
274                     .setName(onep.getName())
275                     .setSupportedCepLayerProtocolQualifier(onep.getSupportedCepLayerProtocolQualifier())
276                     .setAdministrativeState(onep.getAdministrativeState())
277                     .setOperationalState(onep.getOperationalState())
278                     .setLifecycleState(onep.getLifecycleState())
279                     .setTerminationDirection(onep.getTerminationDirection())
280                     .setTerminationState(onep.getTerminationState())
281                     .setLinkPortDirection(onep.getLinkPortDirection())
282                     .setLinkPortRole(onep.getLinkPortRole());
283                 if (onep.getMappedServiceInterfacePoint() != null) {
284                     newOnepBuilder.setMappedServiceInterfacePoint(onep.getMappedServiceInterfacePoint());
285                 }
286                 onepMap.put(newOnepBuilder.key(), newOnepBuilder.build());
287             }
288             return new NodeBuilder(node)
289                 .setOwnedNodeEdgePoint(onepMap)
290                 .build();
291         } catch (InterruptedException | ExecutionException e) {
292             LOG.error("Couldnt read node in topology", e);
293             return null;
294         }
295     }
296
297     public OwnedNodeEdgePoint getTapiNEP(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid) {
298         InstanceIdentifier<OwnedNodeEdgePoint> nepIID = InstanceIdentifier.builder(Context.class)
299             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
300             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
301             .child(Topology.class, new TopologyKey(topoUuid))
302             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
303                 new NodeKey(nodeUuid)).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid)).build();
304         try {
305             Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
306                     .read(LogicalDatastoreType.OPERATIONAL, nepIID)
307                     .get();
308             if (!optNode.isPresent()) {
309                 LOG.error(NODE_NOT_PRESENT);
310                 return null;
311             }
312             return optNode.get();
313         } catch (InterruptedException | ExecutionException e) {
314             LOG.error("Couldnt read NEP in topology", e);
315             return null;
316         }
317     }
318
319     public Link getTapiLink(Uuid topoUuid, Uuid linkUuid) {
320         InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
321             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
322             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
323             .child(Topology.class, new TopologyKey(topoUuid))
324             .child(Link.class, new LinkKey(linkUuid)).build();
325         try {
326             Optional<Link> optLink = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, linkIID)
327                     .get();
328             if (!optLink.isPresent()) {
329                 LOG.error(NODE_NOT_PRESENT);
330                 return null;
331             }
332             return optLink.get();
333         } catch (InterruptedException | ExecutionException e) {
334             LOG.error("Couldnt read link in topology", e);
335             return null;
336         }
337     }
338
339     public Map<TopologyKey, Topology> getTopologyContext() {
340         InstanceIdentifier<TopologyContext> topologycontextIID =
341                 InstanceIdentifier.builder(Context.class).augmentation(org.opendaylight.yang.gen.v1.urn
342                         .onf.otcc.yang.tapi.topology.rev181210.Context1.class)
343                         .child(TopologyContext.class)
344                         .build();
345         try {
346             Optional<TopologyContext> optTopoContext = this.networkTransactionService.read(
347                     LogicalDatastoreType.OPERATIONAL, topologycontextIID).get();
348             if (!optTopoContext.isPresent()) {
349                 LOG.error("Topology context is not present in datastore");
350                 return null;
351             }
352             return optTopoContext.get().getTopology();
353         } catch (InterruptedException | ExecutionException e) {
354             LOG.error("Couldnt read topology context", e);
355             return null;
356         }
357     }
358
359     public ConnectivityService getConnectivityService(Uuid serviceUuid) {
360         try {
361             // First read connectivity service with service uuid and update info
362             InstanceIdentifier<ConnectivityService> connectivityServIID =
363                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
364                     .child(org.opendaylight.yang.gen.v1.urn
365                         .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
366                     .child(ConnectivityService.class, new ConnectivityServiceKey(serviceUuid))
367                     .build();
368
369             Optional<ConnectivityService> optConnServ =
370                 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivityServIID).get();
371             if (!optConnServ.isPresent()) {
372                 LOG.error("Connectivity service not found in tapi context");
373                 return null;
374             }
375             return optConnServ.get();
376         } catch (InterruptedException | ExecutionException e) {
377             LOG.error("Connectivity service not found in tapi context. Error:", e);
378             return null;
379         }
380     }
381
382     public void deleteConnectivityService(Uuid serviceUuid) {
383         ConnectivityService connectivityService = getConnectivityService(serviceUuid);
384         if (connectivityService == null) {
385             LOG.error("Service doesnt exist in tapi context");
386             return;
387         }
388         for (org.opendaylight.yang.gen.v1
389                 .urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.Connection connection:
390                     connectivityService.getConnection().values()) {
391             deleteConnection(connection.getConnectionUuid());
392         }
393         InstanceIdentifier<ConnectivityService> connectivityServIID =
394                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
395                         .child(org.opendaylight.yang.gen.v1.urn
396                                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
397                         .child(ConnectivityService.class, new ConnectivityServiceKey(serviceUuid))
398                         .build();
399         try {
400             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, connectivityServIID);
401             this.networkTransactionService.commit().get();
402             LOG.info("Connectivity service deleted");
403         } catch (InterruptedException | ExecutionException e) {
404             LOG.error("Failed to delete Connectivity service", e);
405         }
406     }
407
408     private void deleteConnection(Uuid connectionUuid) {
409         // First read connectivity service with service uuid and update info
410         InstanceIdentifier<org.opendaylight.yang.gen.v1
411             .urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection> connectionIID =
412             InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
413                 .child(org.opendaylight.yang.gen.v1.urn
414                     .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
415                 .child(org.opendaylight.yang.gen.v1.urn
416                         .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection.class,
417                     new org.opendaylight.yang.gen.v1.urn
418                         .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey(
419                             connectionUuid))
420                 .build();
421         try {
422             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, connectionIID);
423             this.networkTransactionService.commit().get();
424         } catch (InterruptedException | ExecutionException e) {
425             LOG.error("Failed to delete TAPI Connection", e);
426         }
427     }
428
429     public Connection getConnection(Uuid connectionUuid) {
430         try {
431             // First read connectivity service with service uuid and update info
432             InstanceIdentifier<Connection> connIID =
433                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
434                     .child(org.opendaylight.yang.gen.v1.urn
435                         .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
436                     .child(Connection.class, new ConnectionKey(connectionUuid))
437                     .build();
438
439             Optional<Connection> optConn =
440                 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connIID).get();
441             if (!optConn.isPresent()) {
442                 LOG.error("Connection not found in tapi context");
443                 return null;
444             }
445             return optConn.get();
446         } catch (InterruptedException | ExecutionException e) {
447             LOG.error("Connection not found in tapi context. Error:", e);
448             return null;
449         }
450     }
451
452     public Map<ConnectivityServiceKey, ConnectivityService> getConnectivityServices() {
453         try {
454             // First read connectivity service with service uuid and update info
455             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn
456                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> connectivityContextIID =
457                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
458                     .child(org.opendaylight.yang.gen.v1.urn
459                         .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
460                     .build();
461
462             Optional<org.opendaylight.yang.gen.v1.urn
463                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> optConnContext =
464                     this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivityContextIID)
465                         .get();
466             if (!optConnContext.isPresent()) {
467                 LOG.error("Connectivity context not found in tapi context");
468                 return null;
469             }
470             return optConnContext.get().getConnectivityService();
471         } catch (InterruptedException | ExecutionException e) {
472             LOG.error("Connectivity context not found in tapi context. Error:", e);
473             return null;
474         }
475     }
476
477     public ConnectionEndPoint getTapiCEP(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid, Uuid cepUuid) {
478         InstanceIdentifier<OwnedNodeEdgePoint> nepIID = InstanceIdentifier.builder(Context.class)
479             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
480             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
481             .child(Topology.class, new TopologyKey(topoUuid))
482             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
483                 new NodeKey(nodeUuid)).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid)).build();
484         try {
485             Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
486                 .read(LogicalDatastoreType.OPERATIONAL, nepIID).get();
487             if (!optNode.isPresent()) {
488                 LOG.error(NODE_NOT_PRESENT);
489                 return null;
490             }
491             if (optNode.get().augmentation(OwnedNodeEdgePoint1.class) == null) {
492                 LOG.error("Node doesnt have ceps");
493                 return null;
494             }
495             return optNode.get().augmentation(OwnedNodeEdgePoint1.class).getCepList().getConnectionEndPoint()
496                 .get(new ConnectionEndPointKey(cepUuid));
497         } catch (InterruptedException | ExecutionException e) {
498             LOG.error("Couldnt read node in topology", e);
499             return null;
500         }
501     }
502 }