@Bean
  public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    Config config = new Config();
    config.setInstanceName("soesmses");
    config.getNetworkConfig().setPort(5701);
    config.getNetworkConfig().setPortAutoIncrement(true);

    // In development, remove multicast auto-configuration
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
      System.setProperty("hazelcast.local.localAddress", "127.0.0.1");

      config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
      config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
      config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
    }

    config.getMapConfigs().put("default", initializeDefaultMapConfig());
    config
        .getMapConfigs()
        .put("com.soesoft.soesmses.domain.*", initializeDomainMapConfig(jHipsterProperties));
    config
        .getMapConfigs()
        .put("clustered-http-sessions", initializeClusteredSession(jHipsterProperties));

    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config);

    return hazelcastInstance;
  }
Example #2
0
  @Test
  public void testSwitchingMasters() throws Exception {
    Config c1 = buildConfig(false);
    Config c2 = buildConfig(false);
    Config c3 = buildConfig(false);
    Config c4 = buildConfig(false);
    Config c5 = buildConfig(false);

    c1.getNetworkConfig().setPort(55701);
    c2.getNetworkConfig().setPort(55702);
    c3.getNetworkConfig().setPort(55703);
    c4.getNetworkConfig().setPort(55704);
    c5.getNetworkConfig().setPort(55705);

    List<String> allMembers =
        Arrays.asList(
            "127.0.0.1:55701",
            "127.0.0.1:55702",
            "127.0.0.1:55703",
            "127.0.0.1:55704",
            "127.0.0.1:55705");
    c1.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
    c2.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
    c3.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
    c4.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
    c5.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);

    final HazelcastInstance h1 = Hazelcast.newHazelcastInstance(c1);
    final HazelcastInstance h2 = Hazelcast.newHazelcastInstance(c2);
    final HazelcastInstance h3 = Hazelcast.newHazelcastInstance(c3);
    final HazelcastInstance h4 = Hazelcast.newHazelcastInstance(c4);
    final HazelcastInstance h5 = Hazelcast.newHazelcastInstance(c5);

    assertEquals(5, h1.getCluster().getMembers().size());
    assertEquals(5, h2.getCluster().getMembers().size());
    assertEquals(5, h3.getCluster().getMembers().size());
    assertEquals(5, h4.getCluster().getMembers().size());
    assertEquals(5, h5.getCluster().getMembers().size());

    // Need to wait for at least as long as PROP_MAX_NO_MASTER_CONFIRMATION_SECONDS
    Thread.sleep(15 * 1000);
    h1.getLifecycleService().shutdown();
    Thread.sleep(3 * 1000);

    assertEquals(4, h2.getCluster().getMembers().size());
    assertEquals(4, h3.getCluster().getMembers().size());
    assertEquals(4, h4.getCluster().getMembers().size());
    assertEquals(4, h5.getCluster().getMembers().size());

    Thread.sleep(10 * 1000);

    assertEquals(4, h2.getCluster().getMembers().size());
    assertEquals(4, h3.getCluster().getMembers().size());
    assertEquals(4, h4.getCluster().getMembers().size());
    assertEquals(4, h5.getCluster().getMembers().size());
  }
  private Config hazelcast() {
    Config conf = new Config();
    conf.getNetworkConfig().setPort(hazelCastPort);
    conf.getNetworkConfig().setPortAutoIncrement(false);

    conf.setProperty("hazelcast.initial.min.cluster.size", "1");
    conf.setProperty("hazelcast.shutdownhook.enabled", "false");

    JoinConfig join = conf.getNetworkConfig().getJoin();

    boolean isAws = System.getProperty("hazelcast.aws", "false").equals("true");
    log.info("Setting up Joiner with this being " + (isAws ? "AWS" : "Multicast"));

    join.getAwsConfig().setEnabled(isAws);
    if (isAws) {
      join.getAwsConfig().setAccessKey(System.getProperty("hazelcast.access-key"));
      join.getAwsConfig().setSecretKey(System.getProperty("hazelcast.access-secret"));
    }
    join.getMulticastConfig().setEnabled(!isAws);

    ListConfig jobConfig = new ListConfig();
    jobConfig.setName(JOBS);

    conf.addListConfig(jobConfig);

    ListConfig replicateConfig = new ListConfig();
    replicateConfig.setName(REPLICATE_WEIGHTS);

    conf.addListConfig(replicateConfig);

    ListConfig topicsConfig = new ListConfig();
    topicsConfig.setName(TOPICS);

    conf.addListConfig(topicsConfig);

    ListConfig updatesConfig = new ListConfig();
    updatesConfig.setName(UPDATES);

    conf.addListConfig(updatesConfig);

    ListConfig availableWorkersConfig = new ListConfig();
    availableWorkersConfig.setName(AVAILABLE_WORKERS);
    conf.addListConfig(availableWorkersConfig);

    MapConfig heartbeatConfig = new MapConfig();
    heartbeatConfig.setName(HEART_BEAT);
    conf.addMapConfig(heartbeatConfig);

    MapConfig workerEnabledConifg = new MapConfig();
    workerEnabledConifg.setName(WORKER_ENABLED);
    conf.addMapConfig(workerEnabledConifg);

    return conf;
  }
  private void multicastJoin(int count, final boolean sleep) throws InterruptedException {
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(count);

    final Config config = new Config();
    config.setProperty("hazelcast.wait.seconds.before.join", "5");
    config.getNetworkConfig().getJoin().getMulticastConfig().setMulticastTimeoutSeconds(25);
    final ConcurrentMap<Integer, HazelcastInstance> map =
        new ConcurrentHashMap<Integer, HazelcastInstance>();
    final CountDownLatch latch = new CountDownLatch(count);
    final ExecutorService ex = Executors.newCachedThreadPool();
    for (int i = 0; i < count; i++) {
      final int index = i;
      ex.execute(
          new Runnable() {
            public void run() {
              if (sleep) {
                try {
                  Thread.sleep((int) (1000 * Math.random()));
                } catch (InterruptedException ignored) {
                }
              }
              HazelcastInstance h = nodeFactory.newHazelcastInstance(config);
              map.put(index, h);
              latch.countDown();
            }
          });
    }
    assertOpenEventually(latch);
    for (HazelcastInstance h : map.values()) {
      assertEquals(count, h.getCluster().getMembers().size());
    }
    ex.shutdown();
  }
 private static Config getConfigClusterB() {
   Config config = new Config();
   config
       .setLicenseKey(LICENSE_KEY)
       .getGroupConfig()
       .setName("clusterB")
       .setPassword("clusterB-pass");
   config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
   config
       .getNetworkConfig()
       .getJoin()
       .getTcpIpConfig()
       .setEnabled(true)
       .addMember("127.0.0.1:5702");
   return config;
 }
 @Test
 public void readMulticastConfig() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "   <group>\n"
           + "        <name>dev</name>\n"
           + "        <password>dev-pass</password>\n"
           + "    </group>\n"
           + "    <network>\n"
           + "        <port auto-increment=\"true\">5701</port>\n"
           + "        <join>\n"
           + "            <multicast enabled=\"true\" loopbackModeEnabled=\"true\">\n"
           + "                <multicast-group>224.2.2.3</multicast-group>\n"
           + "                <multicast-port>54327</multicast-port>\n"
           + "            </multicast>\n"
           + "            <tcp-ip enabled=\"false\">\n"
           + "                <interface>127.0.0.1</interface>\n"
           + "            </tcp-ip>\n"
           + "            <aws enabled=\"false\" connection-timeout-seconds=\"10\" >\n"
           + "                <access-key>access</access-key>\n"
           + "                <secret-key>secret</secret-key>\n"
           + "            </aws>\n"
           + "        </join>\n"
           + "        <interfaces enabled=\"false\">\n"
           + "            <interface>10.10.1.*</interface>\n"
           + "        </interfaces>\n"
           + "    </network>\n"
           + "</hazelcast>";
   Config config = buildConfig(xml);
   MulticastConfig mcastConfig = config.getNetworkConfig().getJoin().getMulticastConfig();
   assertTrue(mcastConfig.isEnabled());
   assertTrue(mcastConfig.isLoopbackModeEnabled());
   assertEquals("224.2.2.3", mcastConfig.getMulticastGroup());
   assertEquals(54327, mcastConfig.getMulticastPort());
 }
 @Test
 public void testNetworkConfig() {
   NetworkConfig networkConfig = config.getNetworkConfig();
   assertNotNull(networkConfig);
   assertEquals(5700, networkConfig.getPort());
   assertFalse(networkConfig.isPortAutoIncrement());
   final Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions();
   assertEquals(2, allowedPorts.size());
   Iterator portIter = allowedPorts.iterator();
   assertEquals("35000-35100", portIter.next());
   assertEquals("36000,36100", portIter.next());
   assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled());
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8);
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16);
   assertFalse(networkConfig.getInterfaces().isEnabled());
   assertEquals(1, networkConfig.getInterfaces().getInterfaces().size());
   assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next());
   TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig();
   assertNotNull(tcp);
   assertTrue(tcp.isEnabled());
   assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled());
   final List<String> members = tcp.getMembers();
   assertEquals(members.toString(), 2, members.size());
   assertEquals("127.0.0.1:5700", members.get(0));
   assertEquals("127.0.0.1:5701", members.get(1));
   assertEquals("127.0.0.1:5700", tcp.getRequiredMember());
   AwsConfig aws = networkConfig.getJoin().getAwsConfig();
   assertFalse(aws.isEnabled());
   assertEquals("sample-access-key", aws.getAccessKey());
   assertEquals("sample-secret-key", aws.getSecretKey());
   assertEquals("sample-region", aws.getRegion());
   assertEquals("sample-group", aws.getSecurityGroupName());
   assertEquals("sample-tag-key", aws.getTagKey());
   assertEquals("sample-tag-value", aws.getTagValue());
 }
