pce(gnpy) for Sulfur 00/101300/18
authorwede7391 <emmanuelle.delfour@orange.com>
Wed, 25 May 2022 20:26:53 +0000 (22:26 +0200)
committermanuedelf <emmanuelle.delfour@orange.com>
Fri, 17 Jun 2022 10:13:22 +0000 (12:13 +0200)
- replace jackson module with MessageBodyWriter and MessageBodyReader
 to avoid intermediate String (fix scientific notation for decimal)
- add createDataObjectFromInputStream to JsonConverter
- put decimal value in gnpy test data

JIRA: TRNSPRTPCE-639
Signed-off-by: wede7391 <emmanuelle.delfour@orange.com>
Change-Id: I4399bf1004709860796884e3c990c8466cf57ca8

15 files changed:
common/src/main/java/org/opendaylight/transportpce/common/converter/JsonStringConverter.java [changed mode: 0644->0755]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/GnpyApiModule.java [deleted file]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/GnpyConsumerImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/JsonConfigurator.java [deleted file]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/RequestMessageBodyWriter.java [new file with mode: 0644]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/RequestSerializer.java [deleted file]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/ResultDeserializer.java [deleted file]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/ResultMessageBodyReader.java [new file with mode: 0644]
pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java
pce/src/test/java/org/opendaylight/transportpce/pce/gnpy/GnpyUtilitiesImplTest.java
pce/src/test/resources/gnpy/gnpy_request.json
pce/src/test/resources/gnpy/gnpy_result_no_path.json
pce/src/test/resources/gnpy/gnpy_result_with_path.json

