<artifactId>logback-config</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-binding-broker-impl</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-binding-broker-impl</artifactId>
import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private void checkReadSuccess(final RpcResult<CompositeNode> result, final YangInstanceIdentifier path) {
- LOG.warn("{}: Unable to read data: {}, errors: {}", id, path, result.getErrors());
- Preconditions.checkArgument(result.isSuccessful(), "%s: Unable to read data: %s, errors: %s", id, path, result.getErrors());
+ try {
+ Preconditions.checkArgument(result.isSuccessful(), "%s: Unable to read data: %s, errors: %s", id, path, result.getErrors());
+ } catch (IllegalArgumentException e) {
+ LOG.warn("{}: Unable to read data: {}, errors: {}", id, path, result.getErrors());
+ throw e;
+ }
}
private Optional<NormalizedNode<?, ?>> transform(final YangInstanceIdentifier path, final CompositeNode node) {
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-common-util</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-common-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-remote</artifactId>
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.ws.rs.core.Response.Status;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
+import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
+import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
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.NormalizedNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPut(
final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
checkPreconditions();
- return putDataViaTransaction(domDataBroker.newWriteOnlyTransaction(), CONFIGURATION, path, payload);
+ DataNormalizationOperation<?> rootOp = ControllerContext.getInstance().getRootOperation();
+ return putDataViaTransaction(domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload, rootOp);
}
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPut(
final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
if (domDataBrokerService.isPresent()) {
- return putDataViaTransaction(domDataBrokerService.get().newWriteOnlyTransaction(), CONFIGURATION, path,
- payload);
+ DataNormalizationOperation<?> rootOp = new DataNormalizer(mountPoint.getSchemaContext()).getRootOperation();
+ return putDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path,
+ payload, rootOp);
}
throw new RestconfDocumentedException("DOM data broker service isn't available for mount point.");
}
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPost(
final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
checkPreconditions();
- return postDataViaTransaction(domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload);
+ DataNormalizationOperation<?> rootOp = ControllerContext.getInstance().getRootOperation();
+ return postDataViaTransaction(domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload, rootOp);
}
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPost(
final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
if (domDataBrokerService.isPresent()) {
+ DataNormalizationOperation<?> rootOp = new DataNormalizer(mountPoint.getSchemaContext()).getRootOperation();
return postDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path,
- payload);
+ payload, rootOp);
}
throw new RestconfDocumentedException("DOM data broker service isn't available for mount point.");
}
private CheckedFuture<Void, TransactionCommitFailedException> postDataViaTransaction(
final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
- final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, DataNormalizationOperation<?> root) {
ListenableFuture<Optional<NormalizedNode<?, ?>>> futureDatastoreData = rWTransaction.read(datastore, path);
try {
final Optional<NormalizedNode<?, ?>> optionalDatastoreData = futureDatastoreData.get();
} catch (InterruptedException | ExecutionException e) {
LOG.trace("It wasn't possible to get data loaded from datastore at path " + path);
}
+
+ ensureParentsByMerge(datastore, path, rWTransaction, root);
rWTransaction.merge(datastore, path, payload);
LOG.trace("Post " + datastore.name() + " via Restconf: {}", path);
return rWTransaction.submit();
}
private CheckedFuture<Void, TransactionCommitFailedException> putDataViaTransaction(
- final DOMDataWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
- final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
+ final DOMDataReadWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, DataNormalizationOperation<?> root) {
LOG.trace("Put " + datastore.name() + " via Restconf: {}", path);
+ ensureParentsByMerge(datastore, path, writeTransaction, root);
writeTransaction.put(datastore, path, payload);
return writeTransaction.submit();
}
public void setDomDataBroker(DOMDataBroker domDataBroker) {
this.domDataBroker = domDataBroker;
}
+
+ private final void ensureParentsByMerge(final LogicalDatastoreType store,
+ final YangInstanceIdentifier normalizedPath, final DOMDataReadWriteTransaction rwTx,
+ final DataNormalizationOperation<?> root) {
+ List<PathArgument> currentArguments = new ArrayList<>();
+ Iterator<PathArgument> iterator = normalizedPath.getPathArguments().iterator();
+ DataNormalizationOperation<?> currentOp = root;
+ while (iterator.hasNext()) {
+ PathArgument currentArg = iterator.next();
+ try {
+ currentOp = currentOp.getChild(currentArg);
+ } catch (DataNormalizationException e) {
+ throw new IllegalArgumentException(
+ String.format("Invalid child encountered in path %s", normalizedPath), e);
+ }
+ currentArguments.add(currentArg);
+ YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(currentArguments);
+
+ final Optional<NormalizedNode<?, ?>> datastoreData;
+ try {
+ datastoreData = rwTx.read(store, currentPath).get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to read pre-existing data from store {} path {}", store, currentPath, e);
+ throw new IllegalStateException("Failed to read pre-existing data", e);
+ }
+
+ if (!datastoreData.isPresent() && iterator.hasNext()) {
+ rwTx.merge(store, currentPath, currentOp.createDefault(currentArg));
+ }
+ }
+ }
}
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.core.Response.Status;
+import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
+import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.sal.rest.api.Draft02;
import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
private volatile SchemaContext globalSchema;
private volatile DOMMountPointService mountService;
+ private DataNormalizer dataNormalizer;
+
public void setGlobalSchema(final SchemaContext globalSchema) {
this.globalSchema = globalSchema;
+ this.dataNormalizer = new DataNormalizer(globalSchema);
}
public void setMountService(final DOMMountPointService mountService) {
+ Arrays.<Object> asList(container, name).toString());
}
}
+
+ public Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalized(final YangInstanceIdentifier legacy,
+ final CompositeNode compositeNode) {
+ try {
+ return dataNormalizer.toNormalized(legacy, compositeNode);
+ } catch (NullPointerException e) {
+ throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
+ }
+ }
+
+ public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) {
+ try {
+ return dataNormalizer.toNormalized(legacy);
+ } catch (NullPointerException e) {
+ throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
+ }
+ }
+
+ public CompositeNode toLegacy(final YangInstanceIdentifier instanceIdentifier,
+ final NormalizedNode<?,?> normalizedNode) {
+ try {
+ return dataNormalizer.toLegacy(instanceIdentifier, normalizedNode);
+ } catch (NullPointerException e) {
+ throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
+ }
+ }
+
+ public DataNormalizationOperation<?> getRootOperation() {
+ return dataNormalizer.getRootOperation();
+ }
+
}
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.sal.rest.api.Draft02;
import org.opendaylight.controller.sal.rest.api.RestconfService;
if (!Iterables.isEmpty(pathIdentifier.getPathArguments())) {
String fullRestconfIdentifier = this.controllerContext.toFullRestconfIdentifier(pathIdentifier);
- LogicalDatastoreType datastore = parseEnumTypeParameter(value, LogicalDatastoreType.class, DATASTORE_PARAM_NAME);
+ LogicalDatastoreType datastore = parseEnumTypeParameter(value, LogicalDatastoreType.class,
+ DATASTORE_PARAM_NAME);
datastore = datastore == null ? DEFAULT_DATASTORE : datastore;
DataChangeScope scope = parseEnumTypeParameter(value, DataChangeScope.class, SCOPE_PARAM_NAME);
@Override
public StructuredData readConfigurationData(final String identifier, final UriInfo uriInfo) {
- final InstanceIdWithSchemaNode iiWithData = normalizeInstanceIdentifierWithSchemaNode(
- this.controllerContext.toInstanceIdentifier(identifier), true);
+ final InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier(identifier);
DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode<?, ?> data = null;
+ YangInstanceIdentifier normalizedII;
if (mountPoint != null) {
- data = broker.readConfigurationData(mountPoint, iiWithData.getInstanceIdentifier());
+ normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData.getInstanceIdentifier());
+ data = broker.readConfigurationData(mountPoint, normalizedII);
} else {
- data = broker.readConfigurationData(iiWithData.getInstanceIdentifier());
+ normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
+ data = broker.readConfigurationData(normalizedII);
}
- CompositeNode compositeNode = datastoreNormalizedNodeToCompositeNode(data, iiWithData.getSchemaNode());
- compositeNode = pruneDataAtDepth(compositeNode, parseDepthParameter(uriInfo));
- boolean prettyPrintMode = parsePrettyPrintParameter(uriInfo);
- return new StructuredData(compositeNode, iiWithData.getSchemaNode(), iiWithData.getMountPoint(), prettyPrintMode);
+ final CompositeNode compositeNode = datastoreNormalizedNodeToCompositeNode(data, iiWithData.getSchemaNode());
+ final CompositeNode prunedCompositeNode = pruneDataAtDepth(compositeNode, parseDepthParameter(uriInfo));
+
+ final boolean prettyPrintMode = parsePrettyPrintParameter(uriInfo);
+ return new StructuredData(prunedCompositeNode, iiWithData.getSchemaNode(), mountPoint, prettyPrintMode);
}
@SuppressWarnings("unchecked")
@Override
public StructuredData readOperationalData(final String identifier, final UriInfo info) {
- final InstanceIdWithSchemaNode iiWithData = normalizeInstanceIdentifierWithSchemaNode(
- this.controllerContext.toInstanceIdentifier(identifier), true);
- NormalizedNode<?, ?> data = null;
-
+ final InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier(identifier);
DOMMountPoint mountPoint = iiWithData.getMountPoint();
+ NormalizedNode<?, ?> data = null;
+ YangInstanceIdentifier normalizedII;
if (mountPoint != null) {
- data = broker.readOperationalData(mountPoint, iiWithData.getInstanceIdentifier());
+ normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData.getInstanceIdentifier());
+ data = broker.readOperationalData(mountPoint, normalizedII);
} else {
- data = broker.readOperationalData(iiWithData.getInstanceIdentifier());
+ normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
+ data = broker.readOperationalData(normalizedII);
}
final CompositeNode compositeNode = datastoreNormalizedNodeToCompositeNode(data, iiWithData.getSchemaNode());
final CompositeNode prunedCompositeNode = pruneDataAtDepth(compositeNode, parseDepthParameter(info));
+
final boolean prettyPrintMode = parsePrettyPrintParameter(info);
- return new StructuredData(prunedCompositeNode, iiWithData.getSchemaNode(), mountPoint,prettyPrintMode);
+ return new StructuredData(prunedCompositeNode, iiWithData.getSchemaNode(), mountPoint, prettyPrintMode);
}
private boolean parsePrettyPrintParameter(UriInfo info) {
@Override
public Response updateConfigurationData(final String identifier, final Node<?> payload) {
- final InstanceIdWithSchemaNode iiWithData = normalizeInstanceIdentifierWithSchemaNode(this.controllerContext
- .toInstanceIdentifier(identifier));
+ final InstanceIdWithSchemaNode iiWithData = this.controllerContext.toInstanceIdentifier(identifier);
validateInput(iiWithData.getSchemaNode(), payload);
final NormalizedNode<?, ?> datastoreNormalizedNode = compositeNodeToDatastoreNormalizedNode(value,
iiWithData.getSchemaNode());
+ YangInstanceIdentifier normalizedII;
+
try {
if (mountPoint != null) {
- broker.commitConfigurationDataPut(mountPoint, iiWithData.getInstanceIdentifier(),
- datastoreNormalizedNode).get();
+ normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataPut(mountPoint, normalizedII, datastoreNormalizedNode).get();
} else {
- broker.commitConfigurationDataPut(iiWithData.getInstanceIdentifier(), datastoreNormalizedNode)
- .get();
+ normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataPut(normalizedII, datastoreNormalizedNode).get();
}
} catch (Exception e) {
throw new RestconfDocumentedException("Error updating data", e);
parentSchema, payloadName, module.getNamespace());
value = this.normalizeNode(payload, schemaNode, mountPoint);
- iiWithData = normalizeInstanceIdentifierWithSchemaNode(this.addLastIdentifierFromData(
- incompleteInstIdWithData, value, schemaNode));
+ iiWithData = addLastIdentifierFromData(incompleteInstIdWithData, value, schemaNode);
}
final NormalizedNode<?, ?> datastoreNormalizedData = compositeNodeToDatastoreNormalizedNode(value,
iiWithData.getSchemaNode());
DOMMountPoint mountPoint = iiWithData.getMountPoint();
+ YangInstanceIdentifier normalizedII;
+
try {
if (mountPoint != null) {
- broker.commitConfigurationDataPost(mountPoint,
- iiWithData.getInstanceIdentifier(), datastoreNormalizedData);
+ normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataPost(mountPoint, normalizedII, datastoreNormalizedData);
} else {
- broker.commitConfigurationDataPost(
- iiWithData.getInstanceIdentifier(), datastoreNormalizedData);
+ normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataPost(normalizedII, datastoreNormalizedData);
}
} catch (Exception e) {
throw new RestconfDocumentedException("Error creating data", e);
payloadName, module.getNamespace());
final CompositeNode value = this.normalizeNode(payload, schemaNode, null);
final InstanceIdWithSchemaNode iiWithData = this.addLastIdentifierFromData(null, value, schemaNode);
- RpcResult<TransactionStatus> status = null;
final NormalizedNode<?, ?> datastoreNormalizedData = compositeNodeToDatastoreNormalizedNode(value, schemaNode);
DOMMountPoint mountPoint = iiWithData.getMountPoint();
+ YangInstanceIdentifier normalizedII;
try {
if (mountPoint != null) {
- broker.commitConfigurationDataPost(mountPoint,
- iiWithData.getInstanceIdentifier(), datastoreNormalizedData);
+ normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataPost(mountPoint, normalizedII, datastoreNormalizedData);
+
} else {
- broker.commitConfigurationDataPost(
- iiWithData.getInstanceIdentifier(), datastoreNormalizedData);
+ normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataPost(normalizedII, datastoreNormalizedData);
}
} catch (Exception e) {
throw new RestconfDocumentedException("Error creating data", e);
@Override
public Response deleteConfigurationData(final String identifier) {
- final InstanceIdWithSchemaNode iiWithData = normalizeInstanceIdentifierWithSchemaNode(this.controllerContext
- .toInstanceIdentifier(identifier));
- RpcResult<TransactionStatus> status = null;
+ final InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier(identifier);
DOMMountPoint mountPoint = iiWithData.getMountPoint();
+ YangInstanceIdentifier normalizedII;
try {
if (mountPoint != null) {
- broker.commitConfigurationDataDelete(mountPoint, iiWithData.getInstanceIdentifier()).get();
+ normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataDelete(mountPoint, normalizedII);
} else {
- broker.commitConfigurationDataDelete(iiWithData.getInstanceIdentifier()).get();
+ normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
+ broker.commitConfigurationDataDelete(normalizedII).get();
}
} catch (Exception e) {
throw new RestconfDocumentedException("Error creating data", e);
}
/**
- * Subscribes to some path in schema context (stream) to listen on changes
- * on this stream.
+ * Subscribes to some path in schema context (stream) to listen on changes on this stream.
*
- * Additional parameters for subscribing to stream are loaded via rpc input
- * parameters:
+ * Additional parameters for subscribing to stream are loaded via rpc input parameters:
* <ul>
- * <li>datastore</li> - default CONFIGURATION (other values of
- * {@link LogicalDatastoreType} enum type)
+ * <li>datastore</li> - default CONFIGURATION (other values of {@link LogicalDatastoreType} enum type)
* <li>scope</li> - default BASE (other values of {@link DataChangeScope})
* </ul>
*/
*
* @param compNode
* contains value
- * @return enum object if its string value is equal to {@code paramName}. In
- * other cases null.
+ * @return enum object if its string value is equal to {@code paramName}. In other cases null.
*/
private <T> T parseEnumTypeParameter(final CompositeNode compNode, final Class<T> classDescriptor,
final String paramName) {
}
/**
- * Checks whether {@code value} is one of the string representation of
- * enumeration {@code classDescriptor}
+ * Checks whether {@code value} is one of the string representation of enumeration {@code classDescriptor}
*
- * @return enum object if string value of {@code classDescriptor}
- * enumeration is equal to {@code value}. Other cases null.
+ * @return enum object if string value of {@code classDescriptor} enumeration is equal to {@code value}. Other cases
+ * null.
*/
private <T> T parserURIEnumParameter(final Class<T> classDescriptor, final String value) {
if (Strings.isNullOrEmpty(value)) {
return new InstanceIdWithSchemaNode(instance, schemaOfData, mountPoint);
}
- private HashMap<QName, Object> resolveKeysFromData(final ListSchemaNode listNode, final CompositeNode dataNode) {
- final HashMap<QName, Object> keyValues = new HashMap<QName, Object>();
- List<QName> _keyDefinition = listNode.getKeyDefinition();
- for (final QName key : _keyDefinition) {
- SimpleNode<? extends Object> head = null;
- String localName = key.getLocalName();
- List<SimpleNode<? extends Object>> simpleNodesByName = dataNode.getSimpleNodesByName(localName);
- if (simpleNodesByName != null) {
- head = Iterables.getFirst(simpleNodesByName, null);
- }
-
- Object dataNodeKeyValueObject = null;
- if (head != null) {
- dataNodeKeyValueObject = head.getValue();
- }
-
- if (dataNodeKeyValueObject == null) {
- throw new RestconfDocumentedException("Data contains list \"" + dataNode.getNodeType().getLocalName()
- + "\" which does not contain key: \"" + key.getLocalName() + "\"", ErrorType.PROTOCOL,
- ErrorTag.INVALID_VALUE);
- }
-
- keyValues.put(key, dataNodeKeyValueObject);
- }
-
- return keyValues;
- }
-
private boolean endsWithMountPoint(final String identifier) {
return identifier.endsWith(ControllerContext.MOUNT) || identifier.endsWith(ControllerContext.MOUNT + "/");
}
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.util.concurrent.Future;
-import org.apache.commons.lang.StringEscapeUtils;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.controller.sal.restconf.impl.RestconfError;
import org.opendaylight.controller.sal.streams.listeners.ListenerAdapter;
CompositeNode dataNode;
- NormalizedNode<?, ?> dummyNode = createDummyNode("dummy:namespace", "2014-07-01", "dummy local name");
+ NormalizedNode<?, ?> dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces");
CheckedFuture<Optional<NormalizedNode<?, ?>>,ReadFailedException> dummyNodeInFuture = wrapDummyNode(dummyNode);
- QName qname = QName.create("node");
+ QName qname = TestUtils.buildQName("interfaces","test:module", "2014-01-09");
YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(qname).toInstance();
dataNode = TestUtils.prepareCompositeNodeWithIetfInterfacesInterfacesData();
+ ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/test-module"));
+
}
private CheckedFuture<Optional<NormalizedNode<?, ?>>,ReadFailedException> wrapDummyNode(final NormalizedNode<?, ?> dummyNode) {
brokerFacade.invokeRpc(qname, dataNode);
}
+ @Ignore
@Test
public void testCommitConfigurationDataPut() {
CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION, DataChangeScope.BASE, listener);
verifyNoMoreInteractions(domDataBroker);
- String escapeXml = StringEscapeUtils.escapeXml("data might contain & or ! or % or ' ");
- System.out.println(escapeXml);
}
}