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());
}
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations