このコンテンツは選択した言語では利用できません。
Chapter 4. Tutorials
The following example uses CarMart quickstart to deploy EAP 6.4 / EAP 7.0 Infinispan application, accessing a remote JBoss Data Grid server running in the same OpenShift project.
4.1.1. Prerequisite リンクのコピーリンクがクリップボードにコピーされました!
Create a new project.
oc new-project jdg-bin-demo
$ oc new-project jdg-bin-demoCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteFor brevity this example will not configure clustering. See dedicated section if data replication across the cluster is desired.
4.1.2. Deploy JBoss Data Grid 7.1 server リンクのコピーリンクがクリップボードにコピーされました!
Identify the image stream for the JBoss Data Grid 7.1 image.
oc get is -n openshift | grep grid | cut -d ' ' -f 1 jboss-datagrid71-openshift
$ oc get is -n openshift | grep grid | cut -d ' ' -f 1 jboss-datagrid71-openshiftCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the server. Also specify the following:
-
carcacheas the name of application, - A Hot Rod based connector, and
carcacheas the name of the Infinispan cache to configure.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
4.1.3. Deploy binary build of EAP 6.4 / EAP 7.0 CarMart application リンクのコピーリンクがクリップボードにコピーされました!
Clone the source code.
git clone https://github.com/jboss-openshift/openshift-quickstarts.git
$ git clone https://github.com/jboss-openshift/openshift-quickstarts.gitCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Configure the Red Hat JBoss Middleware Maven repository.
Build the
datagrid/carmartapplication.cd openshift-quickstarts/datagrid/carmart/
$ cd openshift-quickstarts/datagrid/carmart/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Prepare the directory structure on the local file system.
Application archives in the deployments/ subdirectory of the main binary build directory are copied directly to the standard deployments folder of the image being built on OpenShift. For the application to deploy, the directory hierarchy containing the web application data must be correctly structured.
Create main directory for the binary build on the local file system and deployments/ subdirectory within it. Copy the previously built WAR archive for the carmart quickstart to the deployments/ subdirectory:
ls pom.xml README.md README-openshift.md README-tomcat.md src target
$ ls pom.xml README.md README-openshift.md README-tomcat.md src targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow mkdir -p jdg-binary-demo/deployments
$ mkdir -p jdg-binary-demo/deploymentsCopy to Clipboard Copied! Toggle word wrap Toggle overflow cp target/jboss-carmart.war jdg-binary-demo/deployments/
$ cp target/jboss-carmart.war jdg-binary-demo/deployments/Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteLocation of the standard deployments directory depends on the underlying base image, that was used to deploy the application. See the following table:
Expand Table 4.1. Standard Location of the Deployments Directory Name of the Underlying Base Image(s) Standard Location of the Deployments Directory EAP for OpenShift 6.4 and 7.0
$JBOSS_HOME/standalone/deployments
Java S2I for OpenShift
/deployments
JWS for OpenShift
$JWS_HOME/webapps
Identify the image stream for EAP 6.4 / EAP 7.0 image.
oc get is -n openshift | grep eap | cut -d ' ' -f 1 jboss-eap64-openshift jboss-eap70-openshift
$ oc get is -n openshift | grep eap | cut -d ' ' -f 1 jboss-eap64-openshift jboss-eap70-openshiftCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Create new binary build, specifying image stream and application name.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteSpecify
jboss-eap70-openshiftas the image stream name in the aforementioned command to use EAP 7.0 image for the application.Start the binary build. Instruct
ocexecutable to use main directory of the binary build we created in previous step as the directory containing binary input for the OpenShift build.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a new OpenShift application based on the build.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expose the service as route.
oc get svc -o name service/carcache service/eap-app
$ oc get svc -o name service/carcache service/eap-appCopy to Clipboard Copied! Toggle word wrap Toggle overflow oc get route No resources found.
$ oc get route No resources found.Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc expose svc/eap-app route "eap-app" exposed
$ oc expose svc/eap-app route "eap-app" exposedCopy to Clipboard Copied! Toggle word wrap Toggle overflow oc get route NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD eap-app eap-app-jdg-bin-demo.openshift.example.com eap-app 8080-tcp None
$ oc get route NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD eap-app eap-app-jdg-bin-demo.openshift.example.com eap-app 8080-tcp NoneCopy to Clipboard Copied! Toggle word wrap Toggle overflow Access the application.
Access the CarMart application in your browser using the URL http://eap-app-jdg-bin-demo.openshift.example.com/jboss-carmart. You can view / remove existing cars (Home tab), or add a new car (New car tab).
The following example details the procedure to perform a rolling upgrade from JBoss Data Grid 6.5 for OpenShift image to JBoss Data Grid 7.1 for OpenShift image, using the REST connector.
When performing a rolling upgrade it is recommended to not update any cache entries in the source cluster, as this may lead to data inconsistency.
4.2.1. Start / Deploy the Source Cluster リンクのコピーリンクがクリップボードにコピーされました!
A rolling upgrade to succeed, it assumes the Source Cluster with properties similar to the ones below:
- The name of the source JBoss Data Grid 6.5 cluster is jdg65-cluster and it has been deployed using the datagrid65-basic template or similar.
- The name of the replicated cache to synchronize its content during rolling upgrade is clustercache.
- The REST Infinispan connector has been configured for the application.
- The service name of the REST connector endpoint on JBoss Data Grid 6.5 cluster is jdg65-cluster.
- The clustercache replicated cache has been previously populated with some content to synchronize.
to be up and running.
For demonstration purposes source JBoss Data Grid 6.5 for OpenShift cluster with aforementioned properties can be deployed running e.g. the following steps:
Create a dedicated OpenShift project.
oc new-project jdg-rest-rolling-upgrade-demo
$ oc new-project jdg-rest-rolling-upgrade-demoCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy source JBoss Data Grid 6.5 cluster with the REST connector enabled, utilizing replicated cache named clustercache.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Populate clustercache with some content to synchronize later.
Add some entries using JBoss Data Grid CLI.
Given the following JBoss Data Grid CLI file to add cache entries non-interactively.
mkdir -p cache-entries
$ mkdir -p cache-entriesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow Please note a rolling upgrade will fail (BZ-1101512 - CLI UPGRADE command fails when testing data stored via CLI with REST encoding) when storing cache data via CLI using the
--codec=restencoding parameter for theputcommands in previous step.To overcome this issue, we do not specify codec to be used for encoding of cache entries (cache entries will be stored using the default
noneencoding).Get the name of the JBoss Data Grid 6.5 pod.
export JDG65_POD=$(oc get pods -o name \ | grep -Po "[^/]+$" | grep "jdg65" \ | grep -v "deploy")
$ export JDG65_POD=$(oc get pods -o name \ | grep -Po "[^/]+$" | grep "jdg65" \ | grep -v "deploy")Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the
cache-input.clifile to JBoss Data Grid 6.5 pod.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add entries to clustercache by executing commands from
cli-input.clifile.oc rsh $JDG65_POD /opt/datagrid/bin/cli.sh \ --connect=localhost --file=/tmp/cache-input.cli Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jboss
$ oc rsh $JDG65_POD /opt/datagrid/bin/cli.sh \ --connect=localhost --file=/tmp/cache-input.cli Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jbossCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Add some entries directly via remote REST client.
Get the host value of the route for jdg65-cluster.
export JDG65_ROUTE=$(oc get routes \ --no-headers | grep "jdg65" | tr -s ' ' \ | cut -d ' ' -f2)
$ export JDG65_ROUTE=$(oc get routes \ --no-headers | grep "jdg65" | tr -s ' ' \ | cut -d ' ' -f2)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add example
ExampleKeyentry to clustercache using the REST endpoint remotely.curl -X PUT -d "ExampleValue" \ $JDG65_ROUTE/rest/clustercache/ExampleKey
$ curl -X PUT -d "ExampleValue" \ $JDG65_ROUTE/rest/clustercache/ExampleKeyCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2.2. Deploy the Target Cluster リンクのコピーリンクがクリップボードにコピーされました!
Perform the following to deploy JBoss Data Grid 7.1 cluster with the name of jdg71-cluster, using datagrid71-basic template, and clustercache as the name of the replicated cache to synchronize during the rolling upgrade:
The datagrid71-basic template uses ephemeral, in-memory datastore for the most frequently accessed data. Therefore any cache data, synchronized during a rolling upgrade will be available only during lifecycle of a JDG 7.1 pod (from rolling upgrade to pod restart). Use persistent templates (datagrid71-mysql-persistent or datagrid71-postgresql-persistent) to preserve the previously synchronized cache data across pod restarts.
4.2.3. Configure REST Store for Caches on the Target Cluster リンクのコピーリンクがクリップボードにコピーされました!
For each cache in the Target Cluster, intended to be synchronized during a rolling upgrade, configure a RestCacheStore with the following settings:
- Ensure that the host and port values point to the Source Cluster.
- Ensure that the path value points to the REST endpoint of the Source Cluster.
Given the following helper script to add a REST store to all replicated caches defined in CACHE_NAMES array:
mkdir -p update-cache
$ mkdir -p update-cache
Edit the definition of the REST_SERVICE variable below to match the name of the REST service endpoint for your environment. Also, edit the definition of CACHE_NAMES variable in the following helper script to contain names of all caches, that should be equipped with the definition of a REST store.
, perform the following:
Get the name of the JBoss Data Grid 7.1 pod.
export JDG71_POD=$(oc get pods -o name \ | grep -Po "[^/]+$" | grep "jdg71" | grep -v "deploy")
$ export JDG71_POD=$(oc get pods -o name \ | grep -Po "[^/]+$" | grep "jdg71" | grep -v "deploy")Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the
add-rest-store-to-cache.shscript to JBoss Data Grid 7.1 pod.oc rsync --no-perms=true update-cache/ $JDG71_POD:/tmp sending incremental file list sent 71 bytes received 11 bytes 54.67 bytes/sec total size is 892 speedup is 10.88
$ oc rsync --no-perms=true update-cache/ $JDG71_POD:/tmp sending incremental file list sent 71 bytes received 11 bytes 54.67 bytes/sec total size is 892 speedup is 10.88Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the script to:
-
Add REST store definition to each replicated cache from
CACHE_NAMESarray. - Set host and port to point to the Source Cluster.
oc rsh $JDG71_POD /bin/bash /tmp/add-rest-store-to-cache.sh
$ oc rsh $JDG71_POD /bin/bash /tmp/add-rest-store-to-cache.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Add REST store definition to each replicated cache from
Restart the JBoss Data Grid 7.1 server in order the corresponding caches to recognize the REST store configuration.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow WarningWhen restarting the server it is important to restart just the JBoss Data Grid process within the running container, not the whole container, since in the latter case the JBoss Data Grid container would be recreated with the default configuration from scratch, without the REST store(s) to be defined for specific cache(s).
4.2.4. Do Not Dump the Key Set During REST Rolling Upgrades リンクのコピーリンクがクリップボードにコピーされました!
The REST rolling upgrades use case is designed to fetch all the data from the Source Cluster without using the recordKnownGlobalKeyset operation.
Do not invoke the recordKnownGlobalKeyset operation for REST rolling upgrades. If you invoke this operation, it will cause data corruption and REST rolling upgrades will not complete successfully.
4.2.5. Synchronize Cache Data Using the REST Connector リンクのコピーリンクがクリップボードにコピーされました!
Run the upgrade --synchronize=rest on the Target Cluster for all caches to be migrated. Optionally, use the --all switch to synchronize all caches in the cluster.
oc rsh $JDG71_POD /opt/datagrid/bin/cli.sh -c \ --commands='cd /subsystem=datagrid-infinispan/cache-container=clustered, \ cache clustercache,upgrade --synchronize=rest' Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jboss ISPN019500: Synchronized 5 entries using migrator 'rest' on cache 'clustercache'
$ oc rsh $JDG71_POD /opt/datagrid/bin/cli.sh -c \
--commands='cd /subsystem=datagrid-infinispan/cache-container=clustered, \
cache clustercache,upgrade --synchronize=rest'
Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jboss
ISPN019500: Synchronized 5 entries using migrator 'rest' on cache 'clustercache'
4.2.6. Use the Synchronized Data from the JBoss Data Grid 7.1 (Target) cluster リンクのコピーリンクがクリップボードにコピーされました!
All the requested data have been just synchronized. You can now point the client application(s) to the Target Cluster.
Get the value of
key1from the JBoss Data Grid 7.1 cache via CLI.oc rsh $JDG71_POD /opt/datagrid/bin/cli.sh -c \ --commands='cd /subsystem=datagrid-infinispan/cache-container=clustered, \ cache clustercache,get key1' \ | grep '"' | base64 -di; echo val1
$ oc rsh $JDG71_POD /opt/datagrid/bin/cli.sh -c \ --commands='cd /subsystem=datagrid-infinispan/cache-container=clustered, \ cache clustercache,get key1' \ | grep '"' | base64 -di; echo val1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the value of
ExampleKeyfrom the JBoss Data Grid 7.1 cache via remote REST call.Get the value of JBoss Data Grid 7.1 route.
JDG71_ROUTE=$(oc get routes | grep jdg71 \ | tr -s ' ' | cut -d ' ' -f2)
$ JDG71_ROUTE=$(oc get routes | grep jdg71 \ | tr -s ' ' | cut -d ' ' -f2)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the value of
ExampleKeyvia remote REST client.curl -X GET \ $JDG71_ROUTE/rest/clustercache/ExampleKey; echo ExampleValue
$ curl -X GET \ $JDG71_ROUTE/rest/clustercache/ExampleKey; echo ExampleValueCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2.7. Disable the RestCacheStore on the Target Cluster リンクのコピーリンクがクリップボードにコピーされました!
Once the Target Cluster has obtained all data from the Source Cluster, disable the RestCacheStore (for each cache it has been previously configured) on the Target Cluster using the following command:
oc rsh $JDG71_POD /opt/datagrid/bin/cli.sh -c \ --commands='cd /subsystem=datagrid-infinispan/cache-container=clustered, \ cache clustercache,upgrade --disconnectsource=rest' Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jboss ISPN019501: Disconnected 'rest' migrator source on cache 'clustercache'
$ oc rsh $JDG71_POD /opt/datagrid/bin/cli.sh -c \
--commands='cd /subsystem=datagrid-infinispan/cache-container=clustered, \
cache clustercache,upgrade --disconnectsource=rest'
Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jboss
ISPN019501: Disconnected 'rest' migrator source on cache 'clustercache'
The Source Cluster can now be decommissioned.