Code Monkey home page Code Monkey logo

hazelcast-aws's Introduction

DEPRECATED: hazelcast-aws plugin has been merged with hazelcast!

Since version 5.0 hazelcast includes hazelcast-aws and does not require additional dependency. For details about running Hazelcast on AWS consider the documentation.

Hazelcast Discovery Plugin for AWS

This repository contains a plugin which provides the automatic Hazelcast member discovery in the Amazon Web Services Platform.

Requirements

  • Hazelcast 3.6+
  • Linux Kernel 3.19+ (TCP connections may get stuck when used with older Kernel versions, resulting in undefined timeouts)
  • Versions compatibility:
    • hazelcast-aws 3+ is compatible with hazelcast 4+
    • hazelcast-aws 2.4 is compatible with hazelcast 3.12.x
    • hazelcast-aws 2.3 is compatible with hazelcast 3.11.x
    • hazelcast-aws 2.2 is compatible with older hazelcast versions

Embedded mode

To use Hazelcast embedded in your application, you need to add the plugin dependency into your Maven/Gradle file (or use hazelcast-all which already includes the plugin). Then, when you provide hazelcast.xml/hazelcast.yaml as presented below or an equivalent Java-based configuration, your Hazelcast instances discover themselves automatically.

Maven

<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast-aws</artifactId>
  <version>${hazelcast-aws.version}</version>
</dependency>

Gradle

compile group: "com.hazelcast", name: "hazelcast-aws", version: "${hazelcast-aws.version}"

Understanding AWS Discovery Strategy

Hazelcast member starts by fetching a list of all running instances filtered by the plugin parameters (region, etc.). 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.

Note that this plugin supports Hazelcast Zone Aware feature.

The plugin is prepared to work for both AWS EC2 and AWS ECS/Fargate environments. However, note that requirements and plugin properties vary depending on the environment you use.

EC2 Configuration

The plugin works both for Hazelcast Member Discovery and Hazelcast Client Discovery.

EC2 Hazelcast Member Discovery

Make sure that:

  • you have the hazelcast-aws.jar (or hazelcast-all.jar) dependency in your classpath
  • your IAM Role has ec2:DescribeInstances permission

Then, you can configure Hazelcast in one of the following manners.

XML Configuration

<hazelcast>
  <network>
    <join>
      <multicast enabled="false"/>
      <aws enabled="true">
        <tag-key>my-ec2-instance-tag-key</tag-key>
        <tag-value>my-ec2-instance-tag-value</tag-value>
      </aws>
    </join>
  </network>
</hazelcast>

YAML Configuration

hazelcast:
  network:
    join:
      multicast:
        enabled: false
      aws:
        enabled: true
        tag-key: my-ec2-instance-tag-key
        tag-value: my-ec2-instance-tag-value

Java-based Configuration

config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(true)
      .setProperty("tag-key", "my-ec2-instance-tag-key")
      .setProperty("tag-value", "my-ec2-instance-tag-value");

The following properties can be configured (all are optional).

  • access-key, secret-key: access and secret keys of your AWS account; if not set, iam-role is used
  • iam-role: IAM Role attached to EC2 instance used to fetch credentials (if access-key/secret-key not specified); if not set, default IAM Role attached to EC2 instance is used
  • region: region where Hazelcast members are running; default is the current region
  • host-header: ec2, ecs, or the URL of a EC2/ECS API endpoint; automatically detected by default
  • security-group-name: filter to look only for EC2 instances with the given security group
  • tag-key, tag-value: filter to look only for EC2 Instances with the given tag-key/tag-value; multi values supported if comma-separated (e.g. KeyA,KeyB); comma-separated values behaves as AND conditions
  • connection-timeout-seconds, read-timeout-seconds: connection and read timeouts when making a call to AWS API; default to 10
  • connection-retries: number of retries while connecting to AWS API; default to 3
  • hz-port: a range of ports where the plugin looks for Hazelcast members; default is 5701-5708

Note that if you don't specify any of the properties, then the plugin uses the IAM Role assigned to EC2 Instance and forms a cluster from all Hazelcast members running in same region.

EC2 Hazelcast Client Configuration

Hazelcast Client discovery parameters are the same as mentioned above.

If Hazelcast Client is run outside AWS, then you need to always specify the following parameters:

  • access-key, secret-key - IAM role cannot be used from outside AWS
  • region - it cannot be detected automatically
  • use-public-ip - must be set to true

Note also that your EC2 instances must have public IP assigned.

Following are example declarative and programmatic configuration snippets.

XML Configuration

<hazelcast-client>
  <network>
    <aws enabled="true">
      <access-key>my-access-key</access-key>
      <secret-key>my-secret-key</secret-key>
      <region>us-west-1</region>
      <tag-key>my-ec2-instance-tag-key</tag-key>
      <tag-value>my-ec2-instance-tag-value</tag-value>
      <use-public-ip>true</use-public-ip>
    </aws>
  </network>
</hazelcast-client>

YAML Configuration

hazelcast-client:
  network:
    aws:
      enabled: true
      access-key: my-access-key
      secret-key: my-secret-key
      region: us-west-1
      tag-key: my-ec2-instance-tag-key
      tag-value: my-ec2-instance-tag-value
      use-public-ip: true

Java-based Configuration

clientConfig.getNetworkConfig().getAwsConfig()
      .setEnabled(true)
      .setProperty("access-key", "my-access-key")
      .setProperty("secret-key", "my-secret-key")
      .setProperty("region", "us-west-1")
      .setProperty("tag-key", "my-ec2-instance-tag-key")
      .setProperty("tag-value", "my-ec2-instance-tag-value")
      .setProperty("use-public-ip", "true");

ECS/Fargate Configuration

The plugin works both for Hazelcast Member Discovery (forming Hazelcast cluster) and Hazelcast Client Discovery.

Note: for the detailed description, check out Hazelcast Guides: Getting Started with Embedded Hazelcast on ECS.

ECS Hazelcast Member Discovery

Make sure that your IAM Task Role has the following permissions:

  • ecs:ListTasks
  • ecs:DescribeTasks
  • ec2:DescribeNetworkInterfaces (needed only if task have public IPs)

Then, you can configure Hazelcast in one of the following manners. Please note that 10.0.*.* value depends on your VPC CIDR block definition.

XML Configuration

<hazelcast>
  <network>
    <join>
      <multicast enabled="false"/>
      <aws enabled="true" />
    </join>
    <interfaces enabled="true">
      <interface>10.0.*.*</interface>
    </interfaces>
  </network>
</hazelcast>

YAML Configuration

hazelcast:
  network:
    join:
      multicast:
        enabled: false
      aws:
        enabled: true
    interfaces:
      enabled: true
      interfaces:
        - 10.0.*.*

Java-based Configuration

config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(true);
config.getNetworkConfig().getInterfaces().setEnabled(true).addInterface("10.0.*.*");

The following properties can be configured (all are optional).

  • access-key, secret-key: access and secret keys of AWS your account; if not set, IAM Task Role is used
  • region: region where Hazelcast members are running; default is the current region
  • cluster: ECS cluster short name or ARN; default is the current cluster
  • family: filter to look only for ECS tasks with the given family name; mutually exclusive with service-name
  • service-name: filter to look only for ECS tasks from the given service; mutually exclusive with family
  • host-header: ecs or the URL of a ECS API endpoint; automatically detected by default
  • connection-timeout-seconds, read-timeout-seconds: connection and read timeouts when making a call to AWS API; default to 10
  • connection-retries: number of retries while connecting to AWS API; default to 3
  • hz-port: a range of ports where the plugin looks for Hazelcast members; default is 5701-5708

Note that if you don't specify any of the properties, then the plugin discovers all Hazelcast members running in the current ECS cluster.

ECS Hazelcast Client Configuration

Hazelcast Client discovery parameters are the same as mentioned above.

If Hazelcast Client is run outside ECS cluster, then you need to always specify the following parameters:

  • access-key, secret-key - IAM role cannot be used from outside AWS
  • region - it cannot be detected automatically
  • cluster - it cannot be detected automatically
  • use-public-ip - must be set to true

Note also that your ECS Tasks must have public IPs assigned and your IAM Task Role must have ec2:DescribeNetworkInterfaces permission.

Following are example declarative and programmatic configuration snippets.

XML Configuration

<hazelcast-client>
  <network>
    <aws enabled="true">
      <access-key>my-access-key</access-key>
      <secret-key>my-secret-key</secret-key>
      <region>eu-central-1</region>
      <cluster>my-cluster</cluster>
      <use-public-ip>true</use-public-ip>
    </aws>
  </network>
</hazelcast-client>

YAML Configuration

hazelcast-client:
  network:
    aws:
      enabled: true
      access-key: my-access-key
      secret-key: my-secret-key
      region: eu-central-1
      cluster: my-cluster
      use-public-ip: true

Java-based Configuration

clientConfig.getNetworkConfig().getAwsConfig()
      .setEnabled(true)
      .setProperty("access-key", "my-access-key")
      .setProperty("secret-key", "my-secret-key")
      .setProperty("region", "eu-central-1")
      .setProperty("cluster", "my-cluster")
      .setProperty("use-public-ip", "true");

ECS Environment with EC2 Discovery

If you use ECS on EC2 instances (not Fargate), you may also set up your ECS Tasks to use host network mode and then use EC2 discovery mode instead of ECS. In that case, your Hazelcast configuration would look as follows.

