IS-Publisher

From Gcube Wiki
Revision as of 21:56, 1 June 2009 by Manuele.simi (Talk | contribs) (Implementation)

Jump to: navigation, search

In conjunction with the IS-Client and the IS-Notifier, the IS-Publisher represents the mediation layer gCube Services will rely on to interact with the Information Service as a whole.

The role of the IS-Publisher is to feed the IS with:

  • GCUBEResource profiles
  • services' states as of WS-ResourceProperty documents

In addition, it offers a built-in mechanism to publish the GCUBEResource profiles as local events to whichever consumer subscribes for them.

Design

The IS-Publisher is a Java library providing the implementation of two interfaces (ISPublisher and ISLocaLPublisher) defined in the context of the gCore Framework to decouple gCube Services from the specific implementation of the Information Service. Its scope is to allow services to publish GCUBEResource as well as their state in the IS (and this is the role of the ISPublisher interface implementation). Moreover, by implementing also the ISLocalPublisher interface, it provides a subscription/notification mechanism based on local events allowing consumers to be notified about changes in the GCUBEResource published by others within the local GHN. This mechanism is widely exploited by the IS services whenever they are themselves hosted on the local GHN.

Interface

Publishing a profile

In order to publish a GCUBEResource profile the IS-Publisher contacts the IS-Registry service of the publishing scope by invoking its appropriate operations. The following operation can be used to manage profiles on the IS:

  • registerGCUBEResource() – which takes as input parameter a message containing a resource (gCUBEResource), an operational scope (GCUBEScope), i.e. an object representing a scope in the gCube model of VO/VREs, and a security manager (GCUBESecurityManager), i.e. the component keeping track of credentials, and returns a string containing the registered profile if the registration is successful;
  • updateGCUBEResource() – which takes as input parameter a message containing a resource, an operational scope and a security manager and updates a resource previously registered in the IS.
  • removeGCUBEResource() – which takes as input parameter a message containing a resource ID, a resource type, an operational scope and a security manager and removes the corresponding resource previously registered in the IS;
Publishing a service's state

Services' states are represented by a view on the stateful resources data of each service. Such a view is then defined as a WS-ResourceProperty document. The IS-Publisher takes as input the whole GCUBE stateful resource and it is able to extract from there its state and publish it. The following operations allow to publish and unpublish a state:

  • registerWSResource() – which takes as input parameter a message containing a stateful resource (each stateful entity different from a gCube Resource) and optionally the registration name and the scope and register such a resource in the IS;
  • removeWSResource() – which takes as input parameter a message containing a stateful resource (each stateful entity different from a gCube Resource) and optionally the registration name and the scope and removes such a resource.

The update of the state is automatically performed by the underlying framework as explained in the implementation section.

Subscribing for local events
  • subscribeLocalProfileEvents(LocalProfileConsumer consumer) - it subscribes a new consumer as listener of local event. A consumer is an instance of a class extending the LocalProfileConsumer class also defined in the interface. The following methods of the class can be overridden to receive the appropriate callbacks after a modification on any of the local profiles occurred:
    • protected void onProfileRemoved(String resourceID, String type, GCUBEScope scope) - removed profile event callback
    • protected void onProfileUpdated(GCUBEResource resource, GCUBEScope scope) - updated profile event callback.
    • protected void onProfileRegistered(GCUBEResource resource, GCUBEScope scope) - new registered profile event callback.
  • isEnabled(GCUBEScope scope) - it checks if in the given scope, the notification mechanism based on local events is enabled or not.

Implementation

The java library implementing the ISPublisher interface has a two-fold role:

  • starting from a registerWSResource() invocation, it creates an Aggregator Source and registers it to an Aggregator Sink hosted by a IS-IC instance
  • it is mere mediator between the method invocations and the IS-IC and IS-Registry services' stubs for all the other methods exposed by the interface


Through the facilities offered by gCore, the ISPublisher implementation is dynamically bound at runtime any time it is needed with the following line of code:

ISLocalPublisher pubblisher = GHNContext.getImplementation(ISLocalPublisher.class);

Sample usages

GCUBEResource registration

Here it is an example of GCUBEResource registration:

try {
	ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
	GCUBEGenericResource resource = GHNContext.getImplementation(GCUBEGenericResource.class);
	publisher.registerGCUBEResource(resource, this.scope, ServiceContext.getContext());
} catch (Exception e) {			
	logger.error(e);
	throw new Exception("Unable to register the Resource");
}

WSRFResource registration

Here it is an example of WSRFREsource registration:

try {
	ISPublisher publisher=GHNContext.getImplementation(ISPublisher.class);
	publisher.registerWSResource(<instance extends GCUBEWSResource>,scope);
} catch(Exception e) {
	logger.error(e);
	logger.warn("could not publish RPS for "+GCUBEWSResource.this.getClass().getSimpleName()+"("+getID()+") in "+scope,e);}		
}

Registration to Local Events

The following example shows how to register a consumer and be notified for local events occurring in the hosting node:

import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer;
 
 
private void subscribeToLocalRegistrationEvents() throws Exception{
	ISLocalPublisher pub = GHNContext.getImplementation(ISLocalPublisher.class);
	LocalProfileConsumer cons = new LocalProfileConsumer() {
 
	        /* (non-Javadoc)
	         * @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRegistered(org.gcube.common.core.resources.GCUBEResource)
	         */
	        @Override
	        protected void onProfileRegistered(GCUBEResource resource, GCUBEScope scope) {
	            logger.debug("onProfileRegistered event received" );                                   
	            //manage the event...
 
	        }
 
	        /* (non-Javadoc)
	         * @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRemoved(java.lang.String, java.lang.String)
	         */
	        @Override
	        protected void onProfileRemoved(String resourceID, String type, GCUBEScope scope) {
	            logger.trace("onProfileRemoved event received");
	            //manage the event...	        		                               
	        }
 
	        /* (non-Javadoc)
	         * @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileUpdated(org.gcube.common.core.resources.GCUBEResource)
	         */
	        @Override
	        protected void onProfileUpdated(GCUBEResource resource, GCUBEScope scope) {
	            logger.trace("onProfileUpdated event received");
	            //manage the event...	        		                               
	        }
 
 
	    };
 
    pub.subscribeLocalProfileEvents(cons);
}