Package org.rhq.core.domain.criteria

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


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

    public static void testAlertCriteria() {
        AlertCriteria alertCriteria = new AlertCriteria();
        alertCriteria.addFilterName("joe");
        alertCriteria.addFilterDescription("query generation is cool");
        alertCriteria.addFilterStartTime(42L);
        alertCriteria.addFilterEndTime(100L);
        alertCriteria.addFilterResourceIds(1, 2, 3);
        alertCriteria.fetchAlertDefinition(true);
        alertCriteria.addSortPriority(PageOrdering.DESC);
        alertCriteria.addSortName(PageOrdering.ASC);
        alertCriteria.setPaging(0, 100);
        alertCriteria.setFiltersOptional(true);
        //alertCriteria.setCaseSensitive(false);

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


            log.debug("Received request to generate report for " + caller);
        }
        return new StreamingOutput() {
            @Override
            public void write(OutputStream stream) throws IOException, WebApplicationException {
                final AlertCriteria criteria = new AlertCriteria();
                criteria.addSortCtime(PageOrdering.DESC);

                if(startTime != null){
                    criteria.addFilterStartTime(startTime);
                }
                if(endTime != null){
                    criteria.addFilterEndTime(endTime);
                }
                // lets default the end time for them to now if they didnt enter it
                if(startTime != null && endTime == null){
                    Date today = new Date();
                    criteria.addFilterEndTime(today.getTime());
                }

                criteria.addFilterPriorities(getAlertPriorities());

                CriteriaQueryExecutor<Alert, AlertCriteria> queryExecutor =
                        new CriteriaQueryExecutor<Alert, AlertCriteria>() {
                            @Override
                            public PageList<Alert> execute(AlertCriteria criteria) {
View Full Code Here

    @GET
    @Path(("/{id}/alerts"))
    @ApiError(code = 404, reason = NO_RESOURCE_FOR_ID)
    @ApiOperation("Get a list of links to the alerts for the passed resource")
    public List<Link> getAlertsForResource(@ApiParam("Id of the resource to query") @PathParam("id") int resourceId) {
        AlertCriteria criteria = new AlertCriteria();

        // Check for resource existence
        fetchResource(resourceId);

        criteria.addFilterResourceIds(resourceId);

        PageList<Alert> alerts = alertManager.findAlertsByCriteria(caller, criteria);
        List<Link> links = new ArrayList<Link>(alerts.size());
        for (Alert al : alerts) {
            Link link = new Link();
View Full Code Here

            public void execute() throws Exception {
                int resourceAlertDefinitionId = createResourceAlertDefinitionAndGetId("fake resource alertdef");
                alertManager.fireAlert(resourceAlertDefinitionId);

                // find the unacked alert
                AlertCriteria c = new AlertCriteria();
                c.addFilterAlertDefinitionIds(resourceAlertDefinitionId);
                c.addFilterUnacknowledgedOnly(Boolean.TRUE);
                List<Alert> result = alertManager.findAlertsByCriteria(testData.getSubject(), c);
                assertEquals(1, result.size());

                // fail to find any acked alert
                c.addFilterUnacknowledgedOnly(Boolean.FALSE);
                c.addFilterAcknowledgingSubject(""); // should match anything acknowledged
                result = alertManager.findAlertsByCriteria(testData.getSubject(), c);
                assertTrue(result.isEmpty());

                // ack the alert
                long testStartTimeStamp = System.currentTimeMillis();
                int count = alertManager.acknowledgeAlertsByContext(testData.getSubject(),
                    EntityContext.forResource(testData.getResource().getId()));
                assertEquals(1, count);

                // find any acked alert
                result = alertManager.findAlertsByCriteria(testData.getSubject(), c);
                assertEquals(1, result.size());
                Alert alert = result.get(0);
                em.refresh(alert);
                assertNotNull(alert.getAcknowledgingSubject());
                assertNotNull(alert.getAcknowledgeTime());
                assertEquals(testData.getSubject().getName(), alert.getAcknowledgingSubject());
                assertTrue("Alert should just have been acknowledged", alert.getAcknowledgeTime() >= testStartTimeStamp);

                // find the acked alert by subject
                c.addFilterAcknowledgingSubject(testData.getSubject().getName());
                c.setStrict(true);
                result = alertManager.findAlertsByCriteria(testData.getSubject(), c);
                assertEquals(1, result.size());
                alert = result.get(0);
                em.refresh(alert);
                assertNotNull(alert.getAcknowledgingSubject());
                assertNotNull(alert.getAcknowledgeTime());
                assertEquals(testData.getSubject().getName(), alert.getAcknowledgingSubject());
                assertTrue("Alert should just have been acknowledged", alert.getAcknowledgeTime() >= testStartTimeStamp);

                // fail to find the acked alert
                c.addFilterUnacknowledgedOnly(Boolean.TRUE);
                c.addFilterAcknowledgingSubject(null);
                result = alertManager.findAlertsByCriteria(testData.getSubject(), c);
                assertTrue(result.isEmpty());
            }
        });
    }
View Full Code Here

            }
        });
    }

    private PageList<Alert> findAlertsByDefinitionIds(Integer... alertDefinitionIds) {
        AlertCriteria criteria = new AlertCriteria();
        criteria.addFilterAlertDefinitionIds(alertDefinitionIds);
        return alertManager.findAlertsByCriteria(testData.getSubject(), criteria);
    }