old mode 100644 (file)
new mode 100755 (executable)
index f29e660..52f8e4a
@@ -13,9 +13,13 @@ import com.google.gson.JsonParser;
 import com.google.gson.stream.JsonReader;
 import com.google.gson.stream.JsonWriter;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -63,7 +67,7 @@ public class JsonStringConverter<T extends DataObject> {
         JSONCodecFactory codecFactory = supplier
                 .getShared(bindingDOMCodecServices.getRuntimeContext().getEffectiveModelContext());
         try (Writer writer = new StringWriter();
-                JsonWriter jsonWriter = JsonWriterFactory.createJsonWriter(writer, 4);) {
+                JsonWriter jsonWriter = JsonWriterFactory.createJsonWriter(writer, 4)) {
             EffectiveStatementInference rootNode = SchemaInferenceStack
                 .of(bindingDOMCodecServices.getRuntimeContext().getEffectiveModelContext())
                 .toInference();
@@ -93,17 +97,36 @@ public class JsonStringConverter<T extends DataObject> {
     @SuppressWarnings("unchecked")
     public T createDataObjectFromJsonString(YangInstanceIdentifier path, String jsonString,
             JSONCodecFactorySupplier supplier) {
-        JsonReader reader = new JsonReader(new StringReader(jsonString));
+        return createDataObjectFromReader(path, new StringReader(jsonString), supplier);
+    }
+
+    public T createDataObjectFromInputStream(YangInstanceIdentifier path, InputStream jsonStream,
+                                            JSONCodecFactorySupplier supplier) {
+        return createDataObjectFromReader(path, new InputStreamReader(jsonStream, StandardCharsets.UTF_8), supplier);
+    }
+
+    /**
+     * Create a dataObject of T type from Reader.
+     * @param path YangInstanceIdentifier
+     * @param inputReader Reader (could be all class implementing Reader) containing Json data.
+     * @param supplier RFC7951 or DRAFT_LHOTKA_NETMOD_YANG_JSON_02
+     * @return the created object.
+     */
+    private T createDataObjectFromReader(YangInstanceIdentifier path, Reader inputReader,
+                                         JSONCodecFactorySupplier supplier) {
+
         NormalizedNodeResult result = new NormalizedNodeResult();
-        try (NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-                JsonParserStream jsonParser = JsonParserStream
-                    .create(
-                        streamWriter,
-                        supplier.getShared(bindingDOMCodecServices.getRuntimeContext().getEffectiveModelContext()))) {
+        try (JsonReader reader = new JsonReader(inputReader);
+             NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+             JsonParserStream jsonParser = JsonParserStream
+                     .create(
+                             streamWriter,
+                             supplier.getShared(bindingDOMCodecServices
+                                     .getRuntimeContext().getEffectiveModelContext()))) {
             jsonParser.parse(reader);
             return (T) bindingDOMCodecServices.fromNormalizedNode(path, result.getResult()).getValue();
         } catch (IOException e) {
-            LOG.warn("An error occured during parsing Json input stream", e);
+            LOG.warn("An error occured during parsing input reader", e);
             return null;
         }
     }
index d8d7bd4dd226d620fbb94ba235d03245e4bf8bd7..02eade3f5dd2258a89ef13bfcc48d6f41dafc099 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.transportpce.pce.gnpy;
 import com.google.common.collect.HashBasedTable;
 import com.google.common.collect.Table;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -373,7 +374,8 @@ public class GnpyServiceImpl {
                 .setTechnology("flexi-grid").setTrxType("OpenROADM MSA ver. 5.0")
                 .setTrxMode(TRX_MODE_TABLE.get(Uint32.valueOf(rate), spacing))
                 .setOutputPower(Decimal64.valueOf(GridUtils.convertDbmW(GridConstant.OUTPUT_POWER_100GB_DBM
-                        + 10 * Math.log10(mvalue / (double)GridConstant.NB_SLOTS_100G))))
+                        + 10 * Math.log10(mvalue / (double)GridConstant.NB_SLOTS_100G))
+                        .setScale(6, RoundingMode.CEILING)))
                 .setEffectiveFreqSlot(Map.of(effectiveFreqSlot.key(), effectiveFreqSlot))
                 .setSpacing(Decimal64.valueOf(spacing.multiply(BigDecimal.valueOf(1e9))))
                 .build();
index 07528bfaba547900adfb63bba8a4e2a56ba5bec3..5687e4b7365de49e8ad75f0634b12a8747ff3528 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.transportpce.pce.gnpy;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -347,7 +348,7 @@ public class GnpyTopoImpl {
             .setLength(Decimal64.valueOf(String.valueOf(length)))
             .setLengthUnits(Km.class)
             .setAttIn(Decimal64.valueOf(String.valueOf(attIn)))
-            .setLossCoef(Decimal64.valueOf(String.valueOf(lossCoef)))
+            .setLossCoef(Decimal64.valueOf(String.valueOf(lossCoef)).scaleTo(5, RoundingMode.CEILING))
             .setConIn(Decimal64.valueOf(String.valueOf(connIn)))
             .setConOut(Decimal64.valueOf(String.valueOf(connOut)))
             .build();
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/GnpyApiModule.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/GnpyApiModule.java
deleted file mode 100644 (file)
index f3f7664..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright © 2021 Orange, 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.transportpce.pce.gnpy.consumer;
-
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.datatype.jsr310.PackageVersion;
-import org.opendaylight.transportpce.common.converter.JsonStringConverter;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
-
-
-
-//This class is a temporary workaround while waiting jackson
-//support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
-public class GnpyApiModule extends SimpleModule {
-
-    private static final long serialVersionUID = 1L;
-
-    public GnpyApiModule(JsonStringConverter<Request> requestConverter, JsonStringConverter<Result> resultConverter) {
-        super(PackageVersion.VERSION);
-        addSerializer(Request.class, new RequestSerializer(requestConverter));
-        addDeserializer(Result.class, new ResultDeserializer(resultConverter));
-    }
-}
index bb3f53b83f9d1c85e0ef38abc8c86d05b0bc7ba9..b0854e02b128628d5527e67a2276ed76c00aa2cd 100644 (file)
@@ -25,21 +25,20 @@ import org.slf4j.LoggerFactory;
 public class GnpyConsumerImpl implements GnpyConsumer {
     private static final Logger LOG = LoggerFactory.getLogger(GnpyConsumerImpl.class);
 
-    private GnpyResource api;
-    JsonStringConverter<Request> gnpyRequestConverter;
-    JsonStringConverter<Result> resultConverter;
+    private final GnpyResource api;
 
     public GnpyConsumerImpl(String baseUrl, String username, String password,
             BindingDOMCodecServices bindingDOMCodecServices) {
-        gnpyRequestConverter = new JsonStringConverter<>(bindingDOMCodecServices);
-        resultConverter = new JsonStringConverter<>(bindingDOMCodecServices);
+        JsonStringConverter<Request> gnpyRequestConverter = new JsonStringConverter<>(bindingDOMCodecServices);
+        JsonStringConverter<Result> resultConverter = new JsonStringConverter<>(bindingDOMCodecServices);
 
-        JsonConfigurator jsonConfigurator = new JsonConfigurator(gnpyRequestConverter, resultConverter);
         Client client = ClientBuilder.newClient();
         HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basic(username, password);
         client.register(authFeature);
         client.register(new LoggingFeature(java.util.logging.Logger.getLogger(this.getClass().getName())))
-            .register(JacksonFeature.class).register(jsonConfigurator);
+            .register(JacksonFeature.class)
+                .register(new ResultMessageBodyReader(resultConverter))
+                .register(new RequestMessageBodyWriter(gnpyRequestConverter));
         api = WebResourceFactory.newResource(GnpyResource.class, client.target(baseUrl));
     }
 
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/JsonConfigurator.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/JsonConfigurator.java
deleted file mode 100644 (file)
index 0f9c63d..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2021 Orange, 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.transportpce.pce.gnpy.consumer;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import javax.ws.rs.ext.ContextResolver;
-import org.opendaylight.transportpce.common.converter.JsonStringConverter;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
-
-public class JsonConfigurator implements ContextResolver<ObjectMapper> {
-
-    private final ObjectMapper mapper;
-
-    public JsonConfigurator(JsonStringConverter<Request> requestConverter,
-            JsonStringConverter<Result> resultConverter) {
-        mapper = new ObjectMapper();
-        mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
-        mapper.enable(SerializationFeature.INDENT_OUTPUT);
-        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
-        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-        mapper.registerModule(new GnpyApiModule(requestConverter, resultConverter));
-    }
-
-    @Override
-    public ObjectMapper getContext(Class<?> type) {
-        return mapper;
-    }
-
-}
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/RequestMessageBodyWriter.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/RequestMessageBodyWriter.java
new file mode 100644 (file)
index 0000000..6197448
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2022 Orange, 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.transportpce.pce.gnpy.consumer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import org.opendaylight.transportpce.common.converter.JsonStringConverter;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RequestMessageBodyWriter implements MessageBodyWriter<Request> {
+    private static final Logger LOG = LoggerFactory.getLogger(RequestMessageBodyWriter.class);
+    private final InstanceIdentifier<Request> idRequest = InstanceIdentifier.builder(Request.class).build();
+    private final JsonStringConverter<Request> converter;
+
+    public RequestMessageBodyWriter(JsonStringConverter<Request> converter) {
+        this.converter = converter;
+    }
+
+    @Override
+    @SuppressWarnings("java:S1872")
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return "org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request$$$codecImpl"
+                .equals(type.getName())
+                || "org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.RequestBuilder$RequestImpl"
+                        .equals(type.getName());
+    }
+
+    @Override
+    public void writeTo(Request request, Class<?> type, Type genericType, Annotation[] annotations,
+                        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
+            throws IOException, WebApplicationException {
+        // we have to use a string because GNPy does not support prefix
+        String jsonStringFromDataObject = converter
+                .createJsonStringFromDataObject(idRequest, request,
+                        JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02)
+                .replace("gnpy-network-topology:", "");
+        LOG.debug("Serialized request {}", jsonStringFromDataObject);
+        entityStream.write(jsonStringFromDataObject
+                .getBytes(StandardCharsets.UTF_8));
+    }
+}
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/RequestSerializer.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/RequestSerializer.java
deleted file mode 100644 (file)
index 4dd687c..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright © 2021 Orange, 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.transportpce.pce.gnpy.consumer;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-import java.io.IOException;
-import org.opendaylight.transportpce.common.converter.JsonStringConverter;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-//This class is a temporary workaround while waiting jackson
-//support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
-@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "temporary class")
-
-public class RequestSerializer extends StdSerializer<Request> {
-    private static final long serialVersionUID = 1L;
-    private static final Logger LOG = LoggerFactory.getLogger(RequestSerializer.class);
-    private JsonStringConverter<Request> converter;
-    private InstanceIdentifier<Request> idRequest = InstanceIdentifier.builder(Request.class).build();
-
-    public RequestSerializer(JsonStringConverter<Request> converter) {
-        super(Request.class);
-        this.converter = converter;
-    }
-
-    @Override
-    public void serialize(Request value, JsonGenerator gen, SerializerProvider provider) throws IOException {
-        String requestStr = this.converter
-                .createJsonStringFromDataObject(this.idRequest, value,
-                        JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02);
-        requestStr =  requestStr.replace("gnpy-network-topology:", "");
-        LOG.info("Serialized request {}", requestStr);
-        gen.writeRaw(requestStr);
-    }
-}
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/ResultDeserializer.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/ResultDeserializer.java
deleted file mode 100644 (file)
index bdf46a4..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright © 2021 Orange, 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.transportpce.pce.gnpy.consumer;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import java.io.IOException;
-import org.opendaylight.transportpce.common.converter.JsonStringConverter;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-//This class is a temporary workaround while waiting jackson
-//support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
-@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "temporary class")
-public class ResultDeserializer extends StdDeserializer<Result> {
-
-    private static final Logger LOG = LoggerFactory.getLogger(ResultDeserializer.class);
-    private static final long serialVersionUID = 1L;
-    private JsonStringConverter<Result> converter;
-    private YangInstanceIdentifier yangId;
-
-    public ResultDeserializer(JsonStringConverter<Result> converter) {
-        super(Result.class);
-        this.converter = converter;
-        QName pathQname = Result.QNAME;
-        LOG.info("QName of the first result class {}", pathQname);
-        yangId = YangInstanceIdentifier.of(pathQname);
-    }
-
-    @Override
-    public Result deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
-        return converter.createDataObjectFromJsonString(yangId,parser.readValueAsTree().toString(),
-            JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02);
-    }
-
-}
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/ResultMessageBodyReader.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/ResultMessageBodyReader.java
new file mode 100644 (file)
index 0000000..e1bcb18
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2022 Orange, 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.transportpce.pce.gnpy.consumer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import org.opendaylight.transportpce.common.converter.JsonStringConverter;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
+
+public class ResultMessageBodyReader implements MessageBodyReader<Result> {
+    private final JsonStringConverter<Result> converter;
+    private final YangInstanceIdentifier yangId;
+
+    public ResultMessageBodyReader(JsonStringConverter<Result> converter) {
+        QName pathQname = Result.QNAME;
+        yangId = YangInstanceIdentifier.of(pathQname);
+        this.converter = converter;
+    }
+
+    @Override
+    @SuppressWarnings("java:S1872")
+    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return "org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result"
+                .equals(type.getName());
+    }
+
+    @Override
+    public Result readFrom(Class<Result> type, Type genericType, Annotation[] annotations,
+                           MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
+            throws IOException, WebApplicationException {
+        return converter.createDataObjectFromInputStream(yangId, entityStream,
+                JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02);
+    }
+}
index ba4eee7d692ddd6b69f9f04baa2ee4345a92b152..960ae3bc1e6e407399d5aa99b40b042e11631d6a 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 import org.jgrapht.GraphPath;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.StringConstants;
@@ -202,42 +203,19 @@ public class PostAlgoPathValidator {
             pceHardConstraintsInput));
 
         // validation: check each type for each element
