/** * Load grid configuration for specified node type. * * @param type Node type to load configuration for. * @return Grid configuration for specified node type. */ static IgniteConfiguration getConfig(String type) { String path = NODE_CFG.get(type); if (path == null) throw new IllegalArgumentException("Unsupported node type: " + type); URL url = U.resolveIgniteUrl(path); BeanFactory ctx = new FileSystemXmlApplicationContext(url.toString()); return (IgniteConfiguration) ctx.getBean("grid.cfg"); }
/** * Sets configuration properties from the map. * * @param endpointCfg Map of properties. * @throws IgniteCheckedException If invalid property name or value. */ public void setupConfiguration(Map<String, String> endpointCfg) throws IgniteCheckedException { for (Map.Entry<String, String> e : endpointCfg.entrySet()) { try { switch (e.getKey()) { case "type": case "host": case "management": // Ignore these properties break; case "port": setPort(Integer.parseInt(e.getValue())); break; case "size": setSize(Integer.parseInt(e.getValue())); break; case "tokenDirectoryPath": setTokenDirectoryPath(e.getValue()); break; default: throw new IgniteCheckedException( "Invalid property '" + e.getKey() + "' of " + getClass().getSimpleName()); } } catch (Throwable t) { if (t instanceof IgniteCheckedException || t instanceof Error) throw t; throw new IgniteCheckedException( "Invalid value '" + e.getValue() + "' of the property '" + e.getKey() + "' in " + getClass().getSimpleName(), t); } } }
/** * 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); } }