Search in sources :

Example 1 with InvalidConfigurationException

use of de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException in project FAAAST-Service by FraunhoferIOSB.

the class Service method init.

private void init() throws ConfigurationException {
    if (config.getPersistence() == null) {
        throw new InvalidConfigurationException("config.persistence must be non-null");
    }
    persistence = (Persistence) config.getPersistence().newInstance(config.getCore(), this);
    if (config.getMessageBus() == null) {
        throw new InvalidConfigurationException("config.messagebus must be non-null");
    }
    messageBus = (MessageBus) config.getMessageBus().newInstance(config.getCore(), this);
    if (config.getAssetConnections() != null) {
        List<AssetConnection> assetConnections = new ArrayList<>();
        for (AssetConnectionConfig assetConnectionConfig : config.getAssetConnections()) {
            assetConnections.add((AssetConnection) assetConnectionConfig.newInstance(config.getCore(), this));
        }
        assetConnectionManager = new AssetConnectionManager(config.getCore(), assetConnections, this);
    }
    if (config.getEndpoints() == null || config.getEndpoints().isEmpty()) {
        // TODO maybe be less restrictive and only print warning
        // throw new InvalidConfigurationException("at least endpoint must be defined in the configuration");
        logger.warn("no endpoint configuration found, starting service without endpoint which means the service will not be accessible via any kind of API");
    } else {
        endpoints = new ArrayList<>();
        for (EndpointConfig endpointConfig : config.getEndpoints()) {
            Endpoint endpoint = (Endpoint) endpointConfig.newInstance(config.getCore(), this);
            endpoints.add(endpoint);
        }
    }
    this.requestHandler = new RequestHandlerManager(this.config.getCore(), this.persistence, this.messageBus, this.assetConnectionManager);
}
Also used : AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) Endpoint(de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) ArrayList(java.util.ArrayList) AssetConnectionConfig(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig) EndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig) InvalidConfigurationException(de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException) AssetConnection(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)

Example 2 with InvalidConfigurationException

use of de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException in project FAAAST-Service by FraunhoferIOSB.

the class AssetConnectionManager method validateConnections.

private void validateConnections() throws ConfigurationException {
    Map<Reference, List<AssetValueProvider>> valueProviders = connections.stream().flatMap(x -> (Stream<Map.Entry<Reference, AssetValueProvider>>) x.getValueProviders().entrySet().stream()).collect(Collectors.groupingBy(x -> x.getKey(), Collectors.mapping(x -> x.getValue(), Collectors.toList()))).entrySet().stream().filter(x -> x.getValue().size() > 1).collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
    for (Reference reference : valueProviders.keySet()) {
        throw new InvalidConfigurationException(String.format("found %d value connections for reference %s but maximum 1 allowed", valueProviders.get(reference).size(), reference));
    }
    Map<Reference, List<AssetOperationProvider>> operationProviders = connections.stream().flatMap(x -> (Stream<Map.Entry<Reference, AssetOperationProvider>>) x.getOperationProviders().entrySet().stream()).collect(Collectors.groupingBy(x -> x.getKey(), Collectors.mapping(x -> x.getValue(), Collectors.toList()))).entrySet().stream().filter(x -> x.getValue().size() > 1).collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
    for (Reference reference : operationProviders.keySet()) {
        throw new InvalidConfigurationException(String.format("found %d operation connections for reference %s but maximum 1 allowed", operationProviders.get(reference).size(), reference));
    }
    Map<Reference, List<AssetSubscriptionProvider>> subscriptionProviders = connections.stream().flatMap(x -> (Stream<Map.Entry<Reference, AssetSubscriptionProvider>>) x.getSubscriptionProviders().entrySet().stream()).collect(Collectors.groupingBy(x -> x.getKey(), Collectors.mapping(x -> x.getValue(), Collectors.toList()))).entrySet().stream().filter(x -> x.getValue().size() > 1).collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
    for (Reference reference : subscriptionProviders.keySet()) {
        throw new InvalidConfigurationException(String.format("found %d subscription connections for reference %s but maximum 1 allowed", subscriptionProviders.get(reference).size(), reference));
    }
}
Also used : IdentifierType(io.adminshell.aas.v3.model.IdentifierType) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) Reference(io.adminshell.aas.v3.model.Reference) ServiceContext(de.fraunhofer.iosb.ilt.faaast.service.ServiceContext) SetSubmodelElementValueByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) InvalidConfigurationException(de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) ConfigurationException(de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationException) Map(java.util.Map) Reference(io.adminshell.aas.v3.model.Reference) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) Map(java.util.Map) InvalidConfigurationException(de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException)2 ArrayList (java.util.ArrayList)2 ServiceContext (de.fraunhofer.iosb.ilt.faaast.service.ServiceContext)1 AssetConnection (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)1 AssetConnectionConfig (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig)1 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)1 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)1 Endpoint (de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint)1 EndpointConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig)1 ConfigurationException (de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationException)1 SetSubmodelElementValueByPathRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest)1 DataElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)1 RequestHandlerManager (de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager)1 IdentifierType (io.adminshell.aas.v3.model.IdentifierType)1 Reference (io.adminshell.aas.v3.model.Reference)1 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Level (java.util.logging.Level)1