import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+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.dom.api.DOMDataReadTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
Iterator<PathArgument> iterator = normalizedPath.getPath().iterator();
while (iterator.hasNext()) {
PathArgument currentArg = iterator.next();
- currentOp = currentOp.getChild(currentArg);
+ try {
+ currentOp = currentOp.getChild(currentArg);
+ } catch (DataNormalizationException e) {
+ throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
+ }
currentArguments.add(currentArg);
org.opendaylight.yangtools.yang.data.api.InstanceIdentifier currentPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier(
currentArguments);
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, 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.controller.md.sal.common.impl.util.compat;
+
+public class DataNormalizationException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public DataNormalizationException(String message) {
+ super(message);
+ }
+
+ public DataNormalizationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
+/*
+ * Copyright (c) 2014 Cisco Systems, 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.controller.md.sal.common.impl.util.compat;
import static com.google.common.base.Preconditions.checkArgument;
return Collections.singleton(identifier.getNodeType());
}
- public abstract DataNormalizationOperation<?> getChild(final PathArgument child);
+ public abstract DataNormalizationOperation<?> getChild(final PathArgument child) throws DataNormalizationException;
- public abstract DataNormalizationOperation<?> getChild(QName child);
+ public abstract DataNormalizationOperation<?> getChild(QName child) throws DataNormalizationException;
public abstract NormalizedNode<?, ?> normalize(Node<?> legacyData);
Set<DataNormalizationOperation<?>> usedMixins = new HashSet<>();
for (Node<?> childLegacy : compositeNode.getValue()) {
- DataNormalizationOperation childOp = getChild(childLegacy.getNodeType());
+ final DataNormalizationOperation childOp;
+
+ try {
+ childOp = getChild(childLegacy.getNodeType());
+ } catch (DataNormalizationException e) {
+ throw new IllegalArgumentException(String.format("Failed to normalize data %s", compositeNode.getValue()), e);
+ }
// We skip unknown nodes if this node is mixin since
// it's nodes and parent nodes are interleaved
if (childOp.isMixin()) {
if (usedMixins.contains(childOp)) {
// We already run / processed that mixin, so to avoid
- // dupliciry we are
- // skiping next nodes.
+ // duplicity we are skipping next nodes.
continue;
}
builder.addChild(childOp.normalize(compositeNode));
}
@Override
- public DataNormalizationOperation<?> getChild(final PathArgument child) {
+ public DataNormalizationOperation<?> getChild(final PathArgument child) throws DataNormalizationException {
DataNormalizationOperation<?> potential = byArg.get(child);
if (potential != null) {
return potential;
}
@Override
- public DataNormalizationOperation<?> getChild(final QName child) {
+ public DataNormalizationOperation<?> getChild(final QName child) throws DataNormalizationException {
DataNormalizationOperation<?> potential = byQName.get(child);
if (potential != null) {
return potential;
}
}
- public static DataNormalizationOperation<?> fromSchemaAndPathArgument(final DataNodeContainer schema,
- final QName child) {
+ private static DataNormalizationOperation<?> fromSchemaAndPathArgument(final DataNodeContainer schema,
+ final QName child) throws DataNormalizationException {
DataSchemaNode potential = schema.getDataChildByName(child);
if (potential == null) {
Iterable<org.opendaylight.yangtools.yang.model.api.ChoiceNode> choices = FluentIterable.from(
schema.getChildNodes()).filter(org.opendaylight.yangtools.yang.model.api.ChoiceNode.class);
potential = findChoice(choices, child);
}
- checkArgument(potential != null, "Supplied QName %s is not valid according to schema %s", child, schema);
+
+ if (potential == null) {
+ throw new DataNormalizationException(String.format("Supplied QName %s is not valid according to schema %s", child, schema));
+ }
+
if ((schema instanceof DataSchemaNode) && !((DataSchemaNode) schema).isAugmenting() && potential.isAugmenting()) {
return fromAugmentation(schema, (AugmentationTarget) schema, potential);
}
}
}
- private static DataNormalizationOperation<?> fromSchema(final DataNodeContainer schema, final PathArgument child) {
+ private static DataNormalizationOperation<?> fromSchema(final DataNodeContainer schema, final PathArgument child) throws DataNormalizationException {
if (child instanceof AugmentationIdentifier) {
return fromSchemaAndPathArgument(schema, ((AugmentationIdentifier) child).getPossibleChildNames()
.iterator().next());
+/*
+ * Copyright (c) 2014 Cisco Systems, 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.controller.md.sal.common.impl.util.compat;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.Iterator;
import java.util.Map;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier;
DataNormalizationOperation<?> currentOp = operation;
Iterator<PathArgument> arguments = legacy.getPath().iterator();
- while ( arguments.hasNext() ) {
- PathArgument legacyArg = arguments.next();
- currentOp = currentOp.getChild(legacyArg);
- checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s",legacy,normalizedArgs.build());
- while (currentOp.isMixin()) {
- normalizedArgs.add(currentOp.getIdentifier());
- currentOp = currentOp.getChild(legacyArg.getNodeType());
- }
- if(arguments.hasNext() || (!currentOp.isKeyedEntry() || legacyArg instanceof NodeIdentifierWithPredicates || legacyArg instanceof NodeWithValue)) {
- normalizedArgs.add(legacyArg);
+
+ try {
+ while ( arguments.hasNext() ) {
+ PathArgument legacyArg = arguments.next();
+ currentOp = currentOp.getChild(legacyArg);
+ checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s",legacy,normalizedArgs.build());
+ while (currentOp.isMixin()) {
+ normalizedArgs.add(currentOp.getIdentifier());
+ currentOp = currentOp.getChild(legacyArg.getNodeType());
+ }
+ if(arguments.hasNext() || (!currentOp.isKeyedEntry() || legacyArg instanceof NodeIdentifierWithPredicates || legacyArg instanceof NodeWithValue)) {
+ normalizedArgs.add(legacyArg);
+ }
}
+ } catch (DataNormalizationException e) {
+ throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e);
}
+
return new InstanceIdentifier(normalizedArgs.build());
}
DataNormalizationOperation<?> currentOp = operation;
for (PathArgument arg : normalizedPath.getPath()) {
- currentOp = currentOp.getChild(arg);
+ try {
+ currentOp = currentOp.getChild(arg);
+ } catch (DataNormalizationException e) {
+ throw new IllegalArgumentException(String.format("Failed to validate normalized path %s", normalizedPath), e);
+ }
}
- // Write Augmentaiton data resolution
+
+ // Write Augmentation data resolution
if (legacyData.getChildren().size() == 1) {
- DataNormalizationOperation<?> potentialOp = currentOp.getChild(legacyData.getChildren().get(0)
- .getNodeType());
+ final DataNormalizationOperation<?> potentialOp;
+
+ try {
+ final QName childType = legacyData.getChildren().get(0).getNodeType();
+ potentialOp = currentOp.getChild(childType);
+ } catch (DataNormalizationException e) {
+ throw new IllegalArgumentException(String.format("Failed to get child operation for %s", legacyData), e);
+ }
+
if(potentialOp.getIdentifier() instanceof AugmentationIdentifier) {
currentOp = potentialOp;
ArrayList<PathArgument> reworkedArgs = new ArrayList<>(normalizedPath.getPath());
+/*
+ * Copyright (c) 2014 Cisco Systems, 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.controller.md.sal.dom.broker.impl.compat;
import static com.google.common.base.Preconditions.checkNotNull;
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+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.DOMDataReadTransaction;
Iterator<PathArgument> iterator = normalizedPath.getPath().iterator();
while(iterator.hasNext()) {
PathArgument currentArg = iterator.next();
- currentOp = currentOp.getChild(currentArg);
+ try {
+ currentOp = currentOp.getChild(currentArg);
+ } catch (DataNormalizationException e) {
+ throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", normalizedPath), e);
+ }
currentArguments.add(currentArg);
InstanceIdentifier currentPath = new InstanceIdentifier(currentArguments);
boolean isPresent = getDelegate().read(store, currentPath).get().isPresent();