com.alibaba.chaosblade.exec.common.model.action.ActionSpec - java examples

Here are the examples of the java api com.alibaba.chaosblade.exec.common.model.action.ActionSpec taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

14 Examples 7

19 View Complete Implementation : JvmModelSpec.java
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);
    }
}

19 View Complete Implementation : JvmModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void preCreate(String uid, Model model) throws ExperimentException {
    ActionSpec actionSpec = getActionSpec(model.getActionName());
    if (actionSpec instanceof DirectlyInjectionAction) {
        try {
            ((DirectlyInjectionAction) actionSpec).createInjection(uid, model);
        } catch (Exception e) {
            throw new ExperimentException("create injection failed:" + e.getMessage());
        }
    } else {
        MethodPreInjectHandler.preHandleInjection(model);
    }
}

19 View Complete Implementation : ModelSpecBean.java
Copyright Apache License 2.0
Author : chaosblade-io
private List<ActionSpecBean> createActions(List<ActionSpec> actions) {
    ArrayList<ActionSpecBean> beans = new ArrayList<ActionSpecBean>();
    if (actions == null) {
        return beans;
    }
    for (ActionSpec action : actions) {
        beans.add(new ActionSpecBean(action));
    }
    return beans;
}

18 View Complete Implementation : DruidModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void preCreate(String suid, Model model) throws ExperimentException {
    if (ConnectionPoolFullActionSpec.NAME.equals(model.getActionName())) {
        ActionSpec actionSpec = getActionSpec(model.getActionName());
        ActionExecutor actionExecutor = actionSpec.getActionExecutor();
        if (actionExecutor instanceof DruidConnectionPoolFullExecutor) {
            DruidConnectionPoolFullExecutor executor = (DruidConnectionPoolFullExecutor) actionExecutor;
            executor.setExpReceived(true);
        } else {
            throw new ExperimentException("The executor about connection pool full for tddl is error when " + "creating");
        }
    }
}

18 View Complete Implementation : DruidModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void preDestroy(String suid, Model model) throws ExperimentException {
    if (ConnectionPoolFullActionSpec.NAME.equals(model.getActionName())) {
        ActionSpec actionSpec = getActionSpec(model.getActionName());
        ActionExecutor actionExecutor = actionSpec.getActionExecutor();
        if (actionExecutor instanceof DruidConnectionPoolFullExecutor) {
            DruidConnectionPoolFullExecutor executor = (DruidConnectionPoolFullExecutor) actionExecutor;
            executor.revoke();
        } else {
            throw new ExperimentException("The executor about connection pool full for tddl is error when " + "destroying");
        }
    }
}

18 View Complete Implementation : DubboModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void preDestroy(String suid, Model model) throws ExperimentException {
    if (ThreadPoolFullActionSpec.NAME.equals(model.getActionName())) {
        ActionSpec actionSpec = this.getActionSpec(model.getActionName());
        ActionExecutor actionExecutor = actionSpec.getActionExecutor();
        if (actionExecutor instanceof DubboThreadPoolFullExecutor) {
            DubboThreadPoolFullExecutor threadPoolFullExecutor = (DubboThreadPoolFullExecutor) actionExecutor;
            threadPoolFullExecutor.revoke();
        } else {
            throw new ExperimentException("actionExecutor is not instance of DubboThreadPoolFullExecutor");
        }
    }
}

18 View Complete Implementation : DubboModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void preCreate(String suid, Model model) throws ExperimentException {
    if (ThreadPoolFullActionSpec.NAME.equals(model.getActionName())) {
        ActionSpec actionSpec = this.getActionSpec(model.getActionName());
        ActionExecutor actionExecutor = actionSpec.getActionExecutor();
        if (actionExecutor instanceof DubboThreadPoolFullExecutor) {
            DubboThreadPoolFullExecutor threadPoolFullExecutor = (DubboThreadPoolFullExecutor) actionExecutor;
            threadPoolFullExecutor.setExpReceived(true);
        } else {
            throw new ExperimentException("actionExecutor is not instance of DubboThreadPoolFullExecutor");
        }
    }
}

17 View Complete Implementation : BaseModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void addMatcherDefToAllActions(MatcherSpec matcherSpec) {
    for (ActionSpec actionSpec : actionSpecs.values()) {
        actionSpec.addMatcherDesc(matcherSpec);
    }
}

17 View Complete Implementation : BaseModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public void addActionSpec(ActionSpec actionSpec) {
    ActionSpec oldActionSpec = actionSpecs.putIfAbsent(actionSpec.getName(), actionSpec);
    if (oldActionSpec != null) {
        LOGGER.warn("{} action has defined in {} target model", actionSpec.getName(), getTarget());
        return;
    }
    if (!(actionSpec instanceof DirectlyInjectionAction)) {
        // add effect matcher
        actionSpec.addMatcherDesc(new EffectCountMatcherSpec());
        actionSpec.addMatcherDesc(new EffectPercentMatcherSpec());
    }
}

17 View Complete Implementation : FrameworkModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
public void addAllMatchersToTheAction(ActionSpec actionSpec) {
    List<MatcherSpec> newMatcherSpecs = createNewMatcherSpecs();
    if (newMatcherSpecs == null) {
        return;
    }
    for (MatcherSpec matcherSpec : newMatcherSpecs) {
        actionSpec.addMatcherDesc(matcherSpec);
    }
}

14 View Complete Implementation : CreateHandler.java
Copyright Apache License 2.0
Author : chaosblade-io
/**
 * Handle request for creating chaos experiment
 *
 * @param request
 * @return
 */
