这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin:'eclipse-wtp'

buildscript {
repositories { mavenCentral() }
apply from: file('gradle/buildscript.gradle'), to: buildscript
apply from: file('gradle/buildscript.gradle'), to: buildscript
}

allprojects {
Expand All @@ -23,7 +23,7 @@ apply plugin: 'jetty'
apply plugin: 'eclipse'

dependencies {
// for the VMWareClient
// for the VMWareClient
compile 'com.cloudbees.thirdparty:vijava:5.0.0'
compile 'dom4j:dom4j:1.6.1'

Expand All @@ -34,10 +34,12 @@ dependencies {
compile 'org.slf4j:slf4j-api:1.6.4'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.2'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.2'
compile 'com.netflix.eureka:eureka-client:1.1.22'
compile('com.amazonaws:aws-java-sdk:1.3.11') {
exclude group:'org.codehaus.jackson'
}
compile 'commons-lang:commons-lang:2.6'
compile 'joda-time:joda-time:2.1'

testCompile 'org.testng:testng:6.3.1'
testCompile 'org.mockito:mockito-core:1.8.5'
Expand All @@ -53,12 +55,12 @@ dependencies {
}

test {
useTestNG()
useTestNG()
}

tasks.withType(Compile) {
options.compilerArgs << "-Xlint" << "-Werror"
}
}

import nl.javadude.gradle.plugins.license.License
tasks.withType(License).each { licenseTask ->
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.3-SNAPSHOT
version=2.4-SNAPSHOT
83 changes: 83 additions & 0 deletions src/main/java/com/netflix/simianarmy/AbstractEmailBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
*
* Copyright 2012 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netflix.simianarmy;

/** The abstract email builder. */
public abstract class AbstractEmailBuilder implements EmailBuilder {

@Override
public String buildEmailBody(String emailAddress) {
StringBuilder body = new StringBuilder();
String header = getHeader();
if (header != null) {
body.append(header);
}
String entryTable = getEntryTable(emailAddress);
if (entryTable != null) {
body.append(entryTable);
}
String footer = getFooter();
if (footer != null) {
body.append(footer);
}
return body.toString();
}

/**
* Gets the header to the email body.
*/
protected abstract String getHeader();

/**
* Gets the table of entries in the email body.
* @param emailAddress the email address to notify
* @return the HTML string representing the table for the resources to send to the
* email address
*/
protected abstract String getEntryTable(String emailAddress);

/**
* Gets the footer of the email body.
*/
protected abstract String getFooter();

/**
* Gets the HTML cell in the table of a string value.
* @param value the string to put in the table
* @return the HTML text
*/
protected String getHtmlCell(String value) {
return "<td style=\"padding: 4px\">" + value + "</td>";
}

/**
* Gets the HTML string displaying the table header with the specified column names.
* @param columns the column names for the table
*/
protected String getHtmlTableHeader(String[] columns) {
StringBuilder tableHeader = new StringBuilder();
tableHeader.append(
"<table border=\"1\" style=\"border-width:1px; border-spacing: 0px; border-collapse: seperate;\">");
tableHeader.append("<tr style=\"background-color: #E8E8E8;\" >");
for (String col : columns) {
tableHeader.append(getHtmlCell(col));
}
tableHeader.append("</tr>");
return tableHeader.toString();
}
}
41 changes: 40 additions & 1 deletion src/main/java/com/netflix/simianarmy/CloudClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
*/
package com.netflix.simianarmy;

import java.util.Map;


/**
* The CloudClient interface. This abstractions provides the interface that the monkeys need to interact with
* "the cloud".
*/
public interface CloudClient {

/**
* Terminate instance.
* Terminates instance.
*
* @param instanceId
* the instance id
Expand All @@ -34,4 +37,40 @@ public interface CloudClient {
* should get a NotFoundException
*/
void terminateInstance(String instanceId);

/**
* Deletes an auto scaling group.
*
* @param asgName
* the auto scaling group name
*/
void deleteAutoScalingGroup(String asgName);

/**
* Deletes a volume.
*
* @param volumeId
* the volume id
*/
void deleteVolume(String volumeId);

/**
* Deletes a snapshot.
*
* @param snapshotId
* the snapshot id.
*/
void deleteSnapshot(String snapshotId);

/**
* Adds or overwrites tags for the specified resources.
*
* @param keyValueMap
* the new tags in the form of map from key to value
*
* @param resourceIds
* the list of resource ids
*/
void createTagsForResources(Map<String, String> keyValueMap, String... resourceIds);

}
28 changes: 28 additions & 0 deletions src/main/java/com/netflix/simianarmy/EmailBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* Copyright 2012 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netflix.simianarmy;

/** Interface for build the email body. */
public interface EmailBuilder {
/**
* Builds an email body for an email address.
* @param emailAddress the email address to send notification to
* @return the email body
*/
String buildEmailBody(String emailAddress);
}
14 changes: 12 additions & 2 deletions src/main/java/com/netflix/simianarmy/Monkey.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ public interface Context {
*/
String getEventReport();

/**
* Configuration.
*
* @return the monkey configuration
*/
MonkeyConfiguration configuration();
}

/** The context. */
private Context ctx;
private final Context ctx;

/**
* Instantiates a new monkey.
Expand Down Expand Up @@ -127,7 +133,10 @@ public void run() {
try {
this.doMonkeyBusiness();
} finally {
LOGGER.info("Reporting what I did...\n" + context().getEventReport());
String eventReport = context().getEventReport();
if (eventReport != null) {
LOGGER.info("Reporting what I did...\n" + eventReport);
}
}
} else {
LOGGER.info("Not Time for " + this.type().name() + " Monkey");
Expand All @@ -140,6 +149,7 @@ public void run() {
public void start() {
final Monkey me = this;
ctx.scheduler().start(this, new Runnable() {
@Override
public void run() {
try {
me.run();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/netflix/simianarmy/MonkeyCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.netflix.simianarmy;

import java.util.Calendar;
import java.util.Date;

/**
* The Interface MonkeyCalendar used to tell if a monkey should be running or now. We only want monkeys to run during
Expand Down Expand Up @@ -54,4 +55,12 @@ public interface MonkeyCalendar {
* @return the calendar
*/
Calendar now();

/** Gets the next business day from the start date after n business days.
*
* @param date the start date
* @param n the number of business days from now
* @return the business day after n business days
*/
Date getBusinessDay(Date date, int n);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/** The interface for the email notifier used by monkeys. */
public interface MonkeyEmailNotifier {

/**
* Determines if a email address is valid.
* @param email the email
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/netflix/simianarmy/MonkeyRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public interface Event {
*
* @param name
* the name
* @return the string assiciated with that field
* @return the string associated with that field
*/
String field(String name);

Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/netflix/simianarmy/MonkeyRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public void stop() {
* The monkey map. Maps the monkey class to the context class that is registered. This is so we can create new
* monkeys in factory() that have the same context types as the registered ones.
*/
// SUPPRESS CHECKSTYLE LineLength
private Map<Class<? extends Monkey>, Class<? extends Monkey.Context>> monkeyMap = new HashMap<Class<? extends Monkey>, Class<? extends Monkey.Context>>();
private final Map<Class<? extends Monkey>, Class<? extends Monkey.Context>> monkeyMap =
new HashMap<Class<? extends Monkey>, Class<? extends Monkey.Context>>();

/** The monkeys. */
private List<Monkey> monkeys = new LinkedList<Monkey>();
private final List<Monkey> monkeys = new LinkedList<Monkey>();

/**
* Gets the registered monkeys.
Expand Down Expand Up @@ -171,12 +171,11 @@ public void removeMonkey(Class<? extends Monkey> monkeyClass) {
* Example:
*
* <pre>
* {@code
* MonkeyRunner.getInstance().addMonkey(BasicChaosMonkey.class, BasicMonkeyContext.class);
*
* // This will actualy return a BasicChaosMonkey since that is the only subclass that was registered
* ChaosMonkey monkey = MonkeyRunner.getInstance().factory(ChaosMonkey.class);
* }
* {@code
* MonkeyRunner.getInstance().addMonkey(BasicChaosMonkey.class, BasicMonkeyContext.class);
* // This will actually return a BasicChaosMonkey since that is the only subclass that was registered
* ChaosMonkey monkey = MonkeyRunner.getInstance().factory(ChaosMonkey.class);
*}
* </pre>
*
* @param <T>
Expand Down Expand Up @@ -240,7 +239,7 @@ public <T extends Monkey> T factory(Class<T> monkeyClass, Class<? extends Monkey
}

/**
* Gets the context class. You shouldnt need this.
* Gets the context class. You should not need this.
*
* @param monkeyClass
* the monkey class
Expand Down
Loading