@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;
  }
 public String toString() {
   StringBuffer s = new StringBuffer(super.toString());
   s.append(" filterSubmit=").append(filterSubmit);
   s.append(" filter=").append(StringUtil.arrayToString(filter));
   s.append(" keyword=").append(keyword);
   return s.toString();
 }
Beispiel #3
0
  private void setTitle(HttpServletRequest request, Portal portal, String titleName)
      throws Exception {
    Resource resource = RequestUtils.getResource(request);
    ResourceGroup group = RequestUtils.getResourceGroupIfExists(request);
    ResourceType type;
    if (resource != null) {
      // resource alert definition
      type = resource.getResourceType();
    } else if (group != null) {
      // group alert definition
      type = group.getResourceType();
    } else {
      // template alert definition
      type = RequestUtils.getResourceType(request);
    }

    ResourceCategory category = type.getCategory();

    titleName = StringUtil.replace(titleName, "platform", category.toString().toLowerCase());

    portal.setName(titleName);

    // if there's an alert definition available, set our second
    // title parameter to its name
    try {
      AlertDefinition alertDef = AlertDefUtil.getAlertDefinition(request);
      request.setAttribute(Constants.TITLE_PARAM2_ATTR, alertDef.getName());
    } catch (ParameterNotFoundException e) {
      // it's okay
      log.trace("couldn't find alert definition: " + e.getMessage());
    }
  }
  private void updateCassandraJvmProps(Configuration newConfig) throws IOException {
    PropertiesFileUpdate propertiesUpdater =
        new PropertiesFileUpdate(jvmOptsFile.getAbsolutePath());
    Properties properties = propertiesUpdater.loadExistingProperties();

    String jmxPort = newConfig.getSimpleValue("jmxPort");
    if (!StringUtil.isEmpty(jmxPort)) {
      validateIntegerArg("jmx_port", jmxPort);
      properties.setProperty("jmx_port", jmxPort);
    }

    String maxHeapSize = newConfig.getSimpleValue("maxHeapSize");
    if (!StringUtil.isEmpty(maxHeapSize)) {
      validateHeapArg("maxHeapSize", maxHeapSize);
      // We want min and max heap to be the same
      properties.setProperty("heap_min", "-Xms" + maxHeapSize);
      properties.setProperty("heap_max", "-Xmx" + maxHeapSize);
    }

    String heapNewSize = newConfig.getSimpleValue("heapNewSize");
    if (!StringUtil.isEmpty(heapNewSize)) {
      validateHeapArg("heapNewSize", heapNewSize);
      properties.setProperty("heap_new", "-Xmn" + heapNewSize);
    }

    String threadStackSize = newConfig.getSimpleValue("threadStackSize");
    if (!StringUtil.isEmpty(threadStackSize)) {
      validateIntegerArg("threadStackSize", threadStackSize);
      properties.setProperty("thread_stack_size", "-Xss" + threadStackSize + "k");
    }

    PropertySimple heapDumpOnOMMError = newConfig.getSimple("heapDumpOnOOMError");
    if (heapDumpOnOMMError != null) {
      if (heapDumpOnOMMError.getBooleanValue()) {
        properties.setProperty("heap_dump_on_OOMError", "-XX:+HeapDumpOnOutOfMemoryError");
      } else {
        properties.setProperty("heap_dump_on_OOMError", "");
      }
    }

    String heapDumpDir = useForwardSlash(newConfig.getSimpleValue("heapDumpDir"));
    if (!StringUtil.isEmpty(heapDumpDir)) {
      properties.setProperty("heap_dump_dir", heapDumpDir);
    }

    propertiesUpdater.update(properties);
  }
  private String getHeapMinProp(Properties properties) {
    String value = properties.getProperty("heap_min");

    if (StringUtil.isEmpty(value)) {
      return "";
    }

    if (!value.startsWith("-Xms")) {
      return value;
    }

    return value.substring(4);
  }
  private String getStackSizeProp(Properties properties) {
    String value = properties.getProperty("thread_stack_size");

    if (StringUtil.isEmpty(value)) {
      return "";
    }

    if (!(value.startsWith("-Xss") || value.endsWith("k") || value.length() > 5)) {
      return value;
    }

    return value.substring(4, value.length() - 1);
  }
  private void updateStorageAuthConf(File basedir) {
    File confDir = new File(basedir, "conf");
    File authFile = new File(confDir, "rhq-storage-auth.conf");
    authFile.delete();

    Set<String> addresses = calculateLocalIPAddresses(deploymentOptions.getNumNodes());

    try {
      StreamUtil.copy(
          new StringReader(StringUtil.collectionToString(addresses, "\n")),
          new FileWriter(authFile),
          true);
    } catch (IOException e) {
      throw new RuntimeException("Failed to update " + authFile);
    }
  }