X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=transportpce.git;a=blobdiff_plain;f=tapi%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Ftapi%2Futils%2FTopologyDataUtils.java;h=2d669c1c3cf4476864cdeff8ba32cff859492a9e;hp=923fe8dc64065d3ba4f26c11897aee1acb3476d7;hb=1badcea7eeb5bd7066749900658c06b027c75745;hpb=92e2991cd0003f4592d12f78b20822642362bb5f diff --git a/tapi/src/test/java/org/opendaylight/transportpce/tapi/utils/TopologyDataUtils.java b/tapi/src/test/java/org/opendaylight/transportpce/tapi/utils/TopologyDataUtils.java index 923fe8dc6..2d669c1c3 100644 --- a/tapi/src/test/java/org/opendaylight/transportpce/tapi/utils/TopologyDataUtils.java +++ b/tapi/src/test/java/org/opendaylight/transportpce/tapi/utils/TopologyDataUtils.java @@ -7,18 +7,20 @@ */ package org.opendaylight.transportpce.tapi.utils; -import edu.umd.cs.findbugs.annotations.NonNull; - +import com.google.common.util.concurrent.FluentFuture; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Optional; +import java.util.concurrent.ExecutionException; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.transportpce.common.DataStoreContext; -import org.opendaylight.transportpce.common.converter.XMLDataObjectConverter; +import org.opendaylight.transportpce.test.DataStoreContext; +import org.opendaylight.transportpce.test.converter.XMLDataObjectConverter; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200827.Network; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInputBuilder; @@ -31,20 +33,21 @@ import org.slf4j.LoggerFactory; public final class TopologyDataUtils { private static final Logger LOG = LoggerFactory.getLogger(TopologyDataUtils.class); - private static final String TOPOLOGY_FILE = - "src/test/resources/openroadm-topology2.xml"; - private static final String PORTMAPPING_FILE = - "src/test/resources/portmapping-example.xml"; + public static final String OPENROADM_TOPOLOGY_FILE = "src/test/resources/openroadm-topology2.xml"; + public static final String OTN_TOPOLOGY_FILE = "src/test/resources/otn-topology.xml"; + public static final String OTN_TOPOLOGY_WITH_OTN_LINKS_FILE = "src/test/resources/otn-topology-with-otn-links.xml"; + public static final String PORTMAPPING_FILE = "src/test/resources/portmapping-example.xml"; - public static GetTopologyDetailsInput buildGetTopologyDetailsInput() { + public static GetTopologyDetailsInput buildGetTopologyDetailsInput(String topoName) { GetTopologyDetailsInputBuilder builtInput = new GetTopologyDetailsInputBuilder(); - builtInput.setTopologyIdOrName("topo1"); + builtInput.setTopologyIdOrName(topoName); return builtInput.build(); } - public static void writeTopologyFromFileToDatastore(DataStoreContext dataStoreContextUtil) { - Networks result = null; - File topoFile = new File(TOPOLOGY_FILE); + public static void writeTopologyFromFileToDatastore(DataStoreContext dataStoreContextUtil, String file, + InstanceIdentifier ii) throws InterruptedException, ExecutionException { + Networks networks = null; + File topoFile = new File(file); if (topoFile.exists()) { String fileName = topoFile.getName(); InputStream targetStream; @@ -62,7 +65,7 @@ public final class TopologyDataUtils { if (!dataObject.isPresent()) { throw new IllegalStateException("Could not transform normalized nodes into data object"); } else { - result = (Networks) dataObject.get(); + networks = (Networks) dataObject.get(); } } catch (FileNotFoundException e) { LOG.error("File not found : {} at {}", e.getMessage(), e.getLocalizedMessage()); @@ -70,23 +73,23 @@ public final class TopologyDataUtils { } else { LOG.error("xml file {} not found at {}", topoFile.getName(), topoFile.getAbsolutePath()); } - LOG.info("Storing openroadm-topology in datastore"); - InstanceIdentifier ietfNetworksIID = InstanceIdentifier.builder(Networks.class).build(); - writeTransaction(dataStoreContextUtil.getDataBroker(), ietfNetworksIID, result); - LOG.info("openroadm-topology stored with success in datastore"); + FluentFuture commitFuture = writeTransaction(dataStoreContextUtil.getDataBroker(), ii, + networks.nonnullNetwork().values().stream().findFirst().get()); + commitFuture.get(); + LOG.info("extraction from {} stored with success in datastore", topoFile.getName()); } - private static boolean writeTransaction(DataBroker dataBroker, InstanceIdentifier instanceIdentifier, - DataObject object) { - @NonNull + @SuppressWarnings("unchecked") + private static FluentFuture writeTransaction(DataBroker dataBroker, + InstanceIdentifier instanceIdentifier, DataObject object) { WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); transaction.put(LogicalDatastoreType.CONFIGURATION, instanceIdentifier, object); - transaction.commit(); - return true; + return transaction.commit(); } - public static void writePortmappingFromFileToDatastore(DataStoreContext dataStoreContextUtil) { - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.Network result = null; + public static void writePortmappingFromFileToDatastore(DataStoreContext dataStoreContextUtil) + throws InterruptedException, ExecutionException { + Network result = null; File portmappingFile = new File(PORTMAPPING_FILE); if (portmappingFile.exists()) { String fileName = portmappingFile.getName(); @@ -101,13 +104,11 @@ public final class TopologyDataUtils { "Could not transform the input %s into normalized nodes", fileName)); } Optional dataObject = XMLDataObjectConverter.createWithDataStoreUtil(dataStoreContextUtil) - .getDataObject(transformIntoNormalizedNode.get(), org.opendaylight.yang.gen.v1.http.org.opendaylight - .transportpce.portmapping.rev190702.Network.QNAME); + .getDataObject(transformIntoNormalizedNode.get(), Network.QNAME); if (!dataObject.isPresent()) { throw new IllegalStateException("Could not transform normalized nodes into data object"); } else { - result = (org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702 - .Network) dataObject.get(); + result = (Network) dataObject.get(); } } catch (FileNotFoundException e) { LOG.error("File not found : {} at {}", e.getMessage(), e.getLocalizedMessage()); @@ -115,15 +116,14 @@ public final class TopologyDataUtils { } else { LOG.error("xml file {} not found at {}", portmappingFile.getName(), portmappingFile.getAbsolutePath()); } - InstanceIdentifier portmappingIID = InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.http.org.opendaylight - .transportpce.portmapping.rev190702.Network.class).build(); - writeTransaction(dataStoreContextUtil.getDataBroker(), portmappingIID, result); + InstanceIdentifier portmappingIID = InstanceIdentifier.builder(Network.class).build(); + FluentFuture writeTransaction = writeTransaction(dataStoreContextUtil.getDataBroker(), + portmappingIID, result); + writeTransaction.get(); LOG.info("portmapping-example stored with success in datastore"); } private TopologyDataUtils() { - } }