Apache Zeppelin SDK - Zeppelin Client API

Overview

Zeppelin client api is a lower level java api which encapsulates Zeppelin's rest api so that you can easily integrate Zeppelin with your system. You can use zeppelin client api to do most of the things in notebook ui in a programmatic way, such as create/delete note/paragraph, run note/paragraph and etc.

How to use Zeppelin Client API

The entry point of zeppelin client api is class ZeppelinClient. All the operations is via this class, e.g. in the following example, we use ZeppelinClient to run the spark tutorial note programmatically.

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");
}

Here we list some importance apis of ZeppelinClient, for the completed api, please refer its javadoc.

public String createNote(String notePath) throws Exception 

public void deleteNote(String noteId) throws Exception 

public NoteResult executeNote(String noteId) throws Exception 

public NoteResult executeNote(String noteId, 
                              Map<String, String> parameters) throws Exception
                              
public NoteResult queryNoteResult(String noteId) throws Exception 

public NoteResult submitNote(String noteId) throws Exception

public NoteResult submitNote(String noteId, 
                             Map<String, String> parameters) throws Exception 
                             
public NoteResult waitUntilNoteFinished(String noteId) throws Exception

public String addParagraph(String noteId, 
                           String title, 
                           String text) throws Exception
                           
public void updateParagraph(String noteId, 
                            String paragraphId, 
                            String title, 
                            String text) throws Exception
                            
public ParagraphResult executeParagraph(String noteId,
                                        String paragraphId,
                                        String sessionId,
                                        Map<String, String> parameters) throws Exception
                                        
public ParagraphResult submitParagraph(String noteId,
                                       String paragraphId,
                                       String sessionId,
                                       Map<String, String> parameters) throws Exception
                                       
public void cancelParagraph(String noteId, String paragraphId)
    
public ParagraphResult queryParagraphResult(String noteId, String paragraphId) 
    
public ParagraphResult waitUtilParagraphFinish(String noteId, String paragraphId)

Examples

For more detailed usage of zeppelin client api, you can check the examples in module zeppelin-client-examples