use of org.apache.zeppelin.user.Credentials in project zeppelin by apache.
the class ZeppelinServer method main.
public static void main(String[] args) throws InterruptedException, IOException {
ZeppelinServer.conf = ZeppelinConfiguration.create();
jettyWebServer = setupJettyServer(conf);
initMetrics(conf);
TimedHandler timedHandler = new TimedHandler(Metrics.globalRegistry, Tags.empty());
jettyWebServer.setHandler(timedHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
timedHandler.setHandler(contexts);
sharedServiceLocator = ServiceLocatorFactory.getInstance().create("shared-locator");
ServiceLocatorUtilities.enableImmediateScope(sharedServiceLocator);
ServiceLocatorUtilities.addClasses(sharedServiceLocator, NotebookRepoSync.class, ImmediateErrorHandlerImpl.class);
ImmediateErrorHandlerImpl handler = sharedServiceLocator.getService(ImmediateErrorHandlerImpl.class);
ServiceLocatorUtilities.bind(sharedServiceLocator, new AbstractBinder() {
@Override
protected void configure() {
Credentials credentials = new Credentials(conf);
bindAsContract(InterpreterFactory.class).in(Singleton.class);
bindAsContract(NotebookRepoSync.class).to(NotebookRepo.class).in(Immediate.class);
bindAsContract(Helium.class).in(Singleton.class);
bind(conf).to(ZeppelinConfiguration.class);
bindAsContract(InterpreterSettingManager.class).in(Singleton.class);
bindAsContract(InterpreterService.class).in(Singleton.class);
bind(credentials).to(Credentials.class);
bindAsContract(GsonProvider.class).in(Singleton.class);
bindAsContract(WebApplicationExceptionMapper.class).in(Singleton.class);
bindAsContract(AdminService.class).in(Singleton.class);
bindAsContract(AuthorizationService.class).in(Singleton.class);
bindAsContract(ConnectionManager.class).in(Singleton.class);
bindAsContract(NoteManager.class).in(Singleton.class);
// TODO(jl): Will make it more beautiful
if (!StringUtils.isBlank(conf.getShiroPath())) {
bind(ShiroAuthenticationService.class).to(AuthenticationService.class).in(Singleton.class);
} else {
// TODO(jl): Will be added more type
bind(NoAuthenticationService.class).to(AuthenticationService.class).in(Singleton.class);
}
bindAsContract(HeliumBundleFactory.class).in(Singleton.class);
bindAsContract(HeliumApplicationFactory.class).in(Singleton.class);
bindAsContract(ConfigurationService.class).in(Singleton.class);
bindAsContract(NotebookService.class).in(Singleton.class);
bindAsContract(JobManagerService.class).in(Singleton.class);
bindAsContract(Notebook.class).in(Singleton.class);
bindAsContract(NotebookServer.class).to(AngularObjectRegistryListener.class).to(RemoteInterpreterProcessListener.class).to(ApplicationEventListener.class).to(NoteEventListener.class).to(WebSocketServlet.class).in(Singleton.class);
if (conf.isZeppelinNotebookCronEnable()) {
bind(QuartzSchedulerService.class).to(SchedulerService.class).in(Singleton.class);
} else {
bind(NoSchedulerService.class).to(SchedulerService.class).in(Singleton.class);
}
if (conf.getBoolean(ConfVars.ZEPPELIN_SEARCH_ENABLE)) {
bind(LuceneSearch.class).to(SearchService.class).in(Singleton.class);
} else {
bind(NoSearchService.class).to(SearchService.class).in(Singleton.class);
}
}
});
// Multiple Web UI
final WebAppContext defaultWebApp = setupWebAppContext(contexts, conf, conf.getString(ConfVars.ZEPPELIN_WAR), conf.getServerContextPath());
final WebAppContext nextWebApp = setupWebAppContext(contexts, conf, conf.getString(ConfVars.ZEPPELIN_ANGULAR_WAR), WEB_APP_CONTEXT_NEXT);
initWebApp(defaultWebApp);
initWebApp(nextWebApp);
// Cluster Manager Server
setupClusterManagerServer(sharedServiceLocator);
// JMX Enable
if (conf.isJMXEnabled()) {
int port = conf.getJMXPort();
// Setup JMX
MBeanContainer mbeanContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
jettyWebServer.addBean(mbeanContainer);
JMXServiceURL jmxURL = new JMXServiceURL(String.format("service:jmx:rmi://0.0.0.0:%d/jndi/rmi://0.0.0.0:%d/jmxrmi", port, port));
ConnectorServer jmxServer = new ConnectorServer(jmxURL, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
jettyWebServer.addBean(jmxServer);
LOG.info("JMX Enabled with port: {}", port);
}
LOG.info("Starting zeppelin server");
try {
// Instantiates ZeppelinServer
jettyWebServer.start();
List<ErrorData> errorData = handler.waitForAtLeastOneConstructionError(5 * 1000);
if (errorData.size() > 0 && errorData.get(0).getThrowable() != null) {
throw new Exception(errorData.get(0).getThrowable());
}
if (conf.getJettyName() != null) {
org.eclipse.jetty.http.HttpGenerator.setJettyVersion(conf.getJettyName());
}
} catch (Exception e) {
LOG.error("Error while running jettyServer", e);
System.exit(-1);
}
LOG.info("Done, zeppelin server started");
runNoteOnStart(conf);
Runtime.getRuntime().addShutdownHook(shutdown(conf));
// Try to get Notebook from ServiceLocator, because Notebook instantiation is lazy, it is
// created when user open zeppelin in browser if we don't get it explicitly here.
// Lazy loading will cause paragraph recovery and cron job initialization is delayed.
Notebook notebook = ServiceLocatorUtilities.getService(sharedServiceLocator, Notebook.class.getName());
ServiceLocatorUtilities.getService(sharedServiceLocator, SearchService.class.getName());
ServiceLocatorUtilities.getService(sharedServiceLocator, SchedulerService.class.getName());
// Try to recover here, don't do it in constructor of Notebook, because it would cause deadlock.
notebook.recoveryIfNecessary();
// 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();
if (!conf.isRecoveryEnabled()) {
sharedServiceLocator.getService(InterpreterSettingManager.class).close();
}
}
use of org.apache.zeppelin.user.Credentials in project zeppelin by apache.
the class AbstractInterpreterTest method setUp.
@Before
public void setUp() throws Exception {
// copy the resources files to a temp folder
zeppelinHome = new File("..");
LOGGER.info("ZEPPELIN_HOME: " + zeppelinHome.getAbsolutePath());
interpreterDir = new File(zeppelinHome, "interpreter_" + getClass().getSimpleName());
confDir = new File(zeppelinHome, "conf_" + getClass().getSimpleName());
notebookDir = new File(zeppelinHome, "notebook_" + getClass().getSimpleName());
FileUtils.deleteDirectory(notebookDir);
interpreterDir.mkdirs();
confDir.mkdirs();
notebookDir.mkdirs();
FileUtils.copyDirectory(new File("src/test/resources/interpreter"), interpreterDir);
FileUtils.copyDirectory(new File("src/test/resources/conf"), confDir);
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinHome.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_DIR.getVarName(), interpreterDir.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT.getVarName(), "test");
conf = ZeppelinConfiguration.create();
NotebookRepo notebookRepo = new InMemoryNotebookRepo();
NoteManager noteManager = new NoteManager(notebookRepo, conf);
AuthorizationService authorizationService = new AuthorizationService(noteManager, conf);
interpreterSettingManager = new InterpreterSettingManager(conf, mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
interpreterFactory = new InterpreterFactory(interpreterSettingManager);
Credentials credentials = new Credentials(conf);
notebook = new Notebook(conf, authorizationService, notebookRepo, noteManager, interpreterFactory, interpreterSettingManager, credentials);
interpreterSettingManager.setNotebook(notebook);
}
use of org.apache.zeppelin.user.Credentials in project zeppelin by apache.
the class NotebookRepoSyncTest method setUp.
@Before
public void setUp() throws Exception {
System.setProperty("zeppelin.isTest", "true");
ZEPPELIN_HOME = Files.createTempDir();
new File(ZEPPELIN_HOME, "conf").mkdirs();
String mainNotePath = ZEPPELIN_HOME.getAbsolutePath() + "/notebook";
String secNotePath = ZEPPELIN_HOME.getAbsolutePath() + "/notebook_secondary";
mainNotebookDir = new File(mainNotePath);
secNotebookDir = new File(secNotePath);
mainNotebookDir.mkdirs();
secNotebookDir.mkdirs();
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), ZEPPELIN_HOME.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.VFSNotebookRepo,org.apache.zeppelin.notebook.repo.mock.VFSNotebookRepoMock");
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_ONE_WAY_SYNC.getVarName(), "false");
System.setProperty(ConfVars.ZEPPELIN_CONFIG_FS_DIR.getVarName(), ZEPPELIN_HOME.getAbsolutePath() + "/conf");
System.setProperty(ConfVars.ZEPPELIN_PLUGINS_DIR.getVarName(), new File("../../../plugins").getAbsolutePath());
LOG.info("main Note dir : " + mainNotePath);
LOG.info("secondary note dir : " + secNotePath);
conf = ZeppelinConfiguration.create();
ConfigStorage.reset();
interpreterSettingManager = new InterpreterSettingManager(conf, mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
factory = new InterpreterFactory(interpreterSettingManager);
notebookRepoSync = new NotebookRepoSync(conf);
noteManager = new NoteManager(notebookRepoSync, conf);
authorizationService = new AuthorizationService(noteManager, conf);
credentials = new Credentials(conf);
notebook = new Notebook(conf, authorizationService, notebookRepoSync, noteManager, factory, interpreterSettingManager, credentials, null);
anonymous = new AuthenticationInfo("anonymous");
}
use of org.apache.zeppelin.user.Credentials in project zeppelin by apache.
the class ParagraphTest method credentialReplacement.
// (TODO zjffdu) temporary disable it.
// https://github.com/apache/zeppelin/pull/3416
@Ignore
@Test
public void credentialReplacement() throws Throwable {
Note mockNote = mock(Note.class);
Credentials creds = mock(Credentials.class);
when(mockNote.getCredentials()).thenReturn(creds);
Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null));
UserCredentials uc = mock(UserCredentials.class);
when(creds.getUserCredentials(anyString())).thenReturn(uc);
UsernamePassword up = new UsernamePassword("user", "pwd");
when(uc.getUsernamePassword("ent")).thenReturn(up);
Interpreter mockInterpreter = mock(Interpreter.class);
spyParagraph.setInterpreter(mockInterpreter);
doReturn(mockInterpreter).when(spyParagraph).getBindedInterpreter();
ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
when(mockInterpreterGroup.getId()).thenReturn("mock_id_1");
when(mockInterpreterGroup.getAngularObjectRegistry()).thenReturn(mock(AngularObjectRegistry.class));
when(mockInterpreterGroup.getResourcePool()).thenReturn(mock(ResourcePool.class));
when(mockInterpreter.getFormType()).thenReturn(FormType.NONE);
ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
doReturn(mockJobListener).when(spyParagraph).getListener();
InterpreterResult mockInterpreterResult = mock(InterpreterResult.class);
when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
AuthenticationInfo user1 = new AuthenticationInfo("user1");
spyParagraph.setAuthenticationInfo(user1);
spyParagraph.setText("val x = \"usr={user.ent}&pass={password.ent}\"");
// Credentials should only be injected when it is enabled for an interpreter or when specified in a local property
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("false");
spyParagraph.jobRun();
verify(mockInterpreter).interpret(eq("val x = \"usr={user.ent}&pass={password.ent}\""), any(InterpreterContext.class));
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("true");
mockInterpreter.setProperty(Constants.INJECT_CREDENTIALS, "true");
spyParagraph.jobRun();
verify(mockInterpreter).interpret(eq("val x = \"usr=user&pass=pwd\""), any(InterpreterContext.class));
// Check if local property override works
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("true");
spyParagraph.getLocalProperties().put(Constants.INJECT_CREDENTIALS, "true");
spyParagraph.jobRun();
verify(mockInterpreter).interpret(eq("val x = \"usr=user&pass=pwd\""), any(InterpreterContext.class));
}
use of org.apache.zeppelin.user.Credentials in project zeppelin by apache.
the class NotebookTest method setUp.
@Override
@Before
public void setUp() throws Exception {
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_PUBLIC.getVarName(), "true");
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "true");
super.setUp();
notebookRepo = new VFSNotebookRepo();
notebookRepo.init(conf);
noteManager = new NoteManager(notebookRepo, conf);
authorizationService = new AuthorizationService(noteManager, conf);
credentials = new Credentials(conf);
notebook = new Notebook(conf, authorizationService, notebookRepo, noteManager, interpreterFactory, interpreterSettingManager, credentials, null);
notebook.setParagraphJobListener(this);
schedulerService = new QuartzSchedulerService(conf, notebook);
schedulerService.waitForFinishInit();
}
Aggregations