Search in sources :

Example 1 with WrapperApp

use of com.vip.saturn.job.console.service.impl.marathon.entity.WrapperApp in project Saturn by vipshop.

the class MarathonRestClient method getContainerStatus.

public static ContainerStatus getContainerStatus(String userName, String password, String appId) throws SaturnJobConsoleException {
    String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + API_VERSION_DES + appId;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    try {
        HttpGet httpGet = new HttpGet(urlStr);
        httpGet.setHeader(AUTHORIZATION_DES, BASIC_DES + Base64.encodeBase64String((userName + ":" + password).getBytes(UTF8_DES)));
        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) {
                WrapperApp app = JSON.parseObject(entityContent, WrapperApp.class);
                ContainerStatus containerStatus = new ContainerStatus();
                containerStatus.setHealthyCount(app.getApp().getTasksHealthy());
                containerStatus.setUnhealthyCount(app.getApp().getTasksUnhealthy());
                containerStatus.setRunningCount(app.getApp().getTasksRunning());
                containerStatus.setStagedCount(app.getApp().getTasksStaged());
                containerStatus.setTotalCount(app.getApp().getInstances());
                return containerStatus;
            } else {
                throw new SaturnJobConsoleException(entityContent);
            }
        } else {
            throw new SaturnJobConsoleException("Not data returned, url is " + urlStr);
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    } finally {
        try {
            httpClient.close();
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ContainerStatus(com.vip.saturn.job.console.domain.container.ContainerStatus) WrapperApp(com.vip.saturn.job.console.service.impl.marathon.entity.WrapperApp) HttpEntity(org.apache.http.HttpEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException)

Aggregations

ContainerStatus (com.vip.saturn.job.console.domain.container.ContainerStatus)1 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)1 WrapperApp (com.vip.saturn.job.console.service.impl.marathon.entity.WrapperApp)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