View Full Code Here

            PageControl pageControl = new PageControl(0, alertPrefs.count);
            AlertManagerLocal alertManager = LookupUtil.getAlertManager();
            ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();

            AlertCriteria criteria = new AlertCriteria();
            criteria.addFilterPriorities(AlertPriority.getByLegacyIndex(alertPrefs.priority));
            criteria.addFilterStartTime(alertPrefs.timeRange);
            criteria.addFilterResourceIds(("all".equals(alertPrefs.displayAll) ? null : ArrayUtils
                .wrapInArray(alertPrefs.asArray())));
            criteria.setPageControl(pageControl);

            PageList<Alert> alerts = alertManager.findAlertsByCriteria(user.getSubject(), criteria);

            disambiguatedAlerts = DisambiguatedResourceListUtil.disambiguate(resourceManager, alerts,
                RESOURCE_ID_EXTRACTOR);
View Full Code Here

        Integer alertId = new Integer(request.getParameter("a"));
        log.trace("alertId=" + alertId);
        request.setAttribute("a", alertId);

        // properties
        AlertCriteria criteria = new AlertCriteria();
        criteria.addFilterId(alertId);
        List<Alert> results = alertManager.findAlertsByCriteria(subject, criteria);

        if (results.size() == 0) {
            throw new IllegalArgumentException("Alert with id " + alertId + " was not found");
        }
View Full Code Here

        Integer alertId = new Integer(request.getParameter("a"));

        Subject subject = RequestUtils.getSubject(request);

        AlertManagerLocal alertManager = LookupUtil.getAlertManager();
        AlertCriteria criteria = new AlertCriteria();
        criteria.addFilterId(alertId);
        List<Alert> results = alertManager.findAlertsByCriteria(subject, criteria);

        if (results.size() == 0) {
            request.setAttribute(AttrConstants.TITLE_PARAM2_ATTR, "! Alert not found !");
        } else {
View Full Code Here

            if (date != null) {
                beginTime = date.getTime();
                endTime = new Date(beginTime + MILLIS_IN_DAY).getTime();
            }

            AlertCriteria searchCriteria = new AlertCriteria();
            if (alertDefinitionId != null) {
                searchCriteria.addFilterGroupAlertDefinitionIds(alertDefinitionId);
            }

            // show alerts for any resource in the group, not just those attached to the group alert definitions
            List<Integer> resourceIds = resourceManager.findImplicitResourceIdsByResourceGroup(resourceGroupId);
            searchCriteria.addFilterResourceIds(resourceIds.toArray(new Integer[resourceIds.size()]));
            searchCriteria.addFilterPriorities(alertPriority);
            searchCriteria.addFilterStartTime(beginTime);
            searchCriteria.addFilterEndTime(endTime);
            searchCriteria.setPageControl(pc);
            searchCriteria.fetchAlertDefinition(true);
            // this is done by default at the object layer
            // searchCriteria.fetchConditionLogs(true);

            PageList<Alert> alerts = alertManager.findAlertsByCriteria(getSubject(), searchCriteria);
View Full Code Here

                beginTime = date.getTime();
                endTime = new Date(beginTime + MILLIS_IN_DAY).getTime();
            }
            Resource resource = getResource();

            AlertCriteria criteria = new AlertCriteria();
            criteria.addFilterResourceIds(resource.getId());
            criteria.addFilterAlertDefinitionIds(alertDefinitionId);
            criteria.addFilterPriorities(alertPriority);
            criteria.addFilterStartTime(beginTime);
            criteria.addFilterEndTime(endTime);
            criteria.setPageControl(pc);

            PageList<Alert> alerts = alertManager.findAlertsByCriteria(getSubject(), criteria);

            List<AlertWithLatestConditionLog> results = new ArrayList<AlertWithLatestConditionLog>(alerts.size());
View Full Code Here

TOP

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

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.