use of org.nzbhydra.indexers.capscheck.CheckCapsResponse in project nzbhydra2 by theotherp.
the class ConfigMigrationTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(baseConfig.getCategoriesConfig()).thenReturn(categoriesConfigMock);
BaseConfig baseConfig = new BaseConfig();
baseConfig.getMain().setPort(5076);
when(configProviderMock.getBaseConfig()).thenReturn(baseConfig, this.baseConfig);
when(categoryProviderMock.getCategories()).thenReturn(Arrays.asList(categoryMock1, categoryMock2, animeCategory, audioCategory));
when(categoryMock1.getName()).thenReturn("Movies");
when(categoryMock2.getName()).thenReturn("Movies HD");
when(this.baseConfig.getCategoriesConfig()).thenReturn(categoriesConfigMock);
baseConfig.getCategoriesConfig().setCategories(Arrays.asList(animeCategory, audioCategory));
when(newznabCheckerMock.checkCaps(any(IndexerConfig.class))).thenAnswer(new Answer<CheckCapsResponse>() {
@Override
public CheckCapsResponse answer(InvocationOnMock invocation) throws Throwable {
IndexerConfig config = invocation.getArgument(0);
config.setConfigComplete(true);
config.setAllCapsChecked(true);
return new CheckCapsResponse(invocation.getArgument(0), true, true);
}
});
}
use of org.nzbhydra.indexers.capscheck.CheckCapsResponse in project nzbhydra2 by theotherp.
the class JsonConfigMigration method checkCapsForEnabledNewznabIndexers.
private void checkCapsForEnabledNewznabIndexers(List<String> messages, Map<String, Boolean> originalEnabledState, List<IndexerConfig> indexerConfigs) {
List<IndexerConfig> enabledNewznabIndexers = indexerConfigs.stream().filter(x -> (x.getSearchModuleType() == SearchModuleType.NEWZNAB || x.getSearchModuleType() == SearchModuleType.TORZNAB) && originalEnabledState.get(x.getName())).collect(Collectors.toList());
if (!enabledNewznabIndexers.isEmpty()) {
logger.info("Checking caps and getting category mapping infos for all previously enabled newznab/torznab indexers");
ExecutorService executor = Executors.newFixedThreadPool(enabledNewznabIndexers.size());
List<Callable<CheckCapsResponse>> callables = enabledNewznabIndexers.stream().<Callable<CheckCapsResponse>>map(indexerConfig -> () -> newznabChecker.checkCaps(indexerConfig)).collect(Collectors.toList());
try {
List<Future<CheckCapsResponse>> futures = executor.invokeAll(callables);
for (Future<CheckCapsResponse> future : futures) {
try {
CheckCapsResponse checkCapsRespone = future.get();
IndexerConfig indexerConfig = checkCapsRespone.getIndexerConfig();
if (checkCapsRespone.isConfigComplete()) {
logger.info("Successfully checked caps of {}. Setting it enabled now", indexerConfig.getName());
indexerConfig.setState(IndexerConfig.State.ENABLED);
indexerConfig = checkCapsRespone.getIndexerConfig();
enabledNewznabIndexers.set(enabledNewznabIndexers.indexOf(indexerConfig), indexerConfig);
if (!checkCapsRespone.isAllCapsChecked()) {
logAsWarningAndAdd(messages, "The caps check for " + indexerConfig.getName() + " was not completed. You should trigger it manually from the config at a later point.");
}
} else {
logAsWarningAndAdd(messages, "Caps check for " + indexerConfig.getName() + " failed. You'll need to repeat it manually from the config section before you can use the indexer");
}
} catch (ExecutionException e) {
logAsWarningAndAdd(messages, "Caps check for an indexer failed. You'll need to repeat it manually from the config section before you can use the indexer");
}
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
executor.shutdown();
}
}
boolean anyDisabledNewznabIndexer = indexerConfigs.stream().anyMatch(x -> (x.getSearchModuleType() == SearchModuleType.NEWZNAB || x.getSearchModuleType() == SearchModuleType.TORZNAB) && originalEnabledState.get(x.getName()));
if (anyDisabledNewznabIndexer) {
logAsWarningAndAdd(messages, "Disabled newznab indexer(s) need to be caps-checked before they can be enabled");
}
}
Aggregations