From: <rm...@hy...> - 2009-02-11 01:09:27
|
Author: rmorgan Date: 2009-02-10 17:09:16 -0800 (Tue, 10 Feb 2009) New Revision: 533 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=533 Modified: trunk/hqu/hqapi1/app/AlertdefinitionController.groovy trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSyncRecoveryCondition_test.java Log: Do not require that recovery alerts to have both sides of the recovery in the sync XML. If the alert cannot be found in the prior list of synced AlertDefinitions, check the Resource if it exists from a prior sync. Modified: trunk/hqu/hqapi1/app/AlertdefinitionController.groovy =================================================================== --- trunk/hqu/hqapi1/app/AlertdefinitionController.groovy 2009-02-09 22:30:23 UTC (rev 532) +++ trunk/hqu/hqapi1/app/AlertdefinitionController.groovy 2009-02-11 01:09:16 UTC (rev 533) @@ -274,7 +274,7 @@ for (xmlDef in syncRequest['AlertDefinition']) { def failureXml = null - def resource // Can be a resource or a prototype in the case of type alerts + def resource = null // Can be a resource or a prototype in the case of type alerts boolean typeBased def existing = null Integer id = xmlDef.'@id'?.toInteger() @@ -560,7 +560,6 @@ break } - // TODO: This requires both recovery alerts to be in the sync. (And ordered) def recoveryDef = definitionsByName[xmlCond.'@recover'] if (recoveryDef) { if (aeid.type == recoveryDef.appdefType && @@ -568,9 +567,24 @@ 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 + } + } + failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND, "Unable to find recovery " + - " with name '" + + "with name '" + xmlCond.'@recover' + "'") break } Modified: trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSyncRecoveryCondition_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSyncRecoveryCondition_test.java 2009-02-09 22:30:23 UTC (rev 532) +++ trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSyncRecoveryCondition_test.java 2009-02-11 01:09:16 UTC (rev 533) @@ -69,6 +69,57 @@ cleanup(response.getAlertDefinition()); } + public void testSyncRecoveryWithoutProblemDef() throws Exception { + + HQApi api = getApi(); + AlertDefinitionApi defApi = api.getAlertDefinitionApi(); + MetricApi metricApi = api.getMetricApi(); + + Resource platform = getLocalPlatformResource(false, false); + + MetricsResponse metricsResponse = metricApi.getMetrics(platform); + hqAssertSuccess(metricsResponse); + assertTrue("No metrics found for " + platform.getName(), + metricsResponse.getMetric().size() > 0); + Metric m = metricsResponse.getMetric().get(0); + + + // First sync the problem definition + AlertDefinition def = generateTestDefinition(); + def.setResource(platform); + final double THRESHOLD = 0; + def.getAlertCondition().add( + AlertDefinitionBuilder.createThresholdCondition(true, m.getName(), + AlertComparator.GREATER_THAN, + THRESHOLD)); + + List<AlertDefinition> definitions = new ArrayList<AlertDefinition>(); + definitions.add(def); + AlertDefinitionsResponse downResponse = defApi.syncAlertDefinitions(definitions); + hqAssertSuccess(downResponse); + + // Next, sync the recovery + AlertDefinition recoveryDef = generateTestDefinition(); + recoveryDef.setResource(platform); + AlertCondition threshold = + AlertDefinitionBuilder.createThresholdCondition(true, m.getName(), + AlertComparator.LESS_THAN, + THRESHOLD); + AlertCondition recovery = + AlertDefinitionBuilder.createRecoveryCondition(true, def); + recoveryDef.getAlertCondition().add(threshold); + recoveryDef.getAlertCondition().add(recovery); + + definitions.clear(); + definitions.add(recoveryDef); + AlertDefinitionsResponse recoveryResponse = defApi.syncAlertDefinitions(definitions); + hqAssertSuccess(recoveryResponse); + + // cleanup + cleanup(downResponse.getAlertDefinition()); + cleanup(recoveryResponse.getAlertDefinition()); + } + // TODO: Type alert // TODO: Missing attributes |