use of bio.terra.model.EnumerateSnapshotModel in project jade-data-repo by DataBiosphere.
the class RepositoryApiController method enumerateSnapshots.
@Override
public ResponseEntity<EnumerateSnapshotModel> enumerateSnapshots(@Valid @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset, @Valid @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit, @Valid @RequestParam(value = "sort", required = false, defaultValue = "created_date") String sort, @Valid @RequestParam(value = "direction", required = false, defaultValue = "asc") String direction, @Valid @RequestParam(value = "filter", required = false) String filter) {
ControllerUtils.validateEnumerateParams(offset, limit, sort, direction);
List<UUID> resources = iamService.listAuthorizedResources(getAuthenticatedInfo(), IamResourceType.DATASNAPSHOT);
EnumerateSnapshotModel edm = snapshotService.enumerateSnapshots(offset, limit, sort, direction, filter, resources);
return new ResponseEntity<>(edm, HttpStatus.OK);
}
use of bio.terra.model.EnumerateSnapshotModel in project jade-data-repo by DataBiosphere.
the class SnapshotConnectedTest method testEnumeration.
@Test
public void testEnumeration() throws Exception {
SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetSummary, "snapshot-test-snapshot.json");
// Other unit tests exercise the array bounds, so here we don't fuss with that here.
// Just make sure we get the same snapshot summary that we made.
List<SnapshotSummaryModel> snapshotList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
MockHttpServletResponse response = performCreateSnapshot(snapshotRequest, "_en_");
SnapshotSummaryModel summaryModel = validateSnapshotCreated(snapshotRequest, response);
snapshotList.add(summaryModel);
}
List<UUID> snapshotIds = snapshotList.stream().map(snapshot -> UUID.fromString(snapshot.getId())).collect(Collectors.toList());
when(samService.listAuthorizedResources(any(), any())).thenReturn(snapshotIds);
EnumerateSnapshotModel enumResponse = enumerateTestSnapshots();
List<SnapshotSummaryModel> enumeratedArray = enumResponse.getItems();
assertThat("total is correct", enumResponse.getTotal(), equalTo(5));
// The enumeratedArray may contain more snapshots than just the set we created,
// but ours should be in order in the enumeration. So we do a merge waiting until we match
// by id and then comparing contents.
int compareIndex = 0;
for (SnapshotSummaryModel anEnumeratedSnapshot : enumeratedArray) {
if (anEnumeratedSnapshot.getId().equals(snapshotList.get(compareIndex).getId())) {
assertThat("MetadataEnumeration summary matches create summary", anEnumeratedSnapshot, equalTo(snapshotList.get(compareIndex)));
compareIndex++;
}
}
assertThat("we found all snapshots", compareIndex, equalTo(5));
for (int i = 0; i < 5; i++) {
connectedOperations.deleteTestSnapshot(enumeratedArray.get(i).getId());
}
}
use of bio.terra.model.EnumerateSnapshotModel 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.EnumerateSnapshotModel in project jade-data-repo by DataBiosphere.
the class SnapshotConnectedTest method enumerateTestSnapshots.
private EnumerateSnapshotModel enumerateTestSnapshots() throws Exception {
MvcResult result = mvc.perform(get("/api/repository/v1/snapshots?offset=0&limit=1000")).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andReturn();
MockHttpServletResponse response = result.getResponse();
EnumerateSnapshotModel summary = TestUtils.mapFromJson(response.getContentAsString(), EnumerateSnapshotModel.class);
return summary;
}
use of bio.terra.model.EnumerateSnapshotModel in project jade-data-repo by DataBiosphere.
the class SnapshotTest method snapshotUnauthorizedPermissionsTest.
@Test
public void snapshotUnauthorizedPermissionsTest() throws Exception {
DataRepoResponse<JobModel> createSnapLaunchResp = dataRepoFixtures.createSnapshotLaunch(reader(), datasetSummaryModel, "ingest-test-snapshot.json");
assertThat("Reader is not authorized to create a dataSnapshot", createSnapLaunchResp.getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
SnapshotSummaryModel snapshotSummary = dataRepoFixtures.createSnapshot(custodian(), datasetSummaryModel, "ingest-test-snapshot.json");
createdSnapshotIds.add(snapshotSummary.getId());
DataRepoResponse<JobModel> deleteSnapResp = dataRepoFixtures.deleteSnapshotLaunch(reader(), snapshotSummary.getId());
assertThat("Reader is not authorized to delete a dataSnapshot", deleteSnapResp.getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
DataRepoResponse<SnapshotModel> getSnapResp = dataRepoFixtures.getSnapshotRaw(discoverer(), snapshotSummary.getId());
assertThat("Discoverer is not authorized to get a dataSnapshot", getSnapResp.getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
EnumerateSnapshotModel enumSnap = dataRepoFixtures.enumerateSnapshots(discoverer());
assertThat("Discoverer does not have access to dataSnapshots", enumSnap.getTotal(), equalTo(0));
}
Aggregations