Search in sources :

Example 1 with IndexerEntity

use of org.nzbhydra.indexers.IndexerEntity in project nzbhydra2 by theotherp.

the class DuplicateDetectorTest method setValues.

protected void setValues(SearchResultItem item, String indexerName, String poster, String group, Instant pubDate) {
    item.setAgePrecise(true);
    item.setTitle("title");
    item.setIndexerGuid("123");
    item.setPubDate(pubDate);
    item.setPoster(poster);
    item.setGroup(group);
    item.setSize(10000L);
    Newznab indexer = new Newznab();
    IndexerConfig config = new IndexerConfig();
    config.setName(indexerName);
    IndexerEntity indexerEntity = new IndexerEntity();
    indexerEntity.setName(indexerName);
    indexer.initialize(config, indexerEntity);
    item.setIndexer(indexer);
}
Also used : Newznab(org.nzbhydra.indexers.Newznab) IndexerConfig(org.nzbhydra.config.IndexerConfig) IndexerEntity(org.nzbhydra.indexers.IndexerEntity)

Example 2 with IndexerEntity

use of org.nzbhydra.indexers.IndexerEntity in project nzbhydra2 by theotherp.

the class SearchResultIdCalculatorTest method shouldCalculateSameSearchResultId.

@Test
public void shouldCalculateSameSearchResultId() throws Exception {
    SearchResultEntity searchResultEntity = new SearchResultEntity();
    IndexerEntity indexerEntity = new IndexerEntity();
    indexerEntity.setName("indexerName");
    indexerEntity = indexerRepository.save(indexerEntity);
    searchResultEntity.setIndexer(indexerEntity);
    searchResultEntity.setIndexerGuid("indexerGuid");
    searchResultEntity.setTitle("title");
    searchResultEntity = searchResultRepository.save(searchResultEntity);
    assertEquals(-2991137394797183212L, SearchResultIdCalculator.calculateSearchResultId(searchResultEntity));
    assertEquals(-2991137394797183212L, searchResultEntity.getId());
    assertEquals(searchResultEntity, searchResultRepository.findOne(-2991137394797183212L));
}
Also used : IndexerEntity(org.nzbhydra.indexers.IndexerEntity) SearchResultEntity(org.nzbhydra.searching.SearchResultEntity) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with IndexerEntity

use of org.nzbhydra.indexers.IndexerEntity in project nzbhydra2 by theotherp.

the class NzbDownloadingTests method setup.

@Before
public void setup() throws Exception {
    System.setProperty("nzbhydra.dev.noApiKey", "true");
    System.setProperty("server.host", "127.0.0.1");
    mockServer = startClientAndServer(7070);
    proxy = startClientAndProxy(7072);
    mvc = MockMvcBuilders.webAppContextSetup(context).apply(SecurityMockMvcConfigurers.springSecurity()).build();
    IndexerEntity indexer = new IndexerEntity();
    indexer.setName("indexer");
    indexerRepository.save(indexer);
    searchResultRepository.deleteAll();
    SearchResultEntity searchResult = new SearchResultEntity();
    searchResult.setIndexer(indexer);
    searchResult.setIndexerGuid("someNzbd");
    searchResult.setLink("http://127.0.0.1:7070/getnzb?id=123");
    searchResult.setTitle("someNzb");
    searchResult.setPubDate(Instant.now());
    searchResult.setFirstFound(Instant.now());
    searchResult = searchResultRepository.save(searchResult);
    searchResultId = searchResult.getId();
    IndexerConfig indexerConfig = new IndexerConfig();
    indexerConfig.setName("indexer");
    indexerConfig.setHost("http://127.0.0.1:7070");
    baseConfig.getIndexers().add(indexerConfig);
    DownloaderConfig downloaderConfig = new DownloaderConfig();
    downloaderConfig.setDownloaderType(DownloaderType.SABNZBD);
    downloaderConfig.setName("sabnzbd");
    downloaderConfig.setUrl("http://127.0.0.1:7070/sabnzbd/");
    downloaderConfig.setNzbAddingType(NzbAddingType.SEND_LINK);
    downloaderConfig.setApiKey("apikey");
    baseConfig.getDownloading().getDownloaders().clear();
    baseConfig.getDownloading().getDownloaders().add(downloaderConfig);
    baseConfig.getSearching().setNzbAccessType(FileDownloadAccessType.REDIRECT);
    downloaderProvider.handleNewConfig(new ConfigChangedEvent(this, new BaseConfig(), baseConfig));
}
Also used : IndexerEntity(org.nzbhydra.indexers.IndexerEntity) SearchResultEntity(org.nzbhydra.searching.SearchResultEntity) Before(org.junit.Before)

