@Test public void createTable() throws Exception { SQSEvent event = new SQSEvent(); SQSEvent.SQSMessage record = new SQSEvent.SQSMessage(); String message = createTableJson(); String payload = "\"Message\" : \"" + message.replace("\"", "\\\"") + "\""; record.setBody(getSnsMessage(payload)); event.setRecords(Lists.newArrayList(record)); Response response = privilegesGrantorLambda.handleRequest(event, context); verify(privilegesGrantor).grantSelectPrivileges("some_db", "some_table1"); assertThat(response.getStatusCode(), is(HttpStatus.SC_OK)); }
@Override public Response handleRequest(SQSEvent event, Context context) { logger = context.getLogger(); List<String> failedEvents = new ArrayList<>(); List<String> successfulTableNames = new ArrayList<>(); IMetaStoreClient metaStoreClient = null; try { ThriftHiveClient thriftHiveClient = thriftHiveClientFactory .newInstance(THRIFT_CONNECTION_URI, THRIFT_CONNECTION_TIMEOUT); metaStoreClient = thriftHiveClient.getMetaStoreClient(); PrivilegesGrantor privilegesGrantor = priviligesGrantorFactory.newInstance(metaStoreClient); MessageDeserializer metaStoreEventDeserializer = defaultMessageDeserializer(); for (SQSEvent.SQSMessage record : event.getRecords()) { handleRecord(failedEvents, successfulTableNames, privilegesGrantor, metaStoreEventDeserializer, record); } } catch (HiveClientException e) { String responseMessage = String .format("Unable to establish Thrift Connection with the uri %s", THRIFT_CONNECTION_URI); logger.log(responseMessage); failedEvents.add(responseMessage); return createResponse(successfulTableNames, failedEvents); } finally { if (metaStoreClient != null) { metaStoreClient.close(); } } return createResponse(successfulTableNames, failedEvents); }
PrivilegesGrantorLambda implements RequestHandler<SQSEvent, Response> { @Override public Response handleRequest(SQSEvent event, Context context) { logger = context.getLogger(); List<String> failedEvents = new ArrayList<>(); List<String> successfulTableNames = new ArrayList<>(); IMetaStoreClient metaStoreClient = null; try { ThriftHiveClient thriftHiveClient = thriftHiveClientFactory .newInstance(THRIFT_CONNECTION_URI, THRIFT_CONNECTION_TIMEOUT); metaStoreClient = thriftHiveClient.getMetaStoreClient(); PrivilegesGrantor privilegesGrantor = priviligesGrantorFactory.newInstance(metaStoreClient); MessageDeserializer metaStoreEventDeserializer = defaultMessageDeserializer(); for (SQSEvent.SQSMessage record : event.getRecords()) { handleRecord(failedEvents, successfulTableNames, privilegesGrantor, metaStoreEventDeserializer, record); } } catch (HiveClientException e) { String responseMessage = String .format("Unable to establish Thrift Connection with the uri %s", THRIFT_CONNECTION_URI); logger.log(responseMessage); failedEvents.add(responseMessage); return createResponse(successfulTableNames, failedEvents); } finally { if (metaStoreClient != null) { metaStoreClient.close(); } } return createResponse(successfulTableNames, failedEvents); } }
PrivilegesGrantorLambda implements RequestHandler<SQSEvent, Response> { @Override public Response handleRequest(SQSEvent event, Context context) { logger = context.getLogger(); List<String> failedEvents = new ArrayList<>(); List<String> successfulTableNames = new ArrayList<>(); IMetaStoreClient metaStoreClient = null; try { ThriftHiveClient thriftHiveClient = thriftHiveClientFactory .newInstance(THRIFT_CONNECTION_URI, THRIFT_CONNECTION_TIMEOUT); metaStoreClient = thriftHiveClient.getMetaStoreClient(); PrivilegesGrantor privilegesGrantor = priviligesGrantorFactory.newInstance(metaStoreClient); MessageDeserializer metaStoreEventDeserializer = defaultMessageDeserializer(); for (SQSEvent.SQSMessage record : event.getRecords()) { handleRecord(failedEvents, successfulTableNames, privilegesGrantor, metaStoreEventDeserializer, record); } } catch (HiveClientException e) { String responseMessage = String .format("Unable to establish Thrift Connection with the uri %s", THRIFT_CONNECTION_URI); logger.log(responseMessage); failedEvents.add(responseMessage); return createResponse(successfulTableNames, failedEvents); } finally { if (metaStoreClient != null) { metaStoreClient.close(); } } return createResponse(successfulTableNames, failedEvents); } PrivilegesGrantorLambda(); @VisibleForTesting  PrivilegesGrantorLambda(
      PriviligesGrantorFactory priviligesGrantorFactory,
      ThriftHiveClientFactory thriftHiveClientFactory); }
