Search in sources :

Example 21 with ConnectionFailureException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException in project open-smart-grid-platform by OSGP.

the class Iec61850SsldDeviceService method setLight.

@Override
public void setLight(final SetLightDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection devCon = null;
    try {
        final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);
        devCon = deviceConnection;
        // Getting the SSLD for the device output-settings.
        final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
        final List<DeviceOutputSetting> deviceOutputSettings = this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT);
        final List<LightValueDto> lightValues = deviceRequest.getLightValuesContainer().getLightValues();
        final List<LightValueDto> relaysWithInternalIdToSwitch;
        // Check if external index 0 is used.
        final LightValueDto index0LightValue = this.checkForIndex0(lightValues);
        if (index0LightValue != null) {
            // If external index 0 is used, create a list of all light
            // relays according to the device output settings.
            relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, index0LightValue.isOn());
        } else {
            // Else, create a list of internal indices based on the given
            // external indices in the light values list.
            relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, lightValues);
        }
        // Switch light relays based on internal indices.
        final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand(this.deviceMessageLoggingService);
        iec61850SetLightCommand.switchLightRelays(this.iec61850Client, deviceConnection, relaysWithInternalIdToSwitch, null);
        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
        this.enableReporting(deviceConnection, deviceRequest);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
        this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
        this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
    }
}
Also used : ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) DeviceOutputSetting(org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) Ssld(org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto) Iec61850SetLightCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand)

Example 22 with ConnectionFailureException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException in project open-smart-grid-platform by OSGP.

the class Iec61850RtuDeviceService method setData.

@Override
public void setData(final SetDataDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    try {
        final String serverName = this.getServerName(deviceRequest);
        final ServerModel serverModel = this.connectAndRetrieveServerModel(deviceRequest, serverName);
        final ClientAssociation clientAssociation = this.iec61850DeviceConnectionService.getClientAssociation(deviceRequest.getDeviceIdentification());
        this.handleSetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.OK);
        deviceResponseHandler.handleResponse(deviceResponse);
    } catch (final ConnectionFailureException se) {
        LOGGER.error("Could not connect to device after all retries", se);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during Set Data", e);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleException(e, deviceResponse);
    }
}
Also used : ServerModel(com.beanit.openiec61850.ServerModel) Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(com.beanit.openiec61850.ClientAssociation) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)

Example 23 with ConnectionFailureException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException in project open-smart-grid-platform by OSGP.

the class Iec61850SsldDeviceService method setConfiguration.

@Override
public void setConfiguration(final SetConfigurationDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection deviceConnection = null;
    try {
        deviceConnection = this.connectToDevice(deviceRequest);
        final ConfigurationDto configuration = deviceRequest.getConfiguration();
        // Ignoring required, unused fields DALI-configuration and
        // preferredLinkType.
        new Iec61850SetConfigurationCommand(this.deviceMessageLoggingService).setConfigurationOnDevice(this.iec61850Client, deviceConnection, configuration);
        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
    }
    this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
Also used : Iec61850SetConfigurationCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetConfigurationCommand) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)

Example 24 with ConnectionFailureException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException in project open-smart-grid-platform by OSGP.

the class Iec61850DeviceConnectionService method connect.

