Search in sources :

Example 11 with ClientConfig

use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.

the class ZeppelinClientExample2 method main.

public static void main(String[] args) throws Exception {
    ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
    ZeppelinClient zClient = new ZeppelinClient(clientConfig);
    String zeppelinVersion = zClient.getVersion();
    System.out.println("Zeppelin version: " + zeppelinVersion);
    // execute note 2A94M5J1Z paragraph by paragraph
    try {
        ParagraphResult paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150210-015259_1403135953");
        System.out.println("Execute the 1st spark tutorial paragraph, paragraph result: " + paragraphResult);
        paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150210-015302_1492795503");
        System.out.println("Execute the 2nd spark tutorial paragraph, paragraph result: " + paragraphResult);
        Map<String, String> parameters = new HashMap<>();
        parameters.put("maxAge", "40");
        paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150212-145404_867439529", parameters);
        System.out.println("Execute the 3rd spark tutorial paragraph, paragraph result: " + paragraphResult);
        parameters = new HashMap<>();
        parameters.put("marital", "married");
        paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150213-230422_1600658137", parameters);
        System.out.println("Execute the 4th spark tutorial paragraph, paragraph result: " + paragraphResult);
    } finally {
        // you need to stop interpreter explicitly if you are running paragraph separately.
        zClient.stopInterpreter("2A94M5J1Z", "spark");
    }
    // execute this whole note, this note will run under a didicated interpreter process which will be
    // stopped after note execution.
    Map<String, String> parameters = new HashMap<>();
    parameters.put("maxAge", "40");
    parameters.put("marital", "married");
    NoteResult noteResult = zClient.executeNote("2A94M5J1Z", parameters);
    System.out.println("Execute the spark tutorial note, note result: " + noteResult);
}
Also used : NoteResult(org.apache.zeppelin.client.NoteResult) HashMap(java.util.HashMap) ZeppelinClient(org.apache.zeppelin.client.ZeppelinClient) ClientConfig(org.apache.zeppelin.client.ClientConfig) ParagraphResult(org.apache.zeppelin.client.ParagraphResult)

Example 12 with ClientConfig

use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.

the class FlinkAdvancedExample method main.

public static void main(String[] args) {
    ZSession session = null;
    try {
        ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
        Map<String, String> intpProperties = new HashMap<>();
        session = ZSession.builder().setClientConfig(clientConfig).setInterpreter("flink").setIntpProperties(intpProperties).build();
        // if MessageHandler is specified, then websocket is enabled.
        // you can get continuous output from Zeppelin via websocket.
        session.start(new SimpleMessageHandler());
        System.out.println("Flink Web UI: " + session.getWeburl());
        String code = "benv.fromElements(1,2,3,4,5,6,7,8,9,10).map(e=> {Thread.sleep(1000); e}).print()";
        System.out.println("Submit code: " + code);
        // use submit to run flink code in non-blocking way.
        ExecuteResult result = session.submit(code);
        System.out.println("Job status: " + result.getStatus());
        while (!result.getStatus().isCompleted()) {
            result = session.queryStatement(result.getStatementId());
            System.out.println("Job status: " + result.getStatus() + ", progress: " + result.getProgress());
            Thread.sleep(1000);
        }
        System.out.println("Job status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
        System.out.println("-----------------------------------------------------------------------------");
        System.out.println("Submit code: " + code);
        result = session.submit("benv.fromElements(1,2,3,4,5,6,7,8,9,10).map(e=> {Thread.sleep(1000); e}).print()");
        System.out.println("Job status: " + result.getStatus());
        result = session.waitUntilFinished(result.getStatementId());
        System.out.println("Job status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
        System.out.println("-----------------------------------------------------------------------------");
        code = "for(i <- 1 to 10) {\n" + "   Thread.sleep(1000)\n" + "   println(i)\n" + "}";
        System.out.println("Submit code: " + code);
        result = session.execute(code);
        System.out.println("Job status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
        System.out.println("-----------------------------------------------------------------------------");
        String initCode = IOUtils.toString(FlinkAdvancedExample.class.getResource("/init_stream.scala"));
        result = session.execute(initCode);
        System.out.println("Job status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
        // run flink ssql
        Map<String, String> localProperties = new HashMap<>();
        localProperties.put("type", "update");
        result = session.submit("ssql", localProperties, "select url, count(1) as pv from log group by url");
        session.waitUntilFinished(result.getStatementId());
        result = session.submit("ssql", localProperties, "select url, count(1) as pv from log group by url");
        session.waitUntilRunning(result.getStatementId());
        Thread.sleep(10 * 1000);
        System.out.println("Try to cancel statement: " + result.getStatementId());
        session.cancel(result.getStatementId());
        session.waitUntilFinished(result.getStatementId());
        System.out.println("Job status: " + result.getStatus());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null) {
            try {
                session.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ClientConfig(org.apache.zeppelin.client.ClientConfig) ExecuteResult(org.apache.zeppelin.client.ExecuteResult) ZSession(org.apache.zeppelin.client.ZSession) SimpleMessageHandler(org.apache.zeppelin.client.websocket.SimpleMessageHandler)

Example 13 with ClientConfig

use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.

the class ZeppelinClientWithAuthIntegrationTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(), "helium");
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ALLOWED_ORIGINS.getVarName(), "*");
    AbstractTestRestApi.startUpWithAuthenticationEnable(ZeppelinClientWithAuthIntegrationTest.class.getSimpleName());
    notebook = TestUtils.getInstance(Notebook.class);
    clientConfig = new ClientConfig("http://localhost:8080");
    zeppelinClient = new ZeppelinClient(clientConfig);
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) ZeppelinClient(org.apache.zeppelin.client.ZeppelinClient) ClientConfig(org.apache.zeppelin.client.ClientConfig) BeforeClass(org.junit.BeforeClass)

Aggregations

ClientConfig (org.apache.zeppelin.client.ClientConfig)13 HashMap (java.util.HashMap)10 ExecuteResult (org.apache.zeppelin.client.ExecuteResult)9 ZSession (org.apache.zeppelin.client.ZSession)9 SimpleMessageHandler (org.apache.zeppelin.client.websocket.SimpleMessageHandler)6 ZeppelinClient (org.apache.zeppelin.client.ZeppelinClient)4 NoteResult (org.apache.zeppelin.client.NoteResult)2 ParagraphResult (org.apache.zeppelin.client.ParagraphResult)2 Notebook (org.apache.zeppelin.notebook.Notebook)2 BeforeClass (org.junit.BeforeClass)2 CompositeMessageHandler (org.apache.zeppelin.client.websocket.CompositeMessageHandler)1