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;
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;
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;
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;
private static final Logger LOG = LoggerFactory.getLogger(GnpyResult.class);
private Response response = null;
private Map<String, IpAddress> 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<? extends YangModuleInfo> moduleInfos;
-
- moduleInfos = Collections.singleton(BindingReflections.getModuleInfo(Result.class));
- moduleContext.addModuleInfos(moduleInfos);
- SchemaContext schemaContext = moduleContext.tryToCreateSchemaContext().get();
+ Collection<? extends YangModuleInfo> 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");
} else {
throw new GnpyException("In GnpyResult: the codec registry from the normalized node is null");
}
- List<Response> responses = null;
- responses = ((Result) dataObject).getResponse();
- if (responses == null) {
+ List<Response> 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());
if (((noPathType.equals("NO_FEASIBLE_BAUDRATE_WITH_SPACING"))
&& (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE"))
&& (noPathType.equals("NO_SPECTRUM")))) {
- List<PathMetric> pathMetricList = noPathCase.getNoPath().getPathProperties().getPathMetric();
+ Collection<PathMetric> pathMetricList = noPathCase.getNoPath()
+ .getPathProperties().nonnullPathMetric().values();
LOG.info("GNPy : path is not feasible : {}", noPathType);
for (PathMetric pathMetric : pathMetricList) {
String metricType = pathMetric.getMetricType().getSimpleName();
} else if (response.getResponseType() instanceof PathCase) {
LOG.info("GNPy : path is feasible");
PathCase pathCase = (PathCase) response.getResponseType();
- List<PathMetric> pathMetricList = pathCase.getPathProperties().getPathMetric();
+ Collection<PathMetric> pathMetricList = pathCase
+ .getPathProperties().nonnullPathMetric().values();
// Path metrics
for (PathMetric pathMetric : pathMetricList) {
String metricType = pathMetric.getMetricType().getSimpleName();
.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++;
}
private SchemaContext getSchemaContext(Class<? extends DataObject> objectClass) throws GnpyException, Exception {
-
- final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
- Iterable<? extends YangModuleInfo> moduleInfos;
- SchemaContext schemaContext = null;
- moduleInfos = Collections.singleton(BindingReflections.getModuleInfo(objectClass));
- moduleContext.addModuleInfos(moduleInfos);
- schemaContext = moduleContext.tryToCreateSchemaContext().get();
- return schemaContext;
+ Collection<? extends YangModuleInfo> moduleInfos = Collections.singleton(BindingReflections
+ .getModuleInfo(objectClass));
+ return BindingRuntimeHelpers.createEffectiveModel(moduleInfos);
}
/**