Commit 0e7c3893 authored by Anastasios Poimenidis's avatar Anastasios Poimenidis
Browse files

refactor: make less verbose logs in ServiceOrderResource, ServiceInventoryResource

parent 8cd8afff
Loading
Loading
Loading
Loading
+29 −15
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import io.quarkus.security.Authenticated;
import jakarta.annotation.security.PermitAll;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.validation.groups.ConvertGroup;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -18,6 +20,8 @@ import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
@@ -28,9 +32,11 @@ import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.etsi.osl.hypo.api.tmf.agreement.schema.ApplicationProperties;
import org.etsi.osl.hypo.api.tmf.common.api.services.UtilService;
import org.etsi.osl.hypo.api.tmf.common.model.ErrorMessage;
import org.etsi.osl.hypo.api.tmf.common.validations.OnPost;
import org.etsi.osl.hypo.api.tmf.services.common.model.ServiceDTO;
import org.etsi.osl.hypo.api.tmf.services.common.model.ServiceResponse;
import org.etsi.osl.hypo.api.tmf.services.inventory.api.services.ServiceInventoryService;
import org.etsi.osl.hypo.api.tmf.services.model.ServiceWithPeeredOrganization;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.RestPath;
import org.jboss.resteasy.reactive.RestQuery;
@@ -48,6 +54,7 @@ public class ServiceInventoryResource {
    public static final String SERVICE_INVENTORY = "/serviceInventory/";
    public static final String SERVICE_INVENTORY_PATH =
            SERVICE_INVENTORY + ApplicationProperties.TMF_URL_VERSION + SERVICE;
    public static final String GET_SERVICE_REQUEST_SUCCESS = "GET Service Request Success";

    @Inject
    public ServiceInventoryResource(ServiceInventoryService serviceInventoryService) {
@@ -78,15 +85,17 @@ public class ServiceInventoryResource {
    public Response createService(
            @Context UriInfo uriInfo,
            @HeaderParam(AUTHORIZATION) String authHeader,
            ServiceDTO serviceDTO) {
            @Valid @ConvertGroup(to = OnPost.class) ServiceDTO serviceDTO) {
        logger.infof("POST Service Request Received. Service name is %s", serviceDTO.getName());
        logger.debugf("Request : %s", serviceDTO);
        ServiceResponse service =
        logger.debugf("POST Request : %s", serviceDTO);
        ServiceResponse serviceResponse =
                serviceInventoryService.createService(serviceDTO, uriInfo, authHeader);
        logger.debugf("Response : %s", service);
        logger.debugf("POST Response : %s", serviceResponse);
        logger.infof(
                "POST Service Request Success. Sending Response. Service name is %s", serviceDTO.getName());
        return Response.ok(service).status(Response.Status.CREATED).build();
                "POST Service Request Success with Service name %s and id %s",
                serviceResponse.getName(), serviceResponse.getId());
        URI uri = UtilService.getUri(serviceResponse.getHref(), uriInfo);
        return Response.created(uri).entity(serviceResponse).build();
    }

    @GET
@@ -103,8 +112,12 @@ public class ServiceInventoryResource {
                            mediaType = APPLICATION_JSON,
                            schema = @Schema(implementation = ServiceResponse.class, type = SchemaType.ARRAY)))
    public Response getServices(@RestQuery String fields, @Context UriInfo uriInfo) {
        logger.infof("GET Service Request Received with fields", fields);
        Map<String, String> criteriaParams = UtilService.getRequestedCriteriaForFiltering(uriInfo);
        return Response.ok(serviceInventoryService.getByCriteria(fields, criteriaParams)).build();
        List<ServiceResponse> servicesByCriteria =
                serviceInventoryService.getServicesByCriteria(fields, criteriaParams);
        logger.info(GET_SERVICE_REQUEST_SUCCESS);
        return Response.ok(servicesByCriteria).build();
    }

    @GET
@@ -123,10 +136,12 @@ public class ServiceInventoryResource {
                            schema = @Schema(implementation = ServiceResponse.class, type = SchemaType.ARRAY)))
    public Response getAllServicesWithPeeredOrganizationDetails(
            @RestQuery String fields, @Context UriInfo uriInfo) {
        logger.infof("GET Service Request Received BY Organization with fields", fields);
        Map<String, String> criteriaParams = UtilService.getRequestedCriteriaForFiltering(uriInfo);
        return Response.ok(
                        serviceInventoryService.getServiceWithOrganizationByCriteria(fields, criteriaParams))
                .build();
        List<ServiceWithPeeredOrganization> serviceWithOrganizationByCriteria =
                serviceInventoryService.getServiceWithOrganizationByCriteria(fields, criteriaParams);
        logger.info(GET_SERVICE_REQUEST_SUCCESS);
        return Response.ok(serviceWithOrganizationByCriteria).build();
    }

    @GET
