@@ -0,0 +1,2832 @@
+/*%0A *%0A *  Copyright 2012 Netflix, Inc.%0A *%0A *     Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *     you may not use this file except in compliance with the License.%0A *     You may obtain a copy of the License at%0A *%0A *         http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *     Unless required by applicable law or agreed to in writing, software%0A *     distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *     See the License for the specific language governing permissions and%0A *     limitations under the License.%0A *%0A */%0A%0Apackage com.netflix.simianarmy.aws.janitor.rule.instance;%0A%0Aimport com.netflix.simianarmy.Resource;%0Aimport com.netflix.simianarmy.aws.AWSResource;%0Aimport com.netflix.simianarmy.janitor.JanitorMonkey;%0Aimport com.netflix.simianarmy.janitor.Rule;%0Aimport org.apache.commons.lang.Validate;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A/**%0A * The rule for checking the tags associated with an instance.%0A */%0Apublic class TaggedInstanceRule implements Rule %7B%0A%0A    /** The Constant LOGGER. */%0A    private static final Logger LOGGER = LoggerFactory.getLogger(TaggedInstanceRule.class);%0A%0A    @SuppressWarnings(%22UnusedDeclaration%22)%0A    private static final String TERMINATION_REASON = %22Tag(s) associated with this instance%22;%0A%0A    /**%0A     * Constructor for TaggedInstanceRule.%0A     *%0A     */%0A    @SuppressWarnings(%22UnusedDeclaration%22)%0A    public TaggedInstanceRule() %7B%0A    %7D%0A%0A    @Override%0A    public boolean isValid(Resource resource) %7B%0A        Validate.notNull(resource);%0A        if (!resource.getResourceType().name().equals(%22INSTANCE%22)) %7B%0A            // The rule is supposed to only work on AWS instances. If a non-instance resource%0A            // is passed to the rule, the rule simply ignores it and considers it as a valid%0A            // resource not for cleanup.%0A            return true;%0A        %7D%0A        String awsStatus = ((AWSResource) resource).getAWSResourceState();%0A        if (!%22running%22.equals(awsStatus) %7C%7C %22pending%22.equals(awsStatus)) %7B%0A            return true;%0A        %7D%0A        // The instance can have a special tag is it wants to be cleaned up%0A        // by Janitor monkey.%0A%0A        // if the instance is labelled cleanup=true%0A        String cleanupTag = resource.getTag(JanitorMonkey.CLEANUP_TAG);%0A        if (cleanupTag != null) %7B%0A            if (%22true%22.equals(cleanupTag)) %7B%0A                LOGGER.info(String.format(%22The instance %25s tagged as cleanup handled by Janitor%22, resource.getId()));%0A                return false;%0A            %7D   else   %7B%0A                LOGGER.info(String.format(%22The instance %25s is not tagged for cleanup handled by Janitor.%22, resource.getId()));%0A                return true;%0A            %7D%0A        %7D else%0A            return true;%0A    %7D%0A%7D

Add config