Examples of MeasurementDefinition


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

    public static final long MINIMUM_INTERVAL = MeasurementSchedule.MINIMUM_INTERVAL;

    public static List<MeasurementDefinition> parseMetricsMetadata(MetricDescriptor metricDescriptor,
        ResourceType resourceType) {
        MeasurementDefinition definition;

        DataType dataType = DataType.valueOf(metricDescriptor.getDataType().toUpperCase());
        DisplayType displayType = DisplayType.valueOf(metricDescriptor.getDisplayType().toUpperCase());

        long collectionInterval = MINUTE_30;
        MeasurementUnits units = getMeasurementUnits(metricDescriptor.getUnits(), dataType);

        switch (dataType) {
        case MEASUREMENT: {
            switch (resourceType.getCategory()) {
            case PLATFORM: {
                collectionInterval = MINUTE_10;
                break;
            }

            case SERVER: {
                collectionInterval = MINUTE_10;
                break;
            }

            case SERVICE: {
                collectionInterval = MINUTE_20;
                break;
            }
            }

            if (displayType != DisplayType.SUMMARY) {
                collectionInterval *= 2;
            }
            break;
        }

        case TRAIT: {
            collectionInterval = HOUR_24; // BZ 741331 no difference between summary and detail
            break;
        }

        case CALLTIME: {
            collectionInterval = MINUTE_10;
            if (units != MeasurementUnits.MILLISECONDS) {
                throw new IllegalStateException("Units must always be set to 'milliseconds' for call-time metrics.");
            }

            break;
        }

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

        collectionInterval = Math.max(MINIMUM_INTERVAL,
            (metricDescriptor.getDefaultInterval() == null) ? collectionInterval : metricDescriptor
                .getDefaultInterval().longValue());

        definition = new MeasurementDefinition(metricDescriptor.getProperty(),
            MeasurementCategory.valueOf(metricDescriptor.getCategory().toUpperCase()), getMeasurementUnits(
                metricDescriptor.getUnits(), dataType), dataType, NumericType.valueOf(metricDescriptor
                .getMeasurementType().toUpperCase()), metricDescriptor.isDefaultOn(), collectionInterval, displayType);

        if (metricDescriptor.getDisplayName() != null) {
            definition.setDisplayName(metricDescriptor.getDisplayName());
        } else {
            definition.setDisplayName(StringUtils.deCamelCase(definition.getName()));
        }
        if (metricDescriptor.getDescription() != null) {
            definition.setDescription(metricDescriptor.getDescription());
        } else {
            definition.setDescription(definition.getDisplayName());
        }

        definition.setDestinationType(metricDescriptor.getDestinationType());

        // Make sure that all summary properties are on by default.
        // It is assumed that if a plugin developer marks a metric as "summary" (which
        // shows the metric's graph within the graph page of the UI) then he doesn't want
        // to show an empty graph by default. Therefore, a summary metric will always be
        // enabled by default. You can't say a metric is a "summary" metric but with
        // defaultOn="false".  The defaultOn will be overridden here and will be set to true.
        if (definition.getDisplayType() == DisplayType.SUMMARY) {
            definition.setDefaultOn(true);
        }

        if ((definition.getNumericType() == NumericType.TRENDSUP)
            || (definition.getNumericType() == NumericType.TRENDSDOWN)) {
            ArrayList<MeasurementDefinition> definitions = new ArrayList<MeasurementDefinition>();
            MeasurementDefinition perMinuteMetric = new MeasurementDefinition(definition);

            // Disable the raw metric since that is usually what the user will want. Typically,
            // the user will only care about the per-minute metric.
            definition.setDisplayType(DisplayType.DETAIL);
            definition.setDefaultOn(false);

            perMinuteMetric.setDisplayName(perMinuteMetric.getDisplayName() + " per Minute");

            // This keeps track of whether the associated raw metric is TRENDUP or TRENDSDOWN.
            perMinuteMetric.setRawNumericType(definition.getNumericType());

            // The per-minute metric is no longer monotonically increasing/decreasing, but swinging within some band.
            perMinuteMetric.setNumericType(NumericType.DYNAMIC);

            definitions.add(definition);
            definitions.add(perMinuteMetric);
            return definitions;
        } else {
View Full Code Here

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

     * @return the report containing the collected data
     */
    @NotNull
    protected MeasurementReport collectMetric(Resource resource, String metricName) throws Exception {
        ResourceType resourceType = resource.getResourceType();
        MeasurementDefinition measurementDefinition = ResourceTypeUtility.getMeasurementDefinition(resourceType,
            metricName);
        assertNotNull(measurementDefinition, "No metric named [" + metricName + "] is defined for ResourceType {"
            + resourceType.getPlugin() + "}" + resourceType.getName() + ".");

        ResourceContainer resourceContainer = this.pluginContainer.getInventoryManager().getResourceContainer(resource);
        long timeoutMillis = 5000;
        if (resourceContainer.getResourceComponentState() != ResourceContainer.ResourceComponentState.STARTED) {
            throw new IllegalStateException("Resource component for " + resource + " has not yet been started.");
        }
        MeasurementFacet measurementFacet = resourceContainer.createResourceComponentProxy(MeasurementFacet.class,
            FacetLockType.READ, timeoutMillis, false, false, false);
        MeasurementReport report = new MeasurementReport();
        MeasurementScheduleRequest request = new MeasurementScheduleRequest(-1, metricName, -1, true,
            measurementDefinition.getDataType(), measurementDefinition.getRawNumericType());
        Set<MeasurementScheduleRequest> requests = new HashSet<MeasurementScheduleRequest>();
        requests.add(request);
        try {
            measurementFacet.getValues(report, requests);
        } catch (Exception e) {
View Full Code Here

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

            EntityManager em = getEntityManager();

            //add our new metric template that we are going to perform the tests with
            testData.fakeType = new ResourceType(RESOURCE_TYPE_NAME, PLUGIN_NAME, ResourceCategory.PLATFORM, null);

            MeasurementDefinition mdef = new MeasurementDefinition(METRIC_NAME, MeasurementCategory.PERFORMANCE,
                MeasurementUnits.NONE, DataType.MEASUREMENT, true, 600000, DisplayType.SUMMARY);
            testData.fakeType.addMetricDefinition(mdef);

            em.persist(testData.fakeType);
View Full Code Here

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

            MeasurementDefinitionManagerLocal measurementDefinitionManager = LookupUtil
                .getMeasurementDefinitionManager();
            MeasurementDefinitionCriteria crit = new MeasurementDefinitionCriteria();
            crit.addFilterResourceTypeName(RESOURCE_TYPE_NAME);
            crit.addFilterName(METRIC_NAME);
            MeasurementDefinition mdef = measurementDefinitionManager.findMeasurementDefinitionsByCriteria(freshUser(),
                crit).get(0);

            assertEquals("The " + METRIC_NAME + " metric should have been updated with default interval of 30s",
                Long.valueOf(30000), new Long(mdef.getDefaultInterval()));

            //ok, and now test that the platform resource schedule was updated as well

            //get the resource id first
            ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
            ResourceCriteria rcrit = new ResourceCriteria();
            rcrit.addFilterResourceTypeName(RESOURCE_TYPE_NAME);
            List<Resource> platforms = resourceManager.findResourcesByCriteria(freshUser(), rcrit);

            assertEquals("Unexpected number of platform resources found.", 1, platforms.size());

            int platformResourceId = platforms.get(0).getId();

            //now find the schedule for the measurement
            MeasurementScheduleManagerLocal measurementScheduleManager = LookupUtil.getMeasurementScheduleManager();
            List<MeasurementSchedule> schedules = measurementScheduleManager.findSchedulesByResourceIdAndDefinitionIds(
                freshUser(), platformResourceId, new int[] { mdef.getId() });

            assertEquals("Unexpected number of '" + METRIC_NAME + "' schedules found.", 1, schedules.size());

            assertEquals("The schedule should have been updated along with the definition during the config sync",
                30000, schedules.get(0).getInterval());
View Full Code Here

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

            MeasurementDefinitionManagerLocal measurementDefinitionManager = LookupUtil
                .getMeasurementDefinitionManager();
            MeasurementDefinitionCriteria crit = new MeasurementDefinitionCriteria();
            crit.addFilterResourceTypeName(RESOURCE_TYPE_NAME);
            crit.addFilterName(METRIC_NAME);
            MeasurementDefinition distroNameDef = measurementDefinitionManager.findMeasurementDefinitionsByCriteria(
                freshUser(), crit).get(0);

            long originalInterval = distroNameDef.getDefaultInterval();

            //now modify the default configuration in the export file
            String exportXML = getExportData();

            exportXML = updateSystemSettingsImportConfiguration(exportXML);
            exportXML = updateMetricTemplatesImportConfiguration(exportXML);

            InputStream exportData = createCompressedStream(exportXML);

            //let's just use the default configs so that we don't apply the changes suggested in
            //the changed default configs created above
            ImportConfiguration systemSettingsConfiguration = new ImportConfiguration(
                SystemSettingsSynchronizer.class.getName(), new SystemSettingsSynchronizer().getImporter()
                    .getImportConfigurationDefinition().getDefaultTemplate().createConfiguration());
            ImportConfiguration metricTemplatesConfiguration = new ImportConfiguration(
                MetricTemplateSynchronizer.class.getName(), new MetricTemplateSynchronizer().getImporter()
                    .getImportConfigurationDefinition().getDefaultTemplate().createConfiguration());

            try {
                synchronizationManager.importAllSubsystems(freshUser(), exportData,
                    Arrays.asList(systemSettingsConfiguration, metricTemplatesConfiguration));
            } finally {
                exportData.close();
            }

            //now check that we import using the manually create configurations, not the inlined ones
            settings = systemManager.getUnmaskedSystemSettings(false);

            assertEquals(settings.get(SystemSetting.BASE_URL), originalBaseUrl);

            measurementDefinitionManager = LookupUtil.getMeasurementDefinitionManager();
            distroNameDef = measurementDefinitionManager.findMeasurementDefinitionsByCriteria(freshUser(), crit).get(0);

            //the definition should have been updated by the data from the export file
            assertEquals("The " + METRIC_NAME + " metric shouldn't have changed its default interval", 30000,
                distroNameDef.getDefaultInterval());

            //ok, and now test that the platform resource schedule was NOT updated because it was configured not to.

            //get the resource id first
            ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
            ResourceCriteria rcrit = new ResourceCriteria();
            rcrit.addFilterResourceTypeName(RESOURCE_TYPE_NAME);
            List<Resource> platforms = resourceManager.findResourcesByCriteria(freshUser(), rcrit);

            assertEquals("Unexpected number of platform resources found.", 1, platforms.size());

            int platformResourceId = platforms.get(0).getId();

            //now find the schedule for the measurement
            MeasurementScheduleManagerLocal measurementScheduleManager = LookupUtil.getMeasurementScheduleManager();
            List<MeasurementSchedule> schedules = measurementScheduleManager.findSchedulesByResourceIdAndDefinitionIds(
                freshUser(), platformResourceId, new int[] { distroNameDef.getId() });

            assertEquals("Unexpected number of '" + METRIC_NAME + "' schedules found.", 1, schedules.size());

            assertEquals("The schedule should have been updated along with the definition during the config sync",
                originalInterval, schedules.get(0).getInterval());
View Full Code Here

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

                agent = new Agent(AGENT_NAME, "localhost", 9999, "", "randomToken");
                agent.setServer(server);
                em.persist(agent);

                dynamicMeasuremenDef = new MeasurementDefinition(resourceType, DYNAMIC_DEF_NAME);
                dynamicMeasuremenDef.setDefaultOn(true);
                dynamicMeasuremenDef.setDataType(MEASUREMENT);
                dynamicMeasuremenDef.setMeasurementType(DYNAMIC);

                em.persist(dynamicMeasuremenDef);
View Full Code Here

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

                em.persist(resource);
            }

            definitions = new ArrayList<MeasurementDefinition>();
            for (int i = 0; i < SIZE; i++) {
                MeasurementDefinition definition = new MeasurementDefinition(type, prefix + "definition " + i);
                definitions.add(definition);
                type.addMetricDefinition(definition);
                em.persist(definition);
            }
            type = em.merge(type);

            schedules = new ArrayList<MeasurementSchedule>();
            for (int i = 0; i < SIZE; i++) {
                for (int j = 0; j < SIZE; j++) {
                    MeasurementDefinition definition = definitions.get(i);
                    Resource resource = resources.get(j);
                    MeasurementSchedule schedule = new MeasurementSchedule(definition, resource);
                    schedules.add(schedule);
                    definition.addSchedule(schedule);
                    resource.addSchedule(schedule);
                    em.persist(schedule);
                }
            }
            for (int i = 0; i < SIZE; i++) {
                MeasurementDefinition definition = definitions.get(i);
                definitions.set(i, em.merge(definition));
            }
            for (int j = 0; j < SIZE; j++) {
                Resource resource = resources.get(j);
                resources.set(j, em.merge(resource));
View Full Code Here

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

            Set<ResourceType> nestedServices = service1.getChildResourceTypes();
            assert nestedServices.size() == 1 : "Expected 1 nested service of 'service1' in v1";
            Set<MeasurementDefinition> nestedDefs = nestedServices.iterator().next().getMetricDefinitions();
            // include the built-in AvailabilityType metric
            assert nestedDefs.size() == 2 : "Expected 2 definition within 'nestedService' in v1";
            MeasurementDefinition defThree = nestedDefs.iterator().next();
            int definitionId = defThree.getId(); // get the id of the definition "Three" and save it for later use
            getTransactionManager().rollback();

            System.out.println("testMoveResourceType -- done with the first plugin version");

            /*
             * The nested service got pulled out and put under platform
             */
            registerPlugin("update2-v2_0.xml");
            ResourceType platform2 = getResourceType("myPlatform");
            getTransactionManager().begin();

            platform2 = em.find(ResourceType.class, platform2.getId());

            assert platform2 != null : "I did not find myPlatform";
            Set<MeasurementDefinition> defs2 = platform2.getMetricDefinitions();
            // no built-in AvailabilityType metric for platforms           
            assert defs2.size() == 1 : "I was expecting 1 definition at platform level in v2";
            assert DisplayType.SUMMARY == defs2.iterator().next().getDisplayType() : "Display type should be SUMMARY in v2";

            ResourceCriteria resourceCriteria = new ResourceCriteria();
            resourceCriteria.setStrict(true);
            resourceCriteria.addFilterResourceKey("foo-myPlatform");
            resourceCriteria.fetchChildResources(true);
            Resource platform2Resource = getResource(resourceCriteria);
            assert platform2Resource != null : "Expected to find platform Resource in db.";

            // two children in v2
            Set<ResourceType> platformChildren2 = platform2.getChildResourceTypes();
            assert platformChildren2.size() == 2 : "Expected 2 direct child service types of platform in v2";

            Set<Resource> platform2ChildResources = platform2Resource.getChildResources();
            assert platform2ChildResources.size() == 2 : "Expected 2 direct child services of platform in v2";
            boolean foundMovedResource = false;
            for (Resource childResource : platform2ChildResources) {
                assert childResource.getChildResources().isEmpty() : "Expected child Resource " + childResource
                    + " to have no children";
                if (childResource.getResourceKey().equals("foo-nestedOne")) {
                    foundMovedResource = true;
                }
            }
            assert foundMovedResource : "Expected 'foo-nestedOne' Resource to have been moved directly under platform Resource";

            for (ResourceType type : platformChildren2) {
                String typeName = type.getName();
                // include the built-in AvailabilityType metric               
                assert type.getMetricDefinitions().size() == 2 : "Expected two definition for " + typeName + " in v2";
                if (typeName.equals("nestedOne")) // The moved one
                {
                    Set<MeasurementDefinition> defs3 = type.getMetricDefinitions();
                    MeasurementDefinition three = defs3.iterator().next();
                    assert three.getDisplayName().equals("Three") : "Expected the nestedOne to have a metric withDisplayName Three in v2, but it was "
                        + three.getDisplayName();
                    assert three.getDisplayType() == DisplayType.SUMMARY : "Expected three to be SUMMARY in v2";

                    /*
                     * TODO check here if the Definition is the one from above which got moved. this should be the case.
                     * Else we would loose all measurement schedules (and disassociate them from measurement data. But the
                     * latter is a different story. We probably should cascade that anyway.
                     */
                    assert three.getId() == definitionId : "Expected the id of 'Three' to be " + definitionId
                        + ", but it was " + three.getId() + " in v2";
                } else if (typeName.equals("service1")) {
                    // check that the nested service is gone
                    Set<ResourceType> childrenOfService = type.getChildResourceTypes();
                    assert childrenOfService.size() == 0 : "No children of 'service1' expected in v2, but found: "
                        + childrenOfService.size();
View Full Code Here

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

    private void assertVersion1(ResourceType resourceType) {
        PropertyGroupDefinition group;
        PropertyDefinition prop;
        ProcessScan processScan;
        OperationDefinition op;
        MeasurementDefinition metric;
        EventDefinition event;
        DriftDefinitionTemplate drift;
        BaseDirectory driftBasedir;
        ResourceTypeBundleConfiguration bundle;
        BundleDestinationBaseDirectory bundleBasedir;

        assert resourceType.getChildSubCategories() == null;

        assert resourceType.getPluginConfigurationDefinition().getGroupDefinitions().size() == 1;
        group = resourceType.getPluginConfigurationDefinition().getGroupDefinitions().get(0);
        assert group.getName().equals(PC_GROUP);
        assert group.isDefaultHidden() == PC_GROUP_HIDDEN;
        prop = resourceType.getPluginConfigurationDefinition().get(PC_PROP);
        assert prop != null;
        assert prop.getName().equals(PC_PROP);
        assert prop.isRequired() == PC_PROP_REQUIRED;
        assert prop.getPropertyGroupDefinition().getName().equals(PC_GROUP);

        assert resourceType.getProcessScans().size() == 1;
        processScan = resourceType.getProcessScans().iterator().next();
        assert processScan.getName().equals(PROCESS_SCAN_NAME);
        assert processScan.getQuery().equals(PROCESS_SCAN_QUERY);

        assert resourceType.getOperationDefinitions().size() == 1;
        op = resourceType.getOperationDefinitions().iterator().next();
        assert op.getName().equals(OP_NAME);
        assert op.getTimeout().intValue() == OP_TIMEOUT;
        assert op.getDescription().equals(OP_DESC);

        assert resourceType.getMetricDefinitions().size() == 2; // include built-in Availability metric
        metric = resourceType.getMetricDefinitions().iterator().next();
        assert metric.getName().equals(METRIC_PROP);
        assert metric.getDefaultInterval() == METRIC_DEFAULT_INTERVAL;

        assert resourceType.getEventDefinitions().size() == 1;
        event = resourceType.getEventDefinitions().iterator().next();
        assert event.getName().equals(EVENT_NAME);
        assert event.getDescription().equals(EVENT_DESC);
View Full Code Here

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

            "metricDefinitions", asList("metric1", "metric2", "metric3", "rhq.availability"));
    }

    @Test(groups = { "plugin.metadata", "Metrics.NewPlugin" }, dependsOnMethods = { "persistNewMetrics" })
    public void persistNewTraitDefinitionProperties() {
        MeasurementDefinition traitDef = loadMeasurementDef("metric1", "MetricServer1");

        MeasurementDefinition expected = new MeasurementDefinition("metric1", MeasurementCategory.AVAILABILITY,
            MeasurementUnits.MILLISECONDS, DataType.TRAIT, NumericType.DYNAMIC, true, 30000, DisplayType.SUMMARY);
        expected.setDescription("Metric 1");
        expected.setDisplayName("metric1");
        expected.setDisplayOrder(1);

        AssertUtils.assertPropertiesMatch("Failed to persist properties for a trait metric definition", expected,
            traitDef, asList("id", "resourceType", "schedules", "alertCondition"));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.