public DeviceConnection connect(final DeviceConnectionParameters deviceConnectionParameters, final String organisationIdentification, final boolean cacheConnection) throws ConnectionFailureException {
    final String deviceIdentification = deviceConnectionParameters.getDeviceIdentification();
    final String serverName = deviceConnectionParameters.getServerName();
    final IED ied = deviceConnectionParameters.getIed();
    // an usable for the given deviceIdentification.
    try {
        if (cacheConnection && this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, serverName, deviceConnectionParameters.getLogicalDevice())) {
            return new DeviceConnection(this.fetchIec61850Connection(deviceIdentification), deviceIdentification, organisationIdentification, serverName);
        }
    } catch (final ProtocolAdapterException e) {
        this.logProtocolAdapterException(deviceIdentification, e);
    }
    final InetAddress inetAddress = this.convertIpAddress(deviceConnectionParameters.getIpAddress());
    // Connect to obtain ClientAssociation and ServerModel.
    LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}", deviceIdentification, deviceConnectionParameters.getIpAddress(), this.responseTimeout);
    final DateTime startTime = DateTime.now();
    // Create instance of appropriate event listener.
    Iec61850ClientBaseEventListener eventListener = null;
    try {
        eventListener = this.iec61850ClientEventListenerFactory.getEventListener(ied, deviceIdentification, organisationIdentification);
    } catch (final ProtocolAdapterException e) {
        this.logProtocolAdapterException(deviceIdentification, e);
    }
    final Iec61850Device iec61850Device = this.iec61850DeviceRepository.findByDeviceIdentification(deviceIdentification);
    final int port = this.determinePortForIec61850Device(ied, iec61850Device);
    // Try to connect and receive the ClientAssociation.
    final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850Client.connect(deviceIdentification, inetAddress, eventListener, port);
    final ClientAssociation clientAssociation = iec61850ClientAssociation.getClientAssociation();
    // Set response time-out.
    clientAssociation.setResponseTimeout(this.responseTimeout);
    // Read the ServerModel, either from the device or from a SCL file.
    ServerModel serverModel;
    try {
        serverModel = this.readServerModel(clientAssociation, deviceIdentification, iec61850Device);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error("ProtocolAdapterException: unable to read ServerModel for deviceIdentification {}", deviceIdentification, e);
        throw new ConnectionFailureException(e.getMessage(), e);
    }
    // Cache the connection.
    final Iec61850Connection iec61850Connection = new Iec61850Connection(iec61850ClientAssociation, serverModel, startTime, ied);
    if (cacheConnection) {
        this.cacheIec61850Connection(deviceIdentification, iec61850Connection);
    }
    final DeviceConnection connection = new DeviceConnection(iec61850Connection, deviceIdentification, organisationIdentification, serverName);
    final DateTime endTime = DateTime.now();
    LOGGER.info("Connected to device: {}, fetched server model. Start time: {}, end time: {}, total time in milliseconds: {}", deviceIdentification, startTime, endTime, endTime.minus(startTime.getMillis()).getMillis());
    this.iec61850RtuDeviceReportingService.enableReportingForDevice(connection, deviceIdentification, serverName);
    return connection;
}
Also used : Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850Device(org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device) IED(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(com.beanit.openiec61850.ClientAssociation) DateTime(org.joda.time.DateTime) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ServerModel(com.beanit.openiec61850.ServerModel) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) Iec61850ClientBaseEventListener(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener) InetAddress(java.net.InetAddress)

Example 25 with ConnectionFailureException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SsldDeviceService method setLight.

@Override
public void setLight(final SetLightDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection deviceConnection = null;
    try {
        deviceConnection = this.connectToDevice(deviceRequest);
        // Getting the SSLD for the device output-settings.
        final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
        final List<DeviceOutputSetting> deviceOutputSettings = this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT);
        final List<LightValueDto> lightValues = deviceRequest.getLightValuesContainer().getLightValues();
        List<LightValueDto> relaysWithInternalIdToSwitch;
        // Check if external index 0 is used.
        final LightValueDto index0LightValue = this.checkForIndex0(lightValues);
        if (index0LightValue != null) {
            // If external index 0 is used, create a list of all light
            // relays according to the device output settings.
            relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, index0LightValue.isOn());
        } else {
            // Else, create a list of internal indices based on the given
            // external indices in the light values list.
            relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, lightValues);
        }
        // Switch light relays based on internal indices.
        final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand();
        for (final LightValueDto relayWithInternalIdToSwitch : relaysWithInternalIdToSwitch) {
            LOGGER.info("Trying to switch light relay with internal index: {} for device: {}", relayWithInternalIdToSwitch.getIndex(), deviceRequest.getDeviceIdentification());
            if (!iec61850SetLightCommand.switchLightRelay(this.iec61850Client, deviceConnection, relayWithInternalIdToSwitch.getIndex(), relayWithInternalIdToSwitch.isOn())) {
                throw new ProtocolAdapterException(String.format("Failed to switch light relay with internal index: %d for device: %s", relayWithInternalIdToSwitch.getIndex(), deviceRequest.getDeviceIdentification()));
            }
        }
        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
    }
    this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
Also used : ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) NodeWriteException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException) FunctionalException(com.alliander.osgp.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) Ssld(com.alliander.osgp.core.db.api.iec61850.entities.Ssld) LightValueDto(com.alliander.osgp.dto.valueobjects.LightValueDto) Iec61850SetLightCommand(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand)

Aggregations

JMSException (javax.jms.JMSException)32 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)19 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)18 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)18 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)17 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)17 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)16 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)14 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)13 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)13 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)12 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)12 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)6 ClientAssociation (com.beanit.openiec61850.ClientAssociation)5 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)5 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)5 Ssld (org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld)5 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)4 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)4