Search in sources :

Example 1 with BigQueryScannerImpl

use of com.google.cloud.pso.bq_pii_classifier.services.scan.BigQueryScannerImpl in project bq-pii-classifier by GoogleCloudPlatform.

the class InspectionDispatcherController method receiveMessage.

@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity receiveMessage(@RequestBody PubSubEvent requestBody) {
    String runId = TrackingHelper.generateInspectionRunId();
    String state = "";
    try {
        if (requestBody == null || requestBody.getMessage() == null) {
            String msg = "Bad Request: invalid message format";
            logger.logSevereWithTracker(runId, msg);
            throw new NonRetryableApplicationException("Request body or message is Null.");
        }
        String requestJsonString = requestBody.getMessage().dataToUtf8String();
        // remove any escape characters (e.g. from Terraform
        requestJsonString = requestJsonString.replace("\\", "");
        logger.logInfoWithTracker(runId, String.format("Received payload: %s", requestJsonString));
        BigQueryScope bqScope = gson.fromJson(requestJsonString, BigQueryScope.class);
        logger.logInfoWithTracker(runId, String.format("Parsed JSON input %s ", bqScope.toString()));
        Dispatcher dispatcher = new Dispatcher(environment.toConfig(), new BigQueryServiceImpl(), new PubSubServiceImpl(), new BigQueryScannerImpl(), new GCSPersistentSetImpl(environment.getGcsFlagsBucket()), "inspection-dispatcher-flags", runId);
        PubSubPublishResults results = dispatcher.execute(bqScope, requestBody.getMessage().getMessageId());
        state = String.format("Publishing results: %s SUCCESS MESSAGES and %s FAILED MESSAGES", results.getSuccessMessages().size(), results.getFailedMessages().size());
        logger.logInfoWithTracker(runId, state);
    } catch (Exception e) {
        logger.logNonRetryableExceptions(runId, e);
        state = String.format("ERROR '%s'", e.getMessage());
    }
    return new ResponseEntity(String.format("Process completed with state = %s", state), HttpStatus.OK);
}
Also used : BigQueryScannerImpl(com.google.cloud.pso.bq_pii_classifier.services.scan.BigQueryScannerImpl) ResponseEntity(org.springframework.http.ResponseEntity) BigQueryServiceImpl(com.google.cloud.pso.bq_pii_classifier.services.bq.BigQueryServiceImpl) PubSubPublishResults(com.google.cloud.pso.bq_pii_classifier.services.pubsub.PubSubPublishResults) NonRetryableApplicationException(com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException) Dispatcher(com.google.cloud.pso.bq_pii_classifier.functions.dispatcher.Dispatcher) GCSPersistentSetImpl(com.google.cloud.pso.bq_pii_classifier.services.set.GCSPersistentSetImpl) NonRetryableApplicationException(com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException) BigQueryScope(com.google.cloud.pso.bq_pii_classifier.functions.dispatcher.BigQueryScope) PubSubServiceImpl(com.google.cloud.pso.bq_pii_classifier.services.pubsub.PubSubServiceImpl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NonRetryableApplicationException (com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException)1 BigQueryScope (com.google.cloud.pso.bq_pii_classifier.functions.dispatcher.BigQueryScope)1 Dispatcher (com.google.cloud.pso.bq_pii_classifier.functions.dispatcher.Dispatcher)1 BigQueryServiceImpl (com.google.cloud.pso.bq_pii_classifier.services.bq.BigQueryServiceImpl)1 PubSubPublishResults (com.google.cloud.pso.bq_pii_classifier.services.pubsub.PubSubPublishResults)1 PubSubServiceImpl (com.google.cloud.pso.bq_pii_classifier.services.pubsub.PubSubServiceImpl)1 BigQueryScannerImpl (com.google.cloud.pso.bq_pii_classifier.services.scan.BigQueryScannerImpl)1 GCSPersistentSetImpl (com.google.cloud.pso.bq_pii_classifier.services.set.GCSPersistentSetImpl)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1