use of com.amazonaws.athena.connector.lambda.request.FederationRequest in project aws-athena-query-federation by awslabs.
the class ObjectMapperUtil method assertBaseSerialization.
private static <T> void assertBaseSerialization(Object object) {
Class<?> clazz = object.getClass();
if (object instanceof FederationRequest)
clazz = FederationRequest.class;
else if (object instanceof FederationResponse) {
clazz = FederationResponse.class;
}
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
// check SerDe write, SerDe read
ByteArrayOutputStream serDeOut = new ByteArrayOutputStream();
ObjectMapper serDe = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
serDe.writeValue(serDeOut, object);
byte[] serDeOutput = serDeOut.toByteArray();
assertEquals(object, serDe.readValue(new ByteArrayInputStream(serDeOutput), clazz));
} catch (IOException | AssertionError ex) {
throw new RuntimeException(ex);
}
}
use of com.amazonaws.athena.connector.lambda.request.FederationRequest in project aws-athena-query-federation by awslabs.
the class ObjectMapperUtil method assertSerializationBackwardsCompatibleV3toV2.
private static <T> void assertSerializationBackwardsCompatibleV3toV2(Object object) {
Class<?> clazz = object.getClass();
if (object instanceof FederationRequest)
clazz = FederationRequest.class;
else if (object instanceof FederationResponse) {
clazz = FederationResponse.class;
}
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
// check SerDe write, SerDe read
ByteArrayOutputStream serDeOut = new ByteArrayOutputStream();
ObjectMapper serDeV3 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_THREE);
ObjectMapper serDeV2 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
serDeV3.writeValue(serDeOut, object);
byte[] serDeOutput = serDeOut.toByteArray();
assertEquals(object, serDeV2.readValue(new ByteArrayInputStream(serDeOutput), clazz));
} catch (IOException | AssertionError ex) {
throw new RuntimeException(ex);
}
}
use of com.amazonaws.athena.connector.lambda.request.FederationRequest in project aws-athena-query-federation by awslabs.
the class ObjectMapperUtil method assertSerializationForwardsCompatibleV2toV3.
private static <T> void assertSerializationForwardsCompatibleV2toV3(Object object) {
Class<?> clazz = object.getClass();
if (object instanceof FederationRequest)
clazz = FederationRequest.class;
else if (object instanceof FederationResponse) {
clazz = FederationResponse.class;
}
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
// check SerDe write, SerDe read
ByteArrayOutputStream serDeOut = new ByteArrayOutputStream();
ObjectMapper serDeV3 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_THREE);
ObjectMapper serDeV2 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
serDeV2.writeValue(serDeOut, object);
byte[] serDeOutput = serDeOut.toByteArray();
assertEquals(object, serDeV3.readValue(new ByteArrayInputStream(serDeOutput), clazz));
} catch (IOException | AssertionError ex) {
throw new RuntimeException(ex);
}
}
use of com.amazonaws.athena.connector.lambda.request.FederationRequest 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.FederationRequest 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