From: PatrikBuhr Date: Thu, 29 Sep 2022 11:20:52 +0000 (+0200) Subject: NONRTRIC - improved logging X-Git-Tag: 1.4.0~7 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F9136%2F1;p=nonrtric%2Fplt%2Finformationcoordinatorservice.git NONRTRIC - improved logging Signed-off-by: PatrikBuhr Issue-ID: NONRTRIC-773 Change-Id: I5b263e1cf3a80e660bd7dcbf85880a401404be0f --- diff --git a/src/main/java/org/oransc/ics/clients/AsyncRestClient.java b/src/main/java/org/oransc/ics/clients/AsyncRestClient.java index 09b07b2..3edabf9 100644 --- a/src/main/java/org/oransc/ics/clients/AsyncRestClient.java +++ b/src/main/java/org/oransc/ics/clients/AsyncRestClient.java @@ -39,6 +39,7 @@ import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; +import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; @@ -138,7 +139,15 @@ public class AsyncRestClient { request.headers(h -> h.setBearerAuth(securityContext.getBearerAuthToken())); } return request.retrieve() // - .toEntity(String.class); + .toEntity(String.class) // + .doOnError(this::onError); + } + + private void onError(Throwable t) { + if (t instanceof WebClientResponseException) { + WebClientResponseException e = (WebClientResponseException) t; + logger.debug("Response error: {}", e.getResponseBodyAsString()); + } } private static Object createTraceTag() { diff --git a/src/main/java/org/oransc/ics/controllers/ErrorResponse.java b/src/main/java/org/oransc/ics/controllers/ErrorResponse.java index 25b0c16..ebad66a 100644 --- a/src/main/java/org/oransc/ics/controllers/ErrorResponse.java +++ b/src/main/java/org/oransc/ics/controllers/ErrorResponse.java @@ -26,7 +26,11 @@ import com.google.gson.annotations.SerializedName; import io.swagger.v3.oas.annotations.media.Schema; +import java.lang.invoke.MethodHandles; + import org.oransc.ics.exceptions.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -35,6 +39,7 @@ import reactor.core.publisher.Mono; public class ErrorResponse { private static Gson gson = new GsonBuilder().create(); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // Returned as body for all failed REST calls @Schema( @@ -96,10 +101,11 @@ public class ErrorResponse { code = se.getHttpStatus(); } } - return create(e.toString(), code); + return create(e.getMessage(), code); } public static ResponseEntity create(String str, HttpStatus code) { + logger.debug("Error response: {}, {}", code, str); ErrorInfo errorInfo = new ErrorInfo(str, code.value()); String json = gson.toJson(errorInfo); HttpHeaders headers = new HttpHeaders(); diff --git a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java index c988595..2690974 100644 --- a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java +++ b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java @@ -103,6 +103,7 @@ public class ConsumerController { }) public ResponseEntity getinfoTypeIdentifiers( // ) { + logger.debug("GET info type identifier"); List result = new ArrayList<>(); for (InfoType infoType : this.infoTypes.getAllInfoTypes()) { result.add(infoType.getId()); @@ -127,6 +128,7 @@ public class ConsumerController { public ResponseEntity getInfoType( // @PathVariable(ConsumerConsts.INFO_TYPE_ID_PATH) String infoTypeId) { try { + logger.debug("GET info type {}", infoTypeId); InfoType type = this.infoTypes.getType(infoTypeId); ConsumerInfoTypeInfo info = toInfoTypeInfo(type); return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK); @@ -160,6 +162,7 @@ public class ConsumerController { description = ConsumerConsts.OWNER_PARAM_DESCRIPTION) // @RequestParam(name = ConsumerConsts.OWNER_PARAM, required = false) String owner) { try { + logger.debug("GET info jobs, id: {}, owner: {}", infoTypeId, owner); List result = new ArrayList<>(); if (owner != null) { for (InfoJob job : this.infoJobs.getJobsForOwner(owner)) { @@ -196,6 +199,7 @@ public class ConsumerController { public ResponseEntity getIndividualEiJob( // @PathVariable(ConsumerConsts.INFO_JOB_ID_PATH) String infoJobId) { try { + logger.debug("GET info job, id: {}", infoJobId); InfoJob job = this.infoJobs.getJob(infoJobId); return new ResponseEntity<>(gson.toJson(toInfoJobInfo(job)), HttpStatus.OK); } catch (Exception e) { @@ -219,6 +223,7 @@ public class ConsumerController { public ResponseEntity getEiJobStatus( // @PathVariable(ConsumerConsts.INFO_JOB_ID_PATH) String jobId) { try { + logger.debug("GET info job status, id: {}", jobId); InfoJob job = this.infoJobs.getJob(jobId); return new ResponseEntity<>(gson.toJson(toInfoJobStatus(job)), HttpStatus.OK); } catch (Exception e) { @@ -256,6 +261,7 @@ public class ConsumerController { public ResponseEntity deleteIndividualEiJob( // @PathVariable(ConsumerConsts.INFO_JOB_ID_PATH) String jobId) { try { + logger.debug("DELETE info job, id: {}", jobId); InfoJob job = this.infoJobs.getJob(jobId); this.infoJobs.remove(job, this.infoProducers); return new ResponseEntity<>(HttpStatus.NO_CONTENT); @@ -297,6 +303,8 @@ public class ConsumerController { final boolean isNewJob = this.infoJobs.get(jobId) == null; + logger.debug("PUT info job, id: {}, obj: {}", jobId, informationJobObject); + return validatePutInfoJob(jobId, informationJobObject) // .flatMap(this::startInfoSubscriptionJob) // .doOnNext(this.infoJobs::put) // @@ -322,6 +330,7 @@ public class ConsumerController { description = ConsumerConsts.OWNER_PARAM_DESCRIPTION) // @RequestParam(name = ConsumerConsts.OWNER_PARAM, required = false) String owner) { try { + logger.debug("GET info type subscriptions, owner: {}", owner); List result = new ArrayList<>(); if (owner != null) { this.infoTypeSubscriptions.getSubscriptionsForOwner(owner) @@ -352,6 +361,7 @@ public class ConsumerController { public ResponseEntity getIndividualTypeSubscription( // @PathVariable(ConsumerConsts.SUBSCRIPTION_ID_PATH) String subscriptionId) { try { + logger.debug("GET info type subscription, subscriptionId: {}", subscriptionId); InfoTypeSubscriptions.SubscriptionInfo subscription = this.infoTypeSubscriptions.getSubscription(subscriptionId); return new ResponseEntity<>(gson.toJson(toTypeSuscriptionInfo(subscription)), HttpStatus.OK); @@ -382,6 +392,7 @@ public class ConsumerController { @PathVariable(ConsumerConsts.SUBSCRIPTION_ID_PATH) String subscriptionId, // @RequestBody ConsumerTypeSubscriptionInfo subscription) { + logger.debug("PUT info type subscription, subscriptionId: {}, body: {}", subscriptionId, subscription); final boolean isNewSubscription = this.infoTypeSubscriptions.get(subscriptionId) == null; this.infoTypeSubscriptions.put(toTypeSuscriptionInfo(subscription, subscriptionId)); return Mono.just(new ResponseEntity<>(isNewSubscription ? HttpStatus.CREATED : HttpStatus.OK)); @@ -407,6 +418,7 @@ public class ConsumerController { public ResponseEntity deleteIndividualTypeSubscription( // @PathVariable(ConsumerConsts.SUBSCRIPTION_ID_PATH) String subscriptionId) { try { + logger.debug("DELETE info type subscription, subscriptionId: {}", subscriptionId); InfoTypeSubscriptions.SubscriptionInfo subscription = this.infoTypeSubscriptions.getSubscription(subscriptionId); this.infoTypeSubscriptions.remove(subscription); diff --git a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerJobInfo.java b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerJobInfo.java index 7babf87..4495530 100644 --- a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerJobInfo.java +++ b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerJobInfo.java @@ -24,7 +24,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.ToString; +@ToString @Schema(name = "consumer_job", description = "Information for an Information Job") public class ConsumerJobInfo { diff --git a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerTypeSubscriptionInfo.java b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerTypeSubscriptionInfo.java index 84e8e9d..fc3c35d 100644 --- a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerTypeSubscriptionInfo.java +++ b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerTypeSubscriptionInfo.java @@ -25,7 +25,9 @@ import com.google.gson.annotations.SerializedName; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; +import lombok.ToString; +@ToString @EqualsAndHashCode @Schema(name = "consumer_type_subscription_info", description = "Information for an information type subscription") public class ConsumerTypeSubscriptionInfo { diff --git a/src/main/java/org/oransc/ics/controllers/r1producer/ProducerController.java b/src/main/java/org/oransc/ics/controllers/r1producer/ProducerController.java index 0372248..5241001 100644 --- a/src/main/java/org/oransc/ics/controllers/r1producer/ProducerController.java +++ b/src/main/java/org/oransc/ics/controllers/r1producer/ProducerController.java @@ -32,6 +32,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; 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; @@ -48,6 +49,8 @@ import org.oransc.ics.repository.InfoProducers; import org.oransc.ics.repository.InfoType; import org.oransc.ics.repository.InfoTypeSubscriptions; import org.oransc.ics.repository.InfoTypes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -66,6 +69,7 @@ import org.springframework.web.bind.annotation.RestController; public class ProducerController { private static Gson gson = new GsonBuilder().create(); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @Autowired private InfoJobs infoJobs; @@ -90,6 +94,7 @@ public class ProducerController { }) public ResponseEntity getInfoTypdentifiers( // ) { + logger.debug("GET info type identifiers"); List result = new ArrayList<>(); for (InfoType infoType : this.infoTypes.getAllInfoTypes()) { result.add(infoType.getId()); @@ -115,6 +120,7 @@ public class ProducerController { public ResponseEntity getInfoType( // @PathVariable(ProducerConsts.INFO_TYPE_ID_PATH) String infoTypeId) { try { + logger.debug("GET info type, infoTypeId: {}", infoTypeId); InfoType t = this.infoTypes.getType(infoTypeId); ProducerInfoTypeInfo info = toInfoTypeInfo(t); return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK); @@ -145,6 +151,8 @@ public class ProducerController { @PathVariable(ProducerConsts.INFO_TYPE_ID_PATH) String infoTypeId, // @RequestBody ProducerInfoTypeInfo registrationInfo) { + logger.debug("PUT info type, infoTypeId: {}, info: {}", infoTypeId, registrationInfo); + InfoType previousDefinition = this.infoTypes.get(infoTypeId); if (registrationInfo.jobDataSchema == null) { return ErrorResponse.create("No schema provided", HttpStatus.BAD_REQUEST); @@ -182,6 +190,7 @@ public class ProducerController { public ResponseEntity deleteInfoType( // @PathVariable(ProducerConsts.INFO_TYPE_ID_PATH) String infoTypeId) { + logger.debug("DELETE info type, infoTypeId: {}", infoTypeId); InfoType type = this.infoTypes.get(infoTypeId); if (type == null) { return ErrorResponse.create("Information type not found", HttpStatus.NOT_FOUND); @@ -212,6 +221,7 @@ public class ProducerController { description = "If given, only the producers for the EI Data type is returned.") // @RequestParam(name = ProducerConsts.INFO_TYPE_ID_PARAM, required = false) String typeId // ) { + logger.debug("GET producer identifiers"); List result = new ArrayList<>(); for (InfoProducer infoProducer : typeId == null ? this.infoProducers.getAllProducers() : this.infoProducers.getProducersForType(typeId)) { @@ -239,6 +249,7 @@ public class ProducerController { public ResponseEntity getInfoProducer( // @PathVariable(ProducerConsts.INFO_PRODUCER_ID_PATH) String infoProducerId) { try { + logger.debug("GET info producer, infoProducerId: {}", infoProducerId); InfoProducer producer = this.infoProducers.getProducer(infoProducerId); ProducerRegistrationInfo info = toProducerRegistrationInfo(producer); return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK); @@ -267,6 +278,7 @@ public class ProducerController { public ResponseEntity getInfoProducerJobs( // @PathVariable(ProducerConsts.INFO_PRODUCER_ID_PATH) String infoProducerId) { try { + logger.debug("GET info producer, infoProducerId: {}", infoProducerId); InfoProducer producer = this.infoProducers.getProducer(infoProducerId); Collection producerJobs = new ArrayList<>(); for (InfoType type : producer.getInfoTypes()) { @@ -300,6 +312,7 @@ public class ProducerController { public ResponseEntity getInfoProducerStatus( // @PathVariable(ProducerConsts.INFO_PRODUCER_ID_PATH) String infoProducerId) { try { + logger.debug("GET producer status, infoProducerId: {}", infoProducerId); InfoProducer producer = this.infoProducers.getProducer(infoProducerId); return new ResponseEntity<>(gson.toJson(producerStatusInfo(producer)), HttpStatus.OK); } catch (Exception e) { @@ -340,6 +353,7 @@ public class ProducerController { @PathVariable("infoProducerId") String infoProducerId, // @RequestBody ProducerRegistrationInfo registrationInfo) { try { + logger.debug("PUT info producer, infoProducerId: {}, body: {}", infoProducerId, registrationInfo); validateUri(registrationInfo.jobCallbackUrl); validateUri(registrationInfo.producerSupervisionCallbackUrl); InfoProducer previousDefinition = this.infoProducers.get(infoProducerId); @@ -387,6 +401,7 @@ public class ProducerController { public ResponseEntity deleteInfoProducer( @PathVariable(ProducerConsts.INFO_PRODUCER_ID_PATH) String infoProducerId) { try { + logger.debug("DELETE info producer, infoProducerId: {}", infoProducerId); final InfoProducer producer = this.infoProducers.getProducer(infoProducerId); this.infoProducers.deregisterProducer(producer); return new ResponseEntity<>(HttpStatus.NO_CONTENT); diff --git a/src/main/java/org/oransc/ics/controllers/r1producer/ProducerRegistrationInfo.java b/src/main/java/org/oransc/ics/controllers/r1producer/ProducerRegistrationInfo.java index ee82546..f2c7ad1 100644 --- a/src/main/java/org/oransc/ics/controllers/r1producer/ProducerRegistrationInfo.java +++ b/src/main/java/org/oransc/ics/controllers/r1producer/ProducerRegistrationInfo.java @@ -27,6 +27,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.Collection; +import lombok.ToString; + +@ToString @Schema(name = "producer_registration_info", description = "Information for an Information Producer") public class ProducerRegistrationInfo { diff --git a/src/main/java/org/oransc/ics/repository/InfoType.java b/src/main/java/org/oransc/ics/repository/InfoType.java index 69ae67c..1a3f6e5 100644 --- a/src/main/java/org/oransc/ics/repository/InfoType.java +++ b/src/main/java/org/oransc/ics/repository/InfoType.java @@ -21,7 +21,9 @@ package org.oransc.ics.repository; import lombok.Getter; +import lombok.ToString; +@ToString public class InfoType { @Getter private final String id;