Resource Registry Service - Instances Management

From Gcube Wiki
Revision as of 17:08, 8 November 2017 by Luca.frosini (Talk | contribs) (Query & Access)

Jump to: navigation, search

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


ER Management

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


Resource Registry Publisher has the following maven coordinates

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

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

By using ResourceRegistryPublisherFactory.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
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();


Facet Instances APIs

Create Facet Instance

REST API
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"
}
Java API
public <F extends Facet> F createFacet(F facet) throws FacetAlreadyPresentException, ResourceRegistryException;
Example
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");

CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
UUID uuid = createdCpuFacet.getHeader().getUUID(); // 69f0b376-38d2-4a85-bc63-37f9fa323f82


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

public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException;

public String createFacet(String facetType, String facet) throws FacetAlreadyPresentException, ResourceRegistryException;

The first methods get the Facet to be created as JSON string instead of as Java class. The second get also the facetType 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 facetType is the same specified in the header of the serialized facet.

Update Facet Instance

REST API
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);

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/69f0b376-38d2-4a85-bc63-37f9fa323f82

Response Body

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

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.

Resource Instances APIs

Create Resource Instance

REST API
PUT /resource-registry/er/resource/HostingNode

Request Body

{
	"@class":"HostingNode",
	"consistsOf":[
		{ 
			"@class":"ConsistsOf", 
			"target":{ 
				"@class":"CPUFacet",
				"model":"Opteron",
				"vendor":"AMD",
				"clockSpeed":"3 GHz"
			}
		},{
			"@class":"IsIdentifiedBy", 
			"target":{ 
				"@class":"NetworkingFacet",
				"header":{"uuid":"59617b01-5856-4d8e-b85c-590a42039933"}, 
/* In this example we suppose that the NetworkingFacet was already created, so the UUID is enought to attach it by using IsIdentifiedBy relation */
			}
		}
	],
	"isRelatedTo":[
		{
			"@class":"Hosts",
			"propagationConstraint":{
				"add":"unpropagate",
				"remove": "cascade"
			},
			"target":{
				"@class":"EService",
				"header":{"uuid":"9bff49c8-c0a7-45de-827c-accb71defbd3"} 
/* The EService was already created, so the UUID is enought to attach it by using Hosts relation */
			}
		}
	]
}

Response

{
	"@class":"HostingNode",
	"header":{"uuid":"670eeabf-76c7-493f-a449-4e6e139a2e84"},
	"consistsOf":[
		{ 
			"@class":"ConsistsOf",
			"header":{"uuid":"9d0b1b2b-ac4e-40a9-8dea-bec90076e0ca", ...},
			"target":{ 
				"@class":"CPUFacet",
				"header":{"uuid":"1daef6a8-5ca4-4700-844b-2a2d784e17b0", ...},
				"model":"Opteron",
				"vendor":"AMD",
				"clockSpeed":"1 GHz"
			}
		},{
			"@class":"IsIdentifiedBy",
			"header":{"uuid":"02a7072c-4f72-4568-945b-9ddccc881e9f", ...},
			"target":{ 
				"@class":"NetworkingFacet",
				"header":{"uuid":"59617b01-5856-4d8e-b85c-590a42039933", ...},
				"ipAddress" : "146.48.87.183",
				"hostName": "pc-frosini.isti.cnr.it",
				"domainName" : "isti.cnr.it",
				"mask" : "255.255.248.0",
				"broadcastAddress":"146.48.87.255"
			}
		}
	],
	"isRelatedTo":[
		{
			"@class":"Hosts",
			"header":{"uuid":"47494ad0-e606-4630-9def-4c607761ae14", ...},
			"propagationConstraint":{
				"add":"unpropagate",
				"remove": "cascade"
			},
			"target":{
				"@class":"EService",
				"header":{"uuid":"9bff49c8-c0a7-45de-827c-accb71defbd3", ...}
			}
		}
	]
}
Java API
public <R extends Resource> R createResource(R resource) throws ResourceAlreadyPresentException, ResourceRegistryException;
Example
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
networkingFacet.setIPAddress("146.48.87.183");
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
networkingFacet.setDomainName("isti.cnr.it");
networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255");

networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet);

HostingNode hostingNode = new HostingNodeImpl();

CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
hostingNode.addFacet(cpuFacet);

isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(hostingNode, networkingFacet, null);
hostingNode.attachFacet(isIdentifiedBy);

PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);

Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(hostingNode, eService, propagationConstraint);
hostingNode.attachResource(hosts);

hostingNode = resourceRegistryPublisher.createResource(hostingNode);


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

public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException;

public String createResource(String resourceType, String resource) throws ResourceAlreadyPresentException, ResourceRegistryException;

The first methods get the Resource to be created as JSON string instead of as Java class. The second get also the resourceType 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 resourceType is the same specified in the header of the serialized resource.

Update Resource Instance

REST API
POST /resource-registry/er/resource/670eeabf-76c7-493f-a449-4e6e139a2e84

Request Body

{
	"@class":"HostingNode",
	"header":{"uuid":"670eeabf-76c7-493f-a449-4e6e139a2e84", ...},
	"consistsOf":[
		{ 
			"@class":"ConsistsOf",
			"header":{"uuid":"9d0b1b2b-ac4e-40a9-8dea-bec90076e0ca", ...},
			"target":{ 
				"@class":"CPUFacet",
				"header":{"uuid":"1daef6a8-5ca4-4700-844b-2a2d784e17b0", ...},
				"model":"Opteron",
				"vendor":"AMD",
				"clockSpeed":"1 GHz" 
			}
		},{
			"@class":"IsIdentifiedBy",
			"header":{"uuid":"02a7072c-4f72-4568-945b-9ddccc881e9f", ...},
			"target":{ 
				"@class":"NetworkingFacet",
				"header":{"uuid":"59617b01-5856-4d8e-b85c-590a42039933", ...},
				"ipAddress" : "146.48.87.183",
				"hostName": "pc-frosini.isti.cnr.it",
				"domainName" : "isti.cnr.it",
				"mask" : "255.255.248.0",
				"broadcastAddress":"146.48.87.255",
				"username":"luca.frosini" /* Added this property */
			}
		}
	]
}

Response

{
	"@class":"HostingNode",
	"header":{"uuid":"670eeabf-76c7-493f-a449-4e6e139a2e84", ...},
	"consistsOf":[
		{ 
			"@class":"ConsistsOf",
			"header":{"uuid":"9d0b1b2b-ac4e-40a9-8dea-bec90076e0ca", ...},
			"target":{ 
				"@class":"CPUFacet",
				"header":{"uuid":"1daef6a8-5ca4-4700-844b-2a2d784e17b0", ...},
				"model":"Opteron",
				"vendor":"AMD",
				"clockSpeed":"1 GHz"
			}
		},{
			"@class":"IsIdentifiedBy",
			"header":{"uuid":"02a7072c-4f72-4568-945b-9ddccc881e9f", ...},
			"target":{ 
				"@class":"NetworkingFacet",
				"header":{"uuid":"59617b01-5856-4d8e-b85c-590a42039933", ...},
				"ipAddress" : "146.48.87.183",
				"hostName": "pc-frosini.isti.cnr.it",
				"domainName" : "isti.cnr.it",
				"mask" : "255.255.248.0",
				"broadcastAddress":"146.48.87.255",
				"username":"luca.frosini"
			}
		}
	]
}
Java API
public <R extends Resource> R updateResource(R resource) throws ResourceNotFoundException, ResourceRegistryException;
Example

/* This is just a code example, here we suppose that there is only one identification Facet of the type (NetworkingFacet). This could not be true  in real scenario*/
networkingFacet = (NetworkingFacet) hostingNode.getIdentificationFacets().get(0);
networkingFacet.setAdditionalProperty("username", "luca.frosini");
		
hostingNode = resourceRegistryPublisher.updateResource(hostingNode);

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

public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException;
public String updateResource(UUID uuid, String resource) throws ResourceNotFoundException, ResourceRegistryException;

The first methods get the Resource 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 uuid is the same specified in the header of the serialized resource.

Delete Resource Instance

REST API
DELETE /resource-registry/er/resource/670eeabf-76c7-493f-a449-4e6e139a2e84
Java API
public <R extends Resource> boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException;
Example
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);

There is also another equivalent methods with the following signature:

