X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fgnpy%2FGnpyResult.java;h=e0775608113b20291ad534e8a621db20eebcafed;hb=refs%2Fchanges%2F94%2F92194%2F13;hp=829c50df41cefbecb9b3a40dee73ebeac1f01715;hpb=e6f1b3acce76396e50731b0c97b07c36dca7224d;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java index 829c50df4..e07756081 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java @@ -8,9 +8,7 @@ package org.opendaylight.transportpce.pce.gnpy; -//import com.google.common.base.Preconditions; import com.google.gson.stream.JsonReader; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -18,6 +16,7 @@ import java.io.InputStreamReader; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -25,13 +24,11 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; - import javax.annotation.Nonnull; - +import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers; +import org.opendaylight.mdsal.binding.dom.adapter.AdapterContext; +import org.opendaylight.mdsal.binding.dom.adapter.ConstantAdapterContext; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; -import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; -import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext; import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; import org.opendaylight.yang.gen.v1.gnpy.path.rev200202.Result; import org.opendaylight.yang.gen.v1.gnpy.path.rev200202.explicit.route.hop.type.NumUnnumHop; @@ -56,6 +53,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @@ -82,21 +80,17 @@ public class GnpyResult { private static final Logger LOG = LoggerFactory.getLogger(GnpyResult.class); private Response response = null; private Map mapNodeRefIp = new HashMap<>(); + private final AdapterContext adapterContext = new ConstantAdapterContext(); public GnpyResult(String gnpyResponseString, GnpyTopoImpl gnpyTopo) throws GnpyException, Exception { this.mapNodeRefIp = gnpyTopo.getMapNodeRefIp(); // Create the schema context - final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create(); - Iterable moduleInfos; - - moduleInfos = Collections.singleton(BindingReflections.getModuleInfo(Result.class)); - moduleContext.addModuleInfos(moduleInfos); - SchemaContext schemaContext = moduleContext.tryToCreateSchemaContext().get(); + Collection moduleInfos = Collections.singleton(BindingReflections + .getModuleInfo(Result.class)); + BindingRuntimeHelpers.createEffectiveModel(moduleInfos); // Create the binding binding normalized node codec registry - BindingRuntimeContext bindingRuntimeContext = BindingRuntimeContext.create(moduleContext, schemaContext); - final BindingNormalizedNodeCodecRegistry codecRegistry = - new BindingNormalizedNodeCodecRegistry(bindingRuntimeContext); + final BindingNormalizedNodeSerializer codecRegistry = adapterContext.currentSerializer(); // Create the data object QName pathQname = QName.create("gnpy:path", "2020-02-02", "result"); @@ -121,9 +115,8 @@ public class GnpyResult { } else { throw new GnpyException("In GnpyResult: the codec registry from the normalized node is null"); } - List responses = null; - responses = ((Result) dataObject).getResponse(); - if (responses == null) { + List responses = new ArrayList<>(((Result) dataObject).nonnullResponse().values()); + if (responses.isEmpty()) { throw new GnpyException("In GnpyResult: the response from GNpy is null!"); } LOG.info("The response id is {}; ", responses.get(0).getResponseId()); @@ -154,7 +147,8 @@ public class GnpyResult { if (((noPathType.equals("NO_FEASIBLE_BAUDRATE_WITH_SPACING")) && (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE")) && (noPathType.equals("NO_SPECTRUM")))) { - List pathMetricList = noPathCase.getNoPath().getPathProperties().getPathMetric(); + Collection pathMetricList = noPathCase.getNoPath() + .getPathProperties().nonnullPathMetric().values(); LOG.info("GNPy : path is not feasible : {}", noPathType); for (PathMetric pathMetric : pathMetricList) { String metricType = pathMetric.getMetricType().getSimpleName(); @@ -165,7 +159,8 @@ public class GnpyResult { } else if (response.getResponseType() instanceof PathCase) { LOG.info("GNPy : path is feasible"); PathCase pathCase = (PathCase) response.getResponseType(); - List pathMetricList = pathCase.getPathProperties().getPathMetric(); + Collection pathMetricList = pathCase + .getPathProperties().nonnullPathMetric().values(); // Path metrics for (PathMetric pathMetric : pathMetricList) { String metricType = pathMetric.getMetricType().getSimpleName(); @@ -200,7 +195,8 @@ public class GnpyResult { .ordered.constraints.sp.hop.type.hop.type.Node node = new NodeBuilder().setNodeId(nodeId) .build(); HopType hopType = new HopTypeBuilder().setHopType(node).build(); - OrderedHops orderedHops = new OrderedHopsBuilder().setHopNumber(counter).setHopType(hopType) + OrderedHops orderedHops = new OrderedHopsBuilder() + .setHopNumber(Uint16.valueOf(counter)).setHopType(hopType) .build(); orderedHopsList.add(orderedHops); counter++; @@ -249,14 +245,9 @@ public class GnpyResult { } private SchemaContext getSchemaContext(Class objectClass) throws GnpyException, Exception { - - final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create(); - Iterable moduleInfos; - SchemaContext schemaContext = null; - moduleInfos = Collections.singleton(BindingReflections.getModuleInfo(objectClass)); - moduleContext.addModuleInfos(moduleInfos); - schemaContext = moduleContext.tryToCreateSchemaContext().get(); - return schemaContext; + Collection moduleInfos = Collections.singleton(BindingReflections + .getModuleInfo(objectClass)); + return BindingRuntimeHelpers.createEffectiveModel(moduleInfos); } /**