Skip to content

Commit

Permalink
Fix alert find methods to account for bad rounding done in AlertManag…
Browse files Browse the repository at this point in the history
…erEJBImpl. Increase performance of generateAlerts(), allow for Escalations to be specified.
  • Loading branch information
Ryan Morgan committed Oct 1, 2009
1 parent 9c26cfc commit e1b50d3
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 143 deletions.
19 changes: 14 additions & 5 deletions hqu/hqapi1/app/AlertController.groovy
Expand Up @@ -13,6 +13,8 @@ public class AlertController extends ApiController {
private aMan = AlertMan.one
private escMan = EscMan.one

private static final int ROUNDING_VOODOO = 60000

private getEscalationState(alert) {
// TODO: Move to AlertCategory
if (alert.stateId) {
Expand Down Expand Up @@ -71,11 +73,14 @@ public class AlertController extends ApiController {
try {
Integer groupId = null
AlertSeverity severity = AlertSeverity.findByCode(sev)
long timerange = end - begin
PageInfo pInfo = PageInfo.create(0, count, AlertSortField.DATE,
false);

alerts = alertHelper.findAlerts(severity, timerange, end,
// TODO: Work around incorrect TimingVoodoo in AlertManagerEJBImpl
long roundedEnd = end + (ROUNDING_VOODOO - (end % ROUNDING_VOODOO))
long timerange = roundedEnd - begin

alerts = alertHelper.findAlerts(severity, timerange, roundedEnd,
inEsc, notFixed, groupId, pInfo)
} catch (IllegalStateException e) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS,
Expand All @@ -93,7 +98,8 @@ public class AlertController extends ApiController {
out << failureXml
} else {
out << getSuccessXML()
for (a in alerts) {
// TODO: See above, re-apply the actual end time
for (a in alerts.findAll { it.ctime <= end }) {
out << getAlertXML(a)
}
}
Expand Down Expand Up @@ -130,7 +136,9 @@ public class AlertController extends ApiController {
"Unable to find resource with " +
"id=" + rid)
} else {
alerts = resource.getAlerts(user, begin, end,
// TODO: Work around incorrect TimingVoodoo in AlertManagerEJBImpl
long roundedEnd = end + (ROUNDING_VOODOO - (end % ROUNDING_VOODOO))
alerts = resource.getAlerts(user, begin, roundedEnd,
count, severity)
//TODO: Move these to ResourceCategory or AlertManager
if (inEsc) {
Expand All @@ -157,7 +165,8 @@ public class AlertController extends ApiController {
out << failureXml
} else {
out << getSuccessXML()
for (a in alerts) {
// TODO: See above, re-apply the actual end time
for (a in alerts.findAll { it.ctime <= end }) {
out << getAlertXML(a)
}
}
Expand Down
38 changes: 23 additions & 15 deletions src/org/hyperic/hq/hqapi1/test/AlertAck_test.java
Expand Up @@ -5,6 +5,7 @@
import org.hyperic.hq.hqapi1.types.Alert;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.Escalation;
import org.hyperic.hq.hqapi1.AlertApi;

public class AlertAck_test extends AlertTestBase {
Expand All @@ -14,32 +15,39 @@ public AlertAck_test(String name) {
}

public void testAckAlert() throws Exception {
Resource platform = getLocalPlatformResource(false, false);
AlertDefinition d = generateAlerts(platform);
AlertApi api = getAlertApi();
Resource platform = getLocalPlatformResource(false, false);
Escalation e = createEscalation();
Alert a = generateAlerts(platform);

validateAlert(a);

// Test ack - alert will be in Escalation
StatusResponse ackResponse = api.ackAlert(a.getId(), "Test ACK", 60000l);
hqAssertSuccess(ackResponse);

AlertsResponse response = api.findAlerts(platform, 0, System.currentTimeMillis(),
10, 1, false, false);
hqAssertSuccess(response);
assertTrue(response.getAlert().size() <= 10);
assertTrue(response.getAlert().size() > 0);
// TODO: Valididate ack? Will require a getById API.

// Cleanup
deleteAlertDefinitionByAlert(a);
deleteEscalation(e);
}

for (Alert a : response.getAlert()) {
validateAlert(a);
}
public void testAckUnacknowledableAlert() throws Exception {
Resource platform = getLocalPlatformResource(false, false);
AlertApi api = getAlertApi();
Alert a = generateAlerts(platform);

// Test ack
Alert a = response.getAlert().get(0);
validateAlert(a);

// Test ack - alert is not in escalation
StatusResponse ackResponse = api.ackAlert(a.getId(), "Test ACK", 60000l);
hqAssertSuccess(ackResponse);

// TODO: Valididate ack? Will require a getById API.

// Cleanup
StatusResponse deleteResponse = getApi().
getAlertDefinitionApi().deleteAlertDefinition(d.getId());
hqAssertSuccess(deleteResponse);
deleteAlertDefinitionByAlert(a);
}

public void testAckInvalidAlert() throws Exception {
Expand Down
40 changes: 8 additions & 32 deletions src/org/hyperic/hq/hqapi1/test/AlertDelete_test.java
Expand Up @@ -17,66 +17,42 @@ public AlertDelete_test(String name) {
}

public void testDeleteAlert() throws Exception {
Resource platform = getLocalPlatformResource(false, false);
AlertDefinition d = generateAlerts(platform);
AlertApi api = getAlertApi();
Resource platform = getLocalPlatformResource(false, false);
Alert a = generateAlerts(platform);

AlertsResponse response = api.findAlerts(platform, 0, System.currentTimeMillis(),
10, 1, false, false);
hqAssertSuccess(response);
assertTrue(response.getAlert().size() <= 10);
assertTrue(response.getAlert().size() > 0);
validateAlert(a);

for (Alert a : response.getAlert()) {
validateAlert(a);
}

// Test delete
Alert a = response.getAlert().get(0);

StatusResponse deleteResponse = api.delete(a.getId());
hqAssertSuccess(deleteResponse);

// TODO: Valididate alert was deleted? Will require a getById API.

// Cleanup
StatusResponse deleteDefResponse = getApi().
getAlertDefinitionApi().deleteAlertDefinition(d.getId());
hqAssertSuccess(deleteDefResponse);
deleteAlertDefinitionByAlert(a);
}

public void testDeleteAlertNoPermission() throws Exception {
Resource platform = getLocalPlatformResource(false, false);
AlertDefinition d = generateAlerts(platform);
AlertApi api = getAlertApi();
Resource platform = getLocalPlatformResource(false, false);
Alert a = generateAlerts(platform);

AlertsResponse response = api.findAlerts(platform, 0, System.currentTimeMillis(),
10, 1, false, false);
hqAssertSuccess(response);
assertTrue(response.getAlert().size() <= 10);
assertTrue(response.getAlert().size() > 0);

for (Alert a : response.getAlert()) {
validateAlert(a);
}
validateAlert(a);

// Test delete with an unprivledged user

List<User> users = createTestUsers(1);
User unprivUser = users.get(0);
AlertApi apiUnpriv = getApi(unprivUser.getName(), TESTUSER_PASSWORD).getAlertApi();

Alert a = response.getAlert().get(0);
StatusResponse deleteResponse = apiUnpriv.delete(a.getId());
hqAssertFailurePermissionDenied(deleteResponse);

// TODO: Valididate alert was deleted? Will require a getById API.

// Cleanup
StatusResponse deleteDefResponse = getApi().
getAlertDefinitionApi().deleteAlertDefinition(d.getId());
hqAssertSuccess(deleteDefResponse);

deleteAlertDefinitionByAlert(a);
deleteTestUsers(users);
}

Expand Down
10 changes: 4 additions & 6 deletions src/org/hyperic/hq/hqapi1/test/AlertFindByResource_test.java
Expand Up @@ -15,7 +15,7 @@ public AlertFindByResource_test(String name) {

public void testFindValid() throws Exception {
Resource r = getLocalPlatformResource(false, false);
AlertDefinition d = generateAlerts(r);
Alert a = generateAlerts(r);

AlertApi api = getAlertApi();

Expand All @@ -25,14 +25,12 @@ public void testFindValid() throws Exception {
assertTrue(response.getAlert().size() <= 10);
assertTrue(response.getAlert().size() > 0);

for (Alert a : response.getAlert()) {
validateAlert(a);
for (Alert alerts : response.getAlert()) {
validateAlert(alerts);
}

// Cleanup
StatusResponse deleteResponse = getApi().getAlertDefinitionApi().
deleteAlertDefinition(d.getId());
hqAssertSuccess(deleteResponse);
deleteAlertDefinitionByAlert(a);
}

public void testFindInvalidSeverity() throws Exception {
Expand Down
12 changes: 5 additions & 7 deletions src/org/hyperic/hq/hqapi1/test/AlertFind_test.java
Expand Up @@ -14,24 +14,22 @@ public AlertFind_test(String name) {
}

public void testFindValid() throws Exception {
Resource platform = getLocalPlatformResource(false, false);
AlertDefinition d = generateAlerts(platform);
AlertApi api = getAlertApi();
Resource platform = getLocalPlatformResource(false, false);
Alert a = generateAlerts(platform);

AlertsResponse response = api.findAlerts(0, System.currentTimeMillis(),
10, 1, false, false);
hqAssertSuccess(response);
assertTrue(response.getAlert().size() <= 10);
assertTrue(response.getAlert().size() > 0);

for (Alert a : response.getAlert()) {
validateAlert(a);
for (Alert alerts : response.getAlert()) {
validateAlert(alerts);
}

// Cleanup
StatusResponse deleteResponse = getApi().
getAlertDefinitionApi().deleteAlertDefinition(d.getId());
hqAssertSuccess(deleteResponse);
deleteAlertDefinitionByAlert(a);
}

public void testFindInvalidSeverity() throws Exception {
Expand Down

0 comments on commit e1b50d3

Please sign in to comment.