return result;
}
private int injectStorageNodeHighHeapTemplate(ResourceType resourceType) {
AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
AlertDefinition newTemplate = new AlertDefinition();
newTemplate.setName(storageNodeHighHeapTemplate.getName());
newTemplate.setResourceType(resourceType);
newTemplate.setPriority(AlertPriority.MEDIUM);
newTemplate.setConditionExpression(BooleanExpression.ANY);
newTemplate.setDescription(storageNodeHighHeapTemplate.getDescription());
newTemplate.setRecoveryId(0);
newTemplate.setEnabled(true);
AlertCondition ac = new AlertCondition();
ac.setCategory(AlertConditionCategory.THRESHOLD);
ac.setComparator(">");
ac.setThreshold(0.75D);
List<Integer> measurementDefinitionIds = new ArrayList<Integer>(2);
for (MeasurementDefinition d : resourceType.getMetricDefinitions()) {
if ("Calculated.HeapUsagePercentage".equals(d.getName())) {
measurementDefinitionIds.add(d.getId());
ac.setMeasurementDefinition(d);
ac.setName(d.getDisplayName());
} else if ("{HeapMemoryUsage.used}".equals(d.getName())) {
measurementDefinitionIds.add(d.getId());
}
}
assert null != ac.getMeasurementDefinition() : "Did not find expected measurement definition [Calculated.HeapUsagePercentage] for "
+ resourceType;
newTemplate.addCondition(ac);
AlertDampening dampener = new AlertDampening(AlertDampening.Category.PARTIAL_COUNT);
dampener.setPeriod(15);
dampener.setPeriodUnits(TimeUnits.MINUTES);
dampener.setValue(10);
newTemplate.setAlertDampening(dampener);
int newTemplateId = alertTemplateManager.createAlertTemplate(subjectManager.getOverlord(), newTemplate,
resourceType.getId());
// additionally, we want to ensure that the metric is enabled and collecting at a more frequent interval than
// is set by default.
MeasurementScheduleManagerLocal measurementManager = LookupUtil.getMeasurementScheduleManager();