Search in sources :

Example 11 with ServiceLevelAssessment

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment in project kylo by Teradata.

the class FeedPreconditionService method checkPrecondition.

private void checkPrecondition(Feed feed, OperationStatus operationStatus) {
    FeedPrecondition precond = feed.getPrecondition();
    if (precond != null) {
        log.debug("Checking precondition of feed: {} ({})", feed.getName(), feed.getId());
        ServiceLevelAgreement sla = precond.getAgreement();
        boolean isAssess = sla.getAllMetrics().stream().anyMatch(metric -> isMetricDependentOnStatus(metric, operationStatus));
        if (isAssess) {
            ServiceLevelAssessment assessment = this.assessor.assess(sla);
            if (assessment.getResult() == AssessmentResult.SUCCESS) {
                log.info("Firing precondition trigger event for feed:{} ({})", feed.getName(), feed.getId());
                this.eventService.notify(new PreconditionTriggerEvent(feed.getId()));
            }
        } else {
            log.debug("Feed {}.{} does not depend on feed {}", feed.getCategory(), feed.getName(), operationStatus.getFeedName());
        }
    }
}
Also used : ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) PreconditionTriggerEvent(com.thinkbiganalytics.metadata.api.event.feed.PreconditionTriggerEvent) FeedPrecondition(com.thinkbiganalytics.metadata.api.feed.FeedPrecondition) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)

Example 12 with ServiceLevelAssessment

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment 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)

Example 13 with ServiceLevelAssessment

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment in project kylo by Teradata.

the class JpaServiceLevelAssessor method assess.

/**
 * Assess the SLA (coming from JCR)
 *
 * @param sla the SLA to be assessed
 */
public ServiceLevelAssessment assess(ServiceLevelAgreement sla) {
    log.info("Assessing SLA: {}", sla.getName());
    ServiceLevelAssessment assessment = null;
    ServiceLevelAgreement serviceLevelAgreement = sla;
    assessment = this.metadataAccess.commit(() -> {
        AssessmentResult combinedResult = AssessmentResult.SUCCESS;
        try {
            // create the new Assessment
            JpaServiceLevelAssessment slaAssessment = new JpaServiceLevelAssessment();
            slaAssessment.setId(JpaServiceLevelAssessment.SlaAssessmentId.create());
            slaAssessment.setAgreement(serviceLevelAgreement);
            List<ObligationGroup> groups = sla.getObligationGroups();
            for (ObligationGroup group : groups) {
                Condition condition = group.getCondition();
                AssessmentResult groupResult = AssessmentResult.SUCCESS;
                Set<ObligationAssessment> obligationAssessments = new HashSet<>();
                log.debug("Assessing obligation group {} with {} obligations", group, group.getObligations().size());
                for (Obligation ob : group.getObligations()) {
                    ObligationAssessment obAssessment = assess(ob, slaAssessment);
                    obligationAssessments.add(obAssessment);
                    // slaAssessment.add(obAssessment);
                    groupResult = groupResult.max(obAssessment.getResult());
                }
                slaAssessment.setObligationAssessments(obligationAssessments);
                // Short-circuit required or sufficient if necessary.
                switch(condition) {
                    case REQUIRED:
                        if (groupResult == AssessmentResult.FAILURE) {
                            return completeAssessment(slaAssessment, groupResult);
                        }
                        break;
                    case SUFFICIENT:
                        if (groupResult != AssessmentResult.FAILURE) {
                            return completeAssessment(slaAssessment, groupResult);
                        }
                        break;
                    default:
                }
                // Required condition but non-failure, sufficient condition but non-success, or optional condition:
                // continue assessing groups and retain the best of the group results.
                combinedResult = combinedResult.max(groupResult);
            }
            return completeAssessment(slaAssessment, combinedResult);
        } finally {
            log.debug("Completed assessment of SLA {}: {}", sla.getName(), combinedResult);
        }
    }, MetadataAccess.SERVICE);
    return assessment;
}
Also used : ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) Condition(com.thinkbiganalytics.metadata.sla.api.ObligationGroup.Condition) HashSet(java.util.HashSet) Set(java.util.Set) ObligationAssessment(com.thinkbiganalytics.metadata.sla.api.ObligationAssessment) Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) ArrayList(java.util.ArrayList) List(java.util.List) AssessmentResult(com.thinkbiganalytics.metadata.sla.api.AssessmentResult) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup)

Example 14 with ServiceLevelAssessment

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment in project kylo by Teradata.

the class SimpleServiceLevelAssessmentCompareTest method testCompareEqualObligationComparables.

@Test
public void testCompareEqualObligationComparables() {
    this.assessor.registerMetricAssessor(new TestMetricAssessor(1, "1"));
    this.assessor.registerObligationAssessor(new TestObligatinAssessor("test"));
    ServiceLevelAgreement sla = this.provider.builder().name("test").obligationBuilder().description("test").metric(new TestMetric(1, "1")).build().build();
    ServiceLevelAssessment assmt1 = this.assessor.assess(sla);
    ServiceLevelAssessment assmt2 = this.assessor.assess(sla);
    assertThat(assmt1).isEqualByComparingTo(assmt2);
}
Also used : ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) Test(org.junit.Test)

Example 15 with ServiceLevelAssessment

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment in project kylo by Teradata.

the class SimpleServiceLevelAssessorTest method testAssessMetricWaring.

@Test
public void testAssessMetricWaring() {
    this.assessor.registerMetricAssessor(new TestMetricAssessor(0, "fail", AssessmentResult.WARNING));
    ServiceLevelAgreement sla = this.provider.builder().name("test").obligationBuilder().description("test").metric(new TestMetric(1, "1")).build().build();
    ServiceLevelAssessment assessment = this.assessor.assess(sla);
    assertThat(assessment.getResult()).isEqualTo(AssessmentResult.WARNING);
    assertThat(assessment.getObligationAssessments()).hasSize(1).extracting("result").contains(AssessmentResult.WARNING);
    assertThat(assessment.getObligationAssessments()).flatExtracting("metricAssessments").hasSize(1).extracting("result").contains(AssessmentResult.WARNING);
}
Also used : ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) Test(org.junit.Test)

Aggregations

ServiceLevelAssessment (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment)19 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)18 Test (org.junit.Test)14 AssessorNotFoundException (com.thinkbiganalytics.metadata.sla.spi.AssessorNotFoundException)2 Alert (com.thinkbiganalytics.alerts.api.Alert)1 PreconditionTriggerEvent (com.thinkbiganalytics.metadata.api.event.feed.PreconditionTriggerEvent)1 FeedPrecondition (com.thinkbiganalytics.metadata.api.feed.FeedPrecondition)1 JcrServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementCheck)1 AssessmentResult (com.thinkbiganalytics.metadata.sla.api.AssessmentResult)1 Obligation (com.thinkbiganalytics.metadata.sla.api.Obligation)1 ObligationAssessment (com.thinkbiganalytics.metadata.sla.api.ObligationAssessment)1 ObligationGroup (com.thinkbiganalytics.metadata.sla.api.ObligationGroup)1 Condition (com.thinkbiganalytics.metadata.sla.api.ObligationGroup.Condition)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 ServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1