Search in sources :

Example 6 with Event

use of com.netflix.simianarmy.MonkeyRecorder.Event in project SimianArmy by Netflix.

the class BasicChaosMonkey method createEvent.

private Event createEvent(EventTypes chaosTermination, InstanceGroup group, String instance) {
    Event evt = context().recorder().newEvent(Type.CHAOS, chaosTermination, group.region(), instance);
    evt.addField("groupType", group.type().name());
    evt.addField("groupName", group.name());
    return evt;
}
Also used : Event(com.netflix.simianarmy.MonkeyRecorder.Event)

Example 7 with Event

use of com.netflix.simianarmy.MonkeyRecorder.Event in project SimianArmy by Netflix.

the class BasicChaosMonkey method recordTermination.

/** {@inheritDoc} */
@Override
public Event recordTermination(InstanceGroup group, String instance, ChaosType chaosType) {
    Event evt = context().recorder().newEvent(Type.CHAOS, EventTypes.CHAOS_TERMINATION, group.region(), instance);
    evt.addField("groupType", group.type().name());
    evt.addField("groupName", group.name());
    evt.addField("chaosType", chaosType.getKey());
    context().recorder().recordEvent(evt);
    return evt;
}
Also used : Event(com.netflix.simianarmy.MonkeyRecorder.Event)

Example 8 with Event

use of com.netflix.simianarmy.MonkeyRecorder.Event in project SimianArmy by Netflix.

the class AbstractJanitor method cleanupResources.

/**
     * Cleans up all cleanup candidates that are OK to remove.
     */
@Override
public void cleanupResources() {
    cleanedResources.clear();
    failedToCleanResources.clear();
    Map<String, Resource> trackedMarkedResources = getTrackedMarkedResources();
    LOGGER.info(String.format("Checking %d marked resources for cleanup.", trackedMarkedResources.size()));
    Date now = calendar.now().getTime();
    for (Resource markedResource : trackedMarkedResources.values()) {
        if (canClean(markedResource, now)) {
            LOGGER.info(String.format("Cleaning up resource %s of type %s", markedResource.getId(), markedResource.getResourceType().name()));
            if (!leashed) {
                try {
                    cleanup(markedResource);
                    markedResource.setActualTerminationTime(now);
                    markedResource.setState(Resource.CleanupState.JANITOR_TERMINATED);
                    resourceTracker.addOrUpdate(markedResource);
                    if (recorder != null) {
                        Event evt = recorder.newEvent(Type.JANITOR, EventTypes.CLEANUP_RESOURCE, markedResource, markedResource.getId());
                        recorder.recordEvent(evt);
                    }
                } catch (Exception e) {
                    LOGGER.error(String.format("Failed to clean up the resource %s of type %s.", markedResource.getId(), markedResource.getResourceType().name()), e);
                    failedToCleanResources.add(markedResource);
                    continue;
                }
                postCleanup(markedResource);
            } else {
                LOGGER.info(String.format("The janitor is leashed, no data change is made for cleaning up the resource %s.", markedResource.getId()));
            }
            cleanedResources.add(markedResource);
        }
    }
}
Also used : Event(com.netflix.simianarmy.MonkeyRecorder.Event)

Example 9 with Event

use of com.netflix.simianarmy.MonkeyRecorder.Event in project SimianArmy by Netflix.

the class JanitorMonkeyResource method optInResource.

private Response.Status optInResource(String resourceId, boolean optIn, String region, JsonGenerator gen) throws IOException {
    String op = optIn ? "in" : "out";
    LOGGER.info(String.format("Opt %s resource %s for Janitor Monkey.", op, resourceId));
    Response.Status responseStatus;
    Event evt;
    if (optIn) {
        evt = getJanitorMonkey().optInResource(resourceId, region);
    } else {
        evt = getJanitorMonkey().optOutResource(resourceId, region);
    }
    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 opt %s resource %s", op, resourceId));
    }
    LOGGER.info(String.format("Opt %s operation completed.", op));
    return responseStatus;
}
Also used : Response(javax.ws.rs.core.Response) Event(com.netflix.simianarmy.MonkeyRecorder.Event) Map(java.util.Map)

Example 10 with Event

use of com.netflix.simianarmy.MonkeyRecorder.Event in project SimianArmy by Netflix.

the class VolumeTaggingMonkey method updateJanitorMetaTag.

private Event updateJanitorMetaTag(Volume volume, String instance, String owner, Date lastDetachTime, AWSClient awsClient) {
    String meta = makeMetaTag(instance, owner, lastDetachTime);
    Map<String, String> janitorTags = new HashMap<String, String>();
    janitorTags.put(JanitorMonkey.JANITOR_META_TAG, meta);
    LOGGER.info(String.format("Setting tag %s to '%s' for volume %s", JanitorMonkey.JANITOR_META_TAG, meta, volume.getVolumeId()));
    String prop = "simianarmy.volumeTagging.leashed";
    Event evt = null;
    if (config.getBoolOrElse(prop, true)) {
        LOGGER.info("Volume tagging monkey is leashed. No real change is made to the volume.");
    } else {
        try {
            awsClient.createTagsForResources(janitorTags, volume.getVolumeId());
            evt = context().recorder().newEvent(type(), EventTypes.TAGGING_JANITOR, awsClient.region(), volume.getVolumeId());
            evt.addField(JanitorMonkey.JANITOR_META_TAG, meta);
        } catch (Exception e) {
            LOGGER.error(String.format("Failed to update the tag for volume %s", volume.getVolumeId()));
        }
    }
    return evt;
}
Also used : HashMap(java.util.HashMap) Event(com.netflix.simianarmy.MonkeyRecorder.Event)

Aggregations

Event (com.netflix.simianarmy.MonkeyRecorder.Event)14 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Calendar (java.util.Calendar)2 Response (javax.ws.rs.core.Response)2 Tag (com.amazonaws.services.ec2.model.Tag)1 Volume (com.amazonaws.services.ec2.model.Volume)1 VolumeAttachment (com.amazonaws.services.ec2.model.VolumeAttachment)1 FeatureNotEnabledException (com.netflix.simianarmy.FeatureNotEnabledException)1 InstanceGroupNotFoundException (com.netflix.simianarmy.InstanceGroupNotFoundException)1 NotFoundException (com.netflix.simianarmy.NotFoundException)1 BasicRecorderEvent (com.netflix.simianarmy.basic.BasicRecorderEvent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 JsonGenerator (org.codehaus.jackson.JsonGenerator)1