@Test public void testGetViolationsWithPolicy5() { System.out.println("---testEvaluateWithPolicy5()---"); List<IMonitoringMetric> metrics = setUpWithPolicies(); term.setPolicies(Arrays.asList(new IPolicy[] { newPolicy("LATENCY", 3, new Date(10000)), newPolicy("LATENCY", 2, new Date(3000)) })); List<IViolation> violations = evaluator.evaluate(contract, term, metrics, now); assertEquals(1, violations.size()); assertViolations(violations, allMetrics.get(0), allMetrics.get(4), allMetrics.get(5)); assertEquals(10000, violations.get(0).getPolicy().getTimeInterval().getTime()); }
@Override public List<IViolation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now) { logger.debug("evaluate(agreement={}, term={}, servicelevel={})", agreement.getAgreementId(), term.getKpiName(), term.getServiceLevel()); checkInitialized(); List<IViolation> newViolations = new ArrayList<IViolation>(); String kpiName = term.getKpiName(); String constraint = term.getServiceLevel(); List<IMonitoringMetric> newBreachMetrics = constraintEval.evaluate(kpiName, constraint, metrics); logger.debug("Found {} breaches in new metrics", newBreachMetrics.size()); List<IPolicy> policies = getPoliciesOrDefault(term); boolean withPolicies = !isDefaultPolicy(policies); List<IBreach> newBreaches = null; if (withPolicies) { newBreaches = breachesFromMetricsBuilder.build(newBreachMetrics, agreement, kpiName); saveBreaches(newBreaches); } for (IPolicy policy : policies) { Date breachesBegin = new Date(now.getTime() - policy.getTimeInterval().getTime()); logger.debug("Evaluating policy({},{}s) in interval({}, {})", policy.getCount(), policy.getTimeInterval().getTime() / 1000, breachesBegin, now); List<IBreach> oldBreaches; if (withPolicies) { oldBreaches = breachRepository.getBreachesByTimeRange(agreement, kpiName, breachesBegin, now); logger.debug("Found {} breaches", oldBreaches.size()); List<IBreach> breaches = new PoliciedServiceLevelEvaluator.CompositeList<IBreach>( oldBreaches, newBreaches); if (evaluatePolicy(policy, oldBreaches, newBreaches)) { IViolation violation = newViolation(agreement, term, policy, kpiName, breaches, now); newViolations.add(violation); violation.setBreaches(breaches); logger.debug("Violation raised"); } } else { oldBreaches = Collections.emptyList(); for (IMonitoringMetric breach : newBreachMetrics) { IViolation violation = newViolation(agreement, term, kpiName, breach); newViolations.add(violation); logger.debug("Violation raised"); } } } return newViolations; }
PoliciedServiceLevelEvaluator implements IServiceLevelEvaluator { @Override public List<IViolation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now) { logger.debug("evaluate(agreement={}, term={}, servicelevel={})", agreement.getAgreementId(), term.getKpiName(), term.getServiceLevel()); checkInitialized(); List<IViolation> newViolations = new ArrayList<IViolation>(); String kpiName = term.getKpiName(); String constraint = term.getServiceLevel(); List<IMonitoringMetric> newBreachMetrics = constraintEval.evaluate(kpiName, constraint, metrics); logger.debug("Found {} breaches in new metrics", newBreachMetrics.size()); List<IPolicy> policies = getPoliciesOrDefault(term); boolean withPolicies = !isDefaultPolicy(policies); List<IBreach> newBreaches = null; if (withPolicies) { newBreaches = breachesFromMetricsBuilder.build(newBreachMetrics, agreement, kpiName); saveBreaches(newBreaches); } for (IPolicy policy : policies) { Date breachesBegin = new Date(now.getTime() - policy.getTimeInterval().getTime()); logger.debug("Evaluating policy({},{}s) in interval({}, {})", policy.getCount(), policy.getTimeInterval().getTime() / 1000, breachesBegin, now); List<IBreach> oldBreaches; if (withPolicies) { oldBreaches = breachRepository.getBreachesByTimeRange(agreement, kpiName, breachesBegin, now); logger.debug("Found {} breaches", oldBreaches.size()); List<IBreach> breaches = new PoliciedServiceLevelEvaluator.CompositeList<IBreach>( oldBreaches, newBreaches); if (evaluatePolicy(policy, oldBreaches, newBreaches)) { IViolation violation = newViolation(agreement, term, policy, kpiName, breaches, now); newViolations.add(violation); violation.setBreaches(breaches); logger.debug("Violation raised"); } } else { oldBreaches = Collections.emptyList(); for (IMonitoringMetric breach : newBreachMetrics) { IViolation violation = newViolation(agreement, term, kpiName, breach); newViolations.add(violation); logger.debug("Violation raised"); } } } return newViolations; } }
PoliciedServiceLevelEvaluator implements IServiceLevelEvaluator { @Override public List<IViolation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now) { logger.debug("evaluate(agreement={}, term={}, servicelevel={})", agreement.getAgreementId(), term.getKpiName(), term.getServiceLevel()); checkInitialized(); List<IViolation> newViolations = new ArrayList<IViolation>(); String kpiName = term.getKpiName(); String constraint = term.getServiceLevel(); List<IMonitoringMetric> newBreachMetrics = constraintEval.evaluate(kpiName, constraint, metrics); logger.debug("Found {} breaches in new metrics", newBreachMetrics.size()); List<IPolicy> policies = getPoliciesOrDefault(term); boolean withPolicies = !isDefaultPolicy(policies); List<IBreach> newBreaches = null; if (withPolicies) { newBreaches = breachesFromMetricsBuilder.build(newBreachMetrics, agreement, kpiName); saveBreaches(newBreaches); } for (IPolicy policy : policies) { Date breachesBegin = new Date(now.getTime() - policy.getTimeInterval().getTime()); logger.debug("Evaluating policy({},{}s) in interval({}, {})", policy.getCount(), policy.getTimeInterval().getTime() / 1000, breachesBegin, now); List<IBreach> oldBreaches; if (withPolicies) { oldBreaches = breachRepository.getBreachesByTimeRange(agreement, kpiName, breachesBegin, now); logger.debug("Found {} breaches", oldBreaches.size()); List<IBreach> breaches = new PoliciedServiceLevelEvaluator.CompositeList<IBreach>( oldBreaches, newBreaches); if (evaluatePolicy(policy, oldBreaches, newBreaches)) { IViolation violation = newViolation(agreement, term, policy, kpiName, breaches, now); newViolations.add(violation); violation.setBreaches(breaches); logger.debug("Violation raised"); } } else { oldBreaches = Collections.emptyList(); for (IMonitoringMetric breach : newBreachMetrics) { IViolation violation = newViolation(agreement, term, kpiName, breach); newViolations.add(violation); logger.debug("Violation raised"); } } } return newViolations; }  }
PoliciedServiceLevelEvaluator implements IServiceLevelEvaluator { @Override public List<IViolation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now) { logger.debug("evaluate(agreement={}, term={}, servicelevel={})", agreement.getAgreementId(), term.getKpiName(), term.getServiceLevel()); checkInitialized(); List<IViolation> newViolations = new ArrayList<IViolation>(); String kpiName = term.getKpiName(); String constraint = term.getServiceLevel(); List<IMonitoringMetric> newBreachMetrics = constraintEval.evaluate(kpiName, constraint, metrics); logger.debug("Found {} breaches in new metrics", newBreachMetrics.size()); List<IPolicy> policies = getPoliciesOrDefault(term); boolean withPolicies = !isDefaultPolicy(policies); List<IBreach> newBreaches = null; if (withPolicies) { newBreaches = breachesFromMetricsBuilder.build(newBreachMetrics, agreement, kpiName); saveBreaches(newBreaches); } for (IPolicy policy : policies) { Date breachesBegin = new Date(now.getTime() - policy.getTimeInterval().getTime()); logger.debug("Evaluating policy({},{}s) in interval({}, {})", policy.getCount(), policy.getTimeInterval().getTime() / 1000, breachesBegin, now); List<IBreach> oldBreaches; if (withPolicies) { oldBreaches = breachRepository.getBreachesByTimeRange(agreement, kpiName, breachesBegin, now); logger.debug("Found {} breaches", oldBreaches.size()); List<IBreach> breaches = new PoliciedServiceLevelEvaluator.CompositeList<IBreach>( oldBreaches, newBreaches); if (evaluatePolicy(policy, oldBreaches, newBreaches)) { IViolation violation = newViolation(agreement, term, policy, kpiName, breaches, now); newViolations.add(violation); violation.setBreaches(breaches); logger.debug("Violation raised"); } } else { oldBreaches = Collections.emptyList(); for (IMonitoringMetric breach : newBreachMetrics) { IViolation violation = newViolation(agreement, term, kpiName, breach); newViolations.add(violation); logger.debug("Violation raised"); } } } return newViolations; }  @Override List<IViolation> evaluate(
            IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now); IConstraintEvaluator getConstraintEvaluator(); void setConstraintEvaluator(IConstraintEvaluator constraintEval); IBreachRepository getBreachRepository(); void setBreachRepository(IBreachRepository breachRepository); }
PoliciedServiceLevelEvaluator implements IServiceLevelEvaluator { @Override public List<IViolation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now) { logger.debug("evaluate(agreement={}, term={}, servicelevel={})", agreement.getAgreementId(), term.getKpiName(), term.getServiceLevel()); checkInitialized(); List<IViolation> newViolations = new ArrayList<IViolation>(); String kpiName = term.getKpiName(); String constraint = term.getServiceLevel(); List<IMonitoringMetric> newBreachMetrics = constraintEval.evaluate(kpiName, constraint, metrics); logger.debug("Found {} breaches in new metrics", newBreachMetrics.size()); List<IPolicy> policies = getPoliciesOrDefault(term); boolean withPolicies = !isDefaultPolicy(policies); List<IBreach> newBreaches = null; if (withPolicies) { newBreaches = breachesFromMetricsBuilder.build(newBreachMetrics, agreement, kpiName); saveBreaches(newBreaches); } for (IPolicy policy : policies) { Date breachesBegin = new Date(now.getTime() - policy.getTimeInterval().getTime()); logger.debug("Evaluating policy({},{}s) in interval({}, {})", policy.getCount(), policy.getTimeInterval().getTime() / 1000, breachesBegin, now); List<IBreach> oldBreaches; if (withPolicies) { oldBreaches = breachRepository.getBreachesByTimeRange(agreement, kpiName, breachesBegin, now); logger.debug("Found {} breaches", oldBreaches.size()); List<IBreach> breaches = new PoliciedServiceLevelEvaluator.CompositeList<IBreach>( oldBreaches, newBreaches); if (evaluatePolicy(policy, oldBreaches, newBreaches)) { IViolation violation = newViolation(agreement, term, policy, kpiName, breaches, now); newViolations.add(violation); violation.setBreaches(breaches); logger.debug("Violation raised"); } } else { oldBreaches = Collections.emptyList(); for (IMonitoringMetric breach : newBreachMetrics) { IViolation violation = newViolation(agreement, term, kpiName, breach); newViolations.add(violation); logger.debug("Violation raised"); } } } return newViolations; }  @Override List<IViolation> evaluate(
            IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now); IConstraintEvaluator getConstraintEvaluator(); void setConstraintEvaluator(IConstraintEvaluator constraintEval); IBreachRepository getBreachRepository(); void setBreachRepository(IBreachRepository breachRepository);  }