Difference between revisions of "Resource Registry Service - Instances Management"

From Gcube Wiki
Jump to: navigation, search
m (Create via Java API)
(Create via Java API)
Line 91: Line 91:
 
</pre>
 
</pre>
  
 +
The first method gets any instance of IdentifiableElement (i.e. Resources, Facets, ConsistsOf, IsRelatedTo)
 
The second method gets the instance to be created as a JSON string instead of a Java class.  
 
The second method gets the instance to be created as a JSON string instead of a Java class.  
  
  
 
===== Create via Java API Example =====
 
===== Create via Java API Example =====
<pre>
+
<source lang="Java">
CPUFacet cpuFacet = new CPUFacetImpl();
+
EService eService = new EServiceImpl();
cpuFacet.setClockSpeed("1 GHz");
+
UUID uuid = UUID.fromString("7f37a79d-0c00-4166-8a68-165de0a438bf");
cpuFacet.setModel("Opteron");
+
Header header = new HeaderImpl(uuid);
cpuFacet.setVendor("AMD");
+
eService.setHeader(header);
  
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
+
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
UUID uuid = createdCpuFacet.getHeader().getUUID(); // 69f0b376-38d2-4a85-bc63-37f9fa323f82
+
softwareFacet.setGroup("WhnManager");
</pre>
+
softwareFacet.setName("VREManagement");
 +
softwareFacet.setVersion("2.0.0-4.15.0-132431");
 +
softwareFacet.setDescription("Web Hosting Node Service");
 +
 
 +
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService,
 +
softwareFacet, null);
 +
eService.addFacet(isIdentifiedBy);
 +
 
 +
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
 +
accessPointFacet.setEndpoint(new URI("http://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager"));
 +
accessPointFacet.setEntryName("whnmanager");
 +
ValueSchema authz = new ValueSchemaImpl();
 +
authz.setValue("gcube-token");
 +
accessPointFacet.setAuthorization(authz);
 +
eService.addFacet(accessPointFacet);
 +
 
 +
AccessPointFacet accessPointFacet2 = new AccessPointFacetImpl();
 +
accessPointFacet2.setEndpoint(new URI("http://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource"));
 +
accessPointFacet2.setEntryName("WhnManager-remote-management");
 +
ValueSchema authz2 = new ValueSchemaImpl();
 +
authz2.setValue("gcube-token");
 +
accessPointFacet2.setAuthorization(authz2);
 +
eService.addFacet(accessPointFacet2);
 +
 
 +
 
 +
EventFacet eventFacet = new EventFacetImpl();
 +
eventFacet.setDate(Calendar.getInstance().getTime());
 +
ValueSchema event = new ValueSchemaImpl();
 +
event.setSchema(new URI("String"));
 +
event.setValue("started");
 +
eventFacet.setEvent(event);
 +
eService.addFacet(eventFacet);
 +
 
 +
StateFacet stateFacet = new StateFacetImpl();
 +
stateFacet.setValue("started");
 +
eService.addFacet(stateFacet);
 +
 
 +
 
 +
eService = resourceRegistryPublisher.create(eService);
 +
 
 +
resourceRegistryPublisher.delete(eService);
 +
</source>
  
 
==== Create via REST API ====
 
==== Create via REST API ====

Revision as of 11:30, 5 July 2021

These sections provide information regarding how to interact with Resource Registry Service for Entities and Relations instances Management. 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.

Instances Management

The Instances Management port type is responsible for the management of entities and relation instances. It offers the following APIs:

  • List: it allows to list instances of a certain type;
  • Create: it allows to create a new entity or relation instance in a certain context;
  • Exists: it allows to check if an instance exists in a certain context;
  • Read: it allows to get the representation of the requested instance in a certain context;
  • Update: it allows to update an instance in a certain context;
  • Delete: it allows to delete an instance.

