@Override public String toString() { return this.schema.toString(); }
public static String toJson(Object o, String exclude) { final ObjectNode jsonNode = MAPPER.valueToTree(o); jsonNode.remove(exclude); return jsonNode.toString(); }
private JsonNode sendQuery(String query) throws Exception { URLConnection urlConnection = new URL("http://" + _brokerAddress + "/query").openConnection(); urlConnection.setDoOutput(true); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8")); writer.write(JsonUtils.newObjectNode().put("pql", query).toString()); writer.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "UTF-8")); return JsonUtils.stringToJsonNode(reader.readLine()); }
public static String groupName( IMetaStoreElementType elementType ) { ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); objectNode.put( "_", "Embedded MetaStore Elements" ); objectNode.put( "namespace", Preconditions.checkNotNull( elementType.getNamespace() ) ); objectNode.put( "type", Preconditions.checkNotNull( elementType.getId() ) ); return objectNode.toString(); }
ObjectNode getDashboardForElasticsearch(String dashboardPath) throws IOException { final ObjectMapper mapper = JsonUtils.getMapper(); final ObjectNode dashboard = (ObjectNode) mapper.readTree(IOUtils.getResourceAsStream(dashboardPath)); dashboard.put("editable", false); ObjectNode dashboardElasticsearchFormat = mapper.createObjectNode(); dashboardElasticsearchFormat.put("user", "guest"); dashboardElasticsearchFormat.put("group", "guest"); dashboardElasticsearchFormat.set(TITLE, dashboard.get(TITLE)); dashboardElasticsearchFormat.set("tags", dashboard.get("tags")); dashboardElasticsearchFormat.put("dashboard", dashboard.toString()); return dashboardElasticsearchFormat; }
@Override public LoadManagerReport deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectMapper mapper = ObjectMapperFactory.getThreadLocal(); ObjectNode root = ObjectMapperFactory.getThreadLocal().readTree(jsonParser); if ((root.has("loadReportType") && root.get("loadReportType").asText().equals(LoadReport.loadReportType)) || (root.has("underLoaded"))) { return mapper.readValue(root.toString(), LoadReport.class); } else { return mapper.readValue(root.toString(), LocalBrokerData.class); } } }
private static String writeDependencies(List<DependencyItem> items) { ObjectNode json = JsonNodeFactory.instance.objectNode(); ArrayNode maps = JsonNodeFactory.instance.arrayNode(); items.forEach((dependency) -> maps.add(mapDependency(dependency))); json.set("dependencies", maps); return json.toString(); }
public static org.apache.avro.Schema getAvroSchema(Schema schema) { ObjectNode avroSchema = JsonUtils.newObjectNode(); avroSchema.put("name", "data_gen_record"); avroSchema.put("type", "record"); ArrayNode fields = JsonUtils.newArrayNode(); for (FieldSpec fieldSpec : schema.getAllFieldSpecs()) { JsonNode jsonObject = fieldSpec.toAvroSchemaJsonObject(); fields.add(jsonObject); } avroSchema.set("fields", fields); return new org.apache.avro.Schema.Parser().parse(avroSchema.toString()); }
public String toJsonString() { ObjectNode objectNode = JsonUtils.newObjectNode(); objectNode.put(MAP_MODIFY_MODE_KEY, _modifyMode.toString()); objectNode.set(MAP_KEY, JsonUtils.objectToJsonNode(_map)); return objectNode.toString(); }
@Override public String encrypt(final String plaintext, final String passphrase, final Version cryptoVersion) { Preconditions.checkArgument(Version.V1_1.equals(cryptoVersion)); final String cipheredText = newEncryptor(passphrase).encrypt(plaintext); final ObjectNode node = MAPPER.createObjectNode(); node.put(CIPHERED_TEXT_KEY, cipheredText); node.put(VERSION_IDENTIFIER, Version.V1_1.versionStr()); return Crypto.encode(node.toString()); }
@Override public String encrypt(final String plaintext, final String passphrase, final Version cryptoVersion) { Preconditions.checkArgument(Version.V1_0.equals(cryptoVersion)); final String cipheredText = newEncryptor(passphrase).encrypt(plaintext); final ObjectNode node = MAPPER.createObjectNode(); node.put(CIPHERED_TEXT_KEY, cipheredText); node.put(VERSION_IDENTIFIER, Version.V1_0.versionStr()); return Crypto.encode(node.toString()); }
private String getTablesServedFromTenant(String tenantName) { Set<String> tables = new HashSet<>(); ObjectNode resourceGetRet = JsonUtils.newObjectNode(); for (String table : pinotHelixResourceManager.getAllTables()) { TableConfig tableConfig = pinotHelixResourceManager.getTableConfig(table); String tableConfigTenant = tableConfig.getTenantConfig().getServer(); if (tenantName.equals(tableConfigTenant)) { tables.add(table); } } resourceGetRet.set(TABLES, JsonUtils.objectToJsonNode(tables)); return resourceGetRet.toString(); }
@Override public Future<BrokerResponse> executeQueryAsync(String brokerAddress, final String query) { try { ObjectNode json = JsonNodeFactory.instance.objectNode(); json.put("pql", query); final String url = "http://" + brokerAddress + "/query"; final Future<Response> response = _httpClient.preparePost(url).setBody(json.toString()).execute(); return new BrokerResponseFuture(response, query, url); } catch (Exception e) { throw new PinotClientException(e); } }
@Test void shouldAllowJwkHeader() { objectNode.put("jwk", "key"); JwtHeader header = JwtHeaderHelper.create(asBase64(objectNode.toString())); assertThat(header.parameters.jwk, is("key")); }
@BeforeClass public void setUp() throws Exception { super.setUp(); // Create eight dummy server instances for (int i = 0; i < 8; ++i) { ObjectNode serverInstance = JsonUtils.newObjectNode(); serverInstance.put("host", hostName); serverInstance.put("port", Integer.toString(basePort + i)); serverInstance.put("tag", serverTenant); serverInstance.put("type", "server"); sendPostRequest(_controllerRequestURLBuilder.forInstanceCreate(), serverInstance.toString()); } }
@Test void keepOrdering() { List<Link> links = new ArrayList<>(); links.add(Link.create("first", "https://example.com")); links.add(Link.create("second", "https://example.com")); ObjectNode model = LinkMapper.mapLinks(links); String json = model.toString(); assertThat(json.indexOf("first")).isLessThan(json.indexOf("second")); }
@Test void keepOrderingWithMultipleUrlForSameRel() { List<Link> links = new ArrayList<>(); links.add(Link.create("first", "https://example.com")); links.add(Link.create("second", "https://example.com")); links.add(Link.create("first", "https://example.com")); ObjectNode model = LinkMapper.mapLinks(links); String json = model.toString(); assertThat(json.indexOf("first")).isLessThan(json.indexOf("second")); }
@Test public void testSendFileWithJson() throws Exception { ObjectNode segmentJson = JsonUtils.newObjectNode(); segmentJson.put(CommonConstants.Segment.Offline.DOWNLOAD_URL, TEST_URI); String jsonString = segmentJson.toString(); try (FileUploadDownloadClient fileUploadDownloadClient = new FileUploadDownloadClient()) { SimpleHttpResponse response = fileUploadDownloadClient .sendSegmentJson(FileUploadDownloadClient.getUploadSegmentHttpURI(TEST_HOST, TEST_PORT), jsonString); Assert.assertEquals(response.getStatusCode(), HttpStatus.SC_OK); Assert.assertEquals(response.getResponse(), "OK"); } }
@Test public void testGetDashboardForElasticsearch() throws Exception { String expected = "{\"user\":\"guest\",\"group\":\"guest\",\"title\":\"Test Title\",\"tags\":[\"jdbc\",\"db\"],\"dashboard\":\"{\\\"title\\\":\\\"Test Title\\\",\\\"editable\\\":false,\\\"failover\\\":false,\\\"panel_hints\\\":true,\\\"style\\\":\\\"dark\\\",\\\"refresh\\\":\\\"1m\\\",\\\"tags\\\":[\\\"jdbc\\\",\\\"db\\\"],\\\"timezone\\\":\\\"browser\\\"}\"}"; assertEquals(expected, elasticsearchClient.getDashboardForElasticsearch("Test Dashboard.json").toString()); }
@Test public void testSetReservedTagName() { final SpanWrapper span = createTestSpan(1, s -> s.setTag("duration_ms", "foo")); final ObjectNode jsonSpan = JsonUtils.toObjectNode(span); assertEquals(jsonSpan.toString(), 1, jsonSpan.get("duration_ms").intValue()); }