Example #8
0
  Joiner createJoiner() {
    JoinConfig join = config.getNetworkConfig().getJoin();
    join.verify();

    if (groupProperties.getBoolean(GroupProperty.DISCOVERY_SPI_ENABLED)) {
      // TODO: Auto-Upgrade Multicast+AWS configuration!
      logger.info("Activating Discovery SPI Joiner");
      return new DiscoveryJoiner(this, discoveryService);
    } else {
      if (join.getMulticastConfig().isEnabled() && multicastService != null) {
        logger.info("Creating MulticastJoiner");
        return new MulticastJoiner(this);
      } else if (join.getTcpIpConfig().isEnabled()) {
        logger.info("Creating TcpIpJoiner");
        return new TcpIpJoiner(this);
      } else if (join.getAwsConfig().isEnabled()) {
        Class clazz;
        try {
          logger.info("Creating AWSJoiner");
          clazz = Class.forName("com.hazelcast.cluster.impl.TcpIpJoinerOverAWS");
          Constructor constructor = clazz.getConstructor(Node.class);
          return (Joiner) constructor.newInstance(this);
        } catch (Exception e) {
          throw ExceptionUtil.rethrow(e);
        }
      }
    }
    return null;
  }
  protected HazelcastInstance hazelcastInstance() {
    Config config = new Config();

    config.addCacheConfig(
        new CacheSimpleConfig()
            .setName("result-cache")
            .setInMemoryFormat(InMemoryFormat.BINARY)
            .setEvictionConfig(new EvictionConfig().setEvictionPolicy(EvictionPolicy.LRU))
            .setExpiryPolicyFactoryConfig(
                new CacheSimpleConfig.ExpiryPolicyFactoryConfig(
                    new CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig(
                        CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig
                            .ExpiryPolicyType.ACCESSED,
                        new CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig(
                            20, TimeUnit.MINUTES)))));

    NetworkConfig networkConfig = new NetworkConfig();
    networkConfig.setPort(5712).setPortAutoIncrement(true);

    config.setNetworkConfig(networkConfig);
    config.setGroupConfig(new GroupConfig("ach-validation", "ach-validation"));

    TcpClusterConfigurator.configureNetwork(config.getNetworkConfig());
    TcpClusterConfigurator.configureGroup(config.getGroupConfig());

    return Hazelcast.newHazelcastInstance(config);
  }
 @Test
 public void testSSLConfig() {
   SSLConfig sslConfig = config.getNetworkConfig().getSSLConfig();
   assertNotNull(sslConfig);
   assertFalse(sslConfig.isEnabled());
   assertEquals(DummySSLContextFactory.class.getName(), sslConfig.getFactoryClassName());
   assertEquals(sslContextFactory, sslConfig.getFactoryImplementation());
 }
  @Before
  public void init() {
    Config config = new Config();
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    config.getNetworkConfig().setPort(5701);
    config.getGroupConfig().setName("cluster1");
    config.getGroupConfig().setPassword("cluster1pass");

    final HazelcastInstance hz1 = Hazelcast.newHazelcastInstance(config);

    Config config2 = new Config();
    config2.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    config2.getNetworkConfig().setPort(5702);
    config2.getGroupConfig().setName("cluster2");
    config2.getGroupConfig().setPassword("cluster2pass");

    final HazelcastInstance hz2 = Hazelcast.newHazelcastInstance(config2);
  }
 @Test
 public void testSocketInterceptorConfig() {
   SocketInterceptorConfig socketInterceptorConfig =
       config.getNetworkConfig().getSocketInterceptorConfig();
   assertNotNull(socketInterceptorConfig);
   assertFalse(socketInterceptorConfig.isEnabled());
   assertEquals(DummySocketInterceptor.class.getName(), socketInterceptorConfig.getClassName());
   assertEquals(socketInterceptor, socketInterceptorConfig.getImplementation());
 }
  /**
   * 通过加载HZ的配置文件,动态创建HZ集群
   *
   * @param configPath hz的配置文件
   */
  public HazelcastStoreManager(HazelcastProperties hazelcastProperties) {
    //        Properties prop = new Properties();
    //        try {
    //            prop = loadConf(null);
    //        } catch (IOException e) {
    //            LOGGER.warn("load conf error,use default config");
    //        }
    Config cfg = new Config();
    cfg.getGroupConfig().setName(hazelcastProperties.getGroupUserName());
    cfg.getGroupConfig().setPassword(hazelcastProperties.getGroupPassword());

    cfg.setInstanceName(hazelcastProperties.getInstanceName());

    // cfg.getQueueConfig(EVENT_QUEUE).addItemListenerConfig(new
    // ItemListenerConfig(this.hazelcastQueueItemListener,true));
    if (hazelcastProperties.getMancenter().isEnable()
        && StringUtils.isNotBlank(hazelcastProperties.getMancenter().getUrl())) {
      cfg.getManagementCenterConfig().setEnabled(true);
      cfg.getManagementCenterConfig().setUrl(hazelcastProperties.getMancenter().getUrl());
    }
    System.setProperty("hazelcast.socket.bind.any", "false");
    String ip = "127.0.0.1";
    try {
      ip = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
      LOGGER.warn("get ip error, {}", e.getMessage());
    }
    LOGGER.info("local memchine ip: {}", ip);
    cfg.getProperties(); // .getGroupProperties().SOCKET_SERVER_BIND_ANY
    cfg.getNetworkConfig().getInterfaces().addInterface(ip);
    cfg.getNetworkConfig().getInterfaces().setEnabled(true);

    JoinConfig join = cfg.getNetworkConfig().getJoin();
    TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
    tcpIpConfig.addMember(hazelcastProperties.getMembers());
    if (!tcpIpConfig.getMembers().contains("127.0.0.1")) {
      tcpIpConfig.addMember("127.0.0.1");
    }
    LOGGER.info("hazelcast members in prop:{}", tcpIpConfig.getMembers());
    tcpIpConfig.setEnabled(true);
    this.hazelcast = Hazelcast.newHazelcastInstance(cfg);
    this.cacheManager = new HazelcastCacheManager(this.hazelcast);
  }
  @Test
  public void testNodeStartup() {
    TestHazelcastFactory factory = new TestHazelcastFactory();

    Config config = new Config();
    config.getNetworkConfig().setPort(50001);
    InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
    interfaces.clear();
    interfaces.setEnabled(true);
    interfaces.addInterface("127.0.0.1");

    final HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance(config);
    final HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance(config);
    final HazelcastInstance hazelcastInstance3 = factory.newHazelcastInstance(config);

    try {
      String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
      InputStream xmlResource =
          ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);

      ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
      final HazelcastInstance client = factory.newHazelcastClient(clientConfig);

      assertNotNull(hazelcastInstance1);
      assertNotNull(hazelcastInstance2);
      assertNotNull(hazelcastInstance3);
      assertNotNull(client);

      assertTrueEventually(
          new AssertTask() {
            @Override
            public void run() throws Exception {

              assertEquals(3, hazelcastInstance1.getCluster().getMembers().size());
              assertEquals(3, hazelcastInstance2.getCluster().getMembers().size());
              assertEquals(3, hazelcastInstance3.getCluster().getMembers().size());
              assertEquals(3, client.getCluster().getMembers().size());
            }
          });
    } finally {
      factory.shutdownAll();
    }
  }
  @Provides
  @LazySingleton
  public synchronized HazelcastInstance getInstance() {
    if (instance == null) {
      Config config = new Config();
      config.setInstanceName(clusterName + "_" + UUID.randomUUID().toString());
      config.setGroupConfig(new GroupConfig(clusterName));
      config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
      config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
      config.getNetworkConfig().getJoin().getTcpIpConfig().addMember("127.0.0.1");
      config.getNetworkConfig().getInterfaces().clear();
      config.getNetworkConfig().getInterfaces().addInterface("127.0.0.*");
      config.getNetworkConfig().getInterfaces().setEnabled(true);

      instance = Hazelcast.newHazelcastInstance(config);
    }

    return instance;
  }
 @Test
 public void networkReuseAddress() {
   Config config =
       buildConfig(
           HAZELCAST_START_TAG
               + "    <network>\n"
               + "        <reuse-address>true</reuse-address>\n"
               + "    </network>\n"
               + "</hazelcast>");
   assertTrue(config.getNetworkConfig().isReuseAddress());
 }
Example #17
0
 public static Collection<String> getConfigurationMembers(Config config) {
   final TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
   final Collection<String> configMembers = tcpIpConfig.getMembers();
   final Set<String> possibleMembers = new HashSet<String>();
   for (String member : configMembers) {
     // split members defined in tcp-ip configuration by comma(,) semi-colon(;) space( ).
     String[] members = member.split("[,; ]");
     Collections.addAll(possibleMembers, members);
   }
   return possibleMembers;
 }
 @Test(expected = RuntimeException.class, timeout = 120000)
 public void testFailingSocketInterceptor() {
   Config config = new Config();
   config.setProperty(GroupProperties.PROP_MAX_JOIN_SECONDS, "3");
   SocketInterceptorConfig sic = new SocketInterceptorConfig();
   MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(false);
   sic.setImplementation(mySocketInterceptor);
   config.getNetworkConfig().setSocketInterceptorConfig(sic);
   HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
   HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
 }
 @Test
 public void networkReuseAddress() {
   Config config =
       buildConfig(
           "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
               + "    <network>\n"
               + "        <reuse-address>true</reuse-address>\n"
               + "    </network>\n"
               + "</hazelcast>");
   assertTrue(config.getNetworkConfig().isReuseAddress());
 }
Example #20
0
  private DiscoveryService createDiscoveryService(Config config) {
    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    DiscoveryStrategiesConfig providersConfig =
        joinConfig.getDiscoveryStrategiesConfig().getAsReadOnly();

    DiscoveryServiceProvider factory = providersConfig.getDiscoveryServiceProvider();
    if (factory == null) {
      factory = new DefaultDiscoveryServiceProvider();
    }
    return factory.newDiscoveryService(
        DiscoveryMode.Member, providersConfig, config.getClassLoader());
  }
