Search in sources :

Example 1 with ZeppelinClient

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

the class ZeppelinClientExample 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);
    String notePath = "/zeppelin_client_examples/note_1";
    String noteId = null;
    try {
        noteId = zClient.createNote(notePath);
        System.out.println("Created note: " + noteId);
        String newNotePath = notePath + "_rename";
        zClient.renameNote(noteId, newNotePath);
        NoteResult renamedNoteResult = zClient.queryNoteResult(noteId);
        System.out.println("Rename note: " + noteId + " name to " + renamedNoteResult.getNotePath());
        String paragraphId = zClient.addParagraph(noteId, "the first paragraph", "%python print('hello world')");
        ParagraphResult paragraphResult = zClient.executeParagraph(noteId, paragraphId);
        System.out.println("Added new paragraph and execute it.");
        System.out.println("Paragraph result: " + paragraphResult);
        String paragraphId2 = zClient.addParagraph(noteId, "the second paragraph", "%python\nimport time\ntime.sleep(5)\nprint('done')");
        zClient.submitParagraph(noteId, paragraphId2);
        zClient.waitUtilParagraphRunning(noteId, paragraphId2);
        zClient.cancelParagraph(noteId, paragraphId2);
        paragraphResult = zClient.waitUtilParagraphFinish(noteId, paragraphId2);
        System.out.println("Added new paragraph, submit it then cancel it");
        System.out.println("Paragraph result: " + paragraphResult);
        NoteResult noteResult = zClient.executeNote(noteId);
        System.out.println("Execute note and the note result: " + noteResult);
        zClient.submitNote(noteId);
        noteResult = zClient.waitUntilNoteFinished(noteId);
        System.out.println("Submit note and the note result: " + noteResult);
    } finally {
        if (noteId != null) {
            zClient.deleteNote(noteId);
            System.out.println("Note " + noteId + " is deleted");
        }
    }
}
Also used : NoteResult(org.apache.zeppelin.client.NoteResult) ZeppelinClient(org.apache.zeppelin.client.ZeppelinClient) ClientConfig(org.apache.zeppelin.client.ClientConfig) ParagraphResult(org.apache.zeppelin.client.ParagraphResult)

Example 2 with ZeppelinClient

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

the class ZeppelinClientIntegrationTest 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.startUp(ZeppelinClientIntegrationTest.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)

Example 3 with ZeppelinClient

use of org.apache.zeppelin.client.ZeppelinClient 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 4 with ZeppelinClient

use of org.apache.zeppelin.client.ZeppelinClient 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)4 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 HashMap (java.util.HashMap)1