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%2Fcontrollers%2Fproducer%2FProducerCallbacks.java;h=dc732e12fff97b42b87bd6361f47533a1662deb4;hb=3ac4de0524650cea3d17f9ad5ff7e9cf5dffbe83;hp=5a47b58f60f61841a204258584f1b8924b965669;hpb=b65d77a754c356931b82c8edf6b29759d294ea51;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java index 5a47b58f..dc732e12 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerCallbacks.java @@ -24,6 +24,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.lang.invoke.MethodHandles; +import java.time.Duration; import java.util.Collection; import java.util.Vector; @@ -31,6 +32,7 @@ import org.oransc.enrichment.clients.AsyncRestClient; import org.oransc.enrichment.clients.AsyncRestClientFactory; import org.oransc.enrichment.configuration.ApplicationConfig; import org.oransc.enrichment.repository.EiJob; +import org.oransc.enrichment.repository.EiJobs; import org.oransc.enrichment.repository.EiProducer; import org.oransc.enrichment.repository.EiTypes; import org.slf4j.Logger; @@ -40,6 +42,7 @@ import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; /** * Callbacks to the EiProducer @@ -63,7 +66,7 @@ public class ProducerCallbacks { public void notifyProducersJobDeleted(EiJob eiJob) { for (EiProducer producer : getProducers(eiJob)) { - String url = producer.getJobCallbackUrl() + "/" + eiJob.id(); + String url = producer.getJobCallbackUrl() + "/" + eiJob.getId(); restClient.delete(url) // .subscribe(notUsed -> logger.debug("Producer job deleted OK {}", producer.getId()), // throwable -> logger.warn("Producer job delete failed {} {}", producer.getId(), @@ -79,25 +82,40 @@ public class ProducerCallbacks { * @return the number of producers that returned OK */ public Mono notifyProducersJobStarted(EiJob eiJob) { + Retry retrySpec = Retry.fixedDelay(1, Duration.ofSeconds(1)); return Flux.fromIterable(getProducers(eiJob)) // - .flatMap(eiProducer -> notifyProducerJobStarted(eiProducer, eiJob)) // + .flatMap(eiProducer -> notifyProducerJobStarted(eiProducer, eiJob, retrySpec)) // .collectList() // .flatMap(okResponses -> Mono.just(Integer.valueOf(okResponses.size()))); // } /** - * Calls one producer for an EiJob activation. + * Restart all jobs for one producer * - * @param producer a producer - * @param eiJob an EI job - * @return the body of the response from the REST call + * @param producer + * @param eiJobs */ - public Mono notifyProducerJobStarted(EiProducer producer, EiJob eiJob) { + public void restartJobs(EiProducer producer, EiJobs eiJobs) { + final int maxNoOfParalellRequests = 10; + Retry retrySpec = Retry.backoff(3, Duration.ofSeconds(1)); + + Flux.fromIterable(producer.getEiTypes()) // + .flatMap(type -> Flux.fromIterable(eiJobs.getJobsForType(type))) // + .flatMap(job -> notifyProducerJobStarted(producer, job, retrySpec), maxNoOfParalellRequests) // + .onErrorResume(t -> { + logger.error("Could not restart EI Job for producer: {}, reason :{}", producer.getId(), t.getMessage()); + return Flux.empty(); + }) // + .subscribe(); + } + + private Mono notifyProducerJobStarted(EiProducer producer, EiJob eiJob, Retry retrySpec) { ProducerJobInfo request = new ProducerJobInfo(eiJob); String body = gson.toJson(request); - return restClient.post(producer.getJobCallbackUrl(), body) - .doOnNext(resp -> logger.debug("Job subscription started OK {}", producer.getId())) + return restClient.post(producer.getJobCallbackUrl(), body) // + .retryWhen(retrySpec) // + .doOnNext(resp -> logger.debug("Job subscription {} started OK {}", eiJob.getId(), producer.getId())) // .onErrorResume(throwable -> { logger.warn("Job subscription failed {}", producer.getId(), throwable.toString()); return Mono.empty(); @@ -106,7 +124,7 @@ public class ProducerCallbacks { private Collection getProducers(EiJob eiJob) { try { - return this.eiTypes.getType(eiJob.typeId()).getProducers(); + return this.eiTypes.getType(eiJob.getTypeId()).getProducers(); } catch (Exception e) { return new Vector<>(); }