hazelcast:
  network:
    join:
      multicast:
        enabled: false
      aws:
        enabled: true
        host-header: ec2
    interfaces:
      enabled: true
      interfaces:
        - 10.0.*.*

All other parameters can be used exactly the same as described in the EC2-related section.

AWS Elastic Beanstalk

The plugin works correctly on the AWS Elastic Beanstalk environment. While deploying your application into the Java Platform, please make sure your Elastic Beanstalk Environment Configuration satisfies the following requirements:

  • EC2 security groups contain a group which allows the port 5701
  • IAM instance profile contains IAM role which has ec2:DescribeInstances permission (or your Hazelcast configuration contains access-key and secret-key)
  • Deployment policy is Rolling (instead of the default All at once which may cause the whole Hazelcast members to restart at the same time and therefore lose data)

High Availability

By default, Hazelcast distributes partition replicas (backups) randomly and equally among cluster members. However, this is not safe in terms of high availability when a partition and its replicas are stored on the same rack, using the same network, or power source. To deal with that, Hazelcast offers logical partition grouping, so that a partition itself and its backup(s) would not be stored within the same group. This way Hazelcast guarantees that a possible failure affecting more than one member at a time will not cause data loss. The details of partition groups can be found in the documentation: Partition Group Configuration

In addition to two built-in grouping options ZONE_AWARE and PLACEMENT_AWARE, you can customize the formation of these groups based on the network interfaces of members. See more details on custom groups in the documentation: Custom Partition Groups.

Multi-Zone Deployments

If ZONE_AWARE partition group is enabled, the backup(s) of a partition is always stored in a different availability zone. Hazelcast AWS Discovery plugin supports ZONE_AWARE feature for both EC2 and ECS.

NOTE: When using the ZONE_AWARE partition grouping, a cluster spanning multiple Availability Zones (AZ) should have an equal number of members in each AZ. Otherwise, it will result in uneven partition distribution among the members.

XML Configuration

<partition-group enabled="true" group-type="ZONE_AWARE" />

YAML Configuration

hazelcast:
  partition-group:
    enabled: true
    group-type: ZONE_AWARE

Java-based Configuration

config.getPartitionGroupConfig()
    .setEnabled(true)
    .setGroupType(MemberGroupType.ZONE_AWARE);

Partition Placement Group Deployments

AWS Partition Placement Group (PPG) ensures low latency between the instances in the same partition of a placement group and also provides availability since no two partitions share the same underlying hardware. As long as the partitions of a PPG contain an equal number of instances, it will be good practice for Hazelcast clusters formed within a single zone.

If EC2 instances belong to a PPG and PLACEMENT_AWARE partition group is enabled, then Hazelcast members will be grouped by the partitions of the PPG. For instance, the Hazelcast members in the first partition of a PPG named ppg will belong to the partition group of ppg-1, and those in the second partition will belong to ppg-2 and so on. Furthermore, these groups will be specific to each availability zone. That is, they are formed with zone names as well: us-east-1-ppg-1, us-east-2-ppg-1, and the like. However, if a Hazelcast cluster spans multiple availability zones then you should consider using ZONE_AWARE.

Cluster Placement Group Deployments

AWS Cluster Placement Group (CPG) ensures low latency by packing instances close together inside an availability zone. If you favor latency over availability, then CPG will serve your purpose.

NOTE: In the case of CPG, using PLACEMENT_AWARE has no effect, so can use the default Hazelcast partition group strategy.

Spread Placement Group Deployments

AWS Spread Placement Groups (SPG) ensures high availability in a single zone by placing each instance in a group on a distinct rack. It provides better latency than multi-zone deployment, but worse than Cluster Placement Group. SPG is limited to 7 instances, so if you need a larger Hazelcast cluster within a single zone, you should use PPG instead.

NOTE: In the case of SPG, using PLACEMENT_AWARE has no effect, so can use the default Hazelcast partition group strategy.

XML Configuration

<partition-group enabled="true" group-type="PLACEMENT_AWARE" />

YAML Configuration

hazelcast:
  partition-group:
    enabled: true
    group-type: PLACEMENT_AWARE

Java-based Configuration

config.getPartitionGroupConfig()
    .setEnabled(true)
    .setGroupType(MemberGroupType.PLACEMENT_AWARE);

Autoscaling

Hazelcast is prepared to work correctly within the autoscaling environments. Note that there are two specific requirements to prevent Hazelcast from losing data:

  • the number of members must change by 1 at the time
  • when a member is launched or terminated, the cluster must be in the safe state

Read about details in the blog post: AWS Auto Scaling with Hazelcast.

AWS EC2 Deployment Guide

You can download the white paper "Amazon EC2 Deployment Guide for Hazelcast IMDG" here.

How to find us?

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.

hazelcast-aws's People

Contributors

ajurasz avatar akoledzhikov avatar alparslanavci avatar asvieira-lucas avatar bilalyasar avatar dependabot-preview[bot] avatar dependabot[bot] avatar devopshazelcast avatar donnerbart avatar dpocock avatar emrahkocaman avatar enesakar avatar enozcan avatar feanor07 avatar fuadm avatar googlielmo avatar hasancelik avatar ihsandemir avatar jerrinot avatar lazerion avatar mdogan avatar mmedenjak avatar mtyazici avatar peterjot avatar pivovarit avatar pveentjer avatar serdaro avatar seriybg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hazelcast-aws's Issues

Release version 3.7

After some digging around it is my understanding that:

  1. This module is to replace hazelcast-cloud.
  2. This module has not yet been released under its new name hazelcast-aws.
  3. The unreleased version of the code matches (nearly?) completely hazelcast-cloud:3.6.5.

I'd like to ask you to release hazelcast-aws:3.7 anyway. This way it's much clearer for users how to upgrade from Hazelcast 3.6.5 to 3.7, because then:

  1. The replacement can actually be found in Maven Central.
  2. One can keep version numbers in sync.

Can the plugin work with network mode as bridge

Hi,

I am trying to use the hazelcast-aws plugin and wanted to know if it can work in network mode as bridge? Please let me know if this is possible
Below is the text from the your document which says that the bind should be in host mode

Configuring Hazelcast Cluster Members for AWS ECS
In order to enable discovery within AWS ECS Cluster, within taskdef.json or container settings, Hazelcast member should be bind to host network. Therefore, proper json representation for task should contain below segment:

"networkMode": "host"

Thanks,

Vignesh

connection-timeout-seconds command rejected

Attempting to start up hazelcast has resulted in this error:
Caused by: com.hazelcast.config.InvalidConfigurationException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'connection-timeout-seconds'. One of '{"http://www.hazelcast.com/schema/config":iam-role, "http://www.hazelcast.com/schema/config":host-header, "http://www.hazelcast.com/schema/config":tag-key, "http://www.hazelcast.com/schema/config":tag-value}' is expected.

Update minimal-json dependencies

Minimal JSON library package has changed from: ""com.hazelcast.com.eclipsesource.json" (3.10) to "com.hazelcast.internal.json" (3.11). It needs to be updated.

AWS credentials required in the new AWS Discovery using SPI mode

The documentation implies that the "access-key", "secret-key", and "iam-role" properties are optional and that Hazelcast can fallback to using the role and credentials assigned to the EC2 instance. This would be ideal so that I do not need to hardcode these values into my hazelcast.xml.

However, when I try to run a hazelcast cluster without these properties, startup will fail with an error stating that "access-key" property is required, or that "access-key" property cannot be blank.

Is there a way I can omit these configurations, or are they actually required?

Thanks for your help!

Client outside AWS fails to connect to cluster in AWS

Hello.

I have:

  • hazelcast 3.9.2 cluster is in AWS
  • hazelcast 3.9.3 client + hazelcast-aws 2.1.0 is outside AWS

Client fails to connect: Unable to retrieve credentials from IAM Role.

Client log:

2018-03-14 13:30:19,445 INFO [main] com.hazelcast.aws.AwsDiscoveryStrategy - Describe instances will be queried with iam-role, please make sure given iam-role have ec2:DescribeInstances policy attached. 
2018-03-14 13:30:19,529 INFO [main] com.hazelcast.core.LifecycleService - hz.client_0 [PrometheusDEV] [3.9.3] HazelcastClient 3.9.3 (20180216 - 539b124) is STARTED 
2018-03-14 13:30:19,554 DEBUG [main] com.hazelcast.internal.networking.nio.NioEventLoopGroup - hz.client_0 [PrometheusDEV] [3.9.3] TcpIpConnectionManager configured with Non Blocking IO-threading model: 1 input threads and 1 output threads 
2018-03-14 13:30:19,555 DEBUG [main] com.hazelcast.internal.networking.nio.NioEventLoopGroup - hz.client_0 [PrometheusDEV] [3.9.3] IO threads selector mode is SELECT 
2018-03-14 13:30:19,775 WARN [hz.client_0.cluster-] com.hazelcast.client.connection.ClientConnectionManager - hz.client_0 [PrometheusDEV] [3.9.3] Could not connect to cluster, shutting down the client. Unable to retrieve credentials from IAM Role: prometheus-hazelcast-core-standalone 
2018-03-14 13:30:19,776 INFO [hz.client_0.clientShutdown-] com.hazelcast.core.LifecycleService - hz.client_0 [PrometheusDEV] [3.9.3] HazelcastClient 3.9.3 (20180216 - 539b124) is SHUTTING_DOWN 
2018-03-14 13:30:19,778 INFO [hz.client_0.clientShutdown-] com.hazelcast.core.LifecycleService - hz.client_0 [PrometheusDEV] [3.9.3] HazelcastClient 3.9.3 (20180216 - 539b124) is SHUTDOWN

