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