Personal tools
You are here: Home GRIA Documentation Documentation 5.2 Tutorials Java Interface Tutorial Registry Service Tutorial 2 - Adding Resources to a Registry

Registry Service Tutorial 2 - Adding Resources to a Registry

This tutorial describes how to add resources to a registry
Tutorials on how to use the GRIA Client Interface API
Page 14 of 15.

In order to register resources in a registry we must first create a proxy to our Registry.

private static String REG_ID
		= "40894e36-16240474-0116-241035c3-0001";
private static String REGISTRY_SERVICE_ENDPOINT 
		= "https://hostname:port/gria-client-mgt/services/CltMgtRegistryService";

StateRepository repository = new MemoryStateRepository();
		RemoteCltMgtRegistryService registryService = (RemoteCltMgtRegistryService)  
			repository.getOrCreateObject(RemoteCltMgtRegistryService.class,
					ConversationID.getEPR(REGISTRY_SERVICE_ENDPOINT));

As an example, we will attempt to register resources from the data service

private static String DATA_SERVICE_ENDPOINT 
		= "https://hostname:port/gria-basic-app-services/services/DataService";

RemoteDataService dataService = (RemoteDataService)  
		repository.getOrCreateObject(RemoteDataService.class,
				ConversationID.getEPR(DATA_SERVICE_ENDPOINT));

Now we create a proxy to our registry resource

EndpointReferenceType regepr = ConversationID.getEPR(REGISTRY_SERVICE_ENDPOINT+"#"+REG_ID);
CltMgtRegistryResourceConversation reg = repository.getOrCreateObject(CltMgtRegistryResourceConversation.class,regepr);

Now try to register the resource in the registry using the 'registerResource' call.

Note : If you are trying to register an SLA in a registry you need to use 'registerMonitorableResource' as this sets an access control rule on the SLA Service allowing the Registry Service to monitor usage of the SLA.

try {
	X509Certificate x509 = dataService.getServiceProviderID().getX509Certificate();
	EndpointReferenceType eprs[] = dataService.getResources();
	for (EndpointReferenceType epr : eprs){
		ConversationID.addKeyInfo(epr,x509);
		ConversationID.setType(epr, DataConversation.class);
		reg.registerResource(epr);
		System.out.println("Adding '"+ConversationID.getLabel(epr)+"' to registry.");
	}		
} catch (Exception e) {
	throw new RuntimeException(e);
}

Full Java Code

package workflow;

import java.rmi.RemoteException;

import javax.swing.JOptionPane;

import org.apache.axis.message.addressing.EndpointReferenceType;

import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;

import uk.ac.soton.ecs.iam.grid.client.staterepos.MemoryStateRepository;
import uk.ac.soton.ecs.iam.grid.comms.client.Conversation;
import uk.ac.soton.ecs.iam.grid.comms.client.DataConversation;
import uk.ac.soton.ecs.iam.grid.comms.client.RemoteDataService;
import uk.ac.soton.ecs.iam.grid.comms.client.RemoteService;
import uk.ac.soton.ecs.iam.grid.comms.client.SLAConversation;
import uk.ac.soton.ecs.iam.grid.comms.client.StateRepository;
import uk.ac.soton.itinnovation.grid.client.registry.CltMgtRegistryResourceConversation;
import uk.ac.soton.itinnovation.grid.client.registry.RemoteCltMgtRegistryService;
import uk.ac.soton.itinnovation.grid.types.ConversationID;
import uk.ac.soton.itinnovation.grid.types.MatchRule;
import uk.ac.soton.itinnovation.grid.types.PolicyRule;
import uk.ac.soton.itinnovation.grid.types.SubjectDescription;

public class RegistryTutorial2 {

	private static String DATA_SERVICE_ENDPOINT 
		= "https://hostname:port/gria-basic-app-services/services/DataService";
	private static String REG_ID
		= "40894e36-16240474-0116-241035c3-0001";
	private static String REGISTRY_SERVICE_ENDPOINT 
			= "https://hostname:port/gria-client-mgt/services/CltMgtRegistryService";

	public static void main(String[] args) {
		
		StateRepository repository = new MemoryStateRepository();
		RemoteCltMgtRegistryService registryService = (RemoteCltMgtRegistryService)  
			repository.getOrCreateObject(RemoteCltMgtRegistryService.class,
					ConversationID.getEPR(REGISTRY_SERVICE_ENDPOINT));

		EndpointReferenceType regepr = ConversationID.getEPR(REGISTRY_SERVICE_ENDPOINT+"#"+REG_ID);
		CltMgtRegistryResourceConversation reg = repository.getOrCreateObject(CltMgtRegistryResourceConversation.class,regepr);
		
		RemoteDataService dataService = (RemoteDataService)  
		repository.getOrCreateObject(RemoteDataService.class,
				ConversationID.getEPR(DATA_SERVICE_ENDPOINT));
		try {
			X509Certificate x509 = dataService.getServiceProviderID().getX509Certificate();
			EndpointReferenceType eprs[] = dataService.getResources();
			for (EndpointReferenceType epr : eprs){
				ConversationID.addKeyInfo(epr,x509);
				ConversationID.setType(epr, DataConversation.class);
				reg.registerResource(epr);
				System.out.println("Adding '"+ConversationID.getLabel(epr)+"' to registry.");
			}		
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		
	}

}