public static void main(final String[] args) { // Parse arguments if (args.length < 5 || args.length > 6) { System.err.println( "VoltCompiler [project file] [hosts] [sites per host] [leader IP] [output JAR] [k-safety factor (optional/future)] "); System.exit(1); } final String projectPath = args[0]; final int hostCount = Integer.parseInt(args[1]); final int siteCount = Integer.parseInt(args[2]); final String leaderAddress = args[3]; final String outputJar = args[4]; int k_factor = 0; if (args.length == 6) { k_factor = Integer.parseInt(args[5]); } // Compile and exit with error code if we failed final ClusterConfig cluster_config = new ClusterConfig(hostCount, siteCount, k_factor, leaderAddress); final VoltCompiler compiler = new VoltCompiler(); final boolean success = compiler.compile(projectPath, cluster_config, outputJar, System.out, null); if (!success) { System.exit(-1); } }
public boolean compile( final VoltCompiler compiler, final String jarPath, final int sitesPerHost, final int hostCount, final int replication, final String leaderAddress) { assert (jarPath != null); assert (sitesPerHost >= 1); assert (hostCount >= 1); assert (leaderAddress != null); // this stuff could all be converted to org.voltdb.compiler.projectfile.* // jaxb objects and (WE ARE!) marshaled to XML. Just needs some elbow grease. DocumentBuilderFactory docFactory; DocumentBuilder docBuilder; Document doc; try { docFactory = DocumentBuilderFactory.newInstance(); docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.newDocument(); } catch (final ParserConfigurationException e) { e.printStackTrace(); return false; } // <project> final Element project = doc.createElement("project"); doc.appendChild(project); // <security> final Element security = doc.createElement("security"); security.setAttribute("enabled", Boolean.valueOf(m_securityEnabled).toString()); project.appendChild(security); // <database> final Element database = doc.createElement("database"); database.setAttribute("name", "database"); database.setAttribute("project", this.project_name); project.appendChild(database); buildDatabaseElement(doc, database); // boilerplate to write this DOM object to file. StreamResult result; try { final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); result = new StreamResult(new StringWriter()); final DOMSource domSource = new DOMSource(doc); transformer.transform(domSource, result); } catch (final TransformerConfigurationException e) { e.printStackTrace(); return false; } catch (final TransformerFactoryConfigurationError e) { e.printStackTrace(); return false; } catch (final TransformerException e) { e.printStackTrace(); return false; } // String xml = result.getWriter().toString(); // System.out.println(xml); final File projectFile = writeStringToTempFile(result.getWriter().toString()); final String projectPath = projectFile.getPath(); LOG.debug("PROJECT XML: " + projectPath); ClusterConfig cc = (this.cluster_config.isEmpty() ? new ClusterConfig(hostCount, sitesPerHost, replication, leaderAddress) : this.cluster_config); final boolean success = compiler.compile(projectPath, cc, jarPath, m_compilerDebugPrintStream, m_procInfoOverrides); // HACK: If we have a ParameterMappingsSet that we need to apply // either from a file or a fixed mappings, then we have // to load the catalog into this JVM, apply the mappings, and then // update the jar file with the new catalog if (m_paramMappingsFile != null || m_paramMappings.isEmpty() == false) { File jarFile = new File(jarPath); Catalog catalog = CatalogUtil.loadCatalogFromJar(jarFile); assert (catalog != null); Database catalog_db = CatalogUtil.getDatabase(catalog); this.applyParameterMappings(catalog_db); // Construct a List of prefetchable Statements this.applyPrefetchableFlags(catalog_db); // Write it out! try { CatalogUtil.updateCatalogInJar(jarFile, catalog, m_paramMappingsFile); } catch (Exception ex) { String msg = "Failed to updated Catalog in jar file '" + jarPath + "'"; throw new RuntimeException(msg, ex); } } return success; }