Search in sources :

Example 16 with Datasource

use of io.openk9.model.Datasource in project openk9 by smclab.

the class InitDataActivator method activate.

@Activate
void activate(BundleContext bundleContext) throws Exception {
    Bundle bundle = bundleContext.getBundle();
    Tenant tenant = _jsonFileToObj(bundle, "tenant.json", Tenant.class);
    Datasource datasource = _jsonFileToObj(bundle, "datasource.json", Datasource.class);
    EnrichItem enrichItem = _jsonFileToObj(bundle, "enrich-item.json", EnrichItem.class);
    EnrichPipeline enrichPipeline = _jsonFileToObj(bundle, "enrich-pipeline.json", EnrichPipeline.class);
    _disposable = _tenantRepository.findByVirtualHost(tenant.getVirtualHost()).thenEmpty(_tenantRepository.insert(tenant).then(_datasourceRepository.insert(datasource)).then(_enrichItemRepository.insert(enrichItem)).then(_enrichPipelineRepository.insert(enrichPipeline)).then(Mono.empty())).subscribe();
}
Also used : Datasource(io.openk9.model.Datasource) Tenant(io.openk9.model.Tenant) Bundle(org.osgi.framework.Bundle) EnrichPipeline(io.openk9.model.EnrichPipeline) EnrichItem(io.openk9.model.EnrichItem) Activate(org.osgi.service.component.annotations.Activate)

Example 17 with Datasource

use of io.openk9.model.Datasource in project openk9 by smclab.

the class BasePluginDriver method invokeDataParser.

@Override
public Mono<Void> invokeDataParser(Datasource datasource, Date fromDate, Date toDate) {
    String jsonConfig = datasource.getJsonConfig();
    JsonNode jsonNode = getJsonFactory().fromJsonToJsonNode(jsonConfig);
    ObjectNode objectNode = jsonNode.toObjectNode();
    ObjectNode requestJson = getJsonFactory().createObjectNode();
    objectNode.stream().filter(e -> _containsKey(e.getKey())).forEach(e -> requestJson.set(e.getKey(), e.getValue()));
    requestJson.put("timestamp", fromDate.getTime());
    requestJson.put("datasourceId", datasource.getDatasourceId());
    Map<String, Object> headers = headersObject();
    Publisher<byte[]> request = getHttpClient().request(method(), path(), requestJson.toString(), headers);
    return Mono.from(request).then();
}
Also used : Arrays(java.util.Arrays) Datasource(io.openk9.model.Datasource) Date(java.util.Date) JsonNode(io.openk9.json.api.JsonNode) Publisher(org.reactivestreams.Publisher) Map(java.util.Map) ObjectNode(io.openk9.json.api.ObjectNode) Mono(reactor.core.publisher.Mono) HttpClient(io.openk9.http.client.HttpClient) Collectors(java.util.stream.Collectors) JsonFactory(io.openk9.json.api.JsonFactory) ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode)

Example 18 with Datasource

use of io.openk9.model.Datasource in project openk9 by smclab.

the class SchedulerListHttpHandler method apply.

@Override
public Publisher<Void> apply(HttpServerRequest httpRequest, HttpServerResponse httpResponse) {
    return _httpResponseWriter.write(httpResponse, Mono.defer(() -> {
        Map<String, ScheduleOptions> jobs;
        try {
            jobs = _scheduler.getJobs();
        } catch (SchedulerError schedulerError) {
            throw new SchedulerException(schedulerError);
        }
        Set<String> jobNames = jobs.keySet();
        Function<Datasource, Optional<String>> findJobName = datasource -> jobNames.stream().filter(e -> e.endsWith("-" + datasource.getName())).findFirst();
        return _datasourceRepository.findAll(true).concatMap(datasource -> {
            Optional<String> jobNameOptional = findJobName.apply(datasource);
            if (jobNameOptional.isPresent()) {
                ObjectNode objectNode = _jsonFactory.createObjectNode();
                objectNode.put("datasourceId", datasource.getDatasourceId());
                objectNode.put("scheduling", datasource.getScheduling());
                objectNode.put("datasourceName", datasource.getName());
                objectNode.put("jobName", jobNameOptional.get());
                return Mono.just(objectNode.toMap());
            } else {
                return Mono.empty();
            }
        }).collectList();
    }));
}
Also used : Function(java.util.function.Function) SchedulerError(org.apache.karaf.scheduler.SchedulerError) SchedulerException(io.openk9.sql.scheduler.web.exception.SchedulerException) Set(java.util.Set) ObjectNode(io.openk9.json.api.ObjectNode) Map(java.util.Map)

Aggregations

Datasource (io.openk9.model.Datasource)12 Mono (reactor.core.publisher.Mono)11 List (java.util.List)9 Activate (org.osgi.service.component.annotations.Activate)9 Component (org.osgi.service.component.annotations.Component)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 JsonFactory (io.openk9.json.api.JsonFactory)8 PluginDriverManagerClient (io.openk9.plugin.driver.manager.client.api.PluginDriverManagerClient)8 Map (java.util.Map)8 Reference (org.osgi.service.component.annotations.Reference)8 PluginDriverDTO (io.openk9.plugin.driver.manager.model.PluginDriverDTO)7 Collectors (java.util.stream.Collectors)7 DatasourceClient (io.openk9.datasource.client.api.DatasourceClient)6 RouterHandler (io.openk9.http.web.RouterHandler)6 Tenant (io.openk9.model.Tenant)6 HashMap (java.util.HashMap)6 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)6 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)6 HttpResponseWriter (io.openk9.http.util.HttpResponseWriter)5