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=36faf86e0f5c852171ce31e85e408b8bd4694356;hb=9e620f8a99f2efc391b580fec98202a812f43ed6;hp=ab127889f9d2834c15dcc08d379bc07343e729a8;hpb=ae67bdaafc371d7937f75dde8db77dadf037aa5b;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 ab127889f..36faf86e0 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,13 +8,7 @@ package org.opendaylight.transportpce.pce.gnpy; -import com.google.gson.stream.JsonReader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.math.BigDecimal; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -22,11 +16,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Optional; import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; -import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices; import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.Result; import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.explicit.route.hop.type.NumUnnumHop; import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathMetric; @@ -47,21 +37,7 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -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; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; -import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,39 +53,10 @@ public class GnpyResult { private static final Logger LOG = LoggerFactory.getLogger(GnpyResult.class); private Response response = null; private Map mapNodeRefIp = new HashMap<>(); - private EffectiveModelContext effectiveModelcontext; - public GnpyResult(String gnpyResponseString, GnpyTopoImpl gnpyTopo, - BindingDOMCodecServices bindingDOMCodecServices) throws GnpyException { + public GnpyResult(Result result, GnpyTopoImpl gnpyTopo) throws GnpyException { this.mapNodeRefIp = gnpyTopo.getMapNodeRefIp(); - effectiveModelcontext = bindingDOMCodecServices.getRuntimeContext().getEffectiveModelContext(); - - // Create the data object - QName pathQname = QName.create("gnpy:path", "2020-09-09", "result"); - LOG.debug("the Qname is {} / namesapce {} ; module {}; ", pathQname, pathQname.getNamespace(), - pathQname.getModule()); - YangInstanceIdentifier yangId = YangInstanceIdentifier.of(pathQname); - DataObject dataObject = null; - - // Create the object response - InputStream streamGnpyRespnse = new ByteArrayInputStream(gnpyResponseString.getBytes(StandardCharsets.UTF_8)); - InputStreamReader gnpyResultReader = new InputStreamReader(streamGnpyRespnse,StandardCharsets.UTF_8); - JsonReader jsonReader = new JsonReader(gnpyResultReader); - Optional> transformIntoNormalizedNode = parseInputJSON(jsonReader, - Result.class); - if (!transformIntoNormalizedNode.isPresent()) { - throw new GnpyException("In GnpyResult: the Normalized Node is not present"); - } - NormalizedNode normalizedNode = transformIntoNormalizedNode.get(); - Entry, DataObject> fromNormalizedNode = bindingDOMCodecServices - .fromNormalizedNode(yangId, normalizedNode); - - if (fromNormalizedNode != null) { - dataObject = fromNormalizedNode.getValue(); - } else { - throw new GnpyException("In GnpyResult: the codec registry from the normalized node is null"); - } - List responses = new ArrayList<>(((Result) dataObject).nonnullResponse().values()); + List responses = new ArrayList<>(result.nonnullResponse().values()); if (responses.isEmpty()) { throw new GnpyException("In GnpyResult: the response from GNpy is null!"); } @@ -196,7 +143,7 @@ public class GnpyResult { counter++; } } catch (IllegalArgumentException e) { - LOG.debug(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp); + LOG.error(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp, e); } } } @@ -220,67 +167,6 @@ public class GnpyResult { return null; } - /** - * Parses the input json with concrete implementation of {@link JsonParserStream}. - * @param reader of the given JSON - * @throws Exception exception - */ - private Optional> parseInputJSON(JsonReader reader, - Class objectClass) { - NormalizedNodeResult result = new NormalizedNodeResult(); - try (NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - JsonParserStream jsonParser = JsonParserStream.create(streamWriter, - JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(effectiveModelcontext), - effectiveModelcontext);) { - jsonParser.parse(reader); - } catch (IOException e) { - LOG.warn("GNPy: exception {} occured during parsing Json input stream", e.getMessage()); - return Optional.empty(); - } - return Optional.ofNullable(result.getResult()); - } - - - /** - * Transforms the given input {@link NormalizedNode} into the given {@link DataObject}. - * - * @param a generic - * @param normalizedNode a non null representation of the normalizedNode - * @param rootNode root node - * @param codecRegistry codec registry - * @return value of the binding Node Entry - */ - @SuppressWarnings("unchecked") - public Optional getDataObject(@Nonnull NormalizedNode normalizedNode, - @Nonnull QName rootNode, BindingNormalizedNodeSerializer codecRegistry) { - if (normalizedNode != null) { - LOG.debug("GNPy: The codecRegistry is {}", codecRegistry); - } else { - LOG.warn("GNPy: The codecRegistry is null"); - } - //Preconditions.checkNotNull(normalizedNode); - if (normalizedNode instanceof ContainerNode) { - YangInstanceIdentifier.PathArgument directChildIdentifier = YangInstanceIdentifier.of(rootNode) - .getLastPathArgument(); - Optional> directChild = NormalizedNodes.getDirectChild(normalizedNode, - directChildIdentifier); - if (!directChild.isPresent()) { - throw new IllegalStateException(String.format("Could not get the direct child of %s", rootNode)); - } - normalizedNode = directChild.get(); - LOG.debug("GNPy: the normalized node is {}", normalizedNode.getNodeType()); - } - YangInstanceIdentifier rootNodeYangInstanceIdentifier = YangInstanceIdentifier.of(rootNode); - LOG.debug("GNPy: the root Node Yang Instance Identifier is {}", rootNodeYangInstanceIdentifier); - Map.Entry bindingNodeEntry = codecRegistry.fromNormalizedNode(rootNodeYangInstanceIdentifier, - normalizedNode); - if (bindingNodeEntry == null) { - LOG.debug("The binding Node Entry is null"); - return Optional.empty(); - } - return Optional.ofNullable((T) bindingNodeEntry.getValue()); - } - public Response getResponse() { return response; }