Search in sources :

Example 16 with ErrorModel

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;
}
Also used : ErrorModel(bio.terra.model.ErrorModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 17 with 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));
}
Also used : BulkLoadFileModel(bio.terra.model.BulkLoadFileModel) FileModel(bio.terra.model.FileModel) ArrayList(java.util.ArrayList) ErrorModel(bio.terra.model.ErrorModel) JobModel(bio.terra.model.JobModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with ErrorModel

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);
}
Also used : ErrorModel(bio.terra.model.ErrorModel) MvcResult(org.springframework.test.web.servlet.MvcResult) BillingProfileModel(bio.terra.model.BillingProfileModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 19 with ErrorModel

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"));
}
Also used : Blob(com.google.cloud.storage.Blob) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IngestRequestModel(bio.terra.model.IngestRequestModel) MvcResult(org.springframework.test.web.servlet.MvcResult) FileModel(bio.terra.model.FileModel) DrsId(bio.terra.service.filedata.DrsId) ErrorModel(bio.terra.model.ErrorModel) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) FieldValueList(com.google.cloud.bigquery.FieldValueList) List(java.util.List) DRSObject(bio.terra.model.DRSObject) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 20 with ErrorModel

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"));
}
Also used : BulkLoadFileModel(bio.terra.model.BulkLoadFileModel) FileModel(bio.terra.model.FileModel) ErrorModel(bio.terra.model.ErrorModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FileLoadModel(bio.terra.model.FileLoadModel) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ErrorModel (bio.terra.model.ErrorModel)48 Test (org.junit.Test)38 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)38 DatasetRequestModel (bio.terra.model.DatasetRequestModel)21 AssetTableModel (bio.terra.model.AssetTableModel)16 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)16 MvcResult (org.springframework.test.web.servlet.MvcResult)14 TableModel (bio.terra.model.TableModel)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 ColumnModel (bio.terra.model.ColumnModel)8 IntPartitionOptionsModel (bio.terra.model.IntPartitionOptionsModel)6 AssetModel (bio.terra.model.AssetModel)5 FileModel (bio.terra.model.FileModel)5 DatePartitionOptionsModel (bio.terra.model.DatePartitionOptionsModel)4 IngestRequestModel (bio.terra.model.IngestRequestModel)4 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)3 DeleteResponseModel (bio.terra.model.DeleteResponseModel)3 FileLoadModel (bio.terra.model.FileLoadModel)3 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)3 Blob (com.google.cloud.storage.Blob)3