Search in sources :

Example 16 with ProtocolAdapterException

use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.

the class DeviceManagementService method addEventNotifications.

/**
     * Send an event notification to OSGP Core.
     *
     * @param deviceIdentification
     *            The identification of the device.
     * @param eventNotifications
     *            The event notifications.
     *
     * @throws ProtocolAdapterException
     *             In case the device can not be found in the database.
     */
public void addEventNotifications(final String deviceIdentification, final List<EventNotificationDto> eventNotifications) throws ProtocolAdapterException {
    final Ssld ssldDevice = this.ssldDataRepository.findByDeviceIdentification(deviceIdentification);
    if (ssldDevice == null) {
        throw new ProtocolAdapterException("Unable to find device using deviceIdentification: " + deviceIdentification);
    }
    LOGGER.info("addEventNotifications called for device {}: {}", deviceIdentification, eventNotifications);
    final RequestMessage requestMessage = new RequestMessage("no-correlationUid", "no-organisation", deviceIdentification, new ArrayList<>(eventNotifications));
    this.osgpRequestMessageSender.send(requestMessage, DeviceFunctionDto.ADD_EVENT_NOTIFICATION.name());
}
Also used : RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) Ssld(com.alliander.osgp.core.db.api.iec61850.entities.Ssld)

Example 17 with ProtocolAdapterException

use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.

the class DeviceRegistrationService method disableRegistration.

/**
     * After the device has registered with the platform successfully, the
     * device has to be informed that the registration worked. Disable an
     * attribute so the device will stop attempting to register once a minute.
     *
     * @param deviceIdentification
     *            The device identification.
     * @param ipAddress
     *            The IP address of the device.
     * @param ied
     *            The type of IED.
     * @param serverName
     *            The server name.
     *
     * @throws ProtocolAdapterException
     *             In case the connection to the device can not be established
     *             or the connection breaks during communication.
     */
public void disableRegistration(final String deviceIdentification, final InetAddress ipAddress, final IED ied, final String serverName) throws ProtocolAdapterException {
    final DeviceConnection deviceConnection = this.iec61850DeviceConnectionService.connectWithoutConnectionCaching(ipAddress.getHostAddress(), deviceIdentification, "", ied, serverName, LogicalDevice.LIGHTING.getDescription());
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            DeviceRegistrationService.this.disableRegistration(deviceConnection);
            DeviceRegistrationService.this.setLocationInformation(deviceConnection);
            if (DeviceRegistrationService.this.isReportingAfterDeviceRegistrationEnabled) {
                LOGGER.info("Reporting enabled for device: {}", deviceConnection.getDeviceIdentification());
                DeviceRegistrationService.this.enableReporting(deviceConnection);
            } else {
                LOGGER.info("Reporting disabled for device: {}", deviceIdentification);
                DeviceRegistrationService.this.iec61850DeviceConnectionService.disconnect(deviceConnection, null);
            }
            return null;
        }
    };
    this.iec61850DeviceConnectionService.sendCommandWithRetry(function, deviceIdentification);
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)

Example 18 with ProtocolAdapterException

use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850Config method createChannelPipeline.

private ChannelPipeline createChannelPipeline(final ChannelHandler handler) throws ProtocolAdapterException {
    final ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("loggingHandler", new LoggingHandler(InternalLogLevel.INFO, true));
    pipeline.addLast("iec61850RegisterDeviceRequestDecoder", new RegisterDeviceRequestDecoder());
    pipeline.addLast("iec61850ChannelHandler", handler);
    return pipeline;
}
Also used : LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) RegisterDeviceRequestDecoder(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.RegisterDeviceRequestDecoder) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 19 with ProtocolAdapterException

use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850DeviceConnectionService method connect.

public synchronized DeviceConnection connect(final String ipAddress, final String deviceIdentification, final String organisationIdentification, final IED ied, final String serverName, final String logicalDevice, final boolean cacheConnection) throws ConnectionFailureException {
    // an usable for the given deviceIdentification.
    try {
        if (cacheConnection && this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, serverName, logicalDevice)) {
            return new DeviceConnection(this.fetchIec61850Connection(deviceIdentification), deviceIdentification, organisationIdentification, serverName);
        }
    } catch (final ProtocolAdapterException e) {
        this.logProtocolAdapterException(deviceIdentification, e);
    }
    if (StringUtils.isEmpty(ipAddress)) {
        throw new ConnectionFailureException("Ip address is null");
    }
    final InetAddress inetAddress = this.convertIpAddress(ipAddress);
    // Connect to obtain ClientAssociation and ServerModel.
    LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}", deviceIdentification, ipAddress, this.responseTimeout);
    final DateTime startTime = DateTime.now();
    // Create instance of appropriate event listener.
    Iec61850ClientBaseEventListener eventListener = null;
    try {
        eventListener = Iec61850ClientEventListenerFactory.getInstance().getEventListener(ied, deviceIdentification, this.deviceManagementService);
    } 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);
    if (cacheConnection) {
        this.cacheIec61850Connection(deviceIdentification, iec61850Connection);
    }
    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());
    return new DeviceConnection(iec61850Connection, deviceIdentification, organisationIdentification, serverName);
}
Also used : Iec61850ClientAssociation(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ServerModel(org.openmuc.openiec61850.ServerModel) Iec61850Connection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850Device(com.alliander.osgp.adapter.protocol.iec61850.domain.entities.Iec61850Device) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) Iec61850ClientAssociation(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(org.openmuc.openiec61850.ClientAssociation) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) Iec61850ClientBaseEventListener(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener) InetAddress(java.net.InetAddress) DateTime(org.joda.time.DateTime)

Example 20 with ProtocolAdapterException

use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850DeviceConnectionService method readServerModel.

private ServerModel readServerModel(final ClientAssociation clientAssociation, final String deviceIdentification, final Iec61850Device iec61850Device) throws ProtocolAdapterException {
    ServerModel serverModel;
    try {
        serverModel = this.readServerModelConfiguredForDevice(clientAssociation, deviceIdentification, iec61850Device);
        if (serverModel != null) {
            return serverModel;
        }
    } catch (final ProtocolAdapterException e) {
        LOGGER.warn("Ignore exception reading server model based on per device configuration for device: {}.", deviceIdentification, e);
    }
    try {
        serverModel = this.readServerModelFromConfiguredIcdFile(clientAssociation);
        if (serverModel != null) {
            return serverModel;
        }
    } catch (final ProtocolAdapterException e) {
        LOGGER.warn("Ignore exception reading server model based on configured ICD file.", e);
    }
    LOGGER.info("Reading ServerModel from device: {} using readServerModelFromDevice()", deviceIdentification);
    return this.iec61850Client.readServerModelFromDevice(clientAssociation);
}
Also used : ServerModel(org.openmuc.openiec61850.ServerModel) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Aggregations

ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)22 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)16 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)15 NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)11 ArrayList (java.util.ArrayList)9 DateTime (org.joda.time.DateTime)7 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)6 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)6 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)5 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)5 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)5 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)5 BdaBoolean (org.openmuc.openiec61850.BdaBoolean)5 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)4 LightValueDto (com.alliander.osgp.dto.valueobjects.LightValueDto)4 IOException (java.io.IOException)4 List (java.util.List)4 JMSException (javax.jms.JMSException)4 ScheduleEntry (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry)3 NodeReadException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException)3