|
| 1 | +== Coherence Operator Federation Example |
| 2 | + |
| 3 | +This simple example demostrates the Coherence federation feature. It shows how to deploy two Coherence clusters that federating data between them using the Coherence Operator. The Coherence federation feature requires Coherence Grid Edition. See https://oracle.github.io/coherence-operator/docs/latest/#/installation/04_obtain_coherence_images[Obtain Coherence Images] on how to get a commercial Coherence image. |
| 4 | + |
| 5 | +You can find the source code in the https://github.com/oracle/coherence-operator/tree/master/examples/federation[Operator GitHub Repo]. |
| 6 | + |
| 7 | +==== What the Example will Cover |
| 8 | + |
| 9 | +* <<install-operator,Install the Coherence Operator>> |
| 10 | +* <<create-the-example-namespace,Create the example namespace>> |
| 11 | +* <<create-secret,Create image pull and config store secrets>> |
| 12 | +* <<example, Run the Example>> |
| 13 | +* <<cleanup, Cleaning Up>> |
| 14 | + |
| 15 | +[#install-operator] |
| 16 | +== Install the Coherence Operator |
| 17 | + |
| 18 | +To run the examples below, you will need to have installed the Coherence Operator, do this using whatever method you prefer from the https://oracle.github.io/coherence-operator/docs/latest/#/installation/01_installation[Installation Guide]. |
| 19 | + |
| 20 | +Once you complete, confirm the operator is running, for example: |
| 21 | +[source,bash] |
| 22 | +---- |
| 23 | +kubectl get pods -n coherence |
| 24 | +
|
| 25 | +NAME READY STATUS RESTARTS AGE |
| 26 | +coherence-operator-controller-manager-74d49cd9f9-sgzjr 1/1 Running 1 27s |
| 27 | +---- |
| 28 | + |
| 29 | +[#create-the-example-namespace] |
| 30 | +== Create the example namespace |
| 31 | + |
| 32 | +First, run the following command to create the namespace, coherence-example, for the example: |
| 33 | + |
| 34 | +[source,bash] |
| 35 | +---- |
| 36 | +kubectl create namespace coherence-example |
| 37 | +
|
| 38 | +namespace/coherence-example created |
| 39 | +---- |
| 40 | + |
| 41 | +[#create-secret] |
| 42 | +== Create image pull and configure store secrets |
| 43 | + |
| 44 | +This example reqires two secrets: |
| 45 | + |
| 46 | +* An image pull secret named ocr-pull-secret containing your OCR credentials to be used by the example. |
| 47 | + |
| 48 | +Use a command similar to the following to create the image pull secret: |
| 49 | + |
| 50 | +[source,bash] |
| 51 | +---- |
| 52 | +kubectl create secret docker-registry ocr-pull-secret \ |
| 53 | + --docker-server=container-registry.oracle.com \ |
| 54 | + --docker-username="<username>" --docker-password="<password>" \ |
| 55 | + --docker-email="<email>" -n coherence-example |
| 56 | +---- |
| 57 | + |
| 58 | +* A configure store secret named storage-config to store the Coherence configuration files. |
| 59 | + |
| 60 | +Run the following command to create the configure store secret: |
| 61 | + |
| 62 | +[source,bash] |
| 63 | +---- |
| 64 | +kubectl create secret generic storage-config -n coherence-example \ |
| 65 | + --from-file=src/main/resources/tangosol-coherence-override.xml \ |
| 66 | + --from-file=src/main/resources/storage-cache-config.xml |
| 67 | +---- |
| 68 | + |
| 69 | +[#example] |
| 70 | +== Run the Example |
| 71 | + |
| 72 | +Ensure you are in the `examples/federation` directory to run the example. This example uses the yaml files `src/main/yaml/primary-cluster.yaml` and `src/main/yaml/secondary-cluster.yaml`, which |
| 73 | +define a primary cluster and a secondary cluster. |
| 74 | + |
| 75 | +==== 1. Install the Coherence clusters |
| 76 | + |
| 77 | +Run the following commands to create the primary and secondary clusters: |
| 78 | + |
| 79 | +[source,bash] |
| 80 | +---- |
| 81 | +kubectl -n coherence-example create -f src/main/yaml/primary-cluster.yaml |
| 82 | +
|
| 83 | +coherence.coherence.oracle.com/primary-cluster created |
| 84 | +---- |
| 85 | + |
| 86 | +[source,bash] |
| 87 | +---- |
| 88 | +kubectl -n coherence-example create -f src/main/yaml/secondary-cluster.yaml |
| 89 | +
|
| 90 | +coherence.coherence.oracle.com/secondary-cluster created |
| 91 | +---- |
| 92 | + |
| 93 | + |
| 94 | +==== 2. List the created Coherence clusters |
| 95 | +Run the following command to list the clusters: |
| 96 | + |
| 97 | +[source,bash] |
| 98 | +---- |
| 99 | +kubectl -n coherence-example get coherence |
| 100 | +
|
| 101 | +NAME CLUSTER ROLE REPLICAS READY PHASE |
| 102 | +primary-cluster primary-cluster primary-cluster 2 2 Ready |
| 103 | +secondary-cluster secondary-cluster secondary-cluster 2 2 Ready |
| 104 | +---- |
| 105 | + |
| 106 | +To see the Coherence cache configuration file loaded from the secret volumn we defined, run the following command: |
| 107 | + |
| 108 | +[source,bash] |
| 109 | +---- |
| 110 | +kubectl logs -n coherence-example primary-cluster-0 | grep "Loaded cache" |
| 111 | +
|
| 112 | +... Oracle Coherence GE 14.1.1.0.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "file:/config/storage-cache-config.xml" |
| 113 | +---- |
| 114 | + |
| 115 | +==== 3. View the running pods |
| 116 | + |
| 117 | +Run the following command to view the Pods: |
| 118 | +[source,bash] |
| 119 | +---- |
| 120 | +kubectl -n coherence-example get pods |
| 121 | +---- |
| 122 | + |
| 123 | +[source,bash] |
| 124 | +---- |
| 125 | +NAME READY STATUS RESTARTS AGE |
| 126 | +primary-cluster-0 1/1 Running 0 83s |
| 127 | +primary-cluster-1 1/1 Running 0 83s |
| 128 | +secondary-cluster-0 1/1 Running 0 74s |
| 129 | +secondary-cluster-1 1/1 Running 0 73s |
| 130 | +---- |
| 131 | + |
| 132 | +==== 4. Connect to the Coherence Console inside the primary cluster to add data |
| 133 | + |
| 134 | +We will connect via Coherence console to add some data using the following commands: |
| 135 | + |
| 136 | +[source,bash] |
| 137 | +---- |
| 138 | +kubectl exec -it -n coherence-example primary-cluster-0 /coherence-operator/utils/runner console |
| 139 | +---- |
| 140 | + |
| 141 | +At the prompt type the following to create a cache called `test`: |
| 142 | + |
| 143 | +[source,bash] |
| 144 | +---- |
| 145 | +cache test |
| 146 | +---- |
| 147 | + |
| 148 | +Use the following to add an entry with "primarykey" and "primaryvalue": |
| 149 | + |
| 150 | +[source,bash] |
| 151 | +---- |
| 152 | +put "primarykey" "primaryvalue" |
| 153 | +---- |
| 154 | + |
| 155 | +Use the following to create 10,000 entries of 100 bytes: |
| 156 | +[source,bash] |
| 157 | +---- |
| 158 | +bulkput 10000 100 0 100 |
| 159 | +---- |
| 160 | + |
| 161 | +Lastly issue the command `size` to verify the cache entry count. It should be 10001. |
| 162 | + |
| 163 | +Type `bye` to exit the console. |
| 164 | + |
| 165 | +==== 6. Connect to the Coherence Console inside the secondary cluster to verify that data is federated from primary cluster |
| 166 | + |
| 167 | +We will connect via Coherence console to confirm that the data we added to the primary cluster is federated to the secondary cluster. |
| 168 | + |
| 169 | +[source,bash] |
| 170 | +---- |
| 171 | +kubectl exec -it -n coherence-example secondary-cluster-0 /coherence-operator/utils/runner console |
| 172 | +---- |
| 173 | + |
| 174 | +At the prompt type the following to set the cache to `test`: |
| 175 | + |
| 176 | +[source,bash] |
| 177 | +---- |
| 178 | +cache test |
| 179 | +---- |
| 180 | + |
| 181 | +Use the following to get entry with "primarykey": |
| 182 | + |
| 183 | +[source,bash] |
| 184 | +---- |
| 185 | +get "primarykey" |
| 186 | +primaryvalue |
| 187 | +---- |
| 188 | + |
| 189 | +Issue the command `size` to verify the cache entry count. It should be 10001. |
| 190 | + |
| 191 | +Our federation has Active/Active topology. So, the data changes in both primary and secondary clusters are federated between the clusters. Use the following to add an entry with "secondarykey" and "secondaryvalue": |
| 192 | +[source,bash] |
| 193 | +---- |
| 194 | +put "secondarykey" "secondaryvalue" |
| 195 | +---- |
| 196 | + |
| 197 | +==== 7. Confirm the primary cluster also received "secondarykey", "secondaryvalue" entry |
| 198 | + |
| 199 | +Follow the command in the previous section to connect to the Coherence Console inside the primary cluster. |
| 200 | + |
| 201 | +Use the following command to confirm that entry with "secondarykey" is federated to primary cluster: |
| 202 | + |
| 203 | +[source,bash] |
| 204 | +---- |
| 205 | +get "secondarykey" |
| 206 | +secondaryvalue |
| 207 | +---- |
| 208 | + |
| 209 | +[#cleanup] |
| 210 | +== Cleaning up |
| 211 | + |
| 212 | +Use the following commands to delete the primary and secondary clusters: |
| 213 | + |
| 214 | +[source,bash] |
| 215 | +---- |
| 216 | +kubectl -n coherence-example delete -f src/main/yaml/primary-cluster.yaml |
| 217 | +
|
| 218 | +kubectl -n coherence-example delete -f src/main/yaml/secondary-cluster.yaml |
| 219 | +---- |
| 220 | + |
| 221 | +Uninstall the Coherence operator using the undeploy commands for whichever method you chose to install it. |
0 commit comments