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;
}
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;
}
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);
}
}
}
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;
}
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;
}
Aggregations