Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4f5d9310
Commit
4f5d9310
authored
May 26, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace wrong code with link
parent
caf5b5f0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
129 deletions
+1
-129
README.md
examples/hazelcast/README.md
+1
-129
No files found.
examples/hazelcast/README.md
View file @
4f5d9310
...
@@ -201,134 +201,6 @@ kubectl resize rc hazelcast --replicas=4
...
@@ -201,134 +201,6 @@ kubectl resize rc hazelcast --replicas=4
### Hazelcast Discovery Source
### Hazelcast Discovery Source
```
java
See
[
here
](
https://github.com/pires/hazelcast-kubernetes-bootstrapper/blob/master/src/main/java/com/github/pires/hazelcast/HazelcastDiscoveryController.java
)
package
com
.
github
.
pires
.
hazelcast
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.config.GroupConfig
;
import
com.hazelcast.config.JoinConfig
;
import
com.hazelcast.config.MulticastConfig
;
import
com.hazelcast.config.NetworkConfig
;
import
com.hazelcast.config.SSLConfig
;
import
com.hazelcast.config.TcpIpConfig
;
import
com.hazelcast.core.Hazelcast
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Controller
;
/**
* Read from Kubernetes API all Hazelcast service bound pods, get their IP and connect to them.
*/
@Controller
public
class
HazelcastDiscoveryController
implements
CommandLineRunner
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HazelcastDiscoveryController
.
class
);
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
static
class
Address
{
public
String
IP
;
}
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
static
class
Subset
{
public
List
<
Address
>
addresses
;
}
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
static
class
Endpoints
{
public
List
<
Subset
>
subsets
;
}
private
static
String
getEnvOrDefault
(
String
var
,
String
def
)
{
final
String
val
=
System
.
getenv
(
var
);
return
(
val
==
null
||
val
.
isEmpty
())
?
def
:
val
;
}
@Override
public
void
run
(
String
...
args
)
{
final
String
hostName
=
getEnvOrDefault
(
"KUBERNETES_RO_SERVICE_HOST"
,
"localhost"
);
final
String
hostPort
=
getEnvOrDefault
(
"KUBERNETES_RO_SERVICE_PORT"
,
"8080"
);
String
serviceName
=
getEnvOrDefault
(
"HAZELCAST_SERVICE"
,
"hazelcast"
);
String
path
=
"/api/v1beta3/namespaces/default/endpoints/"
;
final
String
host
=
"http://"
+
hostName
+
":"
+
hostPort
;
log
.
info
(
"Asking k8s registry at {}.."
,
host
);
final
List
<
String
>
hazelcastEndpoints
=
new
CopyOnWriteArrayList
<>();
try
{
URL
url
=
new
URL
(
host
+
path
+
serviceName
);
ObjectMapper
mapper
=
new
ObjectMapper
();
Endpoints
endpoints
=
mapper
.
readValue
(
url
,
Endpoints
.
class
);
if
(
endpoints
!=
null
)
{
if
(
endpoints
.
subsets
!=
null
&&
!
endpoints
.
subsets
.
isEmpty
())
{
endpoints
.
subsets
.
parallelStream
().
forEach
(
subset
->
{
subset
.
addresses
.
parallelStream
().
forEach
(
addr
->
hazelcastEndpoints
.
add
(
addr
.
IP
));
});
}
}
}
catch
(
IOException
ex
)
{
log
.
warn
(
"Request to Kubernetes API failed"
,
ex
);
}
log
.
info
(
"Found {} pods running Hazelcast."
,
hazelcastEndpoints
.
size
());
runHazelcast
(
hazelcastEndpoints
);
}
private
void
runHazelcast
(
final
List
<
String
>
nodes
)
{
// configure Hazelcast instance
final
Config
cfg
=
new
Config
();
cfg
.
setInstanceName
(
UUID
.
randomUUID
().
toString
());
// group configuration
final
String
HC_GROUP_NAME
=
getEnvOrDefault
(
"HC_GROUP_NAME"
,
"someGroup"
);
final
String
HC_GROUP_PASSWORD
=
getEnvOrDefault
(
"HC_GROUP_PASSWORD"
,
"someSecret"
);
final
int
HC_PORT
=
Integer
.
parseInt
(
getEnvOrDefault
(
"HC_PORT"
,
"5701"
));
cfg
.
setGroupConfig
(
new
GroupConfig
(
HC_GROUP_NAME
,
HC_GROUP_PASSWORD
));
// network configuration initialization
final
NetworkConfig
netCfg
=
new
NetworkConfig
();
netCfg
.
setPortAutoIncrement
(
false
);
netCfg
.
setPort
(
HC_PORT
);
// multicast
final
MulticastConfig
mcCfg
=
new
MulticastConfig
();
mcCfg
.
setEnabled
(
false
);
// tcp
final
TcpIpConfig
tcpCfg
=
new
TcpIpConfig
();
nodes
.
parallelStream
().
forEach
(
tcpCfg:
:
addMember
);
tcpCfg
.
setEnabled
(
true
);
// network join configuration
final
JoinConfig
joinCfg
=
new
JoinConfig
();
joinCfg
.
setMulticastConfig
(
mcCfg
);
joinCfg
.
setTcpIpConfig
(
tcpCfg
);
netCfg
.
setJoin
(
joinCfg
);
// ssl
netCfg
.
setSSLConfig
(
new
SSLConfig
().
setEnabled
(
false
));
// set it all
cfg
.
setNetworkConfig
(
netCfg
);
// run
Hazelcast
.
newHazelcastInstance
(
cfg
);
}
}
```
[

]()
[

]()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment