Search in sources :

Example 1 with CheckCapsResponse

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);
        }
    });
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) CheckCapsResponse(org.nzbhydra.indexers.capscheck.CheckCapsResponse) Before(org.junit.Before)

Example 2 with CheckCapsResponse

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");
    }
}
Also used : java.util(java.util) CheckCapsResponse(org.nzbhydra.indexers.capscheck.CheckCapsResponse) URL(java.net.URL) Strings(joptsimple.internal.Strings) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) BackendType(org.nzbhydra.indexers.Indexer.BackendType) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) NewznabChecker(org.nzbhydra.indexers.capscheck.NewznabChecker) Category(org.nzbhydra.config.Category) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) java.util.concurrent(java.util.concurrent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IdType(org.nzbhydra.mediainfo.InfoProvider.IdType) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ActionAttribute(org.nzbhydra.mapping.newznab.ActionAttribute) CategoryProvider(org.nzbhydra.searching.CategoryProvider) Component(org.springframework.stereotype.Component) org.nzbhydra.migration.configmapping(org.nzbhydra.migration.configmapping) Data(lombok.Data) MigrationMessageEvent(org.nzbhydra.migration.FromPythonMigration.MigrationMessageEvent) AllArgsConstructor(lombok.AllArgsConstructor) org.nzbhydra.config(org.nzbhydra.config) CheckCapsResponse(org.nzbhydra.indexers.capscheck.CheckCapsResponse)

Aggregations

CheckCapsResponse (org.nzbhydra.indexers.capscheck.CheckCapsResponse)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 java.util (java.util)1 java.util.concurrent (java.util.concurrent)1 Collectors (java.util.stream.Collectors)1 Strings (joptsimple.internal.Strings)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 org.nzbhydra.config (org.nzbhydra.config)1 Category (org.nzbhydra.config.Category)1 BackendType (org.nzbhydra.indexers.Indexer.BackendType)1 NewznabChecker (org.nzbhydra.indexers.capscheck.NewznabChecker)1