-        for (ResourcePair next : listToInclude) {
-            int indx = -1;
-            switch (next.getType()) {
-                case NODE:
-                    if (listOfElementsSubNode.contains(next.getName())) {
-                        indx = listOfElementsSubNode.indexOf(next.getName());
-                    }
-                    break;
-                case SRLG:
-                    if (listOfElementsSRLG.contains(next.getName())) {
-                        indx = listOfElementsSRLG.indexOf(next.getName());
-                    }
-                    break;
-                case CLLI:
-                    if (listOfElementsCLLI.contains(next.getName())) {
-                        indx = listOfElementsCLLI.indexOf(next.getName());
-                    }
-                    break;
-                default:
-                    LOG.warn(" in checkInclude vertex list unsupported resource type: [{}]", next.getType());
-            }
-
-            if (indx < 0) {
-                LOG.debug(" in checkInclude stopped : {} ", next.getName());
-                return false;
-            }
-
-            LOG.debug(" in checkInclude next found {} in {}", next.getName(), path.getVertexList());
-
-            listOfElementsSubNode.subList(0, indx).clear();
-            listOfElementsCLLI.subList(0, indx).clear();
-            listOfElementsSRLG.subList(0, indx).clear();
-        }
-
-        LOG.info(" in checkInclude passed : {} ", path.getVertexList());
-        return true;
+        List<String> listNodeToInclude = listToInclude
+                .stream().filter(rp -> PceConstraints.ResourceType.NODE.equals(rp.getType()))
+                .map(ResourcePair::getName).collect(Collectors.toList());
+        List<String> listSrlgToInclude = listToInclude
+                .stream().filter(rp -> PceConstraints.ResourceType.SRLG.equals(rp.getType()))
+                .map(ResourcePair::getName).collect(Collectors.toList());
+        List<String> listClliToInclude = listToInclude
+                .stream().filter(rp -> PceConstraints.ResourceType.CLLI.equals(rp.getType()))
+                .map(ResourcePair::getName).collect(Collectors.toList());
+
+        return listOfElementsSubNode.containsAll(listNodeToInclude)
+                && listOfElementsSRLG.containsAll(listSrlgToInclude)
+                && listOfElementsCLLI.containsAll(listClliToInclude);
     }
 
     private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
