Search in sources :

Example 6 with DeleteResponseModel

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

the class SnapshotConnectedTest method testExcludeLockedFromSnapshotLookups.

@Test
public void testExcludeLockedFromSnapshotLookups() throws Exception {
    // create a snapshot
    SnapshotSummaryModel snapshotSummary = connectedOperations.createSnapshot(datasetSummary, "snapshot-test-snapshot.json", "_d2_");
    // check that the snapshot metadata row is unlocked
    String exclusiveLock = snapshotDao.getExclusiveLockState(UUID.fromString(snapshotSummary.getId()));
    assertNull("snapshot row is unlocked", exclusiveLock);
    // retrieve the snapshot and check that it finds it
    SnapshotModel snapshotModel = connectedOperations.getSnapshot(snapshotSummary.getId());
    assertEquals("Lookup unlocked snapshot succeeds", snapshotSummary.getName(), snapshotModel.getName());
    // enumerate snapshots and check that this snapshot is included in the set
    EnumerateSnapshotModel enumerateSnapshotModelModel = connectedOperations.enumerateSnapshots(snapshotSummary.getName());
    List<SnapshotSummaryModel> enumeratedSnapshots = enumerateSnapshotModelModel.getItems();
    boolean foundSnapshotWithMatchingId = false;
    for (SnapshotSummaryModel enumeratedSnapshot : enumeratedSnapshots) {
        if (enumeratedSnapshot.getId().equals(snapshotSummary.getId())) {
            foundSnapshotWithMatchingId = true;
            break;
        }
    }
    assertTrue("Unlocked included in enumeration", foundSnapshotWithMatchingId);
    // NO ASSERTS inside the block below where hang is enabled to reduce chance of failing before disabling the hang
    // ====================================================
    // enable hang in DeleteSnapshotPrimaryDataStep
    configService.setFault(ConfigEnum.SNAPSHOT_DELETE_LOCK_CONFLICT_STOP_FAULT.name(), true);
    // kick off a request to delete the snapshot. this should hang before unlocking the snapshot object.
    MvcResult deleteResult = mvc.perform(delete("/api/repository/v1/snapshots/" + snapshotSummary.getId())).andReturn();
    // give the flight time to launch
    TimeUnit.SECONDS.sleep(5);
    // note: asserts are below outside the hang block
    exclusiveLock = snapshotDao.getExclusiveLockState(UUID.fromString(snapshotSummary.getId()));
    // retrieve the snapshot and check that it returns not found
    // note: asserts are below outside the hang block
    MvcResult retrieveResult = mvc.perform(get("/api/repository/v1/snapshots/" + snapshotSummary.getId())).andReturn();
    // enumerate snapshots and check that this snapshot is not included in the set
    // note: asserts are below outside the hang block
    MvcResult enumerateResult = connectedOperations.enumerateSnapshotsRaw(snapshotSummary.getName());
    // disable hang in DeleteSnapshotPrimaryDataStep
    configService.setFault(ConfigEnum.SNAPSHOT_DELETE_LOCK_CONFLICT_CONTINUE_FAULT.name(), true);
    // ====================================================
    // check that the snapshot metadata row has an exclusive lock after kicking off the delete
    assertNotNull("snapshot row is exclusively locked", exclusiveLock);
    // check that the retrieve snapshot returned not found
    connectedOperations.handleFailureCase(retrieveResult.getResponse(), HttpStatus.NOT_FOUND);
    // check that the enumerate snapshots returned successfully and that this snapshot is not included in the set
    enumerateSnapshotModelModel = connectedOperations.handleSuccessCase(enumerateResult.getResponse(), EnumerateSnapshotModel.class);
    enumeratedSnapshots = enumerateSnapshotModelModel.getItems();
    foundSnapshotWithMatchingId = false;
    for (SnapshotSummaryModel enumeratedSnapshot : enumeratedSnapshots) {
        if (enumeratedSnapshot.getId().equals(snapshotSummary.getId())) {
            foundSnapshotWithMatchingId = true;
            break;
        }
    }
    assertFalse("Exclusively locked not included in enumeration", foundSnapshotWithMatchingId);
    // check the response from the delete request
    MockHttpServletResponse deleteResponse = connectedOperations.validateJobModelAndWait(deleteResult);
    DeleteResponseModel deleteResponseModel = connectedOperations.handleSuccessCase(deleteResponse, DeleteResponseModel.class);
    assertEquals("Snapshot delete returned successfully", DeleteResponseModel.ObjectStateEnum.DELETED, deleteResponseModel.getObjectState());
    // try to fetch the snapshot again and confirm nothing is returned
    connectedOperations.getSnapshotExpectError(snapshotSummary.getId(), HttpStatus.NOT_FOUND);
}
Also used : SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MvcResult(org.springframework.test.web.servlet.MvcResult) SnapshotModel(bio.terra.model.SnapshotModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DeleteResponseModel(bio.terra.model.DeleteResponseModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with DeleteResponseModel

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

the class DeleteSnapshotMetadataStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    Snapshot snapshot = null;
    boolean found = false;
    try {
        found = snapshotDao.delete(snapshotId);
    } catch (SnapshotNotFoundException ex) {
        found = false;
    }
    DeleteResponseModel.ObjectStateEnum stateEnum = (found) ? DeleteResponseModel.ObjectStateEnum.DELETED : DeleteResponseModel.ObjectStateEnum.NOT_FOUND;
    DeleteResponseModel deleteResponseModel = new DeleteResponseModel().objectState(stateEnum);
    FlightUtils.setResponse(context, deleteResponseModel, HttpStatus.OK);
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException) DeleteResponseModel(bio.terra.model.DeleteResponseModel)

Example 8 with DeleteResponseModel

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

the class DataDeletionStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    Dataset dataset = getDataset(context, datasetService);
    String suffix = getSuffix(context);
    DataDeletionRequest dataDeletionRequest = getRequest(context);
    List<String> tableNames = dataDeletionRequest.getTables().stream().map(DataDeletionTableModel::getTableName).collect(Collectors.toList());
    bigQueryPdao.validateDeleteRequest(dataset, dataDeletionRequest.getTables(), suffix);
    if (configService.testInsertFault(ConfigEnum.SOFT_DELETE_LOCK_CONFLICT_STOP_FAULT)) {
        logger.info("SOFT_DELETE_LOCK_CONFLICT_STOP_FAULT");
        while (!configService.testInsertFault(ConfigEnum.SOFT_DELETE_LOCK_CONFLICT_CONTINUE_FAULT)) {
            logger.info("Sleeping for CONTINUE FAULT");
            TimeUnit.SECONDS.sleep(5);
        }
        logger.info("SOFT_DELETE_LOCK_CONFLICT_CONTINUE_FAULT");
    }
    bigQueryPdao.applySoftDeletes(dataset, tableNames, suffix);
    // TODO: this can be more informative, something like # rows deleted per table, or mismatched row ids
    DeleteResponseModel deleteResponseModel = new DeleteResponseModel().objectState(DeleteResponseModel.ObjectStateEnum.DELETED);
    FlightUtils.setResponse(context, deleteResponseModel, HttpStatus.OK);
    return StepResult.getStepResultSuccess();
}
Also used : DataDeletionUtils.getDataset(bio.terra.service.dataset.flight.datadelete.DataDeletionUtils.getDataset) Dataset(bio.terra.service.dataset.Dataset) DataDeletionRequest(bio.terra.model.DataDeletionRequest) DeleteResponseModel(bio.terra.model.DeleteResponseModel)

