public RestClient(String host, int port, String userName, String password, Integer httpConnectionTimeoutMs, Integer httpSocketTimeoutMs) { if (httpConnectionTimeoutMs != null) this.httpConnectionTimeoutMs = httpConnectionTimeoutMs; if (httpSocketTimeoutMs != null) this.httpSocketTimeoutMs = httpSocketTimeoutMs; init(host, port, userName, password); }
public boolean enableCube(String cubeName) throws Exception { return changeCubeStatus(baseUrl + CUBES + cubeName + "/enable"); }
public boolean disableCache() throws IOException { return setCache(false); }
private static void updateMeta(KylinConfig config) { String[] nodes = config.getRestServers(); for (String node : nodes) { RestClient restClient = new RestClient(node); try { logger.info("update meta cache for " + node); restClient.wipeCache(Broadcaster.SYNC_ALL, Broadcaster.Event.UPDATE.getType(), Broadcaster.SYNC_ALL); } catch (IOException e) { logger.error(e.getMessage()); } } }
@SuppressWarnings("unused") @Test public void basicTests() throws IOException { RestClient a = new RestClient("prod01:80"); //a.wipeCache("metadata", "a", "a"); //String aa = a.getKylinProperties(); //System.out.println(aa); RestClient b = new RestClient("sandbox.hortonworks.com:7070"); //b.wipeCache("metadata", "a", "a"); //String bb = b.getKylinProperties(); //System.out.println(bb); } }
public HashMap getCube(String cubeName) throws Exception { String url = baseUrl + CUBES + cubeName; HttpGet get = newGet(url); HttpResponse response = null; try { get.setURI(new URI(url)); response = client.execute(get); return dealResponse(response); } finally { cleanup(get, response); } }
private static UriType decideUriType(String metaUri) { try { File file = new File(metaUri); if (file.exists() || metaUri.contains("/")) { if (file.exists() == false) { file.mkdirs(); } if (file.isDirectory()) { return UriType.LOCAL_FOLDER; } else if (file.isFile()) { if (file.getName().equalsIgnoreCase(KYLIN_CONF_PROPERTIES_FILE)) { return UriType.PROPERTIES_FILE; } else { throw new IllegalStateException( METADATA_URI_PREFIX + metaUri + " is a local file but not kylin.properties"); } } else { throw new IllegalStateException( METADATA_URI_PREFIX + metaUri + " looks like a file but it's neither a file nor a directory"); } } else { if (RestClient.matchFullRestPattern(metaUri)) return UriType.REST_ADDR; else throw new IllegalStateException(METADATA_URI_PREFIX + metaUri + " is not a valid REST URI address"); } } catch (Exception e) { throw new IllegalStateException(METADATA_URI_PREFIX + metaUri + " is not recognized", e); } }
private HttpPost newPost(String url) { HttpPost post = new HttpPost(url); addHttpHeaders(post); return post; }
private HashMap dealResponse(HttpResponse response) throws IOException { if (response.getStatusLine().getStatusCode() != 200) { throw new IOException(INVALID_RESPONSE + response.getStatusLine().getStatusCode()); } String result = getContent(response); HashMap resultMap = new ObjectMapper().readValue(result, HashMap.class); return resultMap; }
public HttpResponse query(String sql, String project) throws IOException { String url = baseUrl + "/query"; HttpPost post = newPost(url); HashMap<String, String> paraMap = new HashMap<String, String>(); paraMap.put("sql", sql); paraMap.put("project", project); String jsonMsg = new ObjectMapper().writeValueAsString(paraMap); post.setEntity(new StringEntity(jsonMsg, UTF_8)); HttpResponse response = client.execute(post); return response; }
@After public void after() throws Exception { this.cleanupTestMetadata(); }
@Before public void setUp() throws Exception { this.createTestMetadata(); }
public RestClient(String uri, Integer httpConnectionTimeoutMs, Integer httpSocketTimeoutMs) { Matcher m = fullRestPattern.matcher(uri); if (!m.matches()) throw new IllegalArgumentException("URI: " + uri + " -- does not match pattern " + fullRestPattern); String user = m.group(1); String pwd = m.group(2); String host = m.group(3); String portStr = m.group(4); int port = Integer.parseInt(portStr == null ? "7070" : portStr); if (httpConnectionTimeoutMs != null) this.httpConnectionTimeoutMs = httpConnectionTimeoutMs; if (httpSocketTimeoutMs != null) this.httpSocketTimeoutMs = httpSocketTimeoutMs; init(host, port, user, pwd); }
public boolean purgeCube(String cubeName) throws Exception { return changeCubeStatus(baseUrl + CUBES + cubeName + "/purge"); }
private HttpGet newGet(String url) { HttpGet get = new HttpGet(); addHttpHeaders(get); return get; }
public void buildLookupSnapshotCache(String project, String lookupTableName, String snapshotID) throws IOException { String url = baseUrl + "/tables/" + project + "/" + lookupTableName + "/" + snapshotID + "/snapshotLocalCache"; HttpPut put = new HttpPut(url); HttpResponse response = client.execute(put); getContent(response); if (response.getStatusLine().getStatusCode() != 200) { throw new IOException(INVALID_RESPONSE + response.getStatusLine().getStatusCode() + WITH_URL + url + "\n"); } }
public boolean enableCache() throws IOException { return setCache(true); }
public boolean disableCube(String cubeName) throws Exception { return changeCubeStatus(baseUrl + CUBES + cubeName + "/disable"); }
private HttpPut newPut(String url) { HttpPut put = new HttpPut(url); addHttpHeaders(put); return put; }
public String getLookupSnapshotCacheState(String lookupTableName, String snapshotID) throws IOException { String url = baseUrl + "/tables/" + lookupTableName + "/" + snapshotID + "/snapshotLocalCache/state"; HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); String content = getContent(response); if (response.getStatusLine().getStatusCode() != 200) { throw new IOException(INVALID_RESPONSE + response.getStatusLine().getStatusCode() + WITH_URL + url + "\n"); } return content; }