Merge remote-tracking branch 'origin/master' into ZEPPELIN-1999

# Conflicts:
#	zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java
This commit is contained in:
Tinkoff DWH 2017-02-27 10:05:28 +05:00
commit 527419a1c1
41 changed files with 264 additions and 239 deletions

View file

@ -271,7 +271,7 @@ The following components are provided under the BSD 3-Clause license. See file
========================================================================
BSD 2-Clause licenses
========================================================================
The following components are provided under the BSD 3-Clause license. See file headers and project links for details.
The following components are provided under the BSD 2-Clause license. See file headers and project links for details.
(BSD 2 Clause) portions of SQLLine (http://sqlline.sourceforge.net/) - http://sqlline.sourceforge.net/#license
jdbc/src/main/java/org/apache/zeppelin/jdbc/SqlCompleter.java

View file

@ -33,13 +33,6 @@ import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
* Dummy interpreter to support development mode for Zeppelin app
*/
public class DevInterpreter extends Interpreter {
static {
Interpreter.register(
"dev",
"dev",
DevInterpreter.class.getName(),
new InterpreterPropertyBuilder().build());
}
private InterpreterEvent interpreterEvent;
private InterpreterContext context;

View file

@ -1,17 +1,3 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.zeppelin.jdbc;
/*

View file

@ -899,6 +899,9 @@
<exclude>**/constants.json</exclude>
<exclude>scripts/**</exclude>
<!-- from SQLLine 1.0.2, see ZEPPELIN-2135 -->
<exclude>**/src/main/java/org/apache/zeppelin/jdbc/SqlCompleter.java</exclude>
<!-- bundled from bootstrap -->
<exclude>docs/assets/themes/zeppelin/bootstrap/**</exclude>
<exclude>docs/assets/themes/zeppelin/css/style.css</exclude>

View file

@ -432,25 +432,12 @@ public abstract class Interpreter {
public static Map<String, RegisteredInterpreter> registeredInterpreters = Collections
.synchronizedMap(new HashMap<String, RegisteredInterpreter>());
public static void register(String name, String className) {
register(name, name, className);
}
public static void register(String name, String group, String className) {
register(name, group, className, false, new HashMap<String, InterpreterProperty>());
}
@Deprecated
public static void register(String name, String group, String className,
Map<String, InterpreterProperty> properties) {
register(name, group, className, false, properties);
}
public static void register(String name, String group, String className,
boolean defaultInterpreter) {
register(name, group, className, defaultInterpreter,
new HashMap<String, InterpreterProperty>());
}
@Deprecated
public static void register(String name, String group, String className,
boolean defaultInterpreter, Map<String, InterpreterProperty> properties) {
@ -460,6 +447,7 @@ public abstract class Interpreter {
register(new RegisteredInterpreter(name, group, className, defaultInterpreter, properties));
}
@Deprecated
public static void register(RegisteredInterpreter registeredInterpreter) {
String interpreterKey = registeredInterpreter.getInterpreterKey();
if (!registeredInterpreters.containsKey(interpreterKey)) {

View file

@ -30,6 +30,7 @@ public class InterpreterTest {
@Test
public void testDefaultProperty() {
Properties p = new Properties();
p.put("p1", "v1");
MockInterpreterA intp = new MockInterpreterA(p);
assertEquals(1, intp.getProperty().size());
@ -38,29 +39,19 @@ public class InterpreterTest {
}
@Test
public void testOverridedProperty() {
public void testOverriddenProperty() {
Properties p = new Properties();
p.put("p1", "v2");
p.put("p1", "v1");
MockInterpreterA intp = new MockInterpreterA(p);
Properties overriddenProperty = new Properties();
overriddenProperty.put("p1", "v2");
intp.setProperty(overriddenProperty);
assertEquals(1, intp.getProperty().size());
assertEquals("v2", intp.getProperty().get("p1"));
assertEquals("v2", intp.getProperty("p1"));
}
@Test
public void testAdditionalProperty() {
Properties p = new Properties();
p.put("p2", "v2");
MockInterpreterA intp = new MockInterpreterA(p);
assertEquals(2, intp.getProperty().size());
assertEquals("v1", intp.getProperty().get("p1"));
assertEquals("v1", intp.getProperty("p1"));
assertEquals("v2", intp.getProperty().get("p2"));
assertEquals("v2", intp.getProperty("p2"));
}
@Test
public void testPropertyWithReplacedContextFields() {
String noteId = "testNoteId";
@ -92,4 +83,5 @@ public class InterpreterTest {
actual
);
}
}

View file

@ -31,15 +31,6 @@ import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.scheduler.SchedulerFactory;
public class MockInterpreterA extends Interpreter {
static {
Interpreter.register(
"interpreterA",
"group1",
MockInterpreterA.class.getName(),
new InterpreterPropertyBuilder()
.add("p1", "v1", "property1").build());
}
private String lastSt;

View file

@ -31,15 +31,6 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
public class MockInterpreterAngular extends Interpreter {
static {
Interpreter.register(
"angularTest",
"angular",
MockInterpreterA.class.getName(),
new InterpreterPropertyBuilder()
.add("p1", "v1", "property1").build());
}
AtomicInteger numWatch = new AtomicInteger(0);

View file

@ -32,15 +32,7 @@ import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.scheduler.Scheduler;
public class MockInterpreterB extends Interpreter {
static {
Interpreter.register(
"interpreterB",
"group1",
MockInterpreterA.class.getName(),
new InterpreterPropertyBuilder()
.add("p1", "v1", "property1").build());
}
public MockInterpreterB(Properties property) {
super(property);
}

View file

@ -26,15 +26,6 @@ import java.util.Properties;
public class MockInterpreterEnv extends Interpreter {
static {
Interpreter.register(
"interpreterA",
"group1",
MockInterpreterA.class.getName(),
new InterpreterPropertyBuilder().build());
}
public MockInterpreterEnv(Properties property) {
super(property);

View file

@ -29,15 +29,6 @@ import java.util.Properties;
* MockInterpreter to test outputstream
*/
public class MockInterpreterOutputStream extends Interpreter {
static {
Interpreter.register(
"interpreterOutputStream",
"group1",
MockInterpreterA.class.getName(),
new InterpreterPropertyBuilder().build());
}
private String lastSt;
public MockInterpreterOutputStream(Properties property) {

View file

@ -34,15 +34,6 @@ import org.apache.zeppelin.resource.Resource;
import org.apache.zeppelin.resource.ResourcePool;
public class MockInterpreterResourcePool extends Interpreter {
static {
Interpreter.register(
"resourcePoolTest",
"resourcePool",
MockInterpreterA.class.getName(),
new InterpreterPropertyBuilder()
.add("p1", "v1", "property1").build());
}
AtomicInteger numWatch = new AtomicInteger(0);

View file

@ -84,7 +84,7 @@ public abstract class AbstractTestRestApi {
"role1 = *\n" +
"role2 = *\n" +
"role3 = *\n" +
"admin = *" +
"admin = *\n" +
"[urls]\n" +
"/api/version = anon\n" +
"/** = authc";

View file

@ -14,6 +14,7 @@
},
"globals": {
"angular": false,
"inject": false,
"_": false,
"jQuery": false,
"hljs": false,

View file

@ -1,9 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-08-29 using
// generator-karma 0.8.3
var webpackConfig = require('../webpack.config');
var webpackConfig = require('./webpack.config');
module.exports = function(config) {
'use strict';
@ -13,7 +30,7 @@ module.exports = function(config) {
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
basePath: './',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
@ -75,7 +92,7 @@ module.exports = function(config) {
'src/index.js',
// 'test/spec/**/*.js',
{pattern: 'test/spec/**/*.js', watched: false},
{pattern: 'src/**/*.test.js', watched: false},
],
// list of files / patterns to exclude
@ -108,12 +125,12 @@ module.exports = function(config) {
preprocessors: {
'src/*/{*.js,!(test)/**/*.js}': 'coverage',
'src/index.js': ['webpack', 'sourcemap',],
'test/spec/**/*.js': ['webpack', 'sourcemap',],
'src/**/*.test.js': ['webpack', 'sourcemap',],
},
coverageReporter: {
type: 'html',
dir: '../reports/zeppelin-web-coverage',
dir: './reports/zeppelin-web-coverage',
subdir: '.'
},

View file

@ -17,7 +17,7 @@
"dev": "npm-run-all --parallel dev:server dev:watch",
"visdev": "npm-run-all --parallel visdev:server dev:watch",
"pretest": "npm install karma-phantomjs-launcher",
"test": "karma start test/karma.conf.js"
"test": "karma start karma.conf.js"
},
"dependencies": {
"grunt-angular-templates": "^0.5.7",

View file

@ -80,7 +80,8 @@
<exclude>node/**</exclude>
<exclude>node_modules/**</exclude>
<exclude>bower_components/**</exclude>
<exclude>test/**</exclude>
<exclude>src/**/*.test.js</exclude>
<exclude>reports/**</exclude>
<exclude>dist/**</exclude>
<exclude>src/.buildignore</exclude>
<exclude>src/fonts/fontawesome*</exclude>

View file

@ -509,10 +509,8 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
$scope.changeColWidth = function(paragraph, width) {
angular.element('.navbar-right.open').removeClass('open');
if (width !== paragraph.config.colWidth) {
paragraph.config.colWidth = width;
commitParagraph(paragraph);
}
paragraph.config.colWidth = width;
commitParagraph(paragraph);
};
$scope.toggleOutput = function(paragraph) {
@ -1130,23 +1128,23 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
$scope.paragraph.config = newPara.config;
}
};
$scope.updateParagraph = function(oldPara, newPara, updateCallback) {
// 1. get status, refreshed
const statusChanged = (newPara.status !== oldPara.status);
const resultRefreshed = (newPara.dateFinished !== oldPara.dateFinished) ||
isEmpty(newPara.results) !== isEmpty(oldPara.results) ||
newPara.status === 'ERROR' || (newPara.status === 'FINISHED' && statusChanged);
// 2. update texts managed by $scope
$scope.updateAllScopeTexts(oldPara, newPara);
// 3. execute callback to update result
updateCallback();
// 4. update remaining paragraph objects
$scope.updateParagraphObjectWhenUpdated(newPara);
// 5. handle scroll down by key properly if new paragraph is added
if (statusChanged || resultRefreshed) {
// when last paragraph runs, zeppelin automatically appends new paragraph.

View file

@ -12,7 +12,7 @@
* limitations under the License.
*/
import TableData from '../../../src/app/tabledata/tabledata.js';
import TableData from './tabledata.js';
describe('TableData build', function() {
var td;

View file

@ -100,7 +100,7 @@ export default class LinechartVisualization extends Nvd3ChartVisualization {
<input type="checkbox"
ng-model="config.lineWithFocus"
ng-click="save()" />
show line chart with focus
zoom
</label>
</div>`,
scope: {

View file

@ -1,37 +0,0 @@
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"globals": {
"after": false,
"afterEach": false,
"angular": false,
"before": false,
"beforeEach": false,
"browser": false,
"describe": false,
"expect": false,
"inject": false,
"it": false,
"jasmine": false,
"spyOn": false,
"zeppelin" : false
}
}

View file

@ -48,6 +48,8 @@ public class Helium {
private final HeliumBundleFactory bundleFactory;
private final HeliumApplicationFactory applicationFactory;
Map<String, List<HeliumPackageSearchResult>> allPackages;
public Helium(
String heliumConfPath,
String registryPaths,
@ -142,7 +144,7 @@ public class Helium {
}
private void clearNotExistsPackages() {
Map<String, List<HeliumPackageSearchResult>> all = getAllPackageInfo();
Map<String, List<HeliumPackageSearchResult>> all = getAllPackageInfo(false);
// clear visualization display order
List<String> packageOrder = heliumConf.getBundleDisplayOrder();
@ -164,43 +166,64 @@ public class Helium {
}
public Map<String, List<HeliumPackageSearchResult>> getAllPackageInfo() {
return getAllPackageInfo(true);
}
public Map<String, List<HeliumPackageSearchResult>> getAllPackageInfo(boolean refresh) {
Map<String, String> enabledPackageInfo = heliumConf.getEnabledPackages();
Map<String, List<HeliumPackageSearchResult>> map = new HashMap<>();
synchronized (registry) {
for (HeliumRegistry r : registry) {
try {
for (HeliumPackage pkg : r.getAll()) {
String name = pkg.getName();
String artifact = enabledPackageInfo.get(name);
boolean enabled = (artifact != null && artifact.equals(pkg.getArtifact()));
if (refresh || allPackages == null) {
allPackages = new HashMap<>();
for (HeliumRegistry r : registry) {
try {
for (HeliumPackage pkg : r.getAll()) {
String name = pkg.getName();
String artifact = enabledPackageInfo.get(name);
boolean enabled = (artifact != null && artifact.equals(pkg.getArtifact()));
if (!map.containsKey(name)) {
map.put(name, new LinkedList<HeliumPackageSearchResult>());
if (!allPackages.containsKey(name)) {
allPackages.put(name, new LinkedList<HeliumPackageSearchResult>());
}
allPackages.get(name).add(new HeliumPackageSearchResult(r.name(), pkg, enabled));
}
map.get(name).add(new HeliumPackageSearchResult(r.name(), pkg, enabled));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
} else {
for (String name : allPackages.keySet()) {
List<HeliumPackageSearchResult> pkgs = allPackages.get(name);
String artifact = enabledPackageInfo.get(name);
LinkedList<HeliumPackageSearchResult> newResults =
new LinkedList<HeliumPackageSearchResult>();
for (HeliumPackageSearchResult pkg : pkgs) {
boolean enabled = (artifact != null && artifact.equals(pkg.getPkg().getArtifact()));
newResults.add(new HeliumPackageSearchResult(pkg.getRegistry(), pkg.getPkg(), enabled));
}
allPackages.put(name, newResults);
}
}
}
// sort version (artifact)
for (String name : map.keySet()) {
List<HeliumPackageSearchResult> packages = map.get(name);
Collections.sort(packages, new Comparator<HeliumPackageSearchResult>() {
@Override
public int compare(HeliumPackageSearchResult o1, HeliumPackageSearchResult o2) {
return o2.getPkg().getArtifact().compareTo(o1.getPkg().getArtifact());
}
});
// sort version (artifact)
for (String name : allPackages.keySet()) {
List<HeliumPackageSearchResult> packages = allPackages.get(name);
Collections.sort(packages, new Comparator<HeliumPackageSearchResult>() {
@Override
public int compare(HeliumPackageSearchResult o1, HeliumPackageSearchResult o2) {
return o2.getPkg().getArtifact().compareTo(o1.getPkg().getArtifact());
}
});
}
return allPackages;
}
return map;
}
public HeliumPackageSearchResult getPackageInfo(String name, String artifact) {
Map<String, List<HeliumPackageSearchResult>> infos = getAllPackageInfo();
Map<String, List<HeliumPackageSearchResult>> infos = getAllPackageInfo(false);
List<HeliumPackageSearchResult> packages = infos.get(name);
if (artifact == null) {
return packages.get(0);
@ -276,7 +299,7 @@ public class Helium {
allResources = ResourcePoolUtils.getAllResources();
}
for (List<HeliumPackageSearchResult> pkgs : getAllPackageInfo().values()) {
for (List<HeliumPackageSearchResult> pkgs : getAllPackageInfo(false).values()) {
for (HeliumPackageSearchResult pkg : pkgs) {
if (pkg.getPkg().getType() == HeliumType.APPLICATION && pkg.isEnabled()) {
ResourceSet resources = ApplicationLoader.findRequiredResourceSet(
@ -304,7 +327,7 @@ public class Helium {
* @return ordered list of enabled buildBundle package
*/
public List<HeliumPackage> getBundlePackagesToBundle() {
Map<String, List<HeliumPackageSearchResult>> allPackages = getAllPackageInfo();
Map<String, List<HeliumPackageSearchResult>> allPackages = getAllPackageInfo(false);
List<String> visOrder = heliumConf.getBundleDisplayOrder();
List<HeliumPackage> orderedBundlePackages = new LinkedList<>();

View file

@ -31,7 +31,7 @@ public class InterpreterInfo {
private boolean defaultInterpreter = false;
private Map<String, Object> editor;
InterpreterInfo(String className, String name, boolean defaultInterpreter,
public InterpreterInfo(String className, String name, boolean defaultInterpreter,
Map<String, Object> editor) {
this.className = className;
this.name = name;

View file

@ -351,6 +351,7 @@ public class Note implements Serializable, ParagraphJobListener {
synchronized (paragraphs) {
paragraphs.add(index, p);
}
p.addUser(p, p.getUser());
if (noteEventListener != null) {
noteEventListener.onParagraphCreate(p);
}

View file

@ -142,12 +142,14 @@ public class Paragraph extends Job implements Serializable, Cloneable {
p.setResult(getReturn());
p.setStatus(getStatus());
p.setId(getId());
userParagraphMap.put(user, p);
addUser(p, user);
return p;
}
public void addUser(Paragraph p, String user) {
userParagraphMap.put(user, p);
}
public String getUser() {
return user;
}

View file

@ -16,8 +16,10 @@
*/
package org.apache.zeppelin.helium;
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.dep.Dependency;
import org.apache.zeppelin.dep.DependencyResolver;
import org.apache.zeppelin.interpreter.*;
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
@ -35,9 +37,11 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
@ -73,16 +77,11 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), home.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), tmpDir.getAbsolutePath() + "/conf");
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), "org.apache.zeppelin.interpreter.mock.MockInterpreter1,org.apache.zeppelin.interpreter.mock.MockInterpreter2");
conf = new ZeppelinConfiguration();
this.schedulerFactory = new SchedulerFactory();
MockInterpreter1.register("mock1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1");
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
heliumAppFactory = new HeliumApplicationFactory();
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
@ -91,6 +90,18 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
env.put("ZEPPELIN_CLASSPATH", new File("./target/test-classes").getAbsolutePath());
factory.setEnv(env);
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
ArrayList<InterpreterInfo> interpreterInfos2 = new ArrayList<>();
interpreterInfos2.add(new InterpreterInfo(MockInterpreter2.class.getName(), "mock2", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock2", interpreterInfos2, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock2", null);
interpreterSettingManager.createNewSetting("mock2", "mock2", new ArrayList<Dependency>(), new InterpreterOption(), new Properties());
SearchService search = mock(SearchService.class);
notebookRepo = new VFSNotebookRepo(conf);
NotebookAuthorization notebookAuthorization = NotebookAuthorization.init(conf);

View file

@ -100,4 +100,43 @@ public class HeliumTest {
// then
assertEquals(2, helium.getAllPackageInfo().size());
}
@Test
public void testRefresh() throws IOException, URISyntaxException, TaskRunnerException {
File heliumConf = new File(tmpDir, "helium.conf");
Helium helium = new Helium(
heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null, null);
HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1");
helium.addRegistry(registry1);
// when
registry1.add(new HeliumPackage(
HeliumType.APPLICATION,
"name1",
"desc1",
"artifact1",
"className1",
new String[][]{},
"",
""));
// then
assertEquals(1, helium.getAllPackageInfo(false).size());
// when
registry1.add(new HeliumPackage(
HeliumType.APPLICATION,
"name2",
"desc2",
"artifact2",
"className2",
new String[][]{},
"",
""));
// then
assertEquals(1, helium.getAllPackageInfo(false).size());
assertEquals(2, helium.getAllPackageInfo(true).size());
}
}

View file

@ -30,6 +30,7 @@ import java.util.Map;
import java.util.HashMap;
import java.util.Properties;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.NullArgumentException;
@ -87,17 +88,7 @@ public class InterpreterFactoryTest {
new File(tmpDir, "conf").mkdirs();
FileUtils.copyDirectory(new File("src/test/resources/interpreter"), new File(tmpDir, "interpreter"));
Map<String, InterpreterProperty> propertiesMockInterpreter1 = new HashMap<>();
propertiesMockInterpreter1.put("PROPERTY_1", new InterpreterProperty("PROPERTY_1", "", "VALUE_1", "desc"));
propertiesMockInterpreter1.put("property_2", new InterpreterProperty("", "property_2", "value_2", "desc"));
MockInterpreter1.register("mock1", "mock1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1", propertiesMockInterpreter1);
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), tmpDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_INTERPRETERS.getVarName(),
"org.apache.zeppelin.interpreter.mock.MockInterpreter1," +
"org.apache.zeppelin.interpreter.mock.MockInterpreter2," +
"org.apache.zeppelin.interpreter.mock.MockInterpreter11");
System.setProperty(ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER.getVarName(),
"mock1,mock2,mock11,dev");
conf = new ZeppelinConfiguration();
@ -107,6 +98,21 @@ public class InterpreterFactoryTest {
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
context = new InterpreterContext("note", "id", null, "title", "text", null, null, null, null, null, null, null);
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
Properties intp1Properties = new Properties();
intp1Properties.put("PROPERTY_1", "VALUE_1");
intp1Properties.put("property_2", "value_2");
interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), intp1Properties);
ArrayList<InterpreterInfo> interpreterInfos2 = new ArrayList<>();
interpreterInfos2.add(new InterpreterInfo(MockInterpreter2.class.getName(), "mock2", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock2", interpreterInfos2, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock2", null);
interpreterSettingManager.createNewSetting("mock2", "mock2", new ArrayList<Dependency>(), new InterpreterOption(), new Properties());
SearchService search = mock(SearchService.class);
notebookRepo = new VFSNotebookRepo(conf);
notebookAuthorization = NotebookAuthorization.init(conf);
@ -149,6 +155,14 @@ public class InterpreterFactoryTest {
@Test
public void testRemoteRepl() throws Exception {
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
Properties intp1Properties = new Properties();
intp1Properties.put("PROPERTY_1", "VALUE_1");
intp1Properties.put("property_2", "value_2");
interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), intp1Properties);
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
List<InterpreterSetting> all = interpreterSettingManager.get();
InterpreterSetting mock1Setting = null;
@ -178,6 +192,14 @@ public class InterpreterFactoryTest {
@Test
public void testRestartInterpreterInScopedMode() throws Exception {
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
Properties intp1Properties = new Properties();
intp1Properties.put("PROPERTY_1", "VALUE_1");
intp1Properties.put("property_2", "value_2");
interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), intp1Properties);
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
List<InterpreterSetting> all = interpreterSettingManager.get();
InterpreterSetting mock1Setting = null;
@ -215,6 +237,14 @@ public class InterpreterFactoryTest {
@Test
public void testRestartInterpreterInIsolatedMode() throws Exception {
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
Properties intp1Properties = new Properties();
intp1Properties.put("PROPERTY_1", "VALUE_1");
intp1Properties.put("property_2", "value_2");
interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), intp1Properties);
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
List<InterpreterSetting> all = interpreterSettingManager.get();
InterpreterSetting mock1Setting = null;
@ -282,7 +312,13 @@ public class InterpreterFactoryTest {
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
assertEquals(numInterpreters + 1, interpreterSettingManager.get().size());
/*
Current situation, if InterpreterSettinfRef doesn't have the key of InterpreterSetting, it would be ignored.
Thus even though interpreter.json have several interpreterSetting in that file, it would be ignored and would not be initialized from loadFromFile.
In this case, only "mock11" would be referenced from file under interpreter/mock, and "mock11" group would be initialized.
*/
// TODO(jl): Decide how to handle the know referenced interpreterSetting.
assertEquals(1, interpreterSettingManager.get().size());
}
@Test

View file

@ -18,29 +18,30 @@ package org.apache.zeppelin.notebook;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Properties;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.dep.Dependency;
import org.apache.zeppelin.dep.DependencyResolver;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterInfo;
import org.apache.zeppelin.interpreter.InterpreterOption;
import org.apache.zeppelin.interpreter.InterpreterProperty;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.InterpreterSettingManager;
import org.apache.zeppelin.interpreter.LazyOpenInterpreter;
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
import org.apache.zeppelin.interpreter.mock.MockInterpreter11;
import org.apache.zeppelin.interpreter.mock.MockInterpreter2;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static java.lang.Thread.sleep;
import static org.junit.Assert.*;
public class NoteInterpreterLoaderTest {
@ -61,15 +62,23 @@ public class NoteInterpreterLoaderTest {
conf = ZeppelinConfiguration.create();
Interpreter.registeredInterpreters = Collections
.synchronizedMap(new HashMap<String, Interpreter.RegisteredInterpreter>());
MockInterpreter1.register("mock1", "group1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1", true);
MockInterpreter11.register("mock11", "group1", "org.apache.zeppelin.interpreter.mock.MockInterpreter11");
MockInterpreter2.register("mock2", "group2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, Maps.<String, Object>newHashMap()));
interpreterInfos.add(new InterpreterInfo(MockInterpreter11.class.getName(), "mock11", false, Maps.<String, Object>newHashMap()));
ArrayList<InterpreterInfo> interpreterInfos2 = new ArrayList<>();
interpreterInfos2.add(new InterpreterInfo(MockInterpreter2.class.getName(), "mock2", true, Maps.<String, Object>newHashMap()));
interpreterSettingManager.add("group1", interpreterInfos, Lists.<Dependency>newArrayList(), new InterpreterOption(), Maps.<String, InterpreterProperty>newHashMap(), "mock", null);
interpreterSettingManager.add("group2", interpreterInfos2, Lists.<Dependency>newArrayList(), new InterpreterOption(), Maps.<String, InterpreterProperty>newHashMap(), "mock", null);
interpreterSettingManager.createNewSetting("group1", "group1", Lists.<Dependency>newArrayList(), new InterpreterOption(), new Properties());
interpreterSettingManager.createNewSetting("group2", "group2", Lists.<Dependency>newArrayList(), new InterpreterOption(), new Properties());
}
@After

View file

@ -130,6 +130,13 @@ public class NoteTest {
assertNull(p2.getText());
}
@Test
public void insertParagraphwithUser() {
Note note = new Note(repo, interpreterFactory, interpreterSettingManager, jobListenerFactory, index, credentials, noteEventListener);
Paragraph p = note.insertParagraph(note.getParagraphs().size(), AuthenticationInfo.ANONYMOUS);
assertEquals("anonymous", p.getUser());
}
@Test
public void clearAllParagraphOutputTest() {
when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("md"))).thenReturn(interpreter);

View file

@ -20,6 +20,7 @@ package org.apache.zeppelin.notebook;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import com.google.common.collect.Maps;
import java.io.File;
import java.io.IOException;
import java.util.*;
@ -31,6 +32,7 @@ import com.google.common.collect.Sets;
import org.apache.commons.io.FileUtils;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.dep.Dependency;
import org.apache.zeppelin.dep.DependencyResolver;
import org.apache.zeppelin.display.AngularObjectRegistry;
import org.apache.zeppelin.interpreter.*;
@ -83,19 +85,28 @@ public class NotebookTest implements JobListenerFactory{
System.setProperty(ConfVars.ZEPPELIN_CONF_DIR.getVarName(), tmpDir.toString() + "/conf");
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), tmpDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), "org.apache.zeppelin.interpreter.mock.MockInterpreter1,org.apache.zeppelin.interpreter.mock.MockInterpreter2");
conf = ZeppelinConfiguration.create();
this.schedulerFactory = new SchedulerFactory();
MockInterpreter1.register("mock1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1");
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(false));
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(), new Properties());
ArrayList<InterpreterInfo> interpreterInfos2 = new ArrayList<>();
interpreterInfos2.add(new InterpreterInfo(MockInterpreter2.class.getName(), "mock2", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock2", interpreterInfos2, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock2", null);
interpreterSettingManager.createNewSetting("mock2", "mock2", new ArrayList<Dependency>(), new InterpreterOption(), new Properties());
SearchService search = mock(SearchService.class);
notebookRepo = new VFSNotebookRepo(conf);
notebookAuthorization = NotebookAuthorization.init(conf);

View file

@ -78,12 +78,8 @@ public class GitNotebookRepoTest {
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), "org.apache.zeppelin.interpreter.mock.MockInterpreter1,org.apache.zeppelin.interpreter.mock.MockInterpreter2");
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.GitNotebookRepo");
MockInterpreter1.register("mock1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1");
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
conf = ZeppelinConfiguration.create();
}

View file

@ -35,18 +35,13 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.dep.DependencyResolver;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterOption;
import org.apache.zeppelin.interpreter.InterpreterOutput;
import org.apache.zeppelin.interpreter.InterpreterResultMessage;
import org.apache.zeppelin.interpreter.InterpreterSettingManager;
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
import org.apache.zeppelin.interpreter.mock.MockInterpreter2;
import org.apache.zeppelin.notebook.*;
import org.apache.zeppelin.scheduler.Job;
import org.apache.zeppelin.scheduler.Job.Status;
import org.apache.zeppelin.scheduler.JobListener;
import org.apache.zeppelin.scheduler.SchedulerFactory;
import org.apache.zeppelin.search.SearchService;
import org.apache.zeppelin.search.LuceneSearch;
import org.apache.zeppelin.user.AuthenticationInfo;
import org.apache.zeppelin.user.Credentials;
import org.junit.After;
@ -90,7 +85,6 @@ public class NotebookRepoSyncTest implements JobListenerFactory {
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), mainZepDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), "org.apache.zeppelin.interpreter.mock.MockInterpreter1,org.apache.zeppelin.interpreter.mock.MockInterpreter2");
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");
LOG.info("main Note dir : " + mainNotePath);
@ -99,9 +93,6 @@ public class NotebookRepoSyncTest implements JobListenerFactory {
this.schedulerFactory = new SchedulerFactory();
MockInterpreter1.register("mock1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1");
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo");
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);

View file

@ -22,15 +22,22 @@ import static org.mockito.Mockito.mock;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.dep.Dependency;
import org.apache.zeppelin.dep.DependencyResolver;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterInfo;
import org.apache.zeppelin.interpreter.InterpreterOption;
import org.apache.zeppelin.interpreter.InterpreterProperty;
import org.apache.zeppelin.interpreter.InterpreterSettingManager;
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
import org.apache.zeppelin.notebook.JobListenerFactory;
@ -76,19 +83,22 @@ public class VFSNotebookRepoTest implements JobListenerFactory {
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), mainZepDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), "org.apache.zeppelin.interpreter.mock.MockInterpreter1");
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.VFSNotebookRepo");
conf = ZeppelinConfiguration.create();
this.schedulerFactory = new SchedulerFactory();
MockInterpreter1.register("mock1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1");
this.schedulerFactory = new SchedulerFactory();
depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo");
interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(),
Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(), new Properties());
SearchService search = mock(SearchService.class);
notebookRepo = new VFSNotebookRepo(conf);
notebookAuthorization = NotebookAuthorization.init(conf);