@Override
  protected void getValues(
      ManagedComponent managedComponent,
      MeasurementReport report,
      Set<MeasurementScheduleRequest> metrics)
      throws Exception {
    Set<MeasurementScheduleRequest> uncollectedMetrics = new HashSet<MeasurementScheduleRequest>();
    for (MeasurementScheduleRequest request : metrics) {
      String metricName = request.getName();
      if (metricName.equals("custom.connectionAvailable")) {
        try {
          Configuration parameters = new Configuration();
          OperationResult result = invokeOperation(managedComponent, "testConnection", parameters);
          PropertySimple resultProp = result.getComplexResults().getSimple("result");
          boolean connectionAvailable = resultProp.getBooleanValue();
          MeasurementDataTrait trait =
              new MeasurementDataTrait(request, connectionAvailable ? "yes" : "no");
          report.addData(trait);
        } catch (Exception e) {
          log.error("Failed to collect trait [" + metricName + "].", e);
        }
      } else {
        uncollectedMetrics.add(request);
      }
    }

    super.getValues(managedComponent, report, uncollectedMetrics);
  }
  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);
  }
Ejemplo n.º 3
0
  Object getObjectForProperty(PropertySimple prop, PropertyDefinitionSimple propDef) {

    PropertySimpleType type = propDef.getType();
    switch (type) {
      case STRING:
        return prop.getStringValue();
      case INTEGER:
        return prop.getIntegerValue();
      case BOOLEAN:
        return prop.getBooleanValue();
      case LONG:
        return prop.getLongValue();
      case FLOAT:
        return prop.getFloatValue();
      case DOUBLE:
        return prop.getDoubleValue();
      default:
        return prop.getStringValue();
    }
  }
