use of com.vip.saturn.job.console.marathon.entity.Tasks in project Saturn by vipshop.
the class MarathonRestClient method count.
public static int count(String userName, String password, String appId) throws SaturnJobConsoleException {
String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + "/v2/apps/" + appId + "/tasks";
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpGet httpGet = new HttpGet(urlStr);
httpGet.setHeader("Authorization", "Basic " + Base64.encodeBase64String((userName + ":" + password).getBytes("UTF-8")));
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
String entityContent = getEntityContent(entity);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() == 200) {
Tasks tasks = JSON.parseObject(entityContent, Tasks.class);
return tasks != null && tasks.getTasks() != null ? tasks.getTasks().size() : 0;
} else {
throw new SaturnJobConsoleException(entityContent);
}
} else {
throw new SaturnJobConsoleException("Not status returned, url is " + urlStr);
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
} finally {
try {
httpClient.close();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
Aggregations