19

GemFire Introduction Hands-on Labs

Embed Size (px)

DESCRIPTION

This is the lab document for the hands on labs in the Pivotal Academy course "Introduction to Gemfire".

Citation preview

Page 1: GemFire Introduction Hands-on Labs
Page 2: GemFire Introduction Hands-on Labs
Page 3: GemFire Introduction Hands-on Labs

This Page Intentionally Left Blank

Page 4: GemFire Introduction Hands-on Labs

Table of Contents1. Installation and Configuration ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1. Introduction .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2. Instructions .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2.1. Installation Prerequisites .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.2. Install GemFire .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.3. Configuring the Command Line Interface (CLI) .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2.4. Setting up the QuickStart Examples .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2. Using GemFire Tools .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.1. Introduction .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2. Instructions .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.2.1. Start GemFire Locator using gfsh .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2.2. Start two GemFire Instances .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2.3. Enter data for a Replicated region .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2.4. Enter data for a Partitioned region .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2.5. Launch Pulse for Monitoring .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3. Executing OQL Queries .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.1. Introduction .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.2. Instructions .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.2.1. Start GemFire Locator using gfsh .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.2.2. Start two GemFire Cache Servers using gfsh .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2.3. Start the Client Application .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2.4. Lauch the DataBrowser Tool .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103.2.5. Execute OQL Queries .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123.2.6. Shut down the Server Locators .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14

iv

Page 5: GemFire Introduction Hands-on Labs

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 thisprocedure 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 athttp://docs.gopivotal.com/gemfire/.

2. Check that your Java version is appropriate and that Java is on your path. To check your current Javaversion, 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 anerror, that means Java is either not installed, or not on your PATH .

You can download Sun/Oracle Java SEhere.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 anddownload the evaluation version of Pivotal GemFire

1

Page 6: GemFire Introduction Hands-on Labs

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 toset 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 exampleC:\ Pivotal_GemFire_702_b45797 )

3. Ensure the PATH and CLASSPATH are set

Unix

PATH=$PATH:$JAVA_HOME/bin:$GEMFIRE/bin;export PATHCLASSPATH=$GEMFIRE/lib/gemfire.jar:$GEMFIRE/lib/antlr.jar:\$GEMFIRE/lib/gfSecurityImpl.jar:$CLASSPATH;export CLASSPATH

Windows

set PATH=%PATH%;%JAVA_HOME%\bin;%GEMFIRE%\binset 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 thequickstart 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 needthese examples subdirectories in your CLASSPATH to run all of the sample applications:

• tutorial/classes

• helloworld/classes

• quickstart/classes

Installation and Configuration

2

Page 7: GemFire Introduction Hands-on Labs

• 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

Page 8: GemFire Introduction Hands-on Labs

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 Pulseto 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 doneas 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 asmentioned in the installation practice

2. Change directories to the tutorial directory, <product_directory>/SampleCode/tutorial . For example

$ cd <product_directory>/SampleCode/tutorial

4

Page 9: GemFire Introduction Hands-on Labs

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

Page 10: GemFire Introduction Hands-on Labs

person Isabellaperson 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 setthe 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'sbecause partitioned regions make one copy of the post, the primary copy. By default GemFire only invokesthe 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

Page 11: GemFire Introduction Hands-on Labs

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

Page 12: GemFire Introduction Hands-on Labs

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 andmodify data in the servers. Then, you will use the GemFire DataBrowser tool to execute OQL queries on thedata 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 apart 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 asmentioned in the installation practice.

2. Change directories to the tutorial directory, <product_directoy>/SampleCode/tutorial . For example:

8

Page 13: GemFire Introduction Hands-on Labs

$ 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

Page 14: GemFire Introduction Hands-on Labs

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 lauchthe application.

2. Connect to the GemFire locator from the DataBrowser window. Provide the locator's hostname and portnumber:

Executing OQL Queries

10

Page 15: GemFire Introduction Hands-on Labs

Note

Alternatively, you can use gfsh to connect to the locator, and then start DataBrowser byusing the 'start data-browser' command

3. After connecting, you see the GemFire Regions on the left pane, and also the members hosting the Regionsin the pane below.

Executing OQL Queries

11

Page 16: GemFire Introduction Hands-on Labs

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

Page 17: GemFire Introduction Hands-on Labs

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, youhave to import the types as JAR file within the DataBrowser. To accomplish this task, create the followingJAR file:

jar cvf classes.jarcom\gemstone\gemfire\tutorial\model\Profile.classcom\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 theJAR file you created as follows:

Executing OQL Queries

13

Page 18: GemFire Introduction Hands-on Labs

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

Page 19: GemFire Introduction Hands-on Labs

$ 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