Skip to content

Commit 355c1f2

Browse files
committed
Add UI component for the accepting Host and Port when executing option is selected
1 parent 7af8112 commit 355c1f2

File tree

10 files changed

+137
-24
lines changed

10 files changed

+137
-24
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.zeppelin.interpreter;
19+
/**
20+
* Interpreter related constants
21+
*
22+
*
23+
*/
24+
public class Constants {
25+
public static final String ZEPPELIN_INTERPRETER_PORT = "zeppelin.interpreter.port";
26+
27+
public static final String ZEPPELIN_INTERPRETER_HOST = "zeppelin.interpreter.host";
28+
29+
public static final String EXECUTING_PROCESS = "executing_process";
30+
31+
}

zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.exec.environment.EnvironmentUtils;
2323
import org.apache.commons.pool2.impl.GenericObjectPool;
2424
import org.apache.thrift.TException;
25+
import org.apache.zeppelin.interpreter.Constants;
2526
import org.apache.zeppelin.interpreter.InterpreterException;
2627
import org.apache.zeppelin.interpreter.InterpreterGroup;
2728
import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client;
@@ -38,12 +39,6 @@
3839
*/
3940
public class RemoteInterpreterProcess implements ExecuteResultHandler {
4041
private static final Logger logger = LoggerFactory.getLogger(RemoteInterpreterProcess.class);
41-
private static final String ZEPPELIN_INTERPRETER_PORT = "zeppelin.interpreter.port";
42-
43-
private static final String ZEPPELIN_INTERPRETER_HOST = "zeppelin.interpreter.host";
44-
45-
public static final String ZEPPELIN_INTERPRETER_ISEXECUTING = "zeppelin.interpreter.isexecuting";
46-
4742
private final AtomicInteger referenceCount;
4843
private DefaultExecutor executor;
4944
private ExecuteWatchdog watchdog;
@@ -99,25 +94,23 @@ public int getPort() {
9994
public int reference(InterpreterGroup interpreterGroup) {
10095
synchronized (referenceCount) {
10196
if (executor == null) {
102-
Properties properties = interpreterGroup.getProperty();
103-
104-
if (properties.containsKey(ZEPPELIN_INTERPRETER_ISEXECUTING)) {
105-
isInterpreterAlreadyExecuting =
106-
Boolean.parseBoolean(properties.getProperty(ZEPPELIN_INTERPRETER_ISEXECUTING));
97+
if (interpreterGroup.containsKey(Constants.EXECUTING_PROCESS)) {
98+
Properties properties = interpreterGroup.getProperty();
99+
isInterpreterAlreadyExecuting = true;
107100
if (isInterpreterAlreadyExecuting) {
108-
if (properties.containsKey(ZEPPELIN_INTERPRETER_HOST)) {
109-
host = properties.getProperty(ZEPPELIN_INTERPRETER_HOST);
101+
if (properties.containsKey(Constants.ZEPPELIN_INTERPRETER_HOST)) {
102+
host = properties.getProperty(Constants.ZEPPELIN_INTERPRETER_HOST);
110103

111104
} else {
112-
throw new InterpreterException("Can't find property " + ZEPPELIN_INTERPRETER_HOST
113-
+ ".Please specify the host on which interpreter is executing");
105+
throw new InterpreterException("Can't find value for option Host."
106+
+ "Please specify the host on which interpreter is executing");
114107
}
115-
if (properties.containsKey(ZEPPELIN_INTERPRETER_PORT)) {
116-
port = Integer
117-
.parseInt(interpreterGroup.getProperty().getProperty(ZEPPELIN_INTERPRETER_PORT));
108+
if (properties.containsKey(Constants.ZEPPELIN_INTERPRETER_PORT)) {
109+
port = Integer.parseInt(
110+
interpreterGroup.getProperty().getProperty(Constants.ZEPPELIN_INTERPRETER_PORT));
118111
} else {
119-
throw new InterpreterException("Can't find property " + ZEPPELIN_INTERPRETER_PORT
120-
+ ".Please specify the port on which interpreter is listening");
112+
throw new InterpreterException("Can't find value for option Port."
113+
+ "Please specify the port on which interpreter is listening");
121114
}
122115
}
123116
running = true;

zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.apache.thrift.TException;
2828
import org.apache.thrift.transport.TTransportException;
29+
import org.apache.zeppelin.interpreter.Constants;
2930
import org.apache.zeppelin.interpreter.InterpreterGroup;
3031
import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client;
3132
import org.junit.Test;
@@ -90,11 +91,11 @@ public void testStartStopRemoteInterpreter() throws TException, InterruptedExcep
9091
}
9192
}
9293
Properties properties = new Properties();
93-
properties.setProperty("zeppelin.interpreter.port", "3678");
94-
properties.setProperty("zeppelin.interpreter.host", "localhost");
95-
properties.setProperty("zeppelin.interpreter.isexecuting", "true");
94+
properties.setProperty(Constants.ZEPPELIN_INTERPRETER_PORT, "3678");
95+
properties.setProperty(Constants.ZEPPELIN_INTERPRETER_HOST, "localhost");
9696
InterpreterGroup intpGroup = mock(InterpreterGroup.class);
9797
when(intpGroup.getProperty()).thenReturn(properties);
98+
when(intpGroup.containsKey(Constants.EXECUTING_PROCESS)).thenReturn(true);
9899
RemoteInterpreterProcess rip = new RemoteInterpreterProcess(INTERPRETER_SCRIPT, "nonexists",
99100
"fakeRepo", new HashMap<String, String>(), 10 * 1000, null);
100101
assertFalse(rip.isRunning());

zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,29 @@ <h4>Create new interpreter</h4>
6464
isolated
6565
</a>
6666
</li>
67+
<li>
68+
<a style="cursor:pointer"
69+
tooltip="Already executing Remote Interpreter Process"
70+
ng-click="setSessionOption(setting.id, 'executing')">
71+
executing
72+
</a>
73+
</li>
74+
6775
</ul>
6876
</span>
6977
<span>Interpreter for note</span>
7078
</div>
7179
<br />
80+
<div ng-show="newInterpreterSetting.option.executing" class="form-group" style="width:200px">
81+
<b>Host</b>
82+
<input id="newInterpreterSettingHost" input pu-elastic-input
83+
pu-elastic-input-minwidth="180px" ng-model="newInterpreterSetting.option.host" />
84+
</div>
85+
<div ng-show="newInterpreterSetting.option.executing" class="form-group" style="width:200px">
86+
<b>Port</b>
87+
<input id="newInterpreterSettingPort" input pu-elastic-input
88+
pu-elastic-input-minwidth="180px" ng-model="newInterpreterSetting.option.port" />
89+
</div>
7290

7391
<b>Properties</b>
7492
<table class="table table-striped properties">

zeppelin-web/src/app/interpreter/interpreter.controller.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,19 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope,
7373
if (sessionOption === 'isolated') {
7474
option.perNoteSession = false;
7575
option.perNoteProcess = true;
76+
option.executing = false;
7677
} else if (sessionOption === 'scoped') {
7778
option.perNoteSession = true;
7879
option.perNoteProcess = false;
80+
option.executing = false;
81+
} else if (sessionOption === 'executing') {
82+
option.executing = true;
83+
option.perNoteProcess = false;
84+
option.perNoteSession = false;
7985
} else {
8086
option.perNoteSession = false;
8187
option.perNoteProcess = false;
88+
option.executing = false;
8289
}
8390
};
8491

@@ -96,6 +103,8 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope,
96103
return 'scoped';
97104
} else if (option.perNoteProcess) {
98105
return 'isolated';
106+
} else if (option.executing) {
107+
return 'executing';
99108
} else {
100109
return 'shared';
101110
}
@@ -273,8 +282,10 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope,
273282
dependencies: [],
274283
option: {
275284
remote: true,
285+
executing: false,
276286
perNoteSession: false,
277287
perNoteProcess: false
288+
278289
}
279290
};
280291
emptyNewProperty($scope.newInterpreterSetting);

zeppelin-web/src/app/interpreter/interpreter.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,31 @@ <h5>Option</h5>
148148
isolated
149149
</a>
150150
</li>
151+
<li>
152+
<a style="cursor:pointer"
153+
tooltip="Already executing Remote Interpreter Process"
154+
ng-click="setSessionOption(setting.id, 'executing')">
155+
executing
156+
</a>
157+
</li>
158+
151159
</ul>
152160
</span>
153161
<span>Interpreter for note</span>
154162
</div>
155163

164+
<div class="col-md-12" ng-show="setting.option.executing">
165+
<b>Host</b>
166+
<input id="newInterpreterSettingHost" input pu-elastic-input
167+
pu-elastic-input-minwidth="180px" ng-model="setting.option.host" ng-disabled="!valueform.$visible" />
168+
</div>
169+
<div class="col-md-12" ng-show="setting.option.executing">
170+
<b>Port</b>
171+
<input id="newInterpreterSettingPort" input pu-elastic-input
172+
pu-elastic-input-minwidth="180px" ng-model="setting.option.port" ng-disabled="!valueform.$visible" />
173+
</div>
174+
175+
156176

157177
<div ng-show="_.isEmpty(setting.properties) && _.isEmpty(setting.dependencies) || valueform.$hidden" class="col-md-12 gray40-message">
158178
<em>Currently there are no properties and dependencies set for this interpreter</em>

zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ public void createInterpretersForNote(
544544
String groupName = interpreterSetting.getGroup();
545545
InterpreterOption option = interpreterSetting.getOption();
546546
Properties properties = interpreterSetting.getProperties();
547-
547+
if (option.isExecuting()) {
548+
properties.put(Constants.ZEPPELIN_INTERPRETER_HOST, option.getHost());
549+
properties.put(Constants.ZEPPELIN_INTERPRETER_PORT, option.getPort());
550+
}
548551
// if interpreters are already there, wait until they're being removed
549552
synchronized (interpreterGroup) {
550553
long interpreterRemovalWaitStart = System.nanoTime();

zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,37 @@ public class InterpreterOption {
2424
boolean remote;
2525
boolean perNoteSession;
2626
boolean perNoteProcess;
27+
28+
boolean executing;
29+
30+
String host;
31+
String port;
32+
33+
34+
public boolean isExecuting() {
35+
return executing;
36+
}
37+
38+
public void setExecuting(boolean executing) {
39+
this.executing = executing;
40+
}
41+
42+
public String getPort() {
43+
return port;
44+
}
45+
46+
public void setPort(String port) {
47+
this.port = port;
48+
}
49+
50+
public String getHost() {
51+
return host;
52+
}
53+
54+
public void setHost(String host) {
55+
this.host = host;
56+
}
57+
2758

2859
public InterpreterOption() {
2960
remote = false;

zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public String getGroup() {
126126
private String getInterpreterProcessKey(String noteId) {
127127
if (getOption().isPerNoteProcess()) {
128128
return noteId;
129+
} else if (getOption().isExecuting()) {
130+
return Constants.EXECUTING_PROCESS;
129131
} else {
130132
return SHARED_PROCESS;
131133
}

zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteInterpreterLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.LinkedList;
2222
import java.util.List;
2323

24+
import org.apache.zeppelin.interpreter.Constants;
2425
import org.apache.zeppelin.interpreter.Interpreter;
2526
import org.apache.zeppelin.interpreter.Interpreter.RegisteredInterpreter;
2627
import org.apache.zeppelin.interpreter.InterpreterException;
@@ -77,6 +78,8 @@ public List<InterpreterSetting> getInterpreterSettings() {
7778
private String getInterpreterInstanceKey(InterpreterSetting setting) {
7879
if (setting.getOption().isPerNoteSession() || setting.getOption().isPerNoteProcess()) {
7980
return noteId;
81+
} else if (setting.getOption().isExecuting()) {
82+
return Constants.EXECUTING_PROCESS;
8083
} else {
8184
return SHARED_SESSION;
8285
}

0 commit comments

Comments
 (0)