List of usage examples for com.google.gson JsonObject get
public JsonElement get(String memberName)
From source file:co.cask.cdap.internal.app.runtime.codec.ProgramOptionsCodec.java
License:Apache License
@Override public ProgramOptions deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = jsonObj.get("name").getAsString(); Arguments arguments = context.deserialize(jsonObj.get("arguments"), Arguments.class); Arguments userArguments = context.deserialize(jsonObj.get("userArguments"), Arguments.class); boolean debug = jsonObj.get("debug").getAsBoolean(); return new SimpleProgramOptions(name, arguments, userArguments, debug); }
From source file:co.cask.cdap.internal.app.ScheduleCodec.java
License:Apache License
@Override public Schedule deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); String cronExpression = jsonObj.get("cronExpression").getAsString(); String action = jsonObj.get("action").getAsString(); return new Schedule(name, description, cronExpression, Schedule.Action.valueOf(action)); }
From source file:co.cask.cdap.internal.app.services.http.AppFabricTestBase.java
License:Apache License
/** * Waits for the given program to transit to the given state. *//* w ww. j ava 2s . c o m*/ protected void waitState(final Id.Program programId, String state) throws Exception { Tasks.waitFor(state, new Callable<String>() { @Override public String call() throws Exception { String path = String.format("apps/%s/%s/%s/status", programId.getApplicationId(), programId.getType().getCategoryName(), programId.getId()); HttpResponse response = doGet(getVersionedAPIPath(path, programId.getNamespaceId())); JsonObject status = GSON.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class); if (status == null || !status.has("status")) { return null; } return status.get("status").getAsString(); } }, 60, TimeUnit.SECONDS); }
From source file:co.cask.cdap.internal.app.ServiceSpecificationCodec.java
License:Apache License
@Override public ServiceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = (JsonObject) json; if (isOldSpec(jsonObj)) { return decodeOldSpec(jsonObj); }/*from ww w. ja v a 2 s . co m*/ String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); Map<String, HttpServiceHandlerSpecification> handlers = deserializeMap(jsonObj.get("handlers"), context, HttpServiceHandlerSpecification.class); Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class); int instances = jsonObj.get("instances").getAsInt(); return new ServiceSpecification(className, name, description, handlers, resources, instances); }
From source file:co.cask.cdap.internal.app.ServiceSpecificationCodec.java
License:Apache License
private ServiceSpecification decodeOldSpec(JsonObject json) { String className = json.get("classname").getAsString(); TwillSpecification twillSpec = twillSpecificationAdapter.fromJson(json.get("spec").getAsString()); Map<String, HttpServiceHandlerSpecification> handlers = Maps.newHashMap(); RuntimeSpecification handlerSpec = twillSpec.getRunnables().get(twillSpec.getName()); Map<String, String> configs = handlerSpec.getRunnableSpecification().getConfigs(); // Get the class names of all handlers. It is stored in the handler runnable spec configs List<String> handlerClasses = GSON.fromJson(configs.get("service.runnable.handlers"), new TypeToken<List<String>>() { }.getType());/*from www . j av a2 s . com*/ List<JsonObject> handlerSpecs = GSON.fromJson(configs.get("service.runnable.handler.spec"), new TypeToken<List<JsonObject>>() { }.getType()); for (int i = 0; i < handlerClasses.size(); i++) { String handlerClass = handlerClasses.get(i); JsonObject spec = handlerSpecs.get(i); Map<String, String> properties = GSON.fromJson(spec.get("properties"), new TypeToken<Map<String, String>>() { }.getType()); // Reconstruct the HttpServiceSpecification. However there is no way to determine the datasets or endpoints // as it is not recorded in old spec. It's ok since the spec is only used to load data from MDS during redeploy. handlers.put(spec.get("name").getAsString(), new HttpServiceHandlerSpecification(handlerClass, spec.get("name").getAsString(), spec.get("description").getAsString(), properties, ImmutableSet.<String>of(), ImmutableList.<ServiceHttpEndpoint>of())); } ResourceSpecification resourceSpec = handlerSpec.getResourceSpecification(); return new ServiceSpecification(className, twillSpec.getName(), twillSpec.getName(), handlers, new Resources(resourceSpec.getMemorySize(), resourceSpec.getVirtualCores()), resourceSpec.getInstances()); }
From source file:co.cask.cdap.internal.app.SparkSpecificationCodec.java
License:Apache License
@Override public SparkSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); String mainClassName = jsonObj.get("mainClassName").getAsString(); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); return new DefaultSparkSpecification(className, name, description, mainClassName, properties); }
From source file:co.cask.cdap.internal.app.WorkflowActionSpecificationCodec.java
License:Apache License
@Override public WorkflowActionSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); return new DefaultWorkflowActionSpecification(className, name, description, properties); }
From source file:co.cask.cdap.internal.app.WorkflowSpecificationCodec.java
License:Apache License
@Override public WorkflowSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); List<WorkflowActionSpecification> actions = deserializeList(jsonObj.get("actions"), context, WorkflowActionSpecification.class); Map<String, MapReduceSpecification> mapReduces = deserializeMap(jsonObj.get("mapReduces"), context, MapReduceSpecification.class); List<Schedule> schedules = deserializeList(jsonObj.get("schedules"), context, Schedule.class); return new DefaultWorkflowSpecification(className, name, description, actions, mapReduces, schedules); }
From source file:co.cask.cdap.internal.filesystem.LocationCodec.java
License:Apache License
@Override public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { JsonObject jsonObj = json.getAsJsonObject(); String uri = jsonObj.get("uri").getAsString(); try {// www. j ava 2 s . c o m return lf.create(new URI(uri)); } catch (URISyntaxException e) { // should never happen throw new IllegalStateException("Invalid uri " + uri + " found. Cannot deserialize location.", e); } }
From source file:co.cask.cdap.notifications.NotificationFeedInfoDeserializer.java
License:Apache License
@Override public NotificationFeedInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject obj = json.getAsJsonObject(); String category = obj.get("category").getAsString(); JsonElement descriptionElement = obj.get("description"); String description = descriptionElement == null ? "" : descriptionElement.getAsString(); String namespace;//from w ww . java 2s . co m String feed; JsonElement namespaceElement = obj.get("namespace"); // this means its the old Id.NotificationFeed object where namespace is something like "namespace":{"id":"default"} if (namespaceElement.isJsonObject()) { namespace = namespaceElement.getAsJsonObject().get("id").getAsString(); feed = obj.get("name").getAsString(); } else { namespace = namespaceElement.getAsString(); feed = obj.get("feed").getAsString(); } return new NotificationFeedInfo(namespace, category, feed, description); }