Search in sources :

Example 1 with LaunchJar

use of water.deploy.LaunchJar in project h2o-2 by h2oai.

the class CloudConnect method launch.

/**
   * Upload jars to an existing cloud and launches a custom job. Uses the Web API.
   */
public static void launch(String job, String host, File... jars) throws Exception {
    HttpClient client = new HttpClient();
    String args = "job_class=" + job + "&jars=";
    for (File f : jars) {
        PostMethod post = new PostMethod("http://" + host + "/Upload.json?key=" + f.getName());
        Part[] parts = { new FilePart(f.getName(), f) };
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
        if (200 != client.executeMethod(post))
            throw new RuntimeException("Request failed: " + post.getStatusLine());
        args += f.getName() + ",";
        post.releaseConnection();
    }
    String href = new LaunchJar().href();
    GetMethod get = new GetMethod("http://" + host + href + ".json?" + args);
    if (200 != client.executeMethod(get))
        throw new RuntimeException("Request failed: " + get.getStatusLine());
    get.releaseConnection();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) LaunchJar(water.deploy.LaunchJar)

Aggregations

HttpClient (org.apache.commons.httpclient.HttpClient)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1 LaunchJar (water.deploy.LaunchJar)1