Difference between revisions of "Managing State"

From GCube System
Jump to: navigation, search
(How to persist the state)
(How to persist the state)
Line 166: Line 166:
  
 
== How to persist the state ==
 
== How to persist the state ==
The gCF contains a persistence framework that implements GCUBE WS-Resource serialization and deserialization from and to some form of long-term storage.
+
The gCore Framework comes with a persistence mini-framework that implementing <code>GCUBEResource</code> serialization and deserialization from/to some form of long-term storage.  
The Alpha Release comes with a local File Based persistence implementation. Future releases will contain a new implementation for Grid persistence, by exploiting the GAS (Grid Access Service)
+
 
+
=== How to enable persistence ===
+
As most of gCF facilities, GCUBEResource Persistence can be enabled by modifying the gCube Service JNDI file by declaring in the Home resource the persistence delegate class to use:
+
<pre>
+
 
+
<jndiConfig xmlns="http://wsrf.globus.org/jndi/config">
+
 
+
.....
+
 
+
<service name="acme/sample/stateful">
+
+
<environment
+
            name="RPDName"
+
            value="StatefulResourceProperties"
+
            type="java.lang.String"
+
          override="false"/>
+
 
+
          <resource name="home" type="org.acme.sample.stateful.Home">
+
<resourceParams>                
+
        <parameter>
+
              <name>factory</name>
+
              <value>org.globus.wsrf.jndi.BeanFactory</value>
+
          </parameter>
+
          <parameter>
+
                <name>resourceClass</name>
+
                <value>org.acme.sample.stateful.Resource</value>
+
          </parameter>
+
          <parameter>
+
                  <name>persistenceDelegateClass</name>
+
                            <value>org.acme.sample.stateful.ResourcePersistenceDelegate</value>
+
                      </parameter>
+
</resourceParams>
+
</resource>
+
  </service>
+
</jndiConfig>
+
</pre>
+
 
+
  
 
=== GCUBEFilePersistenceDelegate ===
 
=== GCUBEFilePersistenceDelegate ===
  
File-based persistence class (<code>GCUBEFilePersistenceDelegate</code>) is an abstract extension of a persistence delegate.
+
File-based persistence class (<code>GCUBEFilePersistenceDelegate</code>) is an abstract extension of a persistence delegate to add persistence to any <code>GCUBEResource</code>.
 
It configures the persistence storage folder as:
 
It configures the persistence storage folder as:
 
''$HOME/.globus/persisted/$Container.ID/$ServiceName/$Resource.class/$ResourceID.extension''
 
''$HOME/.globus/persisted/$Container.ID/$ServiceName/$Resource.class/$ResourceID.extension''
Line 230: Line 192:
 