Example 4 with IndexerEntity

use of org.nzbhydra.indexers.IndexerEntity in project nzbhydra2 by theotherp.

the class ResultAcceptorTest method shouldCheckForCategoryDisabledForIndexer.

@Test
public void shouldCheckForCategoryDisabledForIndexer() {
    Indexer indexer = new Newznab();
    indexer.initialize(indexerConfig, new IndexerEntity());
    item.setIndexer(indexer);
    // All categories enabled
    when(indexerConfig.getEnabledCategories()).thenReturn(Collections.emptyList());
    assertTrue(testee.checkForCategoryDisabledForIndexer(searchRequest, HashMultiset.create(), item));
    // Used category enabled
    when(indexerConfig.getEnabledCategories()).thenReturn(Arrays.asList(category.getName()));
    assertTrue(testee.checkForCategoryDisabledForIndexer(searchRequest, HashMultiset.create(), item));
    // Only other category enabled
    when(indexerConfig.getEnabledCategories()).thenReturn(Arrays.asList("Other"));
    assertFalse(testee.checkForCategoryDisabledForIndexer(searchRequest, HashMultiset.create(), item));
}
Also used : Newznab(org.nzbhydra.indexers.Newznab) Indexer(org.nzbhydra.indexers.Indexer) IndexerEntity(org.nzbhydra.indexers.IndexerEntity) Test(org.junit.Test)

Example 5 with IndexerEntity

use of org.nzbhydra.indexers.IndexerEntity in project nzbhydra2 by theotherp.

the class Stats method indexerApiAccesses.

