/**
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- * Copyright (c) 2014 Brocade Communication Systems, Inc.
+ * Copyright (c) 2014, 2015 Brocade Communication Systems, Inc., 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.sal.restconf.impl;
import com.google.common.base.Optional;
public class RestconfImpl implements RestconfService {
- private enum UriParameters {
- PRETTY_PRINT("prettyPrint"),
- DEPTH("depth");
-
- private String uriParameterName;
-
- UriParameters(final String uriParameterName) {
- this.uriParameterName = uriParameterName;
- }
-
- @Override
- public String toString() {
- return uriParameterName;
- }
- }
-
private static final RestconfImpl INSTANCE = new RestconfImpl();
private static final int NOTIFICATION_PORT = 8181;
moduleContainerBuilder.withChild(allModuleMap);
return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, modulesSchemaNode,
- null, schemaContext), moduleContainerBuilder.build());
+ null, schemaContext), moduleContainerBuilder.build(),
+ QueryParametersParser.parseWriterParameters(uriInfo));
}
/**
moduleContainerBuilder.withChild(mountPointModulesMap);
return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, modulesSchemaNode,
- mountPoint, controllerContext.getGlobalSchema()), moduleContainerBuilder.build());
+ mountPoint, controllerContext.getGlobalSchema()), moduleContainerBuilder.build(),
+ QueryParametersParser.parseWriterParameters(uriInfo));
}
@Override
Preconditions.checkState(moduleSchemaNode instanceof ListSchemaNode);
return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, moduleSchemaNode, mountPoint,
- schemaContext), moduleMap);
+ schemaContext), moduleMap, QueryParametersParser.parseWriterParameters(uriInfo));
}
@Override
return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, streamsContainerSchemaNode, null,
- schemaContext), streamsContainerBuilder.build());
+ schemaContext), streamsContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
@Override
}
return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null,
- resultNodeSchema, mountPoint, schemaContext), resultData);
+ resultNodeSchema, mountPoint, schemaContext), resultData,
+ QueryParametersParser.parseWriterParameters(uriInfo));
}
private DOMRpcResult checkRpcResponse(final CheckedFuture<DOMRpcResult, DOMRpcException> response) {
}
return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema, mountPoint,
- schemaContext), resultData);
+ schemaContext), resultData, QueryParametersParser.parseWriterParameters(uriInfo));
}
private RpcDefinition findRpc(final SchemaContext schemaContext, final String identifierDecoded) {
LOG.debug(errMsg + identifier);
throw new RestconfDocumentedException(errMsg, ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
}
- return new NormalizedNodeContext(iiWithData, data);
- }
-
- // FIXME: Move this to proper place
- @SuppressWarnings("unused")
- private Integer parseDepthParameter(final UriInfo info) {
- final String param = info.getQueryParameters(false).getFirst(UriParameters.DEPTH.toString());
- if (Strings.isNullOrEmpty(param) || "unbounded".equals(param)) {
- return null;
- }
-
- try {
- final Integer depth = Integer.valueOf(param);
- if (depth < 1) {
- throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
- "Invalid depth parameter: " + depth, null,
- "The depth parameter must be an integer > 1 or \"unbounded\""));
- }
-
- return depth;
- } catch (final NumberFormatException e) {
- throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
- "Invalid depth parameter: " + e.getMessage(), null,
- "The depth parameter must be an integer > 1 or \"unbounded\""));
- }
+ return new NormalizedNodeContext(iiWithData, data, QueryParametersParser.parseWriterParameters(uriInfo));
}
@Override
- public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo info) {
+ public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode<?, ?> data = null;
LOG.debug(errMsg + identifier);
throw new RestconfDocumentedException(errMsg , ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
}
- return new NormalizedNodeContext(iiWithData, data);
+ return new NormalizedNodeContext(iiWithData, data, QueryParametersParser.parseWriterParameters(uriInfo));
}
@Override
LOG.debug("Update ConfigDataStore fail " + identifier, e);
throw new RestconfDocumentedException(e.getMessage(), e, e.getErrorList());
}
+ } catch (Exception e) {
+ final String errMsg = "Error updating data ";
+ LOG.debug(errMsg + identifier, e);
+ throw new RestconfDocumentedException(errMsg, e);
}
}
throw e;
} catch (final Exception e) {
final String errMsg = "Error creating data ";
- LOG.info(errMsg + uriInfo.getPath(), e);
+ LOG.info(errMsg + (uriInfo != null ? uriInfo.getPath() : ""), e);
throw new RestconfDocumentedException(errMsg, e);
}