Search in sources :

Example 1 with Session

use of com.thinkbiganalytics.kylo.spark.model.Session in project kylo by Teradata.

the class DefaultLivyClient method postSessions.

@Override
public Session postSessions(JerseyRestClient client, SessionsPost sessionsPost) {
    try {
        Session session = client.post(SESSIONS_URL, sessionsPost, Session.class);
        livyServer.setLivyServerStatus(LivyServerStatus.alive);
        livyServer.setSessionIdHighWaterMark(session.getId());
        livyServer.setLivySessionState(session.getId(), session.getState());
        logger.debug("session={}", session);
        return session;
    } catch (WebApplicationException wae) {
        if (wae.getResponse().getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
            livyServer.setLivyServerStatus(LivyServerStatus.http_error);
        }
        throw wae;
    } catch (LivyException le) {
        livyServer.setLivyServerStatus(LivyServerStatus.http_error);
        throw le;
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) LivyException(com.thinkbiganalytics.kylo.spark.exceptions.LivyException) Session(com.thinkbiganalytics.kylo.spark.model.Session)

Example 2 with Session

use of com.thinkbiganalytics.kylo.spark.model.Session in project kylo by Teradata.

the class SparkLivyProcessManager method waitForSessionToBecomeIdle.

/**
 * returns true is session becomes idle; false if it fails to start
 */
private boolean waitForSessionToBecomeIdle(JerseyRestClient jerseyClient, Integer id) {
    Optional<Session> optSession;
    do {
        try {
            Thread.sleep(livyProperties.getPollingInterval());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        SessionsGetResponse sessions = livyClient.getSessions(jerseyClient);
        logger.debug("poll server for session with id='{}'", id);
        optSession = sessions.getSessionWithId(id);
        if (optSession.isPresent() && SessionState.FINAL_STATES.contains(optSession.get().getState())) {
            return false;
        }
    } while (!(optSession.isPresent() && optSession.get().getState().equals(SessionState.idle)));
    return true;
}
Also used : SessionsGetResponse(com.thinkbiganalytics.kylo.spark.model.SessionsGetResponse) Session(com.thinkbiganalytics.kylo.spark.model.Session)

Example 3 with Session

use of com.thinkbiganalytics.kylo.spark.model.Session in project kylo by Teradata.

the class LivyHeartbeatMonitor method checkSession.

public Optional<SessionState> checkSession(SparkLivyProcess sparkLivyProcess) {
    // TODO: checkSession seems to get in a state where it is called multiple times per heartbeat
    logger.entry(sparkLivyProcess);
    SessionState sessionState = null;
    try {
        Session session = livyClient.getSession(restClient, sparkLivyProcess);
        sessionState = session.getState();
    } catch (ProcessingException pe) {
        logger.trace("Caught ProcessingException:", pe);
        if (!(pe.getCause() instanceof SocketTimeoutException || pe.getCause() instanceof SSLHandshakeException || pe.getCause() instanceof SocketException)) {
            throw logger.throwing(pe);
        }
    } catch (WebApplicationException wae) {
    // recording of state for wae's was taken care of by livyClient.getSession
    }
    return logger.exit(Optional.ofNullable(sessionState));
}
Also used : SessionState(com.thinkbiganalytics.kylo.spark.model.enums.SessionState) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) WebApplicationException(javax.ws.rs.WebApplicationException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Session(com.thinkbiganalytics.kylo.spark.model.Session) ProcessingException(javax.ws.rs.ProcessingException)

Example 4 with Session

use of com.thinkbiganalytics.kylo.spark.model.Session in project kylo by Teradata.

the class DefaultLivyClient method getSession.

@Override
public Session getSession(JerseyRestClient client, SparkLivyProcess sparkLivyProcess) {
    Integer sessionId = sparkLivyProcess.getSessionId();
    try {
        Session session = client.get(SESSION_URL(sessionId), Session.class);
        livyServer.setLivyServerStatus(LivyServerStatus.alive);
        livyServer.setLivySessionState(session.getId(), session.getState());
        logger.debug("session={}", session);
        return session;
    } catch (WebApplicationException wae) {
        // should catch 404, 500 etc.
        livyServer.recordSessionState(sessionId, wae.getResponse().getStatus(), null);
        throw wae;
    } catch (Exception e) {
        logger.error("Unexpected exception occurred:", e);
        throw e;
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) LivyException(com.thinkbiganalytics.kylo.spark.exceptions.LivyException) LivyUserException(com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException) LivyCodeException(com.thinkbiganalytics.kylo.spark.exceptions.LivyCodeException) WebApplicationException(javax.ws.rs.WebApplicationException) LivyInvalidSessionException(com.thinkbiganalytics.kylo.spark.exceptions.LivyInvalidSessionException) Session(com.thinkbiganalytics.kylo.spark.model.Session)

Example 5 with Session

use of com.thinkbiganalytics.kylo.spark.model.Session 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)

Aggregations

Session (com.thinkbiganalytics.kylo.spark.model.Session)8 LivyUserException (com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException)4 JerseyRestClient (com.thinkbiganalytics.rest.JerseyRestClient)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 LivyException (com.thinkbiganalytics.kylo.spark.exceptions.LivyException)3 LivyInvalidSessionException (com.thinkbiganalytics.kylo.spark.exceptions.LivyInvalidSessionException)2 LivyServerNotReachableException (com.thinkbiganalytics.kylo.spark.exceptions.LivyServerNotReachableException)2 SessionsGetResponse (com.thinkbiganalytics.kylo.spark.model.SessionsGetResponse)2 SocketTimeoutException (java.net.SocketTimeoutException)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 ProcessingException (javax.ws.rs.ProcessingException)2 DefaultLivyClient (com.thinkbiganalytics.kylo.spark.client.DefaultLivyClient)1 LivyClient (com.thinkbiganalytics.kylo.spark.client.LivyClient)1 LivyCodeException (com.thinkbiganalytics.kylo.spark.exceptions.LivyCodeException)1 SparkLivyProcess (com.thinkbiganalytics.kylo.spark.livy.SparkLivyProcess)1 SessionsPost (com.thinkbiganalytics.kylo.spark.model.SessionsPost)1 SessionState (com.thinkbiganalytics.kylo.spark.model.enums.SessionState)1 SocketException (java.net.SocketException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1