use of org.sagebionetworks.bridge.exceptions.NotFoundException in project BridgeServer2 by Sage-Bionetworks.
the class UploadService method uploadComplete.
public void uploadComplete(String appId, UploadCompletionClient completedBy, Upload upload, boolean redrive) {
String uploadId = upload.getUploadId();
// We don't want to kick off upload validation on an upload that already has upload validation.
if (!upload.canBeValidated() && !redrive) {
logger.info(String.format("uploadComplete called for upload %s, which is already complete", uploadId));
return;
}
final String objectId = upload.getObjectId();
ObjectMetadata obj;
try {
Stopwatch stopwatch = Stopwatch.createStarted();
obj = s3Client.getObjectMetadata(uploadBucket, objectId);
logger.info("Finished getting S3 metadata for bucket " + uploadBucket + " key " + objectId + " in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
} catch (AmazonS3Exception ex) {
if (ex.getStatusCode() == 404) {
throw new NotFoundException(ex);
} else {
// Only S3 404s are mapped to 404s. Everything else is an internal server error.
throw new BridgeServiceException(ex);
}
}
String sse = obj.getSSEAlgorithm();
if (!AES_256_SERVER_SIDE_ENCRYPTION.equals(sse)) {
logger.error("Missing S3 server-side encryption (SSE) for presigned upload " + uploadId + ".");
}
try {
uploadDao.uploadComplete(completedBy, upload);
} catch (ConcurrentModificationException ex) {
// The old workflow is the app calls uploadComplete. The new workflow has an S3 trigger to call
// uploadComplete. During the transition, it's very likely that this will be called twice, sometimes
// concurrently. As such, we should log and squelch the ConcurrentModificationException.
logger.info("Concurrent modification of upload " + uploadId + " while marking upload complete");
// and duplicate records.
return;
}
// kick off upload validation
App app = appService.getApp(appId);
if (BridgeUtils.isExporter3Configured(app)) {
exporter3Service.completeUpload(app, upload);
}
// For backwards compatibility, always call Legacy Exporter 2.0. In the future, we may introduce a setting to
// disable this for new apps.
uploadValidationService.validateUpload(appId, upload);
}
use of org.sagebionetworks.bridge.exceptions.NotFoundException in project BridgeServer2 by Sage-Bionetworks.
the class HealthDataService method updateRecordsWithExporterStatus.
/**
* returns received list of record Ids after updating
* @param recordExportStatusRequest
* POJO contains: a lit of health record ids, not upload ids and
* an Synapse Exporter Status with value either NOT_EXPORTED or SUCCEEDED
* @return updated health record ids list
*/
public List<String> updateRecordsWithExporterStatus(RecordExportStatusRequest recordExportStatusRequest) {
Validate.entityThrowingException(exporterStatusValidator, recordExportStatusRequest);
List<String> healthRecordIds = recordExportStatusRequest.getRecordIds();
HealthDataRecord.ExporterStatus synapseExporterStatus = recordExportStatusRequest.getSynapseExporterStatus();
if (healthRecordIds.size() > MAX_NUM_RECORD_IDS) {
throw new BadRequestException("Size of the record ids list exceeds the limit.");
}
List<String> updatedRecordIds = healthRecordIds.stream().map(id -> {
HealthDataRecord record = getRecordById(id);
if (record == null) {
throw new NotFoundException("The record: " + id + " cannot be found in our database.");
}
record.setSynapseExporterStatus(synapseExporterStatus);
return createOrUpdateRecord(record);
}).collect(Collectors.toList());
return updatedRecordIds;
}
use of org.sagebionetworks.bridge.exceptions.NotFoundException in project BridgeServer2 by Sage-Bionetworks.
the class DynamoUploadDaoTest method getUploadNotFound.
@Test
public void getUploadNotFound() {
when(mockMapper.load(uploadCaptor.capture())).thenReturn(null);
// execute
Exception thrown = null;
try {
dao.getUpload("test-get-404");
fail();
} catch (NotFoundException ex) {
thrown = ex;
}
assertNotNull(thrown);
// validate we passed in the expected key
assertEquals(uploadCaptor.getValue().getUploadId(), "test-get-404");
}
use of org.sagebionetworks.bridge.exceptions.NotFoundException in project BridgeServer2 by Sage-Bionetworks.
the class UploadServiceUploadCompleteTest method notFoundInS3.
@Test
public void notFoundInS3() {
// set up input
DynamoUpload2 upload = new DynamoUpload2();
upload.setUploadId(TEST_UPLOAD_ID);
upload.setStatus(UploadStatus.REQUESTED);
// mock S3
AmazonS3Exception s3Ex = new AmazonS3Exception("not found");
s3Ex.setStatusCode(404);
when(mockS3Client.getObjectMetadata(TEST_BUCKET, TEST_UPLOAD_ID)).thenThrow(s3Ex);
// execute
try {
svc.uploadComplete(TEST_APP_ID, APP, upload, false);
fail("expected exception");
} catch (NotFoundException ex) {
// expected exception
}
// Verify upload DAO and validation aren't called.
verifyZeroInteractions(mockUploadDao, mockUploadValidationService);
}
use of org.sagebionetworks.bridge.exceptions.NotFoundException in project BridgeServer2 by Sage-Bionetworks.
the class UploadServiceUploadCompleteTest method s3InternalError.
@Test
public void s3InternalError() {
// set up input
DynamoUpload2 upload = new DynamoUpload2();
upload.setUploadId(TEST_UPLOAD_ID);
upload.setStatus(UploadStatus.REQUESTED);
// mock S3
AmazonS3Exception s3Ex = new AmazonS3Exception("internal server error");
s3Ex.setStatusCode(500);
when(mockS3Client.getObjectMetadata(TEST_BUCKET, TEST_UPLOAD_ID)).thenThrow(s3Ex);
// execute
try {
svc.uploadComplete(TEST_APP_ID, APP, upload, false);
fail("expected exception");
} catch (BridgeServiceException ex) {
// expected exception
assertFalse(ex instanceof NotFoundException);
}
// Verify upload DAO and validation aren't called.
verifyZeroInteractions(mockUploadDao, mockUploadValidationService);
}
Aggregations