Example #21
0
  void start() {
    nodeEngine.start();
    connectionManager.start();
    if (config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()) {
      final Thread multicastServiceThread =
          new Thread(
              hazelcastThreadGroup.getInternalThreadGroup(),
              multicastService,
              hazelcastThreadGroup.getThreadNamePrefix("MulticastThread"));
      multicastServiceThread.start();
    }
    if (groupProperties.getBoolean(GroupProperty.DISCOVERY_SPI_ENABLED)) {
      discoveryService.start();
    }

    if (groupProperties.getBoolean(GroupProperty.SHUTDOWNHOOK_ENABLED)) {
      logger.finest("Adding ShutdownHook");
      Runtime.getRuntime().addShutdownHook(shutdownHookThread);
    }
    state = NodeState.ACTIVE;

    join();
    int clusterSize = clusterService.getSize();
    if (config.getNetworkConfig().isPortAutoIncrement()
        && address.getPort() >= config.getNetworkConfig().getPort() + clusterSize) {
      StringBuilder sb = new StringBuilder("Config seed port is ");
      sb.append(config.getNetworkConfig().getPort());
      sb.append(" and cluster size is ");
      sb.append(clusterSize);
      sb.append(". Some of the ports seem occupied!");
      logger.warning(sb.toString());
    }
    try {
      managementCenterService = new ManagementCenterService(hazelcastInstance);
    } catch (Exception e) {
      logger.warning("ManagementCenterService could not be constructed!", e);
    }
    nodeExtension.afterStart(this);
    versionCheck.check(this, getBuildInfo().getVersion(), buildInfo.isEnterprise());
  }
  @Test
  public void readPortAutoIncrement() {
    // explicitly set.
    Config config =
        buildConfig(
            "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
                + "    <network>\n"
                + "        <port auto-increment=\"false\">5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertFalse(config.getNetworkConfig().isPortAutoIncrement());

    // check if the default is picked up correctly
    config =
        buildConfig(
            "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
                + "    <network>\n"
                + "        <port>5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertTrue(config.getNetworkConfig().isPortAutoIncrement());
  }
  @Test
  public void readPortCount() {
    // check when it is explicitly set.
    Config config =
        buildConfig(
            "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
                + "    <network>\n"
                + "        <port port-count=\"200\">5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertEquals(200, config.getNetworkConfig().getPortCount());

    // check if the default is passed in correctly
    config =
        buildConfig(
            "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
                + "    <network>\n"
                + "        <port>5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertEquals(100, config.getNetworkConfig().getPortCount());
  }
  @Test
  public void readPortCount() {
    // check when it is explicitly set.
    Config config =
        buildConfig(
            HAZELCAST_START_TAG
                + "    <network>\n"
                + "        <port port-count=\"200\">5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertEquals(200, config.getNetworkConfig().getPortCount());

    // check if the default is passed in correctly
    config =
        buildConfig(
            HAZELCAST_START_TAG
                + "    <network>\n"
                + "        <port>5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertEquals(100, config.getNetworkConfig().getPortCount());
  }
  @Test
  public void readPortAutoIncrement() {
    // explicitly set.
    Config config =
        buildConfig(
            HAZELCAST_START_TAG
                + "    <network>\n"
                + "        <port auto-increment=\"false\">5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertFalse(config.getNetworkConfig().isPortAutoIncrement());

    // check if the default is picked up correctly
    config =
        buildConfig(
            HAZELCAST_START_TAG
                + "    <network>\n"
                + "        <port>5701</port>\n"
                + "    </network>\n"
                + "</hazelcast>");
    assertTrue(config.getNetworkConfig().isPortAutoIncrement());
  }
Example #26
0
 public void start() {
   logger.finest(
       "We are asked to start and completelyShutdown is " + String.valueOf(completelyShutdown));
   if (completelyShutdown) return;
   nodeEngine.start();
   connectionManager.start();
   if (config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()) {
     final Thread multicastServiceThread =
         new Thread(
             hazelcastInstance.threadGroup,
             multicastService,
             getThreadNamePrefix("MulticastThread"));
     multicastServiceThread.start();
   }
   setActive(true);
   if (!completelyShutdown) {
     logger.finest("Adding ShutdownHook");
     Runtime.getRuntime().addShutdownHook(shutdownHookThread);
   }
   logger.finest("finished starting threads, calling join");
   join();
   int clusterSize = clusterService.getSize();
   if (config.getNetworkConfig().isPortAutoIncrement()
       && address.getPort() >= config.getNetworkConfig().getPort() + clusterSize) {
     StringBuilder sb = new StringBuilder("Config seed port is ");
     sb.append(config.getNetworkConfig().getPort());
     sb.append(" and cluster size is ");
     sb.append(clusterSize);
     sb.append(". Some of the ports seem occupied!");
     logger.warning(sb.toString());
   }
   try {
     managementCenterService = new ManagementCenterService(hazelcastInstance);
   } catch (Exception e) {
     logger.warning("ManagementCenterService could not be constructed!", e);
   }
   initializer.afterInitialize(this);
 }
 /** https://github.com/hazelcast/hazelcast/issues/8463 */
 @Test
 public void testJMXStatsWithPublicAddressHostName() {
   Config config = new Config();
   config.getNetworkConfig().setPublicAddress("hazelcast.org");
   HazelcastInstance instance = createHazelcastInstance(config);
   warmUpPartitions(instance);
   MemberStateImpl memberState = new MemberStateImpl();
   TimedMemberStateFactoryHelper.registerJMXBeans(
       getNode(instance).hazelcastInstance, memberState);
   PartitionServiceBeanDTO partitionServiceDTO =
       memberState.getMXBeans().getPartitionServiceBean();
   assertEquals(
       partitionServiceDTO.getPartitionCount(), partitionServiceDTO.getActivePartitionCount());
 }
Example #28
0
 private static Config buildConfig(boolean multicastEnabled) {
   Config c = new Config();
   c.getGroupConfig().setName("group").setPassword("pass");
   c.setProperty(GroupProperties.PROP_MERGE_FIRST_RUN_DELAY_SECONDS, "10");
   c.setProperty(GroupProperties.PROP_MERGE_NEXT_RUN_DELAY_SECONDS, "5");
   c.setProperty(GroupProperties.PROP_MAX_NO_HEARTBEAT_SECONDS, "10");
   c.setProperty(GroupProperties.PROP_MASTER_CONFIRMATION_INTERVAL_SECONDS, "2");
   c.setProperty(GroupProperties.PROP_MAX_NO_MASTER_CONFIRMATION_SECONDS, "10");
   c.setProperty(GroupProperties.PROP_MEMBER_LIST_PUBLISH_INTERVAL_SECONDS, "10");
   final NetworkConfig networkConfig = c.getNetworkConfig();
   networkConfig.getJoin().getMulticastConfig().setEnabled(multicastEnabled);
   networkConfig.getJoin().getTcpIpConfig().setEnabled(!multicastEnabled);
   networkConfig.setPortAutoIncrement(false);
   return c;
 }
 @Test
 public void readAwsConfig() {
   String xml =
       HAZELCAST_START_TAG
           + "   <group>\n"
           + "        <name>dev</name>\n"
           + "        <password>dev-pass</password>\n"
           + "    </group>\n"
           + "    <network>\n"
           + "        <port auto-increment=\"true\">5701</port>\n"
           + "        <join>\n"
           + "            <multicast enabled=\"false\">\n"
           + "                <multicast-group>224.2.2.3</multicast-group>\n"
           + "                <multicast-port>54327</multicast-port>\n"
           + "            </multicast>\n"
           + "            <tcp-ip enabled=\"false\">\n"
           + "                <interface>127.0.0.1</interface>\n"
           + "            </tcp-ip>\n"
           + "            <aws enabled=\"true\" connection-timeout-seconds=\"10\" >\n"
           + "                <access-key>access</access-key>\n"
           + "                <secret-key>secret</secret-key>\n"
           + "            </aws>\n"
           + "        </join>\n"
           + "        <interfaces enabled=\"false\">\n"
           + "            <interface>10.10.1.*</interface>\n"
           + "        </interfaces>\n"
           + "    </network>\n"
           + "</hazelcast>";
   Config config = buildConfig(xml);
   AwsConfig awsConfig = config.getNetworkConfig().getJoin().getAwsConfig();
   assertTrue(awsConfig.isEnabled());
   assertEquals(
       10, config.getNetworkConfig().getJoin().getAwsConfig().getConnectionTimeoutSeconds());
   assertEquals("access", awsConfig.getAccessKey());
   assertEquals("secret", awsConfig.getSecretKey());
 }
  public Member startMember(String clusterId) throws ServerException {
    LOG.info("Starting a Member on cluster : " + clusterId);
    HzCluster hzCluster = clusterMap.get(clusterId);
    if (hzCluster != null) {
      Config config = hzCluster.getConfig();

      LOG.info(config.getNetworkConfig().getJoin().getTcpIpConfig());

      HazelcastInstance hzInstance = Hazelcast.newHazelcastInstance(config);
      com.hazelcast.core.Member member = hzInstance.getCluster().getLocalMember();
      if (hzCluster.addInstance(member.getUuid(), hzInstance)) {
        return new Member(
            member.getUuid(), member.getAddress().getHost(), member.getAddress().getPort());
      }
    }
    throw new ServerException("Cannot find Cluster with id:" + clusterId);
  }