Example 9 with DeleteResponseModel

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

the class DeleteDatasetMetadataStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    boolean success = datasetDao.delete(datasetId);
    DeleteResponseModel.ObjectStateEnum stateEnum = (success) ? DeleteResponseModel.ObjectStateEnum.DELETED : DeleteResponseModel.ObjectStateEnum.NOT_FOUND;
    DeleteResponseModel deleteResponseModel = new DeleteResponseModel().objectState(stateEnum);
    FlightUtils.setResponse(context, deleteResponseModel, HttpStatus.OK);
    return StepResult.getStepResultSuccess();
}
Also used : DeleteResponseModel(bio.terra.model.DeleteResponseModel)

Example 10 with DeleteResponseModel

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

the class DeleteFileDirectoryStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    try {
        boolean found = fileDao.deleteDirectoryEntry(dataset, fileId);
        DeleteResponseModel.ObjectStateEnum stateEnum = (found) ? DeleteResponseModel.ObjectStateEnum.DELETED : DeleteResponseModel.ObjectStateEnum.NOT_FOUND;
        DeleteResponseModel deleteResponseModel = new DeleteResponseModel().objectState(stateEnum);
        FlightUtils.setResponse(context, deleteResponseModel, HttpStatus.OK);
    } catch (FileSystemAbortTransactionException rex) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, rex);
    }
    return StepResult.getStepResultSuccess();
}
Also used : FileSystemAbortTransactionException(bio.terra.service.filedata.exception.FileSystemAbortTransactionException) StepResult(bio.terra.stairway.StepResult) DeleteResponseModel(bio.terra.model.DeleteResponseModel)

Aggregations

DeleteResponseModel (bio.terra.model.DeleteResponseModel)12 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 MvcResult (org.springframework.test.web.servlet.MvcResult)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 ErrorModel (bio.terra.model.ErrorModel)3 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)3 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)2 FileLoadModel (bio.terra.model.FileLoadModel)2 FileModel (bio.terra.model.FileModel)2 URI (java.net.URI)2 UUID (java.util.UUID)2 DRSObject (bio.terra.model.DRSObject)1 DataDeletionGcsFileModel (bio.terra.model.DataDeletionGcsFileModel)1 DataDeletionRequest (bio.terra.model.DataDeletionRequest)1 DatasetModel (bio.terra.model.DatasetModel)1 EnumerateDatasetModel (bio.terra.model.EnumerateDatasetModel)1 EnumerateSnapshotModel (bio.terra.model.EnumerateSnapshotModel)1 IngestRequestModel (bio.terra.model.IngestRequestModel)1