@@ -452,7 +430,7 @@ public class PostAlgoPathValidator {
                         .equals(GridConstant.SLOT_WIDTH_50))
                         && (pceNode.getCentralFreqGranularity().setScale(0, RoundingMode.CEILING)
                         .equals(GridConstant.SLOT_WIDTH_50))) {
-                    LOG.info("Node {}: version is {} with slot width granularity  {} and central "
+                    LOG.debug("Node {}: version is {} with slot width granularity  {} and central "
                             + "frequency granularity is {} -> fixed grid mode",
                         pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity(),
                         pceNode.getCentralFreqGranularity());
index 063addcbfa41c94d3b0045fcf8651d014f6959f8..4c94f0628456aa486b3e4b4cb914949c365f93c4 100644 (file)
@@ -27,7 +27,6 @@ import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -148,7 +147,6 @@ public class GnpyUtilitiesImplTest extends AbstractTest {
 
     }
 
-    @Ignore
     @Test
     public void askNewPathFromGnpyTest() throws Exception {
         gnpyUtilitiesImpl = new GnpyUtilitiesImpl(networkTransaction,
index c303ba2823b8cc2f7d52b552e2fe2d634d9458ed..64a6ebdef917ef0ad7c432ea925a9fd40972fec2 100644 (file)
                 }
               ],
               "spacing": 50000000000,
-              "path_bandwidth": 100
+              "path_bandwidth": 1000000000.0
             }
           }
         }
       ]
     }
   }
-}
\ No newline at end of file
+}
index 21983b2de9124736a28eb1550c243f7a5aad5de4..f490424dbf40feabb9648a3a0c5498124470491f 100644 (file)
@@ -29,7 +29,7 @@
                             },
                             {
                                 "metric-type": "path_bandwidth",
-                                "accumulative-value": 100
+                                "accumulative-value": 1000000000.0
                             }
                         ],
                         "path-route-objects": [
             }
         ]
     }
-}
\ No newline at end of file
+}
index 0b0918216db6bbf762eedc89c9f0794180cda722..1c9564608c0d22a3036d02525d5a5b43d2dd2e35 100644 (file)
@@ -27,7 +27,7 @@
                         },
                         {
                             "metric-type": "path_bandwidth",
-                            "accumulative-value": 100
+                            "accumulative-value": 1000000000.0
                         }
                     ],
                     "path-route-objects": [