Search in sources :

Example 1 with ProgressLogger

use of org.nzbhydra.logging.ProgressLogger in project nzbhydra2 by theotherp.

the class SqliteMigration method migrateIndexerSearches.

protected void migrateIndexerSearches(Map<Integer, IndexerEntity> oldIdToIndexersMap, Map<Integer, SearchEntity> oldIdToSearchesMap) throws SQLException {
    Statement statement = connection.createStatement();
    int countIndexerSearches = getCount(statement, "INDEXERSEARCH");
    int countMigrated = 1;
    logger.info("Migrating {} indexer searches from old database", countIndexerSearches);
    eventPublisher.publishEvent(new MigrationMessageEvent("Migrating " + countIndexerSearches + " indexer search entries"));
    ResultSet oldIndexerSearch = statement.executeQuery("SELECT * FROM INDEXERSEARCH");
    IndexerSearchEntity newEntity;
    ProgressLogger progressLogger = new ProgressLogger(logger, 5, TimeUnit.SECONDS);
    progressLogger.expectedUpdates = countIndexerSearches;
    progressLogger.start();
    while (oldIndexerSearch.next()) {
        newEntity = new IndexerSearchEntity();
        newEntity.setSuccessful(oldIndexerSearch.getBoolean("successful"));
        newEntity.setIndexerEntity(oldIdToIndexersMap.get(oldIndexerSearch.getInt("indexer_id")));
        newEntity.setSearchEntity(oldIdToSearchesMap.get(oldIndexerSearch.getInt("search_id")));
        newEntity.setUniqueResults(oldIndexerSearch.getInt("uniqueResults"));
        newEntity.setProcessedResults(oldIndexerSearch.getInt("processedResults"));
        newEntity.setResultsCount(oldIndexerSearch.getInt("resultsCount"));
        entityManager.persist(newEntity);
        progressLogger.lightUpdate();
        if (countMigrated++ % 50 == 0) {
            entityManager.flush();
            entityManager.clear();
        }
    }
    statement.close();
    entityManager.flush();
    entityManager.clear();
    progressLogger.stop();
    logger.info("Successfully migrated indexer searches from old database");
    eventPublisher.publishEvent(new MigrationMessageEvent("Successfully migrated indexer searches from old database"));
}
Also used : MigrationMessageEvent(org.nzbhydra.migration.FromPythonMigration.MigrationMessageEvent) ProgressLogger(org.nzbhydra.logging.ProgressLogger)

Example 2 with ProgressLogger

use of org.nzbhydra.logging.ProgressLogger in project nzbhydra2 by theotherp.

the class SqliteMigration method migrateIndexerApiAccesses.

private void migrateIndexerApiAccesses(Map<Integer, IndexerEntity> oldIdToIndexersMap) throws SQLException {
    Statement statement = connection.createStatement();
    int countIndexerApiAccesses = getCount(statement, "INDEXERAPIACCESS");
    logger.info("Migrating {} indexer API accesses from old database", countIndexerApiAccesses);
    eventPublisher.publishEvent(new MigrationMessageEvent("Migrating " + countIndexerApiAccesses + " indexer API access entries"));
    ResultSet oldIndexerApiAccesses = statement.executeQuery("SELECT * FROM INDEXERAPIACCESS");
    int countMigrated = 1;
    IndexerApiAccessEntity entity;
    ProgressLogger progressLogger = new ProgressLogger(logger, 5, TimeUnit.SECONDS);
    progressLogger.expectedUpdates = countIndexerApiAccesses;
    progressLogger.start();
    while (oldIndexerApiAccesses.next()) {
        entity = new IndexerApiAccessEntity();
        entity.setIndexer(oldIdToIndexersMap.get(oldIndexerApiAccesses.getInt("indexer_id")));
        entity.setTime(timestampToInstant(oldIndexerApiAccesses.getString("time")));
        Object responseTime = oldIndexerApiAccesses.getObject("response_time");
        entity.setResponseTime(responseTime != null ? ((Integer) responseTime).longValue() : null);
        String error = oldIndexerApiAccesses.getString("error");
        entity.setError(error != null ? error.substring(0, Math.min(4000, error.length())) : null);
        entity.setAccessType(null);
        // Close enough
        entity.setResult(oldIndexerApiAccesses.getBoolean("response_successful") ? IndexerAccessResult.SUCCESSFUL : IndexerAccessResult.CONNECTION_ERROR);
        entity.setAccessType(IndexerApiAccessType.valueOf(oldIndexerApiAccesses.getString("type").toUpperCase()));
        entityManager.persist(entity);
        progressLogger.lightUpdate();
        if (countMigrated++ % 50 == 0) {
            entityManager.flush();
            entityManager.clear();
        }
    }
    progressLogger.stop();
    statement.close();
    entityManager.flush();
    entityManager.clear();
    eventPublisher.publishEvent(new MigrationMessageEvent("Successfully migrated indexer API accesses from old database"));
    logger.info("Successfully migrated indexer API accesses from old database");
}
Also used : MigrationMessageEvent(org.nzbhydra.migration.FromPythonMigration.MigrationMessageEvent) ProgressLogger(org.nzbhydra.logging.ProgressLogger)

Aggregations

ProgressLogger (org.nzbhydra.logging.ProgressLogger)2 MigrationMessageEvent (org.nzbhydra.migration.FromPythonMigration.MigrationMessageEvent)2