Search in sources :

Example 1 with Obligation

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

the class SimpleServiceLevelAssessor method assess.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAssessor#assess(com.
     * thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)
     */
@Override
public ServiceLevelAssessment assess(ServiceLevelAgreement sla) {
    Log.info("Assessing SLA: {}", sla.getName());
    AssessmentResult combinedResult = AssessmentResult.FAILURE;
    try {
        SimpleServiceLevelAssessment slaAssessment = new SimpleServiceLevelAssessment(sla);
        List<ObligationGroup> groups = sla.getObligationGroups();
        for (ObligationGroup group : groups) {
            ObligationGroup.Condition condition = group.getCondition();
            AssessmentResult groupResult = AssessmentResult.SUCCESS;
            for (Obligation ob : group.getObligations()) {
                ObligationAssessment obAssessment = assess(ob);
                slaAssessment.add(obAssessment);
                groupResult = groupResult.max(obAssessment.getResult());
            }
            // 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.min(groupResult);
        }
        return completeAssessment(slaAssessment, combinedResult);
    } finally {
        Log.debug("Completed assessment of SLA {}: {}", sla.getName(), combinedResult);
    }
}
Also used : ObligationAssessment(com.thinkbiganalytics.metadata.sla.api.ObligationAssessment) Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) AssessmentResult(com.thinkbiganalytics.metadata.sla.api.AssessmentResult) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup)

Example 2 with Obligation

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

the class ServiceLevelAgreementModelTransform method toModel.

public static com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement toModel(ServiceLevelAgreement domain, boolean deep) {
    com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement sla = new com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement(domain.getId().toString(), domain.getName(), domain.getDescription());
    if (domain.getSlaChecks() != null) {
        List<ServiceLevelAgreementCheck> checks = new ArrayList<>();
        sla.setSlaChecks(checks);
        for (com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck check : domain.getSlaChecks()) {
            ServiceLevelAgreementCheck restModel = new ServiceLevelAgreementCheck();
            restModel.setCronSchedule(check.getCronSchedule());
            if (deep) {
                try {
                    restModel.setActionConfigurations(check.getActionConfigurations());
                } catch (Exception e) {
                    if (ExceptionUtils.getRootCause(e) instanceof ClassNotFoundException) {
                        String msg = ExceptionUtils.getRootCauseMessage(e);
                        // get just the simpleClassName stripping the package info
                        msg = StringUtils.substringAfterLast(msg, ".");
                        sla.addSlaCheckError("Unable to find the SLA Action Configurations of type: " + msg + ". Check with an administrator to ensure the correct plugin is installed with this SLA configuration. ");
                    } else {
                        throw new RuntimeException(e);
                    }
                }
            }
            checks.add(restModel);
        }
    }
    if (deep) {
        if (domain.getObligationGroups().size() == 1 && domain.getObligationGroups().get(0).getCondition() == ObligationGroup.Condition.REQUIRED) {
            for (Obligation domainOb : domain.getObligations()) {
                com.thinkbiganalytics.metadata.rest.model.sla.Obligation ob = toModel(domainOb, true);
                sla.addObligation(ob);
            }
        } else {
            for (ObligationGroup domainGroup : domain.getObligationGroups()) {
                // Force it to be required
                // TODO Rework once the SLA page allows for Sufficient/Required settings
                // TODO use the domainGroup.condition instead
                com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup group = new com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup(ObligationGroup.Condition.REQUIRED.name());
                for (Obligation domainOb : domainGroup.getObligations()) {
                    com.thinkbiganalytics.metadata.rest.model.sla.Obligation ob = toModel(domainOb, true);
                    group.addObligation(ob);
                }
                sla.addGroup(group);
            }
        }
    }
    return sla;
}
Also used : Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck) ArrayList(java.util.ArrayList) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup)

Example 3 with Obligation

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

Aggregations

Obligation (com.thinkbiganalytics.metadata.sla.api.Obligation)3 ObligationGroup (com.thinkbiganalytics.metadata.sla.api.ObligationGroup)3 AssessmentResult (com.thinkbiganalytics.metadata.sla.api.AssessmentResult)2 ObligationAssessment (com.thinkbiganalytics.metadata.sla.api.ObligationAssessment)2 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)2 ArrayList (java.util.ArrayList)2 FeedServiceLevelAgreement (com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement)1 ServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck)1 Condition (com.thinkbiganalytics.metadata.sla.api.ObligationGroup.Condition)1 ServiceLevelAssessment (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1