Search in sources :

Example 1 with JsonObject

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

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

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

the class ProtobufMessageConverter method toJavaObject.

private static Object toJavaObject(JsonElement element) {
    if (element.isJsonNull()) {
        return null;
    } else if (element.isJsonPrimitive()) {
        JsonPrimitive primitive = element.getAsJsonPrimitive();
        if (primitive.isBoolean()) {
            return primitive.getAsBoolean();
        } else if (primitive.isNumber()) {
            return primitive.getAsNumber();
        } else if (primitive.isString()) {
            return primitive.getAsString();
        } else {
            return null;
        }
    } else if (element.isJsonArray()) {
        JsonArray array = element.getAsJsonArray();
        List<Object> list = new ArrayList<>();
        for (JsonElement arrayElement : array) {
            Object javaObject = toJavaObject(arrayElement);
            list.add(javaObject);
        }
        return list;
    } else if (element.isJsonObject()) {
        JsonObject object = element.getAsJsonObject();
        Map<String, Object> map = new LinkedHashMap<>();
        for (Entry<String, JsonElement> entry : object.entrySet()) {
            Object javaObject = toJavaObject(entry.getValue());
            map.put(entry.getKey(), javaObject);
        }
        return map;
    } else {
        return null;
    }
}
Also used : JsonArray(org.apache.hbase.thirdparty.com.google.gson.JsonArray) Entry(java.util.Map.Entry) JsonPrimitive(org.apache.hbase.thirdparty.com.google.gson.JsonPrimitive) JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(org.apache.hbase.thirdparty.com.google.gson.JsonObject) JsonObject(org.apache.hbase.thirdparty.com.google.gson.JsonObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

JsonElement (org.apache.hbase.thirdparty.com.google.gson.JsonElement)3 JsonObject (org.apache.hbase.thirdparty.com.google.gson.JsonObject)3 JsonArray (org.apache.hbase.thirdparty.com.google.gson.JsonArray)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 JsonPrimitive (org.apache.hbase.thirdparty.com.google.gson.JsonPrimitive)1