/**
* Takes the instance off the network.
*/
@Override
public void apply(ChaosInstance instance) {
CloudClient cloudClient = instance.getCloudClient();
String instanceId = instance.getInstanceId();
if (!cloudClient.canChangeInstanceSecurityGroups(instanceId)) {
throw new IllegalStateException("canApply should have returned false");
}
String groupId = cloudClient.findSecurityGroup(instance.getInstanceId(), blockedSecurityGroupName);
if (groupId == null) {
LOGGER.info("Auto-creating security group {}", blockedSecurityGroupName);
String description = "Empty security group for blocked instances";
groupId = cloudClient.createSecurityGroup(instance.getInstanceId(), blockedSecurityGroupName, description);
}
LOGGER.info("Blocking network traffic by applying security group {} to instance {}", groupId, instanceId);
List<String> groups = Lists.newArrayList();
groups.add(groupId);
cloudClient.setInstanceSecurityGroups(instanceId, groups);
}