Difference between revisions of "Managing State"

From GCube System
Jump to: navigation, search
(Publication Profile)
(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 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)
  
--[[User:Manuele.simi|Manuele.simi]] 21:49, 28 March 2008 (EET)
+
=== 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 ===
 +
 
 +
File-based persistence class (<code>GCUBEFilePersistenceDelegate</code>) is an abstract extension of a persistence delegate.
 +
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 <code>onLoad/onStore</code> methods
 +
It has been specialized by the following classes:
 +
* <code>GCUBELocalViewFilePersistenceDelegate</code>
 +
* <code>GCUBELRFilePersistenceDelegate</code>
 +
* <code>GCUBEWSFilePersistenceDelegate</code>
 +
* <code>GCUBEWSLiteFilePersistenceDelegate</code>
 +
 
 +
To enable the persistence of a GCUBEWSResouce, a new class extending the <code>GCUBEWSFilePersistenceDelegate</code> has to be created:
 +
<pre>
 +
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());
 +
 +
}
 +
}
 +
 
 +
</pre>
 +
 
 +
--[[User:Manuele.simi|Manuele.simi]] 22:48, 28 March 2008 (EET)

Revision as of 21:48, 28 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 gCF contains a persistence framework that implements GCUBE WS-Resource serialization and deserialization from and 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:


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


GCUBEFilePersistenceDelegate

File-based persistence class (GCUBEFilePersistenceDelegate) is an abstract extension of a persistence delegate. 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());
		
	}
}

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