Search in sources :

Example 1 with JobConfiguration

use of org.apache.plc4x.java.scraper.config.JobConfiguration in project plc4x by apache.

the class ScraperConfigurationTest method parseJobs_fromString.

@Test
void parseJobs_fromString() throws IOException {
    String yaml = "sources:\n" + "    a1: b\n" + "    a2: b\n" + "    a3: b\n" + "jobs:\n" + "    - name: job1\n" + "      scrapeRate: 10\n" + "      sources:\n" + "        - a1\n" + "        - a2\n" + "        - a3\n" + "      fields:\n" + "        a: DBasdf\n" + "        b: DBbsdf\n";
    ScraperConfiguration configuration = mapper.readValue(yaml, ScraperConfigurationClassicImpl.class);
    assertThat(configuration.getJobConfigurations()).hasSize(1);
    JobConfiguration conf = configuration.getJobConfigurations().get(0);
    assertThat(configuration.getSources()).isNotEmpty().hasSize(3).containsEntry("a1", "b").containsEntry("a2", "b").containsEntry("a3", "b");
    assertThat(conf.getName()).isEqualTo("job1");
    assertThat(conf.getScrapeRate()).isEqualTo(10);
    assertThat(conf.getSources()).hasSize(3);
    assertThat(conf.getFields()).hasSize(2).containsEntry("a", "DBasdf").containsEntry("b", "DBbsdf");
}
Also used : ScraperConfiguration(org.apache.plc4x.java.scraper.config.ScraperConfiguration) JobConfiguration(org.apache.plc4x.java.scraper.config.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with JobConfiguration

use of org.apache.plc4x.java.scraper.config.JobConfiguration in project plc4x by apache.

the class ScraperConfigurationTriggeredImpl method getJobs.

public static List<ScrapeJob> getJobs(List<JobConfigurationImpl> jobConfigurations, Map<String, String> sources) throws ScraperConfigurationException {
    List<ScrapeJob> scrapeJobs = new ArrayList<>();
    for (JobConfiguration jobConfiguration : jobConfigurations) {
        if (jobConfiguration.getTriggerConfig() != null) {
            logger.info("Assuming job as triggered job because triggerConfig has been set");
            scrapeJobs.add(new TriggeredScrapeJobImpl(jobConfiguration.getName(), jobConfiguration.getTriggerConfig(), getSourcesForAliases(jobConfiguration.getSources(), sources), jobConfiguration.getFields()));
        } else {
            if (jobConfiguration.getScrapeRate() != null) {
                logger.info("Assuming job as classic job because triggerConfig has NOT been set but scrapeRate has.");
                scrapeJobs.add(new ScrapeJobImpl(jobConfiguration.getName(), jobConfiguration.getScrapeRate(), getSourcesForAliases(jobConfiguration.getSources(), sources), jobConfiguration.getFields()));
            } else {
                logger.info("Job has lack of trigger/scheduled config");
                throw new ScraperConfigurationException(String.format("Job %s was intended to be o triggered annotation, but no triggerConfig-Field could be found. Canceling!", jobConfiguration.getName()));
            }
        }
    }
    return scrapeJobs;
}
Also used : ScrapeJob(org.apache.plc4x.java.scraper.ScrapeJob) TriggeredScrapeJobImpl(org.apache.plc4x.java.scraper.triggeredscraper.TriggeredScrapeJobImpl) ScrapeJobImpl(org.apache.plc4x.java.scraper.ScrapeJobImpl) ScraperConfigurationException(org.apache.plc4x.java.scraper.exception.ScraperConfigurationException) ArrayList(java.util.ArrayList) TriggeredScrapeJobImpl(org.apache.plc4x.java.scraper.triggeredscraper.TriggeredScrapeJobImpl) JobConfiguration(org.apache.plc4x.java.scraper.config.JobConfiguration)

Aggregations

JobConfiguration (org.apache.plc4x.java.scraper.config.JobConfiguration)2 ArrayList (java.util.ArrayList)1 ScrapeJob (org.apache.plc4x.java.scraper.ScrapeJob)1 ScrapeJobImpl (org.apache.plc4x.java.scraper.ScrapeJobImpl)1 ScraperConfiguration (org.apache.plc4x.java.scraper.config.ScraperConfiguration)1 ScraperConfigurationException (org.apache.plc4x.java.scraper.exception.ScraperConfigurationException)1 TriggeredScrapeJobImpl (org.apache.plc4x.java.scraper.triggeredscraper.TriggeredScrapeJobImpl)1 Test (org.junit.jupiter.api.Test)1