Search in sources :

Example 1 with Tasks

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);
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Tasks(com.vip.saturn.job.console.marathon.entity.Tasks) HttpEntity(org.apache.http.HttpEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)1 Tasks (com.vip.saturn.job.console.marathon.entity.Tasks)1 IOException (java.io.IOException)1 HttpEntity (org.apache.http.HttpEntity)1 StatusLine (org.apache.http.StatusLine)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1