Exemple #1
0
  @SuppressWarnings("unchecked")
  private Collection<String> getServerGroups() {
    Operation op = new ReadChildrenNames(new Address(), "server-group");
    Result res = connection.execute(op);

    return (Collection<String>) res.getResult();
  }
Exemple #2
0
  /**
   * Gather measurement data
   *
   * @see
   *     org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport,
   *     java.util.Set)
   */
  public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics)
      throws Exception {

    for (MeasurementScheduleRequest req : metrics) {

      if (req.getName().startsWith(INTERNAL)) processPluginStats(req, report);
      else {
        // Metrics from the application server

        Operation op = new ReadAttribute(address, req.getName()); // TODO batching
        Result res = connection.execute(op, false);
        if (!res.isSuccess()) {
          log.warn(
              "Getting metric ["
                  + req.getName()
                  + "] at [ "
                  + address
                  + "] failed: "
                  + res.getFailureDescription());
          continue;
        }

        String val = (String) res.getResult();
        if (val
            == null) // One of the AS7 ways of telling "This is not implemented" See also AS7-1454
        continue;

        if (req.getDataType() == DataType.MEASUREMENT) {
          if (!val.equals("no metrics available")) { // AS 7 returns this
            try {
              Double d = Double.parseDouble(val);
              MeasurementDataNumeric data = new MeasurementDataNumeric(req, d);
              report.addData(data);
            } catch (NumberFormatException e) {
              log.warn("Non numeric input for [" + req.getName() + "] : [" + val + "]");
            }
          }
        } else if (req.getDataType() == DataType.TRAIT) {
          MeasurementDataTrait data = new MeasurementDataTrait(req, val);
          report.addData(data);
        }
      }
    }
  }
Exemple #3
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
  public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics)
      throws Exception {
    // we'll handling the rest of the metrics using the super method, but we may leave out some of
    // the requests
    // if we handle them here. Right now, just use the obtained set. We only create a copy of the
    // (unmodifiable) set
    // of requests if necessary.
    Set<MeasurementScheduleRequest> metricsToPassDown = metrics;

    for (MeasurementScheduleRequest request : metrics) {
      if (request.getDataType() == DataType.CALLTIME) {
        ensureGlobalEJB3StatisticsEnabled();
        // make a copy to pass down to super class if necessary
        if (metricsToPassDown == metrics) {
          metricsToPassDown = new HashSet<MeasurementScheduleRequest>(metrics);
        }

        metricsToPassDown.remove(request);

        // handle this ourselves
        // the name of the metric is actually the name of the stat collected for each method. we
        // then provide
        // the calltime data for each method.

        Result result = getASConnection().execute(new ReadAttribute(address, METHODS_ATTRIBUTE));
        Object value = result.getResult();
        if (value instanceof Map) {
          @SuppressWarnings("unchecked")
          Map<String, Map<String, Number>> allMethodStats =
              (Map<String, Map<String, Number>>) value;

          if (allMethodStats.isEmpty()) {
            continue;
          }

          // first we need to know since when the values were collected
          result =
              getASConnection()
                  .execute(new ReadAttribute(RUNTIME_MBEAN_ADDRESS, START_TIME_ATTRIBUTE));
          long serverStartTime = (Long) result.getResult();

          // now process the calltime value
          String requestedMetric = request.getName().substring(CALLTIME_METRIC_NAME_PREFIX_LENGTH);

          Stats lastCollection =
              getLastCallTimeCollection(requestedMetric, allMethodStats, serverStartTime);
          Stats thisCollection =
              Stats.fromMap(
                  allMethodStats, requestedMetric, System.currentTimeMillis(), serverStartTime);

          CallTimeData callTime = new CallTimeData(request);

          fillCallTimeData(callTime, thisCollection, lastCollection);

          saveCallTimeCollection(requestedMetric, thisCollection);

          report.addData(callTime);
        } else {
          OSGiVersion currentAsVersion = getASVersion();
          if (currentAsVersion == null) {
            getLog()
                .warn(
                    "Could not determine the AS version while reporting unexpected result of method"
                        + " stats. Request: "
                        + request);
          } else if (FIRST_VERSION_SUPPORTING_METHOD_STATS.compareTo(currentAsVersion) <= 0) {
            getLog()
                .error(
                    "Unexpected type of results when querying method stats for measurement request "
                        + request
                        + ". Expected map but got "
                        + (value == null ? "null" : value.getClass().getName()));
          }
        }
      }
    }

    super.getValues(report, metricsToPassDown);
  }