Difference between revisions of "Resource Registry Service - Query & Access"

From Gcube Wiki
Jump to: navigation, search
(Example 2)
(Example 2)
Line 175: Line 175:
 
{
 
{
 
"@class":"IsIdentifiedBy",
 
"@class":"IsIdentifiedBy",
"header":{"uuid":"aa1340d3-2229-497f-9eeb-cc7db93950fe", ...},
+
"header":{"uuid":"5e8cf3e3-8c75-49d4-98db-95d4d08d61f9", ...},
 
"target":{  
 
"target":{  
 
"@class":“SoftwareFacet",
 
"@class":“SoftwareFacet",
"header":{"uuid":"187bee6d-6742-49a7-be89-68bdb0f2f221", ...},
+
"header":{"uuid":"3715696d-796f-4e92-98a3-f9a38a2f8d5e", ...},
 
“group": "Accounting",
 
“group": "Accounting",
 
“name" : "accounting-aggregator-se-plugin",
 
“name" : "accounting-aggregator-se-plugin",

Revision as of 13:09, 9 November 2017

This sections provide information regarding how to interact with Resource Registry Service for Query and Access. REST and JAVA API are presented for each functionality.

Please note that the provided examples can intentionally hide some details in the response to avoid unneeded complexity.

Apart the REST API this port type can be used also by using Resource Registry Client java client.

Resource Registry Client has the following maven coordinates

<dependency>
	<groupId>org.gcube.information-system</groupId>
	<artifactId>resource-registry-client</artifactId>
	<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>

To use the client you need first get a ResourceRegistryClient instance.

By using ResourceRegistryClientFactory.create() method the library discover the correct endpoint to interact with the Resource Registry for the current context.

SecurityTokenProvider.instance.set("Your-NextNext-Token-Here"); //If not already set
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();

Exists

REST API

HEAD /resource-registry/access/instance/{ER Type}/{Instance UUID}
Example
HEAD /resource-registry/access/instance/ContactFacet/4d28077b-566d-4132-b073-f4edaf61dcb9

Java API

public <ERType extends ER> boolean exists(Class<ERType> clazz, UUID uuid) throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException;
Example
UUID uuid = UUID.fromString("4d28077b-566d-4132-b073-f4edaf61dcb9");
resourceRegistryClient.exists(ContactFacet.class, uuid);

Alternative Java API

public boolean exists(String type, UUID uuid) throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException;
Example
UUID uuid = UUID.fromString("4d28077b-566d-4132-b073-f4edaf61dcb9");
resourceRegistryClient.exists("ContactFacet", uuid);

Get Instance

REST API

GET /resource-registry/access/instance/{ER Type}/{Instance UUID}
Example
GET /resource-registry/access/instance/CPUFacet/69f0b376-38d2-4a85-bc63-37f9fa323f82


Response Body

{ 
	"@class":"CPUFacet",
	"header": {
		"uuid":"69f0b376-38d2-4a85-bc63-37f9fa323f82",
		"creator":"luca.frosini",
		"lastUpdater":"luca.frosini",
		"creationTime":"2016-10-05 11:16:24",
		"lastUpdateTime":"2016-10-05 11:16:24
	},
	"model":"Opteron",
	"vendor":"AMD",
	"clockSpeed":"1 GHz"
}

Java API

public <ERType extends ER> ERType getInstance(Class<ERType> clazz, UUID uuid) throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException;
Example
UUID uuid = UUID.fromString("69f0b376-38d2-4a85-bc63-37f9fa323f82");
CPUFacet cpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);

Alternative Java API

public String getInstance(String type, UUID uuid) throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException;
Example
UUID uuid = UUID.fromString("69f0b376-38d2-4a85-bc63-37f9fa323f82");
String cpuFacetString = resourceRegistryClient.getInstance("CPUFacet" uuid);

Get All Instances of a Specific Type

REST API

GET /resource-registry/access/instances/{ER Type}?[polymorphic=(true|false)]

Default:

  • polymorphic=false
Example 1
GET /resource-registry/access/instances/EService

Response

[
	{
		"@class":“EService",
		"header":{"uuid":"0717b450-a698-11e2-900a-a46c6ff57f05", ...},
		"consistsOf":[
			{
				"@class":"IsIdentifiedBy",
				"header":{"uuid":"aa1340d3-2229-497f-9eeb-cc7db93950fe", ...},
				"target":{ 
					"@class":"SoftwareFacet",
					"header":{"uuid":"187bee6d-6742-49a7-be89-68bdb0f2f221", ...},
					“group": "DataStorage",
					“name" : "StorageManager",
					“version" : “2.3.0-0",
				}
			},{
				"@class":"ConsistsOf",
				"header":{"uuid":"1f5b5608-4a91-4fe3-a7c2-edf3aeb5dbd7", ...},
				"target": { 
					"@class":"AccessPointFacet",
					"header":{"uuid":" 3b6061f9-e2ab-4c01-b3b2-48b470a5b8a ", ...},
					endpoint  :  "mongo3-p-d4s.d4science.org"
					description  : "MongoDB server"
					authorization	: {
						@class	"ValueSchema"
						value	"d4sUser:Nxae6MegJrITUD6wyBTimw=="
						schema	"USERNAME:PASSWORD“
					}
				}
			}
		]
	}, 
	....
]
Example 2
GET /resource-registry/access/instances/EService?polymorphic=true

Response

[
	{
		"@class":"RunningPlugin",
		"header":{"uuid":"66d69dab-203e-45ff-b49e-a8fa4126a392"},
		"consistsOf":[
			{
				"@class":"IsIdentifiedBy",
				"header":{"uuid":"5e8cf3e3-8c75-49d4-98db-95d4d08d61f9", ...},
				"target":{ 
					"@class":“SoftwareFacet",
					"header":{"uuid":"3715696d-796f-4e92-98a3-f9a38a2f8d5e", ...},
					“group": "Accounting",
					“name" : "accounting-aggregator-se-plugin",
					“version" : “1.3.0",
				}
			},
			...
		]
	},
	{
		"@class":“EService",
		"header":{"uuid":"0717b450-a698-11e2-900a-a46c6ff57f05", ...},
		"consistsOf":[
			{
				"@class":"IsIdentifiedBy",
				"header":{"uuid":"aa1340d3-2229-497f-9eeb-cc7db93950fe", ...},
				"target":{ 
					"@class":"SoftwareFacet",
					"header":{"uuid":"187bee6d-6742-49a7-be89-68bdb0f2f221", ...},
					“group": "DataStorage",
					“name" : "StorageManager",
					“version" : “2.3.0-0",
				}
			},{
				"@class":"ConsistsOf",
				"header":{"uuid":"1f5b5608-4a91-4fe3-a7c2-edf3aeb5dbd7", ...},
				"target": { 
					"@class":"AccessPointFacet",
					"header":{"uuid":" 3b6061f9-e2ab-4c01-b3b2-48b470a5b8a ", ...},
					endpoint  :  "mongo3-p-d4s.d4science.org"
					description  : "MongoDB server"
					authorization	: {
						@class	"ValueSchema"
						value	"d4sUser:Nxae6MegJrITUD6wyBTimw=="
						schema	"USERNAME:PASSWORD“
					}
				}
			},
			....
		]
	}, 
	....
]

Java API

public <ERType extends ER> List<ERType> getInstances(Class<ERType> clazz, Boolean polymorphic) throws ResourceRegistryException;
Example 1
List<EService> eServices = resourceRegistryClient.getInstances(EService.class, false);
Example 2
List<EService> eServices = resourceRegistryClient.getInstances(EService.class, true);

Alternative Java API

public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException;
Example 1
String eServices = resourceRegistryClient.getInstances("EService", false);
Example 2
String eServices = resourceRegistryClient.getInstances("EService", true);

Get All Instances of a Specific Type in relation with a specific entity instance

REST API

GET /resource-registry/access/instances/{ER Type}?[polymorphic=(true|false)]&reference={Instance UUID}&direction=(in|out|both)

Default:

  • polymorphic : false
  • direction : both
Example
GET /resource-registry/access/instances/EService?polymorphic=true&reference=4d28077b-566d-4132-b073-f4edaf61dcb9&direction=out

Java API

Example

Get Filtered Resource Instances

REST API

GET /resource-registry/access/resourceInstances/{Resource Type}/{ConsistsOf Type}/{Facet Type}?[polymorphic=(true|false)]&key1=value1&key2=value2&...

Default:

  • polymorphic : false
Example
GET /resource-registry/access/resourceInstances/EService/IsIdentifiedBy/SoftwareFacet?polymorphic=true&group=DataAccess&name=HomeLibraryWebapp

Java API

public <R extends Resource> List<R> getFilteredResources(Class<R> resourceClass, Class<? extends ConsistsOf> consistsOfClass, Class<? extends Facet> facetClass,boolean polymorphic, Map<String, Object> map) throws ResourceRegistryException
Example
Map<String, Object> map = new HashMap<>();
map.put("group", "DataAccess");
map.put("name", "HomeLibraryWebapp");
		
List<EService> eServices = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, map);

Alternative Java API

public List<Resource> getFilteredResources(String resourceType, String consistsOfType, String facetType, boolean polymorphic, Map<String, Object> map) throws ResourceRegistryException;

Raw Query

REST API

Example
GET /resource-registry/access?query=SELECT FROM Facet

Java API

Example

Read Context

Allow to read the definition of a Context.

REST API

This API is also exposed in Context Port Type

GET /resource-registry/access/context/{Context UUID}
Example

Read the Context having UUID 9d73d3bd-1873-490c-b0a7-e3c0da11ad52

Request URL

GET /resource-registry/context/9d73d3bd-1873-490c-b0a7-e3c0da11ad52

Response Body

{
	"@class":"Context",
	"name":"devVRE",
	"header": {
		"@class":"Header",
		"uuid":"9d73d3bd-1873-490c-b0a7-e3c0da11ad52",
		"creator":"luca.frosini",
		"lastUpdater":"luca.frosini",
		"creationTime":"2017-03-17 11:47:56",
		"lastUpdateTime":"2017-03-17 11:52:56"
	}
}

Read Type Definition

Allow to read Type Definition This API is also exposed in Access Port Type

REST API

GET /resource-registry/access/schema/{ Type Name } 
Example
GET /resource-registry/schema/ContactFacet

Response

{
	"name":"ContactFacet",
	"description":"This facet is expected to capture contact information",
	"abstractType": false,
	"superclasses":["Facet"],
	"properties":[
		{
			"name":"name",
			"description":"First Name",
			"mandatory":true,
			"readonly":false,
			"notnull":true,
			"max":null,
			"min":null,
			"regexpr":null,
			"linkedType":null,
			"linkedClass":null,
			"type":7 /* String*/
		},{
			"name":"eMail",
			"description": "A restricted range of RFC‑822 compliant email address. ... ",
			"mandatory":true,
			"readonly":false,
			"notnull":true,
			"max":null,
			"min":null,
			"regexpr":"^[a-z0-9._%+-]{1,128}@[a-z0-9.-]{1,128}$",
			"linkedType":null,
			"linkedClass":null,
			"type":7 /* String */
		}
	]
}