List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
From source file:com.continuuity.loom.codec.json.current.ServiceActionCodec.java
License:Apache License
@Override public ServiceAction deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String actionType = context.deserialize(jsonObj.get("type"), String.class); Map<String, String> fields = context.deserialize(jsonObj.get("fields"), new TypeToken<Map<String, String>>() { }.getType());//from w w w . jav a 2 s . co m return new ServiceAction(actionType, fields); }
From source file:com.continuuity.loom.codec.json.current.ServiceCodec.java
License:Apache License
@Override public Service deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = context.deserialize(jsonObj.get("name"), String.class); String description = context.deserialize(jsonObj.get("description"), String.class); ServiceDependencies dependencies = context.deserialize(jsonObj.get("dependencies"), ServiceDependencies.class); JsonObject provisioner = context.deserialize(jsonObj.get("provisioner"), JsonObject.class); Map<ProvisionerAction, ServiceAction> actions = Collections.emptyMap(); if (provisioner != null) { actions = context.deserialize(provisioner.get("actions"), new TypeToken<Map<ProvisionerAction, ServiceAction>>() { }.getType());/*www .j av a2s . c om*/ } return new Service(name, description, dependencies, actions); }
From source file:com.continuuity.loom.codec.json.current.ServiceConstraintCodec.java
License:Apache License
@Override public ServiceConstraint deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); JsonObject quantities = jsonObj.get("quantities").getAsJsonObject(); Integer min = context.deserialize(quantities.get("min"), Integer.class); Integer max = context.deserialize(quantities.get("max"), Integer.class); Integer stepSize = context.deserialize(quantities.get("stepSize"), Integer.class); ImmutablePair<Integer, Integer> ratio = stringToRatio( context.<String>deserialize(quantities.get("ratio"), String.class)); Set<String> requiredHardwareTypes = context.deserialize(jsonObj.get("hardwaretypes"), new TypeToken<Set<String>>() { }.getType());//from w ww . j a v a 2 s . c om Set<String> requiredImageTypes = context.deserialize(jsonObj.get("imagetypes"), new TypeToken<Set<String>>() { }.getType()); return new ServiceConstraint(requiredHardwareTypes, requiredImageTypes, min, max, stepSize, ratio); }
From source file:com.continuuity.loom.codec.json.current.ServiceDependenciesCodec.java
License:Apache License
@Override public ServiceDependencies deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<String> provides = context.deserialize(jsonObj.get("provides"), new TypeToken<Set<String>>() { }.getType());//from www .j a va2 s. c o m Set<String> conflicts = context.deserialize(jsonObj.get("conflicts"), new TypeToken<Set<String>>() { }.getType()); ServiceStageDependencies install = context.deserialize(jsonObj.get("install"), ServiceStageDependencies.class); ServiceStageDependencies runtime = context.deserialize(jsonObj.get("runtime"), ServiceStageDependencies.class); return new ServiceDependencies(provides, conflicts, install, runtime); }
From source file:com.continuuity.loom.codec.json.current.ServiceStageDependenciesCodec.java
License:Apache License
@Override public ServiceStageDependencies deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<String> requires = context.deserialize(jsonObj.get("requires"), new TypeToken<Set<String>>() { }.getType());// w w w.j a va 2 s . com Set<String> uses = context.deserialize(jsonObj.get("uses"), new TypeToken<Set<String>>() { }.getType()); return new ServiceStageDependencies(requires, uses); }
From source file:com.continuuity.loom.codec.json.current.TakeTaskRequestCodec.java
License:Apache License
@Override public TakeTaskRequest deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String workerId = context.deserialize(jsonObj.get("workerId"), String.class); String provisionerId = context.deserialize(jsonObj.get("provisionerId"), String.class); String tenantId = context.deserialize(jsonObj.get("tenantId"), String.class); return new TakeTaskRequest(workerId, provisionerId, tenantId); }
From source file:com.continuuity.loom.codec.json.current.TaskConfigCodec.java
License:Apache License
@Override public TaskConfig deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { // make a copy since we'll be doing removes. This is because the provisioner results are at the // same level as all the other fields because... hacks JsonObject jsonObj = shallowCopy(json.getAsJsonObject()); Provider provider = context.deserialize(jsonObj.remove("provider"), Provider.class); Map<String, NodeProperties> nodePropertiesMap = context.deserialize(jsonObj.remove("nodes"), new TypeToken<Map<String, NodeProperties>>() { }.getType());// w w w .jav a 2 s .co m JsonObject clusterConfig = jsonObj.remove("cluster").getAsJsonObject(); TaskServiceAction taskServiceAction = context.deserialize(jsonObj.remove("service"), TaskServiceAction.class); // build node properties String hostname = context.deserialize(jsonObj.remove("hostname"), String.class); String ipaddress = context.deserialize(jsonObj.remove("ipaddress"), String.class); String imagetype = context.deserialize(jsonObj.remove("imagetype"), String.class); String hardwaretype = context.deserialize(jsonObj.remove("hardwaretype"), String.class); String flavor = context.deserialize(jsonObj.remove("flavor"), String.class); String image = context.deserialize(jsonObj.remove("image"), String.class); String sshUser = context.deserialize(jsonObj.remove("ssh-user"), String.class); Integer nodeNum = context.deserialize(jsonObj.remove("nodenum"), Integer.class); Set<String> serviceNames = context.deserialize(jsonObj.remove("services"), new TypeToken<Set<String>>() { }.getType()); Set<String> automators = context.deserialize(jsonObj.remove("automators"), new TypeToken<Set<String>>() { }.getType()); NodeProperties nodeProperties = NodeProperties.builder().setHostname(hostname).setIpaddress(ipaddress) .setNodenum(nodeNum).setHardwaretype(hardwaretype).setImagetype(imagetype).setFlavor(flavor) .setImage(image).setSSHUser(sshUser).setAutomators(automators).setServiceNames(serviceNames) .build(); // what's left is the provisioner results return new TaskConfig(nodeProperties, provider, nodePropertiesMap, taskServiceAction, clusterConfig, jsonObj); }
From source file:com.continuuity.loom.codec.json.current.TenantCodec.java
License:Apache License
@Override public Tenant deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String id = context.deserialize(jsonObj.get("id"), String.class); TenantSpecification specification = context.deserialize(jsonObj.get("specification"), TenantSpecification.class); return new Tenant(id, specification); }
From source file:com.continuuity.loom.codec.json.current.TenantSpecificationCodec.java
License:Apache License
@Override public TenantSpecification deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = context.deserialize(jsonObj.get("name"), String.class); Integer workers = context.deserialize(jsonObj.get("workers"), Integer.class); Integer maxClusters = context.deserialize(jsonObj.get("maxClusters"), Integer.class); Integer maxNodes = context.deserialize(jsonObj.get("maxNodes"), Integer.class); return new TenantSpecification(name, workers, maxClusters, maxNodes); }
From source file:com.continuuity.loom.codec.json.upgrade.ClusterUpgradeCodec.java
License:Apache License
@Override public Cluster deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String id = context.deserialize(jsonObj.get("id"), String.class); String name = context.deserialize(jsonObj.get("name"), String.class); String description = context.deserialize(jsonObj.get("description"), String.class); long createTime = jsonObj.get("createTime").getAsLong(); Long expireTime = context.deserialize(jsonObj.get("expireTime"), Long.class); Provider provider = context.deserialize(jsonObj.get("provider"), Provider.class); ClusterTemplate template = context.deserialize(jsonObj.get("clusterTemplate"), ClusterTemplate.class); Set<String> nodes = context.deserialize(jsonObj.get("nodes"), new TypeToken<Set<String>>() { }.getType());/*ww w . j a v a 2 s. c o m*/ Set<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<String>>() { }.getType()); String latestJobId = context.deserialize(jsonObj.get("latestJobId"), String.class); Cluster.Status status = context.deserialize(jsonObj.get("status"), Cluster.Status.class); JsonObject config = context.deserialize(jsonObj.get("config"), JsonObject.class); // 'jobs' got replaced by 'latestJobId' if (latestJobId == null) { List<String> jobIds = context.deserialize(jsonObj.get("jobs"), new TypeToken<List<String>>() { }.getType()); if (jobIds != null) { latestJobId = jobIds.get(jobIds.size() - 1); } } // owner id replaced with account String ownerId = context.deserialize(jsonObj.get("ownerId"), String.class); Account account = new Account(ownerId, tenant); return new Cluster(id, account, name, createTime, expireTime == null ? 0 : expireTime, description, provider, template, nodes, services, config, status, latestJobId); }