Package org.rhq.core.domain.criteria

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


            throw new IllegalArgumentException("Can not deploy using invalid resourceDeploymentId ["
                + resourceDeploymentId + "].");
        }
        BundleResourceDeployment resourceDeployment = resourceDeployments.get(0);

        ResourceCriteria rc = new ResourceCriteria();
        rc.addFilterId(resourceDeployment.getResource().getId());
        rc.fetchTags(true);
        Resource resource = resourceManager.findResourcesByCriteria(subject, rc).get(0);
        resourceDeployment.setResource(resource);

        // make sure the deployment contains the info required by the schedule service
        BundleDeploymentCriteria bdc = new BundleDeploymentCriteria();
View Full Code Here


            Pattern filterPattern = null;
            if (filter != null)
                filterPattern = Pattern.compile(filter);

            if (tt == PropertyOptionsSource.TargetType.RESOURCE || tt == PropertyOptionsSource.TargetType.CONFIGURATION) {
                ResourceCriteria criteria = new ResourceCriteria();

                //Use CriteriaQuery to automatically chunk/page through criteria query results
                CriteriaQueryExecutor<Resource, ResourceCriteria> queryExecutor = new CriteriaQueryExecutor<Resource, ResourceCriteria>() {
                    @Override
                    public PageList<Resource> execute(ResourceCriteria criteria) {
                        return resourceManager.findResourcesByCriteria(subject, criteria);
                    }
                };

                Iterable<Resource> foundResources = null;
                if (tt == PropertyOptionsSource.TargetType.CONFIGURATION) {
                    // split out expression part for target=configuration
                    // return if no property specifier is given
                    String expr = expression;
                    if (expr.contains(":")) {
                        expr = expr.substring(expr.indexOf(':') + 1);

                        if (!"self".equals(expr)) {
                            criteria.setSearchExpression(expr);
                            foundResources = new CriteriaQuery<Resource, ResourceCriteria>(criteria, queryExecutor);
                            if (expressionScope == PropertyOptionsSource.ExpressionScope.BASE_RESOURCE
                                && baseResource != null) {
                                foundResources = Iterables.filter(foundResources, new IsInBaseResourcePredicate(
                                    baseResource));
                            }
                        } else if (resource != null) {
                            ArrayList<Resource> resourceList = new ArrayList<Resource>();
                            resourceList.add(resource);
                            foundResources = resourceList;
                        } else {
                            LOG.warn("Self reference requested but resource id is not valid."
                                + "Option source expression:" + expression);
                            return;
                        }
                    } else {
                        LOG.warn("Option source expression for property " + pds.getName()
                            + " and target configuration contains no ':'");
                        return;
                    }
                } else {
                    criteria.setSearchExpression(expression);
                    foundResources = new CriteriaQuery<Resource, ResourceCriteria>(criteria, queryExecutor);
                    if (expressionScope == PropertyOptionsSource.ExpressionScope.BASE_RESOURCE && baseResource != null) {
                        foundResources = Iterables.filter(foundResources, new IsInBaseResourcePredicate(baseResource));
                    }
                }
View Full Code Here

        return newValue != null && (oldValue == null || !newValue.equals(oldValue));
    }

    private void abortResourceManualAddIfExistingSingleton(Resource parentResource, ResourceType resourceType) {
        if (resourceType.isSingleton()) {
            ResourceCriteria resourceCriteria = new ResourceCriteria();
            resourceCriteria.addFilterParentResourceId(parentResource.getId());
            resourceCriteria.addFilterResourceTypeId(resourceType.getId());
            resourceCriteria.clearPaging();//Doc: disable paging as the code assumes all the results will be returned.

            PageList<Resource> childResourcesOfType = resourceManager.findResourcesByCriteria(
                subjectManager.getOverlord(), resourceCriteria);
            if (childResourcesOfType.size() >= 1) {
                throw new RuntimeException("Cannot manually add " + resourceType + " child Resource under parent "
View Full Code Here

    private Map<String,String> getStats(Subject caller) {

        Map<String,String> result = new HashMap<String, String>();

        ResourceCriteria criteria = new ResourceCriteria();
        criteria.addFilterResourceCategories(ResourceCategory.PLATFORM);
        criteria.setRestriction(Criteria.Restriction.COUNT_ONLY);
        PageList<Resource> resList = resourceManager.findResourcesByCriteria(caller,criteria);
        result.put("PlatformCount",String.valueOf(resList.getTotalSize()));
        criteria = new ResourceCriteria();
        criteria.addFilterResourceCategories(ResourceCategory.SERVER);
        criteria.setRestriction(Criteria.Restriction.COUNT_ONLY);
        resList = resourceManager.findResourcesByCriteria(caller,criteria);
        result.put("ServerCount",String.valueOf(resList.getTotalSize()));
        criteria = new ResourceCriteria();
        criteria.addFilterResourceCategories(ResourceCategory.SERVICE);
        criteria.setRestriction(Criteria.Restriction.COUNT_ONLY);
        resList = resourceManager.findResourcesByCriteria(caller,criteria);
        result.put("ServiceCount",String.valueOf(resList.getTotalSize()));

        AlertCriteria alertCriteria = new AlertCriteria();
        alertCriteria.setRestriction(Criteria.Restriction.COUNT_ONLY);
View Full Code Here

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void updateResourcePluginConfigurationsInNewTransaction(List<Integer> resourceIds,
        ConfigurationDefinitionUpdateReport updateReport) {

        ResourceCriteria criteria = new ResourceCriteria();
        criteria.addFilterIds(resourceIds.toArray(new Integer[resourceIds.size()]));
        criteria.setPageControl(PageControl.getUnlimitedInstance());
        List<Resource> resources = resourceMgr.findResourcesByCriteria(subjectMgr.getOverlord(), criteria);

        for (Resource resource : resources) {
            boolean modified = false;
            ConfigurationTemplate template = updateReport.getConfigurationDefinition().getDefaultTemplate();
View Full Code Here

        Map<Integer, Set<Integer>> platformMetricDefs = new HashMap<Integer, Set<Integer>>();
        for (ResourceType resourceType : resourceTypes) {
            platformMetricDefs.put(resourceType.getId(), getPlatformMetricDefIds(resourceType));
        }

        final ResourceCriteria resourceCriteria = new ResourceCriteria();
        resourceCriteria.addFilterResourceCategories(PLATFORM);
        resourceCriteria.addFilterInventoryStatus(COMMITTED);
        resourceCriteria.fetchCurrentAvailability(true);

        //Use CriteriaQuery to automatically chunk/page through criteria query results
        CriteriaQueryExecutor<Resource, ResourceCriteria> resourceQueryExecutor = new CriteriaQueryExecutor<Resource, ResourceCriteria>() {
            @Override
            public PageList<Resource> execute(ResourceCriteria criteria) {
View Full Code Here

    }

    private void moveResourcesToNewParent(ResourceType existingType, ResourceType obsoleteParentType,
        Set<ResourceType> newParentTypes) {
        final Subject overlord = subjectManager.getOverlord();
        ResourceCriteria criteria = new ResourceCriteria();
        criteria.addFilterResourceTypeId(existingType.getId());
        criteria.addFilterParentResourceTypeId(obsoleteParentType.getId());

        //Use CriteriaQuery to automatically chunk/page through criteria query results
        CriteriaQueryExecutor<Resource, ResourceCriteria> queryExecutor = new CriteriaQueryExecutor<Resource, ResourceCriteria>() {
            @Override
            public PageList<Resource> execute(ResourceCriteria criteria) {
View Full Code Here

        }
    }

    private void abortResourceCreationIfExistingSingleton(Resource parentResource, ResourceType resourceType) {
        if (resourceType.isSingleton()) {
            ResourceCriteria resourceCriteria = new ResourceCriteria();
            resourceCriteria.addFilterParentResourceId(parentResource.getId());
            resourceCriteria.addFilterResourceTypeId(resourceType.getId());
            resourceCriteria.clearPaging();//disable paging as the code assumes all the results will be returned.

            PageList<Resource> childResourcesOfType = resourceManager.findResourcesByCriteria(
                subjectManager.getOverlord(), resourceCriteria);
            if (childResourcesOfType.size() >= 1) {
                throw new RuntimeException("Cannot create " + resourceType + " child Resource under parent "
View Full Code Here

        System.out.println(generator.getQueryString(false));
        System.out.println(generator.getQueryString(true));
    }

    public static void testResourceCriteria() {
        ResourceCriteria resourceCriteria = new ResourceCriteria();
        resourceCriteria.addFilterResourceCategories(ResourceCategory.SERVER);
        resourceCriteria.addFilterName("marques");
        resourceCriteria.fetchAgent(true);
        resourceCriteria.addSortResourceTypeName(PageOrdering.ASC);
        resourceCriteria.setCaseSensitive(true);
        resourceCriteria.setFiltersOptional(true);

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();
        CriteriaQueryGenerator generator = new CriteriaQueryGenerator(overlord, resourceCriteria);
        System.out.println(generator.getQueryString(false));
        System.out.println(generator.getQueryString(true));
View Full Code Here

     *
     * @param context the entity context
     * @param agentId the agent id
     */
    private void markResources(EntityContext context, int agentId) {
        ResourceCriteria criteria = new ResourceCriteria();
        criteria.clearPaging(); //important to avoid setting the ordering in the generated query
        if (context.type == EntityContext.Type.Resource) {
            criteria.addFilterId(context.resourceId);
        } else if (context.type == EntityContext.Type.ResourceGroup) {
            criteria.addFilterImplicitGroupIds(context.groupId);
        } else if (context.type == EntityContext.Type.AutoGroup) {
            criteria.addFilterParentResourceId(context.parentResourceId);
            criteria.addFilterResourceTypeId(context.resourceTypeId);
        }
        criteria.addFilterAgentId(agentId);

        try {
            CriteriaQueryGenerator generator = new CriteriaQueryGenerator(criteria);

            generator.alterProjection("resource.id");
View Full Code Here

TOP

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

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.