Difference between revisions of "SStorageRest"

From Gcube Wiki
Jump to: navigation, search
(Usage examples)
(Getting-Started)
 
(37 intermediate revisions by the same user not shown)
Line 17: Line 17:
 
= Design  and Architecture =
 
= Design  and Architecture =
  
TO-DO
+
The architecture implements a multiton pattern. The records are collected in two separated collection: the first one is a collection dedicated to a single SmartApps, the second One is a collection that collects all the records of all the smartApplications.
  
 
= Access Mode =
 
= Access Mode =
  
TO-DO
+
The Endpoint of the SStorageRest service can be discovered by [https://gcube.wiki.gcube-system.org/gcube/IS-Collector IS-Collector] service under the SmartArea VO.
 +
For accessing to the service it's needed to use the [https://gcube.wiki.gcube-system.org/gcube/Ic-client ic-client] library in the following way:
  
 +
<source lang="java">
 +
import static org.gcube.resources.discovery.icclient.ICFactory.*;
 +
 +
...
 +
 +
 +
XQuery query = queryFor(GCoreEndpoint.class);
 +
query.addCondition("$resource/Profile/ServiceClass/text() eq 'content-management'");
 +
query.addCondition("$resource/Profile/ServiceName/text() eq 'storage'");
 +
query.addVariable("$entry","$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint");
 +
query.addCondition("$entry/@EntryName/string() eq 'jersey-serlvet'");
 +
query.setResult("$entry/text()");
 +
DiscoveryClient<String> client = client();
 +
List<String> addresses = client.submit(query);
 +
 +
</source>
 +
 +
The method "client.submit(query)" returns a List of resources that match the query parameters. In this case the query should return a list with only one element:
 +
 +
<source lang="java">
 +
[http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest]
 +
 +
</source>
  
 
= Supported Operations =
 
= Supported Operations =
  
TO-DO
+
 
 +
* create: implemented by http POST method;
 +
* read :  implemented by http GET method;
 +
* update: implemented by http PUT method;
 +
* delete: implemented by http DELETE method.
  
 
=  Getting-Started =
 
=  Getting-Started =
  
 +
We introduce the API of the <code>SStorageRest</code> through a set of examples.
 +
 +
Note that, in all the examples, we submit queries to the <code>SStorageRest</code> service. We then need to make sure that we do so in a given scope by a valid gcube-token
  
 
== Maven artifacts ==
 
== Maven artifacts ==
 +
The service package is downloadable from the following nexus server: http://maven.research-infrastructures.eu/nexus
  
 +
<source lang="xml">
 +
<groupId>org.gcube.contentmanagement</groupId>
 +
<artifactId>storage-service-rest</artifactId>
 +
<version>...</version>
  
 +
</source>
  
 
==Usage examples ==
 
==Usage examples ==
  
Post method is used to create new resource. Here we are adding new JSON object to the related collection:
+
To insert (create) a new record in the system, we might use:
 
+
* POST n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources?gcube-token=xxxxxxxx
http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources?gcube-token=xxxxxxxx
+
  
 +
To read a object with  ID# 33245:
 +
* GET http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources/33245?gcube-token=xxxxxxxx The same URI would be used for PUT and DELETE, to update and delete, respectively.
  
Use get method to check if above json have been added to the related collection:
+
Here are proposed URIs for products:
 +
* POST http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources?gcube-token=xxxxxxxx for creating a new object.
  
http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources?gcube-token=xxxxxxxxx
+
* GET|PUT|DELETE http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources/33245?gcube-token=xxxxxxxx
 +
for reading, updating, deleting object with id 66432, respectively.
  
In this way the service return all the object in the collection.
+
For deleting all the objects in the collection:
  
= Deployment =
+
* DELETE http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources?gcube-token=xxxxxxxx

Latest revision as of 12:25, 22 December 2017


Overview

A RESTful service providing functions for create, update, read a json object on MongoDB

Key features

The core of the service is java based. It offers a interface for performing CRUD operation through a remote backend over JSON object:

  • Create
  • Read
  • Update
  • Delete


Design and Architecture

The architecture implements a multiton pattern. The records are collected in two separated collection: the first one is a collection dedicated to a single SmartApps, the second One is a collection that collects all the records of all the smartApplications.

Access Mode

The Endpoint of the SStorageRest service can be discovered by IS-Collector service under the SmartArea VO. For accessing to the service it's needed to use the ic-client library in the following way:

import static org.gcube.resources.discovery.icclient.ICFactory.*;
 
...
 
 
XQuery query = queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceClass/text() eq 'content-management'");
query.addCondition("$resource/Profile/ServiceName/text() eq 'storage'");
query.addVariable("$entry","$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint");
query.addCondition("$entry/@EntryName/string() eq 'jersey-serlvet'");
query.setResult("$entry/text()");
DiscoveryClient<String> client = client();
List<String> addresses = client.submit(query);

The method "client.submit(query)" returns a List of resources that match the query parameters. In this case the query should return a list with only one element:

[http://n039.smart-applications.area.pi.cnr.it:8080/storage/rest]

Supported Operations

  • create: implemented by http POST method;
  • read : implemented by http GET method;
  • update: implemented by http PUT method;
  • delete: implemented by http DELETE method.

Getting-Started

We introduce the API of the SStorageRest through a set of examples.

Note that, in all the examples, we submit queries to the SStorageRest service. We then need to make sure that we do so in a given scope by a valid gcube-token

Maven artifacts

The service package is downloadable from the following nexus server: http://maven.research-infrastructures.eu/nexus

<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-service-rest</artifactId>
<version>...</version>

Usage examples

To insert (create) a new record in the system, we might use:

  • POST n039.smart-applications.area.pi.cnr.it:8080/storage/rest/resources?gcube-token=xxxxxxxx

To read a object with ID# 33245:

Here are proposed URIs for products:

for reading, updating, deleting object with id 66432, respectively.

For deleting all the objects in the collection: