@Test @Transactional public void testEnforceReceivedMetrics() throws Exception { String kpiName = "responsetime"; IProvider provider = new Provider(null, "provider-test", "provider-test"); providerDao.save(provider); ITemplate template = new Template(); template.setUuid(UUID.randomUUID().toString()); template.setText(""); provider.addTemplate(template); template.setProvider(provider); templateDao.save(template); IGuaranteeTerm term = TestAgreementFactory.newGuaranteeTerm(kpiName, kpiName + " LT 100"); IAgreement agreement = TestAgreementFactory.newAgreement( UUID.randomUUID().toString(), provider, "consumer", Arrays.asList( term, TestAgreementFactory.newGuaranteeTerm("performance", "performance GT 0.9") ) ); agreement.setTemplate(template); agreementDao.save(agreement); IEnforcementJob job = new EnforcementJob(); job.setAgreement(agreement); service.createEnforcementJob(job); List<IMonitoringMetric> metrics = Arrays.asList( (IMonitoringMetric) new MonitoringMetric(kpiName, 99, new Date()), (IMonitoringMetric) new MonitoringMetric(kpiName, 100, new Date()) ); Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = new HashMap<IGuaranteeTerm, List<IMonitoringMetric>>(); metricsMap.put(term, metrics); service.doEnforcement(agreement, metricsMap); }
public void enforceReceivedMetrics( IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics) { logger.debug( "enforceReceivedMetrics(agreement=" + agreement.getAgreementId() + ", gt=" + guaranteeTermName + ")"); Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = new HashMap<IGuaranteeTerm, List<IMonitoringMetric>>(); for (IGuaranteeTerm gt : agreement.getGuaranteeTerms()) { if (guaranteeTermName.equals(gt.getName())) { metricsMap.put(gt, metrics); } else { metricsMap.put(gt, Collections.<IMonitoringMetric>emptyList()); } } agreementEnforcement.enforce(agreement, metricsMap); }
EnforcementService implements IEnforcementService { public void enforceReceivedMetrics( IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics) { logger.debug( "enforceReceivedMetrics(agreement=" + agreement.getAgreementId() + ", gt=" + guaranteeTermName + ")"); Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = new HashMap<IGuaranteeTerm, List<IMonitoringMetric>>(); for (IGuaranteeTerm gt : agreement.getGuaranteeTerms()) { if (guaranteeTermName.equals(gt.getName())) { metricsMap.put(gt, metrics); } else { metricsMap.put(gt, Collections.<IMonitoringMetric>emptyList()); } } agreementEnforcement.enforce(agreement, metricsMap); } }
EnforcementService implements IEnforcementService { public void enforceReceivedMetrics( IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics) { logger.debug( "enforceReceivedMetrics(agreement=" + agreement.getAgreementId() + ", gt=" + guaranteeTermName + ")"); Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = new HashMap<IGuaranteeTerm, List<IMonitoringMetric>>(); for (IGuaranteeTerm gt : agreement.getGuaranteeTerms()) { if (guaranteeTermName.equals(gt.getName())) { metricsMap.put(gt, metrics); } else { metricsMap.put(gt, Collections.<IMonitoringMetric>emptyList()); } } agreementEnforcement.enforce(agreement, metricsMap); }  }
EnforcementService implements IEnforcementService { public void enforceReceivedMetrics( IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics) { logger.debug( "enforceReceivedMetrics(agreement=" + agreement.getAgreementId() + ", gt=" + guaranteeTermName + ")"); Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = new HashMap<IGuaranteeTerm, List<IMonitoringMetric>>(); for (IGuaranteeTerm gt : agreement.getGuaranteeTerms()) { if (guaranteeTermName.equals(gt.getName())) { metricsMap.put(gt, metrics); } else { metricsMap.put(gt, Collections.<IMonitoringMetric>emptyList()); } } agreementEnforcement.enforce(agreement, metricsMap); }  @Override IEnforcementJob getEnforcementJob(Long id); @Override IEnforcementJob getEnforcementJobByAgreementId(String agreementId); @Override List<IEnforcementJob> getEnforcementJobs(); @Override IEnforcementJob createEnforcementJob(IEnforcementJob job); @Override IEnforcementJob createEnforcementJob(String agreementId); @Override boolean deleteEnforcementJobByAgreementId(String agreementId); @Override boolean startEnforcement(String agreementId); @Override boolean stopEnforcement(String agreementId); @Override void saveEnforcementResult(IAgreement agreement,
            Map<IGuaranteeTerm, GuaranteeTermEvaluationResult> enforcementResult); void enforceReceivedMetrics(
            IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics); @Override void doEnforcement(IAgreement agreement,
            Map<IGuaranteeTerm, List<IMonitoringMetric>> metrics); @Override void saveCheckedGuaranteeTerm(IGuaranteeTerm term); }
EnforcementService implements IEnforcementService { public void enforceReceivedMetrics( IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics) { logger.debug( "enforceReceivedMetrics(agreement=" + agreement.getAgreementId() + ", gt=" + guaranteeTermName + ")"); Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = new HashMap<IGuaranteeTerm, List<IMonitoringMetric>>(); for (IGuaranteeTerm gt : agreement.getGuaranteeTerms()) { if (guaranteeTermName.equals(gt.getName())) { metricsMap.put(gt, metrics); } else { metricsMap.put(gt, Collections.<IMonitoringMetric>emptyList()); } } agreementEnforcement.enforce(agreement, metricsMap); }  @Override IEnforcementJob getEnforcementJob(Long id); @Override IEnforcementJob getEnforcementJobByAgreementId(String agreementId); @Override List<IEnforcementJob> getEnforcementJobs(); @Override IEnforcementJob createEnforcementJob(IEnforcementJob job); @Override IEnforcementJob createEnforcementJob(String agreementId); @Override boolean deleteEnforcementJobByAgreementId(String agreementId); @Override boolean startEnforcement(String agreementId); @Override boolean stopEnforcement(String agreementId); @Override void saveEnforcementResult(IAgreement agreement,
            Map<IGuaranteeTerm, GuaranteeTermEvaluationResult> enforcementResult); void enforceReceivedMetrics(
            IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics); @Override void doEnforcement(IAgreement agreement,
            Map<IGuaranteeTerm, List<IMonitoringMetric>> metrics); @Override void saveCheckedGuaranteeTerm(IGuaranteeTerm term);  }