/** * Create and start start the cluster. */ public static LocalIgniteCluster start(int initSize) { return new LocalIgniteCluster(initSize); }
/** * Restore one of the failed nodes. */ public void restoreNode() { if (failedCfgs.isEmpty()) throw new IllegalStateException("Cannot restore nodes in healthy cluster"); NodeConfiguration nodeCfg = failedCfgs.get(rnd.nextInt(failedCfgs.size())); Ignite ignite = Ignition.start(getConfiguration(nodeCfg)); srvs.add(ignite); failedCfgs.remove(nodeCfg); }
while (cluster.size() != 1) cluster.failNode(); while (cluster.size() != cluster.getInitialSize()) cluster.restoreNode();
final int CLUSTER_SIZE = 3; try (LocalIgniteCluster cluster = LocalIgniteCluster.start(CLUSTER_SIZE); IgniteClient client = Ignition.startClient(new ClientConfiguration() .setAddresses(cluster.clientAddresses().toArray(new String[CLUSTER_SIZE])) cluster.close();
try (LocalIgniteCluster ignored = LocalIgniteCluster.start(2); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) {
/** Private constructor: use {@link #start(int)} to create instances of {@link LocalIgniteCluster}. */ private LocalIgniteCluster(int initSize) { if (initSize < 1) throw new IllegalArgumentException("Cluster must have at least one node."); this.initSize = initSize; for (int i = 0; i < initSize; i++) { IgniteConfiguration cfg = getConfiguration( new NodeConfiguration(TcpDiscoverySpi.DFLT_PORT + i, ClientConnectorConfiguration.DFLT_PORT + i) ); Ignite ignite = Ignition.start(cfg); srvs.add(ignite); } }