use of org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess in project zeppelin by apache.
the class SessionManagerService method getSessionInfo.
/**
* Get the sessionInfo.
* It method will also update its state if there's an associated interpreter process.
*
* @param sessionId
* @return
* @throws Exception
*/
public SessionInfo getSessionInfo(String sessionId) throws Exception {
SessionInfo sessionInfo = sessions.get(sessionId);
if (sessionInfo == null) {
LOGGER.warn("No such session: " + sessionId);
return null;
}
ManagedInterpreterGroup interpreterGroup = this.interpreterSettingManager.getInterpreterGroupById(sessionId);
if (interpreterGroup != null) {
RemoteInterpreterProcess remoteInterpreterProcess = interpreterGroup.getRemoteInterpreterProcess();
if (remoteInterpreterProcess == null) {
sessionInfo.setState(SessionState.READY.name());
} else {
sessionInfo.setStartTime(remoteInterpreterProcess.getStartTime());
sessionInfo.setWeburl(interpreterGroup.getWebUrl());
if (remoteInterpreterProcess.isRunning()) {
sessionInfo.setState(SessionState.RUNNING.name());
} else {
// e.g. InterpreterProcess is terminated for whatever unexpected reason.
if (SessionState.RUNNING.name().equalsIgnoreCase(sessionInfo.getState())) {
sessionInfo.setState(SessionState.STOPPED.name());
}
}
}
} else {
if (SessionState.RUNNING.name().equalsIgnoreCase(sessionInfo.getState())) {
// if it is running before, but interpreterGroup is null now, that means the session is stopped.
// e.g. InterpreterProcess is killed if it exceed idle timeout threshold.
sessionInfo.setState(SessionState.STOPPED.name());
}
}
return sessionInfo;
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess in project zeppelin by apache.
the class RemoteInterpreterEventServer method getResource.
private Object getResource(final ResourceId resourceId) {
ManagedInterpreterGroup intpGroup = interpreterSettingManager.getInterpreterGroupById(resourceId.getResourcePoolId());
if (intpGroup == null) {
return null;
}
RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
ByteBuffer buffer = remoteInterpreterProcess.callRemoteFunction(client -> client.resourceGet(resourceId.getNoteId(), resourceId.getParagraphId(), resourceId.getName()));
try {
return Resource.deserializeObject(buffer);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess in project zeppelin by apache.
the class RemoteInterpreterEventServer method registerInterpreterProcess.
@Override
public void registerInterpreterProcess(RegisterInfo registerInfo) throws InterpreterRPCException, TException {
InterpreterGroup interpreterGroup = interpreterSettingManager.getInterpreterGroupById(registerInfo.getInterpreterGroupId());
if (interpreterGroup == null) {
LOGGER.warn("Unable to register interpreter process, because no such interpreterGroup: {}", registerInfo.getInterpreterGroupId());
return;
}
RemoteInterpreterProcess interpreterProcess = ((ManagedInterpreterGroup) interpreterGroup).getInterpreterProcess();
if (interpreterProcess == null) {
LOGGER.warn("Unable to register interpreter process, because no interpreter process associated with " + "interpreterGroup: {}", registerInfo.getInterpreterGroupId());
return;
}
LOGGER.info("Register interpreter process: {}:{}, interpreterGroup: {}", registerInfo.getHost(), registerInfo.getPort(), registerInfo.getInterpreterGroupId());
interpreterProcess.processStarted(registerInfo.port, registerInfo.host);
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess in project zeppelin by apache.
the class RemoteInterpreterEventServer method invokeResourceMethod.
private Object invokeResourceMethod(String intpGroupId, final InvokeResourceMethodEventMessage message) {
final ResourceId resourceId = message.resourceId;
ManagedInterpreterGroup intpGroup = interpreterSettingManager.getInterpreterGroupById(resourceId.getResourcePoolId());
if (intpGroup == null) {
return null;
}
RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
if (remoteInterpreterProcess == null) {
ResourcePool localPool = intpGroup.getResourcePool();
if (localPool != null) {
Resource res = localPool.get(resourceId.getName());
if (res != null) {
try {
return res.invokeMethod(message.methodName, message.getParamTypes(), message.params, message.returnResourceName);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return null;
}
} else {
// object is null. can't invoke any method
LOGGER.error("Can't invoke method {} on null object", message.methodName);
return null;
}
} else {
LOGGER.error("no resource pool");
return null;
}
} else if (remoteInterpreterProcess.isRunning()) {
ByteBuffer res = remoteInterpreterProcess.callRemoteFunction(client -> client.resourceInvokeMethod(resourceId.getNoteId(), resourceId.getParagraphId(), resourceId.getName(), message.toJson()));
try {
return Resource.deserializeObject(res);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
return null;
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess in project zeppelin by apache.
the class InterpreterSetting method createInterpreterProcess.
synchronized RemoteInterpreterProcess createInterpreterProcess(String interpreterGroupId, String userName, Properties properties) throws IOException {
InterpreterLauncher launcher = createLauncher(properties);
InterpreterLaunchContext launchContext = new InterpreterLaunchContext(properties, option, interpreterRunner, userName, interpreterGroupId, id, group, name, interpreterEventServer.getPort(), interpreterEventServer.getHost());
RemoteInterpreterProcess process = (RemoteInterpreterProcess) launcher.launch(launchContext);
recoveryStorage.onInterpreterClientStart(process);
return process;
}
Aggregations