Search in sources :

Example 1 with DatasetSummaryModel

use of bio.terra.model.DatasetSummaryModel in project jade-data-repo by DataBiosphere.

the class CreateDatasetMetadataStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    try {
        Dataset newDataset = DatasetUtils.convertRequestWithGeneratedNames(datasetRequest);
        UUID datasetId = datasetDao.createAndLock(newDataset, context.getFlightId());
        FlightMap workingMap = context.getWorkingMap();
        workingMap.put(DatasetWorkingMapKeys.DATASET_ID, datasetId);
        DatasetSummaryModel datasetSummary = DatasetJsonConversion.datasetSummaryModelFromDatasetSummary(newDataset.getDatasetSummary());
        workingMap.put(JobMapKeys.RESPONSE.getKeyName(), datasetSummary);
        return StepResult.getStepResultSuccess();
    } catch (InvalidDatasetException idEx) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, idEx);
    } catch (Exception ex) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new InvalidDatasetException("Cannot create dataset: " + datasetRequest.getName(), ex));
    }
}
Also used : Dataset(bio.terra.service.dataset.Dataset) InvalidDatasetException(bio.terra.service.dataset.exception.InvalidDatasetException) FlightMap(bio.terra.stairway.FlightMap) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult) InvalidDatasetException(bio.terra.service.dataset.exception.InvalidDatasetException)

Example 2 with DatasetSummaryModel

use of bio.terra.model.DatasetSummaryModel in project jade-data-repo by DataBiosphere.

the class SnapshotService method makeSourceModelFromSource.

private SnapshotSourceModel makeSourceModelFromSource(SnapshotSource source) {
    // TODO: when source summary methods are available, use those. Here I roll my own
    Dataset dataset = source.getDataset();
    DatasetSummaryModel summaryModel = new DatasetSummaryModel().id(dataset.getId().toString()).name(dataset.getName()).description(dataset.getDescription()).defaultProfileId(dataset.getDefaultProfileId().toString()).createdDate(dataset.getCreatedDate().toString());
    SnapshotSourceModel sourceModel = new SnapshotSourceModel().dataset(summaryModel);
    AssetSpecification assetSpec = source.getAssetSpecification();
    if (assetSpec != null) {
        sourceModel.asset(assetSpec.getName());
    }
    return sourceModel;
}
Also used : Dataset(bio.terra.service.dataset.Dataset) SnapshotSourceModel(bio.terra.model.SnapshotSourceModel) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) AssetSpecification(bio.terra.service.dataset.AssetSpecification)

Example 3 with DatasetSummaryModel

use of bio.terra.model.DatasetSummaryModel in project jade-data-repo by DataBiosphere.

the class DatasetConnectedTest method testExcludeLockedFromDatasetLookups.