@@ -153,12 +168,11 @@ public class ServiceInventoryResource {
                            schema = @Schema(implementation = ErrorMessage.class)))
    public Response getServiceById(
            @RestPath String id, @RestQuery String fields, @Context UriInfo uriInfo) {
        logger.info("Get service with id : " + id);

        logger.infof("GET service Request received with id : %s", id);
        Map<String, String> criteriaParams = UtilService.getRequestedCriteriaForFiltering(uriInfo);
        ServiceResponse service =
                serviceInventoryService.getByIdAndCriteria(id, fields, criteriaParams);

        logger.info(GET_SERVICE_REQUEST_SUCCESS);
        return Response.ok(service).build();
    }

@@ -228,9 +242,9 @@ public class ServiceInventoryResource {
                            mediaType = APPLICATION_JSON,
                            schema = @Schema(implementation = ErrorMessage.class)))
    public Response deleteService(@RestPath String id) {
        logger.info("DELETE service request with id : " + id);
        logger.infof("DELETE service request with id :%s", id);
        serviceInventoryService.deleteServiceFromRequest(id);
        logger.info("DELETE service success with id : " + id);
        logger.infof("DELETE service success with id :%s", id);
        return Response.noContent().build();
    }

+17 −8
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import org.etsi.osl.hypo.api.tmf.common.exception.ValidationException;
import org.etsi.osl.hypo.api.tmf.common.model.BaseEntity;
import org.etsi.osl.hypo.api.tmf.common.schema.RelatedPartyEntity;
import org.etsi.osl.hypo.api.tmf.party.organization.schema.Organization;
import org.etsi.osl.hypo.api.tmf.resources.inventory.schema.Resource;
import org.etsi.osl.hypo.api.tmf.resources.inventory.schema.ResourceOperationalStateType;
import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceSpecificationEntity;
import org.etsi.osl.hypo.api.tmf.services.common.ServiceRepositories;
import org.etsi.osl.hypo.api.tmf.services.common.ServiceStatesGraph;
@@ -51,6 +53,8 @@ import org.etsi.osl.hypo.api.tmf.services.common.model.ServiceResponse;
import org.etsi.osl.hypo.api.tmf.services.common.schema.ServiceSpecificationRef;
import org.etsi.osl.hypo.api.tmf.services.common.schema.ServiceStateType;
import org.etsi.osl.hypo.api.tmf.services.inventory.api.kafka.ServiceCreatorClassFromKafkaMessages;
import org.etsi.osl.hypo.api.tmf.services.inventory.api.kafka.incoming.monitor.HealthStatusData;
import org.etsi.osl.hypo.api.tmf.services.inventory.api.kafka.incoming.monitor.ServiceMonitorRequest;
import org.etsi.osl.hypo.api.tmf.services.inventory.api.mappers.ServiceMapper;
import org.etsi.osl.hypo.api.tmf.services.inventory.api.repository.ServiceInventoryRepository;
import org.etsi.osl.hypo.api.tmf.services.inventory.api.rules.ServiceRules;
@@ -72,6 +76,7 @@ import org.etsi.osl.hypo.core.common.service.inventory.ServiceUpdateData;
import org.etsi.osl.hypo.core.common.telemetry.CloudEventDeleteServiceTelemetry;
import org.etsi.osl.hypo.core.common.telemetry.DeleteTelemetryData;
import org.jboss.logging.Logger;
import org.jspecify.annotations.NonNull;

@ApplicationScoped
public class ServiceInventoryService {
@@ -252,10 +257,6 @@ public class ServiceInventoryService {
        serviceRules.applyAfterDeleteRules(serviceResponse);
    }

    public void updateServiceById(String id, Service newService) {
        this.updateService(id, newService);
    }

