Search in sources :

Example 1 with MigratableObjectCount

use of org.sagebionetworks.repo.model.MigratableObjectCount in project Synapse-Repository-Services by Sage-Bionetworks.

the class AdministrationServiceImpl method getAllBackupObjectsCounts.

/* (non-Javadoc)
	 * @see org.sagebionetworks.repo.web.service.AdministrationService#getAllBackupObjectsCounts(java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Boolean)
	 */
@Override
public PaginatedResults<MigratableObjectCount> getAllBackupObjectsCounts(String userId) throws DatastoreException, UnauthorizedException, NotFoundException {
    UserInfo userInfo = userManager.getUserInfo(userId);
    if (!userInfo.isAdmin())
        throw new UnauthorizedException("Only an administrator may access this service.");
    QueryResults<MigratableObjectCount> queryResults = dependencyManager.getAllObjectsCounts();
    PaginatedResults<MigratableObjectCount> result = new PaginatedResults<MigratableObjectCount>();
    result.setResults(queryResults.getResults());
    result.setTotalNumberOfResults(queryResults.getTotalNumberOfResults());
    return result;
}
Also used : PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) UnauthorizedException(org.sagebionetworks.repo.model.UnauthorizedException) UserInfo(org.sagebionetworks.repo.model.UserInfo) MigratableObjectCount(org.sagebionetworks.repo.model.MigratableObjectCount)

Example 2 with MigratableObjectCount

use of org.sagebionetworks.repo.model.MigratableObjectCount in project Synapse-Repository-Services by Sage-Bionetworks.

the class StackStatusPresenter method run.

@Override
public void run() {
    // Any work we do here is off of the event dispatch thread, so we will need SwingUtilties to talk to the view.
    while (true) {
        try {
            // Start the progress
            int totalProgress = EntityType.values().length + 3;
            int current = 0;
            resetProgress(current, totalProgress, "Authenticating...");
            // Connect
            ClientFactoryImpl factory = new ClientFactoryImpl();
            SynapseAdministration client = factory.createNewConnection(this.connectionInfo);
            // Get the status
            setProgressValue(current++, "Getting stack status...");
            StackStatus status = client.getCurrentStackStatus();
            setStackStatus(status.getStatus().name());
            QueryRunner queryRunner = new QueryRunnerImpl(client);
            // TODO: Move to query runner to remove dependency on PaginatedResults/MigratableObjectCount
            try {
                PaginatedResults<MigratableObjectCount> moc = client.getMigratableObjectCounts();
                for (MigratableObjectCount oc : moc.getResults()) {
                    setCountForEntity(MigratableObjectType.valueOf(oc.getObjectType()), oc.getCount());
                }
            } catch (Exception e) {
                log.debug("API getMigratableObjectCounts not implemented on repository" + client.getRepoEndpoint());
            }
            // Make some progress
            setProgressValue(current++, "Querying for total entity count...");
            // Count the total number of entities
            long total = queryRunner.getTotalEntityCount();
            setTotalCount(total);
            // Finished
            setProgressValue(totalProgress, "Waiting for next run...");
            Thread.sleep(20000);
        } catch (final Exception e) {
            // Log the error and show it to the user
            log.error(e);
            // Show the error to the user
            showError(e);
            try {
                Thread.sleep(1000 * 60);
            } catch (InterruptedException e1) {
                // terminate
                return;
            }
        }
    }
}
Also used : ClientFactoryImpl(org.sagebionetworks.tool.migration.ClientFactoryImpl) QueryRunnerImpl(org.sagebionetworks.tool.migration.dao.QueryRunnerImpl) StackStatus(org.sagebionetworks.repo.model.status.StackStatus) MigratableObjectCount(org.sagebionetworks.repo.model.MigratableObjectCount) SynapseAdministration(org.sagebionetworks.client.SynapseAdministration) QueryRunner(org.sagebionetworks.tool.migration.dao.QueryRunner) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with MigratableObjectCount

use of org.sagebionetworks.repo.model.MigratableObjectCount in project Synapse-Repository-Services by Sage-Bionetworks.

the class SynapseAdministrationTest method testGetMigratableObjectCounts.

