X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FRestconfImpl.java;h=5cb3cc2bae495724c4133a57c7feb929f682ebf2;hb=eff56082a308f3be21cd4eefd03e0799a6b04714;hp=b68bee2f0c9cc30e04a7c6ae62288f6cf6f4bdb6;hpb=bdcd6c4baea3357499a1fcdff459259b56373baa;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java index b68bee2f0c..5cb3cc2bae 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java @@ -33,9 +33,9 @@ import javax.ws.rs.core.Response.Status; 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; @@ -95,7 +95,7 @@ public class RestconfImpl implements RestconfService { private String uriParameterName; - UriParameters(String uriParameterName) { + UriParameters(final String uriParameterName) { this.uriParameterName = uriParameterName; } @@ -282,7 +282,7 @@ public class RestconfImpl implements RestconfService { } private StructuredData operationsFromModulesToStructuredData(final Set modules, - final DOMMountPoint mountPoint, boolean prettyPrint) { + final DOMMountPoint mountPoint, final boolean prettyPrint) { final List> operationsAsData = new ArrayList>(); Module restconfModule = this.getRestconfModule(); final DataSchemaNode operationsSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode( @@ -475,7 +475,8 @@ public class RestconfImpl implements 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); @@ -575,7 +576,7 @@ public class RestconfImpl implements RestconfService { return null; } - private StructuredData callRpc(final RpcExecutor rpcExecutor, final CompositeNode payload, boolean prettyPrint) { + private StructuredData callRpc(final RpcExecutor rpcExecutor, final CompositeNode payload, final boolean prettyPrint) { if (rpcExecutor == null) { throw new RestconfDocumentedException("RPC does not exist.", ErrorType.RPC, ErrorTag.UNKNOWN_ELEMENT); } @@ -628,20 +629,23 @@ public class RestconfImpl implements RestconfService { @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") @@ -688,32 +692,33 @@ public class RestconfImpl implements RestconfService { @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) { + private boolean parsePrettyPrintParameter(final UriInfo info) { String param = info.getQueryParameters(false).getFirst(UriParameters.PRETTY_PRINT.toString()); return Boolean.parseBoolean(param); } @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); @@ -723,13 +728,15 @@ public class RestconfImpl implements RestconfService { 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); @@ -827,20 +834,21 @@ public class RestconfImpl implements RestconfService { 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); @@ -874,17 +882,18 @@ public class RestconfImpl implements RestconfService { payloadName, module.getNamespace()); final CompositeNode value = this.normalizeNode(payload, schemaNode, null); final InstanceIdWithSchemaNode iiWithData = this.addLastIdentifierFromData(null, value, schemaNode); - RpcResult 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); @@ -895,16 +904,17 @@ public class RestconfImpl implements RestconfService { @Override public Response deleteConfigurationData(final String identifier) { - final InstanceIdWithSchemaNode iiWithData = normalizeInstanceIdentifierWithSchemaNode(this.controllerContext - .toInstanceIdentifier(identifier)); - RpcResult 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); @@ -914,14 +924,11 @@ public class RestconfImpl implements RestconfService { } /** - * 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: *
    - *
  • datastore
  • - default CONFIGURATION (other values of - * {@link LogicalDatastoreType} enum type) + *
  • datastore
  • - default CONFIGURATION (other values of {@link LogicalDatastoreType} enum type) *
  • scope
  • - default BASE (other values of {@link DataChangeScope}) *
*/ @@ -971,8 +978,7 @@ public class RestconfImpl implements RestconfService { * * @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 parseEnumTypeParameter(final CompositeNode compNode, final Class classDescriptor, final String paramName) { @@ -991,11 +997,10 @@ public class RestconfImpl implements RestconfService { } /** - * 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 parserURIEnumParameter(final Class classDescriptor, final String value) { if (Strings.isNullOrEmpty(value)) { @@ -1004,7 +1009,7 @@ public class RestconfImpl implements RestconfService { return resolveAsEnum(classDescriptor, value); } - private T resolveAsEnum(Class classDescriptor, String value) { + private T resolveAsEnum(final Class classDescriptor, final String value) { T[] enumConstants = classDescriptor.getEnumConstants(); if (enumConstants != null) { for (T enm : classDescriptor.getEnumConstants()) { @@ -1016,7 +1021,7 @@ public class RestconfImpl implements RestconfService { return null; } - private Map resolveValuesFromUri(String uri) { + private Map resolveValuesFromUri(final String uri) { Map result = new HashMap<>(); String[] tokens = uri.split("/"); for (int i = 1; i < tokens.length; i++) { @@ -1090,34 +1095,6 @@ public class RestconfImpl implements RestconfService { return new InstanceIdWithSchemaNode(instance, schemaOfData, mountPoint); } - private HashMap resolveKeysFromData(final ListSchemaNode listNode, final CompositeNode dataNode) { - final HashMap keyValues = new HashMap(); - List _keyDefinition = listNode.getKeyDefinition(); - for (final QName key : _keyDefinition) { - SimpleNode head = null; - String localName = key.getLocalName(); - List> 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 + "/"); } @@ -1433,7 +1410,7 @@ public class RestconfImpl implements RestconfService { } } - private CompositeNode datastoreNormalizedNodeToCompositeNode(NormalizedNode dataNode, DataSchemaNode schema) { + private CompositeNode datastoreNormalizedNodeToCompositeNode(final NormalizedNode dataNode, final DataSchemaNode schema) { Iterable> nodes = null; if (dataNode == null) { throw new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.DATA_MISSING, @@ -1465,14 +1442,14 @@ public class RestconfImpl implements RestconfService { "It wasn't possible to correctly interpret data.")); } - private NormalizedNode compositeNodeToDatastoreNormalizedNode(CompositeNode compNode, DataSchemaNode schema) { + private NormalizedNode compositeNodeToDatastoreNormalizedNode(final CompositeNode compNode, final DataSchemaNode schema) { List> lst = new ArrayList>(); lst.add(compNode); if (schema instanceof ContainerSchemaNode) { return CnSnToNormalizedNodeParserFactory.getInstance().getContainerNodeParser() .parse(lst, (ContainerSchemaNode) schema); } else if (schema instanceof ListSchemaNode) { - return CnSnToNormalizedNodeParserFactory.getInstance().getMapNodeParser() + return CnSnToNormalizedNodeParserFactory.getInstance().getMapEntryNodeParser() .parse(lst, (ListSchemaNode) schema); } @@ -1482,19 +1459,19 @@ public class RestconfImpl implements RestconfService { "It wasn't possible to translate specified data to datastore readable form.")); } - private InstanceIdWithSchemaNode normalizeInstanceIdentifierWithSchemaNode(InstanceIdWithSchemaNode iiWithSchemaNode) { + private InstanceIdWithSchemaNode normalizeInstanceIdentifierWithSchemaNode(final InstanceIdWithSchemaNode iiWithSchemaNode) { return normalizeInstanceIdentifierWithSchemaNode(iiWithSchemaNode, false); } private InstanceIdWithSchemaNode normalizeInstanceIdentifierWithSchemaNode( - InstanceIdWithSchemaNode iiWithSchemaNode, boolean unwrapLastListNode) { + final InstanceIdWithSchemaNode iiWithSchemaNode, final boolean unwrapLastListNode) { return new InstanceIdWithSchemaNode(instanceIdentifierToReadableFormForNormalizeNode( iiWithSchemaNode.getInstanceIdentifier(), unwrapLastListNode), iiWithSchemaNode.getSchemaNode(), iiWithSchemaNode.getMountPoint()); } - private YangInstanceIdentifier instanceIdentifierToReadableFormForNormalizeNode(YangInstanceIdentifier instIdentifier, - boolean unwrapLastListNode) { + private YangInstanceIdentifier instanceIdentifierToReadableFormForNormalizeNode(final YangInstanceIdentifier instIdentifier, + final boolean unwrapLastListNode) { Preconditions.checkNotNull(instIdentifier, "Instance identifier can't be null"); final List result = new ArrayList(); final Iterator iter = instIdentifier.getPathArguments().iterator();