bitsofinfo / hazelcast-docker-swarm-discovery-spi

Docker Swarm based discovery strategy SPI for Hazelcast enabled applications
Apache License 2.0
39 stars 33 forks source link

NullPointerException on docker swarm #16

Closed tbolis closed 6 years ago

tbolis commented 6 years ago

Hi,

I'm trying to setup my application to utilize your discovery spi but I'm getting the following error

2018-04-12 15:29:19.041  INFO 1 --- [           main] o.b.h.d.docker.swarm.SwarmDiscoveryUtil  : Found relevant docker network: dev_my-network[uldk9khisx2bbvobda99tcwxz]
server.1.nzo2mv8x8a6e@linuxkit-025000000001    | 2018-04-12 15:29:19.223 ERROR 1 --- [           main] com.hazelcast.instance.AddressPicker     : [LOCAL] [dev] [3.9.3] null
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |
server.1.nzo2mv8x8a6e@linuxkit-025000000001    | java.lang.NullPointerException: null
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at org.bitsofinfo.hazelcast.discovery.docker.swarm.SwarmMemberAddressProvider.getBindAddress(SwarmMemberAddressProvider.java:126)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.instance.DelegatingAddressPicker.pickAddress(DelegatingAddressPicker.java:62)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.instance.Node.<init>(Node.java:184)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.instance.HazelcastInstanceImpl.createNode(HazelcastInstanceImpl.java:160)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.instance.HazelcastInstanceImpl.<init>(HazelcastInstanceImpl.java:128)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:195)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:174)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:124)
server.1.nzo2mv8x8a6e@linuxkit-025000000001    |    at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:58)

I follow instructions from Option 1 in your instructions and I setup a SwarmMemberAddressProvider programmatically.

 NetworkConfig nconf = config.getNetworkConfig();
            JoinConfig jconf = nconf.getJoin();

            nconf.setMemberAddressProviderConfig(new MemberAddressProviderConfig()
                    .setEnabled(true)
                    .setClassName(SwarmMemberAddressProvider.class.getName())
            ); 

...

Map<String,Comparable> properties = new HashMap<>();
properties.put("docker-network-names","my-network");
properties.put("docker-service-names","server");
properties.put("swarm-mgr-uri","http://socat:2375");

DiscoveryStrategyConfig sconf = new DiscoveryStrategyConfig(DockerSwarmDiscoveryStrategy.class.getName(),properties);

I'm playing on a OSX machine therefore I utilize bobrik/socat

version: '3.5'
volumes:
  server_data:
networks:
  my-network:
services:
  socat:
    hostname: socat
    image: bobrik/socat
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    ports:
     - 2375:2375
    command: TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock
    networks:
      - my-network
    deploy:
      placement:
        constraints: [node.role == manager]
  server:
    hostname: server
    image: <my image>
    networks:
      - my-network
    ports:
      - ${PORT:-8080}:8080
      - ${HZ_PORT_RANGE:-5701-5801}:5701-5801
    depends_on:
      - socat
    deploy:
      replicas: 1

Note that from within the server container I get a reploy from http://socat:2375/networks normally

docker version: Docker version 18.03.0-ce, build 0520e24 hazelcast version: 3.9.3

Any idea why is this happening?

Thanks

bitsofinfo commented 6 years ago

What does docker service ls show. I.E what is the name of the docker stack you are launching with that compose file. Your service name would be [stack-name]_server, rather than just server

tbolis commented 6 years ago

Yes indeed I cut some details for simplicity here is how docker service ls looks like:

I start the stack with docker stack deploy -c docker-stack.yml tbolis

ID                  NAME                MODE                REPLICAS            IMAGE                  PORTS
s1cil4jcxu8z        tbolis_server       replicated          1/1                 tbolis/server:latest   *:5701-5801->5701-5801/tcp, *:8200->8200/tcp
kedgxaguyri6        tbolis_socat        replicated          1/1                 bobrik/socat:latest    *:2375->2375/tcp
bitsofinfo commented 6 years ago

Yes so your properties.put("docker-service-names","server"); should instead be properties.put("docker-service-names","tbolis_server");

tbolis commented 6 years ago

that did the trick! I changed as well the network name in the same manner. So closing this and thank you very much for your effort!

cheers