Search in sources :

Example 51 with JsonObject

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);
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) NodeJsDebuggerParseException(org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException) JsonElement(com.google.gson.JsonElement) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) JsonParser(com.google.gson.JsonParser) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 52 with JsonObject

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;
        }
    };
}
Also used : JsonObject(com.google.gson.JsonObject) LogEntry(com.continuuity.weave.api.logging.LogEntry) JsonParseException(com.google.gson.JsonParseException)

Example 53 with JsonObject

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);
}
Also used : JsonObject(com.google.gson.JsonObject) KeeperException(org.apache.zookeeper.KeeperException)

Example 54 with JsonObject

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());
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) DefaultLocalFile(com.continuuity.weave.internal.DefaultLocalFile) URI(java.net.URI)

Example 55 with JsonObject

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;
}
Also used : JsonObject(com.google.gson.JsonObject) WeaveRunResources(com.continuuity.weave.api.WeaveRunResources) Map(java.util.Map)

Aggregations

JsonObject (com.google.gson.JsonObject)5111 JsonArray (com.google.gson.JsonArray)1162 JsonElement (com.google.gson.JsonElement)1084 JsonParser (com.google.gson.JsonParser)710 Test (org.junit.Test)491 IOException (java.io.IOException)471 JsonPrimitive (com.google.gson.JsonPrimitive)387 ArrayList (java.util.ArrayList)376 Gson (com.google.gson.Gson)369 HashMap (java.util.HashMap)324 Map (java.util.Map)269 Test (org.testng.annotations.Test)208 Test (org.junit.jupiter.api.Test)201 File (java.io.File)146 List (java.util.List)142 InputStreamReader (java.io.InputStreamReader)135 JsonParseException (com.google.gson.JsonParseException)121 GsonBuilder (com.google.gson.GsonBuilder)93 JsonSyntaxException (com.google.gson.JsonSyntaxException)88 Nonnull (javax.annotation.Nonnull)87