Search in sources :

Example 1 with ServiceLevelAgreementCheck

use of com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck in project kylo by Teradata.

the class ServiceLevelAgreementActionAlertResponderFactory method handleViolation.

/**
 * handle the violation.  Return true if the sla has actions configured in additional generating an alert.
 * @param alert the alert
 * @return true if additional actions were triggered, false if not
 */
private boolean handleViolation(Alert alert) {
    return metadataAccess.read(() -> {
        ServiceLevelAssessment.ID assessmentId = alert.getContent();
        ServiceLevelAssessment assessment = assessmentProvider.findServiceLevelAssessment(assessmentId);
        ServiceLevelAgreement agreement = assessment.getAgreement();
        assessmentProvider.ensureServiceLevelAgreementOnAssessment(assessment);
        agreement = assessment.getAgreement();
        boolean hasActions = false;
        if (agreement != null && agreement.getSlaChecks() != null && !agreement.getSlaChecks().isEmpty()) {
            for (ServiceLevelAgreementCheck check : agreement.getSlaChecks()) {
                for (ServiceLevelAgreementActionConfiguration configuration : ((JcrServiceLevelAgreementCheck) check).getActionConfigurations(true)) {
                    List<Class<? extends ServiceLevelAgreementAction>> responders = configuration.getActionClasses();
                    if (responders != null) {
                        // first check to see if there is a Spring Bean configured for this class type... if so call that
                        for (Class<? extends ServiceLevelAgreementAction> responderClass : responders) {
                            ServiceLevelAgreementAction action = ServiceLevelAgreementActionUtil.instantiate(responderClass);
                            if (action != null) {
                                hasActions = true;
                                log.info("Found {} action", action.getClass().getName());
                                // reassign the content of the alert to the ServiceLevelAssessment
                                // validate the action is ok
                                ServiceLevelAgreementActionValidation validation = ServiceLevelAgreementActionUtil.validateConfiguration(action);
                                if (validation.isValid()) {
                                    action.respond(configuration, assessment, alert);
                                } else {
                                    log.error("Unable to invoke SLA ImmutableAction {} while assessing {} due to Configuration error: {}.  Please fix.", action.getClass(), agreement.getName(), validation.getValidationMessage());
                                }
                            }
                        }
                    }
                }
            }
        }
        return hasActions;
    }, MetadataAccess.SERVICE);
}
Also used : ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) ServiceLevelAgreementAction(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementAction) JcrServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementCheck) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck) JcrServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementCheck) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) ServiceLevelAgreementActionValidation(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionValidation) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)

Aggregations

JcrServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementCheck)1 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)1 ServiceLevelAgreementAction (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementAction)1 ServiceLevelAgreementActionConfiguration (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)1 ServiceLevelAgreementActionValidation (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionValidation)1 ServiceLevelAssessment (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment)1 ServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck)1