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);
}
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));
}
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));
}
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));
}
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;
}
Aggregations