Search in sources :

Example 1 with PerRequestConfig

use of com.ning.http.client.PerRequestConfig in project Singularity by HubSpot.

the class SandboxManager method browse.

public Collection<MesosFileObject> browse(String slaveHostname, String fullPath) throws SlaveNotFoundException {
    try {
        PerRequestConfig timeoutConfig = new PerRequestConfig();
        timeoutConfig.setRequestTimeoutInMs((int) configuration.getSandboxHttpTimeoutMillis());
        Response response = asyncHttpClient.prepareGet(String.format("http://%s:5051/files/browse", slaveHostname)).setPerRequestConfig(timeoutConfig).addQueryParameter("path", fullPath).execute().get();
        if (response.getStatusCode() == 404) {
            return Collections.emptyList();
        }
        if (response.getStatusCode() != 200) {
            throw new RuntimeException(String.format("Got HTTP %s from Mesos slave", response.getStatusCode()));
        }
        return objectMapper.readValue(response.getResponseBodyAsStream(), MESOS_FILE_OBJECTS);
    } catch (ConnectException ce) {
        throw new SlaveNotFoundException(ce);
    } catch (Exception e) {
        if (e.getCause().getClass() == ConnectException.class) {
            throw new SlaveNotFoundException(e);
        } else {
            throw Throwables.propagate(e);
        }
    }
}
Also used : Response(com.ning.http.client.Response) PerRequestConfig(com.ning.http.client.PerRequestConfig) IOException(java.io.IOException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Aggregations

PerRequestConfig (com.ning.http.client.PerRequestConfig)1 Response (com.ning.http.client.Response)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1