use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterServer method getProgress.
@Override
public int getProgress(String sessionId, String className, RemoteInterpreterContext interpreterContext) throws InterpreterRPCException, TException {
lifecycleManager.onInterpreterUse(interpreterGroupId);
Integer manuallyProvidedProgress = progressMap.get(interpreterContext.getParagraphId());
if (manuallyProvidedProgress != null) {
return manuallyProvidedProgress;
} else {
Interpreter intp = getInterpreter(sessionId, className);
if (intp == null) {
throw new InterpreterRPCException("No interpreter " + className + " existed for session " + sessionId);
}
try {
return intp.getProgress(convert(interpreterContext, null));
} catch (InterpreterException e) {
throw new InterpreterRPCException(e.toString());
}
}
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterServer method angularObjectUpdate.
/**
* called when object is updated in client (web) side.
*
* @param name
* @param noteId noteId where the update issues
* @param paragraphId paragraphId where the update issues
* @param object
* @throws InterpreterRPCException, TException
*/
@Override
public void angularObjectUpdate(String name, String noteId, String paragraphId, String object) throws InterpreterRPCException, TException {
AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
// first try local objects
AngularObject ao = registry.get(name, noteId, paragraphId);
if (ao == null) {
LOGGER.debug("Angular object {} not exists", name);
return;
}
if (object == null) {
ao.set(null, false);
return;
}
Object oldObject = ao.get();
Object value = null;
if (oldObject != null) {
// first try with previous object's type
try {
value = gson.fromJson(object, oldObject.getClass());
ao.set(value, false);
return;
} catch (Exception e) {
// it's not a previous object's type. proceed to treat as a generic type
LOGGER.debug(e.getMessage(), e);
}
}
// Generic java object type for json.
if (value == null) {
try {
value = gson.fromJson(object, new TypeToken<Map<String, Object>>() {
}.getType());
} catch (Exception e) {
// it's not a generic json object, too. okay, proceed to threat as a string type
LOGGER.debug(e.getMessage(), e);
}
}
// try string object type at last
if (value == null) {
value = gson.fromJson(object, String.class);
}
ao.set(value, false);
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterServer method createInterpreter.
@Override
public void createInterpreter(String interpreterGroupId, String sessionId, String className, Map<String, String> properties, String userName) throws InterpreterRPCException, TException {
try {
if (interpreterGroup == null) {
interpreterGroup = new InterpreterGroup(interpreterGroupId);
angularObjectRegistry = new AngularObjectRegistry(interpreterGroup.getId(), intpEventClient);
hookRegistry = new InterpreterHookRegistry();
resourcePool = new DistributedResourcePool(interpreterGroup.getId(), intpEventClient);
interpreterGroup.setInterpreterHookRegistry(hookRegistry);
interpreterGroup.setAngularObjectRegistry(angularObjectRegistry);
interpreterGroup.setResourcePool(resourcePool);
intpEventClient.setIntpGroupId(interpreterGroupId);
String localRepoPath = properties.get("zeppelin.interpreter.localRepo");
if (properties.containsKey("zeppelin.interpreter.output.limit")) {
InterpreterOutput.LIMIT = Integer.parseInt(properties.get("zeppelin.interpreter.output.limit"));
}
depLoader = new DependencyResolver(localRepoPath);
appLoader = new ApplicationLoader(resourcePool, depLoader);
resultCacheInSeconds = Integer.parseInt(properties.getOrDefault("zeppelin.interpreter.result.cache", "0"));
}
Class<Interpreter> replClass = (Class<Interpreter>) Object.class.forName(className);
Properties p = new Properties();
p.putAll(properties);
setSystemProperty(p);
Constructor<Interpreter> constructor = replClass.getConstructor(new Class[] { Properties.class });
Interpreter interpreter = constructor.newInstance(p);
interpreter.setClassloaderUrls(new URL[] {});
interpreter.setInterpreterGroup(interpreterGroup);
interpreter.setUserName(userName);
interpreterGroup.addInterpreterToSession(new LazyOpenInterpreter(interpreter), sessionId);
this.isForceShutdown = Boolean.parseBoolean(properties.getOrDefault("zeppelin.interpreter.forceShutdown", "true"));
LOGGER.info("Instantiate interpreter {}, isForceShutdown: {}", className, isForceShutdown);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new InterpreterRPCException("Fail to create interpreter, cause: " + e.toString());
}
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterServer method loadApplication.
@Override
public RemoteApplicationResult loadApplication(String applicationInstanceId, String packageInfo, String noteId, String paragraphId) throws InterpreterRPCException, TException {
if (runningApplications.containsKey(applicationInstanceId)) {
LOGGER.warn("Application instance {} is already running", applicationInstanceId);
return new RemoteApplicationResult(true, "");
}
HeliumPackage pkgInfo = HeliumPackage.fromJson(packageInfo);
ApplicationContext context = getApplicationContext(pkgInfo, noteId, paragraphId, applicationInstanceId);
try {
Application app = null;
LOGGER.info("Loading application {}({}), artifact={}, className={} into note={}, paragraph={}", pkgInfo.getName(), applicationInstanceId, pkgInfo.getArtifact(), pkgInfo.getClassName(), noteId, paragraphId);
app = appLoader.load(pkgInfo, context);
runningApplications.put(applicationInstanceId, new RunningApplication(pkgInfo, app, noteId, paragraphId));
return new RemoteApplicationResult(true, "");
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return new RemoteApplicationResult(false, e.getMessage());
}
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterServer method reconnect.
@Override
public void reconnect(String host, int port) throws InterpreterRPCException, TException {
try {
LOGGER.info("Reconnect to this interpreter process from {}:{}", host, port);
this.intpEventServerHost = host;
this.intpEventServerPort = port;
intpEventClient = new RemoteInterpreterEventClient(intpEventServerHost, intpEventServerPort, this.zConf.getInt(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECTION_POOL_SIZE));
intpEventClient.setIntpGroupId(interpreterGroupId);
this.angularObjectRegistry = new AngularObjectRegistry(interpreterGroup.getId(), intpEventClient);
this.resourcePool = new DistributedResourcePool(interpreterGroup.getId(), intpEventClient);
// reset all the available InterpreterContext's components that use intpEventClient.
for (InterpreterContext context : InterpreterContext.getAllContexts().values()) {
context.setIntpEventClient(intpEventClient);
context.setAngularObjectRegistry(angularObjectRegistry);
context.setResourcePool(resourcePool);
}
} catch (Exception e) {
throw new InterpreterRPCException(e.toString());
}
}
Aggregations