use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class SearchModuleProvider method loadIndexers.
/**
* Must be called by <tt>{@link SearchModuleConfigProvider}</tt> when config is loaded.
*/
@Transactional
public void loadIndexers(List<IndexerConfig> indexers) {
if (indexers == null) {
logger.error("Indexers not set. Check your configuration");
return;
}
logger.info("Loading indexers");
searchModuleInstances.clear();
for (IndexerConfig config : indexers) {
try {
Optional<IndexerHandlingStrategy> optionalStrategy = indexerHandlingStrategies.stream().filter(x -> x.handlesIndexerConfig(config)).findFirst();
if (!optionalStrategy.isPresent()) {
logger.error("Unable to find implementation for indexer type {} and host {}", config.getSearchModuleType(), config.getHost());
continue;
}
Indexer searchModule = beanFactory.createBean(optionalStrategy.get().getIndexerClass());
logger.info("Initializing indexer {}", config.getName());
IndexerEntity indexerEntity = indexerRepository.findByName(config.getName());
if (indexerEntity == null) {
logger.info("Indexer with name {} not yet in database. Adding it", config.getName());
indexerEntity = new IndexerEntity();
indexerEntity.setName(config.getName());
indexerEntity = indexerRepository.save(indexerEntity);
logger.info("Now {} indexers in database", indexerRepository.count());
}
searchModule.initialize(config, indexerEntity);
searchModuleInstances.put(config.getName(), searchModule);
} catch (Exception e) {
logger.error("Unable to instantiate indexer with name {} and type {}", config.getName(), config.getSearchModuleType(), e);
}
}
List<String> indexerNames = indexers.stream().map(IndexerConfig::getName).collect(Collectors.toList());
Collection<IndexerEntity> byNameNotIn = indexerRepository.findByNameNotIn(indexerNames);
if (!byNameNotIn.isEmpty()) {
logger.info("Found {} indexers in database which are not configured. Will delete them and any related database entries. This may take some time", byNameNotIn.size());
indexerRepository.delete(byNameNotIn);
}
if (searchModuleInstances.isEmpty()) {
logger.warn("No indexers configured");
}
}
use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class Experiments method createSimpleYaml.
@Test
@Ignore
public void createSimpleYaml() throws IOException, InterruptedException {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
objectMapper.registerModule(new Jdk8Module());
IndexerConfig indexerConfig = new IndexerConfig();
indexerConfig.setCategoryMapping(new IndexerCategoryConfig());
BaseConfig baseConfig = new BaseConfig();
baseConfig.setIndexers(Arrays.asList(indexerConfig));
String s = objectMapper.writeValueAsString(baseConfig);
System.out.println(s);
objectMapper.readValue(s, BaseConfig.class);
}
use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class IndexerForSearchSelector method checkIndexerHitLimit.
protected boolean checkIndexerHitLimit(Indexer indexer) {
Stopwatch stopwatch = Stopwatch.createStarted();
IndexerConfig indexerConfig = indexer.getConfig();
if (!indexerConfig.getHitLimit().isPresent() && !indexerConfig.getDownloadLimit().isPresent()) {
return true;
}
LocalDateTime comparisonTime;
LocalDateTime now = LocalDateTime.now(clock);
if (indexerConfig.getHitLimitResetTime().isPresent()) {
comparisonTime = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get());
if (comparisonTime.isAfter(now)) {
comparisonTime = comparisonTime.minus(1, ChronoUnit.DAYS);
}
} else {
comparisonTime = now.minus(1, ChronoUnit.DAYS);
}
if (indexerConfig.getHitLimit().isPresent()) {
Query query = entityManager.createNativeQuery("SELECT x.TIME FROM INDEXERAPIACCESS_SHORT x WHERE x.INDEXER_ID = (:indexerId) ORDER BY TIME DESC LIMIT (:hitLimit)");
query.setParameter("indexerId", indexer.getIndexerEntity().getId());
query.setParameter("hitLimit", indexerConfig.getHitLimit().get());
List resultList = query.getResultList();
if (resultList.size() == indexerConfig.getHitLimit().get()) {
// Found as many as we want, so now we must check if they're all in the time window
Instant earliestAccess = ((Timestamp) Iterables.getLast(resultList)).toInstant();
if (earliestAccess.isAfter(comparisonTime.toInstant(ZoneOffset.UTC))) {
LocalDateTime nextPossibleHit = calculateNextPossibleHit(indexerConfig, earliestAccess);
String message = String.format("Not using %s because all %d allowed API hits were already made. The next API hit should be possible at %s", indexerConfig.getName(), indexerConfig.getHitLimit().get(), nextPossibleHit);
logger.debug(LoggingMarkers.PERFORMANCE, "Detection of API limit reached took {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
return handleIndexerNotSelected(indexer, message, "API hit limit reached");
}
}
}
if (indexerConfig.getDownloadLimit().isPresent()) {
Page<FileDownloadEntity> page = nzbDownloadRepository.findBySearchResultIndexerOrderByTimeDesc(indexer.getIndexerEntity(), new PageRequest(0, indexerConfig.getDownloadLimit().get()));
if (page.getContent().size() == indexerConfig.getDownloadLimit().get() && Iterables.getLast(page.getContent()).getTime().isAfter(comparisonTime.toInstant(ZoneOffset.UTC))) {
LocalDateTime nextPossibleHit = calculateNextPossibleHit(indexerConfig, page.getContent().get(page.getContent().size() - 1).getTime());
String message = String.format("Not using %s because all %d allowed download were already made. The next download should be possible at %s", indexerConfig.getName(), indexerConfig.getDownloadLimit().get(), nextPossibleHit);
logger.debug(LoggingMarkers.PERFORMANCE, "Detection of download limit reached took {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
return handleIndexerNotSelected(indexer, message, "Download limit reached");
}
}
logger.debug(LoggingMarkers.PERFORMANCE, "Detection if hit limits were reached for indexer {} took {}ms", indexer.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
return true;
}
use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class SslTest method shouldBeAbleToAccessSSL.
@Test
public void shouldBeAbleToAccessSSL() throws Exception {
configProvider.getBaseConfig().getMain().setVerifySsl(false);
IndexerConfig config = new IndexerConfig();
config.setTimeout(99999);
binsearch.initialize(config, new IndexerEntity());
// Would not work with SNI disabled
binsearch.callInderWebAccess(URI.create("https://binsearch.info"), String.class);
nzbGeek.initialize(config, new IndexerEntity());
// Would not work with SNI enabled
nzbGeek.callInderWebAccess(URI.create("https://nzbgeek.info/"), String.class);
}
use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class AnizbTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
testee.config = new IndexerConfig();
testee.config.setName("anizb");
testee.config.setHost("https://anizb.org");
}
Aggregations