Skip to content

Commit

Permalink
Merge pull request #21 from hazelcast-guides/revert-20-cn-1202
Browse files Browse the repository at this point in the history
Revert "[CN-1202] Revisit Connect to Hazelcast from Outside Kubernetes Tutorial"
  • Loading branch information
oliverhowell authored May 15, 2024
2 parents 51d5847 + f3641c9 commit a190a47
Show file tree
Hide file tree
Showing 28 changed files with 172 additions and 69 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/integrational-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ env:
GCP_PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_ZONE: europe-west1-b
GCP_NETWORK: tutorial-test-network
EXAMPLES_DIR: docs/modules/ROOT/examples

jobs:
create-gke-cluster:
Expand Down Expand Up @@ -80,10 +79,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK
- name: Set up JDK 1.8
uses: actions/setup-java@v2
with:
java-version: 17
java-version: 8
distribution: "adopt"
cache: "maven"

Expand Down Expand Up @@ -164,7 +163,7 @@ jobs:
- name: Test Java Client
run: |-
EXTERNAL_IP="${{ env.EXTERNAL_IP }}"
cd $EXAMPLES_DIR/java${{matrix.suffix}}
cd java${{matrix.suffix}}
sed -i "s/<EXTERNAL-IP>/$EXTERNAL_IP/g" src/main/java/com/hazelcast/Main.java
mvn package
java -jar target/*jar-with-dependencies*.jar >> output-java.txt &
Expand All @@ -177,7 +176,7 @@ jobs:
- name: Test Node.js Client
run: |-
EXTERNAL_IP="${{ env.EXTERNAL_IP }}"
cd $EXAMPLES_DIR/nodejs${{matrix.suffix}}
cd nodejs${{matrix.suffix}}
sed -i "s/<EXTERNAL-IP>/$EXTERNAL_IP/g" client.js
npm install
npm start >> output-nodejs.txt &
Expand All @@ -190,7 +189,7 @@ jobs:
- name: Test Go Client
run: |-
EXTERNAL_IP="${{ env.EXTERNAL_IP }}"
cd $EXAMPLES_DIR/go${{matrix.suffix}}
cd go${{matrix.suffix}}
sed -i "s/<EXTERNAL-IP>/$EXTERNAL_IP/g" main.go
go run main.go >> output-go.txt &
PID=$!
Expand All @@ -202,7 +201,7 @@ jobs:
- name: Test Python Client
run: |-
EXTERNAL_IP="${{ env.EXTERNAL_IP }}"
cd $EXAMPLES_DIR/python${{matrix.suffix}}
cd python${{matrix.suffix}}
sed -i "s/<EXTERNAL-IP>/$EXTERNAL_IP/g" main.py
pip install -r requirements.txt
python main.py >> output-python.txt &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

* Up and running https://kubernetes.io/[Kubernetes] cluster
* Kubernetes command-line tool, https://kubernetes.io/docs/tasks/tools/#kubectl[kubectl]
* Deployed xref:operator:ROOT:get-started.adoc[Hazelcast Platform Operator]

WARNING: This tutorial uses LoadBalancer services to connect to Hazelcast from outside of the Kubernetes cluster. Therefore, it is essential to ensure that your Kubernetes cluster can assign public IPs to LoadBalancer services. This is particularly important if you are using a local Kubernetes cluster such as Minikube or Kind.
* Deployed xref:operator:ROOT:index.adoc[Hazelcast Platform Operator]

== Introduction

Expand All @@ -43,8 +41,15 @@ Run the following command to create the Hazelcast cluster with Expose Externally

[source, shell]
----
kubectl apply -f - <<EOF
include::ROOT:example$/hazelcast-unisocket.yaml[]
cat <<EOF | kubectl apply -f -
apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
name: my-hazelcast
spec:
exposeExternally:
type: Unisocket
discoveryServiceType: LoadBalancer
EOF
----

Expand Down Expand Up @@ -78,15 +83,13 @@ The `ADDRESS` column displays the external address of your Hazelcast cluster.

=== Connect Hazelcast Clients to the Cluster

To access all sample clients, clone the following repository:

To access all examples (excluding CLC), clone the following repository.
[source,shell]
----
git clone https://github.com/hazelcast-guides/hazelcast-platform-operator-expose-externally.git
cd hazelcast-platform-operator-expose-externally
----

. The sample code(excluding CLC) for this tutorial is in the link:https://github.com/hazelcast-guides/hazelcast-platform-operator-expose-externally/tree/master/docs/modules/ROOT/examples[`docs/modules/ROOT/examples/`] directory.

Configure the Hazelcast client with the external address and disable smart routing to use the unisocket connection.

Expand All @@ -111,7 +114,9 @@ Java::
--
[source, java]
----
include::ROOT:example$/java-unisocket/src/main/java/com/hazelcast/Main.java[]
ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress("<EXTERNAL-IP>")
.setSmartRouting(false);
----
--
Expand All @@ -120,7 +125,17 @@ NodeJS::
--
[source, javascript]
----
include::ROOT:example$/nodejs-unisocket/client.js[]
const { Client } = require('hazelcast-client');
const clientConfig = {
network: {
clusterMembers: [
'<EXTERNAL-IP>'
],
smartRouting: false
}
};
const client = await Client.newHazelcastClient(clientConfig);
----
--
Expand All @@ -129,7 +144,23 @@ Go::
--
[source, go]
----
include::ROOT:example$/go-unisocket/main.go[]
import (
"log"
"github.com/hazelcast/hazelcast-go-client"
)
func main() {
config := hazelcast.Config{}
cc := &config.Cluster
cc.Network.SetAddresses("<EXTERNAL-IP>")
cc.Unisocket = true
ctx := context.TODO()
client, err := hazelcast.StartNewClientWithConfig(ctx, config)
if err != nil {
panic(err)
}
}
----
--
Expand All @@ -138,15 +169,32 @@ Python::
--
[source, python]
----
include::ROOT:example$/python-unisocket/main.py[]
import logging
import hazelcast
logging.basicConfig(level=logging.INFO)
client = hazelcast.HazelcastClient(
cluster_members=["<EXTERNAL-IP>"],
smart_routing=False,
)
----
--
.NET::
+
--
[source, cs]
----
include::ROOT:example$/dotnet-unisocket/csharp_example.cs[]
var options = new HazelcastOptionsBuilder()
.With(args)
.With((configuration, options) =>
{
options.LoggerFactory.Creator = () => LoggerFactory.Create(loggingBuilder => loggingBuilder.AddConfiguration(configuration.GetSection("logging")).AddConsole());
options.Networking.Addresses.Add("<EXTERNAL-IP>");
options.Networking.SmartRouting = false;
})
.Build();
var client = await HazelcastClientFactory.StartNewClientAsync(options);
----
--
====
Expand Down Expand Up @@ -310,8 +358,16 @@ Run the following command to create the Hazelcast cluster with Expose Externally

[source, shell]
----
kubectl apply -f - <<EOF
include::ROOT:example$/hazelcast.yaml[]
cat <<EOF | kubectl apply -f -
apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
name: my-hazelcast
spec:
exposeExternally:
type: Smart
discoveryServiceType: LoadBalancer
memberAccess: LoadBalancer
EOF
----

Expand Down Expand Up @@ -379,7 +435,9 @@ Java::
--
[source, java]
----
include::ROOT:example$/java/src/main/java/com/hazelcast/Main.java[]
ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress("<EXTERNAL-IP>");
config.getProperties().setProperty(ClientProperty.DISCOVERY_SPI_PUBLIC_IP_ENABLED.toString(), "true");
----
--
Expand All @@ -388,7 +446,19 @@ NodeJS::
--
[source, javascript]
----
include::ROOT:example$/nodejs/client.js[]
const { Client } = require('hazelcast-client');
const clientConfig = {
network: {
clusterMembers: [
'<EXTERNAL-IP>'
]
},
properties: {
['hazelcast.discovery.public.ip.enabled']: true
}
};
const client = await Client.newHazelcastClient(clientConfig);
----
--
Expand All @@ -397,7 +467,23 @@ Go::
--
[source, go]
----
include::ROOT:example$/go/main.go[]
import (
"log"
"github.com/hazelcast/hazelcast-go-client"
)
func main() {
config := hazelcast.Config{}
cc := &config.Cluster
cc.Network.SetAddresses("<EXTERNAL-IP>")
cc.Discovery.UsePublicIP = true
ctx := context.TODO()
client, err := hazelcast.StartNewClientWithConfig(ctx, config)
if err != nil {
panic(err)
}
}
----
--
Expand All @@ -406,15 +492,33 @@ Python::
--
[source, python]
----
include::ROOT:example$/python/main.py[]
import logging
import hazelcast
logging.basicConfig(level=logging.INFO)
client = hazelcast.HazelcastClient(
cluster_members=["<EXTERNAL-IP>"],
use_public_ip=True,
)
----
--
.Net::
+
--
[source, cs]
----
include::ROOT:example$/dotnet/csharp_example.cs[]
var options = new HazelcastOptionsBuilder()
.With(args)
.With((configuration, options) =>
{
options.LoggerFactory.Creator = () => LoggerFactory.Create(loggingBuilder => loggingBuilder.AddConfiguration(configuration.GetSection("logging")).AddConsole());
options.Networking.Addresses.Add("<EXTERNAL-IP>");
options.Networking.UsePublicAddresses = true;
})
.Build();
var client = await HazelcastClientFactory.StartNewClientAsync(options);
----
--
====
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hazelcast.Net" Version="5.3.1" />
<PackageReference Include="Hazelcast.Net" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
</ItemGroup>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hazelcast.Net" Version="5.3.1" />
<PackageReference Include="Hazelcast.Net" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/hazelcast-guides/kubernetes/go
go 1.15

require (
github.com/hazelcast/hazelcast-go-client v1.4.1
github.com/hazelcast/hazelcast-go-client v1.4.0
github.com/shirou/gopsutil/v3 v3.21.10 // indirect
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hazelcast/hazelcast-go-client v1.4.1 h1:BSpJqqjbACI4MugfWXGxk+JdZR3JRELx0n769pa85kA=
github.com/hazelcast/hazelcast-go-client v1.4.1/go.mod h1:PJ38lqXJ18S0YpkrRznPDlUH8GnnMAQCx3jpQtBPZ6Q=
github.com/hazelcast/hazelcast-go-client v1.4.0 h1:8+fvcG+Owf5mi3qezc8FN9CG6Vpb6x8tqKTb9nXrQWk=
github.com/hazelcast/hazelcast-go-client v1.4.0/go.mod h1:PJ38lqXJ18S0YpkrRznPDlUH8GnnMAQCx3jpQtBPZ6Q=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/examples/go/go.mod → go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/hazelcast-guides/kubernetes/go
go 1.15

require (
github.com/hazelcast/hazelcast-go-client v1.4.1
github.com/hazelcast/hazelcast-go-client v1.4.0
github.com/shirou/gopsutil/v3 v3.21.10 // indirect
)
4 changes: 2 additions & 2 deletions docs/modules/ROOT/examples/go/go.sum → go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hazelcast/hazelcast-go-client v1.4.1 h1:BSpJqqjbACI4MugfWXGxk+JdZR3JRELx0n769pa85kA=
github.com/hazelcast/hazelcast-go-client v1.4.1/go.mod h1:PJ38lqXJ18S0YpkrRznPDlUH8GnnMAQCx3jpQtBPZ6Q=
github.com/hazelcast/hazelcast-go-client v1.4.0 h1:8+fvcG+Owf5mi3qezc8FN9CG6Vpb6x8tqKTb9nXrQWk=
github.com/hazelcast/hazelcast-go-client v1.4.0/go.mod h1:PJ38lqXJ18S0YpkrRznPDlUH8GnnMAQCx3jpQtBPZ6Q=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>5.4.0</version>
<version>5.0</version>
</dependency>
</dependencies>

Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/examples/java/pom.xml → java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>5.4.0</version>
<version>5.0</version>
</dependency>
</dependencies>

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a190a47

Please sign in to comment.