Client exception:

at com.hazelcast.aws.impl.DescribeInstances.fillKeysFromIamRole(DescribeInstances.java:105) 
at com.hazelcast.aws.impl.DescribeInstances.fillKeysFromIamRoles(DescribeInstances.java:85) 
at com.hazelcast.aws.impl.DescribeInstances.execute(DescribeInstances.java:219) 
at com.hazelcast.aws.AWSClient.getAddresses(AWSClient.java:56) 
at com.hazelcast.aws.AwsDiscoveryStrategy.discoverNodes(AwsDiscoveryStrategy.java:146) 
at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.discoverNodes(DefaultDiscoveryService.java:74) 
at com.hazelcast.client.spi.impl.discovery.DiscoveryAddressProvider.loadAddresses(DiscoveryAddressProvider.java:44) 
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getPossibleMemberAddresses(ClientConnectionManagerImpl.java:895) 
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.connectToClusterInternal(ClientConnectionManagerImpl.java:812) 
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.access$1200(ClientConnectionManagerImpl.java:103) 
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl$2.call(ClientConnectionManagerImpl.java:859) 
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl$2.call(ClientConnectionManagerImpl.java:855) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 
at java.lang.Thread.run(Thread.java:748) 
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64) 
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80) 
Caused by: com.hazelcast.config.InvalidConfigurationException: Unable to lookup role in URI: http://169.254.169.254/latest/meta-data/iam/security-credentials/prometheus-hazelcast-core-standalone 
at com.hazelcast.aws.utility.MetadataUtil.retrieveMetadataFromURI(MetadataUtil.java:75) 
at com.hazelcast.aws.impl.DescribeInstances.retrieveRoleFromURI(DescribeInstances.java:136) 
at com.hazelcast.aws.impl.DescribeInstances.fillKeysFromIamRole(DescribeInstances.java:101) 
... 17 more 
Caused by: java.net.SocketException: Network is unreachable: connect 
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) 
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) 
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) 
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) 
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) 
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
at java.net.Socket.connect(Socket.java:589) 
at sun.net.NetworkClient.doConnect(NetworkClient.java:175) 
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) 
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558) 
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242) 
at sun.net.www.http.HttpClient.New(HttpClient.java:339) 
at sun.net.www.http.HttpClient.New(HttpClient.java:357) 
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220) 
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156) 
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050) 
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984) 
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564) 
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) 
at com.hazelcast.aws.utility.MetadataUtil.retrieveMetadataFromURI(MetadataUtil.java:67) 
... 19 more

Test client code:

clientConfig.getProperties().setProperty("hazelcast.discovery.enabled", "true"); 
clientConfig.getProperties().setProperty("hazelcast.discovery.public.ip.enabled", "true"); 
Map<String, Comparable> properties = new HashMap<>(); 
properties.put("iam-role", "prometheus-hazelcast-core-standalone"); 
properties.put("region", "eu-west-1"); 
properties.put("host-header", "ec2.amazonaws.com"); 
properties.put( 
"security-group-name", 
"security-group-name"); 
properties.put("tag-key", "role_name"); 
properties.put("tag-value", "prometheus-hazelcast-core-standalone"); 
properties.put("hzPort", "5701"); 
AwsDiscoveryStrategyFactory awsDiscoveryStrategyFactory = new AwsDiscoveryStrategyFactory(); 
DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(awsDiscoveryStrategyFactory, 
properties); 
ClientNetworkConfig clientNetworkConfig = clientConfig.getNetworkConfig(); 
clientNetworkConfig.getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig); 
clientConfig.getGroupConfig().setName("PrometheusDEV"); 
clientConfig.getGroupConfig().setPassword("PrometheusDEV"); 
// 
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

Please assist.
Thanks.

Proxy support for hazelcast (AWS)?

In our AWS environment the EC2 endpoint is only reachable via a proxy server, as there is no other way to get to the Internet. Does hazelcast support this? If so how can we configure hazelcast to discovery members via a proxy? Thanks in advance!

why do I have to use access key and secret key for cluster member discovery

Hi,

I am running several applications running in different ec2s, and all these applications should compose to a hazelcast cluster, no cluster client.

When I am trying the auto discovery function, I found that access key and secret key must be specified, can't they use EC2 default authentication as they are already running inside AWS.

Thanks.

Missing docs on required IAM role privileges

I am struggling to find what the required roles / policies are for the AWS IAM user that I have just created for Hazelcast.

(Disclaimer: I already know a gung-ho approach like 'ec2 admin' or sth would work, but I am looking for the specific list of the permissions required.)

Can somebody please point me to a relevant doc? (In return, I'll happily open a PR so that it's also documented in this repo too!)

Hazlecast node repeated close connection to itself.

Hi,

Attached files:
clusterInfo.txt
network-config.txt

Iโ€™m having some problems using Hazelcast in my project, using aws-discovery and docker.

  1. I see exceptions in logs.
  2. I see in the logs of one of the two nodes (not the master/old node) repeated (each 2min) close connection with โ€“ โ€œReason: Connection closed by the other sideโ€
    The close connection message refers to the node try to connect to itself which I donโ€™t know why required at all.

Here are the details (long, sorryโ€ฆ)

We have several instances of our servers deployed in amazon with load balancer so number of instances can vary according to traffic.
The servers are deployed with Docker and amazon cloud-formation.
Each of those servers is now also a hazelcast node with shared IMap data, currently Iโ€™m working with two server instances (two hazelcast nodes).

Iโ€™m using aws auto-discovery and supplying, on hazelcast instance creation, configuration as below with serverโ€™s tag and security-group, for proper discovery match.

networkConfig.getJoin().getMulticastConfig().setEnabled(false);
networkConfig.getJoin().getTcpIpConfig().setEnabled(false);

AwsConfig awsConfig = networkConfig.getJoin().getAwsConfig();
awsConfig.setEnabled(true);
awsConfig.setAccessKey(myAWSAccessKey);
awsConfig.setSecretKey(myAWSSecretKey);
awsConfig.setRegion(myRegion);
awsConfig.setSecurityGroupName(mySecurityGroupName);
awsConfig.setTagKey(myTagKeyName);
awsConfig.setTagValue(myTagKeyValue);
awsConfig.setIamRole(null);
awsConfig.setConnectionTimeoutSeconds(myTimeout);
networkConfig.getJoin().getTcpIpConfig().setConnectionTimeoutSeconds(myTimeout);

In addition, Iโ€™m using only 4 ports โ€“ 5701, 5702, 5703, 5704 which are opened, hazelcast configuration is updated with:

networkConfig.setPort(5701);
networkConfig.setPortCount(4);
networkConfig.setPortAutoIncrement(true);

Also I set to true the ReuseAddress although I donโ€™t think required.

networkConfig.setReuseAddress(true);

The auto-discovery seemed to work ok but since Iโ€™m working with Docker, hazelcast used the docker-ip instead of the server aws ip so the tcp/ip connection fails.
I found online, a suggested solution which Iโ€™m using and it seems to cause the tcp/ip connection to work.

privateIpAddress = get the server aws private-ip.
networkConfig.setPublicAddress(privateIpAddress);
config.setProperty("hazelcast.local.localAddress", privateIpAddress);

All of the above resulted with proper hazelcast memner initialization as seen below in logs:

Members [2] {
        Member [100.125.228.50]:5701 - ffbc4126-a780-460e-ac8d-7a021367f371 this
        Member [100.125.238.93]:5701 - 4306bb9f-5761-4aaf-986e-f57ba716cfb7
}

And now to the problemโ€ฆ

The logs of the server which is the master hazelcast node (100.125.238.93) seems ok,
but the logs of the 2nd server/node (100.125.228.50) has some exceptions from time to time and in addition I see repeated connection close (every 2min) as:

2017-02-07 08:54:24.651  INFO 1 --- [hz._hzInstance_1_web-wfa2.cached.thread-1] c.h.nio.tcp.TcpIpConnectionManager       : 
[100.125.228.50]:5701 [web-wfa2] [3.7] Established socket connection between /172.17.0.4:41880 and /100.125.228.50:5702

2017-02-07 08:54:24.651  INFO 1 --- [hz._hzInstance_1_web-wfa2.IO.thread-in-2] com.hazelcast.nio.tcp.TcpIpConnection    : 
[100.125.228.50]:5701 [web-wfa2] [3.7] Connection[id=930, /172.17.0.4:41880->/100.125.228.50:5702, endpoint=[100.125.228.50]:5702, alive=false, type=NONE] closed. 
Reason: Connection closed by the other side

Please note that the connections close refers to connection of the node to itself according to above log - 100.125.228.50:5701 tries to connect to 100.125.228.50:5702 , with close Reason: Connection closed by the other side (?!?)
The ip - 172.17.0.4:41880 appearing in above log is the docker-ip, and from checking the hazelcast code I see that it refers to the LocalSocketAddress:

  this.logger.info("Established socket connection between " + channel.socket().getLocalSocketAddress() + " and " + channel.socket().getRemoteSocketAddress());

I donโ€™t think the docker-ip in the logs represents a problem since it appears also with an OK connection to the 1st server (100.125.238.93):

