<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <version>3.0.2</version>
<executions>
<execution>
<goals>
--- /dev/null
+/*
+ * 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));
+ }
+}
* @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;
}
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)))
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;
}
}
- private ActivationTransaction prepareTransaction(String serviceId) {
+ private ActivationTransaction prepareTransaction(String serviceId) throws FailureResult {
log.debug("decompose request");
decomposedRequest = service.getDecomposer().decompose(endpoints, null);
--- /dev/null
+/*
+ * 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();
+ }
+}
@Override
public Future<RpcResult<GetConnectivityServiceListOutput>> getConnectivityServiceList() {
- return null;
+ return executor.submit(new ListConnectivityAction(this));
}
@Override
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
* @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();
}
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;
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());
}
}
- 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 -> {
});
}
-
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);
}
}
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;
}
+ @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");
}
@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");
}
@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");
}
@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");
}
@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");
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;
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) {