Search in sources :

Example 1 with InstanceNotFoundException

use of io.gravitee.rest.api.service.exceptions.InstanceNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class InstanceServiceImpl method findByEvent.

@Override
public InstanceEntity findByEvent(String eventId) {
    try {
        LOGGER.debug("Find instance by event ID: {}", eventId);
        EventEntity event = eventService.findById(eventId);
        List<String> environments = Stream.of(event.getProperties().get(ENVIRONMENTS_HRIDS_PROPERTY).split(", ")).filter(env -> !StringUtils.isEmpty(env)).collect(Collectors.toList());
        List<String> organizations = Stream.of(event.getProperties().get(ORGANIZATIONS_HRIDS_PROPERTY).split(", ")).filter(org -> !StringUtils.isEmpty(org)).collect(Collectors.toList());
        return convert(event, environments, organizations);
    } catch (EventNotFoundException enfe) {
        throw new InstanceNotFoundException(eventId);
    }
}
Also used : InstanceService(io.gravitee.rest.api.service.InstanceService) java.util(java.util) InstanceNotFoundException(io.gravitee.rest.api.service.exceptions.InstanceNotFoundException) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Page(io.gravitee.common.data.domain.Page) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Instant(java.time.Instant) EventNotFoundException(io.gravitee.rest.api.service.exceptions.EventNotFoundException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) EventService(io.gravitee.rest.api.service.EventService) Value(org.springframework.beans.factory.annotation.Value) Component(org.springframework.stereotype.Component) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) Duration(java.time.Duration) io.gravitee.rest.api.model(io.gravitee.rest.api.model) StringUtils(org.springframework.util.StringUtils) InstanceNotFoundException(io.gravitee.rest.api.service.exceptions.InstanceNotFoundException) EventNotFoundException(io.gravitee.rest.api.service.exceptions.EventNotFoundException)

Example 2 with InstanceNotFoundException

use of io.gravitee.rest.api.service.exceptions.InstanceNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class HealthCheckServiceImpl method getGatewayMetadata.

private Map<String, String> getGatewayMetadata(String gateway) {
    Map<String, String> metadata = new HashMap<>();
    try {
        InstanceEntity instance = instanceService.findById(gateway);
        metadata.put("hostname", instance.getHostname());
        metadata.put("ip", instance.getIp());
        if (instance.getTenant() != null) {
            metadata.put("tenant", instance.getTenant());
        }
    } catch (InstanceNotFoundException infe) {
        metadata.put("deleted", "true");
    }
    return metadata;
}
Also used : InstanceNotFoundException(io.gravitee.rest.api.service.exceptions.InstanceNotFoundException) InstanceEntity(io.gravitee.rest.api.model.InstanceEntity)

Aggregations

InstanceNotFoundException (io.gravitee.rest.api.service.exceptions.InstanceNotFoundException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Page (io.gravitee.common.data.domain.Page)1 io.gravitee.rest.api.model (io.gravitee.rest.api.model)1 InstanceEntity (io.gravitee.rest.api.model.InstanceEntity)1 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)1 EventService (io.gravitee.rest.api.service.EventService)1 InstanceService (io.gravitee.rest.api.service.InstanceService)1 EventNotFoundException (io.gravitee.rest.api.service.exceptions.EventNotFoundException)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 java.util (java.util)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1