import org.oransc.enrichment.clients.AsyncRestClient;
import org.oransc.enrichment.clients.AsyncRestClientFactory;
import org.oransc.enrichment.configuration.ApplicationConfig;
+import org.oransc.enrichment.configuration.ImmutableHttpProxyConfig;
import org.oransc.enrichment.configuration.ImmutableWebClientConfig;
import org.oransc.enrichment.configuration.WebClientConfig;
+import org.oransc.enrichment.configuration.WebClientConfig.HttpProxyConfig;
import org.oransc.enrichment.controller.ConsumerSimulatorController;
import org.oransc.enrichment.controller.ProducerSimulatorController;
import org.oransc.enrichment.controllers.consumer.ConsumerConsts;
import org.oransc.enrichment.controllers.consumer.ConsumerEiJobInfo;
import org.oransc.enrichment.controllers.consumer.ConsumerEiJobStatus;
import org.oransc.enrichment.controllers.consumer.ConsumerEiTypeInfo;
+import org.oransc.enrichment.controllers.producer.ProducerCallbacks;
import org.oransc.enrichment.controllers.producer.ProducerConsts;
import org.oransc.enrichment.controllers.producer.ProducerJobInfo;
import org.oransc.enrichment.controllers.producer.ProducerRegistrationInfo;
@Autowired
ProducerSupervision producerSupervision;
+ @Autowired
+ ProducerCallbacks producerCallbacks;
+
private static Gson gson = new GsonBuilder().create();
/**
ResponseEntity<String> resp = restClient().getForEntity(url).block();
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
- String indented = (new JSONObject(resp.getBody())).toString(4);
- try (PrintStream out = new PrintStream(new FileOutputStream("../docs/offeredapis/swagger/ecs-api.json"))) {
+ JSONObject jsonObj = new JSONObject(resp.getBody());
+ jsonObj.remove("host");
+ String indented = jsonObj.toString(4);
+ try (PrintStream out = new PrintStream(new FileOutputStream("api/ecs-api.json"))) {
out.print(indented);
}
}
assertThat(this.eiTypes.size()).isEqualTo(1);
EiType type = this.eiTypes.getType(EI_TYPE_ID);
- assertThat(type.getProducerIds()).contains("eiProducerId");
+ assertThat(this.eiProducers.getProducersForType(EI_TYPE_ID).size()).isEqualTo(1);
assertThat(this.eiProducers.size()).isEqualTo(1);
assertThat(this.eiProducers.get("eiProducerId").getEiTypes().iterator().next().getId()).isEqualTo(EI_TYPE_ID);
assertThat(this.eiProducers.size()).isEqualTo(2);
EiType type = this.eiTypes.getType(EI_TYPE_ID);
- assertThat(type.getProducerIds()).contains("eiProducerId");
- assertThat(type.getProducerIds()).contains("eiProducerId2");
+ assertThat(this.eiProducers.getProducerIdsForType(type.getId())).contains("eiProducerId");
+ assertThat(this.eiProducers.getProducerIdsForType(type.getId())).contains("eiProducerId2");
putEiJob(EI_TYPE_ID, "jobId");
assertThat(this.eiJobs.size()).isEqualTo(1);
deleteEiProducer("eiProducerId");
assertThat(this.eiProducers.size()).isEqualTo(1);
- assertThat(this.eiTypes.getType(EI_TYPE_ID).getProducerIds()).doesNotContain("eiProducerId");
+ assertThat(this.eiProducers.getProducerIdsForType(EI_TYPE_ID)).doesNotContain("eiProducerId");
verifyJobStatus("jobId", "ENABLED");
deleteEiProducer("eiProducerId2");
// After 3 failed checks, the producer and the type shall be deregisterred
this.producerSupervision.createTask().blockLast();
- assertThat(this.eiProducers.size()).isEqualTo(0);
- assertThat(this.eiTypes.size()).isEqualTo(0);
+ assertThat(this.eiProducers.size()).isEqualTo(0); // The producer is removed
+ assertThat(this.eiTypes.size()).isEqualTo(0); // The type is removed
verifyJobStatus(EI_JOB_ID, "DISABLED");
// Job disabled status notification shall be received
{
// Restore the jobs
- EiJobs jobs = new EiJobs(this.applicationConfig);
+ EiJobs jobs = new EiJobs(this.applicationConfig, this.producerCallbacks);
jobs.restoreJobsFromDatabase();
assertThat(jobs.size()).isEqualTo(2);
- jobs.remove("jobId1");
- jobs.remove("jobId2");
+ jobs.remove("jobId1", this.eiProducers);
+ jobs.remove("jobId2", this.eiProducers);
}
{
// Restore the jobs, no jobs in database
- EiJobs jobs = new EiJobs(this.applicationConfig);
+ EiJobs jobs = new EiJobs(this.applicationConfig, this.producerCallbacks);
jobs.restoreJobsFromDatabase();
assertThat(jobs.size()).isEqualTo(0);
}
logger.warn("Test removing a job when the db file is gone");
- this.eiJobs.remove("jobId1");
+ this.eiJobs.remove("jobId1", this.eiProducers);
assertThat(this.eiJobs.size()).isEqualTo(1);
+
+ ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults();
+ await().untilAsserted(() -> assertThat(simulatorResults.jobsStopped.size()).isEqualTo(3));
+ }
+
+ @Test
+ void testEiTypesDatabase() throws Exception {
+ putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID);
+
+ assertThat(this.eiTypes.size()).isEqualTo(1);
+
+ {
+ // Restore the types
+ EiTypes types = new EiTypes(this.applicationConfig);
+ types.restoreTypesFromDatabase();
+ assertThat(types.size()).isEqualTo(1);
+
+ }
+ {
+ // Restore the jobs, no jobs in database
+ EiTypes types = new EiTypes(this.applicationConfig);
+ types.clear();
+ types.restoreTypesFromDatabase();
+ assertThat(types.size()).isEqualTo(0);
+ }
+ logger.warn("Test removing a job when the db file is gone");
+ this.eiTypes.remove(this.eiTypes.getType(EI_TYPE_ID));
+ assertThat(this.eiJobs.size()).isEqualTo(0);
}
private void deleteEiProducer(String eiProducerId) {
String body = gson.toJson(producerEiRegistratioInfo(eiTypeId));
restClient().putForEntity(url, body).block();
+
return this.eiTypes.getType(eiTypeId);
}
private AsyncRestClient restClient(boolean useTrustValidation) {
WebClientConfig config = this.applicationConfig.getWebClientConfig();
+ HttpProxyConfig httpProxyConfig = ImmutableHttpProxyConfig.builder() //
+ .httpProxyHost("") //
+ .httpProxyPort(0) //
+ .build();
config = ImmutableWebClientConfig.builder() //
.keyStoreType(config.keyStoreType()) //
.keyStorePassword(config.keyStorePassword()) //
.isTrustStoreUsed(useTrustValidation) //
.trustStore(config.trustStore()) //
.trustStorePassword(config.trustStorePassword()) //
- .build();
+ .httpProxyConfig(httpProxyConfig).build();
AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config);
- return restClientFactory.createRestClient(baseUrl());
+ return restClientFactory.createRestClientNoHttpProxy(baseUrl());
}
private AsyncRestClient restClient() {