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));
}
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);
}
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);
}
}
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);
}
}
}
}
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");
}
Aggregations