X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Fclients%2FProducerCallbacks.java;h=9b238654ce1006d73ad8919f587209485fca2995;hb=b5aa1b04fe2cf730c434e3d5d103b3ab357f2292;hp=f42c6e34ac42605938866cb2bfc0583757e1f583;hpb=6a1eb6e2a6538decc54f5348fcb1589f5b829e68;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 f42c6e34..9b238654 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,13 +26,10 @@ 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; @@ -48,20 +45,29 @@ public class ProducerCallbacks { .serializeNulls() // .create(); // - @Autowired - ApplicationConfig applicationConfig; + private final AsyncRestClient restClient; + + public ProducerCallbacks(ApplicationConfig config) { + AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig()); + this.restClient = restClientFactory.createRestClient(""); + } public void notifyProducersJobDeleted(EiJob eiJob) { - AsyncRestClient restClient = restClient(false); 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); } } + /** + * 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)) // @@ -69,32 +75,23 @@ public class ProducerCallbacks { .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(false); ProducerJobInfo request = new ProducerJobInfo(eiJob); String body = gson.toJson(request); - return restClient.post(producer.jobCreationCallbackUrl(), body) - .doOnNext(resp -> logger.debug("Job subscription started OK {}", producer.id())) + return restClient.post(producer.getJobCreationCallbackUrl(), body) + .doOnNext(resp -> logger.debug("Job subscription started OK {}", producer.getId())) .onErrorResume(throwable -> { - logger.warn("Job subscription failed {}", producer.id(), throwable.toString()); + 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); - } - }