Search in sources :

Example 1 with SimulatorSpec

use of org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec in project open-smart-grid-platform by OSGP.

the class Simulator method getSimulatorSpec.

private SimulatorSpec getSimulatorSpec(final String jsonPath) throws IOException {
    final SimulatorSpec simulatorSpec;
    if (jsonPath != null) {
        File jsonFile = new File(jsonPath);
        if (!jsonFile.exists()) {
            final ClassPathResource jsonResource = new ClassPathResource(jsonPath);
            if (jsonResource.exists()) {
                jsonFile = jsonResource.getFile();
            } else {
                throw new IllegalArgumentException(String.format("Could not find file or class path resource %s", jsonPath));
            }
        }
        simulatorSpec = new ObjectMapper().readValue(jsonFile, SimulatorSpec.class);
    } else {
        simulatorSpec = new SimulatorSpec(Default.BROKER_HOST, Default.BROKER_PORT);
    }
    LOG.info("Simulator spec: {}", simulatorSpec);
    return simulatorSpec;
}
Also used : SimulatorSpec(org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with SimulatorSpec

use of org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec in project open-smart-grid-platform by OSGP.

the class MqttDeviceSteps method startPublishingClient.

private void startPublishingClient(final String host, final int port, final String topic, final String payload, final Map<String, String> parameters) {
    final SimulatorSpec spec = new SimulatorSpec(host, port);
    spec.setStartupPauseMillis(2000);
    final Message message = new Message(topic, payload, 10000);
    final Message[] messages = { message };
    spec.setMessages(messages);
    MqttClientSslConfig mqttClientSslConfig = null;
    final boolean mqttSslEnabled = ReadSettingsHelper.getBoolean(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_ENABLED, PlatformDistributionAutomationDefaults.MQTT_SSL_ENABLED);
    if (mqttSslEnabled) {
        final String truststoreLocation = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_LOCATION, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_LOCATION);
        final String truststorePassword = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_PASSWORD, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_PASSWORD);
        final String truststoreType = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_TYPE, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_TYPE);
        final ResourceLoader resourceLoader = new DefaultResourceLoader();
        final Resource trustStoreResource = resourceLoader.getResource(truststoreLocation);
        mqttClientSslConfig = MqttClientSslConfigFactory.getMqttClientSslConfig(trustStoreResource, truststorePassword, truststoreType);
    }
    final SimulatorSpecPublishingClient publishingClient = new SimulatorSpecPublishingClient(spec, mqttClientSslConfig);
    publishingClient.start();
}
Also used : MqttClientSslConfig(com.hivemq.client.mqtt.MqttClientSslConfig) SimulatorSpecPublishingClient(org.opensmartgridplatform.simulator.protocol.mqtt.SimulatorSpecPublishingClient) ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Message(org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message) Resource(org.springframework.core.io.Resource) SimulatorSpec(org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Aggregations

SimulatorSpec (org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MqttClientSslConfig (com.hivemq.client.mqtt.MqttClientSslConfig)1 File (java.io.File)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 SimulatorSpecPublishingClient (org.opensmartgridplatform.simulator.protocol.mqtt.SimulatorSpecPublishingClient)1 Message (org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)1 Resource (org.springframework.core.io.Resource)1 ResourceLoader (org.springframework.core.io.ResourceLoader)1