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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations