Sie sind auf Seite 1von 19

This Page Intentionally Left Blank

Table of Contents
1. Installation and Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2. Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2.1. Installation Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2.2. Install GemFire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2.3. Configuring the Command Line Interface (CLI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.4. Setting up the QuickStart Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2. Using GemFire Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2. Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.1. Start GemFire Locator using gfsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.2. Start two GemFire Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.3. Enter data for a Replicated region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.4. Enter data for a Partitioned region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.5. Launch Pulse for Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3. Executing OQL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2. Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.1. Start GemFire Locator using gfsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.2. Start two GemFire Cache Servers using gfsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.3. Start the Client Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.4. Lauch the DataBrowser Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2.5. Execute OQL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2.6. Shut down the Server Locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
iv
Chapter 1. Installation and Configuration
1.1. Introduction
Welcome to the GemFire introduction course. We have tried to make the lab setup as simple as possible. In this
procedure it is assumed that you know how to configure environment variables for your operating system.
What you will gain experience with:
How to install and configure GemFire, and the lab environment
1.2. Instructions
1.2.1. Installation Prerequisites
1. Make sure that your system meets the System Requirements listed. Refer to the product documentation at
http://docs.gopivotal.com/gemfire/.
2. Check that your Java version is appropriate and that Java is on your path. To check your current Java
version, type java -version at a command-line. Your output should look something like this:
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
3. To install GemFire, you will need Java Runtime Environment 1.6.0 or higher. If this command returned an
error, that means Java is either not installed, or not on your PATH .
You can download Sun/Oracle Java SE
here.http://www.oracle.com/technetwork/java/javase/downloads/index.html
1.2.2. Install GemFire
1. From the Pivotal downloads (http://www.gopivotal.com/big-data/pivotal-gemfire) page, select and
download the evaluation version of Pivotal GemFire
1
2. Download the ZIP distribution Pivotal GemFire distributed as a ZIP file
3. Open the .zip file, and extract the product files to the desired installation location on your machine
1.2.3. Configuring the Command Line Interface (CLI)
You might be required to use the CLI for executing some of the GemFire commands. Therefore, you need to
set the environment variables before executing the GemFire commands
1. Make sure JAVA_HOME is set
2. Set the GEMFIRE environment variable to point to your GemFire installation top-level directory (for example
C:\ Pivotal_GemFire_702_b45797 )
3. Ensure the PATH and CLASSPATH are set
Unix
PATH=$PATH:$JAVA_HOME/bin:$GEMFIRE/bin;
export PATH
CLASSPATH=$GEMFIRE/lib/gemfire.jar:$GEMFIRE/lib/antlr.jar:\
$GEMFIRE/lib/gfSecurityImpl.jar:$CLASSPATH;
export CLASSPATH
Windows
set PATH=%PATH%;%JAVA_HOME%\bin;%GEMFIRE%\bin
set CLASSPATH=%GEMFIRE%\lib\gemfire.jar;%GEMFIRE%\lib\
antlr.jar;%GEMFIRE%\lib\gfSecurityImpl.jar;%CLASSPATH%
1.2.4. Setting up the QuickStart Examples
The quickstart samples demonstrate how to implement specific functionality in GemFire. You can find the
quickstart sample applications within the \ Pivotal_GemFire_702_b45797\SampleCode directory.
To execute any of the sample applications, add the example class directories to your CLASSPATH. You need
these examples subdirectories in your CLASSPATH to run all of the sample applications:
tutorial/classes
helloworld/classes
quickstart/classes
Installation and Configuration
2
examples/dist/classes
Windows
set CLASSPATH=
< product_directory>\SampleCode\tutorial\classes;
< product_directory>\SampleCode\helloworld\classes;
< product_directory>\SampleCode\quickstart\classes;
< product_directory>\SampleCode\examples\dist\classes;%CLASSPATH%
where <product_directory> corresponds to the location where you installed Pivotal GemFire.
Installation and Configuration
3
Chapter 2. Using GemFire Tools
2.1. Introduction
In this lab, you will use gfsh to launch and exit GemFire members and locator. In addition, you will use Pulse
to monitor the members
What you will gain experience with:
How to launch GemFire members by using gfsh
Monitor GemFire members by using Pulse
2.2. Instructions
2.2.1. Start GemFire Locator using gfsh
1. Start a Command prompt window, and add the example class directories to your CLASSPATH (if not done
as a part of the earlier practice
set CLASSPATH=
<product_directory>\ SampleCode\tutorial\classes;
<product_directory>\SampleCode\helloworld\classes;
<product_directory>\SampleCode\quickstart\classes;
<product_directory>\SampleCode\examples\dist\classes;
<product_directory>\lib\gemfire.jar;%CLASSPATH%
where <product_directory> corresponds to the location where you installed GemFire.
Important
Make sure that for each Command prompt window, you need to set the required PATH as
mentioned in the installation practice
2. Change directories to the tutorial directory, <product_directory>/SampleCode/tutorial . For example
$ cd <product_directory>/SampleCode/tutorial
4
3. Type the following command at the prompt
$ gfsh start locator --name=locator1 --port=55221
The locator process runs in the background, listening for connections on port 55221.
Note
To stop the process, you can type
$ gfsh -e "connect --locator=localhost[55221]" -e "stop locator --name=locator1"
But don't stop yet.
2.2.2. Start two GemFire Instances
You already have one window open where you started the locator. Start another terminal window, and set the
CLASSPATH. In each window, run the Peer application
$ java com.gemstone.gemfire.tutorial.Peer
Example execution output
2.2.3. Enter data for a Replicated region
1. In one of your terminal windows, type:
Using GemFire Tools
5
person Isabella
person Ethan
2. You will see the users show up in the both the window.
In region people created key Isabella value Profile
[friends=[]]
In region people created key Ethan value Profile
[friends=[]]
This is because the cache listener, attached to the region fires notification on both the GemFire instances.
This means that the data got replicated on both the instances.
2.2.4. Enter data for a Partitioned region
1. Start another Command prompt Window and launch the peer application in that Window. Make sure to set
the CLASSPATH for the new Window before executing any application.
java com.gemstone.gemfire.tutorial.Peer
You should have three peers running now.
2. Add some posts in any of the terminal window. For example
> post Isabella I like toast
> post Isabella LOL!
> post Ethan Hello
You see the notification in only one of the Peers, and not all of them unlike the 'person' notification. That's
because partitioned regions make one copy of the post, the primary copy. By default GemFire only invokes
the listener in the peer that holds the primary copy of each post.
3. From any window, list the available posts with the posts command. You should be able to list all posts,
because GemFire fetches them from the peer that hosts each post.
2.2.5. Launch Pulse for Monitoring
1. Enter the following command to launch pulse:
gfsh -e "connect --locator localhost[55221]" -e "start pulse"
Using GemFire Tools
6
2. Enter 'admin/admin' for the username and password, and log in.
3. Click on the respective servers and locator icons to view their respective information.
4. Stop all the servers and locator. For example:
gfsh -e "connect --locator localhost[55221]" -e "stop locator --name=locator1"
Using GemFire Tools
7
Chapter 3. Executing OQL Queries
3.1. Introduction
In this lab, you will instantiate couple of GemFire servers, and use a GemFire client application to populate and
modify data in the servers. Then, you will use the GemFire DataBrowser tool to execute OQL queries on the
data residing in the servers.
What you will gain experience with:
How to start the GemFire members (servers and locator) by using gfsh utility.
Execute a Java GemFire application client to add data.
Launch GemFire DataBrowser tool, and execute OQL queries on the data.
3.2. Instructions
3.2.1. Start GemFire Locator using gfsh
1. Start a Command prompt window, and add the example class directories to your CLASSPATH (if not done as a
part of the earlier practice).
set CLASSPATH=
<product_directory>\ SampleCode\tutorial\classes;
<product_directory>\SampleCode\helloworld\classes;
<product_directory>\SampleCode\quickstart\classes;
<product_directory>\SampleCode\examples\dist\classes;
<product_directory>\lib\gemfire.jar;%CLASSPATH%
where <product_directory> corresponds to the location where you installed GemFire.
Important
Make sure that for each Command prompt window, you need to set the required PATH as
mentioned in the installation practice.
2. Change directories to the tutorial directory, <product_directoy>/SampleCode/tutorial . For example:
8
$ cd <product_directory>/SampleCode/tutorial
3. Type the following command at the prompt:
$ gfsh start locator --name=locator1 --port=55221
The locator process runs in the background, listening for connections on port 55221.
3.2.2. Start two GemFire Cache Servers using gfsh
1. From the tutorial directory, start the first cache server:
$ gfsh start server --name=server1 --locators=localhost[55221] --cache-xml-file=./xml/server.xml
--server-port=0
This command will automatically create a working directory for this server named server1 under the
<product_directory>/SampleCode /tutorial directory where you executed the command.
2. Next start a second cache server by executing the following command in the same terminal:
$ gfsh start server --name=server2 --locators=localhost[55221] --cache-xml-file=./xml/server.xml
--server-port=0
This command will automatically create a working directory for this server named server2 under the
<product_directory>/SampleCode/tutorial directory where you executed the command.
You should now have two GemFire peers (cache servers) that are listening for client connections.
3.2.3. Start the Client Application
1. Open a seperate terminal windows, and start the client application.
$ java com.gemstone.gemfire.tutorial.Client
Caution
Make sure that you set the required PATH and CLASSPATH before executing the client.
Executing OQL Queries
9
2. Enter the following information from the client
a. Add the following persons with their friends:
> person Ethan Isabella Alice
> person Mary John Alice
> person May Tom Jhon
b. Notice that the following message appears for each person you add:
In region people created key Ethan value Profile
[friends=[ Alice , Isabella]]
...
c. Similarly, add some posts for each person. For example:
> post Ethan I like toast
> post Mary LOL!
> post Ethan Hello
> post Mary Good Morning!!!. . .
3.2.4. Lauch the DataBrowser Tool
1. Navigate to <product_directory>\tools\DataBrowser\bin directory. Execute databrowser.bat to lauch
the application.
2. Connect to the GemFire locator from the DataBrowser window. Provide the locator's hostname and port
number:
Executing OQL Queries
10
Note
Alternatively, you can use gfsh to connect to the locator, and then start DataBrowser by
using the 'start data-browser' command
3. After connecting, you see the GemFire Regions on the left pane, and also the members hosting the Regions
in the pane below.
Executing OQL Queries
11
3.2.5. Execute OQL Queries
1. Enter the following query string, and click Execute Query to see the result:
Select * from /posts
Executing OQL Queries
12
You see the results above in the Results pane.
2. By default, DataBrowser only identifies the system types. If you need to work with user-defined types, you
have to import the types as JAR file within the DataBrowser. To accomplish this task, create the following
JAR file:
jar cvf classes.jar
com\gemstone\gemfire\tutorial\model\Profile.class
com\gemstone\gemfire\tutorial\model\PostID.class
You can find these class files in the <product_directory>/SampleCode/tutorial/classes directory
3. Import the JAR file within DataBrowser. Click Options > Preferences. In the following window, add the
JAR file you created as follows:
Executing OQL Queries
13
4. Execute some more queries. For example,
a. To find all the post from Ethan
select p.value from /posts.entries p WHERE p.key.author='Ethan'
b. To find all people who have listed Alice as a friend
select p.key from /people.entrySet p, p.value.friends f where f='Alice'
3.2.6. Shut down the Server Locators
1. Exit Client: Enter 'Quit'
2. Shut down server1:
$ gfsh -e "connect --locator=localhost[55221]" -e "stop server --name=server1"
3. Shut down server2:
Executing OQL Queries
14
$ gfsh -e "connect --locator=localhost[55221]" -e "stop server --name=server2"
4. Shut down locator:
$ gfsh -e "connect --locator=localhost[55221]" -e "stop locator --name=locator1"
Executing OQL Queries
15