Search in sources :

Example 16 with JerseyRestClient

use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.

the class SparkLivyRestClient method transform.

@Nonnull
@Override
public TransformResponse transform(@Nonnull SparkShellProcess process, @Nonnull TransformRequest request) {
    logger.entry(process, request);
    JerseyRestClient client = sparkLivyProcessManager.getClient(process);
    // a tablename will be calculated for the request
    String transformId = ScalaScriptService.newTableName();
    transformCache.put(request, transformId);
    String script = scalaScriptService.wrapScriptForLivy(request, transformId);
    Statement statement = submitCode(client, script, process);
    // check the server for script result.  If polling limit reach just return to UI with PENDING status.
    statement = pollStatement(client, process, statement.getId(), livyProperties.getPollingLimit());
    sparkLivyProcessManager.setStatementId(transformId, statement.getId());
    return logger.exit(LivyRestModelTransformer.toTransformResponse(statement, transformId));
}
Also used : Statement(com.thinkbiganalytics.kylo.spark.model.Statement) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Nonnull(javax.annotation.Nonnull)

Example 17 with JerseyRestClient

use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.

the class SparkLivyRestClient method getDataSources.

@Nonnull
@Override
public DataSources getDataSources(@Nonnull SparkShellProcess process) {
    logger.entry(process);
    JerseyRestClient client = sparkLivyProcessManager.getClient(process);
    String script = scriptGenerator.script("getDataSources");
    Statement statement = submitCode(client, script, process);
    if (statement.getState() == StatementState.running || statement.getState() == StatementState.waiting) {
        statement = pollStatement(client, process, statement.getId());
    } else {
        throw logger.throwing(new LivyUserException("livy.unexpected_error"));
    }
    return logger.exit(LivyRestModelTransformer.toDataSources(statement));
}
Also used : Statement(com.thinkbiganalytics.kylo.spark.model.Statement) LivyUserException(com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Nonnull(javax.annotation.Nonnull)

Example 18 with JerseyRestClient

use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.

the class SparkLivyRestClient method saveTransform.

@Nonnull
@Override
public SaveResponse saveTransform(@Nonnull SparkShellProcess process, @Nonnull String transformId, @Nonnull SaveRequest request) {
    logger.entry(process, transformId, request);
    JerseyRestClient client = sparkLivyProcessManager.getClient(process);
    String script = scriptGenerator.wrappedScript("submitSaveJob", "", "\n", ScalaScriptUtils.toJsonInScalaString(request), transformId);
    Statement statement = submitCode(client, script, process);
    statement = pollStatement(client, process, statement.getId());
    SaveResponse saveResponse = LivyRestModelTransformer.toSaveResponse(statement);
    transformIdsToLivyId.put(transformId, statement.getId());
    return logger.exit(saveResponse);
}
Also used : SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) Statement(com.thinkbiganalytics.kylo.spark.model.Statement) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Nonnull(javax.annotation.Nonnull)

Example 19 with JerseyRestClient

use of com.thinkbiganalytics.rest.JerseyRestClient 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 20 with JerseyRestClient

use of com.thinkbiganalytics.rest.JerseyRestClient 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)

Aggregations

JerseyRestClient (com.thinkbiganalytics.rest.JerseyRestClient)23 Statement (com.thinkbiganalytics.kylo.spark.model.Statement)11 Nonnull (javax.annotation.Nonnull)10 LivyUserException (com.thinkbiganalytics.kylo.spark.exceptions.LivyUserException)7 JerseyClientConfig (com.thinkbiganalytics.rest.JerseyClientConfig)5 Session (com.thinkbiganalytics.kylo.spark.model.Session)4 SparkJobResponse (com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse)3 SaveResponse (com.thinkbiganalytics.spark.rest.model.SaveResponse)3 LivyServerNotReachableException (com.thinkbiganalytics.kylo.spark.exceptions.LivyServerNotReachableException)2 TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Invocation (javax.ws.rs.client.Invocation)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 SPRING_PROFILES_INCLUDE (com.thinkbiganalytics.install.inspector.inspection.Configuration.SPRING_PROFILES_INCLUDE)1