Package org.rhq.core.domain.criteria

Examples of org.rhq.core.domain.criteria.MeasurementDefinitionCriteria


            SystemManagerLocal systemManager = LookupUtil.getSystemManager();
            MeasurementDefinitionManagerLocal measurementDefinitionManager = LookupUtil
                .getMeasurementDefinitionManager();

            SystemSettings beforeSystemSettings = systemManager.getUnmaskedSystemSettings(false);
            MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
            criteria.setPageControl(PageControl.getUnlimitedInstance());
            criteria.fetchResourceType(true);

            List<MeasurementDefinition> beforeMeasurementDefinitions = measurementDefinitionManager
                .findMeasurementDefinitionsByCriteria(freshUser(), criteria);

            synchronizationManager.importAllSubsystems(freshUser(), export.getExportFile(), null);
View Full Code Here


            assertEquals(settings.get(SystemSetting.BASE_URL), "http://testing.domain:7080");

            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()));
View Full Code Here

            String originalBaseUrl = settings.get(SystemSetting.BASE_URL);

            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();
View Full Code Here

    public void deleteMetadata(ResourceType existingType) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Deleting metric definitions for " + existingType);
        }

        MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
        criteria.addFilterResourceTypeId(existingType.getId());
        criteria.setRestriction(COLLECTION_ONLY);

        // Remove the type's metric definitions. We do this separately, rather than just relying on cascade
        // upon deletion of the ResourceType, because the removeMeasurementDefinition() will also take care
        // of removing any associated schedules and those schedules' OOBs.
        List<MeasurementDefinition> definitions = Collections.emptyList();
View Full Code Here

        this.measurementDefinitionManager = measurementDefinitionManager;
    }

    @Override
    public ExportingIterator<MetricTemplate> getExportingIterator() {
        MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
        criteria.setPageControl(PageControl.getUnlimitedInstance());
        criteria.fetchResourceType(true);
       
        List<MeasurementDefinition> defs = measurementDefinitionManager.findMeasurementDefinitionsByCriteria(subject,
            criteria);
       
        return new MetricTemplateIterator(defs.iterator());
View Full Code Here

        PageList<MeasurementDefinition> definitions;
        Map<Integer, Long> definitionIntervalMap = new HashMap<Integer, Long>();
        Map<Integer, Boolean> definitionEnabledMap = new HashMap<Integer, Boolean>();
        if (context.type == EntityContext.Type.ResourceTemplate) {
            MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
            criteria.addFilterResourceTypeId(context.resourceTypeId);

            CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria);
            CriteriaQueryRunner<MeasurementDefinition> queryRunner = new CriteriaQueryRunner(criteria, generator,
                entityManager);
            definitions = queryRunner.execute();
            for (MeasurementDefinition definition : definitions) {
                definitionIntervalMap.put(definition.getId(), definition.getDefaultInterval());
                definitionEnabledMap.put(definition.getId(), definition.isDefaultOn());
            }
        } else {
            // Do general criteria setup.
            MeasurementScheduleCriteria criteria = new MeasurementScheduleCriteria();

            switch (context.type) {
            case Resource:
                criteria.addFilterResourceId(context.resourceId);
                break;
            case ResourceGroup:
                criteria.addFilterResourceGroupId(context.groupId);
                break;
            case AutoGroup:
                criteria.addFilterAutoGroupParentResourceId(context.parentResourceId);
                criteria.addFilterAutoGroupResourceTypeId(context.resourceTypeId);
                break;
            }

            criteria.setPageControl(pc); // for primary return list, use passed PageControl
            pc.addDefaultOrderingField("definition.displayName");

            // Get the core definitions.
            CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria);

            // We previously used the following altered projection for the criteria query:
            //
            //   generator.alterProjection(" distinct measurementschedule.definition");
            //
            // Hibernate4 no longer allowed for the generated criteria JPQL for this projection:
            //
            //    SELECT distinct measurementschedule.definition
            //      FROM MeasurementSchedule measurementschedule
            // LEFT JOIN measurementschedule.definition orderingField0
            //     WHERE ( measurementschedule.resource.id IN ( :resourceId ) )
            //  ORDER BY orderingField0.displayName ASC
            //
            // It causes:
            //   SQLGrammarException: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
            //
            // In essence, using DISTINCT now requires that we use the LEFT JOIN alias in the select
            // list.  To support this we could probably have made some tricky coding changes to the
            // generator. But seeing that this would be to support non-default criteria queries (i.e
            // the altered projection using DISTINCT), of which this is the only one in the code base,
            // and we are in control of the order by clause, and therefore are predictably working with
            // the JPQL above, I've chosen to just make a change to the custom altered projection, using
            // the JPQL to guide me.
            generator.alterProjection(" distinct orderingField0");
            generator.alterCountProjection(" count(distinct orderingField0)");
            CriteriaQueryRunner<MeasurementDefinition> queryRunner = new CriteriaQueryRunner(criteria, generator,
                entityManager);
            definitions = queryRunner.execute();

            // Reset paging -- remove ordering, add group by.
            criteria.setPageControl(PageControl.getUnlimitedInstance());
            generator.setGroupByClause(" measurementschedule.definition.id ");

            // Get the interval results.
            generator.alterProjection("" //
                + " measurementschedule.definition.id, " //
                + " min(measurementschedule.interval), " //
                + " max(measurementschedule.interval) ");
            Query query = generator.getQuery(entityManager);
            List<Object[]> definitionIntervalResults = query.getResultList();

            // Get the enabled results.
            criteria.addFilterEnabled(true);
            generator.alterProjection(" measurementschedule.definition.id, count(measurementschedule.id) ");
            query = generator.getQuery(entityManager);
            List<Object[]> definitionEnabledResults = query.getResultList();

            // Generate intermediate maps for intervals and enabled values.
