beautypg.com

9 error handling, 10 concurrency control using etags, Querying resources – HP OneView User Manual

Page 80

background image

You can then perform a GET on the TaskResource model URI to poll for the status of the
asynchronous operation. The TaskResource model also contains the name and URI of the resource
that is affected by the task in the associatedResource attribute.

Creating an appliance backup example

1.

Create an appliance backup.

/rest/backups

The URI of a TaskResource in the Location header is returned in the response.

2.

Poll for status of the backup using the TaskResource URI returned in step 1.

/rest/tasks/{id}

3.

When the task reaches the Completed state, use the associatedResource URI in the TaskResource to
download the backup file.

GET {associatedResource URI}

5.9 Error handling

If an error occurs during a REST API operation, a 4xx (client-side) or 5xx (appliance) error is
returned along with an error message (ErrorMessage resource model). The error message
contains a description and might contain recommended actions to correct the error.

A successful REST API POST operation returns the newly created resource (synchronous) or a
TaskResource

URI in the Location header (asynchronous).

5.10 Concurrency control using etags

A client uses etags to verify the version of the resource model. This prevents the client from modifying
(PUT) a version of the resource model that is not current. For example, if a client performs a GET
on a server profile and receives an etag in the response header, modifies the server profile, and
then updates (PUT) the resource model, the etag in the PUT request header must match the resource
model etag. If the etags do not match, the client PUT request will not complete and a 412
PRECONDITION FAILED

error is returned.

5.11 Querying resources and pagination using common REST API
parameters

Querying resources

You can use a set of common parameters to customize the results returned from a GET operation,
such as sorting or filtering. Each REST API specification lists the set of available common parameters.

Pagination when querying for a collection of resources

When you perform a GET operation to retrieve multiple resources (that is, a GET on a collection
URI, such as /rest/server-profiles), the resources are returned in a collection object that
includes an array of resources along with information about the set of resources returned. This
collection of resources may be automatically truncated into pages to improve performance when
a query would return a large number of resources. The collection attributes (described below)
provide information needed to determine whether the full set of resources were returned, or if
additional queries are required to retrieve additional pages.

For example, a collection object includes a next page and previous page URI. These URIs indicate
whether additional pages are available, and can be retrieved via a GET operation on these URIs.
This provides a simple model for ensuring all resources in the query have been retrieved, by doing
iterative GETs on the nextPageUri attribute until the attribute comes back empty/null (See
Example: Return all resources in a specific collection query below.).

80

Using the REST APIs and other programmatic interfaces