use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.
the class ConfigurationsRestApi method getByPrefix.
@GET
@Path("prefix/{prefix}")
@ZeppelinApi
public Response getByPrefix(@PathParam("prefix") final String prefix) {
ZeppelinConfiguration conf = notebook.getConf();
Map<String, String> configurations = conf.dumpConfigurations(conf, new ZeppelinConfiguration.ConfigurationKeyPredicate() {
@Override
public boolean apply(String key) {
return !key.contains("password") && !key.equals(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING.getVarName()) && key.startsWith(prefix);
}
});
return new JsonResponse(Status.OK, "", configurations).build();
}
use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.
the class NotebookServer method onMessage.
@Override
public void onMessage(NotebookSocket conn, String msg) {
Notebook notebook = notebook();
try {
Message messagereceived = deserializeMessage(msg);
LOG.debug("RECEIVE << " + messagereceived.op);
LOG.debug("RECEIVE PRINCIPAL << " + messagereceived.principal);
LOG.debug("RECEIVE TICKET << " + messagereceived.ticket);
LOG.debug("RECEIVE ROLES << " + messagereceived.roles);
if (LOG.isTraceEnabled()) {
LOG.trace("RECEIVE MSG = " + messagereceived);
}
String ticket = TicketContainer.instance.getTicket(messagereceived.principal);
if (ticket != null && (messagereceived.ticket == null || !ticket.equals(messagereceived.ticket))) {
/* not to pollute logs, log instead of exception */
if (StringUtils.isEmpty(messagereceived.ticket)) {
LOG.debug("{} message: invalid ticket {} != {}", messagereceived.op, messagereceived.ticket, ticket);
} else {
if (!messagereceived.op.equals(OP.PING)) {
conn.send(serializeMessage(new Message(OP.SESSION_LOGOUT).put("info", "Your ticket is invalid possibly due to server restart. " + "Please login again.")));
}
}
return;
}
ZeppelinConfiguration conf = ZeppelinConfiguration.create();
boolean allowAnonymous = conf.isAnonymousAllowed();
if (!allowAnonymous && messagereceived.principal.equals("anonymous")) {
throw new Exception("Anonymous access not allowed ");
}
HashSet<String> userAndRoles = new HashSet<>();
userAndRoles.add(messagereceived.principal);
if (!messagereceived.roles.equals("")) {
HashSet<String> roles = gson.fromJson(messagereceived.roles, new TypeToken<HashSet<String>>() {
}.getType());
if (roles != null) {
userAndRoles.addAll(roles);
}
}
if (StringUtils.isEmpty(conn.getUser())) {
addUserConnection(messagereceived.principal, conn);
}
AuthenticationInfo subject = new AuthenticationInfo(messagereceived.principal, messagereceived.ticket);
/** Lets be elegant here */
switch(messagereceived.op) {
case LIST_NOTES:
unicastNoteList(conn, subject, userAndRoles);
break;
case RELOAD_NOTES_FROM_REPO:
broadcastReloadedNoteList(subject, userAndRoles);
break;
case GET_HOME_NOTE:
sendHomeNote(conn, userAndRoles, notebook, messagereceived);
break;
case GET_NOTE:
sendNote(conn, userAndRoles, notebook, messagereceived);
break;
case NEW_NOTE:
createNote(conn, userAndRoles, notebook, messagereceived);
break;
case DEL_NOTE:
removeNote(conn, userAndRoles, notebook, messagereceived);
break;
case REMOVE_FOLDER:
removeFolder(conn, userAndRoles, notebook, messagereceived);
break;
case MOVE_NOTE_TO_TRASH:
moveNoteToTrash(conn, userAndRoles, notebook, messagereceived);
break;
case MOVE_FOLDER_TO_TRASH:
moveFolderToTrash(conn, userAndRoles, notebook, messagereceived);
break;
case EMPTY_TRASH:
emptyTrash(conn, userAndRoles, notebook, messagereceived);
break;
case RESTORE_FOLDER:
restoreFolder(conn, userAndRoles, notebook, messagereceived);
break;
case RESTORE_NOTE:
restoreNote(conn, userAndRoles, notebook, messagereceived);
break;
case RESTORE_ALL:
restoreAll(conn, userAndRoles, notebook, messagereceived);
break;
case CLONE_NOTE:
cloneNote(conn, userAndRoles, notebook, messagereceived);
break;
case IMPORT_NOTE:
importNote(conn, userAndRoles, notebook, messagereceived);
break;
case COMMIT_PARAGRAPH:
updateParagraph(conn, userAndRoles, notebook, messagereceived);
break;
case RUN_PARAGRAPH:
runParagraph(conn, userAndRoles, notebook, messagereceived);
break;
case PARAGRAPH_EXECUTED_BY_SPELL:
broadcastSpellExecution(conn, userAndRoles, notebook, messagereceived);
break;
case RUN_ALL_PARAGRAPHS:
runAllParagraphs(conn, userAndRoles, notebook, messagereceived);
break;
case CANCEL_PARAGRAPH:
cancelParagraph(conn, userAndRoles, notebook, messagereceived);
break;
case MOVE_PARAGRAPH:
moveParagraph(conn, userAndRoles, notebook, messagereceived);
break;
case INSERT_PARAGRAPH:
insertParagraph(conn, userAndRoles, notebook, messagereceived);
break;
case COPY_PARAGRAPH:
copyParagraph(conn, userAndRoles, notebook, messagereceived);
break;
case PARAGRAPH_REMOVE:
removeParagraph(conn, userAndRoles, notebook, messagereceived);
break;
case PARAGRAPH_CLEAR_OUTPUT:
clearParagraphOutput(conn, userAndRoles, notebook, messagereceived);
break;
case PARAGRAPH_CLEAR_ALL_OUTPUT:
clearAllParagraphOutput(conn, userAndRoles, notebook, messagereceived);
break;
case NOTE_UPDATE:
updateNote(conn, userAndRoles, notebook, messagereceived);
break;
case NOTE_RENAME:
renameNote(conn, userAndRoles, notebook, messagereceived);
break;
case FOLDER_RENAME:
renameFolder(conn, userAndRoles, notebook, messagereceived);
break;
case UPDATE_PERSONALIZED_MODE:
updatePersonalizedMode(conn, userAndRoles, notebook, messagereceived);
break;
case COMPLETION:
completion(conn, userAndRoles, notebook, messagereceived);
break;
case PING:
//do nothing
break;
case ANGULAR_OBJECT_UPDATED:
angularObjectUpdated(conn, userAndRoles, notebook, messagereceived);
break;
case ANGULAR_OBJECT_CLIENT_BIND:
angularObjectClientBind(conn, userAndRoles, notebook, messagereceived);
break;
case ANGULAR_OBJECT_CLIENT_UNBIND:
angularObjectClientUnbind(conn, userAndRoles, notebook, messagereceived);
break;
case LIST_CONFIGURATIONS:
sendAllConfigurations(conn, userAndRoles, notebook);
break;
case CHECKPOINT_NOTE:
checkpointNote(conn, notebook, messagereceived);
break;
case LIST_REVISION_HISTORY:
listRevisionHistory(conn, notebook, messagereceived);
break;
case SET_NOTE_REVISION:
setNoteRevision(conn, userAndRoles, notebook, messagereceived);
break;
case NOTE_REVISION:
getNoteByRevision(conn, notebook, messagereceived);
break;
case LIST_NOTE_JOBS:
unicastNoteJobInfo(conn, messagereceived);
break;
case UNSUBSCRIBE_UPDATE_NOTE_JOBS:
unsubscribeNoteJobInfo(conn);
break;
case GET_INTERPRETER_BINDINGS:
getInterpreterBindings(conn, messagereceived);
break;
case SAVE_INTERPRETER_BINDINGS:
saveInterpreterBindings(conn, messagereceived);
break;
case EDITOR_SETTING:
getEditorSetting(conn, messagereceived);
break;
case GET_INTERPRETER_SETTINGS:
getInterpreterSettings(conn, subject);
break;
case WATCHER:
switchConnectionToWatcher(conn, messagereceived);
break;
default:
break;
}
} catch (Exception e) {
LOG.error("Can't handle message", e);
}
}
use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.
the class AbstractTestRestApi method start.
private static void start(boolean withAuth) throws Exception {
if (!wasRunning) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), "../");
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_WAR.getVarName(), "../zeppelin-web/dist");
// some test profile does not build zeppelin-web.
// to prevent zeppelin starting up fail, create zeppelin-web/dist directory
new File("../zeppelin-web/dist").mkdirs();
LOG.info("Staring test Zeppelin up...");
ZeppelinConfiguration conf = ZeppelinConfiguration.create();
if (withAuth) {
isRunningWithAuth = true;
// Set Anonymous session to false.
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ANONYMOUS_ALLOWED.getVarName(), "false");
// Create a shiro env test.
shiroIni = new File("../conf/shiro.ini");
if (!shiroIni.exists()) {
shiroIni.createNewFile();
}
FileUtils.writeStringToFile(shiroIni, zeppelinShiro);
}
// exclude org.apache.zeppelin.rinterpreter.* for scala 2.11 test
String interpreters = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETERS);
String interpretersCompatibleWithScala211Test = null;
for (String intp : interpreters.split(",")) {
if (intp.startsWith("org.apache.zeppelin.rinterpreter")) {
continue;
}
if (interpretersCompatibleWithScala211Test == null) {
interpretersCompatibleWithScala211Test = intp;
} else {
interpretersCompatibleWithScala211Test += "," + intp;
}
}
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), interpretersCompatibleWithScala211Test);
executor = Executors.newSingleThreadExecutor();
executor.submit(server);
long s = System.currentTimeMillis();
boolean started = false;
while (System.currentTimeMillis() - s < 1000 * 60 * 3) {
// 3 minutes
Thread.sleep(2000);
started = checkIfServerIsRunning();
if (started == true) {
break;
}
}
if (started == false) {
throw new RuntimeException("Can not start Zeppelin server");
}
LOG.info("Test Zeppelin stared.");
// assume first one is spark
InterpreterSetting sparkIntpSetting = null;
for (InterpreterSetting intpSetting : ZeppelinServer.notebook.getInterpreterSettingManager().get()) {
if (intpSetting.getName().equals("spark")) {
sparkIntpSetting = intpSetting;
}
}
Properties sparkProperties = (Properties) sparkIntpSetting.getProperties();
// so configure zeppelin use spark cluster
if ("true".equals(System.getenv("CI"))) {
// set spark master and other properties
sparkProperties.setProperty("master", "local[2]");
sparkProperties.setProperty("spark.cores.max", "2");
sparkProperties.setProperty("zeppelin.spark.useHiveContext", "false");
// set spark home for pyspark
sparkProperties.setProperty("spark.home", getSparkHome());
sparkIntpSetting.setProperties(sparkProperties);
pySpark = true;
sparkR = true;
ZeppelinServer.notebook.getInterpreterSettingManager().restart(sparkIntpSetting.getId());
} else {
String sparkHome = getSparkHome();
if (sparkHome != null) {
if (System.getenv("SPARK_MASTER") != null) {
sparkProperties.setProperty("master", System.getenv("SPARK_MASTER"));
} else {
sparkProperties.setProperty("master", "local[2]");
}
sparkProperties.setProperty("spark.cores.max", "2");
// set spark home for pyspark
sparkProperties.setProperty("spark.home", sparkHome);
sparkProperties.setProperty("zeppelin.spark.useHiveContext", "false");
pySpark = true;
sparkR = true;
}
ZeppelinServer.notebook.getInterpreterSettingManager().restart(sparkIntpSetting.getId());
}
}
}
use of org.apache.zeppelin.conf.ZeppelinConfiguration in project zeppelin by apache.
the class NotebookServer method sendAllConfigurations.
private void sendAllConfigurations(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook) throws IOException {
ZeppelinConfiguration conf = notebook.getConf();
Map<String, String> configurations = conf.dumpConfigurations(conf, new ZeppelinConfiguration.ConfigurationKeyPredicate() {
@Override
public boolean apply(String key) {
return !key.contains("password") && !key.equals(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING.getVarName());
}
});
conn.send(serializeMessage(new Message(OP.CONFIGURATIONS_INFO).put("configurations", configurations)));
}
Aggregations