use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.
the class DBOUserGroupDAOImpl method getMigrationObjectData.
@Override
public QueryResults<MigratableObjectData> getMigrationObjectData(long offset, long limit, boolean includeDependencies) throws DatastoreException {
// get a page of user groups
List<MigratableObjectData> ods = null;
{
MapSqlParameterSource param = new MapSqlParameterSource();
param.addValue(OFFSET_PARAM_NAME, offset);
param.addValue(LIMIT_PARAM_NAME, limit);
ods = simpleJdbcTemplate.query(SELECT_ALL_PAGINATED_WITH_ETAG, new RowMapper<MigratableObjectData>() {
@Override
public MigratableObjectData mapRow(ResultSet rs, int rowNum) throws SQLException {
// NOTE this is an outer join, so we have to handle the case in which there
// is no etag for the given user group
String ugId = rs.getString(COL_USER_GROUP_ID);
String etag = rs.getString(COL_USER_PROFILE_ETAG);
if (etag == null)
etag = DEFAULT_ETAG;
MigratableObjectData od = new MigratableObjectData();
MigratableObjectDescriptor id = new MigratableObjectDescriptor();
id.setId(ugId);
id.setType(MigratableObjectType.PRINCIPAL);
od.setId(id);
od.setEtag(etag);
// UserGroups have no dependencies
od.setDependencies(new HashSet<MigratableObjectDescriptor>(0));
return od;
}
}, param);
}
QueryResults<MigratableObjectData> queryResults = new QueryResults<MigratableObjectData>();
queryResults.setResults(ods);
queryResults.setTotalNumberOfResults((int) getCount());
return queryResults;
}
use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.
the class AdministrationServiceImpl method deleteMigratableObject.
/* (non-Javadoc)
* @see org.sagebionetworks.repo.web.service.AdministrationService#deleteMigratableObject(java.lang.String, java.lang.String, java.lang.String, org.springframework.http.HttpHeaders, javax.servlet.http.HttpServletRequest)
*/
@Override
public void deleteMigratableObject(String userId, String objectId, String type, HttpHeaders header, HttpServletRequest request) throws DatastoreException, InvalidModelException, UnauthorizedException, NotFoundException, IOException, ConflictingUpdateException {
// Get the user
UserInfo userInfo = userManager.getUserInfo(userId);
MigratableObjectDescriptor mod = new MigratableObjectDescriptor();
mod.setId(objectId);
mod.setType(MigratableObjectType.valueOf(type));
// start a restore daemon
backupDaemonLauncher.delete(userInfo, mod);
}
use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.
the class DeleteWorker method call.
@Override
public WorkerResult call() throws Exception {
try {
// We only delete from the destination.
SynapseAdministration client = clientFactory.createNewDestinationClient(configuration);
for (String entityId : this.entites) {
try {
MigratableObjectDescriptor mod = new MigratableObjectDescriptor();
mod.setId(entityId);
mod.setType(objectType);
client.deleteObject(mod);
} catch (SynapseNotFoundException e) {
// There is nothing to do if the entity does not exist
} catch (SynapseServiceException e) {
if (e.getCause() instanceof SocketTimeoutException) {
// Deletes can take a long to complete so we just continue when it happens
Thread.sleep(2000);
} else {
throw e;
}
}
progress.setCurrent(progress.getCurrent() + 1);
Thread.sleep(1000);
}
// done
progress.setDone();
return new WorkerResult(this.entites.size(), WorkerResult.JobStatus.SUCCEEDED);
} catch (Exception e) {
// done
progress.setDone();
// Log any errors
log.error("CreateUpdateWorker Failed to run job: " + entites.toString(), e);
return new WorkerResult(0, WorkerResult.JobStatus.FAILED);
}
}
use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.
the class UpdateJobBuilderTest method testSourceWithUpdatesSmallUpdates.
@Test
public void testSourceWithUpdatesSmallUpdates() throws Exception {
// make sure the destination is the same as the source
List<MigratableObjectData> dest = new ArrayList<MigratableObjectData>();
for (MigratableObjectData fromSource : source) {
dest.add(XestUtil.cloneMigratableObjectData(fromSource));
}
assertEquals(source, dest);
// Change some eTags on the source
MigratableObjectData toUpdate = source.get(2);
toUpdate.setEtag("33");
Map<MigratableObjectDescriptor, MigratableObjectData> destMap = JobUtil.buildMigratableMapFromList(dest);
// now run the job
int batchSize = 10;
UpdateJobBuilder builder = new UpdateJobBuilder(source, destMap, jobQueue, batchSize);
BuilderResponse response = builder.call();
assertNotNull(response);
// Nothing should have been submitted.
int expectedSubmited = 1;
assertEquals(expectedSubmited, response.getSubmittedToQueue());
assertEquals(0, response.pendingDependencies);
assertEquals(1, jobQueue.size());
Set<String> set = jobQueue.peek().getObjectIds();
assertNotNull(set);
// Does it contain the one expected id.
assertTrue(set.contains(toUpdate.getId().getId()));
}
use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.
the class UpdateJobBuilderTest method testSourceWithUpdatesMultipleTypes.
@Test
public void testSourceWithUpdatesMultipleTypes() throws Exception {
// in addition to Entities, we have an access requirement to migrate
source.add(XestUtil.createMigratableObjectData("1", "0", null, MigratableObjectType.ACCESSREQUIREMENT));
// make sure the destination is the same as the source
List<MigratableObjectData> dest = new ArrayList<MigratableObjectData>();
for (MigratableObjectData fromSource : source) {
dest.add(XestUtil.cloneMigratableObjectData(fromSource));
}
assertEquals(source, dest);
// Change some eTags on the source
source.get(2).setEtag("33");
source.get(5).setEtag("33");
source.get(7).setEtag("33");
source.get(source.size() - 1).setEtag("33");
Map<MigratableObjectDescriptor, MigratableObjectData> destMap = JobUtil.buildMigratableMapFromList(dest);
// now run the job
int batchSize = 2;
UpdateJobBuilder builder = new UpdateJobBuilder(source, destMap, jobQueue, batchSize);
BuilderResponse response = builder.call();
assertNotNull(response);
// Nothing should have been submitted.
// "+1" for separate type
int expectedSubmited = 3 + 1;
assertEquals(expectedSubmited, response.getSubmittedToQueue());
assertEquals(0, response.pendingDependencies);
assertEquals(expectedSubmited / batchSize + 1, jobQueue.size());
// Check the jobQue
Job job = null;
while ((job = jobQueue.poll()) != null) {
assertNotNull(job);
assertEquals(Type.UPDATE, job.getJobType());
assertNotNull(job.getObjectIds());
assertTrue(job.getObjectIds().size() <= batchSize);
}
}
Aggregations