Skip to content

Commit

Permalink
Combine similar getMetric APIs into a single API. Old APIs have been …
Browse files Browse the repository at this point in the history
…marked deprecated.
  • Loading branch information
Ryan Morgan committed Jul 15, 2009
1 parent 6197ae4 commit 5260db2
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 30 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,6 +1,10 @@

Changes in HQApi 3.0

*) MetricApi.getMetrics(Resource r) and MetricApi.getEnabledMetrics(Resource r)
has been combined into a single function which takes an enabled flag. These
2 APIs have been marked as deprecated.

*) [HHQ-3230] Add --conditionTypeExclude to allow definitions to be excluded
based on conditions. As part of this change --conditionType has been
renamed to --conditionTypeInclude
Expand Down
25 changes: 25 additions & 0 deletions src/org/hyperic/hq/hqapi1/MetricApi.java
Expand Up @@ -75,6 +75,7 @@ public class MetricApi extends BaseApi {
* metrics were successfully retrieved.
*
* @throws IOException If a network error occurs while making the request.
* @deprecated See {@link org.hyperic.hq.hqapi1.MetricApi#getMetrics(org.hyperic.hq.hqapi1.types.Resource, boolean)}
*/
public MetricsResponse getMetrics(Resource resource)
throws IOException
Expand All @@ -96,6 +97,7 @@ public MetricsResponse getMetrics(Resource resource)
* metrics were successfully retrieved.
*
* @throws IOException If a network error occurs while making the request.
* @deprecated See {@link org.hyperic.hq.hqapi1.MetricApi#getMetrics(org.hyperic.hq.hqapi1.types.Resource, boolean)}
*/
public MetricsResponse getEnabledMetrics(Resource resource)
throws IOException
Expand All @@ -107,6 +109,29 @@ public MetricsResponse getEnabledMetrics(Resource resource)
MetricsResponse.class);
}

/**
* List all enabled {@link org.hyperic.hq.hqapi1.types.Metric}s associated with a
* {@link org.hyperic.hq.hqapi1.types.Resource}
*
* @param resource The associated {@link org.hyperic.hq.hqapi1.types.Resource}
* which the metrics belong.
* @param enabled If set to true, only Metrics which are enabled will be returned.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if the
* metrics were successfully retrieved.
*
* @throws IOException If a network error occurs while making the request.
*/
public MetricsResponse getMetrics(Resource resource, boolean enabled)
throws IOException
{
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("resourceId", new String[] { Integer.toString(resource.getId()) });
params.put("enabled", new String[] { Boolean.toString(enabled) });
return doGet("metric/getMetrics.hqu", params,
MetricsResponse.class);
}

/**
* Get the {@link org.hyperic.hq.hqapi1.types.Metric} associated
* with the metricId
Expand Down
Expand Up @@ -58,7 +58,7 @@ public void testValidBaselineConditon() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testValidBaselineConditonTypeAlert() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -150,7 +150,7 @@ public void testCreateMissingAttributes() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -218,7 +218,7 @@ public void testCreateInvalidBaselineType() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down
Expand Up @@ -56,7 +56,7 @@ public void testValidMetricChangeConditon() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -93,7 +93,7 @@ public void testValidMetricChangeConditonTypeAlert() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -130,7 +130,7 @@ public void testMetricChangeConditionMissingAttributes() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down
Expand Up @@ -56,7 +56,7 @@ public void testValidRecoveryCondition() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testValidRecoveryConditionTypeAlert() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -152,7 +152,7 @@ public void testSyncRecoveryWithoutProblemDef() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -203,7 +203,7 @@ public void testSyncRecoveryWithoutProblemDefTypeAlert() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -257,7 +257,7 @@ public void testInvalidRecoveryAlert() throws Exception {
MetricApi metricApi = api.getMetricApi();
Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void testValidThresholdConditon() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -100,7 +100,7 @@ public void testValidThresholdConditonTypeAlert() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down Expand Up @@ -143,7 +143,7 @@ public void testCreateMissingAttributes() throws Exception {

Resource platform = getLocalPlatformResource(false, false);

MetricsResponse metricsResponse = metricApi.getMetrics(platform);
MetricsResponse metricsResponse = metricApi.getMetrics(platform, true);
hqAssertSuccess(metricsResponse);
assertTrue("No metrics found for " + platform.getName(),
metricsResponse.getMetric().size() > 0);
Expand Down
8 changes: 4 additions & 4 deletions src/org/hyperic/hq/hqapi1/test/MetricData_test.java
Expand Up @@ -62,7 +62,7 @@ public void testGetEnabledMetricData() throws Exception {

MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getEnabledMetrics(r);
MetricsResponse resp = api.getMetrics(r, true);
hqAssertSuccess(resp);

assertTrue("No enabled metrics found for " + r.getName(),
Expand Down Expand Up @@ -94,7 +94,7 @@ public void testGetMetricDataOldRange() throws Exception {

MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getEnabledMetrics(r);
MetricsResponse resp = api.getMetrics(r, true);
hqAssertSuccess(resp);

assertTrue("No enabled metrics found for " + r.getName(),
Expand Down Expand Up @@ -126,7 +126,7 @@ public void testGetDisabledMetricData() throws Exception {

MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getMetrics(r);
MetricsResponse resp = api.getMetrics(r, false);
hqAssertSuccess(resp);

assertTrue("No metrics found for " + r.getName(),
Expand Down Expand Up @@ -167,7 +167,7 @@ public void testGetMetricDataInvalidRange() throws Exception {

MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getMetrics(r);
MetricsResponse resp = api.getMetrics(r, true);
hqAssertSuccess(resp);

long end = System.currentTimeMillis();
Expand Down
18 changes: 9 additions & 9 deletions src/org/hyperic/hq/hqapi1/test/Metric_test.java
Expand Up @@ -59,7 +59,7 @@ public void testListMetrics() throws Exception {

MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getMetrics(r);
MetricsResponse resp = api.getMetrics(r, false);
hqAssertSuccess(resp);

int numNotDefaultOn = 0;
Expand All @@ -76,7 +76,7 @@ public void testListEnabledMetrics() throws Exception {

MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getEnabledMetrics(r);
MetricsResponse resp = api.getMetrics(r, true);
hqAssertSuccess(resp);

for (Metric m : resp.getMetric()) {
Expand All @@ -91,15 +91,15 @@ public void testMetricListBadResourceId() throws Exception {
MetricApi api = getApi().getMetricApi();
Resource r = new Resource();
r.setId(Integer.MAX_VALUE);
MetricsResponse resp = api.getMetrics(r);
MetricsResponse resp = api.getMetrics(r, true);
hqAssertFailureObjectNotFound(resp);
}

public void testMetricById() throws Exception {

MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getMetrics(r);
MetricsResponse resp = api.getMetrics(r, true);
hqAssertSuccess(resp);

assertFalse("Resource " + r.getName() + " has no metrics",
Expand All @@ -124,7 +124,7 @@ public void testSyncUpdateInterval() throws Exception {
MetricApi metricApi = api.getMetricApi();
Resource r = getLocalPlatformResource(false, false);

MetricsResponse metrics = metricApi.getMetrics(r);
MetricsResponse metrics = metricApi.getMetrics(r, true);
hqAssertSuccess(metrics);

Metric enabledMetric = null;
Expand Down Expand Up @@ -173,9 +173,9 @@ public void testSyncEnable() throws Exception {
Resource r = getLocalPlatformResource(false, false);

// Keep a copy of the old metrics.
MetricsResponse orignalMetrics = metricApi.getMetrics(r);
MetricsResponse orignalMetrics = metricApi.getMetrics(r, false);

MetricsResponse metrics = metricApi.getMetrics(r);
MetricsResponse metrics = metricApi.getMetrics(r, false);
hqAssertSuccess(metrics);

Metric disabledMetric = null;
Expand All @@ -187,7 +187,7 @@ public void testSyncEnable() throws Exception {
}
}

assertNotNull("Unable to find enabled metric for " + r.getName(),
assertNotNull("Unable to find disabled metric for " + r.getName(),
disabledMetric);

disabledMetric.setEnabled(true);
Expand Down Expand Up @@ -235,7 +235,7 @@ public void testSyncInvalidInterval() throws Exception {
MetricApi metricApi = api.getMetricApi();
Resource r = getLocalPlatformResource(false, false);

MetricsResponse metrics = metricApi.getMetrics(r);
MetricsResponse metrics = metricApi.getMetrics(r, true);
hqAssertSuccess(metrics);

assertTrue("No metrics found for " + r.getName(),
Expand Down
4 changes: 2 additions & 2 deletions src/org/hyperic/hq/hqapi1/tools/MetricCommand.java
Expand Up @@ -95,9 +95,9 @@ private void list(String[] args) throws Exception {

MetricsResponse metrics;
if (options.has(OPT_ENABLED)) {
metrics = metricApi.getEnabledMetrics(resourceResponse.getResource());
metrics = metricApi.getMetrics(resourceResponse.getResource(), true);
} else {
metrics = metricApi.getMetrics(resourceResponse.getResource());
metrics = metricApi.getMetrics(resourceResponse.getResource(), false);
}

XmlUtil.serialize(metrics, System.out, Boolean.TRUE);
Expand Down

0 comments on commit 5260db2

Please sign in to comment.