2017-02-06 17:09:20.057  INFO 1 --- [hz._hzInstance_1_web-wfa2.cached.thread-11] c.h.nio.tcp.TcpIpConnectionManager       : 
[100.125.228.50]:5701 [web-wfa2] [3.7] Established socket connection between /172.17.0.4:5701 and /100.125.238.93:54378

Yet, I do not understand why the connection is closed repeatedly and not sure why it tries to connect to itself.

Also there are disturbing exceptions in the logs:

java.io.IOException: Connection reset by peer
        at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
        at sun.nio.ch.IOUtil.read(IOUtil.java:197)
        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
        at com.hazelcast.nio.tcp.DefaultSocketChannelWrapper.read(DefaultSocketChannelWrapper.java:59)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingSocketReader.initReadHandler(NonBlockingSocketReader.java:173)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingSocketReader.handle(NonBlockingSocketReader.java:141)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.handleSelectionKey(NonBlockingIOThread.java:345)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.handleSelectionKeys(NonBlockingIOThread.java:330)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.selectLoop(NonBlockingIOThread.java:248)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.run(NonBlockingIOThread.java:201)

java.io.IOException: Broken pipe  - repeated exception!
        at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
        at sun.nio.ch.IOUtil.write(IOUtil.java:65)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
        at com.hazelcast.nio.tcp.DefaultSocketChannelWrapper.write(DefaultSocketChannelWrapper.java:64)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingSocketWriter.writeOutputBufferToSocket(NonBlockingSocketWriter.java:353)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingSocketWriter.handle(NonBlockingSocketWriter.java:322)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingSocketWriter.run(NonBlockingSocketWriter.java:403)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.executeTask(NonBlockingIOThread.java:309)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.processTaskQueue(NonBlockingIOThread.java:300)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.selectLoop(NonBlockingIOThread.java:244)
        at com.hazelcast.nio.tcp.nonblocking.NonBlockingIOThread.run(NonBlockingIOThread.java:201)

com.hazelcast.core.HazelcastException: java.net.SocketException: Connection reset
        at com.hazelcast.util.ExceptionUtil.peel(ExceptionUtil.java:73)
        at com.hazelcast.util.ExceptionUtil.peel(ExceptionUtil.java:52)
        at com.hazelcast.util.ExceptionUtil.rethrow(ExceptionUtil.java:83)
        at com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.getMembers(TcpIpJoinerOverAWS.java:57)
        at com.hazelcast.cluster.impl.TcpIpJoiner.getPossibleAddresses(TcpIpJoiner.java:404)
        at com.hazelcast.cluster.impl.TcpIpJoiner.searchForOtherClusters(TcpIpJoiner.java:507)
        at com.hazelcast.internal.cluster.impl.SplitBrainHandler.searchForOtherClusters(SplitBrainHandler.java:75)
        at com.hazelcast.internal.cluster.impl.SplitBrainHandler.run(SplitBrainHandler.java:42)
        at com.hazelcast.spi.impl.executionservice.impl.SkipOnConcurrentExecutionDecorator.run(SkipOnConcurrentExecutionDecorator.java:40)
        at com.hazelcast.util.executor.CachedExecutorServiceDelegate$Worker.run(CachedExecutorServiceDelegate.java:212)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
        at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
        at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)
Caused by: java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:209)
        at java.net.SocketInputStream.read(SocketInputStream.java:141)
        at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
        at sun.security.ssl.InputRecord.read(InputRecord.java:503)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
        at com.hazelcast.aws.impl.DescribeInstances.callService(DescribeInstances.java:158)
        at com.hazelcast.aws.impl.DescribeInstances.execute(DescribeInstances.java:144)
        at com.hazelcast.aws.AWSClient.getPrivateIpAddresses(AWSClient.java:53)
        at com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.getMembers(TcpIpJoinerOverAWS.java:42)
        ... 11 common frames omitted

Iโ€™ll appreciate your help.

SocketException[Connected refused] errors

Cannot connect to any of the nodes in my instance.

26-Jul-2017 17:24:09.062 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.8.28:5703, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.063 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.8.28:5703. Reason: SocketException[Connection refused to address /172.31.8.28:5703]
26-Jul-2017 17:24:09.064 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.8.28]:5703 is added to the blacklist.
26-Jul-2017 17:24:09.065 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.8.28:5701, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.065 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.8.28:5701. Reason: SocketException[Connection refused to address /172.31.8.28:5701]
26-Jul-2017 17:24:09.065 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.8.28]:5701 is added to the blacklist.
26-Jul-2017 17:24:09.066 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.8.28:5702, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.066 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.8.28:5702. Reason: SocketException[Connection refused to address /172.31.8.28:5702]
26-Jul-2017 17:24:09.066 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.8.28]:5702 is added to the blacklist.
26-Jul-2017 17:24:09.067 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-1] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.37.34:5701, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.068 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.23.183:5701, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.068 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-2] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.23.183:5702, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.069 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-1] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.37.34:5701. Reason: SocketException[Connection refused to address /172.31.37.34:5701]
26-Jul-2017 17:24:09.069 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-1] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.37.34]:5701 is added to the blacklist.
26-Jul-2017 17:24:09.070 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-2] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.23.183:5702. Reason: SocketException[Connection refused to address /172.31.23.183:5702]
26-Jul-2017 17:24:09.070 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-2] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.23.183]:5702 is added to the blacklist.
26-Jul-2017 17:24:09.069 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.23.183:5701. Reason: SocketException[Connection refused to address /172.31.23.183:5701]
26-Jul-2017 17:24:09.070 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.23.183]:5701 is added to the blacklist.
26-Jul-2017 17:24:09.071 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-2] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.37.34:5703, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.071 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.23.183:5703, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.072 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-1] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Connecting to /172.31.37.34:5702, timeout: 0, bind-any: true
26-Jul-2017 17:24:09.072 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-2] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.37.34:5703. Reason: SocketException[Connection refused to address /172.31.37.34:5703]
26-Jul-2017 17:24:09.072 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-2] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.37.34]:5703 is added to the blacklist.
26-Jul-2017 17:24:09.072 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.23.183:5703. Reason: SocketException[Connection refused to address /172.31.23.183:5703]
26-Jul-2017 17:24:09.073 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-1] com.hazelcast.nio.tcp.InitConnectionTask.null [10.255.0.5]:5701 [dev] [3.8.3] Could not connect to: /172.31.37.34:5702. Reason: SocketException[Connection refused to address /172.31.37.34:5702]
26-Jul-2017 17:24:09.073 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-1] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.37.34]:5702 is added to the blacklist.
26-Jul-2017 17:24:09.073 INFO [hz.SESSION-REPLICATION-INSTANCE.cached.thread-3] com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.null [10.255.0.5]:5701 [dev] [3.8.3] [172.31.23.183]:5703 is added to the blacklist.

Security group is open (to debug I opened every port to all traffic) and AWS credentials are correct.

Support for AWS ElasticBeanstalk EC2 Instances.

Hi
I think that It is not working.
It can not detect other EC2 Instance on AWS ElasticBeanstalk.
And can not clustering.

// Log message

Members {size:1, ver:1} [
Member [10.0.0.234]:5701 - 8fb81705-4afa-4753-bda6-5a2d97f9ee0f this
]

Members {size:1, ver:1} [
Member [10.0.0.234]:5702 - f01ca206-a534-40a0-aff0-830c68d13d4a this
]

Dropped: SplitBrainJoinMessage{packetVersion=4, buildNumber=20180424, 
memberVersion=3.10.0, clusterVersion=3.10, address=[10.0.0.203]:5702, uuid=โ€˜b6aa90a0-b6e7- 
4c59-82d6-c920ba55d9c8โ€™, liteMember=false, memberCount=1, dataMemberCount=1, 
memberListVersion=1}




// My Settings..

import com.hazelcast.aws.AwsDiscoveryStrategyFactory;
import com.hazelcast.config.*;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.instance.HazelcastInstanceFactory;
import com.hazelcast.spring.cache.HazelcastCacheManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@enablecaching
@configuration
public class HazelcastConfig {

private static final String TAG_KEY = "elasticbeanstalk:environment-name";

@Value("${aws.environment-name")
private String environmentName;

@Value("${aws.region}")
private String region;

@Value("${aws.access-key}")
private String accessKey;

@Value("${aws.secret-key}")
private String secretKey;

@Bean
public Config config() {
    Config config = new Config();

    config.setInstanceName("Hazelcast-Instance");

    // EC2  Discovery true
    config.getProperties().setProperty("hazelcast.discovery.enabled", "true");

    // ZONE
    PartitionGroupConfig partitionGroupConfig = config.getPartitionGroupConfig();
    partitionGroupConfig
            .setEnabled(true)
            .setGroupType(PartitionGroupConfig.MemberGroupType.ZONE_AWARE);
    config.setPartitionGroupConfig(partitionGroupConfig);

   
    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    joinConfig.getTcpIpConfig().setEnabled(false);
    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);

    // EC2  Discovery 
    AwsDiscoveryStrategyFactory awsDiscoveryStrategyFactory = new AwsDiscoveryStrategyFactory();
    Map<String, Comparable> properties = new HashMap<>();
    properties.put("access-key", accessKey);
    properties.put("secret-key", secretKey);
    properties.put("region", region);
    properties.put("host-header", "ec2.amazonaws.com");
    properties.put("tag-key", TAG_KEY);
    properties.put("tag-value", environmentName);
    properties.put("connection-timeout-seconds", "5");
    properties.put("hz-port","5701");

