Access Keys:
Skip to content (Access Key - 0)
compared with
Current by Clayton Clark
on Mar 09, 2010 14:04.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (65)

View Page History
h1. Creating a caGrid Data Service Backed by caCORE SDK 4.0
----
{note}NOTE: A number of bugs have been fixed since the 1.2 release that could cause issues with this tutorial. Please make sure you obtain the latest release of caGrid 1.2 by [checking out caGrid from source.|downloads:Source Code]
{note}
NOTE: A number of bugs have been fixed since the 1.2 release that could cause issues with this tutorial. Please make sure you obtain the latest release of caGrid 1.2 by [checking out caGrid from source.|downloads:Source Code]
{note}

caGrid [Data Service|dataservices:Home] creation is accomplished by the use of an [extension|introduce12:Technical Guide] to the [Introduce toolkit|introduce:Home]. This extension can streamline the process of creating a data service backed by the [caCORE SDK|dataservices:caCORE SDK Support] using a wizard like interface which prompts for values as required, or simply make use of a [custom query processing|dataservices13:How-to Implement CQL Query Processors] back end.

{toc:outline=false|exclude=Creating a caGrid Data Service backed by caCORE SDK 4.0|style=bullets}
{cagridroundpanel}

h2. Prerequisites

In a system terminal execute the following commands to launch Introduce

{terminal}%> cd %CAGRID_LOCATION% %> ant introduce
{terminal}
%> cd %CAGRID_LOCATION%
%> ant introduce
{terminal}

h1. Create the Service Skeleton
----

# Select *{_}Create caGrid Service Skeleton{_}* from the toolbar at the top of the Introduce portal, or select Tools \-> Create caBIG Service from the menu. The Create caBIG Grid Service screen will appear.
# Choose a directory in which to place the generated service. This tutorial uses *_"C:\caGrid\generatedServices\Sdk4Example"_*.
h2. The Data Service caCORE SDK 4 Wizard

The caCORE SDK v 4 data service style provides a wizard interface which is run prior to generation of the data service's source code. This wizard provided facilities to select the client interface to the caCORE SDK and configure it, as well as selection of a domain model and mapping that domain to XML schemas for use on the grid.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_1.png}
The caCORE SDK v 4 data service style provides a wizard interface which is run prior to generation of the data service's source code. This wizard provided facilities to select the client interface to the caCORE SDK and configure it, as well as selection of a domain model and mapping that domain to XML schemas for use on the grid.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_1.png}This panel is strictly informational. The wizard displays the current step in the lower left hand corner of the window, and provides simple 'Previous' and 'Next' buttons to navigate the steps. These buttons will become enabled and disabled as the content of each page is validated. If any fields on the current page are in an invalid state, the 'Next' button will be disabled, and the field will show a red highlight. Mouse-over tooltips are used to indicate the problem. When all steps are complete, the 'Next' button becomes 'Finish', and will complete the wizard and proceed to code generation. Click the *{_}Next: Configuration{_}* button to continue the wizard.

h3. Configuring the Client

The next step of the wizard.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_2_Blank.png}
The next step of the wizard.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_2_Blank.png}This panel allows the service developer to select various outputs from the caCORE SDK which are required by the caGrid data service to utilize it as a data resource. There are two modes of operation for this panel: 'simple' and 'advanced', selectable by way of radio buttons near the top-left of the panel. In 'simple' mode, the developer is prompted to select the output directory in a caCORE SDK installation, and the extension will attempt to locate the other components it requires in its subdirectories.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Select_Output_Dir.png}

h3. Selecting the Output Directory

h3. Application Service Security

The caCORES SDK Application Service can be configured to require a user name and password for access. If the service is so configured, this panel allows the service developer to specify which user name and password should be used. Two options are available. One option allows a static, single user name and password to be used for all connections to the application service. The other option attempts to use the grid identity of the user making a query to the data service as the user name.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_3.png}For this tutorial, simply leave all fields blank and unchecked on this page, and click *{_}Next{_}*.
For this tutorial, simply leave all fields blank and unchecked on this page, and click *{_}Next{_}*.

h3. Selecting a Domain Model