@Test
public void testGetMigratableObjectCounts() throws Exception {
    PaginatedResults<MigratableObjectCount> p = new PaginatedResults<MigratableObjectCount>();
    String expectedJSONResult = EntityFactory.createJSONStringForEntity(p);
    StringEntity responseEntity = new StringEntity(expectedJSONResult);
    when(mockResponse.getEntity()).thenReturn(responseEntity);
    PaginatedResults<MigratableObjectCount> oc = synapse.getMigratableObjectCounts();
    assertNotNull(oc);
    assertEquals(p, oc);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) MigratableObjectCount(org.sagebionetworks.repo.model.MigratableObjectCount) Test(org.junit.Test)

Example 4 with MigratableObjectCount

use of org.sagebionetworks.repo.model.MigratableObjectCount in project Synapse-Repository-Services by Sage-Bionetworks.

the class SynapseAdministration method getMigratableObjectCounts.

public PaginatedResults<MigratableObjectCount> getMigratableObjectCounts() throws SynapseException {
    String uri = GET_ALL_BACKUP_COUNTS;
    JSONObject o = getEntity(uri);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(o);
    PaginatedResults<MigratableObjectCount> rs = new PaginatedResults<MigratableObjectCount>(MigratableObjectCount.class);
    try {
        rs.initializeFromJSONObject(adapter);
        return rs;
    } catch (JSONObjectAdapterException e) {
        throw new SynapseException(e);
    }
}
Also used : JSONObject(org.json.JSONObject) SynapseException(org.sagebionetworks.client.exceptions.SynapseException) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) JSONObjectAdapterException(org.sagebionetworks.schema.adapter.JSONObjectAdapterException) MigratableObjectCount(org.sagebionetworks.repo.model.MigratableObjectCount) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)

Example 5 with MigratableObjectCount

use of org.sagebionetworks.repo.model.MigratableObjectCount in project Synapse-Repository-Services by Sage-Bionetworks.

the class DependencyManagerImpl method getAllObjectsCounts.

@Override
public QueryResults<MigratableObjectCount> getAllObjectsCounts() throws DatastoreException {
    List<MigratableObjectCount> ods = new ArrayList<MigratableObjectCount>();
    long total = 0L;
    for (MigratableDAO migratableDAO : getMigratableDaos()) {
        long c = migratableDAO.getCount();
        MigratableObjectCount moc = new MigratableObjectCount();
        moc.setCount(c);
        moc.setObjectType(migratableDAO.getMigratableObjectType().name());
        ods.add(moc);
        total += 1;
    }
    QueryResults<MigratableObjectCount> queryResults = new QueryResults<MigratableObjectCount>();
    queryResults.setResults(ods);
    queryResults.setTotalNumberOfResults((int) total);
    return queryResults;
}
Also used : MigratableDAO(org.sagebionetworks.repo.model.MigratableDAO) ArrayList(java.util.ArrayList) MigratableObjectCount(org.sagebionetworks.repo.model.MigratableObjectCount) QueryResults(org.sagebionetworks.repo.model.QueryResults)

Aggregations

MigratableObjectCount (org.sagebionetworks.repo.model.MigratableObjectCount)7 ArrayList (java.util.ArrayList)3 PaginatedResults (org.sagebionetworks.repo.model.PaginatedResults)3 Test (org.junit.Test)2 MigratableDAO (org.sagebionetworks.repo.model.MigratableDAO)2 QueryResults (org.sagebionetworks.repo.model.QueryResults)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 StringEntity (org.apache.http.entity.StringEntity)1 JSONObject (org.json.JSONObject)1 SynapseAdministration (org.sagebionetworks.client.SynapseAdministration)1 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)1 UnauthorizedException (org.sagebionetworks.repo.model.UnauthorizedException)1 UserInfo (org.sagebionetworks.repo.model.UserInfo)1 StackStatus (org.sagebionetworks.repo.model.status.StackStatus)1 JSONObjectAdapter (org.sagebionetworks.schema.adapter.JSONObjectAdapter)1 JSONObjectAdapterException (org.sagebionetworks.schema.adapter.JSONObjectAdapterException)1 JSONObjectAdapterImpl (org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)1 ClientFactoryImpl (org.sagebionetworks.tool.migration.ClientFactoryImpl)1 QueryRunner (org.sagebionetworks.tool.migration.dao.QueryRunner)1 QueryRunnerImpl (org.sagebionetworks.tool.migration.dao.QueryRunnerImpl)1