    DiscoveryStrategyConfig discoveryStrategyConfig = new 
    DiscoveryStrategyConfig(awsDiscoveryStrategyFactory, properties);
    joinConfig.getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig);

    ArrayList<DiscoveryStrategyConfig> discoveryStrategyConfigs = new ArrayList<>();
    joinConfig.getDiscoveryConfig().setDiscoveryStrategyConfigs(discoveryStrategyConfigs);

    // Cache Map
    MapConfig mapConfig = new MapConfig()
            .setName("cache")
            .setMaxSizeConfig(new MaxSizeConfig(200, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE))
            .setEvictionPolicy(EvictionPolicy.LRU)
            .setTimeToLiveSeconds(20)
            .setNearCacheConfig(new NearCacheConfig());
    config.addMapConfig(mapConfig);

    // Cache ManagementCenter
    ManagementCenterConfig managementCenterConfig = new ManagementCenterConfig()
            .setEnabled(true)
            .setUrl("http://localhost:8080/mancenter")
            .setUpdateInterval(3);
    config.setManagementCenterConfig(managementCenterConfig);

    return config;
    }

    @Bean
    public HazelcastInstance hazelcastInstance() {
        return HazelcastInstanceFactory.newHazelcastInstance(config());
    }

    @Bean
    public CacheManager cacheManager() {
        return new HazelcastCacheManager(hazelcastInstance());
    }
}

Please let me know if it works with Elastic Beanstalk.
I want to use Spring boot data jpa + AWS Beanstalk +Hazelcast Second level cache

-----------------------------------------
<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast-spring</artifactId>
  <version>3.10</version>
</dependency>
<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast-hibernate52</artifactId>
  <version>1.2.3</version>
</dependency>
<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast-aws</artifactId>
  <version>2.1.1</version>
</dependency>

 -----------------------------------------

properties:
hibernate.format_sql: true
hibernate.dialect: org.hibernate.dialect.MariaDBDialect
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: true
hibernate.cache.use_minimal_puts: true
hibernate.cache.region.factory_class: com.hazelcast.hibernate.HazelcastCacheRegionFactory

Not able to start in cluster mode without access-key and secret-key

hey guys,

I am trying to start orientdb using the hazelcast-aws. I have my hazelcast.xml which doesnt have a access-key and secret key. I have a i-am role which has access to ec2 and it complains it needs a access-key

Error log:
accessKey must contain text

My hazelcast.xml looks like this

<properties>
  <property name="hazelcast.discovery.enabled">true</property>      
</properties>

<network>        
    <join>
        <multicast enabled="false"/>
        <aws enabled="false"/>
        <tcp-ip enabled="false"/>
          
         <discovery-strategies>
            <discovery-strategy enabled="true" class="com.hazelcast.aws.AwsDiscoveryStrategy">
              <properties>
                <property name="access-key"></property>
                <property name="secret-key"></property>
                <property name="iam-role">testing</property>
                <property name="region">us-east-1</property>
                <property name="tag-key">something</property>
                <property name="tag-value">something</property>
                <property name="connection-timeout-seconds">30</property>
                <property name="hz-port">5701</property>
              </properties>
            </discovery-strategy>
         </discovery-strategies>
          
    </join>
</network>

Please let me know if i am doing something wrong

Support of hazelcast properties starting scan port (other than default 5701) with AWS TCP Joiner

I have multiple applications using embedded hazelcast deployed in AWS bundled as docker container. I am using AWS discovery for my applications. My applications are deployed something like this (i.e one container for a given application in each AWS instance)

AWS Instance-1
docker run ....... -p 5701:5701 ..... app1
docker run ....... -p 5702:5701 ..... app2
docker run ....... -p 5703:5701 ..... app3

AWS Instance-2
docker run ....... -p 5701:5701 ..... app1
docker run ....... -p 5702:5701 ..... app2
docker run ....... -p 5703:5701 ..... app3

AWS Instance-3
docker run ....... -p 5701:5701 ..... app1
docker run ....... -p 5702:5701 ..... app2
docker run ....... -p 5703:5701 ..... app3

I have configured in my hazelcast config with something like this.

            <hz:network port="${sample.hz.network.port:5701}" port-auto-increment="${sample.hz.network.port.auto.increment:false}" 
            	public-address="${sample.hz.publicAddress}">
            	<hz:outbound-ports>
            		<hz:ports>0</hz:ports>
            	</hz:outbound-ports>
                <hz:join>
                    <hz:multicast enabled="${sample.hz.multicast.enabled:false}" />
                    <hz:tcp-ip connection-timeout-seconds="${sample.hz.tcpip.conn.timeout:30}" enabled="${sample.hz.tcpip.enabled:false}" />
                    <hz:aws enabled="${sample.hz.aws.enabled:true}" 
                    	access-key="${sample.hz.aws.access.key}"
                    	secret-key="${sample.hz.aws.secret.key}"
                    	iam-role="${sample.hz.aws.iam.role}"
                    	region="${sample.hz.aws.region:us-east-1}"
                    	host-header="${sample.hz.aws.host.header:ec2.amazonaws.com}"
                    	security-group-name="${sample.hz.aws.security.group.name}"
                    	tag-key="${sample.hz.aws.tag.key}"
                    	tag-value="${sample.hz.aws.tag.value}" 
                    	connection-timeout-seconds="${sample.hz.aws.conn.timeout:30}" />
                </hz:join>
				<hz:reuse-address>true</hz:reuse-address>
            </hz:network>

From the above configutation my AWS discovery is working fine and it's identifying all 3 private ips of AWS instance for all 3 applications but only app1 is able to find other cluster members and join not app2 & app3. When I dig into issue I found the default scanning port for TCP joiner (which is what AWS discovery uses with TcpIpJoinerOverAWS) is 5701 and it increments the port scanning from that port only. Since app2 and app3 are started with 5702 and 5703 host ports it can't find it's peer cluster members. Default port of 5701 is fine when we don't specify the ports in ip address and that will work for non AWS simple TCP joiner but in case of AWS discovery API itself can only identify list of private IPs by AWS joiner (without any ports) in that case application need to have a way to specify what scanning ports it should start with and it should be configurable via hazelcast poperties (not only forced and mandatory with 5701).

This is a major issue with multiple hazelcast applications deployed in AWS instances and it should be looked on high priority as it limits and enforces application to use only one AWS instance, in my case if I have to use hazelcast here I have to deploy it as many as 9 AWS instances instead of 3 when I know my applications are small and can co-exists in same instances as they can be logically groups to one business functionality.

AWSConfig getConnectionTimeoutSeconds is not used during connection

It seems like DescribeInstances did not use any timeout during https url connection https://github.com/hazelcast/hazelcast-aws/blob/master/src/main/java/com/hazelcast/aws/impl/DescribeInstances.java#L259 . There is a config parameter set/getConnectionTimeoutSeconds which I expect to be used.

Furthermore, this timeout probably needs to be used for other http requests such as https://github.com/hazelcast/hazelcast-aws/blob/master/src/main/java/com/hazelcast/aws/impl/DescribeInstances.java#L132

ZONE_AWARE partition group not working on AWS, unless member-attribute tag added

Using hazelcast 3.9 & AWS plugin 2.1.0.

Defining just <partition-group enabled="true" group-type="ZONE_AWARE"/> causes this exception:

Exception in thread "main" java.lang.IllegalArgumentException: Not enough metadata information is provided. At least one of availability zone, rack or host information must be provided with ZONE_AWARE partition group. 
at com.hazelcast.partition.membergroup.ZoneAwareMemberGroupFactory.createInternalMemberGroups(ZoneAwareMemberGroupFactory.java:47) 
at com.hazelcast.partition.membergroup.BackupSafeMemberGroupFactory.createMemberGroups(BackupSafeMemberGroupFactory.java:29)
at com.hazelcast.internal.partition.impl.PartitionStateManager.createMemberGroups(PartitionStateManager.java:113) 
at com.hazelcast.internal.partition.impl.PartitionStateManager.updateMemberGroupsSize(PartitionStateManager.java:217) 
at com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl.memberAdded(InternalPartitionServiceImpl.java:358) 
at com.hazelcast.internal.cluster.impl.MembershipManager.sendMembershipEvents(MembershipManager.java:592) 
at com.hazelcast.internal.cluster.impl.ClusterServiceImpl.sendLocalMembershipEvent(ClusterServiceImpl.java:183) 
at com.hazelcast.instance.Node.start(Node.java:369) 
at com.hazelcast.instance.HazelcastInstanceImpl.<init>(HazelcastInstanceImpl.java:133) 
at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:195) 
at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:174) 
at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:124) 
at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:58) 
at com.hazelcast.core.server.StartServer.main(StartServer.java:46)

Only way to make it work is adding this:

    <member-attributes>
      <attribute name="hazelcast.partition.group.zone"></attribute>
    </member-attributes>

TcpIpJoinerOverAWSTest.testJoinerCreation

