Search in sources :

Example 1 with MigratableObjectDescriptor

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;
}
Also used : SQLException(java.sql.SQLException) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) QueryResults(org.sagebionetworks.repo.model.QueryResults) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ResultSet(java.sql.ResultSet) HashSet(java.util.HashSet)

Example 2 with MigratableObjectDescriptor

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);
}
Also used : UserInfo(org.sagebionetworks.repo.model.UserInfo) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor)

Example 3 with MigratableObjectDescriptor

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);
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) SynapseServiceException(org.sagebionetworks.client.exceptions.SynapseServiceException) SynapseNotFoundException(org.sagebionetworks.client.exceptions.SynapseNotFoundException) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) SynapseAdministration(org.sagebionetworks.client.SynapseAdministration) SynapseServiceException(org.sagebionetworks.client.exceptions.SynapseServiceException) SocketTimeoutException(java.net.SocketTimeoutException) SynapseNotFoundException(org.sagebionetworks.client.exceptions.SynapseNotFoundException)

Example 4 with MigratableObjectDescriptor

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()));
}
Also used : ArrayList(java.util.ArrayList) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) Test(org.junit.Test)

Example 5 with MigratableObjectDescriptor

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);
    }
}
Also used : ArrayList(java.util.ArrayList) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) Test(org.junit.Test)

Aggregations

MigratableObjectDescriptor (org.sagebionetworks.repo.model.MigratableObjectDescriptor)25 MigratableObjectData (org.sagebionetworks.repo.model.MigratableObjectData)21 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)5 MigratableDAO (org.sagebionetworks.repo.model.MigratableDAO)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 QueryResults (org.sagebionetworks.repo.model.QueryResults)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 HashMap (java.util.HashMap)2 AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)2 TermsOfUseAccessRequirement (org.sagebionetworks.repo.model.TermsOfUseAccessRequirement)2 UserProfile (org.sagebionetworks.repo.model.UserProfile)2 SocketTimeoutException (java.net.SocketTimeoutException)1 Set (java.util.Set)1 SynapseAdministration (org.sagebionetworks.client.SynapseAdministration)1 SynapseNotFoundException (org.sagebionetworks.client.exceptions.SynapseNotFoundException)1 SynapseServiceException (org.sagebionetworks.client.exceptions.SynapseServiceException)1 ConflictingUpdateException (org.sagebionetworks.repo.model.ConflictingUpdateException)1