X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Fclients%2FProducerCallbacks.java;h=7f28a12bac4b787b372ce38396f2f2196f504ab9;hb=5d97a401dc1e26f64ad57daab90f924da9c12c64;hp=07b188d96b1953bd3025207378c0de974f6f84ed;hpb=17041db5ec17da3beb56b962e7a2cca79ca6ff59;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java index 07b188d9..7f28a12b 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java @@ -26,14 +26,15 @@ import com.google.gson.GsonBuilder; import java.lang.invoke.MethodHandles; import org.oransc.enrichment.configuration.ApplicationConfig; -import org.oransc.enrichment.configuration.ImmutableWebClientConfig; -import org.oransc.enrichment.configuration.WebClientConfig; import org.oransc.enrichment.repository.EiJob; import org.oransc.enrichment.repository.EiProducer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + /** * Callbacks to the EiProducer */ @@ -48,47 +49,52 @@ public class ProducerCallbacks { @Autowired ApplicationConfig applicationConfig; - public void notifyProducersJobCreated(EiJob eiJob) { - for (EiProducer producer : eiJob.type().getProducers()) { - notifyProducerJobStarted(producer, eiJob); - } - } - public void notifyProducersJobDeleted(EiJob eiJob) { - AsyncRestClient restClient = restClient(false); + AsyncRestClient restClient = restClient(); ProducerJobInfo request = new ProducerJobInfo(eiJob); String body = gson.toJson(request); for (EiProducer producer : eiJob.type().getProducers()) { - restClient.post(producer.jobDeletionCallbackUrl(), body) // - .subscribe(notUsed -> logger.debug("Job subscription started OK {}", producer.id()), // - throwable -> logger.warn("Job subscription failed {}", producer.id(), throwable.toString()), null); + restClient.post(producer.getJobDeletionCallbackUrl(), body) // + .subscribe(notUsed -> logger.debug("Job deleted OK {}", producer.getId()), // + throwable -> logger.warn("Job delete failed {}", producer.getId(), throwable.toString()), null); } } - public void notifyProducerJobStarted(EiProducer producer, EiJob eiJob) { - AsyncRestClient restClient = restClient(false); + /** + * Calls all producers for an EiJob activation. + * + * @param eiJob an EI job + * @return the number of producers that returned OK + */ + public Mono notifyProducersJobStarted(EiJob eiJob) { + return Flux.fromIterable(eiJob.type().getProducers()) // + .flatMap(eiProducer -> notifyProducerJobStarted(eiProducer, eiJob)) // + .collectList() // + .flatMap(okResponses -> Mono.just(Integer.valueOf(okResponses.size()))); // + } + + /** + * Calls one producer for an EiJob activation. + * + * @param producer a producer + * @param eiJob an EI job + * @return the body of the response from the REST call + */ + public Mono notifyProducerJobStarted(EiProducer producer, EiJob eiJob) { + AsyncRestClient restClient = restClient(); ProducerJobInfo request = new ProducerJobInfo(eiJob); String body = gson.toJson(request); - restClient.post(producer.jobCreationCallbackUrl(), body) // - .subscribe(notUsed -> logger.debug("Job subscription started OK {}", producer.id()), // - throwable -> logger.warn("Job subscription failed {}", producer.id(), throwable.toString()), null); - + return restClient.post(producer.getJobCreationCallbackUrl(), body) + .doOnNext(resp -> logger.debug("Job subscription started OK {}", producer.getId())) + .onErrorResume(throwable -> { + logger.warn("Job subscription failed {}", producer.getId(), throwable.toString()); + return Mono.empty(); + }); } - private AsyncRestClient restClient(boolean useTrustValidation) { - WebClientConfig config = this.applicationConfig.getWebClientConfig(); - config = ImmutableWebClientConfig.builder() // - .keyStoreType(config.keyStoreType()) // - .keyStorePassword(config.keyStorePassword()) // - .keyStore(config.keyStore()) // - .keyPassword(config.keyPassword()) // - .isTrustStoreUsed(useTrustValidation) // - .trustStore(config.trustStore()) // - .trustStorePassword(config.trustStorePassword()) // - .build(); - - return new AsyncRestClient("", config); + private AsyncRestClient restClient() { + return new AsyncRestClient("", this.applicationConfig.getWebClientConfig()); } }