List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:co.cask.cdap.explore.executor.ExploreStatusHandler.java
License:Apache License
@Path("explore/status") @GET//from w w w .j a va 2s . com public void status(HttpRequest request, HttpResponder responder) { JsonObject json = new JsonObject(); json.addProperty("status", "OK"); responder.sendJson(HttpResponseStatus.OK, json); }
From source file:co.cask.cdap.gateway.handlers.AbstractMonitorHandler.java
License:Apache License
public void getServiceInstance(HttpRequest request, HttpResponder responder, String serviceName) throws Exception { JsonObject reply = new JsonObject(); if (!serviceManagementMap.containsKey(serviceName)) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Invalid service name %s", serviceName)); return;//from www . j a v a 2 s. co m } MasterServiceManager serviceManager = serviceManagementMap.get(serviceName); if (serviceManager.isServiceEnabled()) { int actualInstance = serviceManagementMap.get(serviceName).getInstances(); reply.addProperty("provisioned", actualInstance); reply.addProperty("requested", getSystemServiceInstanceCount(serviceName)); responder.sendJson(HttpResponseStatus.OK, reply); } else { responder.sendString(HttpResponseStatus.FORBIDDEN, String.format("Service %s is not enabled", serviceName)); } }
From source file:co.cask.cdap.gateway.handlers.AbstractMonitorHandler.java
License:Apache License
public void monitor(HttpRequest request, HttpResponder responder, String serviceName) { if (!serviceManagementMap.containsKey(serviceName)) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Invalid service name %s", serviceName)); return;/*w w w . ja v a 2s . c om*/ } MasterServiceManager masterServiceManager = serviceManagementMap.get(serviceName); if (!masterServiceManager.isServiceEnabled()) { responder.sendString(HttpResponseStatus.FORBIDDEN, String.format("Service %s is not enabled", serviceName)); return; } if (masterServiceManager.canCheckStatus() && masterServiceManager.isServiceAvailable()) { JsonObject json = new JsonObject(); json.addProperty("status", STATUSOK); responder.sendJson(HttpResponseStatus.OK, json); } else if (masterServiceManager.canCheckStatus()) { JsonObject json = new JsonObject(); json.addProperty("status", STATUSNOTOK); responder.sendJson(HttpResponseStatus.OK, json); } else { responder.sendString(HttpResponseStatus.BAD_REQUEST, "Operation not valid for this service"); } }
From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java
License:Apache License
private void runnableStatus(HttpResponder responder, Id.Program id, ProgramType type) { try {//w ww . ja v a 2 s .c om ProgramStatus status = getProgramStatus(id, type); if (status.getStatus().equals(HttpResponseStatus.NOT_FOUND.toString())) { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } else { JsonObject reply = new JsonObject(); reply.addProperty("status", status.getStatus()); responder.sendJson(HttpResponseStatus.OK, reply); } } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (Throwable e) { LOG.error("Got exception:", e); responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } }
From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java
License:Apache License
/** * Returns next scheduled runtime of a workflow. */// w ww . ja va 2s. com @GET @Path("/apps/{app-id}/workflows/{workflow-id}/nextruntime") public void getScheduledRunTime(HttpRequest request, HttpResponder responder, @PathParam("app-id") final String appId, @PathParam("workflow-id") final String workflowId) { try { String accountId = getAuthenticatedAccountId(request); Id.Program id = Id.Program.from(accountId, appId, workflowId); List<ScheduledRuntime> runtimes = scheduler.nextScheduledRuntime(id, ProgramType.WORKFLOW); JsonArray array = new JsonArray(); for (ScheduledRuntime runtime : runtimes) { JsonObject object = new JsonObject(); object.addProperty("id", runtime.getScheduleId()); object.addProperty("time", runtime.getTime()); array.add(object); } responder.sendJson(HttpResponseStatus.OK, array); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (Throwable e) { LOG.error("Got exception:", e); responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } }
From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java
License:Apache License
/** * Get schedule state./* ww w .j av a2 s .c o m*/ */ @GET @Path("/apps/{app-id}/workflows/{workflow-id}/schedules/{schedule-id}/status") public void getScheuleState(HttpRequest request, HttpResponder responder, @PathParam("app-id") final String appId, @PathParam("workflow-id") final String workflowId, @PathParam("schedule-id") final String scheduleId) { try { // get the accountId to catch if there is a security exception String accountId = getAuthenticatedAccountId(request); JsonObject json = new JsonObject(); json.addProperty("status", scheduler.scheduleState(scheduleId).toString()); responder.sendJson(HttpResponseStatus.OK, json); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (Throwable e) { LOG.error("Got exception:", e); responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } }
From source file:co.cask.cdap.gateway.handlers.ConsoleSettingsHttpHandler.java
License:Apache License
@Path("/") @GET/*w w w . j a v a 2 s . c o m*/ public void get(HttpRequest request, HttpResponder responder) throws Exception { String userId = Objects.firstNonNull(SecurityRequestContext.getUserId(), ""); Config userConfig; try { userConfig = store.get(userId); } catch (ConfigNotFoundException e) { Map<String, String> propMap = ImmutableMap.of(CONFIG_PROPERTY, "{}"); userConfig = new Config(userId, propMap); } JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(ID, userConfig.getId()); //We store the serialized JSON string of the properties in ConfigStore and we return a JsonObject back jsonObject.add(CONFIG_PROPERTY, JSON_PARSER.parse(userConfig.getProperties().get(CONFIG_PROPERTY))); responder.sendJson(HttpResponseStatus.OK, jsonObject); }
From source file:co.cask.cdap.gateway.handlers.DashboardHttpHandler.java
License:Apache License
@Path("/") @GET/*from w w w. j ava 2 s . com*/ public void list(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception { JsonArray jsonArray = new JsonArray(); List<Config> configList = dashboardStore.list(namespace); for (Config config : configList) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(ID, config.getId()); jsonObject.add(CONFIG_PROPERTY, JSON_PARSER.parse(config.getProperties().get(CONFIG_PROPERTY))); jsonArray.add(jsonObject); } responder.sendJson(HttpResponseStatus.OK, jsonArray); }
From source file:co.cask.cdap.gateway.handlers.DashboardHttpHandler.java
License:Apache License
@Path("/{dashboard-id}") @GET/*from w w w .j a va 2 s. c o m*/ public void get(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dashboard-id") String id) throws Exception { try { Config dashConfig = dashboardStore.get(namespace, id); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(ID, id); //Dashboard Config is stored in ConfigStore as serialized JSON string with CONFIG_PROPERTY key. //When we send the data back, we send it as JSON object instead of sending the serialized string. jsonObject.add(CONFIG_PROPERTY, JSON_PARSER.parse(dashConfig.getProperties().get(CONFIG_PROPERTY))); responder.sendJson(HttpResponseStatus.OK, jsonObject); } catch (ConfigNotFoundException e) { responder.sendString(HttpResponseStatus.NOT_FOUND, "Dashboard not found"); } }
From source file:co.cask.cdap.gateway.handlers.MonitorHandler.java
License:Apache License
/** * Returns the number of instances of CDAP Services *//*w w w .j a v a 2 s .c o m*/ @Path("/system/services/{service-name}/instances") @GET public void getServiceInstance(final HttpRequest request, final HttpResponder responder, @PathParam("service-name") String serviceName) throws Exception { JsonObject reply = new JsonObject(); if (!serviceManagementMap.containsKey(serviceName)) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Invalid service name %s", serviceName)); return; } MasterServiceManager serviceManager = serviceManagementMap.get(serviceName); if (serviceManager.isServiceEnabled()) { int actualInstance = serviceManagementMap.get(serviceName).getInstances(); reply.addProperty("provisioned", actualInstance); reply.addProperty("requested", getSystemServiceInstanceCount(serviceName)); responder.sendJson(HttpResponseStatus.OK, reply); } else { responder.sendString(HttpResponseStatus.FORBIDDEN, String.format("Service %s is not enabled", serviceName)); } }