use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class NodeJsBreakpointsParser method parse.
@Override
public Breakpoints parse(NodeJsOutput nodeJsOutput) throws NodeJsDebuggerParseException {
final List<Breakpoint> breakpoints = new ArrayList<>();
JsonObject json = new JsonParser().parse(nodeJsOutput.getOutput()).getAsJsonObject();
if (json.has("breakpoints")) {
Iterator<JsonElement> iter = json.getAsJsonArray("breakpoints").iterator();
while (iter.hasNext()) {
JsonObject item = iter.next().getAsJsonObject();
try {
final String condition = item.has("condition") && !item.get("condition").isJsonNull() ? item.get("condition").getAsString() : null;
final boolean isEnabled = item.has("active") && !item.get("active").isJsonNull() && item.get("active").getAsBoolean();
final int lineNumber = item.get("line").getAsInt();
final String target;
String targetType = item.get("type").getAsString();
switch(targetType) {
case "scriptId":
target = String.valueOf(item.get("script_id").getAsInt());
break;
case "scriptRegExp":
target = item.get("script_regexp").getAsString();
break;
default:
throw new IllegalArgumentException("Unsupported 'type' value: " + targetType);
}
Location location = new LocationImpl(targetType + ":" + target, lineNumber + 1);
Breakpoint breakpoint = new BreakpointImpl(location, isEnabled, condition);
breakpoints.add(breakpoint);
} catch (Exception e) {
LOG.error("Failed to parse breakpoint: " + item.toString(), e);
}
}
}
return new Breakpoints(breakpoints);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class LogEntryDecoder method deserialize.
@Override
public LogEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonObject()) {
return null;
}
JsonObject jsonObj = json.getAsJsonObject();
final String name = JsonUtils.getAsString(jsonObj, "name");
final String host = JsonUtils.getAsString(jsonObj, "host");
final long timestamp = JsonUtils.getAsLong(jsonObj, "timestamp", 0);
LogEntry.Level l;
try {
l = LogEntry.Level.valueOf(JsonUtils.getAsString(jsonObj, "level"));
} catch (Exception e) {
l = LogEntry.Level.FATAL;
}
final LogEntry.Level logLevel = l;
final String className = JsonUtils.getAsString(jsonObj, "className");
final String method = JsonUtils.getAsString(jsonObj, "method");
final String file = JsonUtils.getAsString(jsonObj, "file");
final String line = JsonUtils.getAsString(jsonObj, "line");
final String thread = JsonUtils.getAsString(jsonObj, "thread");
final String message = JsonUtils.getAsString(jsonObj, "message");
final StackTraceElement[] stackTraces = context.deserialize(jsonObj.get("stackTraces").getAsJsonArray(), StackTraceElement[].class);
return new LogEntry() {
@Override
public String getLoggerName() {
return name;
}
@Override
public String getHost() {
return host;
}
@Override
public long getTimestamp() {
return timestamp;
}
@Override
public Level getLogLevel() {
return logLevel;
}
@Override
public String getSourceClassName() {
return className;
}
@Override
public String getSourceMethodName() {
return method;
}
@Override
public String getFileName() {
return file;
}
@Override
public int getLineNumber() {
if (line.equals("?")) {
return -1;
} else {
return Integer.parseInt(line);
}
}
@Override
public String getThreadName() {
return thread;
}
@Override
public String getMessage() {
return message;
}
@Override
public StackTraceElement[] getStackTraces() {
return stackTraces;
}
};
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class ZKServiceDecorator method createLiveNode.
private OperationFuture<String> createLiveNode() {
String liveNode = getLiveNodePath();
LOG.info("Create live node {}{}", zkClient.getConnectString(), liveNode);
JsonObject content = new JsonObject();
content.add("data", liveNodeData.get());
return ZKOperations.ignoreError(zkClient.create(liveNode, encodeJson(content), CreateMode.EPHEMERAL), KeeperException.NodeExistsException.class, liveNode);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class LocalFileCodec method deserialize.
@Override
public LocalFile deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String name = jsonObj.get("name").getAsString();
URI uri = URI.create(jsonObj.get("uri").getAsString());
long lastModified = jsonObj.get("lastModified").getAsLong();
long size = jsonObj.get("size").getAsLong();
boolean archive = jsonObj.get("archive").getAsBoolean();
JsonElement pattern = jsonObj.get("pattern");
return new DefaultLocalFile(name, uri, lastModified, size, archive, (pattern == null || pattern.isJsonNull()) ? null : pattern.getAsString());
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class ResourceReportCodec method serialize.
@Override
public JsonElement serialize(ResourceReport src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
json.addProperty("appMasterId", src.getApplicationId());
json.add("appMasterResources", context.serialize(src.getAppMasterResources(), new TypeToken<WeaveRunResources>() {
}.getType()));
json.add("runnableResources", context.serialize(src.getResources(), new TypeToken<Map<String, Collection<WeaveRunResources>>>() {
}.getType()));
return json;
}
Aggregations