Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch class loader #64

Merged
merged 2 commits into from Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,9 +25,9 @@
package io.jenkins.plugins.ml;

import org.apache.zeppelin.interpreter.*;
import org.apache.zeppelin.jupyter.JupyterInterpreter;
import org.apache.zeppelin.resource.LocalResourcePool;
import org.apache.zeppelin.resource.ResourcePool;
import io.jenkins.plugins.ml.jupyter.JupyterInterpreter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/jenkins/plugins/ml/Server.java
Expand Up @@ -197,7 +197,7 @@ public FormValidation doValidate(

if (Util.fixEmptyAndTrim(kernel) != null) {
try{
IPythonUserConfig userConfig = new IPythonUserConfig(kernel, Integer.parseInt(launchTimeout), Integer.parseInt(maxResults), ".");
IPythonUserConfig userConfig = new IPythonUserConfig(kernel, Integer.parseInt(launchTimeout)*1000, Integer.parseInt(maxResults), ".");
try (InterpreterManager interpreterManager = new IPythonInterpreterManager(userConfig)) {
interpreterManager.initiateInterpreter();
if (interpreterManager.testConnection()) {
Expand Down
116 changes: 116 additions & 0 deletions src/main/java/io/jenkins/plugins/ml/jupyter/JupyterInterpreter.java
@@ -0,0 +1,116 @@
/*
* 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 io.jenkins.plugins.ml.jupyter;

import org.apache.zeppelin.interpreter.*;
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.jupyter.JupyterZeppelinContext;

import java.util.*;

public class JupyterInterpreter extends AbstractInterpreter {
private Map<String, io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter> kernelInterpreterMap = new HashMap();

public JupyterInterpreter(Properties properties) {
super(properties);
}

public ZeppelinContext getZeppelinContext() {
return new JupyterZeppelinContext(this.getInterpreterGroup().getInterpreterHookRegistry(), 1000);
}

protected InterpreterResult internalInterpret(String st, InterpreterContext context) throws InterpreterException {
String kernel = (String) context.getLocalProperties().get("kernel");
if (kernel == null) {
return new InterpreterResult(Code.ERROR, "No kernel is specified");
} else {
io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter kernelInterpreter = null;
synchronized (this.kernelInterpreterMap) {
if (this.kernelInterpreterMap.containsKey(kernel)) {
kernelInterpreter = (io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter) this.kernelInterpreterMap.get(kernel);
} else {
kernelInterpreter = new io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter(kernel, this.properties);
kernelInterpreter.open();
this.kernelInterpreterMap.put(kernel, kernelInterpreter);
}
}

return kernelInterpreter.interpret(st, context);
}
}

public void open() throws InterpreterException {
}

public void close() throws InterpreterException {
Iterator var1 = this.kernelInterpreterMap.values().iterator();

while (var1.hasNext()) {
io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter kernelInterpreter = (io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter) var1.next();
kernelInterpreter.close();
}

}

public void cancel(InterpreterContext context) throws InterpreterException {
String kernel = (String) context.getLocalProperties().get("kernel");
if (kernel == null) {
throw new InterpreterException("No kernel is specified");
} else {
io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter kernelInterpreter = (io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter) this.kernelInterpreterMap.get(kernel);
if (kernelInterpreter == null) {
throw new InterpreterException("No such interpreter: " + kernel);
} else {
kernelInterpreter.cancel(context);
}
}
}

public FormType getFormType() throws InterpreterException {
return FormType.NATIVE;
}

public int getProgress(InterpreterContext context) throws InterpreterException {
String kernel = (String) context.getLocalProperties().get("kernel");
if (kernel == null) {
throw new InterpreterException("No kernel is specified");
} else {
io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter kernelInterpreter = (io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter) this.kernelInterpreterMap.get(kernel);
if (kernelInterpreter == null) {
throw new InterpreterException("No such interpreter: " + kernel);
} else {
return kernelInterpreter.getProgress(context);
}
}
}

public List<InterpreterCompletion> completion(String buf, int cursor, InterpreterContext context) throws InterpreterException {
String kernel = (String) context.getLocalProperties().get("kernel");
if (kernel == null) {
throw new InterpreterException("No kernel is specified");
} else {
io.jenkins.plugins.ml.jupyter.JupyterKernelInterpreter kernelInterpreter = (JupyterKernelInterpreter) this.kernelInterpreterMap.get(kernel);
if (kernelInterpreter == null) {
throw new InterpreterException("No such interpreter: " + kernel);
} else {
return kernelInterpreter.completion(buf, cursor, context);
}
}
}
}
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.zeppelin.jupyter;
package io.jenkins.plugins.ml.jupyter;

import io.grpc.ManagedChannelBuilder;
import org.apache.commons.exec.CommandLine;
Expand All @@ -29,7 +29,9 @@
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterUtils;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.interpreter.util.InterpreterOutputStream;
import org.apache.zeppelin.interpreter.util.ProcessLauncher;
import org.apache.zeppelin.jupyter.JupyterKernelClient;
import org.apache.zeppelin.jupyter.JupyterZeppelinContext;
import io.jenkins.plugins.ml.util.ProcessLauncher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Expand Up @@ -15,9 +15,8 @@
* limitations under the License.
*/

package org.apache.zeppelin.interpreter.util;
package io.jenkins.plugins.ml.util;

import org.apache.commons.exec.LogOutputStream;
import org.apache.commons.exec.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down