public class ResourcePersistenceDelegate extends GCUBEWSFilePersistenceDelegate<Resource>{
 
public class ResourcePersistenceDelegate extends GCUBEWSFilePersistenceDelegate<Resource>{
  
protected void onLoad(Resource resource,ObjectInputStream ois) throws Exception {
+
protected void onLoad(Resource resource,ObjectInputStream ois) throws Exception {
+
 
super.onLoad(resource,ois);
 
super.onLoad(resource,ois);
 
resource.setName((String)ois.readObject());
 
resource.setName((String)ois.readObject());
Line 237: Line 198:
 
}
 
}
 
 
protected void onStore(Resource resource,ObjectOutputStream oos) throws Exception {
+
protected void onStore(Resource resource,ObjectOutputStream oos) throws Exception {
+
 
super.onStore(resource,oos);
 
super.onStore(resource,oos);
 
oos.writeObject(resource.getName());
 
oos.writeObject(resource.getName());
Line 248: Line 208:
 
</pre>
 
</pre>
  
--[[User:Manuele.simi|Manuele.simi]] 22:48, 28 March 2008 (EET)
+
Notes:
 +
* the class extends the <code>GCUBEWSFilePersistenceDelegate</code> class by parametrising the extension with the <code>Resource</code> class
 +
* the class implements the <code>onLoad()</code> and <code>onStore()</code> methods
 +
* as first step, they MUST call their <code>super</code> implementation
 +
* then, they store/load the <code>Resource</code> class state, i.e. the Name and Visits properties' values
 +
 
 +
=== How to enable persistence ===
 +
As most of gCore Framework facilities, GCUBEResource Persistence can be enabled by modifying the gCube Service JNDI file by declaring in the Home resource the persistence delegate class to use:
 +
<pre>
 +
 
 +
<jndiConfig xmlns="http://wsrf.globus.org/jndi/config">
 +
 
 +
.....
 +
 
 +
<service name="acme/sample/stateful">
 +
 +
<environment
 +
            name="RPDName"
 +
            value="StatefulResourceProperties"
 +
            type="java.lang.String"
 +
          override="false"/>
 +
 
 +
          <resource name="home" type="org.acme.sample.stateful.Home">
 +
<resourceParams>                
 +
        <parameter>
 +
              <name>factory</name>
 +
              <value>org.globus.wsrf.jndi.BeanFactory</value>
 +
          </parameter>
 +
          <parameter>
 +
                <name>resourceClass</name>
 +
                <value>org.acme.sample.stateful.Resource</value>
 +
          </parameter>
 +
          <parameter>
 +
                  <name>persistenceDelegateClass</name>
 +
                            <value>org.acme.sample.stateful.ResourcePersistenceDelegate</value>
 +
                      </parameter>
 +
</resourceParams>
 +
</resource>
 +
  </service>
 +
</jndiConfig>
 +
</pre>
 +
 
 +
 
 +
--[[User:Manuele.simi|Manuele.simi]] 23:48, 28 March 2008 (EET)

Revision as of 00:01, 29 March 2008

How to publish the state

GCUBEProvider

Import GCUBEProvider WSDL inside the Stateful WSDL:

<definitions name="Stateful" targetNamespace="http://acme.org/sample"....
xmlns:provider=http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider />

<import namespace=http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider   
location="../gcube/common/core/providers/GCUBEProvider.wsdl"/>

...

</definition>

Include the GCUBEProvider in the list of providers on service WSDD:

 
<parameter name="providers" value="GCUBEProvider"/>

WS-Resource Property document

Declare the WS-Resource Property document in the Stateful WSDL:

<definitions name="Stateful"
    targetNamespace="http://acme.org/sample" ...>

   <types>
	<xsd:schema targetNamespace="http://acme.org/sample">    	
	    <xsd:import namespace="http://gcube-system.org/namespaces/common/core/types" schemaLocation="../gcube/common/core/types/GCUBETypes.xsd"/>
	    	
  		<xsd:element name="aboutSF" type="coretypes:VOID" />
		<xsd:element name="aboutSFResponse" type="xsd:string" />		
		
		<xsd:element name="Name" type="xsd:string"/>
        <xsd:element name="Visits" type="xsd:int"/>
        
            <xsd:element name="StatefulResourceProperties">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element ref="tns:Name" minOccurs="1" maxOccurs="1"/>
                        <xsd:element ref="tns:Visits" minOccurs="1" maxOccurs="1"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element> 	
            
	</xsd:schema>
    </types>

Port-Type definitions

Extend the Stateful port-type with the GCUBEProvider and declare in the port-type definition the Resource Property document:

<portType name="StatefulPortType"
    wsrp:ResourceProperties="tns:StatefulResourceProperties"
        wsdlpp:extends="provider:GCUBEProvider">
 ...
 </portType>

Publication Profile

Provide a Publication Profile:

<ServiceGroupRegistrationParameters
    xmlns:sgc="http://mds.globus.org/servicegroup/client"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"
    xmlns:agg="http://mds.globus.org/aggregator/types"
    xmlns="http://mds.globus.org/servicegroup/client">
    
    
    <!-- Specifies that the registration will be renewed every 30
        seconds -->
    <RefreshIntervalSecs>60</RefreshIntervalSecs>
    
    
    <!-- <Content> specifies registration specific information -->
    <Content xsi:type="agg:AggregatorContent"
        xmlns:agg="http://mds.globus.org/aggregator/types">
        
        <agg:AggregatorConfig>
            <agg:GetMultipleResourcePropertiesPollType 
                xmlns:tutorial="http://acme.org/sample"
                xmlns:provider="http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider">
                
                <agg:PollIntervalMillis>60000</agg:PollIntervalMillis>
                
                <agg:ResourcePropertyNames>tutorial:Name</agg:ResourcePropertyNames>
                <agg:ResourcePropertyNames>tutorial:Visits</agg:ResourcePropertyNames>
                
                <agg:ResourcePropertyNames>provider:RI</agg:ResourcePropertyNames>
                <agg:ResourcePropertyNames>provider:ServiceID</agg:ResourcePropertyNames>
                <agg:ResourcePropertyNames>provider:ServiceName</agg:ResourcePropertyNames>
                <agg:ResourcePropertyNames>provider:ServiceClass</agg:ResourcePropertyNames>
                <agg:ResourcePropertyNames>provider:VO</agg:ResourcePropertyNames>
                <agg:ResourcePropertyNames>provider:GHN</agg:ResourcePropertyNames>
                <agg:ResourcePropertyNames>provider:Scope</agg:ResourcePropertyNames>
                
            </agg:GetMultipleResourcePropertiesPollType>
          </agg:AggregatorConfig>

        <agg:AggregatorData/>
        
    </Content>
    
</ServiceGroupRegistrationParameters>

Include the Publication Profile resource and the Resource Property document name in the stateful JNDI configuration:

<jndiConfig>

    ....

  <service name="acme/sample/stateful">
 	
	 <environment 
            name="RPDName"
            value="StatefulResourceProperties"
            type="java.lang.String"
            override="false"/>	
        
	<resource name="publicationProfile" type="org.gcube.common.core.state.GCUBEPublicationProfile">	
            <resourceParams>
                <parameter>
                    <name>factory</name>
                    <value>org.globus.wsrf.jndi.BeanFactory</value>
                </parameter>
                <parameter>
                    <name>mode</name>
                    <value>pull</value>
                </parameter>
                <parameter>
                    <name>fileName</name>
                    <value>@config.dir@/Registration.xml</value>
                </parameter>
            </resourceParams>
        </resource>
                 
	 <resource name="home" type="org.acme.sample.stateful.Home">
		 	<resourceParams>		                
		         <parameter>
		              <name>factory</name>
		              <value>org.globus.wsrf.jndi.BeanFactory</value>
		          </parameter>
		          <parameter>
		                <name>resourceClass</name>
		                <value>org.acme.sample.stateful.Resource</value>
		          </parameter>
		           <parameter>
                   	 	<name>persistenceDelegateClass</name>
                    	<value>org.acme.sample.stateful.ResourcePersistenceDelegate</value>
                </parameter>
		        </resourceParams>
	 </resource>
	 	
	   <environment 
		name="frequentUserLimit" 
	 	value="3" 
	 	type="java.lang.Integer"
	 	override="false" />
	</service>
</jndiConfig>

How to persist the state

The gCore Framework comes with a persistence mini-framework that implementing GCUBEResource serialization and deserialization from/to some form of long-term storage.

GCUBEFilePersistenceDelegate

File-based persistence class (GCUBEFilePersistenceDelegate) is an abstract extension of a persistence delegate to add persistence to any GCUBEResource. It configures the persistence storage folder as: $HOME/.globus/persisted/$Container.ID/$ServiceName/$Resource.class/$ResourceID.extension It implements resource de/serialization by calling the Resource-specific onLoad/onStore methods It has been specialized by the following classes:

  • GCUBELocalViewFilePersistenceDelegate
  • GCUBELRFilePersistenceDelegate
  • GCUBEWSFilePersistenceDelegate
  • GCUBEWSLiteFilePersistenceDelegate

To enable the persistence of a GCUBEWSResouce, a new class extending the GCUBEWSFilePersistenceDelegate has to be created:

package org.acme.sample.stateful;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


import org.gcube.common.core.persistence.GCUBEWSFilePersistenceDelegate;

public class ResourcePersistenceDelegate extends GCUBEWSFilePersistenceDelegate<Resource>{

	protected void onLoad(Resource resource,ObjectInputStream ois) throws Exception {		
		super.onLoad(resource,ois);
		resource.setName((String)ois.readObject());
		resource.setVisits((Integer)ois.readObject());
	}
	
	protected void onStore(Resource resource,ObjectOutputStream oos) throws Exception {		
		super.onStore(resource,oos);
		oos.writeObject(resource.getName());
		oos.writeObject(resource.getVisits());
		
	}
}

Notes:

  • the class extends the GCUBEWSFilePersistenceDelegate class by parametrising the extension with the Resource class
  • the class implements the onLoad() and onStore() methods
  • as first step, they MUST call their super implementation
  • then, they store/load the Resource class state, i.e. the Name and Visits properties' values

How to enable persistence

As most of gCore Framework facilities, GCUBEResource Persistence can be enabled by modifying the gCube Service JNDI file by declaring in the Home resource the persistence delegate class to use:


<jndiConfig xmlns="http://wsrf.globus.org/jndi/config">

 .....

 <service name="acme/sample/stateful">
 	
	 <environment 
            name="RPDName"
            value="StatefulResourceProperties"
            type="java.lang.String"
           override="false"/>	

          <resource name="home" type="org.acme.sample.stateful.Home">
		 <resourceParams>		                
		         <parameter>
		              <name>factory</name>
		              <value>org.globus.wsrf.jndi.BeanFactory</value>
		          </parameter>
		          <parameter>
		                <name>resourceClass</name>
		                <value>org.acme.sample.stateful.Resource</value>
		          </parameter>
		           <parameter>
                   	 	<name>persistenceDelegateClass</name>
                    	        <value>org.acme.sample.stateful.ResourcePersistenceDelegate</value>
                       </parameter>
		</resourceParams>
	 </resource>
   </service>
</jndiConfig> 


--Manuele.simi 23:48, 28 March 2008 (EET)