public PersistManager(URI iceRoot) { I = new Persist[MAX_BACKENDS]; stats = new PersistStatsEntry[MAX_BACKENDS]; for (int i = 0; i < stats.length; i++) { stats[i] = new PersistStatsEntry(); } if (iceRoot == null) { Log.err("ice_root must be specified. Exiting."); H2O.exit(1); } Persist ice = null; boolean windowsPath = iceRoot.toString().matches("^[a-zA-Z]:.*"); if (windowsPath) { ice = new PersistFS(new File(iceRoot.toString())); } else if ((iceRoot.getScheme() == null) || Schemes.FILE.equals(iceRoot.getScheme())) { ice = new PersistFS(new File(iceRoot.getPath())); } else if (Schemes.HDFS.equals(iceRoot.getScheme())) { Log.err("HDFS ice_root not yet supported. Exiting."); H2O.exit(1); // I am not sure anyone actually ever does this. // H2O on Hadoop launches use local disk for ice root. // This has a chance to work, but turn if off until it gets tested. // // try { // Class klass = Class.forName("water.persist.PersistHdfs"); // java.lang.reflect.Constructor constructor = klass.getConstructor(new // Class[]{URI.class}); // ice = (Persist) constructor.newInstance(iceRoot); // } catch (Exception e) { // Log.err("Could not initialize HDFS"); // throw new RuntimeException(e); // } } I[Value.ICE] = ice; I[Value.NFS] = new PersistNFS(); try { Class klass = Class.forName("water.persist.PersistHdfs"); java.lang.reflect.Constructor constructor = klass.getConstructor(); I[Value.HDFS] = (Persist) constructor.newInstance(); Log.info("HDFS subsystem successfully initialized"); } catch (Throwable ignore) { Log.info("HDFS subsystem not available"); } try { Class klass = Class.forName("water.persist.PersistS3"); java.lang.reflect.Constructor constructor = klass.getConstructor(); I[Value.S3] = (Persist) constructor.newInstance(); Log.info("S3 subsystem successfully initialized"); } catch (Throwable ignore) { Log.info("S3 subsystem not available"); } }
/** * Read Node config from file config.nodeConfigFileName, including available nodes and their * possible connections */ public NodeFactory(Config config, ProblemData problemData) { this.config = config; this.problemData = problemData; try { FileInputStream in = new FileInputStream(config.nodeConfigFileName); Properties props = new Properties(); props.load(in); in.close(); String separator = "\\s*,\\s*"; String tmp = props.getProperty("sets"); String[] sets = tmp.split(separator); nodeSets = new NodeSet[sets.length]; int i, j, k; for (i = 0; i < sets.length; i++) { nodeSets[i] = new NodeSet(sets[i]); String[] nodes; tmp = props.getProperty(sets[i] + "Functions"); if (tmp == null) Logger.log( "Warning: when reading " + config.nodeConfigFileName + ", no functions found for set " + sets[i]); else { nodes = tmp.split(separator); for (j = 0; j < nodes.length; j++) { Class cl = Class.forName("gpalta.nodes." + nodes[j]); java.lang.reflect.Constructor co = cl.getConstructor(); nodeSets[i].addFunction((Node) co.newInstance()); } } tmp = props.getProperty(sets[i] + "Terminals"); if (tmp == null) Logger.log( "Warning: when reading " + config.nodeConfigFileName + ", no terminals found for set " + sets[i]); else { nodes = tmp.split(separator); for (j = 0; j < nodes.length; j++) { Class cl = Class.forName("gpalta.nodes." + nodes[j]); if (nodes[j].contains("Var")) { for (k = 0; k < problemData.nVars; k++) { java.lang.reflect.Constructor[] co = cl.getConstructors(); nodeSets[i].addTerminal((Node) co[0].newInstance(k + 1)); } } else if (nodes[j].contains("Angle")) { for (k = 0; k < problemData.nVars - 1; k++) { java.lang.reflect.Constructor[] co = cl.getConstructors(); nodeSets[i].addTerminal((Node) co[0].newInstance(k + 1)); } } else { java.lang.reflect.Constructor co = cl.getConstructor(); nodeSets[i].addTerminal((Node) co.newInstance()); } } } } for (i = 0; i < nodeSets.length; i++) { for (Node n : nodeSets[i].getAll()) { n.setType(nodeSets[i]); } } for (i = 0; i < nodeSets.length; i++) { for (Node n : nodeSets[i].getAll()) { tmp = props.getProperty("kids" + n.getClass().getSimpleName()); if (tmp != null) { String[] kids = tmp.split(separator); if (kids.length != n.nKids()) { Logger.log( "Error reading " + config.nodeConfigFileName + ": must specify " + n.nKids() + " kids for " + n.getClass().getSimpleName()); } for (j = 0; j < n.nKids(); j++) { for (k = 0; k < nodeSets.length; k++) { if (nodeSets[k].getName().equals(kids[j])) { n.setTypeOfKids(j, nodeSets[k]); break; } } if (k == nodeSets.length) Logger.log( "Error reading " + config.nodeConfigFileName + ": Setting kids for " + n.getClass().getSimpleName() + ", " + kids[j] + " doesn't match any set name"); } } else for (j = 0; j < n.nKids(); j++) n.setTypeOfKids(j, nodeSets[i]); } } tmp = props.getProperty("treeRoot"); if (tmp == null) { Logger.log( "Error reading " + config.nodeConfigFileName + ": property \"treeRoot\" not present"); } for (i = 0; i < nodeSets.length; i++) { if (nodeSets[i].getName().equals(tmp)) { treeRoot = nodeSets[i]; break; } } if (i == nodeSets.length) Logger.log( "Error reading " + config.nodeConfigFileName + ": Setting treeRoot, " + tmp + " doesn't match any set name"); } catch (IOException e) { Logger.log("Error reading " + config.nodeConfigFileName + ":"); Logger.log(e); } catch (ClassNotFoundException e) { Logger.log("Error reading " + config.nodeConfigFileName + ":"); Logger.log(e); } catch (NoSuchMethodException e) { Logger.log("Error reading " + config.nodeConfigFileName + ":"); Logger.log(e); } catch (InstantiationException e) { Logger.log("Error reading " + config.nodeConfigFileName + ":"); Logger.log(e); } catch (IllegalAccessException e) { Logger.log("Error reading " + config.nodeConfigFileName + ":"); Logger.log(e); } catch (InvocationTargetException e) { Logger.log("Error reading " + config.nodeConfigFileName + ":"); Logger.log(e); } }