use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.
the class PingRequestSerDeTest method deserialize.
@Test
public void deserialize() throws IOException {
logger.info("deserialize: enter");
InputStream input = new ByteArrayInputStream(expectedSerDeText.getBytes());
PingRequest actual = (PingRequest) mapper.readValue(input, FederationRequest.class);
logger.info("deserialize: deserialized[{}]", actual);
assertEquals(expected, actual);
assertEquals(expected.getIdentity().getArn(), actual.getIdentity().getArn());
logger.info("deserialize: exit");
}
use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.
the class FederationServiceProvider method getService.
public static FederationService getService(String lambdaFunction, FederatedIdentity identity, String catalog) {
FederationService service = serviceCache.get(lambdaFunction);
if (service != null) {
return service;
}
service = LambdaInvokerFactory.builder().lambdaClient(AWSLambdaClientBuilder.defaultClient()).objectMapper(VersionedObjectMapperFactory.create(BLOCK_ALLOCATOR)).lambdaFunctionNameResolver(new Mapper(lambdaFunction)).build(FederationService.class);
PingRequest pingRequest = new PingRequest(identity, catalog, generateQueryId());
PingResponse pingResponse = (PingResponse) service.call(pingRequest);
int actualSerDeVersion = pingResponse.getSerDeVersion();
log.info("SerDe version for function {}, catalog {} is {}", lambdaFunction, catalog, actualSerDeVersion);
if (actualSerDeVersion != SERDE_VERSION) {
service = LambdaInvokerFactory.builder().lambdaClient(AWSLambdaClientBuilder.defaultClient()).objectMapper(VersionedObjectMapperFactory.create(BLOCK_ALLOCATOR, actualSerDeVersion)).lambdaFunctionNameResolver(new Mapper(lambdaFunction)).build(FederationService.class);
}
serviceCache.put(lambdaFunction, service);
return service;
}
use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.
the class CompositeHandler method handleRequest.
/**
* Handles routing the request to the appropriate Handler, either MetadataHandler or RecordHandler.
*
* @param allocator The BlockAllocator to use for Apache Arrow Resources.
* @param rawReq The request object itself.
* @param outputStream The OutputStream to which all responses should be written.
* @param objectMapper The ObjectMapper that can be used for serializing responses.
* @throws Exception
* @note that PingRequests are routed to the MetadataHandler even though both MetadataHandler and RecordHandler
* implemented PingRequest handling.
*/
public final void handleRequest(BlockAllocator allocator, FederationRequest rawReq, OutputStream outputStream, ObjectMapper objectMapper) throws Exception {
if (rawReq instanceof PingRequest) {
try (PingResponse response = metadataHandler.doPing((PingRequest) rawReq)) {
assertNotNull(response);
objectMapper.writeValue(outputStream, response);
}
return;
}
if (rawReq instanceof MetadataRequest) {
metadataHandler.doHandleRequest(allocator, objectMapper, (MetadataRequest) rawReq, outputStream);
} else if (rawReq instanceof RecordRequest) {
recordHandler.doHandleRequest(allocator, objectMapper, (RecordRequest) rawReq, outputStream);
} else if (udfhandler != null && rawReq instanceof UserDefinedFunctionRequest) {
udfhandler.doHandleRequest(allocator, objectMapper, (UserDefinedFunctionRequest) rawReq, outputStream);
} else {
throw new IllegalArgumentException("Unknown request class " + rawReq.getClass());
}
}
use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.
the class MetadataHandler method handleRequest.
public final void handleRequest(InputStream inputStream, OutputStream outputStream, final Context context) throws IOException {
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
ObjectMapper objectMapper = VersionedObjectMapperFactory.create(allocator);
try (FederationRequest rawReq = objectMapper.readValue(inputStream, FederationRequest.class)) {
if (rawReq instanceof PingRequest) {
try (PingResponse response = doPing((PingRequest) rawReq)) {
assertNotNull(response);
objectMapper.writeValue(outputStream, response);
}
return;
}
if (!(rawReq instanceof MetadataRequest)) {
throw new RuntimeException("Expected a MetadataRequest but found " + rawReq.getClass());
}
((MetadataRequest) rawReq).setContext(context);
doHandleRequest(allocator, objectMapper, (MetadataRequest) rawReq, outputStream);
} catch (Exception ex) {
logger.warn("handleRequest: Completed with an exception.", ex);
throw (ex instanceof RuntimeException) ? (RuntimeException) ex : new RuntimeException(ex);
}
}
}
use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.
the class RecordHandler method handleRequest.
public final void handleRequest(InputStream inputStream, OutputStream outputStream, final Context context) throws IOException {
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
ObjectMapper objectMapper = VersionedObjectMapperFactory.create(allocator);
try (FederationRequest rawReq = objectMapper.readValue(inputStream, FederationRequest.class)) {
if (rawReq instanceof PingRequest) {
try (PingResponse response = doPing((PingRequest) rawReq)) {
assertNotNull(response);
objectMapper.writeValue(outputStream, response);
}
return;
}
if (!(rawReq instanceof RecordRequest)) {
throw new RuntimeException("Expected a RecordRequest but found " + rawReq.getClass());
}
doHandleRequest(allocator, objectMapper, (RecordRequest) rawReq, outputStream);
} catch (Exception ex) {
logger.warn("handleRequest: Completed with an exception.", ex);
throw (ex instanceof RuntimeException) ? (RuntimeException) ex : new RuntimeException(ex);
}
}
}
Aggregations