From: <rm...@hy...> - 2008-11-13 23:45:11
|
Author: rmorgan Date: 2008-11-13 15:45:06 -0800 (Thu, 13 Nov 2008) New Revision: 256 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=256 Added: trunk/src/org/hyperic/hq/hqapi1/test/MetricTestBase.java Modified: trunk/src/org/hyperic/hq/hqapi1/MetricApi.java trunk/src/org/hyperic/hq/hqapi1/test/MetricEnable_test.java trunk/src/org/hyperic/hq/hqapi1/test/MetricTemplateOps_test.java Log: Remove disabled metric tests, rework MetricApi. Modified: trunk/src/org/hyperic/hq/hqapi1/MetricApi.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/MetricApi.java 2008-11-13 23:03:39 UTC (rev 255) +++ trunk/src/org/hyperic/hq/hqapi1/MetricApi.java 2008-11-13 23:45:06 UTC (rev 256) @@ -4,28 +4,10 @@ import java.util.HashMap; import java.util.Map; -import org.hyperic.hq.hqapi1.types.DisableMetricResponse; -import org.hyperic.hq.hqapi1.types.EnableMetricResponse; -import org.hyperic.hq.hqapi1.types.GetMetricResponse; -import org.hyperic.hq.hqapi1.types.GetMetricTemplateResponse; -import org.hyperic.hq.hqapi1.types.ListMetricResponse; -import org.hyperic.hq.hqapi1.types.SetMetricDefaultIndicatorResponse; -import org.hyperic.hq.hqapi1.types.SetMetricDefaultIntervalResponse; -import org.hyperic.hq.hqapi1.types.SetMetricDefaultOnResponse; -import org.hyperic.hq.hqapi1.types.SetMetricIntervalResponse; +import org.hyperic.hq.hqapi1.types.*; -/** - * - * NOTES: - * 1) should we error out for scenarios where a user wants to enable a metric - * which is already enabled or ignore? - * (difference btwn metrics and metrictemplates?) - * - */ public class MetricApi { - private static final String HQU_URI = "/hqu/hqapi1/metric"; - private final HQConnection _conn; MetricApi(HQConnection conn) { @@ -34,157 +16,128 @@ /** * List {@link org.hyperic.hq.hqapi1.types.Metric}s associated with a - * resource + * {@link org.hyperic.hq.hqapi1.types.Resource} * - * @param resourceId The associated resourceId which the metrics belong. + * @param resource The associated {@link Resource} which the metrics belong. + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the * metrics were successfully retrieved. * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public ListMetricResponse listMetrics(Integer resourceId) + public ListMetricResponse listMetrics(Resource resource) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("resourceId", resourceId.toString()); - return _conn.doGet(HQU_URI+"/listMetrics.hqu", params, - ListMetricResponse.class); + params.put("resourceId", Integer.toString(resource.getId())); + return _conn.doGet("/hqu/hqapi1/metric/listMetrics.hqu", params, + ListMetricResponse.class); } /** * Disable a {@link org.hyperic.hq.hqapi1.types.Metric}. * - * @param metricId The metric to disable. + * @param m The {@link Metric} to disable. + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the * metric was successfully disabled. * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public DisableMetricResponse disableMetric(Integer metricId) + public DisableMetricResponse disableMetric(Metric m) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("id", metricId.toString()); - return _conn.doGet(HQU_URI+"/disableMetric.hqu", params, - DisableMetricResponse.class); + params.put("id", Integer.toString(m.getId())); + return _conn.doGet("/hqu/hqapi1/metric/disableMetric.hqu", params, + DisableMetricResponse.class); } /** * Enable a {@link org.hyperic.hq.hqapi1.types.Metric}. * - * @param metricId The metric to enable. + * @param m The metric to enable. + * @param interval The interval for collection, in minutes. + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the * metric was successfully enabled. * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public EnableMetricResponse enableMetric(Integer metricId, Long interval) + public EnableMetricResponse enableMetric(Metric m, long interval) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("id", metricId.toString()); - params.put("interval", interval.toString()); - return _conn.doGet(HQU_URI+"/enableMetric.hqu", params, - EnableMetricResponse.class); + params.put("id", Integer.toString(m.getId())); + params.put("interval", Long.toString(interval)); + return _conn.doGet("/hqu/hqapi1/metric/enableMetric.hqu", params, + EnableMetricResponse.class); } /** * Set a {@link org.hyperic.hq.hqapi1.types.Metric} collection interval. * - * @param metricId The metric to change the collection interval. + * @param m The metric to change the collection interval. + * @param interval The interval for collection in minutes. + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the - * metric's collection interval was successfully updated. + * {@link org.hyperic.hq.hqapi1.types.Metric}s collection interval was + * successfully updated. * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * @throws IOException - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public SetMetricIntervalResponse setInterval(Integer metricId, - Integer interval) + public SetMetricIntervalResponse setInterval(Metric m, long interval) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("id", metricId.toString()); - params.put("interval", interval.toString()); - return _conn.doGet(HQU_URI+"/setInterval.hqu", params, - SetMetricIntervalResponse.class); + params.put("id", Integer.toString(m.getId())); + params.put("interval", Long.toString(interval)); + return _conn.doGet("/hqu/hqapi1/metric/setInterval.hqu", params, + SetMetricIntervalResponse.class); } /** * Get the {@link org.hyperic.hq.hqapi1.types.Metric} associated * with the metricId * - * @param metricId The metricId used to retrieve the associated + * @param id The id used to retrieve the associated * {@link org.hyperic.hq.hqapi1.types.Metric}. + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the * {@link org.hyperic.hq.hqapi1.types.Metric} was retrieved * successfully * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public GetMetricResponse getMetric(Integer metricId) + public GetMetricResponse getMetric(Integer id) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("id", metricId.toString()); - return _conn.doGet(HQU_URI+"/getMetric.hqu", params, - GetMetricResponse.class); + params.put("id", id.toString()); + return _conn.doGet("/hqu/hqapi1/metric/getMetric.hqu", params, + GetMetricResponse.class); } /** * Get the {@link org.hyperic.hq.hqapi1.types.MetricTemplate} associated - * with the metricId + * with the metric id. * - * @param metricId The metricId used to retrieve the associated + * @param id The id used to retrieve the associated * {@link org.hyperic.hq.hqapi1.types.MetricTemplate}. + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the * {@link org.hyperic.hq.hqapi1.types.MetricTemplate} was retrieved * successfully * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public GetMetricTemplateResponse getMetricTemplate(Integer metricId) + public GetMetricTemplateResponse getMetricTemplate(Integer id) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("id", metricId.toString()); - return _conn.doGet(HQU_URI+"/getMetricTemplate.hqu", params, - GetMetricTemplateResponse.class); + params.put("id", id.toString()); + return _conn.doGet("/hqu/hqapi1/metric/getMetricTemplate.hqu", params, + GetMetricTemplateResponse.class); } /** @@ -193,14 +146,11 @@ * {@link org.hyperic.hq.hqapi1.types.MetricTemplate} * * @param templateId Sets the associated metric template's defaultOn + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the - * metric's collection interval was successfully updated. + * {@link org.hyperic.hq.hqapi1.types.Metric}s collection interval was + * successfully updated. * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ @@ -211,62 +161,53 @@ Map<String, String> params = new HashMap<String, String>(); params.put("templateId", templateId.toString()); params.put("on", on.toString()); - return _conn.doGet(HQU_URI+"/setDefaultOn.hqu", params, - SetMetricDefaultOnResponse.class); + return _conn.doGet("/hqu/hqapi1/metric/setDefaultOn.hqu", params, + SetMetricDefaultOnResponse.class); } /** - * Sets the defaultIndicator for all + * Sets the default indicator for all * {@link org.hyperic.hq.hqapi1.types.Metric}s associated with this * {@link org.hyperic.hq.hqapi1.types.MetricTemplate} * - * @param templateId Sets the associated metric template's default - * indicator + * @param template The {@link org.hyperic.hq.hqapi1.types.MetricTemplate} to operate on + * @param on Flag t + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the * metric's collection interval was successfully updated. * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public SetMetricDefaultIndicatorResponse setDefaultIndicator(Integer templateId, - Boolean on) + public SetMetricDefaultIndicatorResponse setDefaultIndicator(MetricTemplate template, + boolean on) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("templateId", templateId.toString()); - params.put("on", on.toString()); - return _conn.doGet(HQU_URI+"/setDefaultIndicator.hqu", params, - SetMetricDefaultIndicatorResponse.class); + params.put("templateId", Integer.toString(template.getId())); + params.put("on", Boolean.toString(on)); + return _conn.doGet("/hqu/hqapi1/metric/setDefaultIndicator.hqu", params, + SetMetricDefaultIndicatorResponse.class); } /** * Set a {@link org.hyperic.hq.hqapi1.types.Metric} collection interval. * - * @param templateId Sets the associated metric template's default interval + * @param template The {@link org.hyperic.hq.hqapi1.types.MetricTemplate} to operate on + * @param interval The new interval, in minutes. + * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the * metric template's default collection interval was successfully updated. * - * On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE} the - * following error codes may be returned: - * - * @see org.hyperic.hq.hqapi1.ErrorCode#LOGIN_FAILURE - * @see org.hyperic.hq.hqapi1.ErrorCode#OBJECT_NOT_FOUND - * @see org.hyperic.hq.hqapi1.ErrorCode#INVALID_PARAMETERS * @throws IOException If a network error occurs while making the request. */ - public SetMetricDefaultIntervalResponse setDefaultInterval(Integer templateId, - Integer interval) + public SetMetricDefaultIntervalResponse setDefaultInterval(MetricTemplate template, + long interval) throws IOException { Map<String, String> params = new HashMap<String, String>(); - params.put("templateId", templateId.toString()); - params.put("interval", interval.toString()); - return _conn.doGet(HQU_URI+"/setDefaultInterval.hqu", params, - SetMetricDefaultIntervalResponse.class); + params.put("templateId", Integer.toString(template.getId())); + params.put("interval", Long.toString(interval)); + return _conn.doGet("/hqu/hqapi1/metric/setDefaultInterval.hqu", params, + SetMetricDefaultIntervalResponse.class); } } Modified: trunk/src/org/hyperic/hq/hqapi1/test/MetricEnable_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/MetricEnable_test.java 2008-11-13 23:03:39 UTC (rev 255) +++ trunk/src/org/hyperic/hq/hqapi1/test/MetricEnable_test.java 2008-11-13 23:45:06 UTC (rev 256) @@ -15,24 +15,5 @@ } public void testEnableMetric() throws Exception { -/** - MetricApi api = getApi().getMetricApi(); - EnableMetricResponse eResp = api.enableMetric(_metricId, 10l); - hqAssertSuccess(eResp); - - GetMetricResponse gResp = api.getMetric(_metricId); - hqAssertSuccess(gResp); - Metric metric = gResp.getMetric(); - assertTrue(metric.isEnabled()); - - DisableMetricResponse dResp = api.disableMetric(_metricId); - hqAssertSuccess(dResp); - - gResp = api.getMetric(_metricId); - hqAssertSuccess(gResp); - metric = gResp.getMetric(); - assertTrue(!metric.isEnabled()); -*/ } - } Modified: trunk/src/org/hyperic/hq/hqapi1/test/MetricTemplateOps_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/MetricTemplateOps_test.java 2008-11-13 23:03:39 UTC (rev 255) +++ trunk/src/org/hyperic/hq/hqapi1/test/MetricTemplateOps_test.java 2008-11-13 23:45:06 UTC (rev 256) @@ -8,71 +8,17 @@ import org.hyperic.hq.hqapi1.types.SetMetricDefaultOnResponse; public class MetricTemplateOps_test extends HQApiTestBase { - - // cannot be an availability metric or setIndicator() will not work properly - private static final Integer metricId = 10103; public MetricTemplateOps_test(String name) { super(name); } public void testSetDefaultInterval() throws Exception { -/* - MetricApi api = getApi().getMetricApi(); - GetMetricTemplateResponse resp = api.getMetricTemplate(metricId); - MetricTemplate templ = resp.getMetricTemplate(); - int templateId = templ.getId(); - - SetMetricDefaultIntervalResponse diResp = - api.setDefaultInterval(templateId, 10); - hqAssertSuccess(diResp); - resp = api.getMetricTemplate(metricId); - templ = resp.getMetricTemplate(); - assertTrue(templ.getDefaultInterval().equals(600000)); -*/ } public void testSetDefaultIndicator() throws Exception { -/* - MetricApi api = getApi().getMetricApi(); - GetMetricTemplateResponse resp = api.getMetricTemplate(metricId); - MetricTemplate templ = resp.getMetricTemplate(); - int templateId = templ.getId(); - - SetMetricDefaultIndicatorResponse diResp = - api.setDefaultIndicator(templateId, true); - hqAssertSuccess(diResp); - resp = api.getMetricTemplate(metricId); - templ = resp.getMetricTemplate(); - assertTrue(templ.isIndicator()); - - diResp = api.setDefaultIndicator(templateId, false); - hqAssertSuccess(diResp); - resp = api.getMetricTemplate(metricId); - templ = resp.getMetricTemplate(); - assertFalse(templ.isIndicator()); -*/ } public void testSetDefaultOn() throws Exception { -/* - MetricApi api = getApi().getMetricApi(); - GetMetricTemplateResponse resp = api.getMetricTemplate(metricId); - MetricTemplate templ = resp.getMetricTemplate(); - int templateId = templ.getId(); - - SetMetricDefaultOnResponse donResp = api.setDefaultOn(templateId, true); - hqAssertSuccess(donResp); - resp = api.getMetricTemplate(metricId); - templ = resp.getMetricTemplate(); - assertTrue(templ.isDefaultOn()); - - donResp = api.setDefaultOn(templateId, false); - hqAssertSuccess(donResp); - resp = api.getMetricTemplate(metricId); - templ = resp.getMetricTemplate(); - assertTrue(!templ.isDefaultOn()); -*/ } - } Added: trunk/src/org/hyperic/hq/hqapi1/test/MetricTestBase.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/MetricTestBase.java (rev 0) +++ trunk/src/org/hyperic/hq/hqapi1/test/MetricTestBase.java 2008-11-13 23:45:06 UTC (rev 256) @@ -0,0 +1,8 @@ +package org.hyperic.hq.hqapi1.test; + +public class MetricTestBase extends HQApiTestBase { + + public MetricTestBase(String name) { + super(name); + } +} |