Search in sources :

Example 1 with ServiceConfig

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

the class Application method run.

@Override
public void run() {
    try {
        ConfigFactory configFactory = new ConfigFactory();
        AASEnvironmentFactory environmentFactory = new AASEnvironmentFactory();
        readConfigurationParametersOverEnvironmentVariables();
        readFilePathsOverEnvironmentVariables();
        List<Config> customConfigComponents = getCustomConfigComponents();
        ServiceConfig config = configFactory.toServiceConfig(configFilePath, autoCompleteConfiguration, properties, customConfigComponents);
        AssetAdministrationShellEnvironment environment = null;
        if (useEmptyAASEnvironment) {
            LOGGER.info("Using empty Asset Administration Shell Environment");
            environment = environmentFactory.getEmptyAASEnvironment();
        } else {
            environment = environmentFactory.getAASEnvironment(aasEnvironmentFilePath);
            LOGGER.info("Successfully parsed Asset Administration Shell Environment");
        }
        if (validateAASEnv) {
            validate(environment);
        }
        service = new Service(config);
        service.setAASEnvironment(environment);
        service.start();
        LOGGER.info("FAAAST Service is running!");
    } catch (Exception ex) {
        if (service != null) {
            service.stop();
        }
        LOGGER.error(ex.getMessage());
        LOGGER.error("Abort starting FAAAST Service");
    }
}
Also used : ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) EndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig) HttpEndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig) ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) Config(de.fraunhofer.iosb.ilt.faaast.service.config.Config) Service(de.fraunhofer.iosb.ilt.faaast.service.Service) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment)

Example 2 with ServiceConfig

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

the class ConfigFactory method toServiceConfig.

/**
 * Parses a given file path to a {@link de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig} object.
 * Adjust it with the given properties.
 *
 * @param pathToConfigFile
 * @param autoCompleteConfiguration if yes then missing components in the given config file are added
 *            with default values
 * @param commandLineProperties the adjustments for the default configuration file.
 * @param customConfigs list of custom configuration which should be applied
 * @return the parsed ServiceConfig object
 * @throws Exception
 */
