DEPRECATED: hazelcast-gcp
plugin has been merged with hazelcast
!
Since version 5.0
hazelcast
includes hazelcast-gcp
and does not require additional dependency. For details about running Hazelcast on GCP consider the documentation.
This repository contains a plugin which provides the automatic Hazelcast member discovery in the Google Cloud Platform (Compute Engine) environment.
- Hazelcast 3.10+
- GCP VM instances must have access to Cloud API (at minimum "Read Only" Access Scope to "Compute Engine" API)
- Versions compatibility:
- hazelcast-gcp 2+ is compatible with hazelcast 4+
- hazelcast-gcp 1.1.x is compatible with hazelcast 3.11.x, 3.12.x
- hazelcast-gcp 1.0 is compatible with older hazelcast versions
To use Hazelcast GCP embedded in your application, you need to add the plugin dependency into your Maven/Gradle file. Then, when you provide hazelcast.xml
(or Java-based configuration) as presented above, your Hazelcast instances discover themselves automatically.
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-gcp</artifactId>
<version>${hazelcast-gcp-version}</version>
</dependency>
compile group: "com.hazelcast", name: "hazelcast-gcp", version: "${hazelcast-gcp-version}"
Hazelcast member starts by fetching a list of all instances filtered by projects, zones, and label. Then, each instance is checked one-by-one with its IP and each of the ports defined in the hz-port
property. When a member is discovered under IP:PORT, then it joins the cluster.
If users want to create multiple Hazelcast clusters in one project/zone, then they need to manually label the instances.
The plugin supports Members Discovery SPI and Zone Aware features.
Make sure you have the hazelcast-gcp.jar
dependency in your classpath. Then, you can configure Hazelcast in one of the following manners.
<hazelcast>
<network>
<join>
<multicast enabled="false"/>
<gcp enabled="true">
<label>application=hazelcast</label>
<hz-port>5701-5708</hz-port>
</gcp>
</join>
</network>
</hazelcast>
hazelcast:
network:
join:
multicast:
enabled: false
gcp:
enabled: true
label: application=hazelcast
hz-port: 5701-5708
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getGcpConfig().setEnabled(true)
.setProperty("label", "application=hazelcast")
.setProperty("hz-port", "5701-5708");
The following properties can be configured:
private-key-path
: a filesystem path to the private key for GCP service account in the JSON format; if not set, the access token is fetched from the GCP VM instanceprojects
: a list of projects where the plugin looks for instances; if not set, the current project is used
region
: a region where the plugin looks for instances; if not set, thezones
property is used; if it andzones
property not set, all zones of the current region are used
zones
: a list of zones where the plugin looks for instances; if not set, all zones of the current region are usedlabel
: a filter to look only for instances labeled as specified; property format:key=value
hz-port
: a range of ports where the plugin looks for Hazelcast members; if not set, the default value5701-5708
is used
Note that:
- Your GCP Service Account must have permissions to query for all the projects/zones specified in the configuration
- If you don't specify any of the properties, then the plugin forms a cluster from all Hazelcast members running in the current project, in the current region
- If you use the plugin in the Hazelcast Client running outside of the GCP network, then the following parameters are mandatory:
private-key-path
,projects
, andzones
orregion
When using ZONE_AWARE
configuration, backups are created in the other availability zone.
<partition-group enabled="true" group-type="ZONE_AWARE" />
hazelcast:
partition-group:
enabled: true
group-type: ZONE-AWARE
config.getPartitionGroupConfig()
.setEnabled(true)
.setGroupType(MemberGroupType.ZONE_AWARE);
NOTE: When using the ZONE_AWARE
partition grouping, a cluster spanning multiple availability zones should have an equal number of members in each AZ. Otherwise, it will result in uneven partition distribution among the members.
If Hazelcast Client is run inside GCP, then the configuration is exactly the same as for the Member.
If Hazelcast Client is run outside GCP, then you always need to specify the following parameters:
private-key-path
- path to the private key for GCP service accountprojects
- a list of projects where the plugin looks for instancesregion
: a region where the plugin looks for instances; if not set, thezones
property is used; if it andzones
property not set, all zones of the current region are usedzones
: a list of zones where the plugin looks for instances; if not set, all zones of the current region are useduse-public-ip
- must be set totrue
Following are example declarative and programmatic configuration snippets.
<hazelcast-client>
<network>
<gcp enabled="true">
<private-key-path>/home/name/service/account/key.json</private-key-path>
<projects>project-1,project-2</projects>
<region>us-east1</region>
<label>application=hazelcast</label>
<hz-port>5701-5708</hz-port>
<use-public-ip>true</use-public-ip>
</gcp>
</network>
</hazelcast-client>
hazelcast-client:
network:
gcp:
enabled: true
private-key-path: /home/name/service/account/key.json
projects: project-1,project-2
region: us-east1
label: application=hazelcast
hz-port: 5701-5708
use-public-ip: true
clientConfig.getGcpConfig().setEnabled(true)
.setProperty("private-key-path", "/home/name/service/account/key.json")
.setProperty("projects", "project-1,project-2")
.setProperty("region", "us-east1")
.setProperty("label", "application=hazelcast")
.setProperty("hz-port", "5701-5708")
.setProperty("use-public-ip", "true");
In case of any question or issue, please raise a GH issue, send an email to Hazelcast Google Groups or contact as directly via Hazelcast Gitter.