throw e;
}
}
public static void configureAlarm(Folder rootFolder) throws Exception {
AlarmManager alarmManager = VcContext.getService().getAlarmManager();
// Create the alarm for VHM
String SERENGETI_UUID = rootFolder.getName(); /* should be the name of the folder clusters get deployed into */
String ALARM_CLEARED_MSG = "all health issues previously reported by Big Data Extensions are in remission";
EventAlarmExpression raiseExpression = new EventAlarmExpressionImpl();
raiseExpression.setEventType(new TypeNameImpl("vim.event.EventEx"));
raiseExpression.setEventTypeId("com.vmware.vhadoop.vhm.vc.events.warning");
raiseExpression.setStatus(ManagedEntity.Status.yellow);
raiseExpression.setObjectType(new TypeNameImpl("vim.VirtualMachine"));
EventAlarmExpression clearExpression = new EventAlarmExpressionImpl();
clearExpression.setEventType(new TypeNameImpl("vim.event.EventEx"));
clearExpression.setEventTypeId("com.vmware.vhadoop.vhm.vc.events.info");
clearExpression.setComparisons(new EventAlarmExpressionImpl.ComparisonImpl[] {
new EventAlarmExpressionImpl.ComparisonImpl("message", "endsWith", ALARM_CLEARED_MSG)
});
clearExpression.setStatus(ManagedEntity.Status.green);
clearExpression.setObjectType(new TypeNameImpl("vim.VirtualMachine"));
OrAlarmExpression or = new OrAlarmExpressionImpl();
or.setExpression(new AlarmExpression[] {raiseExpression, clearExpression});
AlarmTriggeringAction alarmAction = new AlarmTriggeringActionImpl();
alarmAction.setAction(null);
TransitionSpec tSpec = new AlarmTriggeringActionImpl.TransitionSpecImpl();
tSpec.setRepeats(false);
tSpec.setStartState(Status.green);
tSpec.setFinalState(Status.yellow);
alarmAction.setTransitionSpecs(new TransitionSpec[] { tSpec });
alarmAction.setGreen2yellow(true);
AlarmSpec spec = new AlarmSpecImpl();
spec.setActionFrequency(0);
spec.setExpression(or);
/* the name has to be unique, but we need a way to find any matching
alarms later so we use a known prefix */
String alarmName = "BDE Health " + SERENGETI_UUID;
if (alarmName.length() > 80) {
alarmName = alarmName.substring(0, 80);
}
spec.setName(alarmName);
spec.setSystemName(null);
spec.setDescription("Indicates a health issue with a compute VM managed by Big Data Extensions. The specific health issue is detailed in a warning event in the event log.");
spec.setEnabled(true);
AlarmSetting as = new AlarmSettingImpl();
as.setReportingFrequency(0);
as.setToleranceRange(0);
spec.setSetting(as);
ManagedObjectReference[] existingAlarms = alarmManager.getAlarm(rootFolder._getRef());
Alarm existing = null;
try {
if (existingAlarms != null) {
for (ManagedObjectReference m : existingAlarms) {
Alarm a = MoUtil.getManagedObject(m);
if (a.getInfo().getName().equals(alarmName)) {
existing = a;
break;
}
}
}
} catch (NullPointerException e) {
// this just saves a lot of null checks
logger.error("Got NullPointerException when querying alarms", e);
}
try {
if (existing != null) {
existing.reconfigure(spec);
logger.info("Alarm " + alarmName + " exists");
} else {
ManagedObjectReference alarmMoref = alarmManager.create(rootFolder._getRef(), spec);
logger.info("Create " + alarmMoref.getValue() + " " + alarmName);
}
} catch (InvalidName e) {
logger.error("Invalid alarm name", e);
} catch (DuplicateName e) {