X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Fcontrollers%2Fr1consumer%2FConsumerController.java;h=18897c3055ffec4f291be7d3e899d7e575a77fdc;hb=495008908a7062aa8367d7ecc7dc1b91038eed77;hp=e93d9cbdfa29f4f388c3b479188cf0928c9f1d3a;hpb=cb28fdff6d977773c123db418ab0b5f6861f5335;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerController.java index e93d9cbd..18897c30 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerController.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerController.java @@ -34,6 +34,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import java.lang.invoke.MethodHandles; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -43,11 +45,11 @@ import org.oransc.enrichment.controllers.ErrorResponse; import org.oransc.enrichment.controllers.VoidResponse; import org.oransc.enrichment.controllers.r1producer.ProducerCallbacks; import org.oransc.enrichment.exceptions.ServiceException; -import org.oransc.enrichment.repository.EiJob; -import org.oransc.enrichment.repository.EiJobs; -import org.oransc.enrichment.repository.EiProducers; -import org.oransc.enrichment.repository.EiType; -import org.oransc.enrichment.repository.EiTypes; +import org.oransc.enrichment.repository.InfoJob; +import org.oransc.enrichment.repository.InfoJobs; +import org.oransc.enrichment.repository.InfoProducers; +import org.oransc.enrichment.repository.InfoType; +import org.oransc.enrichment.repository.InfoTypes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -76,13 +78,13 @@ public class ConsumerController { ApplicationConfig applicationConfig; @Autowired - private EiJobs jobs; + private InfoJobs jobs; @Autowired - private EiTypes infoTypes; + private InfoTypes infoTypes; @Autowired - private EiProducers infoProducers; + private InfoProducers infoProducers; @Autowired ProducerCallbacks producerCallbacks; @@ -101,7 +103,7 @@ public class ConsumerController { public ResponseEntity getinfoTypeIdentifiers( // ) { List result = new ArrayList<>(); - for (EiType infoType : this.infoTypes.getAllInfoTypes()) { + for (InfoType infoType : this.infoTypes.getAllInfoTypes()) { result.add(infoType.getId()); } @@ -124,7 +126,7 @@ public class ConsumerController { public ResponseEntity getInfoType( // @PathVariable("infoTypeId") String infoTypeId) { try { - EiType type = this.infoTypes.getType(infoTypeId); + InfoType type = this.infoTypes.getType(infoTypeId); ConsumerInfoTypeInfo info = toInfoTypeInfo(type); return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK); } catch (Exception e) { @@ -133,7 +135,7 @@ public class ConsumerController { } @GetMapping(path = "/info-jobs", produces = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "EI job identifiers", description = "query for information job identifiers") + @Operation(summary = "Information Job identifiers", description = "query for information job identifiers") @ApiResponses( value = { // @ApiResponse( @@ -159,7 +161,7 @@ public class ConsumerController { try { List result = new ArrayList<>(); if (owner != null) { - for (EiJob job : this.jobs.getJobsForOwner(owner)) { + for (InfoJob job : this.jobs.getJobsForOwner(owner)) { if (infoTypeId == null || job.getTypeId().equals(infoTypeId)) { result.add(job.getId()); } @@ -193,7 +195,7 @@ public class ConsumerController { public ResponseEntity getIndividualEiJob( // @PathVariable("infoJobId") String infoJobId) { try { - EiJob job = this.jobs.getJob(infoJobId); + InfoJob job = this.jobs.getJob(infoJobId); return new ResponseEntity<>(gson.toJson(toInfoJobInfo(job)), HttpStatus.OK); } catch (Exception e) { return ErrorResponse.create(e, HttpStatus.NOT_FOUND); @@ -216,14 +218,14 @@ public class ConsumerController { public ResponseEntity getEiJobStatus( // @PathVariable("infoJobId") String jobId) { try { - EiJob job = this.jobs.getJob(jobId); + InfoJob job = this.jobs.getJob(jobId); return new ResponseEntity<>(gson.toJson(toInfoJobStatus(job)), HttpStatus.OK); } catch (Exception e) { return ErrorResponse.create(e, HttpStatus.NOT_FOUND); } } - private ConsumerJobStatus toInfoJobStatus(EiJob job) { + private ConsumerJobStatus toInfoJobStatus(InfoJob job) { return this.infoProducers.isJobEnabled(job) ? new ConsumerJobStatus(ConsumerJobStatus.InfoJobStatusValues.ENABLED) : new ConsumerJobStatus(ConsumerJobStatus.InfoJobStatusValues.DISABLED); @@ -241,7 +243,8 @@ public class ConsumerController { @ApiResponse( responseCode = "204", description = "Job deleted", // - content = @Content(schema = @Schema(implementation = VoidResponse.class))), // "Individual EI job" + content = @Content(schema = @Schema(implementation = VoidResponse.class))), // "Individual + // Information Job" @ApiResponse( responseCode = "404", description = "Information subscription job is not found", // @@ -250,7 +253,7 @@ public class ConsumerController { public ResponseEntity deleteIndividualEiJob( // @PathVariable("infoJobId") String jobId) { try { - EiJob job = this.jobs.getJob(jobId); + InfoJob job = this.jobs.getJob(jobId); this.jobs.remove(job, this.infoProducers); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } catch (Exception e) { @@ -275,7 +278,7 @@ public class ConsumerController { content = @Content(schema = @Schema(implementation = VoidResponse.class))), // @ApiResponse( responseCode = "404", - description = "Enrichment Information type is not found", // + description = "Information type is not found", // content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class))) // }) public Mono> putIndividualInfoJob( // @@ -299,20 +302,22 @@ public class ConsumerController { .onErrorResume(throwable -> Mono.just(ErrorResponse.create(throwable, HttpStatus.NOT_FOUND))); } - private Mono startInfoSubscriptionJob(EiJob newInfoJob) { + private Mono startInfoSubscriptionJob(InfoJob newInfoJob) { return this.producerCallbacks.startInfoSubscriptionJob(newInfoJob, infoProducers) // .doOnNext(noOfAcceptingProducers -> this.logger.debug("Started job {}, number of activated producers: {}", newInfoJob.getId(), noOfAcceptingProducers)) // .flatMap(noOfAcceptingProducers -> Mono.just(newInfoJob)); } - private Mono validatePutInfoJob(String jobId, ConsumerJobInfo jobInfo, boolean performTypeCheck) { + private Mono validatePutInfoJob(String jobId, ConsumerJobInfo jobInfo, boolean performTypeCheck) { try { if (performTypeCheck) { - EiType infoType = this.infoTypes.getType(jobInfo.infoTypeId); + InfoType infoType = this.infoTypes.getType(jobInfo.infoTypeId); validateJsonObjectAgainstSchema(infoType.getJobDataSchema(), jobInfo.jobDefinition); } - EiJob existingEiJob = this.jobs.get(jobId); + InfoJob existingEiJob = this.jobs.get(jobId); + validateUri(jobInfo.statusNotificationUri); + validateUri(jobInfo.jobResultUri); if (existingEiJob != null && !existingEiJob.getTypeId().equals(jobInfo.infoTypeId)) { throw new ServiceException("Not allowed to change type for existing job", HttpStatus.CONFLICT); @@ -323,6 +328,15 @@ public class ConsumerController { } } + private void validateUri(String url) throws URISyntaxException, ServiceException { + if (url != null && !url.isEmpty()) { + URI uri = new URI(url); + if (!uri.isAbsolute()) { + throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.CONFLICT); + } + } + } + private void validateJsonObjectAgainstSchema(Object schemaObj, Object object) throws ServiceException { if (schemaObj != null) { // schema is optional for now try { @@ -330,7 +344,7 @@ public class ConsumerController { String schemaAsString = mapper.writeValueAsString(schemaObj); JSONObject schemaJSON = new JSONObject(schemaAsString); - org.everit.json.schema.Schema schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON); + var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON); String objectAsString = mapper.writeValueAsString(object); JSONObject json = new JSONObject(objectAsString); @@ -341,8 +355,8 @@ public class ConsumerController { } } - private EiJob toEiJob(ConsumerJobInfo info, String id, String typeId) { - return EiJob.builder() // + private InfoJob toEiJob(ConsumerJobInfo info, String id, String typeId) { + return InfoJob.builder() // .id(id) // .typeId(typeId) // .owner(info.owner) // @@ -352,15 +366,11 @@ public class ConsumerController { .build(); } - private EiJob toEiJob(ConsumerJobInfo info, String id, EiType type) { - return toEiJob(info, id, type.getId()); - } - - private ConsumerInfoTypeInfo toInfoTypeInfo(EiType type) { + private ConsumerInfoTypeInfo toInfoTypeInfo(InfoType type) { return new ConsumerInfoTypeInfo(type.getJobDataSchema()); } - private ConsumerJobInfo toInfoJobInfo(EiJob s) { + private ConsumerJobInfo toInfoJobInfo(InfoJob s) { return new ConsumerJobInfo(s.getTypeId(), s.getJobData(), s.getOwner(), s.getTargetUrl(), s.getJobStatusUrl()); } }