    @WithSpan("ServiceInventoryService.updateServiceFromRequest")
    @Transactional
    public ServiceResponse updateServiceFromRequest(
@@ -423,8 +424,12 @@ public class ServiceInventoryService {

    @Transactional
    public void updateService(String id, Service newService) {
        this.updateServiceEntity(id, newService);
    }

    private void updateServiceEntity(String id, Service newService) {
        try {
            Service service = this.getServiceById(id);
            Service service = this.getServiceByIdWithLockWrite(id);
            this.checkStateServiceStateTransition(service, newService, id);

            serviceMapper.updateService(newService, service);
@@ -435,16 +440,20 @@ public class ServiceInventoryService {
                            supportingService -> {
                                Service stateHolder = new Service();
                                stateHolder.setState(newService.getState());
                                this.updateService(supportingService.getId(), stateHolder);
                                this.updateServiceEntity(supportingService.getId(), stateHolder);
                            });

            this.handleServiceStates(service, newService.getState());

            persistService(service);
        } catch (ServiceNotFoundException serviceNotFoundException) {
            String errorMessage =
                    String.format(NO_SERVICE_WITH_ID_S_WAS_FOUND_AND_UPDATE_IS_NOT_PERFORMED, id);
            logger.infof(errorMessage);
            logger.warnf(errorMessage);
            throw new ServiceNotFoundException(errorMessage);
        } catch (UpdateStateNotAllowedException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

+23 −10
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.security.Authenticated;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import jakarta.validation.groups.ConvertGroup;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -20,6 +22,7 @@ import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.Map;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
@@ -29,6 +32,7 @@ import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.etsi.osl.hypo.api.tmf.common.api.services.UtilService;
import org.etsi.osl.hypo.api.tmf.common.model.ErrorMessage;
import org.etsi.osl.hypo.api.tmf.common.validations.OnPost;
import org.etsi.osl.hypo.api.tmf.services.order.api.services.ServiceOrderService;
import org.etsi.osl.hypo.api.tmf.services.order.model.ServiceOrderDTO;
import org.etsi.osl.hypo.api.tmf.services.order.model.ServiceOrderResponse;
@@ -82,17 +86,24 @@ public class ServiceOrderResource {
                            mediaType = APPLICATION_JSON,
                            schema = @Schema(implementation = ErrorMessage.class)))
    public Response createServiceOrder(
            @HeaderParam(AUTHORIZATION) String authHeader, ServiceOrderDTO serviceOrderRequest)
            @HeaderParam(AUTHORIZATION) String authHeader,
            @Valid @ConvertGroup(to = OnPost.class) ServiceOrderDTO serviceOrderRequest)
            throws JsonProcessingException {
        logger.debugf(
                "CreateServiceOrder POST Request Received : %s",
                objectMapper.writer().writeValueAsString(serviceOrderRequest));
        ServiceOrderResponse createdServiceOrder =
        logger.infof("POST Service Order Request Received");
        ServiceOrderResponse serviceOrderResponse =
                serviceOrderService.createAndPersistServiceOrder(
                        serviceOrderRequest, uriInfo, authHeader, requestContext.getMethod());
        logger.infof("CreateServiceOrder Response : %s", createdServiceOrder.toString());
        logger.debugf("CreateServiceOrder Response : %s", serviceOrderResponse);

        URI uri = UtilService.getUri(serviceOrderResponse.getHref(), uriInfo);
        logger.infof(
                "POST Service Order Operation Success with service order id: %s",
                serviceOrderResponse.getId());

        return Response.ok(createdServiceOrder).status(Response.Status.CREATED).build();
        return Response.created(uri).entity(serviceOrderResponse).build();
    }

    @GET
@@ -137,11 +148,12 @@ public class ServiceOrderResource {
                            mediaType = APPLICATION_JSON,
                            schema = @Schema(implementation = ErrorMessage.class)))
    public Response getById(@RestPath String id, @RestQuery String fields, @Context UriInfo uriInfo) {
        logger.infof("Get Request: service specification with id : %s", id);
        logger.infof("GET Request: service order with id : %s", id);
        Map<String, String> criteriaParams = UtilService.getRequestedCriteriaForFiltering(uriInfo);
        ServiceOrderResponse serviceOrderResponse =
                serviceOrderService.getByIdAndCriteria(id, fields, criteriaParams);
        logger.infof("Get Response for id %s: %s", id, serviceOrderResponse);
        logger.debugf("GET Response for id %s: %s", id, serviceOrderResponse);
        logger.infof("GET service order with id : %s SUCCESS", id);
        return Response.ok(serviceOrderResponse).build();
    }

@@ -183,10 +195,11 @@ public class ServiceOrderResource {
            @Context ContainerRequestContext requestContext,
            @RestPath String id) {
        String httpMethod = requestContext.getMethod();
        logger.infof("Update Request for service order with id : %s", id);
        logger.infof("Update Request Order Body : %s", serviceOrderRequest.toString());
        logger.infof("PATCH Request for service order with id : %s", id);
        logger.debugf("PATCH Request Order Body : %s", serviceOrderRequest.toString());
        ServiceOrderResponse serviceOrderResponse =
                serviceOrderService.updateServiceOrder(id, serviceOrderRequest, httpMethod);
        logger.infof("PATCH Request SUCCESS for service order with id : %s", id);
        return Response.ok(serviceOrderResponse).build();
    }

@@ -205,9 +218,9 @@ public class ServiceOrderResource {
                            mediaType = APPLICATION_JSON,
                            schema = @Schema(implementation = ErrorMessage.class)))
    public Response delete(@RestPath String id) {
        logger.infof("Delete Request for service specification with id : %s", id);
        logger.infof("DELETE Request for service order with id : %s", id);
        serviceOrderService.deleteServiceOrder(id);
        logger.infof("Successful Delete operation for service specification with id : %s", id);
        logger.infof("DELETE Success for service order with id : %s", id);
        return Response.noContent().build();
    }

+5 −9
Original line number Diff line number Diff line
@@ -234,12 +234,6 @@ public class ServiceOrderService {
        logger.infof("Created And Persisted Service Order : %s", serviceOrder);
    }

