use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class AssetModelValidationTest method expectBadAssetModel.
private ErrorModel expectBadAssetModel(AssetModel asset) throws Exception {
MvcResult result = mvc.perform(post("/api/repository/v1/datasets/assets").contentType(MediaType.APPLICATION_JSON).content(TestUtils.mapToJson(asset))).andExpect(status().is4xxClientError()).andReturn();
MockHttpServletResponse response = result.getResponse();
String responseBody = response.getContentAsString();
assertTrue("Error model was returned on failure", StringUtils.contains(responseBody, "message"));
ErrorModel errorModel = TestUtils.mapFromJson(responseBody, ErrorModel.class);
return errorModel;
}
use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class FileTest method fileParallelFailedLoadTest.
// DR-612 filesystem corruption test; use a non-existent file to make sure everything errors
// Do file ingests in parallel using a filename that will cause failure
@Test
public void fileParallelFailedLoadTest() throws Exception {
List<DataRepoResponse<JobModel>> responseList = new ArrayList<>();
String gsPath = "gs://" + testConfiguration.getIngestbucket() + "/nonexistentfile";
String filePath = "/foo" + UUID.randomUUID().toString() + "/bar";
for (int i = 0; i < 20; i++) {
DataRepoResponse<JobModel> launchResp = dataRepoFixtures.ingestFileLaunch(steward(), datasetId, profileId, gsPath, filePath + i);
responseList.add(launchResp);
}
int failureCount = 0;
for (DataRepoResponse<JobModel> resp : responseList) {
DataRepoResponse<FileModel> response = dataRepoClient.waitForResponse(steward(), resp, FileModel.class);
if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
System.out.println("Got expected not found");
} else {
System.out.println("Unexpected: " + response.getStatusCode().toString());
if (response.getErrorObject().isPresent()) {
ErrorModel errorModel = response.getErrorObject().get();
System.out.println("Error: " + errorModel.getMessage());
}
failureCount++;
}
}
assertThat("No unexpected failures", failureCount, equalTo(0));
}
use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class ConnectedOperations method createProfile.
public BillingProfileModel createProfile(BillingProfileRequestModel profileRequestModel) throws Exception {
MvcResult result = mvc.perform(post("/api/resources/v1/profiles").contentType(MediaType.APPLICATION_JSON).content(TestUtils.mapToJson(profileRequestModel))).andReturn();
MockHttpServletResponse response = result.getResponse();
String responseContent = response.getContentAsString();
if (response.getStatus() == HttpStatus.CREATED.value()) {
BillingProfileModel billingProfileModel = TestUtils.mapFromJson(responseContent, BillingProfileModel.class);
addProfile(billingProfileModel.getId());
return billingProfileModel;
}
ErrorModel errorModel = TestUtils.mapFromJson(responseContent, ErrorModel.class);
List<String> errorDetail = errorModel.getErrorDetail();
String message = String.format("couldn't create profile: %s (%s)", errorModel.getMessage(), String.join(", ", errorDetail));
throw new IllegalArgumentException(message);
}
use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class EncodeFileTest method encodeFileTest.
// NOTES ABOUT THIS TEST: this test requires create access to the jade-testdata bucket in order to
// re-write the json source data replacing the gs paths with the Jade object id.
@Test
public void encodeFileTest() throws Exception {
DatasetSummaryModel datasetSummary = connectedOperations.createDataset(profileModel, "encodefiletest-dataset.json");
// Load all of the files into the dataset
String targetPath = loadFiles(datasetSummary.getId(), false, false);
String gsPath = "gs://" + testConfig.getIngestbucket() + "/" + targetPath;
IngestRequestModel ingestRequest = new IngestRequestModel().format(IngestRequestModel.FormatEnum.JSON).table("file").path(gsPath);
connectedOperations.ingestTableSuccess(datasetSummary.getId(), ingestRequest);
// Delete the scratch blob
Blob scratchBlob = storage.get(BlobId.of(testConfig.getIngestbucket(), targetPath));
if (scratchBlob != null) {
scratchBlob.delete();
}
// Load donor success
ingestRequest.table("donor").path("gs://" + testConfig.getIngestbucket() + "/encodetest/donor.json");
connectedOperations.ingestTableSuccess(datasetSummary.getId(), ingestRequest);
// At this point, we have files and tabular data. Let's make a snapshot!
SnapshotSummaryModel snapshotSummary = connectedOperations.createSnapshot(datasetSummary, "encodefiletest-snapshot.json", "");
String fileUri = getFileRefIdFromSnapshot(snapshotSummary);
DrsId drsId = drsIdService.fromUri(fileUri);
DRSObject drsObject = connectedOperations.drsGetObjectSuccess(drsId.toDrsObjectId(), false);
String filePath = drsObject.getAliases().get(0);
FileModel fsObjById = connectedOperations.lookupSnapshotFileSuccess(snapshotSummary.getId(), drsId.getFsObjectId());
FileModel fsObjByPath = connectedOperations.lookupSnapshotFileByPathSuccess(snapshotSummary.getId(), filePath, 0);
assertThat("Retrieve snapshot file objects match", fsObjById, equalTo(fsObjByPath));
assertThat("Load tag is stored", fsObjById.getFileDetail().getLoadTag(), equalTo(loadTag));
// Build the reference directory name map
String datasetPath = "/" + datasetSummary.getName();
Map<String, List<String>> dirmap = makeDirectoryMap(datasetPath);
testSnapEnum(dirmap, snapshotSummary.getId(), datasetPath, -1);
testSnapEnum(dirmap, snapshotSummary.getId(), datasetPath, 0);
testSnapEnum(dirmap, snapshotSummary.getId(), datasetPath, 6);
testSnapEnum(dirmap, snapshotSummary.getId(), datasetPath, 3);
// Try to delete a file with a dependency
MvcResult result = mvc.perform(delete("/api/repository/v1/datasets/" + datasetSummary.getId() + "/files/" + drsId.getFsObjectId())).andReturn();
MockHttpServletResponse response = connectedOperations.validateJobModelAndWait(result);
assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST.value()));
ErrorModel errorModel = connectedOperations.handleFailureCase(response);
assertThat("correct dependency error message", errorModel.getMessage(), containsString("used by at least one snapshot"));
}
use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class FileOperationTest method fileOperationsTest.
@Test
public void fileOperationsTest() throws Exception {
FileLoadModel fileLoadModel = makeFileLoad(profileModel.getId());
FileModel fileModel = connectedOperations.ingestFileSuccess(datasetSummary.getId(), fileLoadModel);
assertThat("file path matches", fileModel.getPath(), equalTo(fileLoadModel.getTargetPath()));
// Change the data location selector, verify that we can still delete the file
String newBucketName = "bucket-" + UUID.randomUUID().toString();
doReturn(newBucketName).when(dataLocationSelector).bucketForFile(any());
connectedOperations.deleteTestFile(datasetSummary.getId(), fileModel.getFileId());
fileModel = connectedOperations.ingestFileSuccess(datasetSummary.getId(), fileLoadModel);
assertThat("file path reflects new bucket location", fileModel.getFileDetail().getAccessUrl(), containsString(newBucketName));
// Track the bucket so connected ops can remove it on teardown
connectedOperations.addBucket(newBucketName);
// lookup the file we just created
String url = "/api/repository/v1/datasets/" + datasetSummary.getId() + "/files/" + fileModel.getFileId();
MvcResult result = mvc.perform(get(url)).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andReturn();
MockHttpServletResponse response = result.getResponse();
assertThat("Lookup file succeeds", HttpStatus.valueOf(response.getStatus()), equalTo(HttpStatus.OK));
FileModel lookupModel = TestUtils.mapFromJson(response.getContentAsString(), FileModel.class);
assertTrue("Ingest file equals lookup file", lookupModel.equals(fileModel));
// Error: Duplicate target file
ErrorModel errorModel = connectedOperations.ingestFileFailure(datasetSummary.getId(), fileLoadModel);
assertThat("duplicate file error", errorModel.getMessage(), containsString("already exists"));
// Lookup the file by path
url = "/api/repository/v1/datasets/" + datasetSummary.getId() + "/filesystem/objects";
result = mvc.perform(get(url).param("path", fileModel.getPath())).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andReturn();
response = result.getResponse();
assertThat("Lookup file by path succeeds", HttpStatus.valueOf(response.getStatus()), equalTo(HttpStatus.OK));
lookupModel = TestUtils.mapFromJson(response.getContentAsString(), FileModel.class);
assertTrue("Ingest file equals lookup file", lookupModel.equals(fileModel));
// Delete the file and we should be able to create it successfully again
connectedOperations.deleteTestFile(datasetSummary.getId(), fileModel.getFileId());
fileModel = connectedOperations.ingestFileSuccess(datasetSummary.getId(), fileLoadModel);
assertThat("file path matches", fileModel.getPath(), equalTo(fileLoadModel.getTargetPath()));
// Error: Non-existent source file
String badfile = "/I am not a file";
String uribadfile = "gs://" + testConfig.getIngestbucket() + "/" + badfile;
String badPath = "/dd/files/" + Names.randomizeName("dir") + badfile;
fileLoadModel = new FileLoadModel().profileId(profileModel.getId()).sourcePath(uribadfile).description(testDescription).mimeType(testMimeType).targetPath(badPath);
errorModel = connectedOperations.ingestFileFailure(datasetSummary.getId(), fileLoadModel);
assertThat("source file does not exist", errorModel.getMessage(), containsString("file not found"));
// Error: Invalid gs path - case 1: not gs
fileLoadModel = new FileLoadModel().profileId(profileModel.getId()).sourcePath("http://jade_notabucket/foo/bar.txt").description(testDescription).mimeType(testMimeType).targetPath(makeValidUniqueFilePath());
errorModel = connectedOperations.ingestFileFailure(datasetSummary.getId(), fileLoadModel);
assertThat("Not a gs schema", errorModel.getMessage(), containsString("not a gs"));
// Error: Invalid gs path - case 2: invalid bucket name
fileLoadModel = new FileLoadModel().profileId(profileModel.getId()).sourcePath("gs://jade_notabucket:1234/foo/bar.txt").description(testDescription).mimeType(testMimeType).targetPath(makeValidUniqueFilePath());
errorModel = connectedOperations.ingestFileFailure(datasetSummary.getId(), fileLoadModel);
assertThat("Invalid bucket name", errorModel.getMessage(), containsString("Invalid bucket name"));
// Error: Invalid gs path - case 3: no bucket or path
fileLoadModel = new FileLoadModel().profileId(profileModel.getId()).sourcePath("gs:///").description(testDescription).mimeType(testMimeType).targetPath(makeValidUniqueFilePath());
errorModel = connectedOperations.ingestFileFailure(datasetSummary.getId(), fileLoadModel);
assertThat("No bucket or path", errorModel.getMessage(), containsString("gs path"));
}
Aggregations