X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Ftasks%2FProducerSupervision.java;h=d73127f2c90b4c09de7f8bdc5f47f1195b708a73;hb=99bcb01d872b2166ef3b2cb5cf04d346043b5a31;hp=3b62fa74f17ae591f1299a718f6f1eceb6704a6b;hpb=4c4a452097c16debab0177e9e87a33ae17d28e44;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java index 3b62fa74..d73127f2 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,12 +20,13 @@ package org.oransc.enrichment.tasks; -import org.oransc.enrichment.clients.AsyncRestClient; import org.oransc.enrichment.configuration.ApplicationConfig; +import org.oransc.enrichment.controllers.consumer.ConsumerCallbacks; +import org.oransc.enrichment.controllers.producer.ProducerCallbacks; +import org.oransc.enrichment.repository.EiJob; import org.oransc.enrichment.repository.EiJobs; import org.oransc.enrichment.repository.EiProducer; import org.oransc.enrichment.repository.EiProducers; -import org.oransc.enrichment.repository.EiTypes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +36,7 @@ import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; /** * Regularly checks the availability of the EI Producers @@ -45,17 +47,19 @@ import reactor.core.publisher.Mono; public class ProducerSupervision { private static final Logger logger = LoggerFactory.getLogger(ProducerSupervision.class); - @Autowired - ApplicationConfig applicationConfig; - - @Autowired - EiProducers eiProducers; + private final EiProducers eiProducers; + private final EiJobs eiJobs; + private final ProducerCallbacks producerCallbacks; + private final ConsumerCallbacks consumerCallbacks; @Autowired - EiJobs eiJobs; - - @Autowired - EiTypes eiTypes; + public ProducerSupervision(ApplicationConfig applicationConfig, EiProducers eiProducers, EiJobs eiJobs, + ProducerCallbacks producerCallbacks, ConsumerCallbacks consumerCallbacks) { + this.eiProducers = eiProducers; + this.eiJobs = eiJobs; + this.producerCallbacks = producerCallbacks; + this.consumerCallbacks = consumerCallbacks; + } @Scheduled(fixedRate = 1000 * 60 * 5) public void checkAllProducers() { @@ -69,20 +73,36 @@ public class ProducerSupervision { } private Mono checkOneProducer(EiProducer producer) { - return restClient().get(producer.getProducerSupervisionCallbackUrl()) // + return this.producerCallbacks.healthCheck(producer) // .onErrorResume(throwable -> { handleNonRespondingProducer(throwable, producer); return Mono.empty(); })// .doOnNext(response -> handleRespondingProducer(response, producer)) - .flatMap(response -> Mono.just(producer)); + .flatMap(response -> checkProducerJobs(producer)) // + .flatMap(responses -> Mono.just(producer)); + } + + private Mono checkProducerJobs(EiProducer producer) { + final int MAX_CONCURRENCY = 10; + return getEiJobs(producer) // + .filter(eiJob -> !producer.isJobEnabled(eiJob)) // + .flatMap(eiJob -> producerCallbacks.startEiJob(producer, eiJob, Retry.max(1)), MAX_CONCURRENCY) // + .collectList() // + .flatMapMany(startedJobs -> consumerCallbacks.notifyJobStatus(producer.getEiTypes())) // + .collectList(); + } + + private Flux getEiJobs(EiProducer producer) { + return Flux.fromIterable(producer.getEiTypes()) // + .flatMap(eiType -> Flux.fromIterable(eiJobs.getJobsForType(eiType))); } private void handleNonRespondingProducer(Throwable throwable, EiProducer producer) { logger.warn("Unresponsive producer: {} exception: {}", producer.getId(), throwable.getMessage()); producer.setAliveStatus(false); if (producer.isDead()) { - this.eiProducers.deregisterProducer(producer, this.eiTypes, this.eiJobs); + this.eiProducers.deregisterProducer(producer); } } @@ -91,8 +111,4 @@ public class ProducerSupervision { producer.setAliveStatus(true); } - private AsyncRestClient restClient() { - return new AsyncRestClient("", this.applicationConfig.getWebClientConfig()); - } - }