View Full Code Here

        // due to the conditional below which determines what kind of criteria to use, this datasource
        // doesn't rely on getFetchCriteria and the passed in criteria object. It is up to this method to
        // correctly prepare the criteria we build here (e.g. set the page control properly).
        if (request.getCriteria().getValues().containsKey("id")) {
            MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
            criteria.addFilterId(request.getCriteria().getAttributeAsInt("id"));
            criteria.setPageControl(getPageControl(request));

            GWTServiceLookup.getMeasurementDataService().findMeasurementDefinitionsByCriteria(criteria,
                new AsyncCallback<PageList<MeasurementDefinition>>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        CoreGUI.getErrorHandler().handleError(MSG.dataSource_definitions_loadFailed(), caught);
                    }

                    @Override
                    public void onSuccess(PageList<MeasurementDefinition> result) {
                        response.setData(buildRecords(result));
                        setPagingInfo(response, result);
                        processResponse(request.getRequestId(), response);
                    }
                });

        } else if (request.getCriteria().getValues().containsKey("resourceId")) {
            ResourceCriteria rCriteria = new ResourceCriteria();
            rCriteria.addFilterId(request.getCriteria().getAttributeAsInt("resourceId"));
            rCriteria.fetchResourceType(true);

            GWTServiceLookup.getResourceService().findResourcesByCriteria(rCriteria,
                new AsyncCallback<PageList<Resource>>() {
                    public void onFailure(Throwable caught) {
                        CoreGUI.getErrorHandler().handleError(MSG.dataSource_schedules_loadFailed(), caught);
                    }

                    public void onSuccess(PageList<Resource> result) {
                        MeasurementDefinitionCriteria mdCriteria = new MeasurementDefinitionCriteria();
                        mdCriteria.addFilterResourceTypeId(result.get(0).getResourceType().getId());
                        mdCriteria.addSortDisplayName(PageOrdering.ASC);

                        GWTServiceLookup.getMeasurementDataService().findMeasurementDefinitionsByCriteria(mdCriteria,
                            new AsyncCallback<PageList<MeasurementDefinition>>() {
                                @Override
                                public void onFailure(Throwable caught) {
                                    CoreGUI.getErrorHandler()
                                        .handleError(MSG.dataSource_schedules_loadFailed(), caught);
                                }

                                @Override
                                public void onSuccess(PageList<MeasurementDefinition> result) {
                                    response.setData(buildRecords(filter(result)));
                                    setPagingInfo(response, result);
                                    processResponse(request.getRequestId(), response);
                                }
                            });
                    }
                });

        } else if (request.getCriteria().getValues().containsKey("resourceGroupId")) {
            ResourceGroupCriteria rgCriteria = new ResourceGroupCriteria();
            rgCriteria.addFilterId(request.getCriteria().getAttributeAsInt("resourceGroupId"));
            rgCriteria.fetchResourceType(true);

            GWTServiceLookup.getResourceGroupService().findResourceGroupsByCriteria(rgCriteria,
                new AsyncCallback<PageList<ResourceGroup>>() {
                    public void onFailure(Throwable caught) {
                        CoreGUI.getErrorHandler().handleError(MSG.dataSource_schedules_loadFailed(), caught);
                    }

                    public void onSuccess(PageList<ResourceGroup> result) {
                        MeasurementDefinitionCriteria mdCriteria = new MeasurementDefinitionCriteria();
                        mdCriteria.addFilterResourceTypeId(result.get(0).getResourceType().getId());
                        mdCriteria.addSortDisplayName(PageOrdering.ASC);

                        GWTServiceLookup.getMeasurementDataService().findMeasurementDefinitionsByCriteria(mdCriteria,
                            new AsyncCallback<PageList<MeasurementDefinition>>() {
                                @Override
                                public void onFailure(Throwable caught) {
View Full Code Here

            this.children.add(proxyFactory.getResource(child.getId()));
        }
    }

    private void initMeasurements() {
        MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
        criteria.addFilterResourceTypeId(resource.getResourceType().getId());
        //      criteria.addFilterResourceTypeName(resource.getResourceType().getName());
        //      criteria.setStrict(true);

        this.measurementDefinitions = remoteClient.getProxy(MeasurementDefinitionManagerRemote.class)
            .findMeasurementDefinitionsByCriteria(remoteClient.getSubject(), criteria);
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.criteria.MeasurementDefinitionCriteria

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.