这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import com.netflix.simianarmy.Monkey;
import com.sun.jersey.spi.resource.Singleton;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonGenerator;
Expand All @@ -52,13 +54,14 @@
* The Class ChaosMonkeyResource for json REST apis.
*/
@Path("/v1/chaos")
@Singleton
public class ChaosMonkeyResource {

/** The Constant JSON_FACTORY. */
private static final MappingJsonFactory JSON_FACTORY = new MappingJsonFactory();

/** The monkey. */
private final ChaosMonkey monkey;
private ChaosMonkey monkey = null;

/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory.getLogger(ChaosMonkeyResource.class);
Expand All @@ -77,7 +80,16 @@ public ChaosMonkeyResource(ChaosMonkey monkey) {
* Instantiates a chaos monkey resource using a registered chaos monkey from factory.
*/
public ChaosMonkeyResource() {
this.monkey = MonkeyRunner.getInstance().factory(ChaosMonkey.class);
for (Monkey runningMonkey : MonkeyRunner.getInstance().getMonkeys()) {
if (runningMonkey instanceof ChaosMonkey) {
this.monkey = (ChaosMonkey) runningMonkey;
break;
}
}
if (this.monkey == null) {
LOGGER.info("Creating a new Chaos monkey instance for the resource.");
this.monkey = MonkeyRunner.getInstance().factory(ChaosMonkey.class);
}
}

/**
Expand Down