use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class KyloRestLoginModuleTest method test.
/**
* Verify logging in by querying a REST API.
*/
@Test
public void test() throws Exception {
// Mock REST client
final User user = new User();
user.setEnabled(true);
user.setGroups(ImmutableSet.of("designers", "operators"));
user.setSystemName("dladmin");
final JerseyRestClient client = Mockito.mock(JerseyRestClient.class);
Mockito.when(client.get(any(Invocation.Builder.class), eq(User.class))).thenReturn(user);
// Mock callback handler
final CallbackHandler callbackHandler = callbacks -> Arrays.stream(callbacks).forEach(callback -> {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName("dladmin");
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword("thinkbig".toCharArray());
}
});
// Mock login module
final KyloRestLoginModule module = new KyloRestLoginModule() {
@Nonnull
@Override
JerseyRestClient getClient(@Nonnull LoginJerseyClientConfig config) {
return client;
}
};
// Test login
final Subject subject = new Subject();
Map<String, Object> options = new HashMap<>();
options.put(KyloRestLoginModule.REST_CLIENT_CONFIG, new LoginJerseyClientConfig());
options.put(KyloRestLoginModule.SERVICES_LOGOUT, false);
module.initialize(subject, callbackHandler, Collections.emptyMap(), options);
Assert.assertTrue(module.login());
Assert.assertTrue(module.commit());
// Verify subject
final Principal[] principals = subject.getPrincipals().toArray(new Principal[0]);
Assert.assertEquals(3, principals.length);
Arrays.sort(principals, Comparator.comparing(Principal::getName));
Assert.assertEquals("designers", principals[0].getName());
Assert.assertEquals("dladmin", principals[1].getName());
Assert.assertEquals("operators", principals[2].getName());
}
use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class TestSparkLivyRestClient method testGetLivySessions.
/**
* This test assumes: 1) you have configured a Livy Server for Kerberos and that it is running at 8998 2) that server has the library 'kylo-spark-shell-client-v1-0.10.0-SNAPSHOT.jar' installed
*/
@Test
// ignore, for now, because this is an integration test that requires livy configured on the test system
@Ignore
public void testGetLivySessions() throws JsonProcessingException, InterruptedException {
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("sun.security.jgss.debug", "true");
SessionsGet sg = new SessionsGet.Builder().from(1).size(2).build();
String sgJson = new ObjectMapper().writeValueAsString(sg);
logger.debug("{}", sgJson);
assertThat(sgJson).isEqualToIgnoringCase("{\"from\":1,\"size\":2}");
logger.debug("kerberosSparkProperties={}", kerberosSparkProperties);
SparkShellProcess sparkProcess = sparkLivyProcessManager.getProcessForUser("kylo");
// ((SparkLivyProcess) sparkProcess).setPort(8999);
JerseyRestClient client = sparkLivyProcessManager.getClient(sparkProcess);
sparkLivyProcessManager.start("kylo");
Integer stmtId = 0;
Statement statement = livyRestProvider.pollStatement(client, sparkProcess, stmtId);
logger.debug("statement={}", statement);
assertThat(statement.getState()).isEqualTo(StatementState.available);
assertThat(statement.getOutput().getStatus()).isEqualTo(StatementOutputStatus.ok);
}
use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class SparkLivyConfig method livyHeartbeatMonitor.
@Bean
public LivyHeartbeatMonitor livyHeartbeatMonitor() {
// LivyHeartbeatMonitor gets it's own jersey client
LivyProperties livyProperties = livyProperties();
final JerseyClientConfig config = new JerseyClientConfig();
config.setHost(livyProperties.getHostname());
config.setPort(livyProperties.getPort());
if (livyProperties().getTruststorePassword() != null) {
config.setHttps(true);
config.setTruststorePath(livyProperties.getTruststorePath());
config.setTruststorePassword(livyProperties.getTruststorePassword());
config.setTrustStoreType(livyProperties.getTruststoreType());
}
// end if
// all clients will have kerberos
LivyRestClient.setKerberosSparkProperties(kerberosSparkProperties());
JerseyRestClient livyRestClient = new LivyRestClient(config);
return new LivyHeartbeatMonitor(livyClient(), livyRestClient, livyServer(livyProperties()), livyProperties());
}
use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class SparkLivyRestClient method kyloCatalogTransform.
@Nonnull
public TransformResponse kyloCatalogTransform(@Nonnull final SparkShellProcess process, @Nonnull final KyloCatalogReadRequest request) {
logger.entry(process, request);
String script = scriptGenerator.wrappedScript("kyloCatalogTransform", "", "\n", ScalaScriptUtils.toJsonInScalaString(request));
logger.debug("scala str\n{}", script);
JerseyRestClient client = sparkLivyProcessManager.getClient(process);
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"));
}
// call with null so a transformId will be generated for this query
return logger.exit(LivyRestModelTransformer.toTransformResponse(statement, null));
}
use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class SparkLivyRestClient method getTransformSave.
@Nonnull
@Override
public Optional<SaveResponse> getTransformSave(@Nonnull SparkShellProcess process, @Nonnull String transformId, @Nonnull String saveId) {
logger.entry(process, transformId, saveId);
Validate.isInstanceOf(SparkLivyProcess.class, process, "SparkLivyRestClient.getTransformSave called on non Livy Process");
SparkLivyProcess sparkLivyProcess = (SparkLivyProcess) process;
JerseyRestClient client = sparkLivyProcessManager.getClient(process);
SaveResponse response;
Integer stmtId = transformIdsToLivyId.getIfPresent(transformId);
if (stmtId != null) {
Statement statement = livyClient.getStatement(client, sparkLivyProcess, stmtId);
response = LivyRestModelTransformer.toSaveResponse(statement);
if (statement.getState() == StatementState.available) {
transformIdsToLivyId.invalidate(transformId);
}
} else {
// saveId is not an integer. We have already processed Livy Response
String script = scriptGenerator.script("getSave", saveId);
Statement statement = submitCode(client, script, process);
response = LivyRestModelTransformer.toSaveResponse(statement);
response.setId(saveId);
// remember the true id. how? a cache.. it's not gonna get communicated back to us from UI..
transformIdsToLivyId.put(transformId, statement.getId());
}
return logger.exit(Optional.of(response));
}
Aggregations