use of com.thinkbiganalytics.rest.JerseyRestClient 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;
}
use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class JerseySparkShellRestClient method getClient.
/**
* Gets or creates a Jersey REST client for the specified Spark Shell process.
*
* @param process the Spark Shell process
* @return the Jersey REST client
*/
@Nonnull
private JerseyRestClient getClient(@Nonnull final SparkShellProcess process) {
return clients.computeIfAbsent(process, target -> {
final JerseyClientConfig config = new JerseyClientConfig();
config.setHost(target.getHostname());
config.setPort(target.getPort());
if (process instanceof SparkLauncherSparkShellProcess) {
config.setUsername(process.getClientId());
config.setPassword(((SparkLauncherSparkShellProcess) process).getClientSecret().toCharArray());
}
return new JerseyRestClient(config);
});
}
use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class TestLivyHeartbeatMonitor method livyHeartbeatMonitor.
public LivyHeartbeatMonitor livyHeartbeatMonitor() {
LivyClient mockLivyClient = Mockito.mock(LivyClient.class);
Session sessionNotStarted = new Session.Builder().id(1).state(SessionState.not_started).build();
Session sessionStarting = new Session.Builder().id(1).state(SessionState.starting).build();
Session sessionIdle = new Session.Builder().id(1).state(SessionState.idle).build();
Session sessioShuttingDown = new Session.Builder().id(1).state(SessionState.shutting_down).build();
final List<Session> answers = Lists.newArrayList(sessionNotStarted, sessionStarting, sessionIdle, sessioShuttingDown);
final AtomicInteger numResponse = new AtomicInteger(0);
JerseyRestClient client = Mockito.mock(JerseyRestClient.class);
Mockito.when(client.get(Mockito.anyString(), Mockito.eq(Session.class))).thenAnswer(new Answer<Session>() {
@Override
public Session answer(InvocationOnMock invocation) throws Throwable {
try {
if (numResponse.get() == 3 || numResponse.get() == 8) {
// third response and second to last response is session not_found
throw new WebApplicationException("Can't find session", 404);
}
// Now get from our list of Sessions with certain states
Session session = answers.remove(0);
logger.debug("Returning mock response for session with id='{}' and state='{}'", session.getId(), session.getState());
return session;
} catch (IndexOutOfBoundsException e) {
// used up our list of known responses, pretend the server doesn't know the session anymore
throw new WebApplicationException("Can't find session", 404);
}
}
});
Mockito.when(mockLivyClient.getSession(Mockito.any(), Mockito.any(SparkLivyProcess.class))).thenAnswer(invocation -> {
int responseNum = numResponse.addAndGet(1);
logger.debug("Number of responses return from mockLivyClient:: numResponse={}", responseNum);
if (responseNum == 1 || responseNum >= 9) {
// first response and last response is server not started
throw new ProcessingException(new SocketTimeoutException("Server not started"));
}
if (responseNum == 2) {
// second response is server not HTTPS
throw new ProcessingException(new SSLHandshakeException("Server is not HTTPS"));
}
return livyClient.getSession(client, (SparkLivyProcess) invocation.getArguments()[1]);
});
return new LivyHeartbeatMonitor(mockLivyClient, client, livyServer, livyProperties);
}
Aggregations