Package org.rhq.core.domain.measurement

Examples of org.rhq.core.domain.measurement.MeasurementDefinition


        //test methods passes null to the importer.configure() and succeeds.
        testNonMatchingMeasurementDefinitionsAreIgnored();
    }

    public void testDistinguishingBetweenNormalAndPerMinuteTemplates() {
        MeasurementDefinition normalDef = new MeasurementDefinition(FAKE_RESOURCE_TYPE, "def");
        MeasurementDefinition perMinuteDef = new MeasurementDefinition(FAKE_RESOURCE_TYPE, "def");
       
        normalDef.setId(1);
        normalDef.setDefaultOn(true);
        normalDef.setDefaultInterval(1000);
       
        perMinuteDef.setId(2);
        perMinuteDef.setDefaultOn(false);
        perMinuteDef.setDefaultInterval(2000);
        perMinuteDef.setRawNumericType(NumericType.TRENDSUP);
       
        final TestPrerequisities prereqs = new TestPrerequisities(context);
        prereqs.setMeasurementDefinitions(Arrays.asList(normalDef, perMinuteDef));
       
        context.checking(new Expectations() {
View Full Code Here


            break;
        default:
            period = MeasurementDefinition.AVAILABILITY_DEFAULT_PERIOD_SERVICE;
        }

        MeasurementDefinition rhqAvailability = new MeasurementDefinition(newType,
            MeasurementDefinition.AVAILABILITY_NAME);
        rhqAvailability.setDefaultInterval(period);
        rhqAvailability.setDefaultOn(true);
        rhqAvailability.setCategory(MeasurementCategory.AVAILABILITY);
        rhqAvailability.setDisplayName(MeasurementDefinition.AVAILABILITY_DISPLAY_NAME);
        rhqAvailability.setDescription(MeasurementDefinition.AVAILABILITY_DESCRIPTION);
        rhqAvailability.setDataType(DataType.AVAILABILITY);
        rhqAvailability.setUnits(MeasurementUnits.NONE); // n/a protects against non-null
        rhqAvailability.setNumericType(NumericType.DYNAMIC); // n/a protects against non-null
        rhqAvailability.setDisplayType(DisplayType.DETAIL); // n/a protects against non-null

        // Add the built in metric if it is not defined. Otherwise, override only allowed fields
        if (!result.contains(rhqAvailability)) {
            result.add(rhqAvailability);
        } else {
            MeasurementDefinition override = null;
            for (MeasurementDefinition aResult : result) {
                override = aResult;
                if (override.equals(rhqAvailability)) {
                    break;
                }
            }

            // don't let the override muck with fixed field values, only defaultOn and defaultInterval
            override.setCategory(MeasurementCategory.AVAILABILITY);
            override.setDisplayName(MeasurementDefinition.AVAILABILITY_DISPLAY_NAME);
            override.setDescription(MeasurementDefinition.AVAILABILITY_DESCRIPTION);
            override.setDataType(DataType.AVAILABILITY);
            override.setUnits(MeasurementUnits.NONE); // n/a protects against non-null
            override.setNumericType(NumericType.DYNAMIC); // n/a protects against non-null
            override.setDisplayType(DisplayType.DETAIL); // n/a protects against non-null                       
        }

        return result;
    }
View Full Code Here

        MetricDisplaySummary summary = new MetricDisplaySummary();
        summary.setScheduleId(schedule.getId());
        summary.setBeginTimeFrame(begin);
        summary.setEndTimeFrame(end);

        MeasurementDefinition definition = schedule.getDefinition();
        summary.setDefinitionId(definition.getId());
        summary.setMetricName(definition.getName());
        summary.setLabel(definition.getDisplayName());
        summary.setDescription(definition.getDescription());
        summary.setMetricSource(schedule.getResource().getName());
        summary.setMetricSourceId(schedule.getResource().getId());

        switch (definition.getDataType()) {
        case MEASUREMENT: {
            MeasurementUnits units = definition.getUnits();
            summary.setUnits(units.name());

            NumericType type = definition.getNumericType();
            if (type == null) {
                throw new IllegalStateException("NumericType is null, but no traits are expected here");
            }

            int collectionType;
            switch (type) {
            case DYNAMIC: {
                collectionType = 0;
                break;
            }

            case TRENDSUP: {
                collectionType = 2;
                break;
            }

            case TRENDSDOWN: {
                collectionType = 3;
                break;
            }

            default: {
                throw new IllegalStateException("Unknown measurement type: " + type);
            }
            }

            summary.setCollectionType(collectionType);

            if (!narrowed) {
                MeasurementAggregate compositeHighLow = dataManager.getMeasurementAggregate(subject, schedule.getId(),
                    begin, end);
                if (compositeHighLow.isEmpty()) {
                    summary.setValuesPresent(false);
                }

                Map<String, MetricDisplayValue> metricValues = new HashMap<String, MetricDisplayValue>();
                metricValues.put(MetricDisplayConstants.MIN_KEY, new MetricDisplayValue(compositeHighLow.getMin()));
                metricValues.put(MetricDisplayConstants.AVERAGE_KEY, new MetricDisplayValue(compositeHighLow.getAvg()));
                metricValues.put(MetricDisplayConstants.MAX_KEY, new MetricDisplayValue(compositeHighLow.getMax()));
                MeasurementDataNumeric currentNumeric = dataManager.getCurrentNumericForSchedule(schedule.getId());
                Double lastValue = (currentNumeric != null) ? currentNumeric.getValue() : Double.NaN;
                metricValues.put(MetricDisplayConstants.LAST_KEY, new MetricDisplayValue(lastValue));
                summary.setMetrics(metricValues);
            }

            break;
        }

        case TRAIT: {
            summary.setIsTrait(true);
            MeasurementDataTrait trait = dataManager.getCurrentTraitForSchedule(schedule.getId());
            if (trait != null) {
                summary.setValue(trait.getValue());
                summary.setTimestamp(trait.getTimestamp());
            } else {
                summary.setValue("- nothing found -");
                summary.setTimestamp(System.currentTimeMillis());
            }

            break;
        }

        case CALLTIME: {
            // TODO: ignore?
            break;
        }

        default: {
            throw new IllegalStateException("Unsupported metric data type: " + definition.getDataType());
        }
        }

        return summary;
    }