public ServiceConfig toServiceConfig(String pathToConfigFile, boolean autoCompleteConfiguration, Map<String, Object> commandLineProperties, List<Config> customConfigs) throws Exception {
    try {
        JsonNode configNode = mapper.readTree(Files.readString(Path.of(pathToConfigFile)));
        ServiceConfig serviceConfig = mapper.readValue(mapper.writeValueAsString(configNode), ServiceConfig.class);
        LOGGER.info("Read config file '" + pathToConfigFile + "'");
        if (autoCompleteConfiguration) {
            autocompleteServiceConfiguration(serviceConfig);
        }
        if (customConfigs != null && !customConfigs.isEmpty()) {
            LOGGER.debug("Applying costum config components to config file");
            applyToServiceConfig(serviceConfig, customConfigs);
        }
        if (commandLineProperties != null && !commandLineProperties.isEmpty()) {
            LOGGER.debug("Applying properties to config file");
            serviceConfig = applyCommandlineProperties(commandLineProperties, serviceConfig);
        }
        LOGGER.info("Successfully read config file");
        LOGGER.debug("Used configuration file\n" + mapper.writeValueAsString(serviceConfig));
        return serviceConfig;
    } catch (NoSuchFileException ex) {
        if (pathToConfigFile.equalsIgnoreCase(Application.DEFAULT_CONFIG_PATH)) {
            LOGGER.info("No custom configuration file was found");
            LOGGER.info("Using default configuration file");
            ServiceConfig serviceConfig = getDefaultServiceConfig(commandLineProperties);
            applyToServiceConfig(serviceConfig, customConfigs);
            LOGGER.debug("Used configuration file\n" + mapper.writeValueAsString(serviceConfig));
            return serviceConfig;
        } else {
            throw new Exception("Configuration Error - Could not find configuration file: " + pathToConfigFile);
        }
    } catch (IOException ex) {
        throw new Exception("Configuration Error: " + ex.getMessage());
    }
}
Also used : ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) NoSuchFileException(java.nio.file.NoSuchFileException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 3 with ServiceConfig

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

the class ConfigFactory method applyToServiceConfig.

private void applyToServiceConfig(ServiceConfig serviceConfig, List<Config> configs) throws Exception {
    boolean isEndpointAlreadySet = false;
    for (Config c : configs) {
        LOGGER.debug("Apply custom config parameter '" + c.getClass().getSimpleName() + "'");
        if (EndpointConfig.class.isAssignableFrom(c.getClass())) {
            // if yet no endpoint was set remove old enpoints (most likely default endpoint) and set new endpoint
            // else add the new endpoint to the existing list of endpoints
            serviceConfig.setEndpoints(!isEndpointAlreadySet ? new ArrayList<>() {

                {
                    add((EndpointConfig) c);
                }
            } : new ArrayList<>() {

                {
                    addAll(serviceConfig.getEndpoints());
                    add((EndpointConfig) c);
                }
            });
            isEndpointAlreadySet = true;
            continue;
        }
        if (PersistenceConfig.class.isAssignableFrom(c.getClass())) {
            serviceConfig.setPersistence((PersistenceConfig) c);
            continue;
        }
        if (MessageBusConfig.class.isAssignableFrom(c.getClass())) {
            serviceConfig.setMessageBus((MessageBusConfig) c);
            continue;
        }
        if (AssetConnectionConfig.class.isAssignableFrom(c.getClass())) {
            serviceConfig.getAssetConnections().add((AssetConnectionConfig) c);
            continue;
        }
        throw new Exception("Cannot set config component '" + c.getClass().getSimpleName() + "'");
    }
}
Also used : EndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig) ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) MessageBusInternalConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig) MessageBusConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBusConfig) Config(de.fraunhofer.iosb.ilt.faaast.service.config.Config) HttpEndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig) PersistenceInMemoryConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) AssetConnectionConfig(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig) PersistenceConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.PersistenceConfig) ArrayList(java.util.ArrayList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 4 with ServiceConfig

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

the class ConfigFactory method autocompleteServiceConfiguration.

private void autocompleteServiceConfiguration(ServiceConfig serviceConfig) throws Exception {
    ServiceConfig defaultConfig = getDefaultServiceConfig();
    if (serviceConfig.getCore() == null) {
        serviceConfig.setCore(defaultConfig.getCore());
        LOGGER.debug("No configuration for core was found");
        LOGGER.debug("Using default configuration for core");
    }
    if (serviceConfig.getEndpoints() == null || serviceConfig.getEndpoints().size() == 0) {
        serviceConfig.setEndpoints(defaultConfig.getEndpoints());
        LOGGER.debug("No configuration for endpoints was found");
        LOGGER.debug("Using default configuration for endpoints");
    }
    if (serviceConfig.getPersistence() == null) {
        serviceConfig.setPersistence(defaultConfig.getPersistence());
        LOGGER.debug("No configuration for persistence was found");
        LOGGER.debug("Using default configuration for persistence");
    }
    if (serviceConfig.getMessageBus() == null) {
        serviceConfig.setMessageBus(defaultConfig.getMessageBus());
        LOGGER.debug("No configuration for messagebus was found");
        LOGGER.debug("Using default configuration for messagebus");
    }
}
Also used : ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig)

Example 5 with ServiceConfig

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

the class IntegrationTestHttpEndpoint method init.

@Before
public void init() throws Exception {
    environment = AASFull.createEnvironment();
    ServiceConfig serviceConfig = new ServiceConfig.Builder().core(new CoreConfig.Builder().requestHandlerThreadPoolSize(2).build()).persistence(new PersistenceInMemoryConfig()).endpoints(List.of(new HttpEndpointConfig())).messageBus(new MessageBusInternalConfig()).build();
    service = new Service(serviceConfig);
    messageBus = service.getMessageBus();
    service.setAASEnvironment(environment);
    service.start();
}
Also used : ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) MessageBusInternalConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig) Service(de.fraunhofer.iosb.ilt.faaast.service.Service) PersistenceInMemoryConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig) HttpEndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig) Before(org.junit.Before)

Aggregations

ServiceConfig (de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig)9 Test (org.junit.Test)4 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)3 HttpEndpointConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig)3 Service (de.fraunhofer.iosb.ilt.faaast.service.Service)2 Config (de.fraunhofer.iosb.ilt.faaast.service.config.Config)2 EndpointConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig)2 MessageBusInternalConfig (de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig)2 PersistenceInMemoryConfig (de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig)2 IOException (java.io.IOException)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 HashMap (java.util.HashMap)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 AssetConnectionConfig (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig)1 MessageBusConfig (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBusConfig)1 PersistenceConfig (de.fraunhofer.iosb.ilt.faaast.service.persistence.PersistenceConfig)1 AssetAdministrationShellEnvironment (io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1