Skip to content

Commit

Permalink
[HHQ-3962] Allow deletion of alerts in bulk via stdin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed May 4, 2010
1 parent 0d2a510 commit 6cb3f30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
@@ -1,6 +1,8 @@

Changes in HQApi 3.2

*) [HHQ-3962] Allow deletion of alerts in bulk via stdin.

*) Updated MetricDataApi to get metrics data summary for a resource
or group within a specified time range. Functionality added primarily
to do integration testing for HHQ-3803 and HHQ-3748. No
Expand Down
26 changes: 22 additions & 4 deletions src/org/hyperic/hq/hqapi1/tools/AlertCommand.java
Expand Up @@ -30,11 +30,14 @@
import joptsimple.OptionParser;
import joptsimple.OptionSet;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

import org.hyperic.hq.hqapi1.HQApi;
import org.hyperic.hq.hqapi1.XmlUtil;
import org.hyperic.hq.hqapi1.AlertApi;
import org.hyperic.hq.hqapi1.types.Alert;
import org.hyperic.hq.hqapi1.types.AlertsResponse;
import org.hyperic.hq.hqapi1.types.ResourceResponse;
import org.hyperic.hq.hqapi1.types.StatusResponse;
Expand Down Expand Up @@ -221,11 +224,26 @@ private void delete(String[] args) throws Exception {
HQApi api = getApi(options);
AlertApi alertApi = api.getAlertApi();

Integer id = (Integer)getRequired(options, OPT_ID);
if (options.has(OPT_ID)) {
Integer id = (Integer)getRequired(options, OPT_ID);
StatusResponse response = alertApi.delete(id);
checkSuccess(response);
System.out.println("Successfully deleted alert id " + id);
} else {
// Delete via stdin
InputStream is = getInputStream(options);

StatusResponse response = alertApi.delete(id);
checkSuccess(response);
AlertsResponse resp = XmlUtil.deserialize(AlertsResponse.class, is);
List<Alert> alerts = resp.getAlert();

System.out.println("Successfully deleted alert id " + id);
Integer[] alertIds = new Integer[alerts.size()];
for (int i = 0; i < alerts.size(); i++) {
alertIds[i] = alerts.get(i).getId();
}

StatusResponse response = alertApi.delete(alertIds);
checkSuccess(response);
System.out.println("Successfully deleted " + alertIds.length + " alerts");
}
}
}

0 comments on commit 6cb3f30

Please sign in to comment.