public boolean deleteResource(UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;

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

Relation Instances APIs

ConsistsOf

Create ConsistsOf Instance
REST API

Example 1

PUT /resource-registry/er/consistsOf/IsIdentifiedBy

In this example the target Facet already exists. The Service set automatically the Facet_Based_Resource_Model#PropagationConstraint Propagation Constraint to default values (i.e. remove=cascadeWhenOrphan, add=propagate)

Request Body

{
	"@class":"IsIdentifiedBy", 
	"source" : {
		"@class":"HostingNode",
		"header":{"uuid":"670eeabf-76c7-493f-a449-4e6e139a2e84"} // The HostingNode must be already created. The header with UUId is enough.
	}
	"target":{ 
		"@class":"NetworkingFacet",
		"header":{"uuid":"59617b01-5856-4d8e-b85c-590a42039933"}, 
		/* In this example we suppose that the NetworkingFacet already exists, so the UUID is enought to attach it by using IsIdentifiedBy relation */
	}
}

Response

{
	"@class":"IsIdentifiedBy",
	"propagationConstraint":{
		"add":"propagate",
		"remove": "cascadeWhenOrphan"
	},
	"header":{"uuid":"02a7072c-4f72-4568-945b-9ddccc881e9f", ...},
	"target":{ 
		"@class":"NetworkingFacet",
		"header":{"uuid":"59617b01-5856-4d8e-b85c-590a42039933", ...},
		"ipAddress" : "146.48.87.183",
		"hostName": "pc-frosini.isti.cnr.it",
		"domainName" : "isti.cnr.it",
		"mask" : "255.255.248.0",
		"broadcastAddress":"146.48.87.255"
	}
}

Example 2

PUT /resource-registry/er/consistsOf/ConsistsOf

In this example the target Facet is created contestually with ConsistsOf relation. Moreover the Facet_Based_Resource_Model#PropagationConstraint Propagation Constraint are explicitly set (i.e. remove=cascade, add=propagate).

Request Body

{
	"@class":"ConsistsOf", 
	"propagationConstraint":{
		"add":"propagate",
		"remove": "cascade"
	},
	"source" : {
		"@class":"HostingNode",
		"header":{"uuid":"670eeabf-76c7-493f-a449-4e6e139a2e84"} // The HostingNode must be already created. The header with UUId is enough.
	}
	"target":{ 
		"@class":"CPUFacet",
		"model":"Opteron",
		"vendor":"AMD",
		"clockSpeed":"3 GHz"
	}
}

Response

{
	"@class":"ConsistsOf",
	"header":{"uuid":"9bff49c8-c0a7-45de-827c-accb71defbd3", ...},
	"propagationConstraint":{
		"add":"propagate",
		"remove": "cascade"
	},
	"target":{ 
		"@class":"CPUFacet",
		"header":{"uuid":"1daef6a8-5ca4-4700-844b-2a2d784e17b0", ...},
		"model":"Opteron",
		"vendor":"AMD",
		"clockSpeed":"1 GHz"
	}
}
Java API
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException;

Example 1

IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(hostingNode, networkingFacet, null);
resourceRegistryPublisher.createConsistsOf(isIdentifiedBy);

Example 2

CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");

PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint.setAddConstraint(AddConstraint.propagate);

ConsistsOf consistsOf = new ConsistsOfImpl<Resource, Facet>(hostingNode, cpuFacet, propagationConstraint);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);


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

public String createConsistsOf(String consistsOfType, String consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException;
	
public String createConsistsOf(String consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException;

The first methods get the Resource to be created as JSON string instead of as Java class. The second get also the consistsOfType 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 consistsOfType is the same specified in the header of the serialized resource.

Delete ConsistsOf Instance
REST API
DELETE /resource-registry/er/consistsOf/02a7072c-4f72-4568-945b-9ddccc881e9f
DELETE /resource-registry/er/consistsOf/9bff49c8-c0a7-45de-827c-accb71defbd3


Java API
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf) throws ResourceRegistryException;
boolean deleted = resourceRegistryPublisher.deleteConsistsOf(isIdentifiedBy);
boolean deleted = resourceRegistryPublisher.deleteConsistsOf(consistsOf);


There is also another equivalent methods with the following signature:

public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException;


UUID uuid = UUID.fromString("9bff49c8-c0a7-45de-827c-accb71defbd3")
boolean deleted = resourceRegistryPublisher.deleteConsistsOf(uuid);

The method just need the UUID of the ConsistsOf relation to be deleted.