Here are the examples of the java api com.alibaba.chaosblade.exec.common.util.StringUtil.isBlank() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
15 Examples
18
View Complete Implementation : Request.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Add parameter
*
* @param key
* @param value
* @return
*/
public Request addParam(String key, String value) {
if (StringUtil.isBlank(key)) {
throw new IllegalArgumentException("Parameter key cannot be empty");
}
params.put(key, value);
return this;
}
18
View Complete Implementation : Request.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Add header
*
* @param key
* @param value
* @return
*/
public Request addHeader(String key, String value) {
if (StringUtil.isBlank(key)) {
throw new IllegalArgumentException("Parameter key cannot be empty");
}
headers.put(key, value);
return this;
}
18
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);
}
18
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);
}
16
View Complete Implementation : DefaultStatusManager.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public StatusMetric getStatusMetricByUid(String uid) {
// get model identifier
String identifier = experiments.get(uid);
if (StringUtil.isBlank(identifier)) {
return null;
}
String target = ModelUtil.getTarget(identifier);
ConcurrentHashMap<String, StatusMetric> metricMap = models.get(target);
if (metricMap == null || metricMap.size() == 0) {
return null;
}
return metricMap.get(identifier);
}
16
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 : 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;
}
15
View Complete Implementation : DefaultStatusManager.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public Model removeExp(String suid) {
// get model identifier
String identifier = experiments.remove(suid);
if (StringUtil.isBlank(identifier)) {
return null;
}
String target = ModelUtil.getTarget(identifier);
ConcurrentHashMap<String, StatusMetric> metricMap = models.get(target);
if (metricMap == null || metricMap.size() == 0) {
return null;
}
// remove identifier
StatusMetric metric = metricMap.remove(identifier);
if (metric == null) {
return null;
}
return metric.getModel();
}
15
View Complete Implementation : DelayActionSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public PredicateResult predicate(ActionModel actionModel) {
if (StringUtil.isBlank(actionModel.getFlag(timeFlag.getName()))) {
return PredicateResult.fail("less time argument");
}
return PredicateResult.success();
}
15
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 : ThrowCustomExceptionActionSpec.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
@Override
public PredicateResult predicate(ActionModel actionModel) {
String exceptionClreplaced = actionModel.getFlag(exceptionFlag.getName());
if (StringUtil.isBlank(exceptionClreplaced)) {
return PredicateResult.fail("less exception argument");
}
if (exceptionClreplaced.startsWith("-")) {
return PredicateResult.fail("illegal exception value");
}
return PredicateResult.success();
}
14
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());
}
}
13
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");
}
11
View Complete Implementation : DynamicScriptExecutor.java
Copyright Apache License 2.0
Author : chaosblade-io
Copyright Apache License 2.0
Author : chaosblade-io
/**
* Get script content
*
* @param enhancerModel
* @return
*/
private String getScriptContent(EnhancerModel enhancerModel) {
// get script file
String scriptFile = enhancerModel.getActionFlag(JvmConstant.FLAG_NAME_SCRIPT_FILE);
String scriptContent = enhancerModel.getActionFlag(JvmConstant.FLAG_NAME_SCRIPT_CONTENT);
if (StringUtil.isBlank(scriptFile) && StringUtil.isBlank(scriptContent)) {
throw new IllegalArgumentException("less script file or content");
}
if (!StringUtil.isBlank(scriptFile) && !StringUtil.isBlank(scriptContent)) {
throw new IllegalArgumentException("must only specify one flag between script file and script content");
}
// parse script file
if (!StringUtil.isBlank(scriptFile)) {
StringBuilder sb = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(scriptFile));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
}
reader.close();
} catch (IOException e) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
return sb.toString();
}
String decodeScriptContent = enhancerModel.getActionFlag(JvmConstant.FLAG_NAME_SCRIPT_CONTENT_DECODE);
if (StringUtil.isBlank(decodeScriptContent)) {
// parse script content and cache
scriptContent = scriptContent.replaceAll(" ", "+");
String decode = Base64Util.decode(scriptContent.getBytes(Charset.forName("UTF-8")));
enhancerModel.addActionFlag(JvmConstant.FLAG_NAME_SCRIPT_CONTENT_DECODE, decode);
return decode;
}
return decodeScriptContent;
}
9
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()));
}