Package org.rhq.core.domain.measurement

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


            }
            Set<MeasurementDefinition> mDefs = rt.getMetricDefinitions();
            if (mDefs != null) {
                Iterator<MeasurementDefinition> mdIter = mDefs.iterator();
                while (mdIter.hasNext()) {
                    MeasurementDefinition def = mdIter.next();
                    em.remove(def);
                    mdIter.remove();
                }
            }
            em.remove(rt);
View Full Code Here


            EventDefinition ed = new EventDefinition(resourceType, "DataPurgeJobTestEventDefinition");
            em.persist(ed);
            resourceType.addEventDefinition(ed);

            // add calltime schedule
            MeasurementDefinition def = new MeasurementDefinition(resourceType, "DataPurgeJobTestCalltimeMeasDef");
            def.setCategory(MeasurementCategory.PERFORMANCE);
            def.setDataType(DataType.CALLTIME);
            def.setDefaultInterval(12345);
            def.setDefaultOn(true);
            def.setDestinationType("DataPurgeJobTestDestType");
            def.setDisplayName(def.getName());
            def.setDisplayType(DisplayType.SUMMARY);
            em.persist(def);
            MeasurementSchedule schedule = new MeasurementSchedule(def, resource);
            em.persist(schedule);
            def.addSchedule(schedule);
            resource.addSchedule(schedule);

            // add trait schedule
            def = new MeasurementDefinition(resourceType, "DataPurgeJobTestTraitMeasDef");
            def.setCategory(MeasurementCategory.PERFORMANCE);
            def.setDataType(DataType.TRAIT);
            def.setDefaultInterval(12345);
            def.setDefaultOn(true);
            def.setDisplayName(def.getName());
            def.setDisplayType(DisplayType.SUMMARY);
            em.persist(def);
            schedule = new MeasurementSchedule(def, resource);
            em.persist(schedule);
            def.addSchedule(schedule);
            resource.addSchedule(schedule);

            // add normal measurment schedule
            def = new MeasurementDefinition(resourceType, "DataPurgeJobTestNormalMeasDef");
            def.setCategory(MeasurementCategory.PERFORMANCE);
            def.setDataType(DataType.MEASUREMENT);
            def.setDefaultInterval(12345);
            def.setDefaultOn(true);
            def.setDisplayName(def.getName());
            def.setDisplayType(DisplayType.SUMMARY);
            em.persist(def);
            schedule = new MeasurementSchedule(def, resource);
            em.persist(schedule);
            def.addSchedule(schedule);
            resource.addSchedule(schedule);

        } catch (Exception e) {
            System.out.println("CANNOT PREPARE TEST: " + e);
            getTransactionManager().rollback();
View Full Code Here

                        if (!results.isEmpty()) {

                            //load the data results for the given metric definition
                            List<MeasurementDataNumericHighLowComposite> measurementList = results.get(0);

                            MeasurementDefinition measurementDefinition = null;
                            for (MeasurementDefinition definition : resource.getResourceType().getMetricDefinitions()) {
                                if (definition.getId() == definitionId) {
                                    measurementDefinition = definition;
                                    break;
                                }
View Full Code Here

            throw new BadArgumentException("Field 'category' [" + conditionRest.getCategory() + "] is invalid. Allowed values "+
                "are : " + allowedValues);
        }

        int measurementDefinition = conditionRest.getMeasurementDefinition();
        MeasurementDefinition md;
        if (measurementDefinition!=0) {
            md = entityManager.find(MeasurementDefinition.class, measurementDefinition);
            if (md==null) {
                throw new StuffNotFoundException("measurementDefinition with id " + measurementDefinition);
            }

            // Validate that the definition belongs to the resource, if passed
            if (resource!=null) {
                ResourceType type = resource.getResourceType();
                Set<MeasurementDefinition> definitions = type.getMetricDefinitions();
                if (!definitions.contains(md)) {
                    throw new BadArgumentException("MeasurementDefinition does not apply to resource");
                }
            }

            // Validate that the definition belongs to the passed resource type
            if (resourceType!=null) {
                Set<MeasurementDefinition> definitions = resourceType.getMetricDefinitions();
                if (!definitions.contains(md)) {
                    throw new BadArgumentException("MeasurementDefinition does not apply to resource type");
                }
            }
        }


        String optionValue = conditionRest.getOption();

        String conditionName = conditionRest.getName();
        // Set the name for all cases and allow it to be overridden later.
        condition.setName(conditionName);

        AlertConditionCategory category = condition.getCategory();
        switch (category) {
        case ALERT:
            // Looks internal -- noting to do.
            break;
        case AVAIL_DURATION:
            if (optionValue ==null) {
                throw new BadArgumentException("Option needs to be provided as duration in seconds");
            }
            try {
                Integer.parseInt(optionValue);
            } catch (NumberFormatException nfe) {
                throw new BadArgumentException("Option provided [" + optionValue + "] was bad. Must be duration in seconds");
            }
            checkForAllowedValues("name", conditionName, "AVAIL_DURATION_DOWN", "AVAIL_DURATION_NOT_UP");
            break;
        case AVAILABILITY:
            checkForAllowedValues("name", conditionName, "AVAIL_GOES_DOWN", "AVAIL_GOES_DISABLED",
                "AVAIL_GOES_UNKNOWN", "AVAIL_GOES_NOT_UP", "AVAIL_GOES_UP");
            break;
        case BASELINE:
            if (measurementDefinition ==0) {
                throw new BadArgumentException("You need to provide a measurementDefinition for category BASELINE");
            }

            md = entityManager.find(MeasurementDefinition.class,
                measurementDefinition);
            if (md==null) {
                throw new StuffNotFoundException("measurementDefinition with id " + measurementDefinition);
            }
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());
            checkForAllowedValues("option", optionValue, "min", "max", "mean");
            checkForAllowedValues("comparator", conditionRest.getComparator(), "<", "=", ">");
            break;
        case CHANGE:
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());
            if (md.getDataType()== DataType.CALLTIME) {
                checkForAllowedValues("option", optionValue, "MIN", "MAX", "AVG");
            }
            break;
        case CONTROL:
            checkForAllowedValues("option",optionValue,"INPROGRESS", "SUCCESS", "FAILURE", "CANCELED");

            if (conditionName ==null) {
                throw new BadArgumentException("name must be the name (not display name) of a valid operation.");
            }
            // TODO check for valid operation -- only on the resource or type itself (still hard enough)
            break;
        case DRIFT:
            // option and name are optional, so nothing to do
            break;
        case EVENT:
            checkForAllowedValues("name", conditionName,"DEBUG", "INFO", "WARN", "ERROR", "FATAL");
            // option is an optional regular expression
            break;
        case RANGE:
            checkForAllowedValues("comparator", conditionRest.getComparator(), "<", "=", ">","<=",">=");
            if (optionValue==null) {
                throw new BadArgumentException("You need to supply an upper threshold in 'option' as numeric value");
            }
            try {
                Double.parseDouble(optionValue);
            }
            catch (NumberFormatException nfe) {
                throw new BadArgumentException("You need to supply an upper threshold in 'option' as numeric value");
            }
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());

            break;
        case RESOURCE_CONFIG:
            // Nothing to do
            break;
        case THRESHOLD:
            checkForAllowedValues("comparator", conditionRest.getComparator(), "<", "=", ">");
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());

            if (md.getDataType()== DataType.CALLTIME) {
                checkForAllowedValues("option", optionValue, "MIN", "MAX", "AVG");
            }

            break;
        case TRAIT:
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());

            // No need to check options - they are optional
            break;
        }
