Mapped the location of some functions related to InterpreterSetting again

This commit is contained in:
Jongyoul Lee 2017-02-11 12:01:02 +09:00
parent c378c3fa6c
commit 0affba7499
7 changed files with 36 additions and 33 deletions

View file

@ -37,6 +37,7 @@ import javax.ws.rs.core.Response.Status;
import com.google.gson.Gson;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.zeppelin.interpreter.InterpreterSettingManager;
import org.apache.zeppelin.rest.message.RestartInterpreterRequest;
import org.apache.zeppelin.utils.SecurityUtils;
import org.slf4j.Logger;
@ -61,7 +62,7 @@ import org.apache.zeppelin.socket.NotebookServer;
public class InterpreterRestApi {
private static final Logger logger = LoggerFactory.getLogger(InterpreterRestApi.class);
private InterpreterFactory interpreterFactory;
private InterpreterSettingManager interpreterSettingManager;
private NotebookServer notebookServer;
Gson gson = new Gson();
@ -69,9 +70,9 @@ public class InterpreterRestApi {
public InterpreterRestApi() {
}
public InterpreterRestApi(InterpreterFactory interpreterFactory,
NotebookServer notebookWsServer) {
this.interpreterFactory = interpreterFactory;
public InterpreterRestApi(InterpreterSettingManager interpreterSettingManager,
NotebookServer notebookWsServer) {
this.interpreterSettingManager = interpreterSettingManager;
this.notebookServer = notebookWsServer;
}
@ -82,7 +83,7 @@ public class InterpreterRestApi {
@Path("setting")
@ZeppelinApi
public Response listSettings() {
return new JsonResponse<>(Status.OK, "", interpreterFactory.get()).build();
return new JsonResponse<>(Status.OK, "", interpreterSettingManager.get()).build();
}
/**
@ -93,7 +94,7 @@ public class InterpreterRestApi {
@ZeppelinApi
public Response getSetting(@PathParam("settingId") String settingId) {
try {
InterpreterSetting setting = interpreterFactory.get(settingId);
InterpreterSetting setting = interpreterSettingManager.get(settingId);
if (setting == null) {
return new JsonResponse<>(Status.NOT_FOUND).build();
} else {
@ -123,7 +124,7 @@ public class InterpreterRestApi {
}
Properties p = new Properties();
p.putAll(request.getProperties());
InterpreterSetting interpreterSetting = interpreterFactory
InterpreterSetting interpreterSetting = interpreterSettingManager
.createNewSetting(request.getName(), request.getGroup(), request.getDependencies(),
request.getOption(), p);
logger.info("new setting created with {}", interpreterSetting.getId());
@ -144,7 +145,7 @@ public class InterpreterRestApi {
try {
UpdateInterpreterSettingRequest request =
gson.fromJson(message, UpdateInterpreterSettingRequest.class);
interpreterFactory
interpreterSettingManager
.setPropertyAndRestart(settingId, request.getOption(), request.getProperties(),
request.getDependencies());
} catch (InterpreterException e) {
@ -156,7 +157,7 @@ public class InterpreterRestApi {
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(),
ExceptionUtils.getStackTrace(e)).build();
}
InterpreterSetting setting = interpreterFactory.get(settingId);
InterpreterSetting setting = interpreterSettingManager.get(settingId);
if (setting == null) {
return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build();
}
@ -171,7 +172,7 @@ public class InterpreterRestApi {
@ZeppelinApi
public Response removeSetting(@PathParam("settingId") String settingId) throws IOException {
logger.info("Remove interpreterSetting {}", settingId);
interpreterFactory.remove(settingId);
interpreterSettingManager.remove(settingId);
return new JsonResponse(Status.OK).build();
}
@ -184,12 +185,12 @@ public class InterpreterRestApi {
public Response restartSetting(String message, @PathParam("settingId") String settingId) {
logger.info("Restart interpreterSetting {}, msg={}", settingId, message);
InterpreterSetting setting = interpreterFactory.get(settingId);
InterpreterSetting setting = interpreterSettingManager.get(settingId);
try {
RestartInterpreterRequest request = gson.fromJson(message, RestartInterpreterRequest.class);
String noteId = request == null ? null : request.getNoteId();
interpreterFactory.restart(settingId, noteId, SecurityUtils.getPrincipal());
interpreterSettingManager.restart(settingId, noteId, SecurityUtils.getPrincipal());
notebookServer.clearParagraphRuntimeInfo(setting);
} catch (InterpreterException e) {
@ -209,7 +210,7 @@ public class InterpreterRestApi {
@GET
@ZeppelinApi
public Response listInterpreter(String message) {
Map<String, InterpreterSetting> m = interpreterFactory.getAvailableInterpreterSettings();
Map<String, InterpreterSetting> m = interpreterSettingManager.getAvailableInterpreterSettings();
return new JsonResponse<>(Status.OK, "", m).build();
}
@ -220,7 +221,7 @@ public class InterpreterRestApi {
@Path("repository")
@ZeppelinApi
public Response listRepositories() {
List<RemoteRepository> interpreterRepositories = interpreterFactory.getRepositories();
List<RemoteRepository> interpreterRepositories = interpreterSettingManager.getRepositories();
return new JsonResponse<>(Status.OK, "", interpreterRepositories).build();
}
@ -235,8 +236,8 @@ public class InterpreterRestApi {
public Response addRepository(String message) {
try {
Repository request = gson.fromJson(message, Repository.class);
interpreterFactory.addRepository(request.getId(), request.getUrl(), request.isSnapshot(),
request.getAuthentication(), request.getProxy());
interpreterSettingManager.addRepository(request.getId(), request.getUrl(),
request.isSnapshot(), request.getAuthentication(), request.getProxy());
logger.info("New repository {} added", request.getId());
} catch (Exception e) {
logger.error("Exception in InterpreterRestApi while adding repository ", e);
@ -258,7 +259,7 @@ public class InterpreterRestApi {
return new JsonResponse<>(Status.BAD_REQUEST).build();
}
String propValue = null;
InterpreterSetting interpreterSetting = interpreterFactory.get(settingId);
InterpreterSetting interpreterSetting = interpreterSettingManager.get(settingId);
Map<String, String> infos = interpreterSetting.getInfos();
if (infos != null) {
propValue = infos.get(propName);
@ -282,7 +283,7 @@ public class InterpreterRestApi {
public Response removeRepository(@PathParam("repoId") String repoId) {
logger.info("Remove repository {}", repoId);
try {
interpreterFactory.removeRepository(repoId);
interpreterSettingManager.removeRepository(repoId);
} catch (Exception e) {
logger.error("Exception in InterpreterRestApi while removing repository ", e);
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(),

View file

@ -383,7 +383,8 @@ public class ZeppelinServer extends Application {
HeliumRestApi heliumApi = new HeliumRestApi(helium, notebook);
singletons.add(heliumApi);
InterpreterRestApi interpreterApi = new InterpreterRestApi(replFactory, notebookWsServer);
InterpreterRestApi interpreterApi = new InterpreterRestApi(interpreterSettingManager,
notebookWsServer);
singletons.add(interpreterApi);
CredentialRestApi credentialApi = new CredentialRestApi(credentials);

View file

@ -37,7 +37,7 @@ public class InterpreterBindingUtils {
setting.getInterpreterInfos(), true));
}
List<InterpreterSetting> availableSettings = notebook.getInterpreterFactory().get();
List<InterpreterSetting> availableSettings = notebook.getInterpreterSettingManager().get();
for (InterpreterSetting setting : availableSettings) {
boolean selected = false;
for (InterpreterSetting selectedSetting : selectedSettings) {

View file

@ -188,7 +188,8 @@ public abstract class AbstractTestRestApi {
// assume first one is spark
InterpreterSetting sparkIntpSetting = null;
for(InterpreterSetting intpSetting : ZeppelinServer.notebook.getInterpreterFactory().get()) {
for(InterpreterSetting intpSetting :
ZeppelinServer.notebook.getInterpreterSettingManager().get()) {
if (intpSetting.getName().equals("spark")) {
sparkIntpSetting = intpSetting;
}
@ -208,7 +209,7 @@ public abstract class AbstractTestRestApi {
sparkIntpSetting.setProperties(sparkProperties);
pySpark = true;
sparkR = true;
ZeppelinServer.notebook.getInterpreterFactory().restart(sparkIntpSetting.getId());
ZeppelinServer.notebook.getInterpreterSettingManager().restart(sparkIntpSetting.getId());
} else {
String sparkHome = getSparkHome();
if (sparkHome != null) {
@ -225,7 +226,7 @@ public abstract class AbstractTestRestApi {
sparkR = true;
}
ZeppelinServer.notebook.getInterpreterFactory().restart(sparkIntpSetting.getId());
ZeppelinServer.notebook.getInterpreterSettingManager().restart(sparkIntpSetting.getId());
}
}
}
@ -292,10 +293,10 @@ public abstract class AbstractTestRestApi {
protected static void shutDown() throws Exception {
if (!wasRunning) {
// restart interpreter to stop all interpreter processes
List<String> settingList = ZeppelinServer.notebook.getInterpreterFactory()
List<String> settingList = ZeppelinServer.notebook.getInterpreterSettingManager()
.getDefaultInterpreterSettingList();
for (String setting : settingList) {
ZeppelinServer.notebook.getInterpreterFactory().restart(setting);
ZeppelinServer.notebook.getInterpreterSettingManager().restart(setting);
}
if (shiroIni != null) {
FileUtils.deleteQuietly(shiroIni);

View file

@ -80,7 +80,7 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
// then
assertThat(get, isAllowed());
assertEquals(ZeppelinServer.notebook.getInterpreterFactory().getAvailableInterpreterSettings().size(),
assertEquals(ZeppelinServer.notebook.getInterpreterSettingManager().getAvailableInterpreterSettings().size(),
body.entrySet().size());
get.releaseConnection();
}
@ -258,7 +258,7 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
assertEquals(p.getResult().message().get(0).getData(), getSimulatedMarkdownResult("markdown"));
// when: restart interpreter
for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterFactory().getInterpreterSettings(note.getId())) {
for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId())) {
if (setting.getName().equals("md")) {
// call restart interpreter API
PutMethod put = httpPut("/interpreter/setting/restart/" + setting.getId(), "");
@ -304,7 +304,7 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
// when: get md interpreter
InterpreterSetting mdIntpSetting = null;
for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterFactory().getInterpreterSettings(note.getId())) {
for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId())) {
if (setting.getName().equals("md")) {
mdIntpSetting = setting;
break;

View file

@ -185,7 +185,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("spark")) {
ZeppelinServer.notebook.getInterpreterFactory().restart(setting.getId());
ZeppelinServer.notebook.getInterpreterSettingManager().restart(setting.getId());
break;
}
}
@ -417,7 +417,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("spark")) {
ZeppelinServer.notebook.getInterpreterFactory().restart(setting.getId());
ZeppelinServer.notebook.getInterpreterSettingManager().restart(setting.getId());
break;
}
}

View file

@ -101,7 +101,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
// get reference to interpreterGroup
InterpreterGroup interpreterGroup = null;
List<InterpreterSetting> settings = notebook.getInterpreterFactory().getInterpreterSettings(note1.getId());
List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId());
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("md")) {
interpreterGroup = setting.getInterpreterGroup("anonymous", "sharedProcess");
@ -374,7 +374,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
String noteName = "Note with millis " + System.currentTimeMillis();
String defaultInterpreterId = "";
List<InterpreterSetting> settings = notebook.getInterpreterFactory().get();
List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().get();
if (settings.size() > 1) {
defaultInterpreterId = settings.get(1).getId();
}
@ -396,7 +396,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
}
if (settings.size() > 1) {
assertEquals(notebook.getInterpreterFactory().getDefaultInterpreterSetting(
assertEquals(notebook.getInterpreterSettingManager().getDefaultInterpreterSetting(
createdNote.getId()).getId(), defaultInterpreterId);
}
notebook.removeNote(createdNote.getId(), anonymous);