コード例 #1
0
  @Override
  public Configuration loadResourceConfiguration() throws Exception {
    Properties properties = new Properties();
    properties.load(new FileInputStream(jvmOptsFile));

    Configuration config = new Configuration();

    String heapDumpOnOOMError = properties.getProperty("heap_dump_on_OOMError");
    String heapDumpDir = properties.getProperty("heap_dump_dir");

    config.put(new PropertySimple("minHeapSize", getHeapMinProp(properties)));
    config.put(new PropertySimple("maxHeapSize", getHeapMaxProp(properties)));
    config.put(new PropertySimple("heapNewSize", getHeapNewProp(properties)));
    config.put(new PropertySimple("threadStackSize", getStackSizeProp(properties)));

    if (!StringUtil.isEmpty(heapDumpOnOOMError)) {
      config.put(new PropertySimple("heapDumpOnOOMError", true));
    } else {
      config.put(new PropertySimple("heapDumpOnOOMError", false));
    }

    if (!StringUtil.isEmpty(heapDumpDir)) {
      config.put(new PropertySimple("heapDumpDir", heapDumpDir));
    } else {
      File basedir = jvmOptsFile.getParentFile().getParentFile();
      config.put(new PropertySimple("heapDumpDir", new File(basedir, "bin").getAbsolutePath()));
    }

    ConfigEditor yamlEditor = new ConfigEditor(cassandraYamlFile);
    yamlEditor.load();
    config.put(new PropertySimple("cqlPort", yamlEditor.getNativeTransportPort()));
    config.put(new PropertySimple("gossipPort", yamlEditor.getStoragePort()));

    return config;
  }
コード例 #2
0
  private void updateCassandraYaml(Configuration newConfig) {
    ConfigEditor editor = new ConfigEditor(cassandraYamlFile);
    try {
      editor.load();

      PropertySimple cqlPortProperty = newConfig.getSimple("cqlPort");
      if (cqlPortProperty != null) {
        editor.setNativeTransportPort(cqlPortProperty.getIntegerValue());
      }

      PropertySimple gossipPortProperty = newConfig.getSimple("gossipPort");
      if (gossipPortProperty != null) {
        editor.setStoragePort(gossipPortProperty.getIntegerValue());
      }

      editor.save();
    } catch (ConfigEditorException e) {
      if (e.getCause() instanceof YAMLException) {
        log.error("Failed to update " + cassandraYamlFile);
        log.info("Attempting to restore " + cassandraYamlFile);
        try {
          editor.restore();
          throw e;
        } catch (ConfigEditorException e1) {
          log.error(
              "Failed to restore "
                  + cassandraYamlFile
                  + ". A copy of the file prior to any "
                  + "modifications can be found at "
                  + editor.getBackupFile());
          throw new ConfigEditorException(
              "There was an error updating "
                  + cassandraYamlFile
                  + " and "
                  + "undoing the changes failed. A copy of the file can be found at "
                  + editor.getBackupFile()
                  + ". See the agent logs for more details.",
              e);
        }
      } else {
        log.error(
            "No updates were made to " + cassandraYamlFile + " due to an unexpected error", e);
        throw e;
      }
    }
  }