in services/configurator-app/src/main/java/com/google/cloud/pso/bq_snapshot_manager/configurator/ConfiguratorController.java [99:186]
public ResponseEntity receiveMessage(@RequestBody PubSubEvent requestBody) {
BackupPolicyService backupPolicyService = null;
// These values will be updated based on the execution flow and logged at the end
ResponseEntity responseEntity;
ConfiguratorRequest configuratorRequest = null;
ConfiguratorResponse configuratorResponse = null;
boolean isSuccess;
Exception error = null;
boolean isRetryableError= false;
try {
if (requestBody == null || requestBody.getMessage() == null) {
String msg = "Bad Request: invalid message format";
logger.logSevereWithTracker(trackingId,null, 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(trackingId, null, String.format("Received payload: %s", requestJsonString));
configuratorRequest = gson.fromJson(requestJsonString, ConfiguratorRequest.class);
trackingId = configuratorRequest.getTrackingId();
logger.logInfoWithTracker(configuratorRequest.isDryRun(), trackingId, configuratorRequest.getTargetTable(), String.format("Parsed Request: %s", configuratorRequest.toString()));
backupPolicyService = new BackupPolicyServiceGCSImpl(environment.getGcsBackupPoliciesBucket());
Configurator configurator = new Configurator(
environment.toConfig(),
new BigQueryServiceImpl(configuratorRequest.getTargetTable().getProject()),
backupPolicyService,
new PubSubServiceImpl(),
new ResourceScannerImpl(),
new GCSPersistentSetImpl(environment.getGcsFlagsBucket()),
fallbackBackupPolicy,
"configurator-flags",
functionNumber
);
configuratorResponse = configurator.execute(configuratorRequest, requestBody.getMessage().getMessageId());
responseEntity = new ResponseEntity("Process completed successfully.", HttpStatus.OK);
isSuccess = true;
} catch (Exception e) {
Tuple<ResponseEntity, Boolean> handlingResults = ControllerExceptionHelper.handleException(
e,
logger,
trackingId,
configuratorRequest == null? null : configuratorRequest.getTargetTable()
);
isSuccess = false;
responseEntity = handlingResults.x();
isRetryableError = handlingResults.y();
error = e;
} finally {
if (backupPolicyService != null) {
backupPolicyService.shutdown();
}
}
logger.logUnified(
configuratorRequest == null? null: configuratorRequest.isDryRun(),
functionNumber.toString(),
configuratorRequest == null? null: configuratorRequest.getRunId(),
configuratorRequest == null? null: configuratorRequest.getTrackingId(),
configuratorRequest == null? null : configuratorRequest.getTargetTable(),
configuratorRequest,
configuratorResponse,
isSuccess,
error,
isRetryableError
);
return responseEntity;
}