Search in sources :

Example 1 with ScriptEvaluator

use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.

the class MockStrategy method processNonBlock.

@Override
public Object processNonBlock(Class returnType, ClassLoader classLoader, Object params, ExecutionCall call) throws ProcessControlException {
    if (Pradar.isClusterTest()) {
        if (params instanceof MatchConfig) {
            try {
                MatchConfig config = (MatchConfig) params;
                String scriptContent = config.getScriptContent();
                ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
                Object result = evaluator.evaluate(scriptContent, config.getArgs());
                return call.call(result);
            } catch (ProcessControlException e) {
                throw e;
            } catch (Throwable e) {
                LOGGER.error("mock处理异常 {}", e);
                ErrorReporter.buildError().setErrorType(ErrorTypeEnum.mock).setErrorCode("mock-0001").setMessage("mock处理异常!" + e.getMessage()).setDetail("脚本内容" + ((MatchConfig) params).getScriptContent()).report();
                throw new PressureMeasureError(e);
            }
        }
    }
    return true;
}
Also used : ScriptEvaluator(com.pamirs.pradar.script.ScriptEvaluator) ProcessControlException(com.shulie.instrument.simulator.api.ProcessControlException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MatchConfig(com.pamirs.pradar.internal.config.MatchConfig)

Example 2 with ScriptEvaluator

use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.

the class MockStrategy method processBlock.

@Override
public Object processBlock(Class returnType, ClassLoader classLoader, Object params, ExecutionCall call) throws ProcessControlException {
    if (Pradar.isClusterTest()) {
        if (params instanceof MatchConfig) {
            try {
                MatchConfig config = (MatchConfig) params;
                String scriptContent = config.getScriptContent();
                ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
                Object result = evaluator.evaluate(scriptContent, config.getArgs());
                Object callResult = call.call(result);
                ProcessController.returnImmediately(returnType, callResult);
            } catch (ProcessControlException e) {
                throw e;
            } catch (Throwable e) {
                LOGGER.error("mock处理异常 {}", e);
                ErrorReporter.buildError().setErrorType(ErrorTypeEnum.mock).setErrorCode("mock-0001").setMessage("mock处理异常!" + e.getMessage()).setDetail("脚本内容" + ((MatchConfig) params).getScriptContent()).report();
                throw new PressureMeasureError(e);
            }
        }
    }
    return true;
}
Also used : ScriptEvaluator(com.pamirs.pradar.script.ScriptEvaluator) ProcessControlException(com.shulie.instrument.simulator.api.ProcessControlException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MatchConfig(com.pamirs.pradar.internal.config.MatchConfig)

Example 3 with ScriptEvaluator

use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.

the class MockStrategy method processBlock.

@Override
public Object processBlock(Class returnType, ClassLoader classLoader, Object params) throws ProcessControlException {
    if (Pradar.isClusterTest()) {
        if (params instanceof MatchConfig) {
            try {
                MatchConfig config = (MatchConfig) params;
                String scriptContent = config.getScriptContent();
                ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
                Object result = evaluator.evaluate(scriptContent, config.getArgs());
                ProcessController.returnImmediately(returnType, result);
            } catch (ProcessControlException e) {
                throw e;
            } catch (Throwable e) {
                LOGGER.error("mock处理异常 {}", e);
                ErrorReporter.buildError().setErrorType(ErrorTypeEnum.mock).setErrorCode("mock-0003").setMessage("mock处理异常!" + e.getMessage()).setDetail("脚本内容" + ((MatchConfig) params).getScriptContent()).report();
                throw new PressureMeasureError(e);
            }
        }
    }
    return true;
}
Also used : ScriptEvaluator(com.pamirs.pradar.script.ScriptEvaluator) ProcessControlException(com.shulie.instrument.simulator.api.ProcessControlException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MatchConfig(com.pamirs.pradar.internal.config.MatchConfig)

Example 4 with ScriptEvaluator

use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.

the class MockAdviceListener method before.

@Override
public void before(Advice advice) throws Throwable {
    if (Pradar.isClusterTest()) {
        Map<String, Object> binding = new HashMap<String, Object>(4, 1.0f);
        binding.put("args", advice.getParameterArray());
        binding.put("target", advice.getTarget());
        binding.put("classLoader", advice.getClassLoader());
        binding.put("logger", mockLogger);
        ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
        Object result = evaluator.evaluate(advice.getClassLoader(), scriptContent, binding);
        ProcessController.returnImmediately(advice.getBehavior().getReturnType(), result);
    }
}
Also used : ScriptEvaluator(com.pamirs.pradar.script.ScriptEvaluator) HashMap(java.util.HashMap)

Aggregations

ScriptEvaluator (com.pamirs.pradar.script.ScriptEvaluator)4 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)3 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)3 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)3 HashMap (java.util.HashMap)1