Java Code Examples for org.apache.kylin.common.util.JsonUtil#writeValueAsString()
The following examples show how to use
org.apache.kylin.common.util.JsonUtil#writeValueAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CubeInstance.java From kylin with Apache License 2.0 | 6 votes |
public void setCuboids(Map<Long, Long> cuboids) { if (cuboids == null) return; if (cuboids.isEmpty()) { cuboidBytes = null; return; } try { String str = JsonUtil.writeValueAsString(cuboids); byte[] compressed = CompressionUtils.compress(str.getBytes(StandardCharsets.UTF_8)); cuboidBytes = compressed; } catch (IOException e) { throw new RuntimeException(e); } }
Example 2
Source File: RestClient.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
public void clearCacheForCubeMigration(String cube, String project, String model, Map<String, String> tableToProjects) throws IOException { String url = baseUrl + "/cache/migration"; HttpPost post = new HttpPost(url); post.addHeader("Accept", "application/json, text/plain, */*"); post.addHeader("Content-Type", APPLICATION_JSON); HashMap<String, Object> paraMap = new HashMap<String, Object>(); paraMap.put("cube", cube); paraMap.put("project", project); paraMap.put("model", model); paraMap.put("tableToProjects", tableToProjects); String jsonMsg = JsonUtil.writeValueAsString(paraMap); post.setEntity(new StringEntity(jsonMsg, UTF_8)); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() != 200) { throw new IOException(INVALID_RESPONSE + response.getStatusLine().getStatusCode()); } }
Example 3
Source File: RestClient.java From kylin with Apache License 2.0 | 6 votes |
public void clearCacheForCubeMigration(String cube, String project, String model, Map<String, String> tableToProjects) throws IOException { String url = baseUrl + "/cache/migration"; HttpPost post = new HttpPost(url); post.addHeader("Accept", "application/json, text/plain, */*"); post.addHeader("Content-Type", APPLICATION_JSON); HashMap<String, Object> paraMap = new HashMap<String, Object>(); paraMap.put("cube", cube); paraMap.put("project", project); paraMap.put("model", model); paraMap.put("tableToProjects", tableToProjects); String jsonMsg = JsonUtil.writeValueAsString(paraMap); post.setEntity(new StringEntity(jsonMsg, UTF_8)); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() != 200) { throw new IOException(INVALID_RESPONSE + response.getStatusLine().getStatusCode()); } }
Example 4
Source File: SQLResponseTest.java From kylin with Apache License 2.0 | 6 votes |
@Test public void testInterfaceConsistency() throws IOException { String[] attrArray = new String[] { "columnMetas", "results", "cube", "affectedRowCount", "isException", "exceptionMessage", "duration", "partial", "totalScanCount", "hitExceptionCache", "storageCacheUsed", "pushDown", "traceUrl", "totalScanBytes" }; SQLResponse sqlResponse = new SQLResponse(null, null, "learn_cube", 100, false, null, false, false); String jsonStr = JsonUtil.writeValueAsString(sqlResponse); System.out.println(jsonStr); JsonNode jnode = JsonUtil.readValueAsTree(jsonStr); assertEquals(jnode.size(), attrArray.length); for (String attr : attrArray) { Assert.assertTrue(attr + " doesn't exist", jnode.has(attr)); } }
Example 5
Source File: ZookeeperStreamMetadataStore.java From kylin with Apache License 2.0 | 5 votes |
@Override public void updateSegmentBuildState(String cubeName, String segmentName, SegmentBuildState.BuildState state) { logger.trace("Update {} {} to state {}", cubeName, segmentName, state); checkPath(cubeName, segmentName); try { String stateStr = JsonUtil.writeValueAsString(state); String path = ZKPaths.makePath(cubeRoot, cubeName, CUBE_BUILD_STATE, segmentName); client.setData().forPath(path, Bytes.toBytes(stateStr)); writeSuccess.getAndIncrement(); } catch (Exception e) { writeFail.getAndIncrement(); logger.error("Fail to update segment build state for " + segmentName + " to " + state, e); throw new StoreException(e); } }
Example 6
Source File: HttpStreamDataSearchClient.java From kylin with Apache License 2.0 | 5 votes |
public Iterator<ITuple> doSearch(DataRequest dataRequest, CubeInstance cube, StreamingTupleConverter tupleConverter, RecordsSerializer recordsSerializer, Node receiver, TupleInfo tupleInfo) throws Exception { String queryId = dataRequest.getQueryId(); String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/data/query"; try { int connTimeout = cube.getConfig().getStreamingRPCHttpConnTimeout(); int readTimeout = cube.getConfig().getStreamingRPCHttpReadTimeout(); dataRequest.setDeadline(System.currentTimeMillis() + (int)(readTimeout * 1.5)); String content = JsonUtil.writeValueAsString(dataRequest); Stopwatch sw; sw = Stopwatch.createUnstarted(); sw.start(); String msg = restService.postRequest(url, content, connTimeout, readTimeout); logger.info("query-{}: receive response from {} take time:{}", queryId, receiver, sw.elapsed(MILLISECONDS)); if (failedReceivers.containsKey(receiver)) { failedReceivers.remove(receiver); } DataResponse response = JsonUtil.readValue(msg, DataResponse.class); logger.info("query-{}: receiver {} profile info:{}", queryId, receiver, response.getProfile()); return deserializeResponse(tupleConverter, recordsSerializer, cube.getName(), tupleInfo, response); } catch (Exception e) { logger.error("error when search data from receiver:" + url, e); throw e; } }
Example 7
Source File: MemcachedCache.java From kylin with Apache License 2.0 | 5 votes |
protected String serializeKey(Object key) { try { return JsonUtil.writeValueAsString(key); } catch (JsonProcessingException e) { logger.warn("Can not convert key to String.", e); } return null; }
Example 8
Source File: HttpReceiverAdminClient.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public ConsumerStatsResponse stopConsumers(Node receiver, StopConsumersRequest stopRequest) throws IOException { logger.info("send stop consume request:{} to receiver:{}", stopRequest, receiver); String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/consumers/stop"; String content = JsonUtil.writeValueAsString(stopRequest); String retMsg = retryPostRequest(url, content); return JsonUtil.readValue(retMsg, ConsumerStatsResponse.class); }
Example 9
Source File: HttpReceiverAdminClient.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public void startConsumers(Node receiver, StartConsumersRequest startRequest) throws IOException { logger.info("send start request:{} to receiver:{}", startRequest, receiver); String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/consumers/start"; String content = JsonUtil.writeValueAsString(startRequest); retryPostRequest(url, content); }
Example 10
Source File: HttpReceiverAdminClient.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public void unAssign(Node receiver, UnAssignRequest unAssignRequest) throws IOException { logger.info("send unAssign request:{} to receiver:{}", unAssignRequest, receiver); String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/unAssign"; String content = JsonUtil.writeValueAsString(unAssignRequest); retryPostRequest(url, content); }
Example 11
Source File: HttpReceiverAdminClient.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public void assign(Node receiver, AssignRequest assignRequest) throws IOException { logger.info("send assign request:{} to receiver:{}", assignRequest, receiver); final String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/assign"; final String content = JsonUtil.writeValueAsString(assignRequest); retryPostRequest(url, content); }
Example 12
Source File: HttpReceiverAdminClient.java From kylin with Apache License 2.0 | 5 votes |
@Override public ConsumerStatsResponse resumeConsumers(Node receiver, ResumeConsumerRequest resumeRequest) throws IOException { logger.info("send resume consumer request:{} to receiver:{}", resumeRequest, receiver); String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/consumers/resume"; String content = JsonUtil.writeValueAsString(resumeRequest); String retMsg = retryPostRequest(url, content); return JsonUtil.readValue(retMsg, ConsumerStatsResponse.class); }
Example 13
Source File: MemcachedCache.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
protected String serializeKey(Object key) { try { return JsonUtil.writeValueAsString(key); } catch (JsonProcessingException e) { logger.warn("Can not convert key to String.", e); } return null; }
Example 14
Source File: CubeInstance.java From kylin with Apache License 2.0 | 5 votes |
public void setCuboidsRecommend(Set<Long> cuboids) { if (cuboids == null) return; if (cuboids.isEmpty()) { cuboidBytesRecommend = null; return; } try { String str = JsonUtil.writeValueAsString(cuboids); byte[] compressed = CompressionUtils.compress(str.getBytes(StandardCharsets.UTF_8)); cuboidBytesRecommend = compressed; } catch (IOException e) { throw new RuntimeException(e); } }
Example 15
Source File: HttpReceiverAdminClient.java From kylin with Apache License 2.0 | 5 votes |
@Override public ConsumerStatsResponse stopConsumers(Node receiver, StopConsumersRequest stopRequest) throws IOException { logger.info("send stop consume request:{} to receiver:{}", stopRequest, receiver); String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/consumers/stop"; String content = JsonUtil.writeValueAsString(stopRequest); String retMsg = retryPostRequest(url, content); return JsonUtil.readValue(retMsg, ConsumerStatsResponse.class); }
Example 16
Source File: ZookeeperStreamMetadataStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public void updateSegmentBuildState(String cubeName, String segmentName, SegmentBuildState.BuildState state) { logger.trace("Update {} {} to state {}", cubeName, segmentName, state); checkPath(cubeName, segmentName); try { String stateStr = JsonUtil.writeValueAsString(state); String path = ZKPaths.makePath(cubeRoot, cubeName, CUBE_BUILD_STATE, segmentName); client.setData().forPath(path, Bytes.toBytes(stateStr)); writeSuccess.getAndIncrement(); } catch (Exception e) { writeFail.getAndIncrement(); logger.error("Fail to update segment build state for " + segmentName + " to " + state, e); throw new StoreException(e); } }
Example 17
Source File: QueryService.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override public void serialize(QueryRecord record, DataOutputStream out) throws IOException { String jsonStr = JsonUtil.writeValueAsString(record); out.writeUTF(jsonStr); }
Example 18
Source File: ZookeeperStreamMetadataStore.java From kylin with Apache License 2.0 | 4 votes |
private byte[] serializeReplicaSet(ReplicaSet rs) throws Exception { String nodesStr = JsonUtil.writeValueAsString(rs); return Bytes.toBytes(nodesStr); }
Example 19
Source File: CubeDescTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 3 votes |
@Test public void testSerializeMap() throws Exception { Map<String, String> map = Maps.newHashMap(); map.put("key1", "value1"); map.put("key2", "value2"); String mapStr = JsonUtil.writeValueAsString(map); //System.out.println(mapStr); Map<?, ?> map2 = JsonUtil.readValue(mapStr, HashMap.class); Assert.assertEquals(map, map2); }
Example 20
Source File: CubeDescTest.java From kylin with Apache License 2.0 | 3 votes |
@Test public void testSerializeMap() throws Exception { Map<String, String> map = Maps.newHashMap(); map.put("key1", "value1"); map.put("key2", "value2"); String mapStr = JsonUtil.writeValueAsString(map); //System.out.println(mapStr); Map<?, ?> map2 = JsonUtil.readValue(mapStr, HashMap.class); Assert.assertEquals(map, map2); }