Ejemplo n.º 4
0
  @Override
  public OperationResult invokeOperation(String name, Configuration parameters)
      throws InterruptedException, Exception {

    if (!name.contains(":")) {
      OperationResult badName = new OperationResult("Operation name did not contain a ':'");
      badName.setErrorMessage("Operation name did not contain a ':'");
      return badName;
    }

    int colonPos = name.indexOf(':');
    String what = name.substring(0, colonPos);
    String op = name.substring(colonPos + 1);
    Operation operation = null;

    Address theAddress = new Address();

    if (what.equals("server-group")) {
      String groupName = parameters.getSimpleValue("name", "");
      String profile = parameters.getSimpleValue("profile", "default");

      theAddress.add("server-group", groupName);

      operation = new Operation(op, theAddress);
      operation.addAdditionalProperty("profile", profile);
    } else if (what.equals("server")) {
      if (context.getResourceType().getName().equals("JBossAS-Managed")) {
        String host = pluginConfiguration.getSimpleValue("domainHost", "local");
        theAddress.add("host", host);
        theAddress.add("server-config", myServerName);
        operation = new Operation(op, theAddress);
      } else if (context.getResourceType().getName().equals("Host")) {
        theAddress.add(address);
        String serverName = parameters.getSimpleValue("name", null);
        theAddress.add("server-config", serverName);
        Map<String, Object> props = new HashMap<String, Object>();
        String serverGroup = parameters.getSimpleValue("group", null);
        props.put("group", serverGroup);
        if (op.equals("add")) {
          props.put("name", serverName);
          boolean autoStart = parameters.getSimple("auto-start").getBooleanValue();
          props.put("auto-start", autoStart);
          // TODO put more properties in
        }

        operation = new Operation(op, theAddress, props);
      } else {
        operation = new Operation(op, theAddress);
      }
    } else if (what.equals("destination")) {
      theAddress.add(address);
      String newName = parameters.getSimpleValue("name", "");
      String type = parameters.getSimpleValue("type", "jms-queue").toLowerCase();
      theAddress.add(type, newName);
      PropertyList jndiNamesProp = parameters.getList("entries");
      if (jndiNamesProp == null || jndiNamesProp.getList().isEmpty()) {
        OperationResult fail = new OperationResult();
        fail.setErrorMessage("No jndi bindings given");
        return fail;
      }
      List<String> jndiNames = new ArrayList<String>();
      for (Property p : jndiNamesProp.getList()) {
        PropertySimple ps = (PropertySimple) p;
        jndiNames.add(ps.getStringValue());
      }

      operation = new Operation(op, theAddress);
      operation.addAdditionalProperty("entries", jndiNames);
      if (type.equals("jms-queue")) {
        PropertySimple ps = (PropertySimple) parameters.get("durable");
        if (ps != null) {
          boolean durable = ps.getBooleanValue();
          operation.addAdditionalProperty("durable", durable);
        }
        String selector = parameters.getSimpleValue("selector", "");
        if (!selector.isEmpty()) operation.addAdditionalProperty("selector", selector);
      }

    } else if (what.equals("managed-server")) {
      String chost = parameters.getSimpleValue("hostname", "");
      String serverName = parameters.getSimpleValue("servername", "");
      String serverGroup = parameters.getSimpleValue("server-group", "");
      String socketBindings = parameters.getSimpleValue("socket-bindings", "");
      String portS = parameters.getSimpleValue("port-offset", "0");
      int port = Integer.parseInt(portS);
      String autostartS = parameters.getSimpleValue("auto-start", "false");
      boolean autoStart = Boolean.getBoolean(autostartS);

      theAddress.add("host", chost);
      theAddress.add("server-config", serverName);
      Map<String, Object> props = new HashMap<String, Object>();
      props.put("name", serverName);
      props.put("group", serverGroup);
      props.put("socket-binding-group", socketBindings);
      props.put("socket-binding-port-offset", port);
      props.put("auto-start", autoStart);

      operation = new Operation(op, theAddress, props);
    } else if (what.equals("domain")) {
      operation = new Operation(op, new Address());
    } else if (what.equals("domain-deployment")) {
      if (op.equals("promote")) {
        String serverGroup = parameters.getSimpleValue("server-group", "-not set-");
        List<String> serverGroups = new ArrayList<String>();
        if (serverGroup.equals("__all")) {
          serverGroups.addAll(getServerGroups());
        } else {
          serverGroups.add(serverGroup);
        }
        String resourceKey = context.getResourceKey();
        resourceKey = resourceKey.substring(resourceKey.indexOf("=") + 1);

        log.info(
            "Promoting ["
                + resourceKey
                + "] to server group(s) ["
                + Arrays.asList(serverGroups)
                + "]");

        PropertySimple simple = parameters.getSimple("enabled");
        Boolean enabled = false;
        if (simple != null && simple.getBooleanValue() != null) enabled = simple.getBooleanValue();

        operation = new CompositeOperation();
        for (String theGroup : serverGroups) {
          theAddress = new Address();
          theAddress.add("server-group", theGroup);

          theAddress.add("deployment", resourceKey);
          Operation step = new Operation("add", theAddress);
          step.addAdditionalProperty("enabled", enabled);
          ((CompositeOperation) operation).addStep(step);
        }
      }
    } else if (what.equals("naming")) {
      if (op.equals("jndi-view")) {
        theAddress.add(address);
        operation = new Operation("jndi-view", theAddress);
      }
    }

    OperationResult operationResult = new OperationResult();
    if (operation != null) {
      Result result = connection.execute(operation);

      if (!result.isSuccess()) {
        operationResult.setErrorMessage(result.getFailureDescription());
      } else {
        String tmp;
        if (result.getResult() == null) tmp = "-none provided by the server-";
        else tmp = result.getResult().toString();
        operationResult.setSimpleResult(tmp);
      }
    } else {
      operationResult.setErrorMessage("No valid operation was given for input [" + name + "]");
    }
    return operationResult;
  }
  @Override
  protected AlertCriteria getFetchCriteria(DSRequest request) {
    AlertCriteria criteria = new AlertCriteria();

    // retrieve previous settings from portlet config
    if ((portlet != null) && (this.portlet instanceof DashboardPortlet)) {
      Configuration portletConfig = configuration;
      // filter priority, if null or empty then no priority filtering
      String currentSetting =
          portletConfig.getSimpleValue(Constant.ALERT_PRIORITY, Constant.ALERT_PRIORITY_DEFAULT);
      if (!currentSetting.trim().isEmpty()) {
        String[] parsedValues = currentSetting.trim().split(",");

        if (parsedValues.length < AlertPriority.values().length) {
          AlertPriority[] filterPriorities = new AlertPriority[parsedValues.length];
          int indx = 0;
          for (String priority : parsedValues) {
            AlertPriority p = AlertPriority.valueOf(priority);
            filterPriorities[indx++] = p;
          }
          criteria.addFilterPriorities(filterPriorities);
        }
      }

      PageControl pc = new PageControl();
      // result sort order
      currentSetting =
          portletConfig.getSimpleValue(
              Constant.RESULT_SORT_ORDER, Constant.RESULT_SORT_ORDER_DEFAULT);
      if (currentSetting.trim().isEmpty()) {
        pc.setPrimarySortOrder(PageOrdering.valueOf(Constant.RESULT_SORT_ORDER_DEFAULT));
      } else {
        pc.setPrimarySortOrder(PageOrdering.valueOf(currentSetting));
      }

      // result timeframe if enabled
      PropertySimple property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE);
      if (null != property && Boolean.valueOf(property.getBooleanValue())) { // then proceed setting

        boolean isAdvanced =
            Boolean.valueOf(
                portletConfig.getSimpleValue(
                    Constant.METRIC_RANGE_BEGIN_END_FLAG,
                    Constant.METRIC_RANGE_BEGIN_END_FLAG_DEFAULT));
        if (isAdvanced) {
          // Advanced time settings
          currentSetting =
              portletConfig.getSimpleValue(Constant.METRIC_RANGE, Constant.METRIC_RANGE_DEFAULT);
          String[] range = currentSetting.split(",");
          if (range.length == 2) {
            criteria.addFilterStartTime(Long.valueOf(range[0]));
            criteria.addFilterEndTime(Long.valueOf(range[1]));
          }
        } else {
          // Simple time settings
          property = portletConfig.getSimple(Constant.METRIC_RANGE_LASTN);
          if (property != null) {
            Integer lastN =
                Integer.valueOf(
                    portletConfig.getSimpleValue(
                        Constant.METRIC_RANGE_LASTN, Constant.METRIC_RANGE_LASTN_DEFAULT));
            Integer units =
                Integer.valueOf(
                    portletConfig.getSimpleValue(
                        Constant.METRIC_RANGE_UNIT, Constant.METRIC_RANGE_UNIT_DEFAULT));
            ArrayList<Long> beginEnd = MeasurementUtility.calculateTimeFrame(lastN, units);
            criteria.addFilterStartTime(Long.valueOf(beginEnd.get(0)));
            criteria.addFilterEndTime(Long.valueOf(beginEnd.get(1)));
          }
        }
      }

      // result count
      currentSetting =
          portletConfig.getSimpleValue(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT);
      if (currentSetting.trim().isEmpty()) {
        pc.setPageSize(Integer.valueOf(Constant.RESULT_COUNT_DEFAULT));
      } else {
        pc.setPageSize(Integer.valueOf(currentSetting));
      }

      criteria.setPageControl(pc);

      if (groupId != null) {
        criteria.addFilterResourceGroupIds(groupId);
      }
      if ((resourceIds != null) && (resourceIds.length > 0)) {
        criteria.addFilterResourceIds(resourceIds);
      }
    }
    criteria.fetchAlertDefinition(true);
    criteria.fetchRecoveryAlertDefinition(true);
    criteria.fetchConditionLogs(true);
    return criteria;
  }