    @WithSpan("ServiceOrderService.persistServiceOrder")
    @Transactional
    public void persistServiceOrder(ServiceOrder serviceOrder) {
        serviceOrderRepository.persist(serviceOrder);
    }

    /**
     * retrieve the existing service order based on the @id provided and update it according to the
     * values provided in the variable newServiceOrder . since the operation takes place inside a
@@ -293,11 +287,14 @@ public class ServiceOrderService {
        this.getOptionalServiceOrderByIdWithLock(serviceOrderId)
                .ifPresentOrElse(
                        serviceOrder -> {
                            logger.debugf(
                                    "Will Update Service Order with id %s according to Kafka data  %s",
                                    serviceOrderId, serviceOrderItemUpdateState);

                            updateServiceOrderItemStateById(
                                    serviceOrder, serviceOrderItemId, serviceOrderStateType);
                            updateServiceOrderState(serviceOrder, serviceOrderStateType);

                            String logMessage = "Update Service Order with id %s according to Kafka data  %s";
                            String messageNote =
                                    String.format(
                                            "Updating Service Order with id %s to state %s according to Kafka message id %s",
@@ -310,8 +307,7 @@ public class ServiceOrderService {
                                        String.join("", "Service failed with failure message :", failureMessage);
                                ServiceUtilsHelper.addServiceOrderNoteWithMessage(serviceOrder, noteMessage);
                            }

                            logger.infof(logMessage, serviceOrderId, serviceOrderItemUpdateState);
                            logger.infof("Service Order with id %s was successfully updated", serviceOrderId);
                        },
                        () -> logger.warnf("Service Order with id %s was not found", serviceOrderId));
    }
+36 −5
Original line number Diff line number Diff line
@@ -40,12 +40,15 @@ import java.nio.file.Paths;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import net.joshka.junit.json.params.JsonFileSource;
import org.etsi.osl.hypo.api.tmf.common.api.constants.ApiConstants;
import org.etsi.osl.hypo.api.tmf.common.api.helpers.SystemClockHelper;
import org.etsi.osl.hypo.api.tmf.common.api.services.RelatedPartyService;
import org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef;
import org.etsi.osl.hypo.api.tmf.common.schema.RelatedPartyEntity;
import org.etsi.osl.hypo.api.tmf.services.common.ServiceRepositories;
import org.etsi.osl.hypo.api.tmf.services.common.model.Characteristic;
import org.etsi.osl.hypo.api.tmf.services.common.model.ServiceDTO;
import org.etsi.osl.hypo.api.tmf.services.common.model.ServiceResponse;
import org.etsi.osl.hypo.api.tmf.services.common.schema.ServiceStateType;
@@ -69,12 +72,8 @@ class ServiceInventoryIntegrationTest {
    URL serviceInventoryManagementURL;

    @Inject RelatedPartyService relatedPartyService;

    @Inject ServiceMapper serviceMapper;

    @InjectSpy ServiceInventoryService serviceInventoryService;
    @InjectSpy ServiceRepositories serviceRepositories;

    @InjectSpy ServiceUpdateRuleEngine serviceUpdateRuleEngine;

    static ObjectMapper objectMapper;
@@ -218,6 +217,12 @@ class ServiceInventoryIntegrationTest {
        ServiceDTO firstService = new ServiceDTO();
        firstService.setStartDate(firstStartDate);
        firstService.setEndDate(firstEndDate);
        ServiceSpecificationRef serviceSpecification = new ServiceSpecificationRef();
        serviceSpecification.setId(UUID.randomUUID().toString());
        firstService.setServiceSpecification(serviceSpecification);
        Characteristic characteristic = new Characteristic();
        characteristic.setName("char");
        firstService.setServiceCharacteristic(Set.of(characteristic));

        // POST service
        postService(firstService, serviceInventoryManagementURL);
@@ -226,6 +231,9 @@ class ServiceInventoryIntegrationTest {
        ServiceDTO secondService = new ServiceDTO();
        secondService.setStartDate(firstStartDate.plusYears(3L));
        secondService.setEndDate(firstEndDate.plusYears(3L));
        secondService.setServiceSpecification(serviceSpecification);
        secondService.setServiceCharacteristic(Set.of(characteristic));

        postService(secondService, serviceInventoryManagementURL);

        // GET services
@@ -281,6 +289,13 @@ class ServiceInventoryIntegrationTest {
        firstService.setStartDate(firstStartDate);
        firstService.setEndDate(firstEndDate);

        ServiceSpecificationRef serviceSpecification = new ServiceSpecificationRef();
        serviceSpecification.setId(UUID.randomUUID().toString());
        firstService.setServiceSpecification(serviceSpecification);
        Characteristic characteristic = new Characteristic();
        characteristic.setName("char");
        firstService.setServiceCharacteristic(Set.of(characteristic));

        given()
                .body(firstService)
                .header(CONTENT_TYPE, JSON)
@@ -296,6 +311,9 @@ class ServiceInventoryIntegrationTest {
        ServiceDTO secondService = new ServiceDTO();
        secondService.setStartDate(firstStartDate.plusYears(3L));
        secondService.setEndDate(firstEndDate.plusYears(3L));
        secondService.setServiceSpecification(serviceSpecification);
        characteristic.setName("char");
        secondService.setServiceCharacteristic(Set.of(characteristic));

        given()
                .body(secondService)
@@ -361,6 +379,13 @@ class ServiceInventoryIntegrationTest {
        firstService.setStartDate(firstStartDate);
        firstService.setEndDate(firstEndDate);

        ServiceSpecificationRef serviceSpecification = new ServiceSpecificationRef();
        serviceSpecification.setId(UUID.randomUUID().toString());
        firstService.setServiceSpecification(serviceSpecification);
        Characteristic characteristic = new Characteristic();
        characteristic.setName("char");
        firstService.setServiceCharacteristic(Set.of(characteristic));

        given()
                .body(firstService)
                .header(CONTENT_TYPE, JSON)
@@ -381,6 +406,9 @@ class ServiceInventoryIntegrationTest {
        ServiceDTO secondService = new ServiceDTO();
        secondService.setStartDate(secondStartDate);
        secondService.setEndDate(secondEndDate);
        serviceSpecification.setId(UUID.randomUUID().toString());
        secondService.setServiceSpecification(serviceSpecification);
        secondService.setServiceCharacteristic(Set.of(characteristic));

        given()
                .body(secondService)
@@ -398,6 +426,9 @@ class ServiceInventoryIntegrationTest {
        ServiceDTO thirdService = new ServiceDTO();
        thirdService.setStartDate(systemDateTime.plusYears(4L));
        thirdService.setEndDate(systemDateTime.plusYears(5L));
        serviceSpecification.setId(UUID.randomUUID().toString());
        thirdService.setServiceSpecification(serviceSpecification);
        thirdService.setServiceCharacteristic(Set.of(characteristic));

        given()
                .body(thirdService)
Loading