Search in sources :

Example 1 with RemoteInterpreterProcess

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;
}
Also used : SessionInfo(org.apache.zeppelin.common.SessionInfo) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup)

Example 2 with RemoteInterpreterProcess

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;
}
Also used : RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ByteBuffer(java.nio.ByteBuffer) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 3 with RemoteInterpreterProcess

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);
}
Also used : RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess)

Example 4 with RemoteInterpreterProcess

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;
}
Also used : RegisterInfo(org.apache.zeppelin.interpreter.thrift.RegisterInfo) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) RemoteInterpreterEventService(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventService) TypeToken(com.google.gson.reflect.TypeToken) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ScheduledFuture(java.util.concurrent.ScheduledFuture) AppendOutputRunner(org.apache.zeppelin.interpreter.remote.AppendOutputRunner) Resource(org.apache.zeppelin.resource.Resource) TTransportException(org.apache.thrift.transport.TTransportException) LoggerFactory(org.slf4j.LoggerFactory) ResourcePool(org.apache.zeppelin.resource.ResourcePool) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) StringUtils(org.apache.commons.lang3.StringUtils) ByteBuffer(java.nio.ByteBuffer) LibraryMetadata(org.apache.zeppelin.interpreter.thrift.LibraryMetadata) ParagraphInfo(org.apache.zeppelin.interpreter.thrift.ParagraphInfo) Gson(com.google.gson.Gson) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) Map(java.util.Map) AngularObject(org.apache.zeppelin.display.AngularObject) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) List(java.util.List) OutputAppendEvent(org.apache.zeppelin.interpreter.thrift.OutputAppendEvent) WebUrlInfo(org.apache.zeppelin.interpreter.thrift.WebUrlInfo) OutputUpdateEvent(org.apache.zeppelin.interpreter.thrift.OutputUpdateEvent) RemoteInterpreterUtils(org.apache.zeppelin.interpreter.remote.RemoteInterpreterUtils) RemoteInterpreterProcessListener(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener) ArrayList(java.util.ArrayList) RunParagraphsEvent(org.apache.zeppelin.interpreter.thrift.RunParagraphsEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) LinkedList(java.util.LinkedList) RemoteInterpreterResultMessage(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage) ResourceSet(org.apache.zeppelin.resource.ResourceSet) OutputUpdateAllEvent(org.apache.zeppelin.interpreter.thrift.OutputUpdateAllEvent) Logger(org.slf4j.Logger) ApplicationEventListener(org.apache.zeppelin.helium.ApplicationEventListener) AppOutputAppendEvent(org.apache.zeppelin.interpreter.thrift.AppOutputAppendEvent) ResourceId(org.apache.zeppelin.resource.ResourceId) Note(org.apache.zeppelin.notebook.Note) TException(org.apache.thrift.TException) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TServerSocket(org.apache.thrift.transport.TServerSocket) RemoteResource(org.apache.zeppelin.resource.RemoteResource) AppStatusUpdateEvent(org.apache.zeppelin.interpreter.thrift.AppStatusUpdateEvent) InvokeResourceMethodEventMessage(org.apache.zeppelin.interpreter.remote.InvokeResourceMethodEventMessage) AppOutputUpdateEvent(org.apache.zeppelin.interpreter.thrift.AppOutputUpdateEvent) Collections(java.util.Collections) ResourceId(org.apache.zeppelin.resource.ResourceId) Resource(org.apache.zeppelin.resource.Resource) RemoteResource(org.apache.zeppelin.resource.RemoteResource) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ResourcePool(org.apache.zeppelin.resource.ResourcePool) ByteBuffer(java.nio.ByteBuffer) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 5 with RemoteInterpreterProcess

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;
}
Also used : InterpreterLaunchContext(org.apache.zeppelin.interpreter.launcher.InterpreterLaunchContext) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) InterpreterLauncher(org.apache.zeppelin.interpreter.launcher.InterpreterLauncher)

Aggregations

RemoteInterpreterProcess (org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess)10 Gson (com.google.gson.Gson)6 List (java.util.List)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)4 IOException (java.io.IOException)3 TypeToken (com.google.gson.reflect.TypeToken)2 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 TException (org.apache.thrift.TException)2 TTransportException (org.apache.thrift.transport.TTransportException)2 InterpreterRPCException (org.apache.zeppelin.interpreter.thrift.InterpreterRPCException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 GsonBuilder (com.google.gson.GsonBuilder)1 Gauge (io.micrometer.core.instrument.Gauge)1