use of com.netflix.simianarmy.InstanceGroupNotFoundException in project SimianArmy by Netflix.
the class ChaosMonkeyResource method addTerminationEvent.
private Response.Status addTerminationEvent(String groupType, String groupName, ChaosType chaosType, JsonGenerator gen) throws IOException {
LOGGER.info("Running on-demand termination for instance group type '{}' and name '{}'", groupType, groupName);
Response.Status responseStatus;
try {
Event evt = monkey.terminateNow(groupType, groupName, chaosType);
if (evt != null) {
responseStatus = Response.Status.OK;
gen.writeStringField("monkeyType", evt.monkeyType().name());
gen.writeStringField("eventId", evt.id());
gen.writeNumberField("eventTime", evt.eventTime().getTime());
gen.writeStringField("region", evt.region());
for (Map.Entry<String, String> pair : evt.fields().entrySet()) {
gen.writeStringField(pair.getKey(), pair.getValue());
}
} else {
responseStatus = Response.Status.INTERNAL_SERVER_ERROR;
gen.writeStringField("message", String.format("Failed to terminate instance in group %s [type %s]", groupName, groupType));
}
} catch (FeatureNotEnabledException e) {
responseStatus = Response.Status.FORBIDDEN;
gen.writeStringField("message", e.getMessage());
} catch (InstanceGroupNotFoundException e) {
responseStatus = Response.Status.NOT_FOUND;
gen.writeStringField("message", e.getMessage());
} catch (NotFoundException e) {
// Available instance cannot be found to terminate, maybe the instance is already gone
responseStatus = Response.Status.GONE;
gen.writeStringField("message", e.getMessage());
}
LOGGER.info("On-demand termination completed.");
return responseStatus;
}
Aggregations