Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B49E7200D60 for ; Fri, 1 Dec 2017 16:43:04 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B1B0B160C06; Fri, 1 Dec 2017 15:43:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D1502160BFB for ; Fri, 1 Dec 2017 16:43:03 +0100 (CET) Received: (qmail 17276 invoked by uid 500); 1 Dec 2017 15:43:03 -0000 Mailing-List: contact user-help@livy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@livy.incubator.apache.org Delivered-To: mailing list user@livy.incubator.apache.org Received: (qmail 17264 invoked by uid 99); 1 Dec 2017 15:43:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Dec 2017 15:43:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 3F826180733 for ; Fri, 1 Dec 2017 15:43:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -2.401 X-Spam-Level: X-Spam-Status: No, score=-2.401 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-2.8, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id z8oyG_chjyH5 for ; Fri, 1 Dec 2017 15:43:00 +0000 (UTC) Received: from mail-qk0-f171.google.com (mail-qk0-f171.google.com [209.85.220.171]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 390225F24C for ; Fri, 1 Dec 2017 15:43:00 +0000 (UTC) Received: by mail-qk0-f171.google.com with SMTP id i130so13648408qke.4 for ; Fri, 01 Dec 2017 07:43:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=3qmGUOlyxzYyWim2x7fCOwr9xp5iWTDHZGonYi4c388=; b=Hgff/tGGTH+lg7TjlBgjDgj7EETSx7xFm6FNd3+cofGTL0LaMwKRmYXp52yJpO9HPH dtyhUMqt5VRgklkN3/k1vW2FwDB3IXt2JCg0v8glNnaNEd/lkxaLa53c3Fh4GMbLb4Wg kAHP6a4GsGg8CjQ9JJLk+9dRG485kUos4RGtFSWyTaj+hO6AozTNKw0w49sA5EDBB6k8 QO2NNyHYXVJCaBiyhuhT1IkQhTsskmlXL14bNxV6FMQC/9b31U+4JZaf2jmd9iu1ENeS GJ5YxSBwddS3lCIcL9PAAgr1TRn726lqEBU0wNyKZr34p5jFz3pzrv2tZ4tSsjBc4YKo AkIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=3qmGUOlyxzYyWim2x7fCOwr9xp5iWTDHZGonYi4c388=; b=L1jLaMhf8CWl6H6XnSuoB5hHAL9t+cqPDJuc6zub8g0UNR98z2E2dn6Va+gd3pC/Jn YDhVYFC+PldUyZVe+sRU673ySTOqlc7nX0AISHv+2xt4n4zcK84VieUtB4R16G/931x6 I5cfMOmuGpImuDQTI01VrqA6eHD7qMG3vUpAHkjRRWcZdtVo+cYEW1L2hM5MtRx2rqYH zU4nm5bBbyDd3SKigBaUaNQTW5LBstGoPlfX0Ppskud1Ci3phbUNYY8FOH4dxVR91RNX iUnjM37MqYg9i25Vv7u9jqwivjsWteim/ZRATCfSQmbrkcMmmGzTux5j/fQMZS8fjo1o IQAQ== X-Gm-Message-State: AKGB3mI6qyN+zTm2NpIqXEIpvfTcnkuDOnpwZOJCQaImEKeUNnB6qfIz tanJxBJVr+RKcFOnq246D8RGGxiIcuGikVJGhWcdcA== X-Google-Smtp-Source: AGs4zMbDP72ZABtGG/vYCDnVFyQ4Ki3RUElcHtngKNL4UHH2WjNoteSyArTyip2QP/gTR/Xy9AGBwtfxHO6YGEtwKXo= X-Received: by 10.233.220.199 with SMTP id q190mr8657648qkf.72.1512142973169; Fri, 01 Dec 2017 07:42:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.55.99.68 with HTTP; Fri, 1 Dec 2017 07:42:52 -0800 (PST) In-Reply-To: References: From: Stefan Miklosovic Date: Fri, 1 Dec 2017 16:42:52 +0100 Message-ID: Subject: Re: How to submit the job via REST ? To: user@livy.incubator.apache.org Content-Type: text/plain; charset="UTF-8" archived-at: Fri, 01 Dec 2017 15:43:04 -0000 As a former Red Hatter, I am using ShrinkWrap and ShrinkWrap Maven resolver for it. It basically looks like this: public static final class JarBuilder { public File buildJobJar(File destinationJar) { final JavaArchive javaArchive = ShrinkWrap.create(MavenImporter.class) .loadPomFromFile("pom.xml") .importBuildOutput() .as(JavaArchive.class) .addClass(MyLivyJob.class); logger.info(javaArchive.toString(true)); javaArchive.as(ZipExporter.class).exportTo(destinationJar, true); return destinationJar; } // for every other dependency in the runtime which is not bundled into the build jar // you would need to make something similar as below public File buildHttpClientJar() { return Maven.configureResolver() .withMavenCentralRepo(true) .resolve(HTTP_CLIENT_COORDINATES) .withoutTransitivity() .asSingleFile(); } public File buildJacksonDatatyeJodaJar() { return Maven.configureResolver() .withMavenCentralRepo(true) .resolve(JACKSON_DATATYPE_JODA_COORDINATES) .withoutTransitivity() .asSingleFile(); } } After that, you just use uploadJar on livy client instance. After that, you can submit your job via submit method on Livy client. Notice that I made a jar and I added that job class into that. If you dont add it there and you upload it, it will not know how to deserialize it because that compiled class would not be there. On Fri, Dec 1, 2017 at 3:54 PM, Meisam Fathi wrote: > You should compile and package PiJar before running this code snippet. It > does not need to be a separate app/project. You can put the PiJob code right > next to the code snippet to run it. MVN/sbt/gradle can create the jar for > you and I assume there is a way to call them programmatically, but that is > not needed. You can use the path to the jar file as piJar. > > I hope this answers your question. > > Thanks, > Meisam > > import org.apache.spark.api.java.function.*; > > import org.apache.livy.*; > > public class PiJob implements Job, Function, > Function2 { > > private final int samples; > > public PiJob(int samples) { > this.samples = samples; > } > > @Override > public Double call(JobContext ctx) throws Exception { > List sampleList = new ArrayList(); > for (int i = 0; i < samples; i++) { > sampleList.add(i + 1); > } > > return 4.0d * ctx.sc().parallelize(sampleList).map(this).reduce(this) / > samples; > } > > @Override > public Integer call(Integer v1) { > double x = Math.random(); > double y = Math.random(); > return (x*x + y*y < 1) ? 1 : 0; > } > > @Override > public Integer call(Integer v1, Integer v2) { > return v1 + v2; > } > > } > > > On Fri, Dec 1, 2017 at 1:09 AM kant kodali wrote: >> >> Hi All, >> >> I am looking at the following snippet of code and I wonder where and how >> do I create piJar ? can I create programmatically if so how? is there a >> complete hello world example somewhere where I can follow steps and see how >> this works? >> >> Concerning line >> >> client.uploadJar(new File(piJar)).get(); >> >> >> >> Code snippet >> >> LivyClient client = new LivyClientBuilder() >> .setURI(new URI(livyUrl)) >> .build(); >> >> try { >> System.err.printf("Uploading %s to the Spark context...\n", piJar); >> client.uploadJar(new File(piJar)).get(); >> >> System.err.printf("Running PiJob with %d samples...\n", samples); >> double pi = client.submit(new PiJob(samples)).get(); >> >> System.out.println("Pi is roughly: " + pi); >> } finally { >> client.stop(true); >> } -- Stefan Miklosovic