Implement get-connectivity-service-list RPC 78/60078/1
authorDonald Hunter <donaldh@cisco.com>
Fri, 7 Jul 2017 13:52:13 +0000 (14:52 +0100)
committerDonald Hunter <donaldh@cisco.com>
Fri, 7 Jul 2017 13:52:13 +0000 (14:52 +0100)
Change-Id: I2803ae88d347bb02ea118e4e884df9c30f5314cf
Signed-off-by: Donald Hunter <donaldh@cisco.com>
impl/pom.xml
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/api/FailureResult.java [new file with mode: 0644]
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/api/RequestDecomposer.java
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/common/NrpDao.java
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/impl/connectivityservice/CreateConnectivityAction.java
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/impl/connectivityservice/ListConnectivityAction.java [new file with mode: 0644]
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/impl/connectivityservice/TapiConnectivityServiceImpl.java
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/impl/decomposer/BasicDecomposer.java
impl/src/main/java/org/opendaylight/unimgr/mef/nrp/impl/decomposer/DecompositionAction.java
impl/src/test/java/org/opendaylight/unimgr/mef/nrp/impl/BasicDecomposerTest.java
impl/src/test/java/org/opendaylight/unimgr/mef/nrp/impl/connectivityservice/TapiConnectivityServiceImplTest.java

index 12470954663c6eca13173bd733f3779e862662af..80c6d704ff7716d8a82447a6694ea7380d9556e2 100644 (file)
@@ -41,7 +41,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
-                <version>3.0.2</version>
                 <executions>
                     <execution>
                         <goals>
diff --git a/impl/src/main/java/org/opendaylight/unimgr/mef/nrp/api/FailureResult.java b/impl/src/main/java/org/opendaylight/unimgr/mef/nrp/api/FailureResult.java
new file mode 100644 (file)
index 0000000..647209a
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 Cisco Systems 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.unimgr.mef.nrp.api;
+
+import java.text.MessageFormat;
+
+public class FailureResult extends Exception {
+
+    private static final long serialVersionUID = -995923939107287244L;
+
+    public FailureResult(String message) {
+        super(message);
+    }
+
+    public FailureResult(String message, Object ... args) {
+        super(MessageFormat.format(message, args));
+    }
+}
index 1faa04dafdde4631fd5f82ed8186535757b84d26..1ac6171bb4e3851e109d80ebad1c07b7fc1cfe2c 100644 (file)
@@ -22,5 +22,5 @@ public interface RequestDecomposer {
      * @param constraint on decoposition
      * @return list of subrequests - one per driver
      */
-    List<Subrequrest> decompose(List<EndPoint> endpoints, Constraints constraint);
+    List<Subrequrest> decompose(List<EndPoint> endpoints, Constraints constraint) throws FailureResult;
 }
index 8d6c6d1aa885c4765ec17caeee6173e8414f0f0c..018236d7ee1dfe657b3fa7bf32fb41d98ae4a850 100644 (file)
@@ -202,6 +202,17 @@ public class NrpDao  {
         tx.delete(LogicalDatastoreType.OPERATIONAL, nodeIdent);
     }
 
+    public List<ConnectivityService> getConnectivityServiceList() {
+        try {
+            return rtx.read(LogicalDatastoreType.OPERATIONAL,
+                    ctx().augmentation(org.opendaylight.yang.gen.v1.urn.mef.yang.tapiconnectivity.rev170531.Context1.class))
+                    .checkedGet().orNull().getConnectivityService();
+        } catch (ReadFailedException e) {
+            log.warn("reading connectivity services failed", e);
+            return null;
+        }
+    }
+
     public ConnectivityService getConnectivityService(UniversalId id) {
         try {
             return rtx.read(LogicalDatastoreType.OPERATIONAL, ctx().augmentation(org.opendaylight.yang.gen.v1.urn.mef.yang.tapiconnectivity.rev170531.Context1.class).child(ConnectivityService.class, new ConnectivityServiceKey(id)))
index 770655c0fe9bc47bb5eb8c1907369b008a9f6363..8c0d0316f1d7e36d92bd14bcaa1707367e141873 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.unimgr.mef.nrp.api.ActivationDriver;
 import org.opendaylight.unimgr.mef.nrp.api.EndPoint;
+import org.opendaylight.unimgr.mef.nrp.api.FailureResult;
 import org.opendaylight.unimgr.mef.nrp.api.RequestValidator;
 import org.opendaylight.unimgr.mef.nrp.api.Subrequrest;
 import org.opendaylight.unimgr.mef.nrp.api.TapiConstants;
@@ -123,7 +124,7 @@ class CreateConnectivityAction implements Callable<RpcResult<CreateConnectivityS
         }
     }
 
