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