List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.AgentStatusReportExecutor.java
License:Apache License
public GoPluginApiResponse execute() throws Exception { String elasticAgentId = request.getElasticAgentId(); JobIdentifier jobIdentifier = request.getJobIdentifier(); LOG.info(String.format("[status-report] Generating status report for agent: %s with job: %s", elasticAgentId, jobIdentifier)); try {//ww w.ja va 2 s .co m agentInstances.refreshAll(pluginRequest); final DockerClient dockerClient = dockerClientFactory.docker(pluginRequest.getPluginSettings()); Service dockerService = findService(elasticAgentId, jobIdentifier, dockerClient); DockerServiceElasticAgent elasticAgent = DockerServiceElasticAgent.fromService(dockerService, dockerClient); final String statusReportView = builder.build(builder.getTemplate("agent-status-report.template.ftlh"), elasticAgent); JsonObject responseJSON = new JsonObject(); responseJSON.addProperty("view", statusReportView); return DefaultGoPluginApiResponse.success(responseJSON.toString()); } catch (Exception e) { return StatusReportGenerationErrorHandler.handle(builder, e); } }
From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.GetPluginSettingsIconExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("content-type", "image/png"); jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes("/docker-swarm.png"))); DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject));//from w ww . ja va 2 s. c o m return defaultGoPluginApiResponse; }
From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.StatusReportExecutor.java
License:Apache License
public GoPluginApiResponse execute() { try {/*from w ww .ja va 2s . c om*/ LOG.debug("[status-report] Generating status report."); agentInstances.refreshAll(pluginRequest); final DockerClient dockerClient = dockerClientFactory.docker(pluginRequest.getPluginSettings()); final SwarmCluster swarmCluster = new SwarmCluster(dockerClient); final Template template = statusReportViewBuilder.getTemplate("status-report.template.ftlh"); final String statusReportView = statusReportViewBuilder.build(template, swarmCluster); JsonObject responseJSON = new JsonObject(); responseJSON.addProperty("view", statusReportView); return DefaultGoPluginApiResponse.success(responseJSON.toString()); } catch (Exception e) { return StatusReportGenerationErrorHandler.handle(statusReportViewBuilder, e); } }
From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.reports.StatusReportGenerationErrorHandler.java
License:Apache License
public static GoPluginApiResponse handle(PluginStatusReportViewBuilder builder, Exception e) { try {//ww w . j a v a 2s . c om LOG.error(format("Error while generating status report: {0}", e.getMessage()), e); final Template template = builder.getTemplate("error.template.ftlh"); final String errorView = builder.build(template, new StatusReportGenerationError(e)); final JsonObject responseJSON = new JsonObject(); responseJSON.addProperty("view", errorView); return DefaultGoPluginApiResponse.success(responseJSON.toString()); } catch (Exception ex) { LOG.error(format("Failed to generate error report: {0}", e.getMessage()), e); return DefaultGoPluginApiResponse.error(format("Failed to generate error report: {0}.", e.toString())); } }
From source file:cd.go.contrib.elasticagents.marathon.executors.GetPluginSettingsIconExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("content_type", "image/svg+xml"); jsonObject.addProperty("data", BaseEncoding.base64().encode(Util.readResourceBytes("/plugin-icon.svg"))); return new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject)); }
From source file:cd.go.contrib.elasticagents.marathon.executors.GetProfileViewExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("template", Util.readResource("/profile.template.html")); return new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject)); }
From source file:cd.go.contrib.elasticagents.marathon.executors.GetViewRequestExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("template", Util.readResource("/plugin-settings.template.html")); return new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject)); }
From source file:cd.go.contrib.elasticagents.openstack.executors.GetPluginSettingsIconExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("content_type", "image/svg+xml"); jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes("/openstack-logo-vertical" + ".svg"))); DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject));// w w w.j a v a 2 s. co m return defaultGoPluginApiResponse; }
From source file:cf.adriantodt.David.modules.db.DBModule.java
License:LGPL
private DBModule() { mainConfig = ConfigUtils.get("main", ImmutableMap.<String, java.util.function.Predicate<JsonElement>>builder() .put("ownerID", ConfigUtils::isJsonString).put("token", ConfigUtils::isJsonString).build(), () -> {//w w w .j av a 2 s .c o m JsonObject object = new JsonObject(); object.add("ownerID", null); object.add("token", null); return object; }, false, true); JsonObject dbConfig = ConfigUtils.get("db", ImmutableMap.<String, java.util.function.Predicate<JsonElement>>builder() .put("hostname", ConfigUtils::isJsonString) .put("port", element -> ConfigUtils.isJsonNumber(element) && element.getAsInt() != 0) .build(), () -> { JsonObject object = new JsonObject(); object.addProperty("hostname", "localhost"); object.addProperty("port", 28015); return object; }, true, true); conn = r.connection().hostname(dbConfig.get("hostname").getAsString()).port(dbConfig.get("port").getAsInt()) .db("bot").connect(); }
From source file:cf.adriantodt.David.modules.db.I18nModule.java
License:LGPL
public static String generateJsonDump() { System.out.println();//w w w. ja v a 2 s .c o m JsonObject json = new JsonObject(); JsonObject parentsJson = new JsonObject(); JsonObject localizations = new JsonObject(); parents.forEach(parentsJson::addProperty); locales.forEach((k, v) -> { JsonObject localization = new JsonObject(); v.forEach(localization::addProperty); localizations.add(k, localization); }); json.add("parents", parentsJson); json.add("localizations", localizations); return json.toString(); }