@Override public boolean compile(VoltProjectBuilder builder) { if (m_compiled) { return true; } m_compiled = builder.compile(m_jarFileName, m_partitionPerSite, m_siteCount, m_replication, "localhost"); // (1) Load catalog from Jar Catalog tmpCatalog = CatalogUtil.loadCatalogFromJar(m_jarFileName); // (2) Update catalog to include target cluster configuration ClusterConfiguration cc = new ClusterConfiguration(); // Update cc with a bunch of hosts/sites/partitions for (int site = 0, currentPartition = 0; site < m_siteCount; ++site) { for (int partition = 0; partition < m_partitionPerSite; ++partition, ++currentPartition) { cc.addPartition("localhost", site, currentPartition); } } this.catalog = FixCatalog.addHostInfo(tmpCatalog, cc); // (3) Write updated catalog back out to jar file try { CatalogUtil.updateCatalogInJar(m_jarFileName, catalog); } catch (Exception e) { throw new RuntimeException(e); } tmpCatalog = CatalogUtil.loadCatalogFromJar(m_jarFileName); // System.err.println(CatalogInfo.getInfo(this.catalog, new File(m_jarFileName))); // Construct the base command that we will want to use to start // all of the "remote" HStoreSites List<String> siteCommand = new ArrayList<String>(); CollectionUtil.addAll(siteCommand, "ant", "hstore-site", "-Djar=" + m_jarFileName); // Be sure to include our HStoreConf parameters for (Entry<String, String> e : this.confParams.entrySet()) { siteCommand.add(String.format("-D%s=%s", e.getKey(), e.getValue())); } // Lastly, we will include the site.id as the last parameter // so that we can easily change it siteCommand.add("-Dsite.id=-1"); m_procBuilder = new ProcessBuilder(siteCommand.toArray(new String[0])); m_procBuilder.redirectErrorStream(true); // set the working directory to obj/release/prod // m_procBuilder.directory(new File(m_buildDir + File.separator + "prod")); return m_compiled; }
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; }