Skip to content

Commit b9dfdba

Browse files
committed
* adding src and tests
1 parent 2ac2de7 commit b9dfdba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2551
-22
lines changed

GNUmakefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
reformat:
2+
eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config $(shell pwd)/codequality/org.eclipse.jdt.core.prefs $(shell pwd)/src
3+
find $(shell pwd)/src -name \*.java | xargs perl -pi -e 's/{ /{/g; s/(\S) }/$$1}/g'

build.gradle

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Establish version and status
2-
ext.releaseVersion = '1.1.3' // TEMPLATE: Set to latest release
3-
ext.githubProjectName = name // TEMPLATE: change to match github project, if it doesn't match project name
4-
group = "com.netflix.${githubProjectName}" // TEMPLATE: Set to organization of project
2+
ext.releaseVersion = '2.2'
3+
ext.githubProjectName = name
4+
group = "com.netflix.${githubProjectName}"
55

66
buildscript {
77
repositories { mavenCentral() }
@@ -41,7 +41,19 @@ dependencies {
4141
compile 'com.sun.jersey:jersey-core:1.11'
4242
compile 'com.sun.jersey:jersey-server:1.11'
4343
compile 'com.sun.jersey:jersey-servlet:1.11'
44+
compile 'org.slf4j:slf4j-api:1.6.3'
45+
compile 'com.amazonaws:aws-java-sdk:1.2.1'
46+
4447
testCompile 'org.testng:testng:6.1.1'
4548
testCompile 'org.mockito:mockito-core:1.8.5'
49+
50+
// needed for findbug Missing Class: org.slf4j.impl.StaticLoggerBinder
51+
providedCompile 'org.slf4j:slf4j-log4j12:1.6.3'
52+
providedCompile "javax.servlet:servlet-api:2.5"
53+
// needed for findbug Missing Class: javax.annotation.Nonnull
54+
providedCompile "com.google.code.findbugs:jsr305:1.3.9"
4655
}
4756

57+
test {
58+
useTestNG()
59+
}

codequality/checkstyle.xml

+18-18
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@
4343

4444
<!-- Checks for Javadoc comments. -->
4545
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
46-
<module name="JavadocMethod">
47-
<property name="scope" value="package"/>
48-
<property name="allowMissingParamTags" value="true"/>
49-
<property name="allowMissingThrowsTags" value="true"/>
50-
<property name="allowMissingReturnTag" value="true"/>
51-
<property name="allowThrowsTagsForSubclasses" value="true"/>
52-
<property name="allowUndeclaredRTE" value="true"/>
53-
<property name="allowMissingPropertyJavadoc" value="true"/>
54-
</module>
55-
<module name="JavadocType">
56-
<property name="scope" value="package"/>
57-
</module>
58-
<module name="JavadocVariable">
59-
<property name="scope" value="package"/>
60-
</module>
61-
<module name="JavadocStyle">
62-
<property name="checkEmptyJavadoc" value="true"/>
63-
</module>
46+
<!-- <module name="JavadocMethod"> -->
47+
<!-- <property name="scope" value="package"/> -->
48+
<!-- <property name="allowMissingParamTags" value="true"/> -->
49+
<!-- <property name="allowMissingThrowsTags" value="true"/> -->
50+
<!-- <property name="allowMissingReturnTag" value="true"/> -->
51+
<!-- <property name="allowThrowsTagsForSubclasses" value="true"/> -->
52+
<!-- <property name="allowUndeclaredRTE" value="true"/> -->
53+
<!-- <property name="allowMissingPropertyJavadoc" value="true"/> -->
54+
<!-- </module> -->
55+
<!-- <module name="JavadocType"> -->
56+
<!-- <property name="scope" value="package"/> -->
57+
<!-- </module> -->
58+
<!-- <module name="JavadocVariable"> -->
59+
<!-- <property name="scope" value="package"/> -->
60+
<!-- </module> -->
61+
<!-- <module name="JavadocStyle"> -->
62+
<!-- <property name="checkEmptyJavadoc" value="true"/> -->
63+
<!-- </module> -->
6464

6565
<!-- Checks for Naming Conventions. -->
6666
<!-- See http://checkstyle.sf.net/config_naming.html -->

codequality/org.eclipse.jdt.core.prefs

+287
Large diffs are not rendered by default.

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name='gradle-template-single'
1+
rootProject.name='simianarmy'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
*
3+
* Copyright 2012 Netflix, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
package com.netflix.simianarmy;
19+
20+
public interface CloudClient {
21+
void terminateInstance(String instanceId);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
*
3+
* Copyright 2012 Netflix, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
package com.netflix.simianarmy;
19+
20+
public abstract class Monkey {
21+
public interface Context {
22+
MonkeyScheduler scheduler();
23+
24+
MonkeyCalendar calendar();
25+
26+
CloudClient cloudClient();
27+
}
28+
29+
private Context ctx;
30+
31+
public Monkey(Context ctx) {
32+
this.ctx = ctx;
33+
}
34+
35+
public abstract String name();
36+
37+
public abstract void doMonkeyBusiness();
38+
39+
public void start() {
40+
final Monkey me = this;
41+
ctx.scheduler().start(name(), new Runnable() {
42+
public void run() {
43+
if (ctx.calendar().isMonkeyTime(me)) {
44+
me.doMonkeyBusiness();
45+
}
46+
}
47+
});
48+
}
49+
50+
public void stop() {
51+
ctx.scheduler().stop(name());
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* Copyright 2012 Netflix, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
package com.netflix.simianarmy;
19+
20+
import java.util.Calendar;
21+
22+
public interface MonkeyCalendar {
23+
boolean isMonkeyTime(Monkey monkey);
24+
25+
int openHour();
26+
27+
int closeHour();
28+
29+
Calendar now();
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* Copyright 2012 Netflix, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
package com.netflix.simianarmy;
19+
20+
public interface MonkeyConfiguration {
21+
boolean getBool(String property);
22+
23+
boolean getBoolOrElse(String property, boolean dflt);
24+
25+
double getNumOrElse(String property, double dflt);
26+
27+
String getStr(String property);
28+
29+
String getStrOrElse(String property, String dflt);
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* Copyright 2012 Netflix, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
package com.netflix.simianarmy;
19+
20+
import java.util.concurrent.TimeUnit;
21+
22+
public interface MonkeyScheduler {
23+
int frequency();
24+
25+
TimeUnit frequencyUnit();
26+
27+
void start(String name, Runnable run);
28+
29+
void stop(String name);
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
*
3+
* Copyright 2012 Netflix, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
package com.netflix.simianarmy.aws;
19+
20+
import java.util.Arrays;
21+
import java.util.List;
22+
import java.util.LinkedList;
23+
24+
import com.netflix.simianarmy.CloudClient;
25+
26+
import com.amazonaws.services.ec2.AmazonEC2;
27+
import com.amazonaws.services.ec2.AmazonEC2Client;
28+
import com.amazonaws.services.ec2.model.TerminateInstancesRequest;
29+
30+
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
31+
import com.amazonaws.services.autoscaling.model.AutoScalingGroup;
32+
import com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest;
33+
import com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult;
34+
35+
import com.amazonaws.auth.BasicAWSCredentials;
36+
import com.amazonaws.auth.AWSCredentials;
37+
38+
public class AmazonClient implements CloudClient {
39+
private AWSCredentials cred;
40+
private String region;
41+
42+
public AmazonClient(String accessKey, String secretKey, String region) {
43+
this.cred = new BasicAWSCredentials(accessKey, secretKey);
44+
this.region = region;
45+
}
46+
47+
public AmazonClient(AWSCredentials cred, String region) {
48+
this.cred = cred;
49+
this.region = region;
50+
}
51+
52+
protected AmazonEC2 ec2Client() {
53+
AmazonEC2 client = new AmazonEC2Client(cred);
54+
client.setEndpoint("ec2." + region + ".amazonaws.com");
55+
return client;
56+
}
57+
58+
protected AmazonAutoScalingClient asgClient() {
59+
AmazonAutoScalingClient client = new AmazonAutoScalingClient(cred);
60+
client.setEndpoint("autoscaling" + region + ".amazonaws.com");
61+
return client;
62+
}
63+
64+
public List<AutoScalingGroup> describeAutoScalingGroups() {
65+
List<AutoScalingGroup> asgs = new LinkedList<AutoScalingGroup>();
66+
67+
AmazonAutoScalingClient asgClient = asgClient();
68+
DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
69+
DescribeAutoScalingGroupsResult result = asgClient.describeAutoScalingGroups(request);
70+
asgs.addAll(result.getAutoScalingGroups());
71+
while (result.getNextToken() != null) {
72+
request = request.withNextToken(result.getNextToken());
73+
result = asgClient.describeAutoScalingGroups(request);
74+
asgs.addAll(result.getAutoScalingGroups());
75+
}
76+
77+
return asgs;
78+
}
79+
80+
public void terminateInstance(String instanceId) {
81+
ec2Client().terminateInstances(new TerminateInstancesRequest(Arrays.asList(instanceId)));
82+
}
83+
}

0 commit comments

Comments
 (0)