@Override
public Response handle(Request request) {
    if (unloaded) {
        return Response.ofFailure(Code.ILLEGAL_STATE, "the agent is uninstalling");
    }
    // check necessary arguments
    String suid = request.getParam("suid");
    if (StringUtil.isBlank(suid)) {
        return Response.ofFailure(Response.Code.ILLEGAL_PARAMETER, "less experiment argument");
    }
    String target = request.getParam("target");
    if (StringUtil.isBlank(target)) {
        return Response.ofFailure(Response.Code.ILLEGAL_PARAMETER, "less target argument");
    }
    String actionArg = request.getParam("action");
    if (StringUtil.isBlank(actionArg)) {
        return Response.ofFailure(Response.Code.ILLEGAL_PARAMETER, "less action argument");
    }
    // change level from info to debug if open debug mode
    checkAndSetLogLevel(request);
    // check the command supported or not
    ModelSpec modelSpec = this.modelSpecManager.getModelSpec(target);
    if (modelSpec == null) {
        return Response.ofFailure(Response.Code.ILLEGAL_PARAMETER, "the target not supported");
    }
    ActionSpec actionSpec = modelSpec.getActionSpec(actionArg);
    if (actionSpec == null) {
        return Response.ofFailure(Code.NOT_FOUND, "the action not supported");
    }
    // parse request to model
    Model model = ModelParser.parseRequest(target, request, actionSpec);
    // check command arguments
    PredicateResult predicate = modelSpec.predicate(model);
    if (!predicate.isSuccess()) {
        return Response.ofFailure(Response.Code.ILLEGAL_PARAMETER, predicate.getErr());
    }
    return handleInjection(suid, model, modelSpec);
}

13 View Complete Implementation : BaseModelSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public PredicateResult predicate(Model model) {
    // check action
    Collection<ActionSpec> actionSpecs = getActionSpecs().values();
    if (actionSpecs == null) {
        LOGGER.error("the model action desc is null. target: {}", this.getTarget());
        return PredicateResult.fail("model action desc is null");
    }
    for (ActionSpec actionSpec : actionSpecs) {
        if (!actionSpec.getName().equals(model.getActionName())) {
            continue;
        }
        PredicateResult result = actionSpec.predicate(model.getAction());
        if (!result.isSuccess()) {
            LOGGER.error("the model action predicate failed. target: {}, action: {}", this.getTarget(), actionSpec.getName());
            return PredicateResult.fail(result.getErr());
        }
        // check matcher
        result = preMatcherPredicate(model);
        if (!result.isSuccess()) {
            return PredicateResult.fail(result.getErr());
        }
        Collection<MatcherSpec> matcherSpecs = actionSpec.getMatcherSpecs().values();
        if (matcherSpecs == null) {
            continue;
        }
        for (MatcherSpec matcherSpec : matcherSpecs) {
            result = matcherSpec.predicate(model.getMatcher());
            if (!result.isSuccess()) {
                return PredicateResult.fail(result.getErr());
            }
        }
    }
    return PredicateResult.success();
}

10 View Complete Implementation : ModelParser.java
Copyright Apache License 2.0
Author : chaosblade-io
public static Model parseRequest(String target, Request request, ActionSpec actionSpec) {
    Model model = new Model(target, actionSpec.getName());
    Map<String, String> params = request.getParams();
    List<FlagSpec> actionFlags = actionSpec.getActionFlags();
    if (actionFlags != null) {
        for (FlagSpec actionFlag : actionFlags) {
            String flagValue = request.getParam(actionFlag.getName());
            if (StringUtil.isBlank(flagValue)) {
                continue;
            }
            model.getAction().addFlag(actionFlag.getName(), flagValue);
            // delete itnot replacedign from
            request.getParams().remove(actionFlag.getName());
        }
    }
    for (Entry<String, String> entry : params.entrySet()) {
        String key = entry.getKey();
        if (replacedistantFlag.contains(key)) {
            continue;
        }
        // add matcher flag
        model.getMatcher().add(key, entry.getValue());
    }
    return model;
}

4 View Complete Implementation : Injector.java
Copyright Apache License 2.0
Author : chaosblade-io
/**
 * Inject
 *
 * @param enhancerModel
 * @throws InterruptProcessException
 */
public static void inject(EnhancerModel enhancerModel) throws InterruptProcessException {
    String target = enhancerModel.getTarget();
    List<StatusMetric> statusMetrics = ManagerFactory.getStatusManager().getExpByTarget(target);
    for (StatusMetric statusMetric : statusMetrics) {
        Model model = statusMetric.getModel();
        if (!compare(model, enhancerModel)) {
            continue;
        }
        try {
            boolean preplaced = limitAndIncrease(statusMetric);
            if (!preplaced) {
                LOGGER.info("Limited by: {}", JSON.toJSONString(model));
                break;
            }
            LOGGER.info("Match rule: {}", JSON.toJSONString(model));
            enhancerModel.merge(model);
            ModelSpec modelSpec = ManagerFactory.getModelSpecManager().getModelSpec(target);
            ActionSpec actionSpec = modelSpec.getActionSpec(model.getActionName());
            actionSpec.getActionExecutor().run(enhancerModel);
        } catch (InterruptProcessException e) {
            throw e;
        } catch (UnsupportedReturnTypeException e) {
            LOGGER.warn("unsupported return type for return experiment", e);
            // decrease the count if throw unexpected exception
            statusMetric.decrease();
        } catch (Throwable e) {
            LOGGER.warn("inject exception", e);
            // decrease the count if throw unexpected exception
            statusMetric.decrease();
        }
        // break it if compared success
        break;
    }
}