Search in sources :

Example 1 with JsonElement

use of org.apache.hbase.thirdparty.com.google.gson.JsonElement 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 JsonElement

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

the class ProtobufUtil method toLockJson.

public static String toLockJson(List<LockServiceProtos.LockedResource> lockedResourceProtos) {
    JsonArray lockedResourceJsons = new JsonArray(lockedResourceProtos.size());
    for (LockServiceProtos.LockedResource lockedResourceProto : lockedResourceProtos) {
        try {
            JsonElement lockedResourceJson = ProtobufMessageConverter.toJsonElement(lockedResourceProto);
            lockedResourceJsons.add(lockedResourceJson);
        } catch (InvalidProtocolBufferException e) {
            lockedResourceJsons.add(e.toString());
        }
    }
    return lockedResourceJsons.toString();
}
Also used : JsonArray(org.apache.hbase.thirdparty.com.google.gson.JsonArray) LockServiceProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos) JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException)

Example 3 with JsonElement

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

the class ProcedureTestUtil method getProcedure.

private static Optional<JsonObject> getProcedure(HBaseTestingUtil util, Class<? extends Procedure<?>> clazz, JsonParser parser) throws IOException {
    JsonArray array = parser.parse(util.getAdmin().getProcedures()).getAsJsonArray();
    Iterator<JsonElement> iterator = array.iterator();
    while (iterator.hasNext()) {
        JsonElement element = iterator.next();
        JsonObject obj = element.getAsJsonObject();
        String className = obj.get("className").getAsString();
        if (className.equals(clazz.getName())) {
            return Optional.of(obj);
        }
    }
    return Optional.empty();
}
Also used : JsonArray(org.apache.hbase.thirdparty.com.google.gson.JsonArray) JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) JsonObject(org.apache.hbase.thirdparty.com.google.gson.JsonObject)

Example 4 with JsonElement

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

the class RESTApiClusterManager method getRolePropertyValue.

// Get the value of a property from a role on a particular host.
private String getRolePropertyValue(String serviceName, String roleType, String hostId, String property) {
    String roleValue = null;
    URI uri = UriBuilder.fromUri(serverHostname).path("api").path(API_VERSION).path("clusters").path(clusterName).path("services").path(serviceName).path("roles").build();
    JsonElement roles = parser.parse(getFromURIGet(uri)).getAsJsonObject().get("items");
    if (roles != null) {
        // Iterate through the list of roles, stopping once the requested one is found.
        for (JsonElement role : roles.getAsJsonArray()) {
            JsonObject roleObj = role.getAsJsonObject();
            if (roleObj.get("hostRef").getAsJsonObject().get("hostId").getAsString().equals(hostId) && roleObj.get("type").getAsString().toLowerCase(Locale.ROOT).equals(roleType.toLowerCase(Locale.ROOT))) {
                roleValue = roleObj.get(property).getAsString();
                break;
            }
        }
    }
    return roleValue;
}
Also used : JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) JsonObject(org.apache.hbase.thirdparty.com.google.gson.JsonObject) URI(java.net.URI)

Example 5 with JsonElement

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

the class RESTApiClusterManager method getHostId.

// This API uses a hostId to execute host-specific commands; get one from a hostname.
private String getHostId(String hostname) {
    String hostId = null;
    URI uri = UriBuilder.fromUri(serverHostname).path("api").path(API_VERSION).path("hosts").build();
    JsonElement hosts = parser.parse(getFromURIGet(uri)).getAsJsonObject().get("items");
    if (hosts != null) {
        // Iterate through the list of hosts, stopping once you've reached the requested hostname.
        for (JsonElement host : hosts.getAsJsonArray()) {
            if (host.getAsJsonObject().get("hostname").getAsString().equals(hostname)) {
                hostId = host.getAsJsonObject().get("hostId").getAsString();
                break;
            }
        }
    }
    return hostId;
}
Also used : JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) URI(java.net.URI)

Aggregations

JsonElement (org.apache.hbase.thirdparty.com.google.gson.JsonElement)8 JsonArray (org.apache.hbase.thirdparty.com.google.gson.JsonArray)4 URI (java.net.URI)3 JsonObject (org.apache.hbase.thirdparty.com.google.gson.JsonObject)3 InvalidProtocolBufferException (org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 LockServiceProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos)1 ProcedureProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos)1 JsonParser (org.apache.hbase.thirdparty.com.google.gson.JsonParser)1 JsonPrimitive (org.apache.hbase.thirdparty.com.google.gson.JsonPrimitive)1