Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove internal alert definition by name cache used for recovery aler…

…t lookups. Instead

query the resource in question for the definition by that name.  This fixes problems where
a sync file may have many problem/recoveries and may not be in order.
[HHQ-2973]
  • Loading branch information...
commit c00ce09ae4e453ac264891c4e676e20e166b7c0f 1 parent b4cbd70
Ryan Morgan authored
Showing with 15 additions and 25 deletions.
  1. +15 −25 hqu/hqapi1/app/AlertdefinitionController.groovy
View
40 hqu/hqapi1/app/AlertdefinitionController.groovy
@@ -297,7 +297,7 @@ public class AlertdefinitionController extends ApiController {
def sync(params) {
def syncRequest = new XmlParser().parseText(getUpload('postdata'))
- def definitionsByName = [:]
+ def definitions = []
for (xmlDef in syncRequest['AlertDefinition']) {
def failureXml = null
@@ -610,33 +610,23 @@ public class AlertdefinitionController extends ApiController {
break
}
- def recoveryDef = definitionsByName[xmlCond.'@recover']
- if (recoveryDef) {
- if (aeid.type == recoveryDef.appdefType &&
- aeid.id == recoveryDef.appdefId) {
- acv.measurementId = recoveryDef.id
- }
- } else {
- // Attempt to look for the name of alert on the
- // given resource.
- if (resource) {
- log.warn("Recovery alert " +
- xmlCond.'@recover' + " not found " +
- "in sync XML, checking resource.")
- def resourceDefs = resource.getAlertDefinitions(user)
- def recovery = resourceDefs.find { it.name == xmlCond.'@recover' }
- if (recovery) {
- log.info("Found definition " + recovery.id)
- acv.measurementId = recovery.id
- break
- }
+ // If a resource alert, look up alert by name
+ if (resource) {
+ log.debug("Looking up alerts for resource=" + resource.id)
+ def resourceDefs = resource.getAlertDefinitions(user)
+ def recovery = resourceDefs.find { it.name == xmlCond.'@recover' }
+ if (recovery) {
+ log.info("Found recovery definition " + recovery.id)
+ acv.measurementId = recovery.id
+ break
}
+ }
+ if (!acv.measurementId) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Unable to find recovery " +
"with name '" +
xmlCond.'@recover' + "'")
- break
}
break
@@ -738,14 +728,14 @@ public class AlertdefinitionController extends ApiController {
pojo.unsetEscalation(user)
}
- // Keep defs around so we don't need to look up recovery alerts
- definitionsByName[pojo.name] = pojo
+ // Keep synced defintions for sync return XML
+ definitions << pojo
}
renderXml() {
out << AlertDefinitionsResponse() {
out << getSuccessXML()
- for (alertdef in definitionsByName.values()) {
+ for (alertdef in definitions) {
out << getAlertDefinitionXML(alertdef, false)
}
}

0 comments on commit c00ce09

Please sign in to comment.
Something went wrong with that request. Please try again.