View Full Code Here

        return condition;
    }

    private MeasurementDefinition getMeasurementDefinition(int measurementDefinition, AlertConditionCategory category) {
        MeasurementDefinition md;
        if (measurementDefinition ==0) {
            throw new BadArgumentException("You need to provide a measurementDefinition for category " + category.name());
        }
        md = entityManager.find(MeasurementDefinition.class,
            measurementDefinition);
View Full Code Here

                subject = new Subject(universalName, true, false);
                subject.addRole(role);

                resourceType = new ResourceTypeBuilder().createPlatformResourceType().withId(0).withName(universalName)
                    .withPlugin(universalName).build();
                MeasurementDefinition md = new MeasurementDefinition(universalName, MeasurementCategory.PERFORMANCE,
                    MeasurementUnits.PERCENTAGE, DataType.MEASUREMENT, false, 100000, DisplayType.DETAIL);
                resourceType.addMetricDefinition(md);

                resourceGroup = new ResourceGroup(universalName, resourceType);
View Full Code Here

                Role role = SessionTestHelper.createNewRoleForSubject(em, subject, roleName, Permission.MANAGE_ALERTS);
                newTestData.setRole(role);
                ResourceType resourceType = SessionTestHelper.createNewResourceType(em);

                // To test bug 949048 we need a metric on the type
                MeasurementDefinition dynamicMeasuremenDef = new MeasurementDefinition(resourceType, measurementDefName);
                dynamicMeasuremenDef.setDefaultOn(true);
                dynamicMeasuremenDef.setDataType(MEASUREMENT);
                dynamicMeasuremenDef.setMeasurementType(DYNAMIC);
                em.persist(dynamicMeasuremenDef);

                newTestData.setResourceType(resourceType);
                ResourceGroup resourceGroup = new ResourceGroup(groupName, resourceType);
                resourceGroup = resourceGroupManager.createPrivateResourceGroup(subject, resourceGroup);
View Full Code Here

                if (prop != null) {
                    MetaType type = prop.getMetaType();
                    MetaValue value = prop.getValue();

                    if (value != null) {
                        MeasurementDefinition measurementDefinition = ResourceTypeUtils.getMeasurementDefinition(
                            context.getResourceType(), metricName);

                        if (type.isSimple()) {
                            MeasurementAdapter measurementAdapter = new SimpleMetaValueMeasurementAdapter();
                            if (measurementDefinition != null & measurementAdapter != null)
View Full Code Here

        if (measurementDataList != null)
        {
            for (MeasurementData measurementData : measurementDataList)
            {
                MeasurementDefinition measurementDefinition = summaryMeasurementDefinitionMap.get(measurementData.getName());
                summaryMeasurementDisplayList.add(measurementUtils.createMeasurementDisplay(measurementData, measurementDefinition));
            }
        }

        List<MeasurementData> traitDataList = measurementUtils.loadMeasurementData(DisplayType.SUMMARY, DataType.TRAIT);
View Full Code Here

    public int compare(MeasurementData data1, MeasurementData data2)
    {
        if (measurementDefinitionMap != null)
        {
            MeasurementDefinition definition1 = measurementDefinitionMap.get(data1.getName());
            MeasurementDefinition definition2 = measurementDefinitionMap.get(data2.getName());

            if (definition1 != null && definition2 != null)
            {
                if (definition1.getDisplayOrder() > definition2.getDisplayOrder())
                {
                    return 1;
                }
                else if (definition1.getDisplayOrder() < definition2.getDisplayOrder())
                {
                    return -1;
                }

                return definition1.getDisplayName().compareTo(definition2.getDisplayName());
            }
        }
        // if trying to get display name fails in anyway, then we will sort by the
        // name of the metric
        return data1.getName().compareTo(data2.getName());
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.