Search in sources :

Example 1 with ZeppelinConfiguration

use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.

the class SecurityRestApi method ticket.

/**
   * Get ticket
   * Returns username & ticket
   * for anonymous access, username is always anonymous.
   * After getting this ticket, access through websockets become safe
   *
   * @return 200 response
   */
@GET
@Path("ticket")
@ZeppelinApi
public Response ticket() {
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    String principal = SecurityUtils.getPrincipal();
    HashSet<String> roles = SecurityUtils.getRoles();
    JsonResponse response;
    // ticket set to anonymous for anonymous user. Simplify testing.
    String ticket;
    if ("anonymous".equals(principal))
        ticket = "anonymous";
    else
        ticket = TicketContainer.instance.getTicket(principal);
    Map<String, String> data = new HashMap<>();
    data.put("principal", principal);
    data.put("roles", roles.toString());
    data.put("ticket", ticket);
    response = new JsonResponse(Response.Status.OK, "", data);
    LOG.warn(response.toString());
    return response.build();
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 2 with ZeppelinConfiguration

use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.

the class ZeppelinServer method main.

public static void main(String[] args) throws InterruptedException {
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    conf.setProperty("args", args);
    jettyWebServer = setupJettyServer(conf);
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    jettyWebServer.setHandler(contexts);
    // Web UI
    final WebAppContext webApp = setupWebAppContext(contexts, conf);
    // Create `ZeppelinServer` using reflection and setup REST Api
    setupRestApiContextHandler(webApp, conf);
    // Notebook server
    setupNotebookServer(webApp, conf);
    //Below is commented since zeppelin-docs module is removed.
    //final WebAppContext webAppSwagg = setupWebAppSwagger(conf);
    LOG.info("Starting zeppelin server");
    try {
        //Instantiates ZeppelinServer
        jettyWebServer.start();
    } catch (Exception e) {
        LOG.error("Error while running jettyServer", e);
        System.exit(-1);
    }
    LOG.info("Done, zeppelin server started");
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            LOG.info("Shutting down Zeppelin Server ... ");
            try {
                jettyWebServer.stop();
                notebook.getInterpreterSettingManager().shutdown();
                notebook.close();
                Thread.sleep(3000);
            } catch (Exception e) {
                LOG.error("Error while stopping servlet container", e);
            }
            LOG.info("Bye");
        }
    });
    // for graceful shutdown, input any key in console window
    if (System.getenv("ZEPPELIN_IDENT_STRING") == null) {
        try {
            System.in.read();
        } catch (IOException e) {
            LOG.error("Exception in ZeppelinServer while main ", e);
        }
        System.exit(0);
    }
    jettyWebServer.join();
    ZeppelinServer.notebook.getInterpreterSettingManager().close();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with ZeppelinConfiguration

use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.

the class NotebookServer method generateNotesInfo.

public List<Map<String, String>> generateNotesInfo(boolean needsReload, AuthenticationInfo subject, Set<String> userAndRoles) {
    Notebook notebook = notebook();
    ZeppelinConfiguration conf = notebook.getConf();
    String homescreenNoteId = conf.getString(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN);
    boolean hideHomeScreenNotebookFromList = conf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN_HIDE);
    if (needsReload) {
        try {
            notebook.reloadAllNotes(subject);
        } catch (IOException e) {
            LOG.error("Fail to reload notes from repository", e);
        }
    }
    List<Note> notes = notebook.getAllNotes(userAndRoles);
    List<Map<String, String>> notesInfo = new LinkedList<>();
    for (Note note : notes) {
        Map<String, String> info = new HashMap<>();
        if (hideHomeScreenNotebookFromList && note.getId().equals(homescreenNoteId)) {
            continue;
        }
        info.put("id", note.getId());
        info.put("name", note.getName());
        notesInfo.add(info);
    }
    return notesInfo;
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) Note(org.apache.zeppelin.notebook.Note) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 4 with ZeppelinConfiguration

use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.

the class AuthenticationIT method startUp.

@BeforeClass
public static void startUp() {
    if (!endToEndTestEnabled()) {
        return;
    }
    try {
        System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), "../");
        ZeppelinConfiguration conf = ZeppelinConfiguration.create();
        shiroPath = conf.getRelativeDir(String.format("%s/shiro.ini", conf.getConfDir()));
        File file = new File(shiroPath);
        if (file.exists()) {
            originalShiro = StringUtils.join(FileUtils.readLines(file, "UTF-8"), "\n");
        }
        FileUtils.write(file, authShiro, "UTF-8");
    } catch (IOException e) {
        LOG.error("Error in AuthenticationIT startUp::", e);
    }
    ZeppelinITUtils.restartZeppelin();
    driver = WebDriverManager.getWebDriver();
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) IOException(java.io.IOException) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 5 with ZeppelinConfiguration

use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.

the class InstallInterpreter method main.

public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        usage();
        return;
    }
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    InstallInterpreter installer = new InstallInterpreter(new File(conf.getInterpreterListPath()), new File(conf.getInterpreterDir()), conf.getInterpreterLocalRepoPath());
    String names = null;
    String artifacts = null;
    URL proxyUrl = null;
    String proxyUser = null;
    String proxyPassword = null;
    boolean all = false;
    for (int i = 0; i < args.length; i++) {
        String arg = args[i].toLowerCase(Locale.US);
        switch(arg) {
            case "--list":
            case "-l":
                installer.list();
                System.exit(0);
                break;
            case "--all":
            case "-a":
                all = true;
                break;
            case "--name":
            case "-n":
                names = args[++i];
                break;
            case "--artifact":
            case "-t":
                artifacts = args[++i];
                break;
            case "--version":
            case "-v":
                Util.getVersion();
                break;
            case "--proxy-url":
                proxyUrl = new URL(args[++i]);
                break;
            case "--proxy-user":
                proxyUser = args[++i];
                break;
            case "--proxy-password":
                proxyPassword = args[++i];
                break;
            case "--help":
            case "-h":
                usage();
                System.exit(0);
                break;
            default:
                System.out.println("Unknown option " + arg);
        }
    }
    if (proxyUrl != null) {
        installer.setProxy(proxyUrl, proxyUser, proxyPassword);
    }
    if (all) {
        installer.installAll();
        System.exit(0);
    }
    if (names != null) {
        if (artifacts != null) {
            installer.install(names.split(","), artifacts.split(","));
        } else {
            installer.install(names.split(","));
        }
    }
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) File(java.io.File) URL(java.net.URL)

Aggregations

ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)24 Test (org.junit.Test)10 File (java.io.File)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)3 Notebook (org.apache.zeppelin.notebook.Notebook)3 JsonResponse (org.apache.zeppelin.server.JsonResponse)3 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 Dependency (org.apache.zeppelin.dep.Dependency)2 DependencyResolver (org.apache.zeppelin.dep.DependencyResolver)2 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)2 VFSNotebookRepo (org.apache.zeppelin.notebook.repo.VFSNotebookRepo)2 VFSNotebookRepoMock (org.apache.zeppelin.notebook.repo.mock.VFSNotebookRepoMock)2 Message (org.apache.zeppelin.notebook.socket.Message)2