/*-
* ========================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
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.repository.EiJobs;
import org.oransc.enrichment.repository.EiProducer;
import org.oransc.enrichment.repository.EiProducers;
public class ProducerSupervision {
private static final Logger logger = LoggerFactory.getLogger(ProducerSupervision.class);
- @Autowired
- ApplicationConfig applicationConfig;
-
- @Autowired
- EiProducers eiProducers;
-
- @Autowired
- EiJobs eiJobs;
+ private final EiProducers eiProducers;
+ private final EiJobs eiJobs;
+ private final EiTypes eiTypes;
+ private final AsyncRestClient restClient;
+ private final ConsumerCallbacks consumerCallbacks;
@Autowired
- EiTypes eiTypes;
+ public ProducerSupervision(ApplicationConfig applicationConfig, EiProducers eiProducers, EiJobs eiJobs,
+ EiTypes eiTypes, ConsumerCallbacks consumerCallbacks) {
+ AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(applicationConfig.getWebClientConfig());
+ this.restClient = restClientFactory.createRestClient("");
+ this.eiJobs = eiJobs;
+ this.eiProducers = eiProducers;
+ this.eiTypes = eiTypes;
+ this.consumerCallbacks = consumerCallbacks;
+ }
@Scheduled(fixedRate = 1000 * 60 * 5)
public void checkAllProducers() {
}
private Mono<EiProducer> checkOneProducer(EiProducer producer) {
- return restClient().get(producer.getProducerSupervisionCallbackUrl()) //
+ return restClient.get(producer.getProducerSupervisionCallbackUrl()) //
.onErrorResume(throwable -> {
handleNonRespondingProducer(throwable, producer);
return Mono.empty();
producer.setAliveStatus(false);
if (producer.isDead()) {
this.eiProducers.deregisterProducer(producer, this.eiTypes, this.eiJobs);
+ this.consumerCallbacks.notifyConsumersProducerDeleted(producer);
}
}
producer.setAliveStatus(true);
}
- private AsyncRestClient restClient() {
- return new AsyncRestClient("", this.applicationConfig.getWebClientConfig());
- }
-
}