The Instances Management implements the following policies:

  • it manages the Header automatically;
  • it allows identifying an instance via the Universally Unique Identifier (UUID) specified in the Header;
  • it allows the creation of an instance only if the declared type is already present in the system (previously registered via the Types Collection;
  • it validates the instance against the schema of the defined type;
  • it imposes the default values of propagation constraints (IsRelatedTo (remove=keep, add=unpropagate); ConsistsOf (remove=cascadeWhenOrphan, add=propagate).) when the client does not specify their values;
  • it guarantees propagation constraints.

Instances Collection

The following table shows the exposed APIs as REST Collection

Operation HTTP Method URL
List GET /instances/{TYPE_NAME}[?polymorphic=true]
Create PUT /instances/{TYPE_NAME}/{UUID}
Exists GET /instances/{TYPE_NAME}/{UUID}
Read GET /instances/{TYPE_NAME}/{UUID}
Update PUT /instances/{TYPE_NAME}/{UUID}
Delete DELETE /instances/{TYPE_NAME}/{UUID}

Security configuration based on Authorization Framework make this port type accessible only from Resource Manager. In other words, no others client is allowed to manage types rather than Resource Manager.

Resource Registry Publisher

Resource Registry Publisher is a java library providing RPC facilities to interact with Instances Management and Instances Sharing Management. The library hides all the complexity of marshalling and unmarshalling of requests and results. By using this library any client is able to manage java classes instead of JSON objects.

To use the Java library to interact with Instances Collection declare the following dependency in your pom.xml file.

<dependency>
	<groupId>org.gcube.information-system</groupId>
	<artifactId>resource-registry-publisher</artifactId>
	<version>[4.0.0,5.0.0-SNAPSHOT)</version>
<dependency>

To use the client you just need to instantiate the client via the provided factory.

import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
 
...
 
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();

APIs

Create Instance

Create via Java API

public <IE extends IdentifiableElement> IE create(IE er) throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException;

public String create(String json) throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException;

The first method gets any instance of IdentifiableElement (i.e. Resources, Facets, ConsistsOf, IsRelatedTo) The second method gets the instance to be created as a JSON string instead of a Java class.


Create via Java API Example
EService eService = new EServiceImpl();
UUID uuid = UUID.fromString("7f37a79d-0c00-4166-8a68-165de0a438bf");
Header header = new HeaderImpl(uuid);
eService.setHeader(header);
 
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("WhnManager");
softwareFacet.setName("VREManagement");
softwareFacet.setVersion("2.0.0-4.15.0-132431");
softwareFacet.setDescription("Web Hosting Node Service");
 
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService,
		softwareFacet, null);
eService.addFacet(isIdentifiedBy);
 
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("http://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager"));
accessPointFacet.setEntryName("whnmanager");
ValueSchema authz = new ValueSchemaImpl();
authz.setValue("gcube-token");
accessPointFacet.setAuthorization(authz);
eService.addFacet(accessPointFacet);
 
AccessPointFacet accessPointFacet2 = new AccessPointFacetImpl();
accessPointFacet2.setEndpoint(new URI("http://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource"));
accessPointFacet2.setEntryName("WhnManager-remote-management");
ValueSchema authz2 = new ValueSchemaImpl();
authz2.setValue("gcube-token");
accessPointFacet2.setAuthorization(authz2);
eService.addFacet(accessPointFacet2);
 
 
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
ValueSchema event = new ValueSchemaImpl();
event.setSchema(new URI("String"));
event.setValue("started");
eventFacet.setEvent(event);
eService.addFacet(eventFacet);
 
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("started");
eService.addFacet(stateFacet);
 
 
eService = resourceRegistryPublisher.create(eService);
 
resourceRegistryPublisher.delete(eService);

Create via REST API

PUT /resource-registry/er/facet/{FacetType}
Example
PUT /resource-registry/er/facet/CPUFacet

Request Body

{
	"@class":"CPUFacet",
	"header":null,
	"model":"Opteron",
	"vendor":"AMD",
	"clockSpeed":"1 GHz"
}

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"
}

Update Facet Instance

REST API

POST /resource-registry/er/facet/{Facet Instance UUID}
Example
POST /resource-registry/er/facet/69f0b376-38d2-4a85-bc63-37f9fa323f82

Request Body

{
	"@class":"CPUFacet",
	"header":{"uuid":"69f0b376-38d2-4a85-bc63-37f9fa323f82"}, /* if you pass the header only the UUID is checked and must be the same of the one provided in the URL*/
	"model":"Opteron",
	"vendor":"AMD",
	"clockSpeed":"2 GHz"
}

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:17:32"
	},
	"model":"Opteron",
	"vendor":"AMD",
	"clockSpeed":"2 GHz"
}

Java API

public <F extends Facet> F updateFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
Example
createdCpuFacet.setClockSpeed("2 GHz");
CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(createdCpuFacet);

Alternative JAVA API

There are also two other equivalent methods with the following signature:

public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException;
public String updateFacet(UUID uuid, String facet) throws FacetNotFoundException, ResourceRegistryException;

The first methods get the Facet to be created as JSON string instead of as Java class. The second get also the uuid as parameter (which as to be specified as PATH PARAMETER in the request) avoiding to force client to retrieve it from the string. The second method is more efficient but you have to be sure that the provided uuid is the same specified in the header of the serialized facet.

Delete Facet Instance

REST API

DELETE /resource-registry/er/facet/{Facet Instance UUID}
Example
DELETE /resource-registry/er/facet/69f0b376-38d2-4a85-bc63-37f9fa323f82

Java API

public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
Example
boolean deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet);

Alternative JAVA API

There is also another equivalent methods with the following signature:

public boolean deleteFacet(UUID uuid) throws FacetNotFoundException, ResourceRegistryException;

The method just need the UUID of the Facet to be deleted.