Package org.rhq.core.domain.alert

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


         */
        log.debug("Exporting " + this.getNumConditions() + " conditions...");
        alertDef.removeAllConditions();
        for (int i = 0; i < this.getNumConditions(); ++i) {
            ConditionBean condBean = this.getCondition(i);
            AlertCondition newCondition = condBean.exportProperties(request, subject);
            alertDef.addCondition(newCondition);
        }

        /*
         * recovery
 
View Full Code Here


    }

    private void insertAlertConditionComposite(AbstractAlertConditionCategoryComposite composite,
        AlertConditionCacheStats stats) {

        AlertCondition alertCondition = composite.getCondition();
        int alertConditionId = alertCondition.getId(); // auto-unboxing is safe here because as the PK it's guaranteed to be non-null

        AlertConditionCategory alertConditionCategory = alertCondition.getCategory();
        AlertConditionOperator alertConditionOperator = AlertConditionCacheUtils
            .getAlertConditionOperator(alertCondition);

        if (alertConditionCategory == AlertConditionCategory.AVAILABILITY) {
            AlertConditionAvailabilityCategoryComposite availabilityComposite = (AlertConditionAvailabilityCategoryComposite) composite;

            try {
                AvailabilityCacheElement cacheElement = new AvailabilityCacheElement(alertConditionOperator,
                    availabilityComposite.getAvailabilityType(), alertConditionId);
                addTo("availabilityCache", availabilityCache, availabilityComposite.getResourceId(), cacheElement,
                    alertConditionId, stats);
            } catch (InvalidCacheElementException icee) {
                log.info("Failed to create AvailabilityCacheElement with parameters: "
                    + AlertConditionCacheUtils.getCacheElementErrorString(alertConditionId, alertConditionOperator,
                        availabilityComposite.getAvailabilityType(), AvailabilityType.UP, icee));
            }
        } else if (alertConditionCategory == AlertConditionCategory.AVAIL_DURATION) {
            AlertConditionAvailabilityCategoryComposite availabilityComposite = (AlertConditionAvailabilityCategoryComposite) composite;

            try {
                AvailabilityDurationCacheElement cacheElement = new AvailabilityDurationCacheElement(
                    availabilityComposite.getAlertDefinitionId(), alertConditionOperator, alertCondition.getOption(),
                    availabilityComposite.getAvailabilityType(), alertConditionId);
                addTo("availabilityDurationCache", availabilityDurationCache, availabilityComposite.getResourceId(),
                    cacheElement, alertConditionId, stats);
            } catch (InvalidCacheElementException icee) {
                log.info("Failed to create AvailabilityCacheElement with parameters: "
                    + AlertConditionCacheUtils.getCacheElementErrorString(alertConditionId, alertConditionOperator,
                        availabilityComposite.getAvailabilityType(), alertConditionOperator.toString(), icee));
            }
        } else if (alertConditionCategory == AlertConditionCategory.CONTROL) {
            AlertConditionControlCategoryComposite controlComposite = (AlertConditionControlCategoryComposite) composite;
            String option = alertCondition.getOption();
            OperationRequestStatus operationRequestStatus = OperationRequestStatus.valueOf(option.toUpperCase());

            try {
                ResourceOperationCacheElement cacheElement = new ResourceOperationCacheElement(alertConditionOperator,
                    operationRequestStatus, alertConditionId);
View Full Code Here

                }
            });

        AlertDefinition alertDef = new AlertDefinition();

        AlertCondition cond = new AlertCondition(alertDef, AlertConditionCategory.AVAILABILITY);
        cond.setName(AlertConditionOperator.AVAIL_GOES_UP.name());
        alertDef.setName("liveAvailabilityTestAlert");
        alertDef.setResource(newResource);
        alertDef.setPriority(AlertPriority.MEDIUM);
        alertDef.setRecoveryId(0);
        alertDef.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
View Full Code Here

            alertDefinition.setResourceType(resourceType);
        }

        Set<AlertCondition> conditions = new HashSet<AlertCondition>(adr.getConditions().size());
        for (AlertConditionRest acr : adr.getConditions()) {
            AlertCondition condition = conditionRestToCondition(acr, resource, resourceType);
            conditions.add(condition);
        }
        alertDefinition.setConditions(conditions);

        List<AlertNotification> notifications = new ArrayList<AlertNotification>(adr.getNotifications().size());
View Full Code Here

            }
        }

        AlertDefinition definition2;
        definition2 = entityManager.find(AlertDefinition.class,definitionId);
        AlertCondition condition=null;
        for (AlertCondition c: definition2.getConditions()) {
            if (c.getId() == conditionId) {
                condition=c;
            }
        }
View Full Code Here

        if (definition==null)
            throw new StuffNotFoundException("AlertDefinition with id " + definitionId);

        Resource resource = definition.getResource();
        ResourceType resourceType = definition.getResourceType();
        AlertCondition condition = conditionRestToCondition(conditionRest, resource, resourceType);

        definition.addCondition(condition);

        alertDefinitionManager.updateAlertDefinition(caller,definitionId,definition,false);
View Full Code Here

        catch (NoResultException nre) {
            throw new StuffNotFoundException("Condition with id " + conditionId);
        }

        AlertDefinition definition = entityManager.find(AlertDefinition.class,definitionId);
        AlertCondition condition=null;

        for (Iterator<AlertCondition> iterator = definition.getConditions().iterator(); iterator.hasNext(); ) {
            AlertCondition oldCondition = iterator.next();
            if (oldCondition.getId() == conditionId) {
                condition = new AlertCondition(oldCondition);
                oldCondition.setAlertDefinition(null);
                iterator.remove();
                entityManager.remove(oldCondition);
            }
        }

        Resource resource = definition.getResource();
        ResourceType resourceType = definition.getResourceType();
        AlertCondition restCondition = conditionRestToCondition(conditionRest, resource, resourceType);

        condition.setOption(conditionRest.getOption());
        condition.setComparator(conditionRest.getComparator());
        condition.setMeasurementDefinition(restCondition.getMeasurementDefinition());
        condition.setThreshold(conditionRest.getThreshold());
        condition.setTriggerId(conditionRest.getTriggerId());
        definition.getConditions().add(condition);

        alertDefinitionManager.updateAlertDefinitionInternal(caller, definitionId, definition, true, true, true);
View Full Code Here

    @ApiOperation("Retrieve a condition of an alert definition by its condition id")
    @ApiError(code = 404, reason = "No condition with the passed id exists")
    public Response getCondition(
        @ApiParam("The id of the condition to retrieve") @PathParam("cid") int conditionId) {

        AlertCondition condition = conditionMgr.getAlertConditionById(conditionId);
        if (condition==null) {
            throw new StuffNotFoundException("No condition with id " + conditionId);
        }
        AlertConditionRest acr = conditionToConditionRest(condition);
View Full Code Here

     * @return Converted domain object
     * @throws BadArgumentException If validation fails
     */
    private AlertCondition conditionRestToCondition(AlertConditionRest conditionRest, Resource resource,
                                                    ResourceType resourceType) {
        AlertCondition condition = new AlertCondition();

        try {
            condition.setCategory(AlertConditionCategory.valueOf(conditionRest.getCategory().toUpperCase()));
        } catch (Exception e) {
            String allowedValues = stringify(AlertConditionCategory.class);
            throw new BadArgumentException("Field 'category' [" + conditionRest.getCategory() + "] is invalid. Allowed values "+
                "are : " + allowedValues);
        }

        int measurementDefinition = conditionRest.getMeasurementDefinition();
        MeasurementDefinition md;
        if (measurementDefinition!=0) {
            md = entityManager.find(MeasurementDefinition.class, measurementDefinition);
            if (md==null) {
                throw new StuffNotFoundException("measurementDefinition with id " + measurementDefinition);
            }

            // Validate that the definition belongs to the resource, if passed
            if (resource!=null) {
                ResourceType type = resource.getResourceType();
                Set<MeasurementDefinition> definitions = type.getMetricDefinitions();
                if (!definitions.contains(md)) {
                    throw new BadArgumentException("MeasurementDefinition does not apply to resource");
                }
            }

            // Validate that the definition belongs to the passed resource type
            if (resourceType!=null) {
                Set<MeasurementDefinition> definitions = resourceType.getMetricDefinitions();
                if (!definitions.contains(md)) {
                    throw new BadArgumentException("MeasurementDefinition does not apply to resource type");
                }
            }
        }


        String optionValue = conditionRest.getOption();

        String conditionName = conditionRest.getName();
        // Set the name for all cases and allow it to be overridden later.
        condition.setName(conditionName);

        AlertConditionCategory category = condition.getCategory();
        switch (category) {
        case ALERT:
            // Looks internal -- noting to do.
            break;
        case AVAIL_DURATION:
            if (optionValue ==null) {
                throw new BadArgumentException("Option needs to be provided as duration in seconds");
            }
            try {
                Integer.parseInt(optionValue);
            } catch (NumberFormatException nfe) {
                throw new BadArgumentException("Option provided [" + optionValue + "] was bad. Must be duration in seconds");
            }
            checkForAllowedValues("name", conditionName, "AVAIL_DURATION_DOWN", "AVAIL_DURATION_NOT_UP");
            break;
        case AVAILABILITY:
            checkForAllowedValues("name", conditionName, "AVAIL_GOES_DOWN", "AVAIL_GOES_DISABLED",
                "AVAIL_GOES_UNKNOWN", "AVAIL_GOES_NOT_UP", "AVAIL_GOES_UP");
            break;
        case BASELINE:
            if (measurementDefinition ==0) {
                throw new BadArgumentException("You need to provide a measurementDefinition for category BASELINE");
            }

            md = entityManager.find(MeasurementDefinition.class,
                measurementDefinition);
            if (md==null) {
                throw new StuffNotFoundException("measurementDefinition with id " + measurementDefinition);
            }
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());
            checkForAllowedValues("option", optionValue, "min", "max", "mean");
            checkForAllowedValues("comparator", conditionRest.getComparator(), "<", "=", ">");
            break;
        case CHANGE:
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());
            if (md.getDataType()== DataType.CALLTIME) {
                checkForAllowedValues("option", optionValue, "MIN", "MAX", "AVG");
            }
            break;
        case CONTROL:
            checkForAllowedValues("option",optionValue,"INPROGRESS", "SUCCESS", "FAILURE", "CANCELED");

            if (conditionName ==null) {
                throw new BadArgumentException("name must be the name (not display name) of a valid operation.");
            }
            // TODO check for valid operation -- only on the resource or type itself (still hard enough)
            break;
        case DRIFT:
            // option and name are optional, so nothing to do
            break;
        case EVENT:
            checkForAllowedValues("name", conditionName,"DEBUG", "INFO", "WARN", "ERROR", "FATAL");
            // option is an optional regular expression
            break;
        case RANGE:
            checkForAllowedValues("comparator", conditionRest.getComparator(), "<", "=", ">","<=",">=");
            if (optionValue==null) {
                throw new BadArgumentException("You need to supply an upper threshold in 'option' as numeric value");
            }
            try {
                Double.parseDouble(optionValue);
            }
            catch (NumberFormatException nfe) {
                throw new BadArgumentException("You need to supply an upper threshold in 'option' as numeric value");
            }
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());

            break;
        case RESOURCE_CONFIG:
            // Nothing to do
            break;
        case THRESHOLD:
            checkForAllowedValues("comparator", conditionRest.getComparator(), "<", "=", ">");
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());

            if (md.getDataType()== DataType.CALLTIME) {
                checkForAllowedValues("option", optionValue, "MIN", "MAX", "AVG");
            }

            break;
        case TRAIT:
            md = getMeasurementDefinition(measurementDefinition, category);
            condition.setMeasurementDefinition(md);
            condition.setName(md.getDisplayName());

            // No need to check options - they are optional
            break;
        }

        condition.setOption(optionValue);
        condition.setComparator(conditionRest.getComparator());
        condition.setThreshold(conditionRest.getThreshold());
        condition.setTriggerId(conditionRest.getTriggerId());

        return condition;
    }
View Full Code Here

    private Response.ResponseBuilder getResponseBuilderForCondition(int definitionId, UriInfo uriInfo,
                                                                    AlertCondition originalCondition, boolean isCreate) {
        AlertDefinition updatedDefinition = alertDefinitionManager.getAlertDefinition(caller,definitionId);
        Set<AlertCondition> conditions = updatedDefinition.getConditions();
        int conditionId=-1;
        AlertCondition createdCondition = null;
        for (AlertCondition cond :conditions) {
            if (originalCondition.getId() == cond.getId() || (
                cond.getName() != null && cond.getName().equals(originalCondition.getName())))
            {
                conditionId = cond.getId();
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.alert.AlertCondition

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.