Commit 52663a67 authored by Anastasios Poimenidis's avatar Anastasios Poimenidis
Browse files

fix: null pointers. introduce extra checks for service monitor and dashboard

parent 63ededcc
Loading
Loading
Loading
Loading
Loading
+6 −1
Changes for src/main/java/org/etsi/osl/hypo/api/tmf/services/common/ServiceRepositories.java: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.etsi.osl.hypo.api.tmf.common.api.constants.ApiConstants;
import org.etsi.osl.hypo.api.tmf.common.api.helpers.ServiceCatalogHelper;
import org.etsi.osl.hypo.api.tmf.common.api.services.RelatedPartyService;
@@ -150,7 +151,11 @@ public class ServiceRepositories {
                service -> {
                    Optional<Resource> dashboardResourceOptional =
                            service.getSupportingResource().stream()
                                    .filter(resource -> resource.getType().equalsIgnoreCase(DASHBOARD_RESOURCE))
                                    .filter(
                                            resource -> {
                                                String type = resource.getType();
                                                return Strings.CS.equals(type, DASHBOARD_RESOURCE);
                                            })
                                    .findFirst();
                    dashboardResourceOptional.ifPresentOrElse(
                            resource -> resourceID.set(resource.getId()),
+25 −11
Changes for src/main/java/org/etsi/osl/hypo/api/tmf/services/inventory/api/services/ServiceInventoryService.java: 25 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ 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.MonitorResults;
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;
@@ -118,7 +119,9 @@ public class ServiceInventoryService {
            return createdService;
        } catch (Exception e) {
            String error = AlarmLogsConstants.POST_SERVICE_REQUEST_ALARM_LOG;
            throw new ValidationException(error);
            String format = String.format("for service with name %s", serviceDTO.getName());
            logger.errorf(e, String.join("", error, format));
            throw new ValidationException(format);
        }
    }

@@ -279,15 +282,18 @@ public class ServiceInventoryService {
                    String.format(
                            AlarmLogsConstants.PATCH_SERVICE_REQUEST_ALARM_LOG + " Error message: %s",
                            e.getMessage());
            logger.error(error);
            throw new UpdateStateNotAllowedException(error);
        } catch (ServiceNotFoundException e) {
            String error =
                    String.format(
                            AlarmLogsConstants.PATCH_SERVICE_REQUEST_ALARM_LOG + " Error message: %s",
                            e.getMessage());
            logger.error(error);
            throw new ServiceNotFoundException(error);
        } catch (Exception e) {
            String error = AlarmLogsConstants.PATCH_SERVICE_REQUEST_ALARM_LOG + " Rules Execution Error";
            logger.errorf(e, error);
            throw new ValidationException(error);
        }
    }
@@ -331,11 +337,11 @@ public class ServiceInventoryService {
                updateSupportingService(service, state);
            }

        } catch (ServiceNotFoundException serviceNotFoundException) {
        } catch (ServiceNotFoundException e) {
            String errorMessage =
                    String.format(
                            NO_SERVICE_WITH_ID_S_WAS_FOUND_AND_UPDATE_IS_NOT_PERFORMED, service.getId());
            logger.warnf(errorMessage);
            logger.warnf(e, errorMessage);
            throw new ServiceNotFoundException(errorMessage);
        }
    }
@@ -446,10 +452,10 @@ public class ServiceInventoryService {

            this.handleServiceStates(service, newService.getState());
            persistService(service);
        } catch (ServiceNotFoundException serviceNotFoundException) {
        } catch (ServiceNotFoundException e) {
            String errorMessage =
                    String.format(NO_SERVICE_WITH_ID_S_WAS_FOUND_AND_UPDATE_IS_NOT_PERFORMED, id);
            logger.warnf(errorMessage);
            logger.warnf(e, errorMessage);
            throw new ServiceNotFoundException(errorMessage);
        } catch (UpdateStateNotAllowedException e) {
            throw e;
@@ -509,12 +515,19 @@ public class ServiceInventoryService {
                    logger.infof("Will update monitor resources for service with id %s", serviceId);
                    Set<Resource> supportingResource = service.getSupportingResource();

                    data.getMonitorResults()
                            .getResources()
                            .forEach(
                    MonitorResults monitorResults = data.getMonitorResults();

                    if (monitorResults != null) {
                        List<org.etsi.osl.hypo.api.tmf.services.inventory.api.kafka.incoming.monitor.Resource>
                                monitorResultsResources = monitorResults.getResources();
                        if (CollectionUtils.isNotEmpty(monitorResultsResources)) {
                            monitorResultsResources.forEach(
                                    resource ->
                                            createOrUpdateCorrespondingResource(service, resource, supportingResource));
                    logger.infof("Completed updating monitor resources for service with id %s", serviceId);
                            logger.infof(
                                    "Completed updating monitor resources for service with id %s", serviceId);
                        }
                    }
                },
                () -> logger.warnf("Service with id %s was not found", serviceId));
    }
@@ -544,8 +557,9 @@ public class ServiceInventoryService {
            Service service = this.getServiceByIdWithLockWrite(serviceId);
            this.handleStateUpdate(service, serviceStateType);
            logger.infof("Service RFS with id: %s was updated to %s", serviceId, service);
        } catch (ServiceNotFoundException serviceNotFoundException) {
            logger.infof("No service with id %s was found and state update is not performed", serviceId);
        } catch (ServiceNotFoundException e) {
            logger.warnf(
                    e, "No service with id %s was found and state update is not performed", serviceId);
        }
    }