Search in sources :

Example 1 with DataNormalizationException

use of org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException in project controller by opendaylight.

the class BindingToNormalizedNodeCodec method getDefaultNodeFor.

/**
 * Returns an default object according to YANG schema for supplied path.
 *
 * @param path DOM Path
 * @return Node with defaults set on.
 */
public NormalizedNode<?, ?> getDefaultNodeFor(final YangInstanceIdentifier path) {
    final Iterator<PathArgument> iterator = path.getPathArguments().iterator();
    DataNormalizationOperation<?> currentOp = this.legacyToNormalized.getRootOperation();
    while (iterator.hasNext()) {
        final PathArgument currentArg = iterator.next();
        try {
            currentOp = currentOp.getChild(currentArg);
        } catch (final DataNormalizationException e) {
            throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
        }
    }
    return currentOp.createDefault(path.getLastPathArgument());
}
Also used : DataNormalizationException(org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 2 with DataNormalizationException

use of org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException in project controller by opendaylight.

the class BindingDOMWriteTransactionAdapter method ensureParentsByMerge.

@Override
protected void ensureParentsByMerge(final LogicalDatastoreType store, final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath, final InstanceIdentifier<?> path) {
    List<PathArgument> currentArguments = new ArrayList<>();
    DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
    for (PathArgument currentArg : normalizedPath.getPathArguments()) {
        try {
            currentOp = currentOp.getChild(currentArg);
        } catch (DataNormalizationException e) {
            throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
        }
        currentArguments.add(currentArg);
        YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(currentArguments);
        getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
    }
}
Also used : DataNormalizationException(org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException) ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 3 with DataNormalizationException

use of org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException in project controller by opendaylight.

the class AbstractReadWriteTransaction method ensureParentsByMerge.

@Override
protected final void ensureParentsByMerge(final LogicalDatastoreType store, final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath, final InstanceIdentifier<?> path) {
    List<PathArgument> currentArguments = new ArrayList<>();
    DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
    Iterator<PathArgument> iterator = normalizedPath.getPathArguments().iterator();
    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", path), e);
        }
        currentArguments.add(currentArg);
        org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier currentPath = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.create(currentArguments);
        final Boolean exists;
        try {
            exists = getDelegate().exists(store, currentPath).checkedGet();
        } catch (ReadFailedException 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 (!exists && iterator.hasNext()) {
            getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ArrayList(java.util.ArrayList) DataNormalizationException(org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Aggregations

DataNormalizationException (org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 ArrayList (java.util.ArrayList)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1