@Test public void testTranslate() throws IOException { String json = readFile("/violation_t4c.json"); IConstraintEvaluator constraintEvaluator = new SimpleConstraintEvaluator(); Tower4CloudsTranslator translator = new Tower4CloudsTranslator(constraintEvaluator); Agreement agreement = new Agreement(); GuaranteeTerm term = new GuaranteeTerm(); term.setKpiName("responsetime"); term.setName("rt"); term.setServiceLevel("AverageDatabaseCPUUtilizationViolated NOT_EXISTS"); agreement.setGuaranteeTerms(Arrays.asList(new IGuaranteeTerm[] { term})); Map<IGuaranteeTerm, List<IMonitoringMetric>> map = translator.translate(agreement, json); assertEquals(1, map.get(term).size()); IMonitoringMetric item = map.get(term).get(0); assertEquals(1435136856709L, item.getDate().getTime()); assertEquals("AverageDatabaseCPUUtilizationViolated", item.getMetricKey()); assertEquals("0.022784559188465933e0", item.getMetricValue()); }
@Override public Map<IGuaranteeTerm, List<IMonitoringMetric>> translate(IAgreement agreement, String data) { MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric> resultWrapper = new MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric>(); Gson gson = new Gson(); JsonReader reader = null; Type type = new TypeToken<Map<String,Map<String,List<Map<String,String>>>>>(){}.getType(); reader = new JsonReader(new StringReader(data)); final Map<String,Map<String,List<Map<String,String>>>> json = gson.fromJson(reader, type); final MultivaluedMapWrapper<String, IGuaranteeTerm> metric2terms = initTermsMap(agreement); for (Map<String,List<Map<String,String>>> item : json.values()) { BindingHelper var = new BindingHelper(item); List<IGuaranteeTerm> terms = metric2terms.get(var.key); if (terms == null) { logger.warn("List of terms handling " + var.key + " is empty"); continue; } resultWrapper.addToKeys(terms, new MonitoringMetric(var)); } logger.debug("Output metricsmap = " + resultWrapper.getMap()); return resultWrapper.getMap(); }
Tower4CloudsTranslator implements IMetricTranslator<String> { @Override public Map<IGuaranteeTerm, List<IMonitoringMetric>> translate(IAgreement agreement, String data) { MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric> resultWrapper = new MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric>(); Gson gson = new Gson(); JsonReader reader = null; Type type = new TypeToken<Map<String,Map<String,List<Map<String,String>>>>>(){}.getType(); reader = new JsonReader(new StringReader(data)); final Map<String,Map<String,List<Map<String,String>>>> json = gson.fromJson(reader, type); final MultivaluedMapWrapper<String, IGuaranteeTerm> metric2terms = initTermsMap(agreement); for (Map<String,List<Map<String,String>>> item : json.values()) { BindingHelper var = new BindingHelper(item); List<IGuaranteeTerm> terms = metric2terms.get(var.key); if (terms == null) { logger.warn("List of terms handling " + var.key + " is empty"); continue; } resultWrapper.addToKeys(terms, new MonitoringMetric(var)); } logger.debug("Output metricsmap = " + resultWrapper.getMap()); return resultWrapper.getMap(); } }
Tower4CloudsTranslator implements IMetricTranslator<String> { @Override public Map<IGuaranteeTerm, List<IMonitoringMetric>> translate(IAgreement agreement, String data) { MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric> resultWrapper = new MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric>(); Gson gson = new Gson(); JsonReader reader = null; Type type = new TypeToken<Map<String,Map<String,List<Map<String,String>>>>>(){}.getType(); reader = new JsonReader(new StringReader(data)); final Map<String,Map<String,List<Map<String,String>>>> json = gson.fromJson(reader, type); final MultivaluedMapWrapper<String, IGuaranteeTerm> metric2terms = initTermsMap(agreement); for (Map<String,List<Map<String,String>>> item : json.values()) { BindingHelper var = new BindingHelper(item); List<IGuaranteeTerm> terms = metric2terms.get(var.key); if (terms == null) { logger.warn("List of terms handling " + var.key + " is empty"); continue; } resultWrapper.addToKeys(terms, new MonitoringMetric(var)); } logger.debug("Output metricsmap = " + resultWrapper.getMap()); return resultWrapper.getMap(); } Tower4CloudsTranslator(IConstraintEvaluator constraintEvaluator); }
Tower4CloudsTranslator implements IMetricTranslator<String> { @Override public Map<IGuaranteeTerm, List<IMonitoringMetric>> translate(IAgreement agreement, String data) { MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric> resultWrapper = new MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric>(); Gson gson = new Gson(); JsonReader reader = null; Type type = new TypeToken<Map<String,Map<String,List<Map<String,String>>>>>(){}.getType(); reader = new JsonReader(new StringReader(data)); final Map<String,Map<String,List<Map<String,String>>>> json = gson.fromJson(reader, type); final MultivaluedMapWrapper<String, IGuaranteeTerm> metric2terms = initTermsMap(agreement); for (Map<String,List<Map<String,String>>> item : json.values()) { BindingHelper var = new BindingHelper(item); List<IGuaranteeTerm> terms = metric2terms.get(var.key); if (terms == null) { logger.warn("List of terms handling " + var.key + " is empty"); continue; } resultWrapper.addToKeys(terms, new MonitoringMetric(var)); } logger.debug("Output metricsmap = " + resultWrapper.getMap()); return resultWrapper.getMap(); } Tower4CloudsTranslator(IConstraintEvaluator constraintEvaluator); @Override /** * Performs the translation from the data coming from the Monitor and SLA's MonitoringMetric. * * The key of each monitor data is the name of the violation (contained in the slo), so each * slo containing the key must enforce that metric. */ Map<IGuaranteeTerm, List<IMonitoringMetric>> translate(IAgreement agreement, String data); }
Tower4CloudsTranslator implements IMetricTranslator<String> { @Override public Map<IGuaranteeTerm, List<IMonitoringMetric>> translate(IAgreement agreement, String data) { MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric> resultWrapper = new MultivaluedMapWrapper<IGuaranteeTerm, IMonitoringMetric>(); Gson gson = new Gson(); JsonReader reader = null; Type type = new TypeToken<Map<String,Map<String,List<Map<String,String>>>>>(){}.getType(); reader = new JsonReader(new StringReader(data)); final Map<String,Map<String,List<Map<String,String>>>> json = gson.fromJson(reader, type); final MultivaluedMapWrapper<String, IGuaranteeTerm> metric2terms = initTermsMap(agreement); for (Map<String,List<Map<String,String>>> item : json.values()) { BindingHelper var = new BindingHelper(item); List<IGuaranteeTerm> terms = metric2terms.get(var.key); if (terms == null) { logger.warn("List of terms handling " + var.key + " is empty"); continue; } resultWrapper.addToKeys(terms, new MonitoringMetric(var)); } logger.debug("Output metricsmap = " + resultWrapper.getMap()); return resultWrapper.getMap(); } Tower4CloudsTranslator(IConstraintEvaluator constraintEvaluator); @Override /** * Performs the translation from the data coming from the Monitor and SLA's MonitoringMetric. * * The key of each monitor data is the name of the violation (contained in the slo), so each * slo containing the key must enforce that metric. */ Map<IGuaranteeTerm, List<IMonitoringMetric>> translate(IAgreement agreement, String data);  }