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;
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() {
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;
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(
code = se.getHttpStatus();
}
}
- return create(e.toString(), code);
+ return create(e.getMessage(), code);
}
public static ResponseEntity<Object> 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();
})
public ResponseEntity<Object> getinfoTypeIdentifiers( //
) {
+ logger.debug("GET info type identifier");
List<String> result = new ArrayList<>();
for (InfoType infoType : this.infoTypes.getAllInfoTypes()) {
result.add(infoType.getId());
public ResponseEntity<Object> 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);
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<String> result = new ArrayList<>();
if (owner != null) {
for (InfoJob job : this.infoJobs.getJobsForOwner(owner)) {
public ResponseEntity<Object> 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) {
public ResponseEntity<Object> 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) {
public ResponseEntity<Object> 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);
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) //
description = ConsumerConsts.OWNER_PARAM_DESCRIPTION) //
@RequestParam(name = ConsumerConsts.OWNER_PARAM, required = false) String owner) {
try {
+ logger.debug("GET info type subscriptions, owner: {}", owner);
List<String> result = new ArrayList<>();
if (owner != null) {
this.infoTypeSubscriptions.getSubscriptionsForOwner(owner)
public ResponseEntity<Object> 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);
@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));
public ResponseEntity<Object> 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);
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 {
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 {
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 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;
public class ProducerController {
private static Gson gson = new GsonBuilder().create();
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Autowired
private InfoJobs infoJobs;
})
public ResponseEntity<Object> getInfoTypdentifiers( //
) {
+ logger.debug("GET info type identifiers");
List<String> result = new ArrayList<>();
for (InfoType infoType : this.infoTypes.getAllInfoTypes()) {
result.add(infoType.getId());
public ResponseEntity<Object> 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);
@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);
public ResponseEntity<Object> 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);
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<String> result = new ArrayList<>();
for (InfoProducer infoProducer : typeId == null ? this.infoProducers.getAllProducers()
: this.infoProducers.getProducersForType(typeId)) {
public ResponseEntity<Object> 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);
public ResponseEntity<Object> getInfoProducerJobs( //
@PathVariable(ProducerConsts.INFO_PRODUCER_ID_PATH) String infoProducerId) {
try {
+ logger.debug("GET info producer, infoProducerId: {}", infoProducerId);
InfoProducer producer = this.infoProducers.getProducer(infoProducerId);
Collection<ProducerJobInfo> producerJobs = new ArrayList<>();
for (InfoType type : producer.getInfoTypes()) {
public ResponseEntity<Object> 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) {
@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);
public ResponseEntity<Object> 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);
import java.util.Collection;
+import lombok.ToString;
+
+@ToString
@Schema(name = "producer_registration_info", description = "Information for an Information Producer")
public class ProducerRegistrationInfo {
package org.oransc.ics.repository;
import lombok.Getter;
+import lombok.ToString;
+@ToString
public class InfoType {
@Getter
private final String id;