{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_4_Full.png}
{info}Note: to use another domain model file (for example, if you're creating a data service from another caCORE SDK 4 project), please use the following steps:

{info}
Note: to use another domain model file (for example, if you're creating a data service from another caCORE SDK 4 project), please use the following steps:

1. cd to $CAGRID_LOCATION/projects/dataExtensions
2. ant xmiToDomainModel
8. Choose where to save your domain model file and type in a name.
{info}

4. Click the *{_}Next{_}* button to continue to the last step in the wizard.

h3. Mapping Domain Packages to XML Schema

Every class exposed by the domain model must be supplied with a corresponding XML schema representation so it may be utilized in the grid. The mapping panel of this wizard streamlines this process by simultaneously generating the mapping from model to schema and configuring serialization of the XML data types to correspond to the domain model's Java beans.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_5_Unresolved.png}
Packages from the domain model are listed, along with a suggested XML schema namespace, a mapping status, and a button to manually resolve the mapping for each package. This panel contains two buttons which serve as convenience methods for mapping a large batch of packages to their schemas. The 'Map From GME' button attempts to locate the suggested namespaces in the Global Model Exchange service and pull the corresponding schemas. The 'Map From Config' button makes use of the XML schemas provided by the caCORE SDK's output to map to each package of the domain model.
Every class exposed by the domain model must be supplied with a corresponding XML schema representation so it may be utilized in the grid. The mapping panel of this wizard streamlines this process by simultaneously generating the mapping from model to schema and configuring serialization of the XML data types to correspond to the domain model's Java beans.{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_5_Unresolved.png}Packages from the domain model are listed, along with a suggested XML schema namespace, a mapping status, and a button to manually resolve the mapping for each package. This panel contains two buttons which serve as convenience methods for mapping a large batch of packages to their schemas. The 'Map From GME' button attempts to locate the suggested namespaces in the Global Model Exchange service and pull the corresponding schemas. The 'Map From Config' button makes use of the XML schemas provided by the caCORE SDK's output to map to each package of the domain model.

1. Click the *{_}Map From Config{_}* button, and this mapping will be performed automatically.

{attached-image:tablealign=center|attachmentname=DataService_1.2_SDK_4_Wizard_Step_5_Resolved.png}

2. Click the *{_}Done{_}* button to complete the wizard.


*{_}Linux / Unix{_}*
{terminal}%> cd $CATALINA_HOME %> rm \-rf webapps/wsrf
{terminal}
%> cd $CATALINA_HOME
%> rm \-rf webapps/wsrf
{terminal}

*{_}Windows{_}*
{terminal}%> cd %CATALINA_HOME% %> rmdir /S webapps\wsrf
{terminal}
%> cd %CATALINA_HOME%
%> rmdir /S webapps\wsrf
{terminal}

h3. Deploying Globus


*{_}Linux / Unix{_}*
{terminal}%> cd $GLOBUS_LOCATION %> ant \-f share/globus_wsrf_common/tomcat/tomcat.xml deployTomcat \-Dtomcat.dir="$CATALINA_HOME"
{terminal}
%> cd $GLOBUS_LOCATION %> ant \-f share/globus_wsrf_common/tomcat/tomcat.xml deployTomcat \-Dtomcat.dir="$CATALINA_HOME"
{terminal}

*{_}Windows{_}*
{terminal}cd %GLOBUS_LOCATION% ant \-f share\globus_wsrf_common\tomcat\tomcat.xml deployTomcat \-Dtomcat.dir="%CATALINA_HOME%"
{terminal}
cd %GLOBUS_LOCATION% ant \-f share\globus_wsrf_common\tomcat\tomcat.xml deployTomcat \-Dtomcat.dir="%CATALINA_HOME%"
{terminal}

h3. Deploying the Service

Now the generated grid service may be deployed to the Tomcat container. The tutorial uses _C:\caGrid\generatedServices\Sdk4Example_; if you selected a different directory, substitute it appropriately. The following command will recompile the service and deploy it to the tomcat container residing at $CATALINA_HOME:

{terminal}cd C:\caGrid\generatedServices\Sdk4Example ant all deployTomcat
{terminal}
cd C:\caGrid\generatedServices\Sdk4Example ant all deployTomcat
{terminal}

h3. Starting Tomcat


*{_}Linux / Unix{_}*
{terminal}%> cd $CATALINA_HOME %> bin/startup.sh
{terminal}
%> cd $CATALINA_HOME %> bin/startup.sh
{terminal}

*{_}Windows{_}*
{terminal}cd %CATALINA_HOME% bin\startup.bat
{terminal}
cd %CATALINA_HOME% bin\startup.bat
{terminal}

h2. Invoking the Grid Data Service


{attached-image:tablealign=center|attachmentname=Eclipse_Import_Project_1.png}

To import the project into the Eclipse workspace, select '''Import''' from the '''File''' menu in Eclipse. Then select '''Existing Projects into Workspace''' under '''General'''. Click '''Next'''. Then, select the root directory of the tutorial service using the '''Browse''' button. Once the directory is selected, the name of the project (matching that of the service) will appear in the list. Click '''Finish''' to import the tutorial service as an Eclipse project.

{attached-image:tablealign=center|attachmentname=Data_Services_SDK_4_Tutorial_New_Class.png} Alternatively, the class can be created as a simple text file named QueryRunner.java in the src/org/cagrid/sdk4/example/tutorial directory. Once created, the class template should look something like this:

{code}
{code}package org.cagrid.sdk4.example.tutorial;

public class QueryRunner {
}
{code}

h3. Create a Class Constructor

For the purposes of this tutorial, we'll create a very simple class constructor for the QueryRunner class. Copy and paste the following code into the new java file, immediately after the class declaration and opening bracket:

{code}
{code} private String serviceUrl;
private String queryFilename;

}
{code}

This constructor simply takes two string properties and stores them in instance variables. These values will be used later to create a client to the remote data service, and load a CQL query from the local file system.

Now a method must be added to the class which can handle invocation of the data service. In the new class file, add the following code after the constructor declaration:

{code}
{code} private void performQuery() {
try {
// initialize the generic data service client
}
{code}

This code adds a method named '''performQuery''', which creates a generic data service client, loads a CQL query from the file system, invokes the query, and finally prints XML results to the console.

Additionally, some import statements must be added to the class. At the top of the class file, below the package declaration and before the class declaration, add the following:

{code}
{code}import java.util.Iterator;

import gov.nih.nci.cagrid.common.Utils;
import gov.nih.nci.cagrid.data.utilities.CQLQueryResultsIterator;
{code}

These statements make code from caGrid available in this class, including utilities, the data service client, and query and results handling code.

The last addition to the QueryRunner class is the implementation of the main method. We'll use this method to pass a service URL and query file name to the QueryRunner utility, and then to invoke the newly added performQuery() method. Copy the following code into the main method, replacing the text ''// TODO Auto-generated method stub'':

{code} if (args.length != 2) {
if (args.length != 2) {
System.err.println("USAGE: <serviceUrl> <queryFilename>");
System.exit(1);
runner.performQuery();
{code}

Once all code has been added to the QueryRunner class, save the java file.

To make use of the QueryRunner class, we'll need a CQL query which can be executed against the data service developed earlier. Create an xml file in the root of the tutorial service directory named '''exampleCqlQuery.xml.''' For example, the directory might look like "C:\caGrid\generatedServices\Sdk4Example". Copy and paste into it the following CQL query in XML form:

{code}
{code}<ns1:CQLQuery xmlns:ns1="http://CQL.caBIG/1/gov.nih.nci.cagrid.CQLQuery">
<ns1:Target name="gov.nih.nci.cacoresdk.domain.other.levelassociation.Suit">
<ns1:Association name="gov.nih.nci.cacoresdk.domain.other.levelassociation.Card">
</ns1:CQLQuery>
{code}

This query will return Suit instances from the example service. These have the requirement that they be associated with a Card, which in turn has an association to a Suit whose name is Spades, and also have a Name with the value Ace. More simply, this query returns the suit of the Ace of Spades.

Since Eclipse automatically compiles classes when the associated java source files are saved, there is no need to recompile the service. If you are not using Eclipse, run the following command to rebuild the service, including the QueryRunner class:

{terminal}cd C:\caGrid\generatedServices\Sdk4Example ant clean all
{terminal}
cd C:\caGrid\generatedServices\Sdk4Example ant clean all
{terminal}

Once compiled, the QueryRunner can be invoked. In Eclipse, right-click the QueryRunner class file, and select '''Run As->Run...''' to bring up the Run dialog. Click the '''New Launch Configuration''' icon in the upper right. The name of the run configuration, the project name, and Main class name will automatically be populated.{attached-image:tablealign=center|attachmentname=Data_Services_SDK_4_Tutorial_Run_Configuration.png} Change to the '''Arguments''' tab to specify the command line arguments which will be passed to the QueryRunner's main method. In the '''Program arguments''' text field, enter the following two items, separated by a single space:

Finally, click the '''Run''' button to save this configuration and execute the QueryRunner class. As the class executes, any messages from it will be printed to the console. When complete, the console should appear similar to the following:

{noformat}Querying
Querying
Iterating
-- RESULT --
Done
{noformat}

h3. Execution Outside Eclipse

The QueryRunner class can be executed without Eclipse by means of a simple Ant build script. Copy the following into a file named '''queryRunnerExec.xml''' and place it in the root directory of the tutorial service:

{code}
{code}<?xml version="1.0"?>
<project default="run" name="Query Runner Execution File" basedir=".">

</project>
{code}

To use the build file, execute the following in the base directory of the service:

{terminal}ant \-f queryRunnerExec.xml \-Dservice.url=http://localhost:8080/wsrf/services/cagrid/Sdk4Example \-Dcql.file=exampleCqlQuery.xml
{terminal}
ant -f queryRunnerExec.xml -Dservice.url=http://localhost:8080/wsrf/services/cagrid/Sdk4Example -Dcql.file=exampleCqlQuery.xml
{terminal}

When run, the output should be similar to the following:

{noformat}
{noformat}Buildfile: queryRunnerExec.xml

run:
Total time: 7 seconds
{noformat}

h2. Conclusions

Last edited by
Clayton Clark (1173 days ago) , ...
Adaptavist Theme Builder Powered by Atlassian Confluence