@Test
public void testExcludeLockedFromDatasetLookups() throws Exception {
    // check that the dataset metadata row is unlocked
    UUID datasetId = UUID.fromString(summaryModel.getId());
    String exclusiveLock = datasetDao.getExclusiveLock(datasetId);
    assertNull("dataset row is not exclusively locked", exclusiveLock);
    String[] sharedLocks = datasetDao.getSharedLocks(datasetId);
    assertEquals("dataset row has no shared lock", 0, sharedLocks.length);
    // retrieve the dataset and check that it finds it
    DatasetModel datasetModel = connectedOperations.getDataset(summaryModel.getId());
    assertEquals("Lookup unlocked dataset succeeds", summaryModel.getName(), datasetModel.getName());
    // enumerate datasets and check that this dataset is included in the set
    EnumerateDatasetModel enumerateDatasetModel = connectedOperations.enumerateDatasets(summaryModel.getName());
    List<DatasetSummaryModel> enumeratedDatasets = enumerateDatasetModel.getItems();
    boolean foundDatasetWithMatchingId = false;
    for (DatasetSummaryModel enumeratedDataset : enumeratedDatasets) {
        if (enumeratedDataset.getId().equals(summaryModel.getId())) {
            foundDatasetWithMatchingId = true;
            break;
        }
    }
    assertTrue("Unlocked included in enumeration", foundDatasetWithMatchingId);
    // NO ASSERTS inside the block below where hang is enabled to reduce chance of failing before disabling the hang
    // ====================================================
    // enable hang in DeleteDatasetPrimaryDataStep
    configService.setFault(ConfigEnum.DATASET_DELETE_LOCK_CONFLICT_STOP_FAULT.name(), true);
    // kick off a request to delete the dataset. this should hang before unlocking the dataset object.
    MvcResult deleteResult = mvc.perform(delete("/api/repository/v1/datasets/" + summaryModel.getId())).andReturn();
    // give the flight time to launch
    TimeUnit.SECONDS.sleep(5);
    // check that the dataset metadata row has an exclusive lock
    // note: asserts are below outside the hang block
    exclusiveLock = datasetDao.getExclusiveLock(datasetId);
    sharedLocks = datasetDao.getSharedLocks(datasetId);
    // retrieve the dataset, should return not found
    // note: asserts are below outside the hang block
    MvcResult retrieveResult = mvc.perform(get("/api/repository/v1/datasets/" + datasetId)).andReturn();
    // enumerate datasets, this dataset should not be included in the set
    // note: asserts are below outside the hang block
    MvcResult enumerateResult = connectedOperations.enumerateDatasetsRaw(summaryModel.getName());
    // disable hang in DeleteDatasetPrimaryDataStep
    configService.setFault(ConfigEnum.DATASET_DELETE_LOCK_CONFLICT_CONTINUE_FAULT.name(), true);
    // ====================================================
    // check that the dataset metadata row has an exclusive lock after kicking off the delete
    assertNotNull("dataset row is exclusively locked", exclusiveLock);
    assertEquals("dataset row has no shared lock", 0, sharedLocks.length);
    // check that the retrieve request returned not found
    connectedOperations.handleFailureCase(retrieveResult.getResponse(), HttpStatus.NOT_FOUND);
    // check that the enumerate request returned successfully and that this dataset is not included in the set
    enumerateDatasetModel = connectedOperations.handleSuccessCase(enumerateResult.getResponse(), EnumerateDatasetModel.class);
    enumeratedDatasets = enumerateDatasetModel.getItems();
    foundDatasetWithMatchingId = false;
    for (DatasetSummaryModel enumeratedDataset : enumeratedDatasets) {
        if (enumeratedDataset.getId().equals(summaryModel.getId())) {
            foundDatasetWithMatchingId = true;
            break;
        }
    }
    assertFalse("Exclusively locked not included in enumeration", foundDatasetWithMatchingId);
    // check the response from the delete request
    MockHttpServletResponse deleteResponse = connectedOperations.validateJobModelAndWait(deleteResult);
    DeleteResponseModel deleteResponseModel = connectedOperations.handleSuccessCase(deleteResponse, DeleteResponseModel.class);
    assertEquals("Dataset delete returned successfully", DeleteResponseModel.ObjectStateEnum.DELETED, deleteResponseModel.getObjectState());
    // try to fetch the dataset again and confirm nothing is returned
    connectedOperations.getDatasetExpectError(summaryModel.getId(), HttpStatus.NOT_FOUND);
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) MvcResult(org.springframework.test.web.servlet.MvcResult) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DeleteResponseModel(bio.terra.model.DeleteResponseModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with DatasetSummaryModel

use of bio.terra.model.DatasetSummaryModel in project jade-data-repo by DataBiosphere.

the class ConnectedOperations method createDataset.

public DatasetSummaryModel createDataset(DatasetRequestModel datasetRequest) throws Exception {
    MvcResult result = mvc.perform(post("/api/repository/v1/datasets").contentType(MediaType.APPLICATION_JSON).content(TestUtils.mapToJson(datasetRequest))).andReturn();
    MockHttpServletResponse response = validateJobModelAndWait(result);
    DatasetSummaryModel datasetSummaryModel = handleSuccessCase(response, DatasetSummaryModel.class);
    addDataset(datasetSummaryModel.getId());
    return datasetSummaryModel;
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 5 with DatasetSummaryModel

use of bio.terra.model.DatasetSummaryModel in project jade-data-repo by DataBiosphere.

the class FlightStates method makeFlightCompletedState.

public static FlightState makeFlightCompletedState() {
    DatasetSummaryModel req = buildMinimalDatasetSummary();
    FlightMap resultMap = new FlightMap();
    resultMap.put(JobMapKeys.RESPONSE.getKeyName(), req);
    resultMap.put(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.I_AM_A_TEAPOT);
    resultMap.put(JobMapKeys.DESCRIPTION.getKeyName(), req.getDescription());
    FlightState flightState = new FlightState();
    flightState.setFlightId(testFlightId);
    flightState.setFlightStatus(FlightStatus.SUCCESS);
    flightState.setSubmitted(submittedTime);
    flightState.setInputParameters(resultMap);
    flightState.setResultMap(resultMap);
    flightState.setCompleted(completedTime);
    return flightState;
}
Also used : FlightState(bio.terra.stairway.FlightState) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) FlightMap(bio.terra.stairway.FlightMap)

Aggregations

DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)28 Test (org.junit.Test)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 IngestRequestModel (bio.terra.model.IngestRequestModel)11 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)9 MvcResult (org.springframework.test.web.servlet.MvcResult)8 Dataset (bio.terra.service.dataset.Dataset)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 SnapshotModel (bio.terra.model.SnapshotModel)6 BillingProfileModel (bio.terra.model.BillingProfileModel)5 EnumerateDatasetModel (bio.terra.model.EnumerateDatasetModel)5 BlobInfo (com.google.cloud.storage.BlobInfo)5 DatasetModel (bio.terra.model.DatasetModel)4 ErrorModel (bio.terra.model.ErrorModel)4 Blob (com.google.cloud.storage.Blob)4 BillingProfileRequestModel (bio.terra.model.BillingProfileRequestModel)3 DRSObject (bio.terra.model.DRSObject)3 DeleteResponseModel (bio.terra.model.DeleteResponseModel)3 FileModel (bio.terra.model.FileModel)3