View Full Code Here

            summary.setDefinitionId(definitionId);
            summary.setBeginTimeFrame(begin);
            summary.setAlertCount(getAlertCountForContext(definitionId, context, begin, end));
            summary.setEndTimeFrame(end);

            MeasurementDefinition definition = entityManager.find(MeasurementDefinition.class, definitionId);
            summary.setDefinitionId(definition.getId());
            summary.setUnits(definition.getUnits().getName());
            summary.setDescription(definition.getDescription());
            summary.setMetricName(definition.getName());
            summary.setLabel(definition.getDisplayName());
            summary.setDescription(definition.getDescription());
            summary.setMetricSource(definition.getResourceType().getName());

            /*
             * Get the aggregate data from the backend and check if it is empty or not. If it is empty (for all members
             * of the group), skip over this metric.
             */
            MeasurementAggregate aggregate;
            if (totalScheduleCount == 0) {
                aggregate = new MeasurementAggregate(null, null, null);
                log.warn("No metric schedules found for def=[" + definition + "] and " + context
                    + ", using empty aggregate");
            } else {
                if (context.type == EntityContext.Type.ResourceGroup
                    && definition.getDataType() == DataType.MEASUREMENT) {
                    aggregate = dataManager.getAggregate(subject, context.getGroupId(), definitionId, begin, end);
                } else {
                    aggregate = dataUtil.getAggregateByDefinitionAndContext(begin, end, definitionId, context);
                }
            }
