T-API context creation on feature install 13/95013/23
authorJavier Errea <errea@eurecom.fr>
Wed, 3 Feb 2021 10:30:32 +0000 (11:30 +0100)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Mon, 26 Apr 2021 10:29:06 +0000 (10:29 +0000)
- TAPI context java class (create & get context)
- Instantiation in Tapi provider
- Modify module structure -> New connectivity Package
- Rename TapiImpl -> TapiConnectivityImpl

JIRA: TRNSPRTPCE-424
Change-Id: Icf533c4217cf0daf40cf6715339858c9aaa2a738
Signed-off-by: errea <errea@eurecom.fr>
lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java [moved from tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiImpl.java with 97% similarity]
tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiProvider.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/utils/TapiContext.java [new file with mode: 0644]
tapi/src/main/resources/OSGI-INF/blueprint/tapi-blueprint.xml

index f977f15d3470a90722a1f4fa23ef26b7e4249052..1611a08a5ad5c2aad4aa87d2b6d552c5fd41452f 100644 (file)
@@ -188,8 +188,9 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                 lightyServices.getRpcProviderService(), lightyServices.getNotificationService(),
                 serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
                 servicehandler);
-        tapiProvider = initTapi(lightyServices, servicehandler);
-        if (activateNbiNotification) {
+
+        tapiProvider = initTapi(lightyServices, servicehandler, networkTransaction);
+        if(activateNbiNotification) {
             LOG.info("Creating nbi-notifications beans ...");
             nbiNotificationsProvider = new NbiNotificationsProvider(
                     publisherTopicList, null, null, lightyServices.getRpcProviderService(),
@@ -248,9 +249,10 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
      * @param rendererServiceOperations RendererServiceOperations
      * @return TapiProvider instance
      */
-    private TapiProvider initTapi(LightyServices lightyServices, OrgOpenroadmServiceService servicehandler) {
+    private TapiProvider initTapi(LightyServices lightyServices, OrgOpenroadmServiceService servicehandler,
+                                  NetworkTransactionService networkTransaction) {
         return new TapiProvider(lightyServices.getBindingDataBroker(), lightyServices.getRpcProviderService(),
-                servicehandler, new TapiListener());
+                servicehandler, new TapiListener(), networkTransaction);
     }
 
     /**
similarity index 97%
rename from tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiImpl.java
rename to tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java
index 19af382c5e912b493114429567a1943e0856b609..20dd577950ae217b728a077f53cebe0a86f43144 100644 (file)
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.transportpce.tapi.impl;
+package org.opendaylight.transportpce.tapi.connectivity;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.HashMap;
@@ -55,13 +55,13 @@ import org.slf4j.LoggerFactory;
 /**
  * Top level service interface providing main TAPI Connectivity services.
  */
-public class TapiImpl implements TapiConnectivityService {
+public class TapiConnectivityImpl implements TapiConnectivityService {
 
-    private static final Logger LOG = LoggerFactory.getLogger(TapiImpl.class);
+    private static final Logger LOG = LoggerFactory.getLogger(TapiConnectivityImpl.class);
 
     private OrgOpenroadmServiceService serviceHandler;
 
-    public TapiImpl(OrgOpenroadmServiceService serviceHandler) {
+    public TapiConnectivityImpl(OrgOpenroadmServiceService serviceHandler) {
         LOG.info("inside TapiImpl constructor");
         this.serviceHandler = serviceHandler;
     }
index b6173df6b23e80de826c354f2503305c82d3c953..6bde010fd084cb640d3cf7dadb3085d6b459f109 100644 (file)
@@ -12,7 +12,10 @@ import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.transportpce.common.network.NetworkTransactionService;
+import org.opendaylight.transportpce.tapi.connectivity.TapiConnectivityImpl;
 import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl;
+import org.opendaylight.transportpce.tapi.utils.TapiContext;
 import org.opendaylight.transportpce.tapi.utils.TapiListener;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
@@ -38,13 +41,16 @@ public class TapiProvider {
     private ObjectRegistration<TapiConnectivityService> rpcRegistration;
     private final OrgOpenroadmServiceService serviceHandler;
     private final TapiListener tapiListener;
+    private final NetworkTransactionService networkTransactionService;
 
     public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
-        OrgOpenroadmServiceService serviceHandler, TapiListener tapiListener) {
+            OrgOpenroadmServiceService serviceHandler, TapiListener tapiListener,
+            NetworkTransactionService networkTransactionService) {
         this.dataBroker = dataBroker;
         this.rpcProviderService = rpcProviderService;
         this.serviceHandler = serviceHandler;
         this.tapiListener = tapiListener;
+        this.networkTransactionService = networkTransactionService;
     }
 
     /**
@@ -52,7 +58,9 @@ public class TapiProvider {
      */
     public void init() {
         LOG.info("TapiProvider Session Initiated");
-        TapiImpl tapi = new TapiImpl(this.serviceHandler);
+        TapiContext tapiContext = new TapiContext(this.networkTransactionService);
+        LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
+        TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler);
         TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker);
         rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
         rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
diff --git a/tapi/src/main/java/org/opendaylight/transportpce/tapi/utils/TapiContext.java b/tapi/src/main/java/org/opendaylight/transportpce/tapi/utils/TapiContext.java
new file mode 100644 (file)
index 0000000..5c195f0
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright © 2021 Nokia, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.tapi.utils;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.transportpce.common.network.NetworkTransactionService;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1Builder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.NwTopologyServiceBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TapiContext {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TapiContext.class);
+    public static final String TAPI_CONTEXT = "T-API context";
+    private final NetworkTransactionService networkTransactionService;
+
+    public TapiContext(NetworkTransactionService networkTransactionService) {
+        this.networkTransactionService = networkTransactionService;
+        createTapiContext();
+    }
+
+    private void createTapiContext() {
+        try {
+            // Augmenting tapi context to include topology and connectivity contexts
+            Name contextName = new NameBuilder().setValue(TAPI_CONTEXT).setValueName("TAPI Context Name").build();
+
+            Context1 connectivityContext =
+                new Context1Builder()
+                    .setConnectivityContext(
+                        new ConnectivityContextBuilder()
+                            .setConnection(new HashMap<>())
+                            .setConnectivityService(new HashMap<>())
+                            .build())
+                    .build();
+
+            Name nwTopoServiceName =
+                new NameBuilder()
+                    .setValue("Network Topo Service")
+                    .setValueName("Network Topo Service Name")
+                    .build();
+
+            org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1 topologyContext
+                = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1Builder()
+                    .setTopologyContext(new TopologyContextBuilder()
+                        .setNwTopologyService(new NwTopologyServiceBuilder()
+                            .setTopology(new HashMap<>())
+                            .setUuid(
+                                new Uuid(
+                                    UUID.nameUUIDFromBytes("Network Topo Service".getBytes(Charset.forName("UTF-8")))
+                                        .toString()))
+                            .setName(Map.of(nwTopoServiceName.key(), nwTopoServiceName))
+                            .build())
+                        .setTopology(new HashMap<>())
+                        .build())
+                    .build();
+
+            ContextBuilder contextBuilder = new ContextBuilder()
+                    .setName(Map.of(contextName.key(), contextName))
+                    .setUuid(
+                        new Uuid(UUID.nameUUIDFromBytes(TAPI_CONTEXT.getBytes(Charset.forName("UTF-8"))).toString()))
+                    .setServiceInterfacePoint(new HashMap<>())
+                    .addAugmentation(connectivityContext)
+                    .addAugmentation(topologyContext);
+
+            // todo: add notification context
+            InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
+            // put in datastore
+            this.networkTransactionService.put(LogicalDatastoreType.OPERATIONAL, contextIID, contextBuilder.build());
+            this.networkTransactionService.commit().get();
+            LOG.info("TAPI context created successfully.");
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Failed to create TAPI context", e);
+        }
+    }
+
+    public Context getTapiContext() {
+        // TODO: verify this is correct. Should we identify the context IID with the context UUID??
+        //  There is no Identifiable in Context model
+        InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
+        try {
+            Optional<Context> optionalContext = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL,
+                    contextIID).get();
+            if (!optionalContext.isPresent()) {
+                LOG.error("Tapi context is not present in datastore");
+                return null;
+            }
+            return optionalContext.get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Couldnt read tapi context from datastore", e);
+            return null;
+        }
+    }
+
+    public void deleteTapiContext() {
+
+    }
+
+}
index 6149a54c8ba46ef65bf9d147bbcd8bb4113c3de3..31c00bb6ed002040e712c723d6deab8bb6acd602 100644 (file)
@@ -22,6 +22,9 @@ Author: Gilles Thouenon <gilles.thouenon@orange.com>
     <reference id="serviceHandlerService"
           interface="org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService" />
 
+    <reference id="networkTransactionImpl"
+          interface="org.opendaylight.transportpce.common.network.NetworkTransactionService" />
+
     <bean id="tapiListener"
           class="org.opendaylight.transportpce.tapi.utils.TapiListener">
     </bean>
@@ -33,6 +36,7 @@ Author: Gilles Thouenon <gilles.thouenon@orange.com>
         <argument ref="rpcProviderService" />
         <argument ref="serviceHandlerService" />
         <argument ref="tapiListener" />
+        <argument ref="networkTransactionImpl" />
     </bean>
 
 </blueprint>