PrivilegesGrantorLambda implements RequestHandler<SQSEvent, Response> { @Override public Response handleRequest(SQSEvent event, Context context) { logger = context.getLogger(); List<String> failedEvents = new ArrayList<>(); List<String> successfulTableNames = new ArrayList<>(); IMetaStoreClient metaStoreClient = null; try { ThriftHiveClient thriftHiveClient = thriftHiveClientFactory .newInstance(THRIFT_CONNECTION_URI, THRIFT_CONNECTION_TIMEOUT); metaStoreClient = thriftHiveClient.getMetaStoreClient(); PrivilegesGrantor privilegesGrantor = priviligesGrantorFactory.newInstance(metaStoreClient); MessageDeserializer metaStoreEventDeserializer = defaultMessageDeserializer(); for (SQSEvent.SQSMessage record : event.getRecords()) { handleRecord(failedEvents, successfulTableNames, privilegesGrantor, metaStoreEventDeserializer, record); } } catch (HiveClientException e) { String responseMessage = String .format("Unable to establish Thrift Connection with the uri %s", THRIFT_CONNECTION_URI); logger.log(responseMessage); failedEvents.add(responseMessage); return createResponse(successfulTableNames, failedEvents); } finally { if (metaStoreClient != null) { metaStoreClient.close(); } } return createResponse(successfulTableNames, failedEvents); } PrivilegesGrantorLambda(); @VisibleForTesting  PrivilegesGrantorLambda(
      PriviligesGrantorFactory priviligesGrantorFactory,
      ThriftHiveClientFactory thriftHiveClientFactory); @Override Response handleRequest(SQSEvent event, Context context); }
PrivilegesGrantorLambda implements RequestHandler<SQSEvent, Response> { @Override public Response handleRequest(SQSEvent event, Context context) { logger = context.getLogger(); List<String> failedEvents = new ArrayList<>(); List<String> successfulTableNames = new ArrayList<>(); IMetaStoreClient metaStoreClient = null; try { ThriftHiveClient thriftHiveClient = thriftHiveClientFactory .newInstance(THRIFT_CONNECTION_URI, THRIFT_CONNECTION_TIMEOUT); metaStoreClient = thriftHiveClient.getMetaStoreClient(); PrivilegesGrantor privilegesGrantor = priviligesGrantorFactory.newInstance(metaStoreClient); MessageDeserializer metaStoreEventDeserializer = defaultMessageDeserializer(); for (SQSEvent.SQSMessage record : event.getRecords()) { handleRecord(failedEvents, successfulTableNames, privilegesGrantor, metaStoreEventDeserializer, record); } } catch (HiveClientException e) { String responseMessage = String .format("Unable to establish Thrift Connection with the uri %s", THRIFT_CONNECTION_URI); logger.log(responseMessage); failedEvents.add(responseMessage); return createResponse(successfulTableNames, failedEvents); } finally { if (metaStoreClient != null) { metaStoreClient.close(); } } return createResponse(successfulTableNames, failedEvents); } PrivilegesGrantorLambda(); @VisibleForTesting  PrivilegesGrantorLambda(
      PriviligesGrantorFactory priviligesGrantorFactory,
      ThriftHiveClientFactory thriftHiveClientFactory); @Override Response handleRequest(SQSEvent event, Context context);  }