这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/main/java/com/netflix/simianarmy/janitor/AbstractJanitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -198,49 +198,49 @@ 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
* the janitor rule engine thinks so.
*/
@Override
public void markResources() {
markedResources.clear();
markedResources.clear();
unmarkedResources.clear();
checkedResourcesCount = 0;
Map<String, Resource> trackedMarkedResources = getTrackedMarkedResources();
Expand All @@ -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(
Expand All @@ -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.",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -460,7 +460,7 @@ private void unmarkUserTerminatedResources(
}
}
}

@Monitor(name="cleanedResourcesCount", type=DataSourceType.GAUGE)
public int getResourcesCleanedCount() {
return cleanedResources.size();
Expand All @@ -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;
}
}

}