Search in sources :

Example 11 with LivyUserException

use of com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException in project kylo by Teradata.

the class SparkLivyProcessManager method startLivySession.

private Session startLivySession(SparkLivyProcess sparkLivyProcess) {
    // it was determined we needed a
    sparkLivyProcess.newSession();
    JerseyRestClient jerseyClient = getClient(sparkLivyProcess);
    Map<String, String> sparkProps = livyProperties.getSparkProperties();
    SessionsPost.Builder builder = new SessionsPost.Builder().kind(// "shared" most likely
    livyProperties.getLivySessionKind().toString()).conf(// "spark.driver.extraJavaOptions", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8990"
    sparkProps);
    logger.debug("LivyProperties={}", livyProperties);
    if (livyProperties.getProxyUser()) {
        String user = processCache.inverse().get(sparkLivyProcess);
        if (user != null) {
            builder.proxyUser(user);
        }
    }
    SessionsPost sessionsPost = builder.build();
    logger.info("sessionsPost={}", sessionsPost);
    Session currentSession;
    try {
        currentSession = livyClient.postSessions(jerseyClient, sessionsPost);
        if (currentSession == null) {
            logger.error("Server not reachable", new LivyServerNotReachableException("Empty result from LivyClient.postSessions"));
            throw new LivyUserException("livy.server_not_found");
        }
    } catch (LivyException le) {
        throw le;
    } catch (Exception e) {
        // resets the latch
        sparkLivyProcess.startFailed();
        this.processStopped(sparkLivyProcess);
        // NOTE: you can get "javax.ws.rs.ProcessingException: java.io.IOException: Error writing to server" on Ubuntu see: https://stackoverflow.com/a/39718929/154461
        throw new LivyException(e);
    }
    sparkLivyProcess.setSessionId(currentSession.getId());
    // notifies listeners
    this.processStarted(sparkLivyProcess);
    // begin monitoring this session if configured to do so..
    heartbeatMonitor.monitorSession(sparkLivyProcess);
    return currentSession;
}
Also used : SessionsPost(com.thinkbiganalytics.kylo.spark.model.SessionsPost) LivyException(com.thinkbiganalytics.kylo.spark.exceptions.LivyException) LivyUserException(com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) LivyException(com.thinkbiganalytics.kylo.spark.exceptions.LivyException) LivyServerNotReachableException(com.thinkbiganalytics.kylo.spark.exceptions.LivyServerNotReachableException) LivyUserException(com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException) LivyInvalidSessionException(com.thinkbiganalytics.kylo.spark.exceptions.LivyInvalidSessionException) Session(com.thinkbiganalytics.kylo.spark.model.Session) LivyServerNotReachableException(com.thinkbiganalytics.kylo.spark.exceptions.LivyServerNotReachableException)

Example 12 with LivyUserException

use of com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException in project kylo by Teradata.

the class SparkLivyProcessManager method start.

public void start(@Nonnull final SparkLivyProcess sparkLivyProcess) {
    JerseyRestClient jerseyClient = getClient(sparkLivyProcess);
    // fetch or create new server session
    Session currentSession;
    if (sparkLivyProcess.getSessionId() != null) {
        Optional<Session> optSession = getLivySession(sparkLivyProcess);
        if (optSession.isPresent()) {
            currentSession = optSession.get();
        } else {
            currentSession = startLivySession(sparkLivyProcess);
        }
    } else {
        currentSession = startLivySession(sparkLivyProcess);
    }
    Integer currentSessionId = currentSession.getId();
    if (!currentSession.getState().equals(SessionState.idle)) {
        logger.debug("Created session with id='{}', but it was returned with state != idle, state = '{}'", currentSession.getId(), currentSession.getState());
        if (!waitForSessionToBecomeIdle(jerseyClient, currentSessionId)) {
            throw new LivyUserException("livy.start_failed");
        }
        // At this point the server is ready and we can send it an initialization command, any following
        // statement sent by UI will wait for their turn to execute
        initSession(sparkLivyProcess);
    }
    // end if
    // notifies all and any waiting threads session is started, OK to call many times..
    sparkLivyProcess.sessionStarted();
}
Also used : LivyUserException(com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Session(com.thinkbiganalytics.kylo.spark.model.Session)

Example 13 with LivyUserException

use of com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException in project kylo by Teradata.

the class SparkLivyProcessManager method getLivySession.

private Optional<Session> getLivySession(SparkLivyProcess sparkLivyProcess) {
    JerseyRestClient jerseyClient = getClient(sparkLivyProcess);
    SessionsGetResponse sessions = livyClient.getSessions(jerseyClient);
    if (sessions == null) {
        logger.error("Server not reachable", new LivyServerNotReachableException("Empty result from LivyClient.getSessions"));
        throw new LivyUserException("livy.server_not_found");
    }
    Optional<Session> optSession = sessions.getSessionWithId(sparkLivyProcess.getSessionId());
    if (!optSession.isPresent()) {
        // current client not found... let's make a new one
        clearClientState(sparkLivyProcess);
    }
    return optSession;
}
Also used : SessionsGetResponse(com.thinkbiganalytics.kylo.spark.model.SessionsGetResponse) LivyUserException(com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) LivyServerNotReachableException(com.thinkbiganalytics.kylo.spark.exceptions.LivyServerNotReachableException) Session(com.thinkbiganalytics.kylo.spark.model.Session)

Aggregations

LivyUserException (com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException)13 JerseyRestClient (com.thinkbiganalytics.rest.JerseyRestClient)7 Statement (com.thinkbiganalytics.kylo.spark.model.Statement)6 Nonnull (javax.annotation.Nonnull)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 LivyCodeException (com.thinkbiganalytics.kylo.spark.exceptions.LivyCodeException)4 LivyDeserializationException (com.thinkbiganalytics.kylo.spark.exceptions.LivyDeserializationException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Session (com.thinkbiganalytics.kylo.spark.model.Session)3 TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)3 IOException (java.io.IOException)3 DefaultQueryResultColumn (com.thinkbiganalytics.discovery.model.DefaultQueryResultColumn)2 QueryResultColumn (com.thinkbiganalytics.discovery.schema.QueryResultColumn)2 LivyServerNotReachableException (com.thinkbiganalytics.kylo.spark.exceptions.LivyServerNotReachableException)2 SparkLivySaveException (com.thinkbiganalytics.kylo.spark.livy.SparkLivySaveException)2 SparkJobResponse (com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse)2 SaveResponse (com.thinkbiganalytics.spark.rest.model.SaveResponse)2 ServerStatusResponse (com.thinkbiganalytics.spark.rest.model.ServerStatusResponse)2 TransformQueryResult (com.thinkbiganalytics.spark.rest.model.TransformQueryResult)2