Search in sources :

Example 11 with InstanceGroup

use of com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup in project SimianArmy by Netflix.

the class TestCloudFormationChaosMonkey method testIsMaxTerminationCountExceeded.

@Test
public void testIsMaxTerminationCountExceeded() {
    TestChaosMonkeyContext ctx = new TestChaosMonkeyContext("cloudformation.properties");
    CloudFormationChaosMonkey chaos = new CloudFormationChaosMonkey(ctx);
    InstanceGroup group1 = new BasicInstanceGroup("new-group-TestGroup1-XCFNFNFNF", TestChaosMonkeyContext.CrawlerTypes.TYPE_D, "region", Collections.<TagDescription>emptyList());
    assertFalse(chaos.isMaxTerminationCountExceeded(group1));
}
Also used : TestChaosMonkeyContext(com.netflix.simianarmy.chaos.TestChaosMonkeyContext) InstanceGroup(com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup) Test(org.testng.annotations.Test)

Example 12 with InstanceGroup

use of com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup in project SimianArmy by Netflix.

the class TestCloudFormationChaosMonkey method testGetLastOptInMilliseconds.

@Test
public void testGetLastOptInMilliseconds() {
    TestChaosMonkeyContext ctx = new TestChaosMonkeyContext("cloudformation.properties");
    CloudFormationChaosMonkey chaos = new CloudFormationChaosMonkey(ctx);
    InstanceGroup group = new BasicInstanceGroup("new-group-TestGroup1-XCFNFNFNF", TestChaosMonkeyContext.CrawlerTypes.TYPE_D, "region", Collections.<TagDescription>emptyList());
    assertEquals(chaos.getLastOptInMilliseconds(group), EXPECTED_MILLISECONDS);
}
Also used : TestChaosMonkeyContext(com.netflix.simianarmy.chaos.TestChaosMonkeyContext) InstanceGroup(com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup) Test(org.testng.annotations.Test)

Example 13 with InstanceGroup

use of com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup in project SimianArmy by Netflix.

the class BasicChaosMonkey method terminateNow.

@Override
public Event terminateNow(String type, String name, ChaosType chaosType) throws FeatureNotEnabledException, InstanceGroupNotFoundException {
    Validate.notNull(type);
    Validate.notNull(name);
    cfg.reload(name);
    if (!isChaosMonkeyEnabled()) {
        String msg = String.format("Chaos monkey is not enabled for group %s [type %s]", name, type);
        LOGGER.info(msg);
        throw new FeatureNotEnabledException(msg);
    }
    String prop = NS + "terminateOndemand.enabled";
    if (cfg.getBool(prop)) {
        InstanceGroup group = findInstanceGroup(type, name);
        if (group == null) {
            throw new InstanceGroupNotFoundException(type, name);
        }
        Collection<String> instances = context().chaosInstanceSelector().select(group, 1.0);
        Validate.isTrue(instances.size() <= 1);
        if (instances.size() == 1) {
            return terminateInstance(group, instances.iterator().next(), chaosType);
        } else {
            throw new NotFoundException(String.format("No instance is found in group %s [type %s]", name, type));
        }
    } else {
        String msg = String.format("Group %s [type %s] does not allow on-demand termination, set %s=true", name, type, prop);
        LOGGER.info(msg);
        throw new FeatureNotEnabledException(msg);
    }
}
Also used : InstanceGroup(com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup)

Example 14 with InstanceGroup

use of com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup in project SimianArmy by Netflix.

the class BasicChaosMonkey method doMonkeyBusiness.

/** {@inheritDoc} */
@Override
public void doMonkeyBusiness() {
    context().resetEventReport();
    cfg.reload();
    if (!isChaosMonkeyEnabled()) {
        return;
    }
    for (InstanceGroup group : context().chaosCrawler().groups()) {
        if (isGroupEnabled(group)) {
            if (isMaxTerminationCountExceeded(group)) {
                continue;
            }
            double prob = getEffectiveProbability(group);
            Collection<String> instances = context().chaosInstanceSelector().select(group, prob / runsPerDay);
            for (String inst : instances) {
                if (isMaxTerminationCountExceeded(group)) {
                    break;
                }
                ChaosType chaosType = pickChaosType(context().cloudClient(), inst);
                if (chaosType == null) {
                    // This is surprising ... normally we can always just terminate it
                    LOGGER.warn("No chaos type was applicable to the instance: {}", inst);
                    continue;
                }
                terminateInstance(group, inst, chaosType);
            }
        }
    }
}
Also used : InstanceGroup(com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup)

Example 15 with InstanceGroup

use of com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup in project SimianArmy by Netflix.

the class TestBasicChaosMonkey method testEnabledAwithout1.

@Test
public void testEnabledAwithout1() {
    TestChaosMonkeyContext ctx = new TestChaosMonkeyContext("enabledAwithout1.properties");
    ChaosMonkey chaos = new BasicChaosMonkey(ctx);
    chaos.start();
    chaos.stop();
    List<InstanceGroup> selectedOn = ctx.selectedOn();
    List<String> terminated = ctx.terminated();
    Assert.assertEquals(selectedOn.size(), 1);
    Assert.assertEquals(selectedOn.get(0).type(), TestChaosMonkeyContext.CrawlerTypes.TYPE_A);
    Assert.assertEquals(selectedOn.get(0).name(), "name0");
    Assert.assertEquals(terminated.size(), 1);
    Assert.assertEquals(terminated.get(0), "0:i-123456789012345670");
}
Also used : ChaosMonkey(com.netflix.simianarmy.chaos.ChaosMonkey) TestChaosMonkeyContext(com.netflix.simianarmy.chaos.TestChaosMonkeyContext) InstanceGroup(com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup) Test(org.testng.annotations.Test)

Aggregations

InstanceGroup (com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup)25 Test (org.testng.annotations.Test)21 TestChaosMonkeyContext (com.netflix.simianarmy.chaos.TestChaosMonkeyContext)18 ChaosMonkey (com.netflix.simianarmy.chaos.ChaosMonkey)11 BasicInstanceGroup (com.netflix.simianarmy.basic.chaos.BasicInstanceGroup)4 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 TunableInstanceGroup (com.netflix.simianarmy.tunable.TunableInstanceGroup)2 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)1 Monkey (com.netflix.simianarmy.Monkey)1 MonkeyScheduler (com.netflix.simianarmy.MonkeyScheduler)1 BeforeTest (org.testng.annotations.BeforeTest)1