Examples of AlertDefinition


Examples of org.rhq.core.domain.alert.AlertDefinition

        /*
         * Method for catching ENABLE / DISABLE changes will use switch logic off of the delta instead of calling out to
         * the enable/disable functions
         */
        AlertDefinition oldAlertDefinition = entityManager.find(AlertDefinition.class, alertDefinitionId);

        if (checkPerms && checkPermission(subject, oldAlertDefinition) == false) {
            if (oldAlertDefinition.getResourceType() != null) {
                throw new PermissionException("User [" + subject.getName()
                    + "] does not have permission to modify alert templates for type ["
                    + oldAlertDefinition.getResourceType() + "]");
            } else if (oldAlertDefinition.getGroup() != null) {
                throw new PermissionException("User [" + subject.getName()
                    + "] does not have permission to modify alert definitions for group ["
                    + oldAlertDefinition.getGroup() + "]");
            } else {
                throw new PermissionException("User [" + subject.getName()
                    + "] does not have permission to modify alert definitions for resource ["
                    + oldAlertDefinition.getResource() + "]");
            }
        }

        /*
         * only need to check the validity of the new alert definition if the authz checks pass *and* the old definition
         * is not currently deleted
         */
        boolean isResourceLevel = (oldAlertDefinition.getResource() != null);

        checkAlertDefinition(subject, oldAlertDefinition, alertDefinition, isResourceLevel ? oldAlertDefinition
            .getResource().getId() : null, finalizeNotifications);

        /*
         * Should not be able to update an alert definition if the old alert definition is in an invalid state
         */
        if (oldAlertDefinition.getDeleted()) {
            throw new AlertDefinitionUpdateException("Can not update deleted " + oldAlertDefinition.toSimpleString());
        }

        AlertDefinitionUpdateType updateType = AlertDefinitionUpdateType.get(oldAlertDefinition, alertDefinition);

        if (isResourceLevel
            && ((updateType == AlertDefinitionUpdateType.JUST_DISABLED) || (updateType == AlertDefinitionUpdateType.STILL_ENABLED))) {
            /*
             * if you were JUST_DISABLED or STILL_ENABLED, you are coming from the ENABLED state, which means you need
             * to be removed from the cache as the first half of this update
             */
            if (LOG.isDebugEnabled()) {
                LOG.debug("Updating AlertConditionCacheManager with AlertDefinition[ id=" + oldAlertDefinition.getId()
                    + " ]...DELETING");
                for (AlertCondition nextCondition : oldAlertDefinition.getConditions()) {
                    LOG.debug("OldAlertCondition[ id=" + nextCondition.getId() + " ]");
                }
            }
            notifyAlertConditionCacheManager(subject, "updateAlertDefinition", oldAlertDefinition,
                AlertDefinitionEvent.DELETED);
        }

        /*
         * performance optimization for the common case of single-condition alerts; it's easier for the
         * out-of-band process to check whether or not ANY conditions are true rather than ALL of them
         */
        if (alertDefinition.getConditions().size() == 1) {
            alertDefinition.setConditionExpression(BooleanExpression.ANY);
        }

        oldAlertDefinition.update(alertDefinition, resetMatching);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Updating: " + oldAlertDefinition);
            for (AlertCondition nextCondition : oldAlertDefinition.getConditions()) {
                LOG.debug("Condition: " + nextCondition);
            }
            for (AlertNotification nextNotification : oldAlertDefinition.getAlertNotifications()) {
                LOG.debug("Notification: " + nextNotification);
                LOG.debug("Notification-Configuration: " + nextNotification.getConfiguration().toString(true));
                if (nextNotification.getExtraConfiguration() != null) {
                    LOG.debug("Notification-Extra-Configuration: "
                        + nextNotification.getExtraConfiguration().toString(true));
                }
            }
        }

        fixRecoveryId(oldAlertDefinition);
        oldAlertDefinition.setMtime(System.currentTimeMillis());

        AlertDefinition newAlertDefinition = entityManager.merge(oldAlertDefinition);

        if (isResourceLevel
            && ((updateType == AlertDefinitionUpdateType.JUST_ENABLED) || (updateType == AlertDefinitionUpdateType.STILL_ENABLED))) {
            /*
             * if you were JUST_ENABLED or STILL_ENABLED, you are moving to the ENABLED state, which means you need to
             * be added to the cache as the last half of this update
             */

            boolean addToCache = false;
            // if this was a recovery alert, or was recently turned into one
            if (newAlertDefinition.getRecoveryId() != 0) {
                // only add to the cache if the to-be-recovered definition is disabled, and thus needs recovering
                AlertDefinition toBeRecoveredDefinition = getAlertDefinitionById(subject,
                    newAlertDefinition.getRecoveryId());
                if (toBeRecoveredDefinition.getEnabled() == false) {
                    addToCache = true;
                }
            } else {
                addToCache = true;
            }
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

        Query purgeQuery = entityManager.createNamedQuery(AlertDefinition.QUERY_FIND_UNUSED_DEFINITION_IDS);
        List<Integer> resultIds = purgeQuery.getResultList();

        int removed = 0;
        for (int unusedDefinitionId : resultIds) {
            AlertDefinition unusedDefinition = entityManager.find(AlertDefinition.class, unusedDefinitionId);
            if (unusedDefinition != null) {
                entityManager.remove(unusedDefinition);
                removed++;
            } else {
                LOG.warn("Could not find alertDefinition[id=" + unusedDefinitionId + "] for purge");
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

        } else if (conditionMessage instanceof InactiveAlertConditionMessage) {
            // first do some bookkeeping by removing partially matched condition logs
            alertConditionLogManager.removeUnmatchedLogByAlertConditionId(conditionMessage.getAlertConditionId());

            // then create a NEGATIVE dampening event, to breakup any contiguous POSITIVE events for correct processing
            AlertDefinition flyWeightDefinition = new AlertDefinition();
            flyWeightDefinition.setId(definitionId);
            AlertDampeningEvent event = new AlertDampeningEvent(flyWeightDefinition, AlertDampeningEvent.Type.NEGATIVE);
            entityManager.persist(event);

        } else {
            log.error("Unsupported message type sent to consumer for processing: "
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

     *
     * Note: for AlertNotification updates to work properly, alertDefinitionManager.getAlertDefinitionById() must
     *        eagerly load the List<AlertNotification> on the returned AlertDefinition
     */
    private AlertDefinition getDetachedAlertDefinition(int alertDefinitionId) {
        AlertDefinition alertDefinition = alertDefinitionManager.getAlertDefinitionById(subjectManager.getOverlord(),
            alertDefinitionId);
        return alertDefinition;
    }
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

        if (validSenders.contains(notification.getSenderName()) == false) {
            throw new AlertDefinitionUpdateException(notification.getSenderName()
                + " is not a valid alert sender, options are: " + validSenders);
        }

        AlertDefinition definition = getDetachedAlertDefinition(alertDefinitionId);
        List<AlertNotification> notifications = definition.getAlertNotifications();
        notifications.add(notification);

        postProcessAlertDefinition(user, definition);

        return notification;
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

    }

    @Deprecated
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public void updateAlertNotification(Subject subject, int alertDefinitionId, AlertNotification notification) {
        AlertDefinition alertDefinition = getDetachedAlertDefinition(alertDefinitionId); // permissions check first

        /*
         * NULL notifications used to perform cascade updates from template and group level for alert senders
         * that leverage custom UIs, which have a completely external methodology for loading/saving the data
         * into and out of configuration object(s) associated with an AlertNotification.
         */
        if (notification != null) {
            // remove then add is a cheap way of performing an update
            List<AlertNotification> notifications = alertDefinition.getAlertNotifications();
            notifications.remove(notification);
            notifications.add(notification);
        }

        postProcessAlertDefinition(subject, alertDefinition);
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

        try {
            boolean fire = false;

            // get the alert definition in preparation for lots of processing on it
            AlertDefinition alertDefinition = entityManager.find(AlertDefinition.class, alertDefinitionId);

            AlertDampening alertDampening = alertDefinition.getAlertDampening();
            AlertDampening.Category category = alertDampening.getCategory();

            if (log.isDebugEnabled()) {
                log.debug("Alert condition processing for " + alertDefinition);
                log.debug("Dampening rules are: " + alertDampening);
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

        }

        int modified = 0;
        List<Integer> allChildDefinitionIds = new ArrayList<Integer>();
        for (Integer groupAlertDefinitionId : groupAlertDefinitionIds) {
            AlertDefinition groupAlertDefinition = entityManager.find(AlertDefinition.class, groupAlertDefinitionId);
            if (null == groupAlertDefinition) {
                continue;
            }

            // remove the group def
            groupAlertDefinition.setDeleted(true);
            groupAlertDefinition.setGroup(null); // break bonds so corresponding ResourceGroup can be purged
            ++modified;

            // remove the child resource-level defs
            Subject overlord = subjectManager.getOverlord();
            List<Integer> childDefinitionIds = getChildrenAlertDefinitionIds(groupAlertDefinitionId);
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

    public int createGroupAlertDefinitions(Subject subject, AlertDefinition groupAlertDefinition,
        Integer resourceGroupId) throws InvalidAlertDefinitionException, AlertDefinitionCreationException {
        ResourceGroup group = resourceGroupManager.getResourceGroupById(subject, resourceGroupId, null);
        groupAlertDefinition.setGroup(group);

        AlertDefinition persistedDefinition = null;
        int groupAlertDefinitionId = 0;
        try {
            persistedDefinition = alertDefinitionManager.createAlertDefinitionInNewTransaction(subject,
                groupAlertDefinition, null, true);
            groupAlertDefinitionId = persistedDefinition.getId();
        } catch (Throwable t) {
            throw new AlertDefinitionCreationException("Could not create groupAlertDefinitions for " + group
                + " with data " + groupAlertDefinition.toSimpleString(), t);
        }

        Throwable firstThrowable = null;

        List<Integer> resourceIdsForGroup = getCommittedResourceIdsNeedingGroupAlertDefinitionApplication(subject,
            groupAlertDefinitionId, resourceGroupId);
        List<Integer> resourceIdsInError = new ArrayList<Integer>();
        for (Integer resourceId : resourceIdsForGroup) {
            try {
                // construct the child
                AlertDefinition childAlertDefinition = new AlertDefinition(persistedDefinition);
                childAlertDefinition.setGroupAlertDefinition(groupAlertDefinition);

                // persist the child
                alertDefinitionManager.createDependentAlertDefinition(subject, childAlertDefinition, resourceId);
            } catch (Throwable t) {
                // continue on error, create as many as possible
View Full Code Here

Examples of org.rhq.core.domain.alert.AlertDefinition

        }

        int modified = 0;

        for (Integer groupAlertDefinitionId : groupAlertDefinitionIds) {
            AlertDefinition groupAlertDefinition = entityManager.find(AlertDefinition.class, groupAlertDefinitionId);
            if (null == groupAlertDefinition || !groupAlertDefinition.getEnabled() || groupAlertDefinition.getDeleted()) {
                continue;
            }

            // enable the template
            groupAlertDefinition.setEnabled(false);
            ++modified;

            // enable the child resource-level defs
            List<Integer> childDefinitionIds = getChildrenAlertDefinitionIds(groupAlertDefinitionId);
            if (childDefinitionIds.isEmpty()) {
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.