Skip to content

Commit 60f3ced

Browse files
lshothegridman
andauthored
Added federation example (#477)
* Added federation example * fix Copyright * incorporated Jonathan Knight's review comments * Delete .primary-cluster-app.yaml.swp Co-authored-by: Jonathan Knight <[email protected]>
1 parent 3afae72 commit 60f3ced

File tree

6 files changed

+391
-1
lines changed

6 files changed

+391
-1
lines changed

examples/federation/README.adoc

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version='1.0'?>
2+
3+
<!--
4+
~ Copyright (c) 2021, Oracle and/or its affiliates.
5+
~ Licensed under the Universal Permissive License v 1.0 as shown at
6+
~ http://oss.oracle.com/licenses/upl.
7+
-->
8+
9+
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
11+
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
12+
13+
<caching-scheme-mapping>
14+
<cache-mapping>
15+
<cache-name>*</cache-name>
16+
<scheme-name>server</scheme-name>
17+
</cache-mapping>
18+
</caching-scheme-mapping>
19+
20+
<caching-schemes>
21+
<!-- federated caching scheme for servers -->
22+
<federated-scheme>
23+
<scheme-name>server</scheme-name>
24+
<backing-map-scheme>
25+
<local-scheme/>
26+
</backing-map-scheme>
27+
<autostart>true</autostart>
28+
<address-provider>
29+
<local-address>
30+
<address system-property="coherence.extend.address"></address>
31+
<port system-property="coherence.federation.port">40000</port>
32+
</local-address>
33+
</address-provider>
34+
<topologies>
35+
<topology>
36+
<name>Active</name>
37+
</topology>
38+
</topologies>
39+
</federated-scheme>
40+
</caching-schemes>
41+
</cache-config>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Copyright (c) 2021, Oracle and/or its affiliates.
4+
~ Licensed under the Universal Permissive License v 1.0 as shown at
5+
~ http://oss.oracle.com/licenses/upl.
6+
-->
7+
8+
<!--
9+
Grid Edition version of the override file which includes Federation.
10+
-->
11+
<coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
13+
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-operational-config coherence-operational-config.xsd">
14+
15+
<license-config>
16+
<edition-name system-property="coherence.edition">GE</edition-name>
17+
</license-config>
18+
19+
<!--
20+
Define a federation configuration for PrimaryCluster and SecondaryCluster
21+
where the default topology is Active-Active.
22+
-->
23+
<federation-config>
24+
<participants>
25+
<participant>
26+
<name system-property="primary.cluster">PrimaryCluster</name>
27+
<initial-action>start</initial-action>
28+
<remote-addresses>
29+
<socket-address>
30+
<address system-property="primary.cluster.host">primary-cluster-federation</address>
31+
<port system-property="primary.cluster.port">7574</port>
32+
</socket-address>
33+
</remote-addresses>
34+
</participant>
35+
<participant>
36+
<name system-property="secondary.cluster">SecondaryCluster</name>
37+
<initial-action>start</initial-action>
38+
<remote-addresses>
39+
<socket-address>
40+
<address system-property="secondary.cluster.host">secondary-cluster-federation</address>
41+
<port system-property="secondary.cluster.port">7574</port>
42+
</socket-address>
43+
</remote-addresses>
44+
</participant>
45+
</participants>
46+
<topology-definitions>
47+
<active-active>
48+
<name>Active</name>
49+
<active system-property="primary.cluster">PrimaryCluster</active>
50+
<active system-property="secondary.cluster">SecondaryCluster</active>
51+
</active-active>
52+
</topology-definitions>
53+
</federation-config>
54+
</coherence>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Copyright (c) 2021 Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at
4+
# http://oss.oracle.com/licenses/upl.
5+
#
6+
# Federation Example
7+
# Primary cluster in an Active/Active topology
8+
apiVersion: coherence.oracle.com/v1
9+
kind: Coherence
10+
metadata:
11+
name: primary-cluster
12+
spec:
13+
jvm:
14+
classpath:
15+
- /config
16+
- /u01/oracle/oracle_home/coherence/lib/coherence.jar
17+
args:
18+
- "-Dprimary.cluster=primary-cluster"
19+
- "-Dprimary.cluster.port=40000"
20+
- "-Dprimary.cluster.host=primary-cluster-federation"
21+
- "-Dsecondary.cluster=secondary-cluster"
22+
- "-Dsecondary.cluster.port=40000"
23+
- "-Dsecondary.cluster.host=secondary-cluster-federation"
24+
secretVolumes:
25+
- mountPath: /config
26+
name: storage-config
27+
ports:
28+
- name: federation
29+
port: 40000
30+
coherence:
31+
cacheConfig: storage-cache-config.xml
32+
overrideConfig: tangosol-coherence-override.xml
33+
logLevel: 9
34+
image: container-registry.oracle.com/middleware/coherence:14.1.1.0.0
35+
imagePullSecrets:
36+
- name: ocr-pull-secret
37+
replicas: 2
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Copyright (c) 2021 Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at
4+
# http://oss.oracle.com/licenses/upl.
5+
#
6+
# Federation Example
7+
# Secondary cluster in an Active/Active topology
8+
apiVersion: coherence.oracle.com/v1
9+
kind: Coherence
10+
metadata:
11+
name: secondary-cluster
12+
spec:
13+
jvm:
14+
classpath:
15+
- /config
16+
- /u01/oracle/oracle_home/coherence/lib/coherence.jar
17+
args:
18+
- "-Dprimary.cluster=primary-cluster"
19+
- "-Dprimary.cluster.port=40000"
20+
- "-Dprimary.cluster.host=primary-cluster-federation"
21+
- "-Dprimary.cluster=secondary-cluster"
22+
- "-Dsecondary.cluster.port=40000"
23+
- "-Dsecondary.cluster.host=secondary-cluster-federation"
24+
secretVolumes:
25+
- mountPath: /config
26+
name: storage-config
27+
ports:
28+
- name: federation
29+
port: 40000
30+
coherence:
31+
cacheConfig: storage-cache-config.xml
32+
overrideConfig: tangosol-coherence-override.xml
33+
logLevel: 9
34+
image: container-registry.oracle.com/middleware/coherence:14.1.1.0.0
35+
imagePullSecrets:
36+
- name: ocr-pull-secret
37+
replicas: 2

0 commit comments

Comments
 (0)