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=7852bef6548d714103a69f5d5ee102759a376285;hb=6c468636c3790e3420da97dab19057892988fa11;hp=d8ee97071069173f9fbbd94d14ef6828126938ff;hpb=b61264738a459de5f1b9333ee4cb486df9f3b9f4;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 d8ee9707..7852bef6 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 @@ -20,14 +20,13 @@ package org.oransc.enrichment.tasks; -import org.oransc.enrichment.clients.AsyncRestClient; -import org.oransc.enrichment.clients.AsyncRestClientFactory; import org.oransc.enrichment.configuration.ApplicationConfig; -import org.oransc.enrichment.controllers.consumer.ConsumerCallbacks; +import org.oransc.enrichment.controllers.a1e.A1eCallbacks; +import org.oransc.enrichment.controllers.r1producer.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; @@ -37,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 @@ -49,18 +49,15 @@ public class ProducerSupervision { private final EiProducers eiProducers; private final EiJobs eiJobs; - private final EiTypes eiTypes; - private final AsyncRestClient restClient; - private final ConsumerCallbacks consumerCallbacks; + private final ProducerCallbacks producerCallbacks; + private final A1eCallbacks consumerCallbacks; @Autowired public ProducerSupervision(ApplicationConfig applicationConfig, EiProducers eiProducers, EiJobs eiJobs, - EiTypes eiTypes, ConsumerCallbacks consumerCallbacks) { - AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(applicationConfig.getWebClientConfig()); - this.restClient = restClientFactory.createRestClientNoHttpProxy(""); - this.eiJobs = eiJobs; + ProducerCallbacks producerCallbacks, A1eCallbacks consumerCallbacks) { this.eiProducers = eiProducers; - this.eiTypes = eiTypes; + this.eiJobs = eiJobs; + this.producerCallbacks = producerCallbacks; this.consumerCallbacks = consumerCallbacks; } @@ -76,21 +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.consumerCallbacks.notifyConsumersProducerDeleted(producer); + this.eiProducers.deregisterProducer(producer); } }