java.lang.NoClassDefFoundError: javax/cache/Cache
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)
    at java.lang.Class.getDeclaredMethods(Class.java:1793)
    at org.mockito.cglib.core.ReflectUtils.addAllMethods(ReflectUtils.java:349)
    at org.mockito.cglib.proxy.Enhancer.getMethods(Enhancer.java:422)
    at org.mockito.cglib.proxy.Enhancer.generateClass(Enhancer.java:457)
    at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217)
    at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378)
    at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318)
    at org.mockito.internal.creation.cglib.ClassImposterizer.createProxyClass(ClassImposterizer.java:123)
    at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:57)
    at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:49)
    at org.mockito.internal.creation.cglib.CglibMockMaker.createMock(CglibMockMaker.java:24)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
    at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
    at org.mockito.Mockito.mock(Mockito.java:1285)
    at org.mockito.Mockito.mock(Mockito.java:1163)
    at com.hazelcast.cluster.impl.TcpIpJoinerOverAWSTest.testJoinerCreation(TcpIpJoinerOverAWSTest.java:58)

https://hazelcast-l337.ci.cloudbees.com/view/Plugins/job/AWS-master/6/com.hazelcast$hazelcast-aws/testReport/com.hazelcast.cluster.impl/TcpIpJoinerOverAWSTest/testJoinerCreation/

InvalidConfigurationException after split brain recovery

After a split brain, in one of our server nodes Hazelcast started printing the following error to our logs:

com.hazelcast.config.InvalidConfigurationException: You should only define one of `<iam-role>` and `<access-key>`
        at com.hazelcast.aws.impl.DescribeInstances.checkKeysFromIamRoles(DescribeInstances.java:83) ~[hazelcast-aws-1.1.jar:1.1]
        at com.hazelcast.aws.impl.DescribeInstances.<init>(DescribeInstances.java:61) ~[hazelcast-aws-1.1.jar:1.1]
        at com.hazelcast.aws.AWSClient.getPrivateIpAddresses(AWSClient.java:47) ~[hazelcast-aws-1.1.jar:1.1]
        at com.hazelcast.cluster.impl.TcpIpJoinerOverAWS.getMembers(TcpIpJoinerOverAWS.java:42) [hazelcast-aws-1.1.jar:1.1]
        at com.hazelcast.cluster.impl.TcpIpJoiner.getPossibleAddresses(TcpIpJoiner.java:404) [hazelcast-3.7.1.jar:1.1]
        at com.hazelcast.cluster.impl.TcpIpJoiner.searchForOtherClusters(TcpIpJoiner.java:507) [hazelcast-3.7.1.jar:1.1]
        at com.hazelcast.internal.cluster.impl.SplitBrainHandler.searchForOtherClusters(SplitBrainHandler.java:75) [hazelcast-3.7.1.jar:3.7.1]
        at com.hazelcast.internal.cluster.impl.SplitBrainHandler.run(SplitBrainHandler.java:42) [hazelcast-3.7.1.jar:3.7.1]
        at com.hazelcast.spi.impl.executionservice.impl.SkipOnConcurrentExecutionDecorator.run(SkipOnConcurrentExecutionDecorator.java:40) [hazelcast-3.7.1.jar:3.7.1]
        at com.hazelcast.util.executor.CachedExecutorServiceDelegate$Worker.run(CachedExecutorServiceDelegate.java:212) [hazelcast-3.7.1.jar:3.7.1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_111]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
        at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76) [hazelcast-3.7.1.jar:3.7.1]
        at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92) [hazelcast-3.7.1.jar:3.7.1]

I'm pretty sure our config has no access-key though, we're using iam-role only.
Our aws config looks like this:

            <aws enabled="true">
		<iam-role>xxx_role</iam-role>
                <!--optional, default is us-east-1 -->
                <region>us-east-1</region>
                <!-- optional, only instances belonging to this group will be discovered, default will try all running instances -->
                <security-group-name>xxx_group</security-group-name>
            </aws>

Note that even though this exception is constantly being logged (every couple minutes), discovery seemed to be working OK, and our application was responding normally.
Only one of our nodes displayed this behavior. The other nodes were working fine.

I'm on Hazelcast 3.7.1, using hazelcast-aws plugin 1.1.
This issue didn't happen with the old hazelcast-cloud plugin.

AWS client does not retrieve error reasons

When AWS issues an error they do so under the 503 error code. The current AWS client does not retrieve the text content of error messages as an Exception is thrown when the response code is not 2xx or 3xx. The following patch attempts to retrieve and log the error reason:

Index: src/main/java/com/hazelcast/aws/impl/DescribeInstances.java

IDEA additional info:

Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP

<+>UTF-8

===================================================================

--- src/main/java/com/hazelcast/aws/impl/DescribeInstances.java            (revision 2b2fa219a4cf12892a1b914bef98f2caca10d24a)

+++ src/main/java/com/hazelcast/aws/impl/DescribeInstances.java         (date 1519741021000)

@@ -23,10 +23,14 @@

import com.hazelcast.com.eclipsesource.json.JsonObject;

import com.hazelcast.config.AwsConfig;

import com.hazelcast.config.InvalidConfigurationException;

+import com.hazelcast.logging.ILogger;

+import com.hazelcast.logging.Logger;

+import com.hazelcast.nio.IOUtil;


 import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

+import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.text.SimpleDateFormat;

@@ -52,7 +56,9 @@

  */

