这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
42aa4a2
Merge branch 'dont_email_foo_bar_com'
justinsb Sep 13, 2013
1122660
Make the chaos type pluggable
justinsb Sep 13, 2013
5f50099
Add chaos strategy that detaches all EBS volumes
justinsb Sep 13, 2013
db75c28
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
b6ec42f
Log ChaosType
justinsb Sep 13, 2013
bb71d00
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
877a615
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
c7b8e7e
Merge branch 'auto_create_simpledb_domain'
justinsb Sep 13, 2013
8abee27
A bunch of checkstyle fixes
justinsb Sep 13, 2013
1aac368
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
83a610e
Better Javadoc on ShutdownInstanceChaosType
justinsb Sep 13, 2013
39eacc1
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
6a10de9
More checkstyle fixes
justinsb Sep 13, 2013
8653ed7
Working around findbugs / checkstyle issues
justinsb Sep 13, 2013
56003a7
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
b47ca83
Add DetachVolumes to strategy list
justinsb Sep 13, 2013
63a2233
Fix Checkstyle issue
justinsb Sep 13, 2013
18e3a83
Merge branch 'auto_create_simpledb_domain'
justinsb Sep 13, 2013
38a5d90
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
5df001d
Avoid FindBugs warnings
justinsb Sep 13, 2013
7ac9c69
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
d560090
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
e319181
Actually use the ChaosType we chose
justinsb Sep 13, 2013
872075d
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
0d36918
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
f3a72cb
Exclude root EBS volume in the chaos strategy
justinsb Sep 13, 2013
1494b44
Initial commit on jclouds support
justinsb Sep 13, 2013
fa56dc5
A bit more jclouds exposed
justinsb Sep 13, 2013
60595e7
Adding a strategy that puts instances in an unreachable security group
justinsb Sep 13, 2013
1b4aae3
Merge branch 'block_network_chaos_type'
justinsb Sep 13, 2013
56a6b73
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
bf2234a
Log if detach volumes wasn't able to run
justinsb Sep 13, 2013
1f1855d
Log if detach volumes wasn't able to run
justinsb Sep 13, 2013
e1ac912
Set instance id in ModifyInstanceRequest
justinsb Sep 13, 2013
4ddf10c
Set instance id in ModifyInstanceRequest
justinsb Sep 13, 2013
a81d133
Merge branch 'block_network_chaos_type'
justinsb Sep 13, 2013
cdf4169
Each strategy can be enabled / disabled through a config key
justinsb Sep 13, 2013
6cb18cf
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
ba9861b
Enable detachvolumes in default configuration
justinsb Sep 13, 2013
8eb39cf
Merge branch 'pluggable_chaos_type' into block_network_chaos_type
justinsb Sep 13, 2013
9cc3fa3
Set BlockAllNetworkTrafficChaosType to enabled in config
justinsb Sep 13, 2013
bf7e0b8
Merge branch 'block_network_chaos_type'
justinsb Sep 13, 2013
3c8fc71
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
65898fe
Remove singleton
justinsb Sep 13, 2013
86f4652
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 13, 2013
0ef718b
Merge branch 'pluggable_chaos_type' into block_network_chaos_type
justinsb Sep 13, 2013
46a1956
Merge branch 'block_network_chaos_type'
justinsb Sep 13, 2013
06de659
Merge branch 'simulate_ebs_failure'
justinsb Sep 13, 2013
8764f78
Merge branch 'upstream'
justinsb Sep 14, 2013
83170ab
Merge branch 'upstream' into pluggable_chaos_type
justinsb Sep 14, 2013
f794995
Default ShutdownInstance chaos type to enabled
justinsb Sep 14, 2013
09590bc
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 14, 2013
0560928
Merge branch 'pluggable_chaos_type' into block_network_chaos_type
justinsb Sep 14, 2013
cafca39
Merge branch 'block_network_chaos_type'
justinsb Sep 14, 2013
f9be9bf
Merge branch 'simulate_ebs_failure'
justinsb Sep 14, 2013
9a94df8
We want to specify a security group name, but we have to use an ID.
justinsb Sep 14, 2013
24d3d38
Merge branch 'block_network_chaos_type'
justinsb Sep 14, 2013
51f3f30
Rename the list of chaosTypes field.
justinsb Sep 14, 2013
fa2fb5f
Merge branch 'pluggable_chaos_type' into block_network_chaos_type
justinsb Sep 14, 2013
683c991
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 14, 2013
d2473b2
Merge branch 'simulate_ebs_failure'
justinsb Sep 14, 2013
4c5e6df
Merge branch 'block_network_chaos_type'
justinsb Sep 14, 2013
027ce92
Be mindful of VPC ids in BlockAllNetworkTraffixChaosType
justinsb Sep 14, 2013
228af7b
Log enabled status of ChaosTypes
justinsb Sep 14, 2013
d6b56ab
Merge branch 'pluggable_chaos_type' into block_network_chaos_type
justinsb Sep 14, 2013
18c9aab
Merge branch 'block_network_chaos_type'
justinsb Sep 14, 2013
01218c6
Merge branch 'pluggable_chaos_type' into simulate_ebs_failure
justinsb Sep 14, 2013
1c33d0e
Merge branch 'simulate_ebs_failure'
justinsb Sep 14, 2013
86b9392
Reverting an accidental (blank) line deletion
justinsb Sep 14, 2013
f6f9a3c
Merge branch 'block_network_chaos_type'
justinsb Sep 14, 2013
e7d7c42
I moved setting security groups into AwsClient, but forgot to remove …
justinsb Sep 14, 2013
c4ad5e8
Merge branch 'block_network_chaos_type'
justinsb Sep 14, 2013
cc52e80
Merge branch 'use_jclouds'
justinsb Sep 14, 2013
bc1a63b
Expose jClouds compute context
justinsb Sep 14, 2013
24d2a5a
Another chaos type: burn cpu
justinsb Sep 14, 2013
8626201
Checkstyle fixes
justinsb Sep 14, 2013
8cc6982
Make code uglier to keep PMD happy
justinsb Sep 14, 2013
28fedff
Avoid hitting unsupported methods in the mocks
justinsb Sep 14, 2013
2d5f9c6
Lazy-init jclouds because of ... you guessed it ... the mocks
justinsb Sep 14, 2013
a98f8a3
Abstracted out common code into ScriptChaosType
justinsb Sep 14, 2013
9e83d8f
Chaos Strategy: Kill processes
justinsb Sep 14, 2013
f50f619
Created null route chaos type
justinsb Sep 14, 2013
3b20c8e
Add KillProcesses chaos type to list of chaos types
justinsb Sep 14, 2013
cdb41d7
Merge branch 'kill_processes_chaos_type' into null_route_chaos_type
justinsb Sep 14, 2013
fe25bd0
Added null route chaos type to enabled chaos types
justinsb Sep 14, 2013
b93cf61
Add a lot of new chaos types, using the script support
justinsb Sep 15, 2013
f1172f8
Enable all the chaos strategies by default
justinsb Sep 15, 2013
bd63196
Make sure everything is clearly Apache licensed
justinsb Sep 15, 2013
7a6366b
Change the default for force-detach EBS volumes to false.
justinsb Sep 15, 2013
3c62917
FailEc2 is a better name than FailApi
justinsb Sep 15, 2013
19da83b
Add other S3 endpoints, per review by coryb
justinsb Sep 27, 2013
1506829
Ensure default for all new strategies is disabled
justinsb Sep 27, 2013
40fad4f
Check for isEnabled before check canApply
justinsb Sep 27, 2013
17dcd4b
Don't try to use BlockNetworkTrafficChaosType on non-VPC instances
justinsb Sep 27, 2013
748c697
Refactor a strongly-typed wrapper around cloud, instance & ssh config
justinsb Sep 27, 2013
2631987
Checkstyle fixes
justinsb Sep 30, 2013
1e9eab8
Skip invalid regions for SimpleDB auto-create, to speed up unit test
justinsb Sep 30, 2013
0f201fe
Include the chaos type in the notification emails, use that for the f…
justinsb Sep 30, 2013
1d6ef8b
Move SshClient to CloudClient, to enable mocking
justinsb Sep 30, 2013
28c418a
Include the full exception when the chaos monkey fails
justinsb Sep 30, 2013
d4374ed
Work around broken TestNG classloader
justinsb Sep 30, 2013
990f342
Each tested chaos monkey script must now include the name of the monkey
justinsb Sep 30, 2013
2a96712
Checkstyle etc fixes
justinsb Sep 30, 2013
d07ca40
Add tests for all chaos monkey types
justinsb Sep 30, 2013
a6a991a
Fix DetachVolumes test
justinsb Sep 30, 2013
bca81a9
Refactor security group changing code into CloudClient, so we can moc…
justinsb Sep 30, 2013
bae857f
Add notes on the activities which can cost money and where we maybe w…
justinsb Sep 30, 2013
66c112a
Remove todos from unit tests
justinsb Sep 30, 2013
449ef17
Support burnmoney option, so users must opt-in to activities which wi…
justinsb Sep 30, 2013
cd29175
Checkstyle fixes
justinsb Sep 30, 2013
de561f8
PMD fixes
justinsb Sep 30, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ dependencies {
compile 'com.google.guava:guava:11.+'
compile 'org.apache.httpcomponents:httpclient:4.2.1'
compile 'org.apache.httpcomponents:httpcore:4.2.1'
compile 'org.jclouds:jclouds-all:1.6.0'
compile 'org.jclouds.driver:jclouds-jsch:1.6.0'
compile 'org.jclouds.driver:jclouds-slf4j:1.6.0'

testCompile 'org.testng:testng:6.3.1'
testCompile 'org.mockito:mockito-core:1.8.5'
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/com/netflix/simianarmy/CloudClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
*/
package com.netflix.simianarmy;

import java.util.List;
import java.util.Map;

import org.jclouds.compute.ComputeService;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.ssh.SshClient;

/**
* The CloudClient interface. This abstractions provides the interface that the monkeys need to interact with
Expand Down Expand Up @@ -88,4 +92,108 @@ public interface CloudClient {
*/
void createTagsForResources(Map<String, String> keyValueMap, String... resourceIds);

/**
* Lists all EBS volumes attached to the specified instance.
*
* @param instanceId
* the instance id
* @param includeRoot
* if the root volume is on EBS, should we include it?
*
* @throws NotFoundException
* if the instance no longer exists or was already terminated after the crawler discovered it then you
* should get a NotFoundException
*/
List<String> listAttachedVolumes(String instanceId, boolean includeRoot);

/**
* Detaches an EBS volumes from the specified instance.
*
* @param instanceId
* the instance id
* @param volumeId
* the volume id
* @param force
* if we should force-detach the volume. Probably best not to use on high-value volumes.
*
* @throws NotFoundException
* if the instance no longer exists or was already terminated after the crawler discovered it then you
* should get a NotFoundException
*/
void detachVolume(String instanceId, String volumeId, boolean force);

/**
* Returns the jClouds compute service.
*/
ComputeService getJcloudsComputeService();

/**
* Returns the jClouds node id for an instance id on this CloudClient.
*/
String getJcloudsId(String instanceId);

/**
* Opens an SSH connection to an instance.
*
* @param instanceId
* instance id to connect to
* @param credentials
* SSH credentials to use
* @return {@link SshClient}, in connected state
*/
SshClient connectSsh(String instanceId, LoginCredentials credentials);

/**
* Finds a security group with the given name, that can be applied to the given instance.
*
* For example, if it is a VPC instance, it makes sure that it is in the same VPC group.
*
* @param instanceId
* the instance that the group must be applied to
* @param groupName
* the name of the group to find
*
* @return The group id, or null if not found
*/
String findSecurityGroup(String instanceId, String groupName);

/**
* Creates an (empty) security group, that can be applied to the given instance.
*
* @param instanceId
* instance that group should be applicable to
* @param groupName
* name for new group
* @param description
* description for new group
*
* @return the id of the security group
*/
String createSecurityGroup(String instanceId, String groupName, String description);

/**
* Checks if we can change the security groups of an instance.
*
* @param instanceId
* instance to check
*
* @return true iff we can change security groups.
*/
boolean canChangeInstanceSecurityGroups(String instanceId);

/**
* Sets the security groups for an instance.
*
* Note this is only valid for VPC instances.
*
* @param instanceId
* the instance id
* @param groupIds
* ids of desired new groups
*
* @throws NotFoundException
* if the instance no longer exists or was already terminated after the crawler discovered it then you
* should get a NotFoundException
*/
void setInstanceSecurityGroups(String instanceId, List<String> groupIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ public List<Event> findEvents(Enum monkeyType, Enum eventType, Map<String, Strin
*/
public void init() {
try {
if (this.region == null || this.region.equals("region-null")) {
// This is a mock with an invalid region; avoid a slow timeout
LOGGER.debug("Region=null; skipping SimpleDB domain creation");
return;
}
ListDomainsResult listDomains = sdbClient().listDomains();
for (String d : listDomains.getDomainNames()) {
if (d.equals(domain)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.netflix.simianarmy.MonkeyConfiguration;
import com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup;
import com.netflix.simianarmy.chaos.ChaosEmailNotifier;
import com.netflix.simianarmy.chaos.ChaosType;

/** The basic implementation of the email notifier for Chaos monkey.
*
Expand Down Expand Up @@ -62,29 +63,31 @@ public BasicChaosEmailNotifier(MonkeyConfiguration cfg, AmazonSimpleEmailService
* email address.
* @param group the instance group
* @param instanceId the instance id
* @param chaosType the chosen chaos strategy
*/
@Override
public void sendTerminationGlobalNotification(InstanceGroup group, String instanceId) {
public void sendTerminationGlobalNotification(InstanceGroup group, String instanceId, ChaosType chaosType) {
String to = cfg.getStr("simianarmy.chaos.notification.global.receiverEmail");
if (StringUtils.isBlank(to)) {
LOGGER.warn("Global email address was not set, but global email notification was enabled!");
return;
}
LOGGER.info("sending termination notification to global email address {}", to);
buildAndSendEmail(to, group, instanceId);
buildAndSendEmail(to, group, instanceId, chaosType);
}

/**
* Sends an email notification for a termination of instance to the group
* owner's email address.
* @param group the instance group
* @param instanceId the instance id
* @param chaosType the chosen chaos strategy
*/
@Override
public void sendTerminationNotification(InstanceGroup group, String instanceId) {
public void sendTerminationNotification(InstanceGroup group, String instanceId, ChaosType chaosType) {
String to = getOwnerEmail(group);
LOGGER.info("sending termination notification to group owner email address {}", to);
buildAndSendEmail(to, group, instanceId);
buildAndSendEmail(to, group, instanceId, chaosType);
}

/**
Expand Down Expand Up @@ -113,9 +116,10 @@ protected String getOwnerEmail(InstanceGroup group) {
* the instance id
* @param to
* the email address to be sent to
* @param chaosType the chosen chaos strategy
*/
public void buildAndSendEmail(String to, InstanceGroup group, String instanceId) {
String body = buildEmailBody(group, instanceId);
public void buildAndSendEmail(String to, InstanceGroup group, String instanceId, ChaosType chaosType) {
String body = buildEmailBody(group, instanceId, chaosType);

String subject;
boolean emailSubjectIsBody = cfg.getBoolOrElse(
Expand Down Expand Up @@ -143,13 +147,20 @@ public String buildEmailSubject(String to) {
* the instance group
* @param instanceId
* the instance id
* @param chaosType the chosen chaos strategy
* @return the created string
*/
public String buildEmailBody(InstanceGroup group, String instanceId) {
public String buildEmailBody(InstanceGroup group, String instanceId, ChaosType chaosType) {
String emailBodyPrefix = cfg.getStrOrElse("simianarmy.chaos.notification.body.prefix", "");
String emailBodySuffix = cfg.getStrOrElse("simianarmy.chaos.notification.body.suffix", "");
String body = String.format("%sInstance %s of %s %s is being terminated by Chaos monkey.%s",
emailBodyPrefix, instanceId, group.type(), group.name(), emailBodySuffix);
String body = emailBodyPrefix;
body += String.format("Instance %s of %s %s is being terminated by Chaos monkey.",
instanceId, group.type(), group.name());
if (chaosType != null) {
body += "\n";
body += String.format("Chaos type: %s.", chaosType.getKey());
}
body += emailBodySuffix;
return body;
}

Expand Down
Loading