-    private ActivationTransaction prepareTransaction(String serviceId) {
+    private ActivationTransaction prepareTransaction(String serviceId) throws FailureResult {
         log.debug("decompose request");
         decomposedRequest = service.getDecomposer().decompose(endpoints, null);
 
diff --git a/impl/src/main/java/org/opendaylight/unimgr/mef/nrp/impl/connectivityservice/ListConnectivityAction.java b/impl/src/main/java/org/opendaylight/unimgr/mef/nrp/impl/connectivityservice/ListConnectivityAction.java
new file mode 100644 (file)
index 0000000..f203811
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2017 Cisco Systems 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.unimgr.mef.nrp.impl.connectivityservice;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+
+import org.opendaylight.unimgr.mef.nrp.common.NrpDao;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.tapiconnectivity.rev170531.GetConnectivityServiceListOutput;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.tapiconnectivity.rev170531.GetConnectivityServiceListOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.tapiconnectivity.rev170531.connectivity.context.g.ConnectivityService;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.tapiconnectivity.rev170531.get.connectivity.service.list.output.Service;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.tapiconnectivity.rev170531.get.connectivity.service.list.output.ServiceBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
+public class ListConnectivityAction implements Callable<RpcResult<GetConnectivityServiceListOutput>> {
+
+    private final TapiConnectivityServiceImpl service;
+
+    public ListConnectivityAction(TapiConnectivityServiceImpl service) {
+        Objects.requireNonNull(service);
+        this.service = service;
+    }
+
+    @Override
+    public RpcResult<GetConnectivityServiceListOutput> call() throws Exception {
+        List<Service> services = new ArrayList<Service>();
+
+        NrpDao nrpDao = new NrpDao(service.getBroker().newReadOnlyTransaction());
+        List<ConnectivityService> connectivityServices = nrpDao.getConnectivityServiceList();
+        if (connectivityServices != null) {
+            for (ConnectivityService cs : connectivityServices) {
+                services.add(new ServiceBuilder(cs).build());
+            }
+        }
+
+        return RpcResultBuilder.success(
+                new GetConnectivityServiceListOutputBuilder()
+                .setService(services)).build();
+    }
+}
index 138efceb83f3e9218e1bc6f984133c3aeb72b4c5..def3f1859bed1ddd0defacb9752d1c47b42c307d 100644 (file)
@@ -96,7 +96,7 @@ public class TapiConnectivityServiceImpl implements TapiConnectivityService, Aut
 
     @Override
     public Future<RpcResult<GetConnectivityServiceListOutput>> getConnectivityServiceList() {
-        return null;
+        return executor.submit(new ListConnectivityAction(this));
     }
 
     @Override
index 05401292fc8195b74f22eccee490859163254b0f..1ae3f26df65ee88d422d4608b89b3e2addcbd415 100644 (file)
@@ -8,16 +8,17 @@
 
 package org.opendaylight.unimgr.mef.nrp.impl.decomposer;
 
+import java.util.List;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.unimgr.mef.nrp.api.Constraints;
 import org.opendaylight.unimgr.mef.nrp.api.EndPoint;
+import org.opendaylight.unimgr.mef.nrp.api.FailureResult;
 import org.opendaylight.unimgr.mef.nrp.api.RequestDecomposer;
 import org.opendaylight.unimgr.mef.nrp.api.Subrequrest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
-
 /**
  * Basic graph based request decomposer
  * @author bartosz.michalik@amartus.com
@@ -40,7 +41,7 @@ public class BasicDecomposer implements RequestDecomposer {
      * @return
      */
     @Override
-    public List<Subrequrest> decompose(List<EndPoint> endpoints, Constraints constraint) {
+    public List<Subrequrest> decompose(List<EndPoint> endpoints, Constraints constraint) throws FailureResult {
         return new DecompositionAction(endpoints, broker).decompose();
     }
 
index 01abfba896ae4d3c888af80b7a3af7c04f665932..d4a8137f7d4d4e768490dfcaaaf1002637e99066 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.unimgr.mef.nrp.api.EndPoint;
+import org.opendaylight.unimgr.mef.nrp.api.FailureResult;
 import org.opendaylight.unimgr.mef.nrp.api.Subrequrest;
 import org.opendaylight.unimgr.mef.nrp.api.TapiConstants;
 import org.opendaylight.unimgr.mef.nrp.common.NrpDao;
@@ -51,7 +52,7 @@ public class DecompositionAction {
         this.broker = broker;
     }
 
-    List<Subrequrest> decompose() {
+    List<Subrequrest> decompose() throws FailureResult {
         Graph<Vertex, DefaultEdge> graph = prepareData();
 
         List<Vertex> vertexes = endpoints.stream().map(e -> sipToNep.get(e.getEndpoint().getServiceInterfacePoint())).collect(Collectors.toList());
@@ -90,11 +91,13 @@ public class DecompositionAction {
         }
     }
 
-    protected Graph<Vertex, DefaultEdge> prepareData() {
+    protected Graph<Vertex, DefaultEdge> prepareData() throws FailureResult {
         ReadWriteTransaction tx = broker.newReadWriteTransaction();
         try {
             Topology topo = new NrpDao(tx).getTopology(TapiConstants.PRESTO_SYSTEM_TOPO);
-
+            if (topo.getNode() == null) {
+                throw new FailureResult("There are no nodes in {0} topology", TapiConstants.PRESTO_SYSTEM_TOPO);
+            }
 
             Graph<Vertex, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
             topo.getNode().stream().map(this::nodeToGraph).forEach(vs -> {
@@ -114,11 +117,9 @@ public class DecompositionAction {
                 });
             }
 
-
             return graph;
         } catch (ReadFailedException e) {
-            log.warn("Cannot read {} topology", TapiConstants.PRESTO_SYSTEM_TOPO);
-            return null;
+            throw new FailureResult("Cannot read {0} topology", TapiConstants.PRESTO_SYSTEM_TOPO);
         }
     }
 
index 0b8d5ddf0963216836217384b626c4795a764f48..3782a1feb3c92131bdd6db8c1be89692f6cc5f34 100644 (file)
@@ -16,8 +16,11 @@ import java.util.Arrays;
 import java.util.List;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.unimgr.mef.nrp.api.FailureResult;
 import org.opendaylight.unimgr.mef.nrp.api.Subrequrest;
 import org.opendaylight.unimgr.mef.nrp.impl.decomposer.BasicDecomposer;
 import org.opendaylight.yang.gen.v1.urn.mef.yang.tapicommon.rev170531.OperationalState;
@@ -37,8 +40,17 @@ public class BasicDecomposerTest extends AbstractTestWithTopo {
 
     }
 
+    @Rule
+    public ExpectedException expected = ExpectedException.none();
+
+    @Test()
+    public void emptyNodeInventoryTest() throws FailureResult {
+        expected.expect(FailureResult.class);
+        decomposer.decompose(Arrays.asList(ep("n1:1"), ep("n1:2")), null);
+    }
+
     @Test
-    public void singleNodeTest() throws OperationFailedException {
+    public void singleNodeTest() throws FailureResult, OperationFailedException {
         //having
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
         n(tx, "n1", "n1:1", "n1:2", "n1:3");
@@ -51,7 +63,7 @@ public class BasicDecomposerTest extends AbstractTestWithTopo {
     }
 
     @Test
-    public void noPathTest() throws OperationFailedException {
+    public void noPathTest() throws FailureResult, OperationFailedException {
         //having
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
         n(tx, "n1", "n1:1", "n1:2", "n1:3");
@@ -63,7 +75,7 @@ public class BasicDecomposerTest extends AbstractTestWithTopo {
     }
 
     @Test
-    public void twoNodesTest() throws OperationFailedException {
+    public void twoNodesTest() throws FailureResult, OperationFailedException {
         //having
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
         n(tx, "n1", "n1:1", "n1:2", "n1:3");
@@ -79,7 +91,7 @@ public class BasicDecomposerTest extends AbstractTestWithTopo {
     }
 
     @Test
-    public void threeNodesTest() throws OperationFailedException {
+    public void threeNodesTest() throws FailureResult, OperationFailedException {
         //having
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
         n(tx, "n1", "n1:1", "n1:2", "n1:3");
@@ -95,7 +107,7 @@ public class BasicDecomposerTest extends AbstractTestWithTopo {
     }
 
     @Test
-    public void threeNodesDisabledLinkTest() throws OperationFailedException {
+    public void threeNodesDisabledLinkTest() throws FailureResult, OperationFailedException {
         //having
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
         n(tx, "n1", "n1:1", "n1:2", "n1:3");
index acd3643396bc5085da0b319bcc08c92de5bf6f52..d5a7b6bf33b8626c44f6093226ed153b803bd17f 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFaile
 import org.opendaylight.unimgr.mef.nrp.api.ActivationDriver;
 import org.opendaylight.unimgr.mef.nrp.api.ActivationDriverRepoService;
 import org.opendaylight.unimgr.mef.nrp.api.Constraints;
+import org.opendaylight.unimgr.mef.nrp.api.FailureResult;
 import org.opendaylight.unimgr.mef.nrp.api.RequestDecomposer;
 import org.opendaylight.unimgr.mef.nrp.api.RequestValidator;
 import org.opendaylight.unimgr.mef.nrp.api.Subrequrest;
@@ -189,11 +190,14 @@ public class TapiConnectivityServiceImplTest {
 
 
     private void configureDecomposerAnswer(Function<List<org.opendaylight.unimgr.mef.nrp.api.EndPoint>, List<Subrequrest>> resp) {
+        try {
         when(decomposer.decompose(any(), any(Constraints.class)))
                 .thenAnswer(a -> {
                     List<org.opendaylight.unimgr.mef.nrp.api.EndPoint> eps = a.getArgumentAt(0, List.class);
                     return resp.apply(eps);
                 });
+        } catch (FailureResult f) {
+        }
     }
 
     private CreateConnectivityServiceInput input(int count) {