public class DescribeInstances {


-    /**

+             private static final ILogger LOGGER = Logger.getLogger( DescribeInstances.class );

+

+             /**

      * URI to fetch container credentials (when IAM role is enabled)

      *

      * see http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html

@@ -241,7 +247,50 @@

         httpConnection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(awsConfig.getConnectionTimeoutSeconds()));

         httpConnection.setDoOutput(false);

         httpConnection.connect();

-        return httpConnection.getInputStream();

+

+                 InputStream is = null;

+                 try

+                 {

+                                 is = httpConnection.getInputStream();

+                 }

+                 catch( IOException e )

+                 {

+                                 LOGGER.warning( "Unable to retrieve info from URL: " + httpConnection.getResponseCode() );

+                                 InputStream errorStream = httpConnection.getErrorStream();

+                                 String errorMsg = inputStreamToString( errorStream );

+                                             LOGGER.warning( "Error Message: " + errorMsg );

+

+                                             throw e;

+                 }

+

+                 return is;

+    }

+

+    private String inputStreamToString( InputStream is )

+    {

+                 StringBuilder buf = new StringBuilder();

+

+                 BufferedReader br = null;

+                 try

+                 {

+                                 br = new BufferedReader( new InputStreamReader( is, "UTF-8" ) );

+

+                                 String line;

+                                 while( (line = br.readLine()) != null )

+                                 {

+                                                 buf.append( line );

+                                 }

+                 }

+                 catch( IOException e )

+                 {

+                                 LOGGER.warning( "Unable to retrieve error stream response", e );

+                 }

+                 finally

+                 {

+                                 IOUtil.closeResource( br );

+                 }

+

+                 return buf.toString();

     }


     public EC2RequestSigner getRequestSigner() {

AWS discovery does not support AWS ECS service (?)

I've been struggling to get AWS discovery to work within docker containers (the official hazelcast docker containers) deployed on AWS ECS.

I've narrowed this down to the fact that this library only supports EC2 IAM roles, and does not support the credentials scheme defined by task definition roles in AWS ECS.

The problem is that the getKeysFromIamRole method in the DescribeInstances class - defined here - does not support looking up IAM roles for AWS ECS tasks.
These use a slightly different scheme, as is documented here.

I am happy to help with a PR for this, but, as an entirely new contributor, I would like to know your thoughts on whether you think this should come in the form of a different configuration in the hazelcast.xml, etc., or whether we should simply extend the DescribeInstances class to also attempt looking up for an IAM task role, in case it can't find the regular EC2 IAM role.

AWS Lambda support

Dears,

Not sure if this is at all possible but I was wondering if you are at least considering add support for AWS lambda.

Regards

How do I configure the AwsDiscoveryStrategy programmatically ?

InterfacesConfig interfacesConfig = new InterfacesConfig();
interfacesConfig.setEnabled(true);
List interface1 = new ArrayList<>();
interface1.add("10.0..");
interfacesConfig.setInterfaces(interface1);
network.setInterfaces(interfacesConfig);

        //set aws discovery
        Map<String, Comparable> properties = new HashMap<String, Comparable>();
        properties.put("access-key", awsAccessKeyId);
        properties.put("secret-key", awsSecretAccessKey);
        properties.put("iam-role", "aaaa");
        //properties.put("region",awsSecretAccessKey); //Default value is us-east-1
        properties.put("host-header", "ec2.amazonaws.com");
        properties.put("security-group-name", "hazelcast");
        properties.put("tag-key", "aa-cluster");
        properties.put("tag-value", "aa-cluster");
        properties.put("hz-port", port.toString());

        DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig("AwsDiscoveryStrategy",properties);
      
        DiscoveryConfig discoveryConfig = new DiscoveryConfig();
        discoveryConfig.addDiscoveryStrategyConfig(discoveryStrategyConfig);
        join.setDiscoveryConfig(discoveryConfig);

Is this is the correct why to configure the AwsDiscoveryStrategy ?

Thanks,
Tal

Stopped working with Hazelcast 3.9+

I have the following setup, which used to work with Hazelcast 3.8.6, but fails on AWS:

@Bean
    @Profile("!test")
    public HazelcastInstance hazelcast() {
        Config config = new Config();
        config.setProperty("hazelcast.jmx", "true");
        config.setProperty(GroupProperty.PHONE_HOME_ENABLED.getName(), "false");
        config.getGroupConfig().setName(environment);
        if (awsDeployment) {
            config.getPartitionGroupConfig()
                    .setGroupType(PartitionGroupConfig.MemberGroupType.ZONE_AWARE)
                    .setEnabled(true);
            config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
            JoinConfig joinConfig = config.getNetworkConfig().getJoin();
            joinConfig.getTcpIpConfig().setEnabled(false);
            joinConfig.getAwsConfig().setEnabled(false); // counter-intuitive, but it's a legacy configuration
            joinConfig.getMulticastConfig().setEnabled(false);
            DiscoveryStrategyConfig discoveryStrategy = new DiscoveryStrategyConfig(new AwsDiscoveryStrategyFactory());
            joinConfig.getDiscoveryConfig().getDiscoveryStrategyConfigs().add(discoveryStrategy);
            joinConfig.getDiscoveryConfig().setDiscoveryServiceProvider(new DefaultDiscoveryServiceProvider());
            discoveryStrategy.addProperty("iam-role", iamRole);
            discoveryStrategy.addProperty("region", new DefaultAwsRegionProviderChain().getRegion());
            discoveryStrategy.addProperty("host-header", "ec2.amazonaws.com");
            discoveryStrategy.addProperty("tag-key", "Name");
            discoveryStrategy.addProperty("tag-value", WEB_APP_NODE_TAG_VALUE);
        }

        return Hazelcast.newHazelcastInstance(config);
    }

The stacktrace of the error with 3.9+ is:

Caused by: java.lang.IllegalArgumentException: Not enough metadata information is provided. At least one of availability zone, rack or host information must be provided with ZONE_AWARE partition group.
        at com.hazelcast.partition.membergroup.ZoneAwareMemberGroupFactory.createInternalMemberGroups(ZoneAwareMemberGroupFactory.java:47)
        at com.hazelcast.partition.membergroup.BackupSafeMemberGroupFactory.createMemberGroups(BackupSafeMemberGroupFactory.java:29)
        at com.hazelcast.internal.partition.impl.PartitionStateManager.createMemberGroups(PartitionStateManager.java:113)
        at com.hazelcast.internal.partition.impl.PartitionStateManager.updateMemberGroupsSize(PartitionStateManager.java:217)
        at com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl.memberAdded(InternalPartitionServiceImpl.java:358)
        at com.hazelcast.internal.cluster.impl.MembershipManager.sendMembershipEvents(MembershipManager.java:601)
        at com.hazelcast.internal.cluster.impl.ClusterServiceImpl.sendLocalMembershipEvent(ClusterServiceImpl.java:183)
        at com.hazelcast.instance.Node.start(Node.java:369)
        at com.hazelcast.instance.HazelcastInstanceImpl.<init>(HazelcastInstanceImpl.java:133)
        at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:195)
        at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:174)
        at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:124)
        at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:58)

Discovery SPI not working between Client and Cluster

Getting the Following error when trying to connect to the client in AWS. Below is the error log: Any help would be greatly appreciated.

Aug 07, 2017 6:03:13 PM com.hazelcast.client.config.XmlClientConfigLocator INFO: Loading configuration /home/ec2-user/hazelcast-client-config.xml from System property 'hazelcast.client.config' Aug 07, 2017 6:03:13 PM com.hazelcast.client.config.XmlClientConfigLocator INFO: Using configuration file at /home/ec2-user/hazelcast-client-config.xml Aug 07, 2017 6:03:13 PM com.hazelcast.core.LifecycleService INFO: hz.client_0 [cerberus-dev] [3.8.3] HazelcastClient 3.8.3 (20170704 - 10e1449) is STARTING Aug 07, 2017 6:03:13 PM com.hazelcast.core.LifecycleService INFO: hz.client_0 [cerberus-dev] [3.8.3] HazelcastClient 3.8.3 (20170704 - 10e1449) is STARTED Aug 07, 2017 6:03:13 PM com.hazelcast.client.spi.impl.ClusterListenerSupport INFO: hz.client_0 [cerberus-dev] [3.8.3] Trying to connect to [127.0.0.1]:5703 as owner member Aug 07, 2017 6:03:13 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Exception during initial connection to localhost/127.0.0.1:5703, exception com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused Aug 07, 2017 6:03:13 PM com.hazelcast.client.spi.impl.ClusterListenerSupport INFO: hz.client_0 [cerberus-dev] [3.8.3] Trying to connect to [127.0.0.1]:5701 as owner member Aug 07, 2017 6:03:13 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Exception during initial connection to localhost/127.0.0.1:5701, exception com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused Aug 07, 2017 6:03:13 PM com.hazelcast.client.spi.impl.ClusterListenerSupport INFO: hz.client_0 [cerberus-dev] [3.8.3] Trying to connect to [127.0.0.1]:5702 as owner member Aug 07, 2017 6:03:13 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Exception during initial connection to localhost/127.0.0.1:5702, exception com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused Aug 07, 2017 6:03:13 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Unable to get alive cluster connection, try in 2935 ms later, attempt 1 of 2. Aug 07, 2017 6:03:16 PM com.hazelcast.client.spi.impl.ClusterListenerSupport INFO: hz.client_0 [cerberus-dev] [3.8.3] Trying to connect to [127.0.0.1]:5703 as owner member Aug 07, 2017 6:03:16 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Exception during initial connection to localhost/127.0.0.1:5703, exception com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused Aug 07, 2017 6:03:16 PM com.hazelcast.client.spi.impl.ClusterListenerSupport INFO: hz.client_0 [cerberus-dev] [3.8.3] Trying to connect to [127.0.0.1]:5702 as owner member Aug 07, 2017 6:03:16 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Exception during initial connection to localhost/127.0.0.1:5702, exception com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused Aug 07, 2017 6:03:16 PM com.hazelcast.client.spi.impl.ClusterListenerSupport INFO: hz.client_0 [cerberus-dev] [3.8.3] Trying to connect to [127.0.0.1]:5701 as owner member Aug 07, 2017 6:03:16 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Exception during initial connection to localhost/127.0.0.1:5701, exception com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused Aug 07, 2017 6:03:16 PM com.hazelcast.client.spi.impl.ClusterListenerSupport WARNING: hz.client_0 [cerberus-dev] [3.8.3] Unable to get alive cluster connection, try in 2997 ms later, attempt 2 of 2. Aug 07, 2017 6:03:19 PM com.hazelcast.core.LifecycleService INFO: hz.client_0 [cerberus-dev] [3.8.3] HazelcastClient 3.8.3 (20170704 - 10e1449) is SHUTTING_DOWN Aug 07, 2017 6:03:19 PM com.hazelcast.core.LifecycleService INFO: hz.client_0 [cerberus-dev] [3.8.3] HazelcastClient 3.8.3 (20170704 - 10e1449) is SHUTDOWN Exception in thread "main" java.lang.IllegalStateException: Unable to connect to any address in the config! The following addresses were tried: [localhost/127.0.0.1:5701, localhost/127.0.0.1:5702, localhost/127.0.0.1:5703] at com.hazelcast.client.spi.impl.ClusterListenerSupport.connectToCluster(ClusterListenerSupport.java:178) at com.hazelcast.client.spi.impl.ClientClusterServiceImpl.start(ClientClusterServiceImpl.java:189) at com.hazelcast.client.impl.HazelcastClientInstanceImpl.start(HazelcastClientInstanceImpl.java:403) at com.hazelcast.client.HazelcastClientManager.newHazelcastClient(HazelcastClientManager.java:78) at com.hazelcast.client.HazelcastClient.newHazelcastClient(HazelcastClient.java:72) at com.capitalone.cerberus.GettingStartedClient.main(GettingStartedClient.java:19)

Missing property 'access-key' when 'iam-role' is specified.

Hi.

I am trying to deploy Hazelcast on EC2 using IAM roles for discovering other cluster members and I am getting the following error:

Exception in thread "main" java.lang.RuntimeException: Failed to configure discovery strategies
	at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.loadDiscoveryStrategies(DefaultDiscoveryService.java:168)
	at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.<init>(DefaultDiscoveryService.java:60)
	at com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider.newDiscoveryService(DefaultDiscoveryServiceProvider.java:29)
	at com.hazelcast.instance.Node.createDiscoveryService(Node.java:259)
	at com.hazelcast.instance.Node.<init>(Node.java:213)
	at com.hazelcast.instance.HazelcastInstanceImpl.createNode(HazelcastInstanceImpl.java:159)
	at com.hazelcast.instance.HazelcastInstanceImpl.<init>(HazelcastInstanceImpl.java:127)
	at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:218)
	at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:176)
	at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:126)
	at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:58)
	at com.hazelcast.core.server.StartServer.main(StartServer.java:46)
Caused by: com.hazelcast.core.HazelcastException: Missing property 'access-key' on discovery strategy 'com.hazelcast.aws.AwsDiscoveryStrategy' configuration
	at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.buildProperties(DefaultDiscoveryService.java:188)
	at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.buildDiscoveryStrategy(DefaultDiscoveryService.java:216)
	at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.loadDiscoveryStrategies(DefaultDiscoveryService.java:158)
	... 11 more

This is my hazelcast.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.8.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <!--
     | Hazelcast configuration file for running a default-configured cluster
     | on AWS.
    -->
    <properties>
        <property name="hazelcast.discovery.enabled">true</property>
    </properties>

    <group>
        <name>dev</name>
        <password>dev-pass</password>
    </group>

    <management-center enabled="false">http://localhost:8080/mancenter</management-center>

    <network>
        <port auto-increment="true" port-count="50">5701</port>
        <join>
            <multicast enabled="false"/>
            <tcp-ip enabled="false"/>
            <aws enabled="false"/>
            <discovery-strategies>
                <!-- See: https://github.com/hazelcast/hazelcast-aws -->
                <!-- "class" attribute equals to the DiscoveryStrategy not the factory! -->
                <discovery-strategy enabled="true" class="com.hazelcast.aws.AwsDiscoveryStrategy">
                    <properties>
                       <property name="iam-role">PippoRole</property>
                       <property name="region">eu-central-1</property>
                       <property name="tag-key">role</property>
                       <property name="tag-value">hazelcast-node</property>
                       <property name="connection-timeout-seconds">20</property>
                    </properties>
                </discovery-strategy>
            </discovery-strategies>
        </join>
    </network>

    <partition-group enabled="false"/>

    <executor-service name="default">
        <pool-size>16</pool-size>
        <!-- Queue capacity. 0 means Integer.MAX_VALUE. -->
        <queue-capacity>0</queue-capacity>
    </executor-service>
</hazelcast>

PippoRole has the following policy attached:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

and it is correctly attached to the running instance.

From inside the instance, when I try to get the auth token from the metadata, I get

$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/PippoRole
{
  "Code" : "Success",
  "LastUpdated" : "2017-07-24T13:14:53Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : " ... key text ... ",
  "SecretAccessKey" : " ... key text ... ",
  "Token" : " ... long token text ... ",
  "Expiration" : "2017-07-24T19:18:56Z"

which seems to show that everything is OK.

  • Hazelcast is v3.8.3
  • Hazelcast AWS is v2.0.1
  • OS is Ubuntu Linux Xenial fully updated

What am I doing wrong?

Why don't you use the AWS SDK?

Is there a special reason why you do not use the SDK?

I think credentials management and API calls would be a lot easier. This would lead to more advanced discovery mechanisms based on AWS.

Problem Configuring Hazelcast Members for AWS ECS

Following the instruction and I get this error which seems to directly contradict the readme.

'10.0.. ' is not an IP address! Removing from interface list.

I'm using the NetworkConfig class to configure instead of hazelcast.xml file.

if (properties.isInterfacesEnable()) {
            InterfacesConfig interfacesConfig = new InterfacesConfig()
                    .setEnabled(properties.isInterfacesEnable())
                    .addInterface(properties.getInterfacesSubnet());
            networkConfig.setInterfaces(interfacesConfig);
        }

Change implementation of <aws> to discovery strategy

Currently there are two implementations of AWS Discovery:

  • <aws> (deprecated) - implemented in Hazelcast Root
  • SPI Discovery Strategy - implemented in Hazelcast AWS

The underlying implementation of <aws> should be changed to SPI.

Note: Most of this issue will have to be implemented in Hazelcast Root.

Alternate Behavior for Tag Filtering

Here's a feature request for consideration:

In my AWS setup, I have two tags: "Role" (which might have values like "api", "search", etc), and "Env" (which might have values like "Prod", "Staging", and "QA").

I would like all the Prod-API servers to form a cluster, all the QA-API servers to form a cluster, all the Staging-Search servers to form a cluster.

It would be great to be able to say setTagNames("Role, Env"), and have the library

  • find out what values the current server has for those tag names
  • filter cluster results to those servers that have the same values for those tags as the current server

In this way, a single config will work for all server roles and environments. As it is, if I understand it correctly, I have to have a separate file for each role-environment combination, and also I need to create a single unique tag for each server group (IOW, I need a tag with a value of "QA-API" or "Prod-Search" in order to prevent clusters from forming across roles or environments).

AwsDiscoveryStrategy.discoverNodes throws exception causes node to shutdown immediately

When member try to make the initial connection, DiscoveryJoiner.getPossibleAddressesForInitialJoin called, which calls AwsDiscoveryStrategy.discoverNodes. If any exception happens, this goes all the way back to TCPJoiner & causes node to shut down immediately instead of waiting to join. See below exception. Is this an expected behaviour?


2018-04-06 16:08:18,927Z INFO  [main] com.hazelcast.instance.Node - [10.205.89.32]:11415 [dev] [3.9.3] Activating Discovery SPI Joiner

2018-04-06 16:08:19,027Z INFO  [main] com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl - [10.205.89.32]:11415 [dev] [3.9.3] Starting 16 partition threads and 9 generic threads (1 dedicated for priority tasks)

2018-04-06 16:08:19,030Z INFO  [main] com.hazelcast.internal.diagnostics.Diagnostics - [10.205.89.32]:11415 [dev] [3.9.3] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.

2018-04-06 16:08:19,034Z INFO  [main] com.hazelcast.core.LifecycleService - [10.205.89.32]:11415 [dev] [3.9.3] [10.205.89.32]:11415 is STARTING

2018-04-06 16:08:19,056Z INFO  [main] com.hazelcast.system - [10.205.89.32]:11415 [dev] [3.9.3] Cluster version set to 3.9

2018-04-06 16:08:19,064Z INFO  [main] com.hazelcast.spi.hotrestart - [10.205.89.32]:11415 [dev] [3.9.3] hz._hzInstance_1_dev.s00 homeDir: /home/ec2-user/HR_DATA/s00

2018-04-06 16:08:19,086Z INFO  [main] com.hazelcast.spi.hotrestart - [10.205.89.32]:11415 [dev] [3.9.3] hz._hzInstance_1_dev.s01 homeDir: /home/ec2-user/HR_DATA/s01

2018-04-06 16:08:29,213Z ERROR [main] com.hazelcast.internal.cluster.impl.DiscoveryJoiner - [10.205.89.32]:11415 [dev] [3.9.3] java.net.SocketTimeoutException: connect timed out

com.hazelcast.core.HazelcastException: java.net.SocketTimeoutException: connect timed out

      at com.hazelcast.util.ExceptionUtil$1.create(ExceptionUtil.java:40)

      at com.hazelcast.util.ExceptionUtil.peel(ExceptionUtil.java:124)

      at com.hazelcast.util.ExceptionUtil.peel(ExceptionUtil.java:69)

      at com.hazelcast.util.ExceptionUtil.rethrow(ExceptionUtil.java:129)

      at com.hazelcast.aws.AwsDiscoveryStrategy.discoverNodes(AwsDiscoveryStrategy.java:167)

      at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.discoverNodes(DefaultDiscoveryService.java:74)

      at com.hazelcast.internal.cluster.impl.DiscoveryJoiner.getPossibleAddresses(DiscoveryJoiner.java:70)

      at com.hazelcast.internal.cluster.impl.DiscoveryJoiner.getPossibleAddressesForInitialJoin(DiscoveryJoiner.java:59)

      at com.hazelcast.cluster.impl.TcpIpJoiner.joinViaPossibleMembers(TcpIpJoiner.java:131)

      at com.hazelcast.cluster.impl.TcpIpJoiner.doJoin(TcpIpJoiner.java:90)

      at com.hazelcast.internal.cluster.impl.AbstractJoiner.join(AbstractJoiner.java:134)

      at com.hazelcast.instance.Node.join(Node.java:690)

      at com.hazelcast.instance.Node.start(Node.java:390)

      at com.hazelcast.instance.HazelcastInstanceImpl.<init>(HazelcastInstanceImpl.java:133)

      at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:195)

      at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:174)

      at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:124)

      at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:58)

      at com.vertex.c1.hotrestart.HRMain.runServer(HRMain.java:429)

      at com.vertex.c1.hotrestart.HRMain.run(HRMain.java:167)

      at com.vertex.c1.hotrestart.HRMain.main(HRMain.java:146)

Caused by: java.net.SocketTimeoutException: connect timed out

      at java.net.PlainSocketImpl.socketConnect(Native Method)

      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

      at java.net.Socket.connect(Socket.java:589)

      at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)

      at sun.net.NetworkClient.doConnect(NetworkClient.java:175)

      at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)

      at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)

      at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)

      at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)

      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)

      at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)

      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)

      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)

      at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:162)

      at com.hazelcast.aws.impl.DescribeInstances.callService(DescribeInstances.java:243)

      at com.hazelcast.aws.impl.DescribeInstances.execute(DescribeInstances.java:227)

      at com.hazelcast.aws.AWSClient.getAddresses(AWSClient.java:56)

      at com.hazelcast.aws.AwsDiscoveryStrategy.discoverNodes(AwsDiscoveryStrategy.java:146)

      ... 16 more

2018-04-06 16:08:29,216Z ERROR [main] com.hazelcast.instance.Node - [10.205.89.32]:11415 [dev] [3.9.3] Could not join cluster in 300000 ms. Shutting down now!

ZONE_AWARE partition group only work with Discovery SPI and not doc. about that wont work work with `aws` tag config

From Node.java

        if (properties.getBoolean(DISCOVERY_SPI_ENABLED)) {
            discoveryService.start();

            // Discover local metadata from environment and merge into member attributes
            mergeEnvironmentProvidedMemberMetadata();
        }

So if AWS is configured the old way, then mergeEnvironmentProvidedMemberMetadata methods not called and this causes PARTITION_GROUP_ZONE info not being populated: https://github.com/hazelcast/hazelcast-aws/blob/master/src/main/java/com/hazelcast/aws/AwsDiscoveryStrategy.java#L118

Since aws tag is deprecated, this seems normal but please at least add a doc to READ.me that ZONE_AWARE partition group works only SPI, not with aws tags.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.