Search in sources :

Example 1 with JsonParser

use of org.apache.hbase.thirdparty.com.google.gson.JsonParser in project hbase by apache.

the class ProtobufMessageConverter method toJsonElement.

public static JsonElement toJsonElement(MessageOrBuilder messageOrBuilder, boolean removeType) throws InvalidProtocolBufferException {
    String jsonString = toJsonString(messageOrBuilder);
    JsonParser parser = new JsonParser();
    JsonElement element = parser.parse(jsonString);
    if (removeType) {
        removeTypeFromJson(element);
    }
    return element;
}
Also used : JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) JsonParser(org.apache.hbase.thirdparty.com.google.gson.JsonParser)

Example 2 with JsonParser

use of org.apache.hbase.thirdparty.com.google.gson.JsonParser in project hbase by apache.

the class ProcedureTestUtil method waitUntilProcedureWaitingTimeout.

public static void waitUntilProcedureWaitingTimeout(HBaseTestingUtil util, Class<? extends Procedure<?>> clazz, long timeout) throws IOException {
    JsonParser parser = new JsonParser();
    util.waitFor(timeout, () -> getProcedure(util, clazz, parser).filter(o -> ProcedureState.WAITING_TIMEOUT.name().equals(o.get("state").getAsString())).isPresent());
}
Also used : JsonParser(org.apache.hbase.thirdparty.com.google.gson.JsonParser)

Example 3 with JsonParser

use of org.apache.hbase.thirdparty.com.google.gson.JsonParser in project hbase by apache.

the class ProcedureTestUtil method waitUntilProcedureTimeoutIncrease.

public static void waitUntilProcedureTimeoutIncrease(HBaseTestingUtil util, Class<? extends Procedure<?>> clazz, int times) throws IOException, InterruptedException {
    JsonParser parser = new JsonParser();
    long oldTimeout = 0;
    int timeoutIncrements = 0;
    for (; ; ) {
        long timeout = getProcedure(util, clazz, parser).filter(o -> o.has("timeout")).map(o -> o.get("timeout").getAsLong()).orElse(-1L);
        if (timeout > oldTimeout) {
            LOG.info("Timeout incremented, was {}, now is {}, increments={}", timeout, oldTimeout, timeoutIncrements);
            oldTimeout = timeout;
            timeoutIncrements++;
            if (timeoutIncrements > times) {
                break;
            }
        }
        Thread.sleep(1000);
    }
}
Also used : Logger(org.slf4j.Logger) Iterator(java.util.Iterator) JsonObject(org.apache.hbase.thirdparty.com.google.gson.JsonObject) ProcedureState(org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) IOException(java.io.IOException) JsonParser(org.apache.hbase.thirdparty.com.google.gson.JsonParser) JsonArray(org.apache.hbase.thirdparty.com.google.gson.JsonArray) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) JsonParser(org.apache.hbase.thirdparty.com.google.gson.JsonParser)

Aggregations

JsonParser (org.apache.hbase.thirdparty.com.google.gson.JsonParser)3 JsonElement (org.apache.hbase.thirdparty.com.google.gson.JsonElement)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Optional (java.util.Optional)1 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)1 ProcedureState (org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState)1 JsonArray (org.apache.hbase.thirdparty.com.google.gson.JsonArray)1 JsonObject (org.apache.hbase.thirdparty.com.google.gson.JsonObject)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1