Search in sources :

Example 1 with FeatureNotEnabledException

use of com.netflix.simianarmy.FeatureNotEnabledException 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;
}
Also used : Response(javax.ws.rs.core.Response) InstanceGroupNotFoundException(com.netflix.simianarmy.InstanceGroupNotFoundException) FeatureNotEnabledException(com.netflix.simianarmy.FeatureNotEnabledException) Event(com.netflix.simianarmy.MonkeyRecorder.Event) NotFoundException(com.netflix.simianarmy.NotFoundException) InstanceGroupNotFoundException(com.netflix.simianarmy.InstanceGroupNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FeatureNotEnabledException (com.netflix.simianarmy.FeatureNotEnabledException)1 InstanceGroupNotFoundException (com.netflix.simianarmy.InstanceGroupNotFoundException)1 Event (com.netflix.simianarmy.MonkeyRecorder.Event)1 NotFoundException (com.netflix.simianarmy.NotFoundException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1