List<IndexerApiAccessStatsEntry> indexerApiAccesses(final StatsRequest statsRequest) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    logger.debug("Calculating indexer API stats");
    Set<Integer> indexerIdsToInclude = searchModuleProvider.getIndexers().stream().filter(x -> x.getConfig().getState() == IndexerConfig.State.ENABLED || statsRequest.isIncludeDisabled()).map(x -> x.getIndexerEntity().getId()).filter(id -> indexerRepository.findOne(id) != null).collect(Collectors.toSet());
    String averageIndexerAccessesPerDay = "SELECT\n" + "  indexer_id,\n" + "  avg(count)\n" + "FROM (\n" + "  (SELECT\n" + "     INDEXER_ID,\n" + "     cast(count(INDEXER_ID) AS FLOAT) AS count" + "   FROM INDEXERAPIACCESS\n" + buildWhereFromStatsRequest(false, statsRequest) + "   GROUP BY INDEXER_ID,\n" + "     truncate(time)))\n" + "GROUP BY INDEXER_ID";
    Map<Integer, Double> accessesPerDayCountMap = new HashMap<>();
    Query query = entityManager.createNativeQuery(averageIndexerAccessesPerDay);
    // query = query.setParameter("indexerIds", indexerIdsToInclude);
    List results = query.getResultList();
    for (Object resultObject : results) {
        Object[] array = (Object[]) resultObject;
        Integer indexerId = (Integer) array[0];
        if (!indexerIdsToInclude.contains(indexerId)) {
            continue;
        }
        Double avg = (Double) array[1];
        accessesPerDayCountMap.put(indexerId, avg);
    }
    logger.debug(LoggingMarkers.PERFORMANCE, "Calculating accesses per day took {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
    stopwatch.reset();
    stopwatch.start();
    String countByResultSql = "SELECT\n" + "     INDEXER_ID,\n" + "     RESULT,\n" + "     count(result) AS count\n" + "   FROM INDEXERAPIACCESS\n" + buildWhereFromStatsRequest(false, statsRequest) + "   GROUP BY INDEXER_ID, RESULT\n" + "   ORDER BY INDEXER_ID, RESULT";
    Map<Integer, Integer> successCountMap = new HashMap<>();
    Map<Integer, Integer> connectionErrorCountMap = new HashMap<>();
    Map<Integer, Integer> allAccessesCountMap = new HashMap<>();
    query = entityManager.createNativeQuery(countByResultSql);
    // query = query.setParameter("indexerIds", indexerIdsToInclude);
    results = query.getResultList();
    for (Object resultObject : results) {
        Object[] array = (Object[]) resultObject;
        Integer indexerId = (Integer) array[0];
        if (!indexerIdsToInclude.contains(indexerId)) {
            continue;
        }
        String result = (String) array[1];
        int count = ((BigInteger) array[2]).intValue();
        if (result.equals(IndexerAccessResult.SUCCESSFUL.name())) {
            successCountMap.put(indexerId, count);
        } else if (result.equals(IndexerAccessResult.CONNECTION_ERROR.name())) {
            connectionErrorCountMap.put(indexerId, count);
        }
        if (allAccessesCountMap.containsKey(indexerId)) {
            allAccessesCountMap.put(indexerId, allAccessesCountMap.get(indexerId) + count);
        } else {
            allAccessesCountMap.put(indexerId, count);
        }
    }
    List<IndexerApiAccessStatsEntry> indexerApiAccessStatsEntries = new ArrayList<>();
    for (Integer id : indexerIdsToInclude) {
        IndexerApiAccessStatsEntry entry = new IndexerApiAccessStatsEntry();
        IndexerEntity indexerEntity = indexerRepository.findOne(id);
        entry.setIndexerName(indexerEntity.getName());
        if (allAccessesCountMap.containsKey(id) && allAccessesCountMap.get(id) != null) {
            if (successCountMap.get(id) != null) {
                Double percentSuccessFul = 100D / (allAccessesCountMap.get(id).doubleValue() / successCountMap.get(id).doubleValue());
                entry.setPercentSuccessful(percentSuccessFul);
            }
            if (connectionErrorCountMap.get(id) != null) {
                Double percentConnectionError = 100D / (allAccessesCountMap.get(id).doubleValue() / connectionErrorCountMap.get(id).doubleValue());
                entry.setPercentConnectionError(percentConnectionError);
            }
        }
        if (accessesPerDayCountMap.containsKey(id) && accessesPerDayCountMap.get(id) != null) {
            entry.setAverageAccessesPerDay(accessesPerDayCountMap.get(id));
        }
        indexerApiAccessStatsEntries.add(entry);
    }
    logger.debug(LoggingMarkers.PERFORMANCE, "Calculating success/failure stats took {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
    return indexerApiAccessStatsEntries;
}
Also used : IndexerEntity(org.nzbhydra.indexers.IndexerEntity) org.nzbhydra.historystats.stats(org.nzbhydra.historystats.stats) java.util(java.util) Logger(org.slf4j.Logger) IndexerConfig(org.nzbhydra.config.IndexerConfig) Stopwatch(com.google.common.base.Stopwatch) java.util.concurrent(java.util.concurrent) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) SearchModuleType(org.nzbhydra.config.SearchModuleType) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) SearchModuleProvider(org.nzbhydra.searching.SearchModuleProvider) Query(javax.persistence.Query) Indexer(org.nzbhydra.indexers.Indexer) IndexerRepository(org.nzbhydra.indexers.IndexerRepository) Entry(java.util.Map.Entry) BigInteger(java.math.BigInteger) IndexerAccessResult(org.nzbhydra.indexers.IndexerAccessResult) LoggingMarkers(org.nzbhydra.logging.LoggingMarkers) Transactional(org.springframework.transaction.annotation.Transactional) Query(javax.persistence.Query) Stopwatch(com.google.common.base.Stopwatch) BigInteger(java.math.BigInteger) IndexerEntity(org.nzbhydra.indexers.IndexerEntity) BigInteger(java.math.BigInteger)

Aggregations

IndexerEntity (org.nzbhydra.indexers.IndexerEntity)5 Test (org.junit.Test)2 IndexerConfig (org.nzbhydra.config.IndexerConfig)2 Indexer (org.nzbhydra.indexers.Indexer)2 Newznab (org.nzbhydra.indexers.Newznab)2 SearchResultEntity (org.nzbhydra.searching.SearchResultEntity)2 Stopwatch (com.google.common.base.Stopwatch)1 BigInteger (java.math.BigInteger)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 java.util.concurrent (java.util.concurrent)1 Collectors (java.util.stream.Collectors)1 EntityManager (javax.persistence.EntityManager)1 PersistenceContext (javax.persistence.PersistenceContext)1 Query (javax.persistence.Query)1 Before (org.junit.Before)1 SearchModuleType (org.nzbhydra.config.SearchModuleType)1 org.nzbhydra.historystats.stats (org.nzbhydra.historystats.stats)1 IndexerAccessResult (org.nzbhydra.indexers.IndexerAccessResult)1 IndexerRepository (org.nzbhydra.indexers.IndexerRepository)1