import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.math.BigInteger;
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.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
private static final URI NAMESPACE_EVENT_SUBSCRIPTION_AUGMENT = URI.create("urn:sal:restconf:event:subscription");
- private static final Date EVENT_SUBSCRIPTION_AUGMENT_REVISION;
-
private static final String DATASTORE_PARAM_NAME = "datastore";
private static final String SCOPE_PARAM_NAME = "scope";
private static final QName NETCONF_BASE_QNAME;
+ private static final QNameModule SAL_REMOTE_AUGMENT;
+
+ private static final YangInstanceIdentifier.AugmentationIdentifier SAL_REMOTE_AUG_IDENTIFIER;
+
static {
try {
- EVENT_SUBSCRIPTION_AUGMENT_REVISION = new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-08");
+ final Date eventSubscriptionAugRevision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-08");
NETCONF_BASE_QNAME = QName.create(QNameModule.create(new URI(NETCONF_BASE), null), NETCONF_BASE_PAYLOAD_NAME );
+ SAL_REMOTE_AUGMENT = QNameModule.create(NAMESPACE_EVENT_SUBSCRIPTION_AUGMENT,
+ eventSubscriptionAugRevision);
+ SAL_REMOTE_AUG_IDENTIFIER = new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(QName.create(SAL_REMOTE_AUGMENT, "scope"),
+ QName.create(SAL_REMOTE_AUGMENT, "datastore")));
} catch (final ParseException e) {
throw new RestconfDocumentedException(
"It wasn't possible to convert revision date of sal-remote-augment to date", ErrorType.APPLICATION,
final DOMRpcResult result = checkRpcResponse(response);
- DataSchemaNode resultNodeSchema = null;
- NormalizedNode<?, ?> resultData = null;
+ RpcDefinition resultNodeSchema = null;
+ final NormalizedNode<?, ?> resultData = result.getResult();
if (result != null && result.getResult() != null) {
- resultData = result.getResult();
- final ContainerSchemaNode rpcDataSchemaNode = SchemaContextUtil.getRpcDataSchema(schemaContext, type);
- resultNodeSchema = rpcDataSchemaNode.getDataChildByName(result.getResult().getNodeType());
+ resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
}
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, resultNodeSchema, mountPoint,
- schemaContext), resultData);
+ return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null,
+ resultNodeSchema, mountPoint, schemaContext), resultData);
}
private DOMRpcResult checkRpcResponse(final CheckedFuture<DOMRpcResult, DOMRpcException> response) {
}
}
- private void validateInput(final DataSchemaNode inputSchema, final NormalizedNodeContext payload) {
+ private void validateInput(final SchemaNode inputSchema, final NormalizedNodeContext payload) {
if (inputSchema != null && payload.getData() == null) {
// expected a non null payload
throw new RestconfDocumentedException("Input is required.", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
private CheckedFuture<DOMRpcResult, DOMRpcException> invokeSalRemoteRpcSubscribeRPC(final NormalizedNodeContext payload) {
final ContainerNode value = (ContainerNode) payload.getData();
final QName rpcQName = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
- Optional<DataContainerChild<? extends PathArgument, ?>> path = value.getChild(new NodeIdentifier(
+ final Optional<DataContainerChild<? extends PathArgument, ?>> path = value.getChild(new NodeIdentifier(
QName.create(payload.getInstanceIdentifierContext().getSchemaNode().getQName(), "path")));
final Object pathValue = path.isPresent() ? path.get().getValue() : null;
ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
- QName outputQname = QName.create(rpcQName, "output");
- QName streamNameQname = QName.create(rpcQName, "stream-name");
+ final QName outputQname = QName.create(rpcQName, "output");
+ final QName streamNameQname = QName.create(rpcQName, "stream-name");
- ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname))
+ final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname))
.withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
if (!Notificator.existListenerFor(streamName)) {
- YangInstanceIdentifier normalizedPathIdentifier = controllerContext.toNormalized(pathIdentifier);
+ final YangInstanceIdentifier normalizedPathIdentifier = controllerContext.toNormalized(pathIdentifier);
Notificator.createListener(normalizedPathIdentifier, streamName);
}
- DOMRpcResult defaultDOMRpcResult = new DefaultDOMRpcResult(output);
+ final DOMRpcResult defaultDOMRpcResult = new DefaultDOMRpcResult(output);
return Futures.immediateCheckedFuture(defaultDOMRpcResult);
}
if (rpc.getInput() != null) {
// FIXME : find a correct Error from specification
- throw new IllegalStateException("RPC " + rpc + " needs input value!");
+ throw new IllegalStateException("RPC " + rpc + " does'n need input value!");
}
final CheckedFuture<DOMRpcResult, DOMRpcException> response;
final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode<?, ?> data = null;
- YangInstanceIdentifier normalizedII;
+ final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
if (mountPoint != null) {
- normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData
- .getInstanceIdentifier());
data = broker.readConfigurationData(mountPoint, normalizedII);
} else {
- normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
data = broker.readConfigurationData(normalizedII);
}
+ if(data == null) {
+ throw new RestconfDocumentedException(
+ "Request could not be completed because the relevant data model content does not exist.",
+ ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
+ }
return new NormalizedNodeContext(iiWithData, data);
}
final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode<?, ?> data = null;
- YangInstanceIdentifier normalizedII;
+ final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
if (mountPoint != null) {
- normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData
- .getInstanceIdentifier());
data = broker.readOperationalData(mountPoint, normalizedII);
} else {
- normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
data = broker.readOperationalData(normalizedII);
}
-
+ if(data == null) {
+ throw new RestconfDocumentedException(
+ "Request could not be completed because the relevant data model content does not exist.",
+ ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
+ }
return new NormalizedNodeContext(iiWithData, data);
}
@Override
public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload) {
Preconditions.checkNotNull(identifier);
- final InstanceIdentifierContext<DataSchemaNode> iiWithData = controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<DataSchemaNode> iiWithData =
+ (InstanceIdentifierContext<DataSchemaNode>) payload.getInstanceIdentifierContext();
validateInput(iiWithData.getSchemaNode(), payload);
validateTopLevelNodeName(payload, iiWithData.getInstanceIdentifier());
* if key values or key count in payload and URI isn't equal
*
*/
- private void validateListKeysEqualityInPayloadAndUri(final InstanceIdentifierContext iiWithData,
+ private void validateListKeysEqualityInPayloadAndUri(final InstanceIdentifierContext<DataSchemaNode> iiWithData,
final NormalizedNode<?, ?> payload) {
if (iiWithData.getSchemaNode() instanceof ListSchemaNode) {
final List<QName> keyDefinitions = ((ListSchemaNode) iiWithData.getSchemaNode()).getKeyDefinition();
@Override
public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
- if (payload == null) {
- throw new RestconfDocumentedException("Input is required.", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
- }
-
- final URI payloadNS = payload.getData().getNodeType().getNamespace();
- if (payloadNS == null) {
- throw new RestconfDocumentedException(
- "Data has bad format. Root element node must have namespace (XML format) or module name(JSON format)",
- ErrorType.PROTOCOL, ErrorTag.UNKNOWN_NAMESPACE);
- }
-
- final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
-
- final InstanceIdentifierContext iiWithData = mountPoint != null
- ? controllerContext.toMountPointIdentifier(identifier)
- : controllerContext.toInstanceIdentifier(identifier);
- final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
-
- try {
- if (mountPoint != null) {
- broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData());
- } else {
- broker.commitConfigurationDataPost(normalizedII, payload.getData());
- }
- } catch(final RestconfDocumentedException e) {
- throw e;
- } catch (final Exception e) {
- throw new RestconfDocumentedException("Error creating data", e);
- }
-
-
- final ResponseBuilder responseBuilder = Response.status(Status.NO_CONTENT);
- final URI location = resolveLocation(uriInfo, "config", mountPoint, normalizedII);
- if (location != null) {
- responseBuilder.location(location);
- }
- return responseBuilder.build();
+ return createConfigurationData(payload, uriInfo);
}
// FIXME create RestconfIdetifierHelper and move this method there
}
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final InstanceIdentifierContext iiWithData = payload.getInstanceIdentifierContext();
+ final InstanceIdentifierContext<DataSchemaNode> iiWithData = (InstanceIdentifierContext<DataSchemaNode>) payload.getInstanceIdentifierContext();
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
-
+ final YangInstanceIdentifier resultII;
try {
if (mountPoint != null) {
- broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData());
-
+ broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData()).checkedGet();
} else {
- broker.commitConfigurationDataPost(normalizedII, payload.getData());
+ broker.commitConfigurationDataPost(normalizedII, payload.getData()).checkedGet();
}
} catch(final RestconfDocumentedException e) {
throw e;
}
final ResponseBuilder responseBuilder = Response.status(Status.NO_CONTENT);
+ // FIXME: Provide path to result.
final URI location = resolveLocation(uriInfo, "", mountPoint, normalizedII);
if (location != null) {
responseBuilder.location(location);
@Override
public Response deleteConfigurationData(final String identifier) {
- final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<DataSchemaNode> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
- YangInstanceIdentifier normalizedII;
+ final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
try {
if (mountPoint != null) {
- normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData
- .getInstanceIdentifier());
broker.commitConfigurationDataDelete(mountPoint, normalizedII);
} else {
- normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
broker.commitConfigurationDataDelete(normalizedII).get();
}
} catch (final Exception e) {
*/
private <T> T parseEnumTypeParameter(final ContainerNode value, final Class<T> classDescriptor,
final String paramName) {
- final QNameModule salRemoteAugment = QNameModule.create(NAMESPACE_EVENT_SUBSCRIPTION_AUGMENT,
- EVENT_SUBSCRIPTION_AUGMENT_REVISION);
- Optional<DataContainerChild<? extends PathArgument, ?>> enumNode = value.getChild(new NodeIdentifier(
- QName.create(salRemoteAugment, paramName)));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> augNode = value.getChild(SAL_REMOTE_AUG_IDENTIFIER);
+ if (!augNode.isPresent() && !(augNode instanceof AugmentationNode)) {
+ return null;
+ }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> enumNode =
+ ((AugmentationNode) augNode.get()).getChild(new NodeIdentifier(QName.create(SAL_REMOTE_AUGMENT, paramName)));
if (!enumNode.isPresent()) {
return null;
}