Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Make Janitor Monkey ignore Stopped Instances/Resources #310

Open
truongvinhtien opened this issue Jan 18, 2018 · 1 comment
Open

Make Janitor Monkey ignore Stopped Instances/Resources #310

truongvinhtien opened this issue Jan 18, 2018 · 1 comment

Comments

@truongvinhtien
Copy link

truongvinhtien commented Jan 18, 2018

Hi,
I am new to SimianArmy, and my company required me to set the Janitor Monkey to shutting down the resources instead of terminating them so they can keep the data. I just merely edited some pieces of code in the AWSClient.java and InstanceJanitor.java so that it can stop the instance, and somehow it worked.
In the AWSClient.java:

@Override
    public void terminateInstance(String instanceId) {
        Validate.notEmpty(instanceId);
        LOGGER.info(String.format("Stopping instance %s in region %s.", instanceId, region));
        try {
            ec2Client().stopInstances(new StopInstancesRequest(Arrays.asList(instanceId)));
        } catch (AmazonServiceException e) {
            if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
                throw new NotFoundException("AWS instance " + instanceId + " not found", e);
            }
            throw e;
        }
    }   

In the InstanceJanitor.java

@Override
    protected void cleanup(Resource resource) {
        LOGGER.info(String.format("Stopping instance %s", resource.getId()));
        awsClient.terminateInstance(resource.getId());
    }

I wonder if there is any proper way to apply this method for all the resource types. Moreover, when I ran the Janitor Monkey again it also remarked the stopped instances for cleaning up. Can I implement the JM to ignore the stopped/inactive resources?

Many thanks.

@arpansolanki
Copy link

Check InstanceJanitorCrawler.java
You will have to modify it to only crawl running instances.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants