Here are the examples of the java api com.alibaba.chaosblade.exec.common.aop.EnhancerModel taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
55 Examples
19
View Complete Implementation : ConfigUtil.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
public static Boolean getActionFlag(EnhancerModel enhancerModel, String flagKey, Boolean defaultValue) {
String value = getActionFlag(enhancerModel, flagKey);
if (value == null) {
return defaultValue;
}
try {
return Boolean.parseBoolean(flagKey);
} catch (Exception ex) {
return defaultValue;
}
}
19
View Complete Implementation : JvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* real operation to create oom
*
* @param enhancerModel
*/
protected abstract void innerRun(EnhancerModel enhancerModel, JvmOomConfiguration jvmOomConfiguration);
19
View Complete Implementation : JvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(final EnhancerModel enhancerModel) throws Exception {
if (started.compareAndSet(false, true)) {
oomExceptionCounter.init();
final JvmOomConfiguration jvmOomConfiguration = parse(enhancerModel);
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "chaosblade-oom-thread");
}
});
executorService.submit(new Runnable() {
@Override
public void run() {
Long interval = calculateCostMemoryInterval(jvmOomConfiguration);
while (isStarted()) {
try {
innerRun(enhancerModel, jvmOomConfiguration);
if (interval > 0) {
TimeUnit.MILLISECONDS.sleep(interval);
}
} catch (Throwable throwable) {
handleThrowable(jvmOomConfiguration, throwable);
}
}
}
});
}
}
19
View Complete Implementation : JvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* real operation to stop oom
*
* @param enhancerModel
*/
protected abstract void innerStop(EnhancerModel enhancerModel);
19
View Complete Implementation : ConfigUtil.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
public static Integer getActionFlag(EnhancerModel enhancerModel, String flagKey, Integer defaultFlagValue) {
String value = getActionFlag(enhancerModel, flagKey);
if (value == null) {
return defaultFlagValue;
}
try {
return Integer.valueOf(value);
} catch (Exception ex) {
return defaultFlagValue;
}
}
19
View Complete Implementation : DubboEnhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
protected abstract void postDoBeforeAdvice(EnhancerModel enhancerModel);
19
View Complete Implementation : JvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void stop(EnhancerModel enhancerModel) throws Exception {
if (started.compareAndSet(true, false)) {
if (executorService == null) {
return;
}
safelyShutdownExecutor(executorService);
innerStop(enhancerModel);
oomExceptionCounter.reset();
}
}
18
View Complete Implementation : JvmOomExecutorFacade.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void stop(EnhancerModel enhancerModel) throws Exception {
selectExecutor(enhancerModel).stop(enhancerModel);
}
18
View Complete Implementation : ConfigUtil.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
public static String getActionFlag(EnhancerModel enhancerModel, String flagKey, String defaultFlagValue) {
String value = enhancerModel.getActionFlag(flagKey);
if (value == null) {
return defaultFlagValue;
}
return value;
}
18
View Complete Implementation : JvmOomActionSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void createInjection(String expId, Model model) throws Exception {
EnhancerModel enhancerModel = new EnhancerModel(EnhancerModel.clreplaced.getClreplacedLoader(), model.getMatcher());
enhancerModel.merge(model);
getActionExecutor().run(enhancerModel);
}
18
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
private ClreplacedLoader getClreplacedLoader(ScriptTypeEnum scriptType, EnhancerModel enhancerModel) {
ClreplacedLoader loader = enhancerModel.getClreplacedLoader();
if (scriptType == ScriptTypeEnum.GROOVY) {
loader = new ClreplacedLoaderForScript(this.getClreplaced().getClreplacedLoader(), enhancerModel.getClreplacedLoader());
}
return loader;
}
18
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Check and change the parameters
*
* @param scriptType
* @param params
* @param enhancerModel
*/
private void checkAndChangeParameters(ScriptTypeEnum scriptType, Map<String, Object> params, EnhancerModel enhancerModel) {
Object[] methodArguments = enhancerModel.getMethodArguments();
if (scriptType == ScriptTypeEnum.GROOVY) {
params = (Map<String, Object>) params.get(JvmConstant.GROOVY_VAL_KEY);
}
if (methodArguments != null) {
for (int i = 0; i < methodArguments.length; i++) {
methodArguments[i] = params.get(i + "");
}
}
}
18
View Complete Implementation : HeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
oomObjects = new ArrayList<OomObject>();
super.run(enhancerModel);
}
18
View Complete Implementation : OffHeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void innerStop(EnhancerModel enhancerModel) {
this.oomObjects = null;
}
18
View Complete Implementation : AbstractConnPoolFullExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
}
18
View Complete Implementation : JvmOomExecutorFacade.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
selectExecutor(enhancerModel).run(enhancerModel);
}
18
View Complete Implementation : JvmOomActionSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void destroyInjection(String expId, Model model) throws Exception {
EnhancerModel enhancerModel = new EnhancerModel(EnhancerModel.clreplaced.getClreplacedLoader(), model.getMatcher());
enhancerModel.merge(model);
((StoppableActionExecutor) getActionExecutor()).stop(enhancerModel);
}
18
View Complete Implementation : ConfigUtil.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
public static String getActionFlag(EnhancerModel enhancerModel, String flagKey) {
return enhancerModel.getActionFlag(flagKey);
}
18
View Complete Implementation : HeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void innerStop(EnhancerModel enhancerModel) {
oomObjects = null;
}
18
View Complete Implementation : NoHeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void stop(EnhancerModel enhancerModel) throws Exception {
started.compareAndSet(true, false);
}
18
View Complete Implementation : NoHeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void innerStop(EnhancerModel enhancerModel) {
}
18
View Complete Implementation : OffHeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
oomObjects = new ArrayList<ByteBuffer>();
super.run(enhancerModel);
}
17
View Complete Implementation : BaseTimeoutExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
if (timeoutInMillis > 0) {
Exception exception = generateTimeoutException(clreplacedLoader);
InterruptProcessException.throwThrowsImmediately(exception != null ? exception : new Exception("chaosblade mock timeout"));
}
}
17
View Complete Implementation : DefaultDelayExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
String time = enhancerModel.getActionFlag(timeFlagSpec.getName());
Integer sleepTimeInMillis = Integer.valueOf(time);
int offset = 0;
String offsetTime = enhancerModel.getActionFlag(timeOffsetFlagSpec.getName());
if (!StringUtil.isBlank(offsetTime)) {
offset = Integer.valueOf(offsetTime);
}
TimeoutExecutor timeoutExecutor = enhancerModel.getTimeoutExecutor();
if (timeoutExecutor != null) {
long timeoutInMillis = timeoutExecutor.getTimeoutInMillis();
if (timeoutInMillis > 0 && timeoutInMillis < sleepTimeInMillis) {
sleep(timeoutInMillis, 0);
timeoutExecutor.run(enhancerModel);
return;
}
}
sleep(sleepTimeInMillis, offset);
}
17
View Complete Implementation : HttpClient3Enhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void postDoBeforeAdvice(EnhancerModel enhancerModel) {
enhancerModel.addMatcher(HTTPCLIENT3, "true");
}
17
View Complete Implementation : HttpClient4Enhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void postDoBeforeAdvice(EnhancerModel enhancerModel) {
enhancerModel.addMatcher(HTTPCLIENT4, "true");
}
17
View Complete Implementation : CodeCacheFillingExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void stop(EnhancerModel enhancerModel) {
try {
if (null != monitor) {
if (monitor.isAlive()) {
monitor.interrupt();
}
monitor = null;
}
if (null != workers) {
if (!workers.isShutdown()) {
workers.shutdown();
}
workers = null;
}
} finally {
started.set(false);
}
}
17
View Complete Implementation : JvmCpuFullLoadExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void stop(EnhancerModel enhancerModel) throws Exception {
flag = false;
if (executorService != null && !executorService.isShutdown()) {
executorService.shutdownNow();
executorService = null;
LOGGER.info("jvm cpu full load stopped");
}
}
17
View Complete Implementation : HeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void innerRun(EnhancerModel enhancerModel, JvmOomConfiguration jvmOomConfiguration) {
oomObjects.add(new OomObject(jvmOomConfiguration.getBlock()));
}
17
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
private String getScriptName(String scriptId, EnhancerModel enhancerModel) {
String scriptName = enhancerModel.getActionFlag(JvmConstant.FLAG_NAME_SCRIPT_NAME);
if (StringUtil.isBlank(scriptName)) {
scriptName = scriptId;
}
return scriptName;
}
16
View Complete Implementation : DubboConsumerEnhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void postDoBeforeAdvice(EnhancerModel enhancerModel) {
enhancerModel.addMatcher(DubboConstant.CONSUMER_KEY, "true");
}
16
View Complete Implementation : DubboProviderEnhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void postDoBeforeAdvice(EnhancerModel enhancerModel) {
enhancerModel.addMatcher(DubboConstant.PROVIDER_KEY, "true");
}
16
View Complete Implementation : RestTemplateEnhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void postDoBeforeAdvice(EnhancerModel enhancerModel) {
enhancerModel.addMatcher(HttpConstant.REST_KEY, "true");
}
16
View Complete Implementation : CodeCacheFillingActionSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void destroyInjection(String uid, Model model) throws Exception {
EnhancerModel enhancerModel = new EnhancerModel(EnhancerModel.clreplaced.getClreplacedLoader(), model.getMatcher());
enhancerModel.merge(model);
((StoppableActionExecutor) getActionExecutor()).stop(enhancerModel);
}
16
View Complete Implementation : CodeCacheFillingActionSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void createInjection(String uid, Model model) throws Exception {
EnhancerModel enhancerModel = new EnhancerModel(EnhancerModel.clreplaced.getClreplacedLoader(), model.getMatcher());
enhancerModel.merge(model);
getActionExecutor().run(enhancerModel);
}
16
View Complete Implementation : OffHeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void innerRun(EnhancerModel enhancerModel, JvmOomConfiguration jvmOomConfiguration) {
oomObjects.add(ByteBuffer.allocateDirect(jvmOomConfiguration.getBlock() * JvmConstant.ONE_MB));
}
16
View Complete Implementation : JvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
private JvmOomConfiguration parse(EnhancerModel enhancerModel) {
JvmOomConfiguration jvmOomConfiguration = new JvmOomConfiguration();
jvmOomConfiguration.setWildMode(ConfigUtil.getActionFlag(enhancerModel, JvmConstant.FLAG_NAME_OOM_HAPPEN_MODE, false));
jvmOomConfiguration.setInterval(ConfigUtil.getActionFlag(enhancerModel, JvmConstant.FLAG_OOM_ERROR_INTERVAL, JvmConstant.MIN_OOM_HAPPEN_INTERVAL_IN_MILLS));
jvmOomConfiguration.setBlock(ConfigUtil.getActionFlag(enhancerModel, JvmConstant.FLAG_NAME_OOM_BLOCK, 1));
return jvmOomConfiguration;
}
16
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void stop(EnhancerModel enhancerModel) throws Exception {
MatcherModel matcherModel = enhancerModel.getMatcherModel();
String scriptId = createScriptId(matcherModel);
if (scriptId != null) {
engineService.cleanCompiledScript(scriptId);
}
}
16
View Complete Implementation : DefaultThrowExceptionExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
Exception exception = null;
String exceptionMessage = null;
if (exceptionMessageFlag != null) {
exceptionMessage = enhancerModel.getActionFlag(exceptionMessageFlag.getName());
}
if (StringUtil.isBlank(exceptionMessage)) {
exceptionMessage = DEFAULT_EXCEPTION_MESSAGE;
}
if (enhancerModel.getAction().equals(THROW_CUSTOM_EXCEPTION)) {
exception = throwCustomException(enhancerModel.getClreplacedLoader(), enhancerModel.getActionFlag(exceptionFlag.getName()), exceptionMessage);
} else if (enhancerModel.getAction().equals(THROW_DECLARED_EXCEPTION)) {
exception = throwDeclaredException(enhancerModel.getClreplacedLoader(), enhancerModel.getMethod(), exceptionMessage);
}
if (exception != null) {
InterruptProcessException.throwThrowsImmediately(exception);
}
}
15
View Complete Implementation : JvmOomExecutorFacade.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
private JvmOomExecutor selectExecutor(EnhancerModel enhancerModel) throws Exception {
String area = enhancerModel.getActionFlag(JvmConstant.FLAG_NAME_MEMORY_AREA);
JvmMemoryArea jvmMemoryArea = JvmMemoryArea.nameOf(area);
for (JvmOomExecutor jvmOomExecutor : jvmOomExecutors) {
if (jvmOomExecutor.supportArea().equals(jvmMemoryArea)) {
return jvmOomExecutor;
}
}
throw new Exception("Illegal jvm error");
}
14
View Complete Implementation : Injector.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Compare the experiment rule with the date collected by method enhancer
*
* @param model
* @param enhancerModel
* @return
*/
private static boolean compare(Model model, EnhancerModel enhancerModel) {
MatcherModel matcher = model.getMatcher();
if (matcher == null) {
return true;
}
MatcherModel enhancerMatcherModel = enhancerModel.getMatcherModel();
if (enhancerMatcherModel == null) {
return false;
}
Map<String, String> matchers = matcher.getMatchers();
for (Entry<String, String> entry : matchers.entrySet()) {
// filter effect count and effect percent
if (entry.getKey().equalsIgnoreCase(ModelConstant.EFFECT_COUNT_MATCHER_NAME) || entry.getKey().equalsIgnoreCase(ModelConstant.EFFECT_PERCENT_MATCHER_NAME)) {
continue;
}
String value = enhancerMatcherModel.get(entry.getKey());
if (value == null) {
return false;
}
if (!value.equalsIgnoreCase(entry.getValue())) {
return false;
}
}
return true;
}
14
View Complete Implementation : DubboEnhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public EnhancerModel doBeforeAdvice(ClreplacedLoader clreplacedLoader, String clreplacedName, Object object, Method method, Object[] methodArguments) throws Exception {
if (method.getName().equals(RECEIVED_METHOD)) {
// received method for thread pool experiment
DubboThreadPoolFullExecutor.INSTANCE.setWrappedChannelHandler(object);
return null;
}
Object invocation = methodArguments[0];
if (object == null || invocation == null) {
LOGGER.warn("The necessary parameter is null.");
return null;
}
Object url = getUrl(object, invocation);
if (url == null) {
LOGGER.warn("Url is null, can not get necessary values.");
return null;
}
String appName = ReflectUtil.invokeMethod(url, GET_PARAMETER, new Object[] { APPLICATION_KEY }, false);
String methodName = ReflectUtil.invokeMethod(invocation, GET_METHOD_NAME, new Object[0], false);
String[] serviceAndVersionGroup = getServiceNameWithVersionGroup(invocation, url);
MatcherModel matcherModel = new MatcherModel();
matcherModel.add(DubboConstant.APP_KEY, appName);
matcherModel.add(DubboConstant.SERVICE_KEY, serviceAndVersionGroup[0]);
matcherModel.add(DubboConstant.VERSION_KEY, serviceAndVersionGroup[1]);
if (2 < serviceAndVersionGroup.length && null != serviceAndVersionGroup[2]) {
matcherModel.add(DubboConstant.GROUP_KEY, serviceAndVersionGroup[2]);
}
matcherModel.add(DubboConstant.METHOD_KEY, methodName);
int timeout = getTimeout(methodName, object, invocation);
matcherModel.add(DubboConstant.TIMEOUT_KEY, timeout + "");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("dubbo matchers: {}", JSON.toJSONString(matcherModel));
}
EnhancerModel enhancerModel = new EnhancerModel(clreplacedLoader, matcherModel);
enhancerModel.setTimeoutExecutor(createTimeoutExecutor(clreplacedLoader, timeout, clreplacedName));
postDoBeforeAdvice(enhancerModel);
return enhancerModel;
}
14
View Complete Implementation : CodeCacheFillingExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void run(EnhancerModel enhancerModel) {
if (started.get() || !started.compareAndSet(false, true)) {
throw new IllegalStateException("Experiment is running. Please stop the experiment before re-run.");
}
if (null != workers && !workers.isShutdown()) {
workers.shutdown();
workers = null;
}
try {
int processors = Runtime.getRuntime().availableProcessors();
int compileThreshold = getCompileThreshold();
int bucketSize = GENERATE_OBJECT_COUNT / processors;
CyclicBarrier cyclicBarrier = new CyclicBarrier(processors + 1);
workers = Executors.newFixedThreadPool(processors);
monitor = new Thread(new CodeCacheMonitorRunnable(cyclicBarrier, started));
monitor.start();
for (int n = 0; n < processors; n++) {
workers.submit(new CodeCacheObjectPreheatingRunnable(bucketSize, compileThreshold, cyclicBarrier, started));
}
} catch (Throwable e) {
LOGGER.error("Unknown Error.", e);
started.compareAndSet(true, false);
}
}
14
View Complete Implementation : JvmCpuFullLoadExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Through the infinite loop to achieve full CPU load.
*
* @param enhancerModel
* @throws Exception
*/
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
if (executorService != null && (!executorService.isShutdown())) {
throw new IllegalStateException("The jvm cpu full load experiment is running");
}
String cpuCount = enhancerModel.getActionFlag(JvmConstant.FLAG_NAME_CPU_COUNT);
int maxProcessors = Runtime.getRuntime().availableProcessors();
int threadCount = maxProcessors;
if (!StringUtil.isBlank(cpuCount)) {
Integer count = Integer.valueOf(cpuCount.trim());
if (count > 0 && count < maxProcessors) {
threadCount = count;
}
}
synchronized (lock) {
if (executorService != null && (!executorService.isShutdown())) {
throw new IllegalStateException("The jvm cpu full load experiment is running...");
}
executorService = Executors.newFixedThreadPool(threadCount);
}
flag = true;
for (int i = 0; i < threadCount; i++) {
executorService.submit(new Runnable() {
@Override
public void run() {
while (flag) {
}
}
});
LOGGER.info("start jvm cpu full load thread, {}", i);
}
}
14
View Complete Implementation : JvmModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void preDestroy(String uid, Model model) throws ExperimentException {
ActionSpec actionSpec = getActionSpec(model.getActionName());
if (actionSpec instanceof DirectlyInjectionAction) {
try {
((DirectlyInjectionAction) actionSpec).destroyInjection(uid, model);
} catch (Exception e) {
throw new ExperimentException("destroy injection failed:" + e.getMessage());
}
} else {
// invoke action executor stop method if the executor extends StoppableActionExecutor clreplaced
ActionExecutor actionExecutor = actionSpec.getActionExecutor();
if (actionExecutor instanceof StoppableActionExecutor) {
EnhancerModel enhancerModel = new EnhancerModel(null, model.getMatcher());
try {
((StoppableActionExecutor) actionExecutor).stop(enhancerModel);
} catch (Exception e) {
throw new ExperimentException("stop experiment exception", e);
}
}
MethodPreInjectHandler.preHandleRecovery(model);
}
}
14
View Complete Implementation : NoHeapJvmOomExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
protected void innerRun(EnhancerModel enhancerModel, JvmOomConfiguration jvmOomConfiguration) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclreplaced(OomObject.clreplaced);
enhancer.setUseCache(false);
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
return proxy.invokeSuper(obj, args);
}
});
enhancer.create();
}
14
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Get script type
*
* @param enhancerModel
* @return
*/
private ScriptTypeEnum getScriptType(EnhancerModel enhancerModel) {
// get script type
String scriptType = enhancerModel.getActionFlag(JvmConstant.FLAG_NAME_SCRIPT_TYPE);
if (StringUtil.isBlank(scriptType)) {
return ScriptTypeEnum.JAVA;
}
if (scriptType.equalsIgnoreCase(JvmConstant.SCRIPT_TYPE_JAVA)) {
return ScriptTypeEnum.JAVA;
}
if (scriptType.equalsIgnoreCase(JvmConstant.SCRIPT_TYPE_GROOVY)) {
return ScriptTypeEnum.GROOVY;
}
throw new IllegalArgumentException(JvmConstant.FLAG_NAME_SCRIPT_TYPE + " value is illegal");
}
13
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Create parameters for script
*
* @param scriptType
* @param enhancerModel
* @return
*/
private Map<String, Object> createParams(ScriptTypeEnum scriptType, EnhancerModel enhancerModel) {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put(JvmConstant.SCRIPT_INVOKE_TARGET, enhancerModel.getObject());
params.put(JvmConstant.SCRIPT_INVOKE_RETURN, enhancerModel.getReturnValue());
Object[] methodArguments = enhancerModel.getMethodArguments();
if (methodArguments != null) {
for (int i = 0; i < methodArguments.length; i++) {
params.put("" + i, methodArguments[i]);
}
}
if (scriptType == ScriptTypeEnum.JAVA) {
return params;
}
// for groovy
HashMap<String, Object> result = new HashMap<String, Object>();
result.put(JvmConstant.GROOVY_VAL_KEY, params);
return result;
}
13
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* @param enhancerModel
* @throws Exception
*/
@Override
public void run(EnhancerModel enhancerModel) throws Exception {
// check experiment exists or not
MatcherModel matcher = enhancerModel.getMatcherModel();
String scriptId = createScriptId(matcher);
if (scriptId == null) {
throw new IllegalArgumentException("can not get script id from matcher model");
}
ScriptTypeEnum scriptType = getScriptType(enhancerModel);
String scriptContent = getScriptContent(enhancerModel);
String scriptName = getScriptName(scriptId, enhancerModel);
// create script object
Script script = new Script(scriptId, "", scriptName, scriptContent, scriptType.getName());
ClreplacedLoader clreplacedLoader = getClreplacedLoader(scriptType, enhancerModel);
// compile script content
CompiledScript compiledScript = engineService.compile(clreplacedLoader, script, null);
Map<String, Object> params = createParams(scriptType, enhancerModel);
// execute script
ExecutableScript executableScript = engineService.execute(compiledScript, params);
Object result = null;
try {
result = executableScript.run();
} catch (ScriptException e) {
if (e.getCause() instanceof InvocationTargetException) {
InvocationTargetException targetException = (InvocationTargetException) e.getCause();
throw InterruptProcessException.throwThrowsImmediately(targetException.getCause());
}
throw e;
} catch (Exception e) {
throw e;
}
if (result != null) {
// if result is not null, then return the value
InterruptProcessException.throwReturnImmediately(result);
}
// change parameters if they are modified
checkAndChangeParameters(scriptType, params, enhancerModel);
}
12
View Complete Implementation : HttpEnhancer.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public EnhancerModel doBeforeAdvice(ClreplacedLoader clreplacedLoader, String clreplacedName, Object object, Method method, Object[] methodArguments) throws Exception {
MatcherModel matcherModel = new MatcherModel();
matcherModel.add(HttpConstant.URI_KEY, getUrl(methodArguments));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("http matchers: {}", JSON.toJSONString(matcherModel));
}
EnhancerModel enhancerModel = new EnhancerModel(clreplacedLoader, matcherModel);
postDoBeforeAdvice(enhancerModel);
return new EnhancerModel(clreplacedLoader, matcherModel);
}