/** * Starts new grid node. * * @param gridName name of new node. * @param springCfg file with spring configuration to use for this node. * @return a grid instance local to new node {@link GridGain#start(GridConfiguration)}. * @throws Exception if node run failed. */ protected Grid startNode(String gridName, File springCfg) throws Exception { assert springCfg != null; ListableBeanFactory springCtx = new FileSystemXmlApplicationContext("file:///" + springCfg.getAbsolutePath()); Map cfgMap = springCtx.getBeansOfType(GridConfiguration.class); assert cfgMap != null; assert !cfgMap.isEmpty(); GridConfiguration cfg = (GridConfiguration) cfgMap.values().iterator().next(); cfg.setGridName(gridName + "-" + getNextNodeNum()); return G.start(cfg); }
/** {@inheritDoc} */ @Override protected Object executeJob(int gridSize, String type) { log.info(">>> Starting new grid node [currGridSize=" + gridSize + ", arg=" + type + "]"); if (type == null) throw new IllegalArgumentException("Node type to start should be specified."); IgniteConfiguration cfg = getConfig(type); // Generate unique for this VM grid name. String gridName = cfg.getGridName() + " (" + UUID.randomUUID() + ")"; // Update grid name (required to be unique). cfg.setGridName(gridName); // Start new node in current VM. Ignite g = G.start(cfg); log.info( ">>> Grid started [nodeId=" + g.cluster().localNode().id() + ", name='" + g.name() + "']"); return true; }
/** * Example for start/stop node tasks. * * @param args Not used. */ public static void main(String[] args) { String nodeType = "tcp+ssl"; // Start initial node = 1 try (Ignite g = G.start(NODE_CFG.get(nodeType))) { // Change topology. changeTopology(g, 4, 1, nodeType); changeTopology(g, 1, 4, nodeType); // Stop node by id = 0 g.compute().execute(ClientStopNodeTask.class, g.cluster().localNode().id().toString()); // Wait for node stops. // U.sleep(1000); assert G.allGrids().isEmpty(); } catch (Exception e) { System.err.println("Uncaught exception: " + e.getMessage()); e.printStackTrace(System.err); } }