From: <rm...@hy...> - 2009-03-31 17:22:56
|
Author: rmorgan Date: 2009-03-31 10:22:40 -0700 (Tue, 31 Mar 2009) New Revision: 554 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=554 Modified: trunk/hqu/hqapi1/app/AlertdefinitionController.groovy Log: Remove internal alert definition by name cache used for recovery alert 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] Modified: trunk/hqu/hqapi1/app/AlertdefinitionController.groovy =================================================================== --- trunk/hqu/hqapi1/app/AlertdefinitionController.groovy 2009-03-27 00:06:41 UTC (rev 553) +++ trunk/hqu/hqapi1/app/AlertdefinitionController.groovy 2009-03-31 17:22:40 UTC (rev 554) @@ -270,7 +270,7 @@ def sync(params) { def syncRequest = new XmlParser().parseText(getUpload('postdata')) - def definitionsByName = [:] + def definitions = [] for (xmlDef in syncRequest['AlertDefinition']) { def failureXml = null @@ -559,33 +559,23 @@ break } - def recoveryDef = definitionsByName[xmlCond.'@recover'] - if (recoveryDef) { - if (aeid.type == recoveryDef.appdefType && - aeid.id == recoveryDef.appdefId) { - acv.measurementId = recoveryDef.id + // 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 } - } 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 (!acv.measurementId) { failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND, "Unable to find recovery " + "with name '" + xmlCond.'@recover' + "'") - break } break @@ -687,14 +677,14 @@ 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) } } |