Esempio n. 1
0
  ProcedureDescriptor getProcedure(org.voltdb.compiler.projectfile.ProceduresType.Procedure xmlproc)
      throws VoltCompilerException {
    final ArrayList<String> users = new ArrayList<String>();
    final ArrayList<String> groups = new ArrayList<String>();
    final ArrayList<String> prefetchable = new ArrayList<String>();
    final ArrayList<String> deferrable = new ArrayList<String>();

    // @users
    if (xmlproc.getUsers() != null) {
      for (String user : xmlproc.getUsers().split(",")) {
        users.add(user);
      }
    }

    // @groups
    if (xmlproc.getGroups() != null) {
      for (String group : xmlproc.getGroups().split(",")) {
        groups.add(group);
      }
    }

    // @class
    String classattr = xmlproc.getClazz();

    // If procedure/sql is present, this is a "statement procedure"
    if (xmlproc.getSql() != null) {
      String partattr = xmlproc.getPartitioninfo();
      // null partattr means multi-partition
      // set empty attributes to multi-partition
      if (partattr != null && partattr.length() == 0) partattr = null;
      return new ProcedureDescriptor(users, groups, classattr, xmlproc.getSql(), partattr);
    } else {
      String partattr = xmlproc.getPartitioninfo();
      if (partattr != null) {
        String msg =
            "Java procedures must specify partition info using "
                + "@ProcInfo annotation in the Java class implementation "
                + "and may not use the @partitioninfo project file procedure attribute.";
        throw new VoltCompilerException(msg);
      }
      // HACK: Prefetchable
      if (xmlproc.getPrefetchable() != null) {
        CollectionUtil.addAll(prefetchable, xmlproc.getPrefetchable().split("[\\s]*,[\\s]*"));
      }
      // HACK: Deferrable
      if (xmlproc.getDeferrable() != null) {
        CollectionUtil.addAll(deferrable, xmlproc.getDeferrable().split("[\\s]*,[\\s]*"));
      }
      return new ProcedureDescriptor(users, groups, classattr, prefetchable, deferrable);
    }
  }
Esempio n. 2
0
  @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;
  }