diff --git a/src/main/java/com/netflix/simianarmy/janitor/AbstractJanitor.java b/src/main/java/com/netflix/simianarmy/janitor/AbstractJanitor.java index 0197f0dc..fbc4a7f2 100644 --- a/src/main/java/com/netflix/simianarmy/janitor/AbstractJanitor.java +++ b/src/main/java/com/netflix/simianarmy/janitor/AbstractJanitor.java @@ -62,7 +62,7 @@ public abstract class AbstractJanitor implements Janitor { /** The Constant LOGGER. */ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJanitor.class); - + /** Tags to attach to servo metrics */ @MonitorTags protected TagList tags; @@ -72,7 +72,7 @@ public abstract class AbstractJanitor implements Janitor { public String getRegion() { return region; } - + /** * The rule engine used to decide if a resource should be a cleanup * candidate. @@ -106,7 +106,7 @@ public String getRegion() { private boolean leashed; private final MonkeyRecorder recorder; - + /** The number of resources that have been checked on this run. */ private int checkedResourcesCount; @@ -198,41 +198,41 @@ public AbstractJanitor(Context ctx, ResourceType resourceType) { Validate.notNull(resourceType); // recorder could be null and no events are recorded when it is. this.recorder = ctx.recorder(); - + // setup servo tags, currently just tag each published metric with the region - this.tags = BasicTagList.of("simianarmy.janitor.region", ctx.region()); - + this.tags = BasicTagList.of("simianarmy.janitor.region", ctx.region()); + // register this janitor with servo String monitorObjName = String.format("simianarmy.janitor.%s.%s", this.resourceType.name(), this.region); - Monitors.registerObject(monitorObjName, this); + Monitors.registerObject(monitorObjName, this); } @Override public ResourceType getResourceType() { return resourceType; } - + /** * Clears this object's internal resource lists in preparation for a new * run. - * - * This is an optional method as regular Janitor processing will - * automatically clear resource lists as it runs. - * + * + * This is an optional method as regular Janitor processing will + * automatically clear resource lists as it runs. + * * This method offers an explicit clear so that the resources will be * consistent across the run. For example, when starting a run after a - * previous run has finished, cleanedResources will be holding the cleaned - * resources from the prior run until cleanupResources() is called. By + * previous run has finished, cleanedResources will be holding the cleaned + * resources from the prior run until cleanupResources() is called. By * calling prepareToRun() first, the resource lists will be consistent * for the entire run. */ public void prepareToRun() { - markedResources.clear(); + markedResources.clear(); unmarkedResources.clear(); - checkedResourcesCount = 0; + checkedResourcesCount = 0; cleanedResources.clear(); failedToCleanResources.clear(); - } + } /** * Marks all resources obtained from the crawler as cleanup candidate if @@ -240,7 +240,7 @@ public void prepareToRun() { */ @Override public void markResources() { - markedResources.clear(); + markedResources.clear(); unmarkedResources.clear(); checkedResourcesCount = 0; Map trackedMarkedResources = getTrackedMarkedResources(); @@ -263,12 +263,12 @@ public void markResources() { resource.setState(CleanupState.MARKED); resource.setMarkTime(now); if (!leashed) { + resourceTracker.addOrUpdate(resource); if (recorder != null) { Event evt = recorder.newEvent(Type.JANITOR, EventTypes.MARK_RESOURCE, region, resource.getId()); addFieldsAndTagsToEvent(resource, evt); recorder.recordEvent(evt); } - resourceTracker.addOrUpdate(resource); postMark(resource); } else { LOGGER.info(String.format( @@ -282,13 +282,13 @@ public void markResources() { LOGGER.info(String.format("Unmarking resource %s", resource.getId())); resource.setState(CleanupState.UNMARKED); if (!leashed) { + resourceTracker.addOrUpdate(resource); if (recorder != null) { Event evt = recorder.newEvent( Type.JANITOR, EventTypes.UNMARK_RESOURCE, region, resource.getId()); addFieldsAndTagsToEvent(resource, evt); recorder.recordEvent(evt); } - resourceTracker.addOrUpdate(resource); } else { LOGGER.info(String.format( "The janitor is leashed, no data change is made for unmarking the resource %s.", @@ -360,7 +360,7 @@ public void cleanupResources() { } } - /** + /** * Adds selected resource fields and all the tags from the given resource as additional fields on the event. * @param resource the resource with the the source data * @param event the event that will hold the source data as additional fields @@ -373,7 +373,7 @@ private void addFieldsAndTagsToEvent(Resource resource, Event event) { } } event.addField("ResourceDescription", resource.getDescription()); - event.addField("ResourceType", resource.getResourceType().toString()); + event.addField("ResourceType", resource.getResourceType().toString()); } /** Determines if the input resource can be cleaned. The Janitor calls this method @@ -460,7 +460,7 @@ private void unmarkUserTerminatedResources( } } } - + @Monitor(name="cleanedResourcesCount", type=DataSourceType.GAUGE) public int getResourcesCleanedCount() { return cleanedResources.size(); @@ -474,16 +474,16 @@ public int getMarkedResourcesCount() { @Monitor(name="failedToCleanResourcesCount", type=DataSourceType.GAUGE) public int getFailedToCleanResourcesCount() { return failedToCleanResources.size(); - } + } @Monitor(name="unmarkedResourcesCount", type=DataSourceType.GAUGE) public int getUnmarkedResourcesCount() { return unmarkedResources.size(); - } - + } + @Monitor(name="checkedResourcesCount", type=DataSourceType.GAUGE) public int getCheckedResourcesCount() { return checkedResourcesCount; - } - + } + }