This versioned example app for VMware Tanzu GemFire is a Spring Boot app that can be used with a Tanzu GemFire service instance. This branch demonstrates deployment scenarios for an app, and how the app's location affects communication with a Tanzu GemFire For VMs service instance. Branches of this git repository correspond to the Tanzu GemFire version that this app will work with. Check out and run the app from the branch that matches your Tanzu GemFire tile version. For example, if your Tanzu GemFire service instance is version 2.1, check out this repository's release/2.1 branch.
The app uses Spring Boot for Apache Geode (SBDG) to talk to the Tanzu GemFire service instance. The app provides a REST interface that lets a user view pizzas, place orders, and view an order. The app leverages Spring Web MVC controllers to expose data access operations.
Pizzas are stored in the Tanzu GemFire servers running within
the Tanzu GemFire service instance.
The app uses a Spring Data Repository to store,
access, and query data stored on the servers.
The app stores data in the Pizza
repository (repositories are referred to as regions in Tanzu GemFire).
See GemFire Basics for the briefest of introductions to Tanzu GemFire,
and see Region Design for a quick tour of Tanzu GemFire regions.
The app talks to a Tanzu GemFire service instance. The app does create, read, and delete CRUD operations on data held in a region within service instance.
The app exposes these endpoints:
-
https://APP-URL/
Prints the available app endpoints.
-
https://APP-URL/ping
Prints PONG! if the app is running.
-
https://APP-URL/preheatOven
Creates three pre-defined pizzas, which adds them to the region.
-
https://APP-URL/pizzas
Gets all pizzas from the region.
-
https://APP-URL/pizzas/{name}
Gets details of a pizza specified by its name.
-
https://APP-URL/pizzas/order/{name}
Orders a given pizza, which does a create operation. For example:
https://APP-URL/pizzas/order/myCustomPizza?sauce=MARINARA&toppings=CHEESE,PEPPERONI,MUSHROOM
orders a pizza namedmyCustomPizza
, which hasMARINARA
sauce and three toppings. -
https://APP-URL/cleanSlate
Deletes all pizzas from the region.
- The cf CLI will be used.
- Log in to your CF (TAS) environment.
- The CF (TAS) environment should have a Tanzu GemFire for VMs Tile installed.
An app that uses a Tanzu GemFire service instance may be located in one of three locations, as specified in The App's Location. This app demonstrates all three possibilities of app location using Spring profiles.
In addition, the app may be run locally, without having a Geode or Tanzu GemFire service instance. All four running environments are described.
This Spring Boot app can run locally,
without having an Apache Geode or Tanzu GemFire service instance.
Uncomment the annotation @EnableClusterAware
in the app's source file src/main/java/io/pivotal/cloudcache/app/config/PizzaConfig.java
to enable redirecting cache operations operations to LOCAL
regions
when there is no service instance to talk to.
It implements an embedded cache on the client.
To run the app in the local environment,
$ ./mvnw spring-boot:run
Ignore the ConnectException: Connection refused
from the root of this repository.
Use a web browser to talk to the app at http://localhost:8080
.
When the app and the service instance are in the same foundation, SBDG eliminates the need to do any security configuration. Credentials and TLS configurations are auto applied.
-
Make note of the
SERVICE-INSTANCE-NAME
when you Create a Service Instance. The service instance may be TLS-enabled or not TLS-enabled. -
Modify the
manifest.yml
file to provide the service instance name. ReplaceSERVICE_INSTANCE
with your notedSERVICE-INSTANCE-NAME
. Remove the#
character so that the line is no longer a comment. -
Build the app:
$ ./mvnw clean install
-
With a current working directory of
PCC-Sample-App-PizzaStore
, push the app to your services foundation with acf push
command. Note the app's route (APP-URL
).
Interact with the running app by hitting the endpoints exposed by the app.
You can use gfsh to inspect the service instance. Follow the instructions in Accessing a Service Instance to connect to the cluster using gfsh.
Running an app foundation app requires a service gateway. To set up a service gateway, follow the directions in Configure a Service Gateway.
-
Make note of the
SERVICE-INSTANCE-NAME
when you Create a Service Instance. Provide the optional parameters for enabling TLS and specifying the creation of a service gateway. -
Follow these instructions to Create Truststore for the App. Note the password you set for the truststore.
-
Copy the truststore to the
resources
directory within the app source code. -
Follow these instructions to Create a Service Key.
-
Edit the app's
src/main/resources/application-app-foundation.properties
file, and specify the properties described in Specifying Application Properties. Find the values needed in the service key and the truststore. -
Edit the app's
manifest_app_foundation.yml
file to specify the truststore password noted when you created the truststore. -
Build the app:
$ ./mvnw clean install
-
Do a
cf login
that targets the app foundation's org and space. With a current working directory ofPCC-Sample-App-PizzaStore
, push the app to the app foundation, specifying the manifest:$ cf push -f manifest_app_foundation.yml
Note the app's route (
APP-URL
).
Interact with the running app by hitting the endpoints exposed by the app.
Running an app that is not on any Cloud Foundry foundation requires a service gateway. To set up a service gateway, follow the directions in Configure a Service Gateway.
-
Make note of the
SERVICE-INSTANCE-NAME
when you Create a Service Instance. Provide the optional parameters for enabling TLS and specifying the creation of a service gateway. -
Follow these instructions to Create Truststore for the App. Note the password you set for the truststore.
-
Copy the truststore to the
resources
directory within the app source code. -
Follow these instructions to Create a Service Key.
-
Edit the app's
src/main/resources/application-off-platform.properties
file, and specify the properties described in Specifying Application Properties. Find the values needed in the service key and the truststore. -
Build the app:
$ ./mvnw clean install
-
Run the app locally:
$ ./mvnw spring-boot:run -Dspring-boot.run.profiles=off-platform -Dspring-boot.run.jvmArguments="-Djavax.net.ssl.trustStore=/tmp/mytruststore1.jks -Djavax.net.ssl.trustStorePassword=PASSWD-HERE"
replacing
PASSWD-HERE
with the truststore password noted when you created the truststore.
Interact with the running app by hitting the endpoints exposed by the app at http://localhost:8080.