View Full Code Here

            List<MetricDisplaySummary> resourceMDS = getMetricDisplaySummariesForResource(subject, resource.getId(),
                schedIds, begin, end);
            for (MetricDisplaySummary summary : resourceMDS) {
                Integer definitionId = summary.getDefinitionId();
                MeasurementDefinition definition = measurementDefinitionsMap.get(definitionId);

                // This isn't a collecting metric, so move along
                if (definition == null) {
                    continue;
                }

                summary.setResource(resource);
                summary.setParent(resource.getParentResource());
                summary.setUnits(definition.getUnits().getName());
                summary.setDescription(definition.getDescription());
                summary.setMetricName(definition.getName());
                summary.setLabel(definition.getDisplayName());
                summary.setMetricSource(definition.getResourceType().getName());

                List<MetricDisplaySummary> metricsForDefinition = compareMetrics.get(definition);
                if (metricsForDefinition == null) {
                    metricsForDefinition = new ArrayList<MetricDisplaySummary>();
                    compareMetrics.put(definition, metricsForDefinition);
View Full Code Here

                cache = new HashMap<MetricTemplate, MeasurementDefinition>();
               
                Query q = entityManager.createQuery("SELECT md FROM MeasurementDefinition md");

                for (Object r : q.getResultList()) {
                    MeasurementDefinition md = (MeasurementDefinition) r;

                    cache.put(new MetricTemplate(md), md);
                }
               
            }
            @Override
            public MeasurementDefinition findMatch(MetricTemplate object) {
                MeasurementDefinition md = cache.get(object);
               
                if (md == null && LOG.isDebugEnabled()) {
                        LOG.debug("Failed to find a measurement definition corresponding to "
                            + object
                            + ". This means that the plugins in the source RHQ install were different than in this RHQ install "
View Full Code Here

    @EJB
    private SubjectManagerLocal subjectManager;

    public MeasurementDefinition getMeasurementDefinition(Subject subject, int definitionId) {
        // no authz check, this is basically interrogating a plugin, logged in auth should be enough
        MeasurementDefinition definition = entityManager.find(MeasurementDefinition.class, definitionId);
        return definition;
    }
View Full Code Here

            throw new PermissionException("User[" + subject.getName()
                + "] does not have permission to calculate measurement aggregate for group[id=" + groupId
                + "], definition[id=" + definitionId + "]");
        }

        MeasurementDefinition def = measurementDefinitionManager.getMeasurementDefinition(subject, definitionId);
        if (def.getDataType() != DataType.MEASUREMENT) {
            throw new IllegalArgumentException(def + " is not about numerical values. Can't compute aggregates");
        }

        if (startTime > endTime) {
            throw new IllegalArgumentException("Start date " + startTime + " is not before " + endTime);
View Full Code Here

        pretty = getShortPrettyAlertConditionString(condition);
        assert "Avail stays NOT UP [2m]".equals(pretty) : pretty;
    }

    public void testPrettyPrintTHRESHOLD() {
        MeasurementDefinition md = createDynamicMeasurementDefinition();
        AlertCondition condition = createCondition(AlertConditionCategory.THRESHOLD, md.getDisplayName(), ">", 12.5d,
            null, md);
        pretty = getPrettyAlertConditionString(condition);
        String ref = String.format("Foo Prop > %2.1fB", 12.5d);
        assert ref.equals(pretty) : pretty;
        pretty = getShortPrettyAlertConditionString(condition);
View Full Code Here

        pretty = getShortPrettyAlertConditionString(condition);
        assert ref.equals(pretty) : pretty;
    }

    public void testPrettyPrintTHRESHOLD_Calltime() {
        MeasurementDefinition md = createCalltimeMeasurementDefinition();
        String regex = "some.*(reg)?ex$"; // this is the "name" of the condition

        AlertCondition condition = createCondition(AlertConditionCategory.THRESHOLD, regex, ">", 12.5d, "MAX", md);
        pretty = getPrettyAlertConditionString(condition);
        check(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD_WITH_EXPR, "CT Prop", "MAX", ">", TWELVE_DOT_5_B,
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.measurement.MeasurementDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.