From: <rm...@hy...> - 2009-05-06 22:32:52
|
Author: rmorgan Date: 2009-05-06 15:32:40 -0700 (Wed, 06 May 2009) New Revision: 573 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=573 Modified: trunk/hqu/hqapi1/app/MetricController.groovy trunk/src/org/hyperic/hq/hqapi1/test/MetricData_test.java Log: Add better error messages. Unhardcode template from 10001 to Linux template. Add test for getting data in the past where no data exists. Modified: trunk/hqu/hqapi1/app/MetricController.groovy =================================================================== --- trunk/hqu/hqapi1/app/MetricController.groovy 2009-05-06 18:49:41 UTC (rev 572) +++ trunk/hqu/hqapi1/app/MetricController.groovy 2009-05-06 22:32:40 UTC (rev 573) @@ -66,7 +66,8 @@ def failureXml = null def templates if (!prototype) { - failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS) + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "No prototype given") } else { // Make sure the prototype exists. def proto = resourceHelper.find(prototype: prototype) @@ -99,7 +100,8 @@ def template def failureXml = null if (!id) { - failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS) + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Metric template id not given") } else { template = metricHelper.findTemplateById(id) if (!template) { @@ -127,7 +129,8 @@ def enabled = params.getOne("enabled")?.toBoolean() if (!resourceId) { - failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS) + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Resource id not given") } else { def res = getResource(resourceId) if (!res) { @@ -167,7 +170,8 @@ def metricId = params.getOne("id")?.toInteger() if (!metricId) { - failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS) + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Metric id not given") } else { try { metric = metricHelper.findMeasurementById(metricId); @@ -336,12 +340,14 @@ def end = params.getOne("end")?.toLong() def failureXml = null - if (!metricId || !start || !end) { - failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS) + if (metricId == null || start == null || end == null) { + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Missing argument") } if (end < start) { - failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS) + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "End time cannot be < start time") } def metric = metricHelper.findMeasurementById(metricId) Modified: trunk/src/org/hyperic/hq/hqapi1/test/MetricData_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/MetricData_test.java 2009-05-06 18:49:41 UTC (rev 572) +++ trunk/src/org/hyperic/hq/hqapi1/test/MetricData_test.java 2009-05-06 22:32:40 UTC (rev 573) @@ -34,7 +34,6 @@ import org.hyperic.hq.hqapi1.types.DataPoint; import org.hyperic.hq.hqapi1.types.Group; import org.hyperic.hq.hqapi1.types.GroupResponse; -import org.hyperic.hq.hqapi1.types.GroupsResponse; import org.hyperic.hq.hqapi1.types.Metric; import org.hyperic.hq.hqapi1.types.MetricData; import org.hyperic.hq.hqapi1.types.MetricDataResponse; @@ -51,6 +50,7 @@ import java.util.List; import java.util.Random; +import java.io.IOException; public class MetricData_test extends MetricTestBase { @@ -90,6 +90,38 @@ } } + public void testGetMetricDataOldRange() throws Exception { + + MetricApi api = getApi().getMetricApi(); + Resource r = getLocalPlatformResource(false, false); + MetricsResponse resp = api.getEnabledMetrics(r); + hqAssertSuccess(resp); + + assertTrue("No enabled metrics found for " + r.getName(), + resp.getMetric().size() > 0); + + Metric metric = null; + for (Metric m : resp.getMetric()) { + if (!m.getMetricTemplate().getAlias().equals("Availability")) { + metric = m; + break; + } + } + + assertNotNull("No metric found for " + r.getName(), metric); + + long end = 100; + long start = 0; + + MetricDataResponse dataResponse = api.getMetricData(metric.getId(), + start, end); + hqAssertSuccess(dataResponse); + + assertTrue("Wrong number of data points, expected 0, got " + + dataResponse.getMetricData().getDataPoint().size(), + dataResponse.getMetricData().getDataPoint().size() == 0); + } + public void testGetDisabledMetricData() throws Exception { MetricApi api = getApi().getMetricApi(); @@ -151,8 +183,28 @@ hqAssertFailureInvalidParameters(dataResponse); } - private Group getCompatibleGroup() throws Exception { + // Helper method to get a MetricTemplate for the Linux ResourcePrototype + private MetricTemplate getLinuxTemplate() throws IOException + { + HQApi api = getApi(); + ResourceApi resourceApi = api.getResourceApi(); + MetricApi metricApi = api.getMetricApi(); + ResourcePrototypeResponse protoResponse = + resourceApi.getResourcePrototype("Linux"); + hqAssertSuccess(protoResponse); + + MetricTemplatesResponse templatesResponse = + metricApi.getMetricTemplates(protoResponse.getResourcePrototype()); + hqAssertSuccess(templatesResponse); + + assertTrue("No templates found!", templatesResponse.getMetricTemplate().size() > 0); + + return templatesResponse.getMetricTemplate().get(0); + } + + private Group getFileServerMountCompatibleGroup() throws Exception { + HQApi api = getApi(); ResourceApi resourceApi = api.getResourceApi(); GroupApi groupApi = api.getGroupApi(); @@ -212,7 +264,7 @@ HQApi api = getApi(); - Group g = getCompatibleGroup(); + Group g = getFileServerMountCompatibleGroup(); ResourcePrototype pt = g.getResourcePrototype(); MetricApi metricApi = api.getMetricApi(); MetricTemplatesResponse templatesResponse = metricApi.getMetricTemplates(pt); @@ -262,7 +314,7 @@ HQApi api = getApi(); - Group g = getCompatibleGroup(); + Group g = getFileServerMountCompatibleGroup(); ResourcePrototype pt = g.getResourcePrototype(); MetricApi metricApi = api.getMetricApi(); MetricTemplatesResponse templatesResponse = metricApi.getMetricTemplates(pt); @@ -298,7 +350,7 @@ HQApi api = getApi(); - Group g = getCompatibleGroup(); + Group g = getFileServerMountCompatibleGroup(); MetricApi metricApi = api.getMetricApi(); long end = System.currentTimeMillis(); long start = end - (8 * 60 * 60 * 1000); @@ -313,13 +365,10 @@ HQApi api = getApi(); - Group g = getCompatibleGroup(); + Group g = getFileServerMountCompatibleGroup(); MetricApi metricApi = api.getMetricApi(); - MetricTemplateResponse getTemplateResponse = - metricApi.getMetricTemplate(10001); - hqAssertSuccess(getTemplateResponse); - MetricTemplate t = getTemplateResponse.getMetricTemplate(); + MetricTemplate t = getLinuxTemplate(); long end = System.currentTimeMillis(); long start = end - (8 * 60 * 60 * 1000); @@ -336,12 +385,8 @@ Group g = getMixedGroup(); MetricApi metricApi = api.getMetricApi(); + MetricTemplate t = getLinuxTemplate(); - MetricTemplateResponse getTemplateResponse = - metricApi.getMetricTemplate(10001); - hqAssertSuccess(getTemplateResponse); - MetricTemplate t = getTemplateResponse.getMetricTemplate(); - long end = System.currentTimeMillis(); long start = end - (8 * 60 * 60 * 1000); MetricsDataResponse response = metricApi.getMetricData(g.getId(), @@ -356,7 +401,7 @@ HQApi api = getApi(); - Group g = getCompatibleGroup(); + Group g = getFileServerMountCompatibleGroup(); ResourcePrototype pt = g.getResourcePrototype(); MetricApi metricApi = api.getMetricApi(); MetricTemplatesResponse templatesResponse = metricApi.getMetricTemplates(pt); @@ -391,7 +436,7 @@ HQApi api = getApi(); - Group g = getCompatibleGroup(); + Group g = getFileServerMountCompatibleGroup(); ResourcePrototype pt = g.getResourcePrototype(); MetricApi metricApi = api.getMetricApi(); MetricTemplatesResponse templatesResponse = metricApi.getMetricTemplates(pt); @@ -508,8 +553,9 @@ hqAssertFailureObjectNotFound(invalidTemplateResponse); // Retry with valid template, but belonging to this type + MetricTemplate linuxTemplate = getLinuxTemplate(); MetricsDataResponse wrongTemplateResponse = - metricApi.getMetricData(resourceIds, 10001, start, end); + metricApi.getMetricData(resourceIds, linuxTemplate.getId(), start, end); hqAssertFailureInvalidParameters(wrongTemplateResponse); // Retry with empty resources array |