Here are the examples of the java api com.alibaba.chaosblade.exec.common.transport.Request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
19
View Complete Implementation : DefaultDispatchService.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public Response dispatch(String command, Request request) {
LOGGER.info("command: {}, request: {}", command, JSON.toJSONString(request));
if (StringUtil.isBlank(command)) {
return Response.ofFailure(Response.Code.ILLEGAL_PARAMETER, "less request command");
}
RequestHandler handler = this.handles.get(command);
if (handler == null) {
return Response.ofFailure(Response.Code.NOT_FOUND, command + " command not found");
}
try {
return handler.handle(request);
} catch (Throwable e) {
LOGGER.warn("handle {} request exception, params: {}", new Object[] { command, JSON.toJSONString(request.getParams()), e });
return Response.ofFailure(Response.Code.SERVER_ERROR, e.getMessage());
}
}
17
View Complete Implementation : DestroyHandler.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public Response handle(Request request) {
String uid = request.getParam("suid");
String target = request.getParam("target");
String action = request.getParam("action");
if (StringUtil.isBlank(uid)) {
if (StringUtil.isBlank(target) || StringUtil.isBlank(action)) {
return Response.ofFailure(Code.ILLEGAL_PARAMETER, "less necessary parameters, such as uid, target and" + " action");
}
return destroy(target, action);
}
return destroy(uid);
}
17
View Complete Implementation : StatusHandler.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public Response handle(Request request) {
String suid = request.getParam("suid");
if (StringUtil.isBlank(suid)) {
return Response.ofFailure(Code.ILLEGAL_PARAMETER, "suid must not be empty");
}
StatusMetric statusMetric = statusManager.getStatusMetricByUid(suid);
if (statusMetric == null) {
return Response.ofFailure(Code.NOT_FOUND, "data not found");
}
return Response.ofSuccess(String.valueOf(statusMetric.getCount()));
}
16
View Complete Implementation : SandboxModule.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
private void service(String command, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
Request request;
if ("POST".equalsIgnoreCase(httpServletRequest.getMethod())) {
try {
request = getRequestFromBody(httpServletRequest);
} catch (IOException e) {
Response response = Response.ofFailure(Code.ILLEGAL_PARAMETER, e.getMessage());
output(httpServletResponse, response);
return;
}
} else {
request = getRequestFromParams(httpServletRequest);
}
Response response = dispatchService.dispatch(command, request);
output(httpServletResponse, response);
}
16
View Complete Implementation : CreateHandler.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Set log level to debug if debug parameter is true
*
* @param request
*/
private void checkAndSetLogLevel(Request request) {
String debug = request.getParam("debug");
if (Boolean.TRUE.toString().equalsIgnoreCase(debug)) {
try {
LogUtil.setDebug();
LOGGER.info("change log level to debug");
} catch (Exception e) {
LOGGER.warn("set log level to debug failed", e);
}
}
}
15
View Complete Implementation : CreateHandler.java
Copyright Apache License 2.0
Author : chaosblade-io
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);
}
14
View Complete Implementation : ModelParser.java
Copyright Apache License 2.0
Author : chaosblade-io
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;
}
13
View Complete Implementation : SandboxModule.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
private Request getRequestFromBody(HttpServletRequest httpServletRequest) throws IOException {
ServletInputStream inputStream = httpServletRequest.getInputStream();
Map<String, String> parameters = JSON.parseObject(inputStream, Map.clreplaced);
Request request = new Request();
request.addParams(parameters);
return request;
}
11
View Complete Implementation : SandboxModule.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
private Request getRequestFromParams(HttpServletRequest httpServletRequest) {
Request request;
request = new Request();
Map<String, String[]> parameterMap = httpServletRequest.getParameterMap();
Set<Entry<String, String[]>> entries = parameterMap.entrySet();
for (Entry<String, String[]> entry : entries) {
String value = "";
String[] values = entry.getValue();
if (values.length > 0) {
value = values[0];
}
request.addParam(entry.getKey(), value);
}
return request;
}