Search in sources :

Example 1 with SetDataDeviceRequest

use of com.alliander.osgp.adapter.protocol.iec61850.device.rtu.requests.SetDataDeviceRequest in project Protocol-Adapter-IEC61850 by OSGP.

the class MicrogridsSetDataRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.info("Processing microgrids set data request message");
    String correlationUid = null;
    String domain = null;
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    int retryCount = 0;
    boolean isScheduled = false;
    SetDataRequestDto setDataRequest = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        if (message.propertyExists(Constants.IS_SCHEDULED)) {
            isScheduled = message.getBooleanProperty(Constants.IS_SCHEDULED);
        } else {
            isScheduled = false;
        }
        setDataRequest = (SetDataRequestDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("ipAddress: {}", ipAddress);
        return;
    }
    final RequestMessageData requestMessageData = new RequestMessageData(null, domain, domainVersion, messageType, retryCount, isScheduled, correlationUid, organisationIdentification, deviceIdentification);
    LOGGER.info("Calling DeviceService function: {} for domain: {} {}", messageType, domain, domainVersion);
    final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
    final SetDataDeviceRequest deviceRequest = new SetDataDeviceRequest(organisationIdentification, deviceIdentification, correlationUid, setDataRequest, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);
    this.deviceService.setData(deviceRequest, iec61850DeviceResponseHandler);
}
Also used : Iec61850DeviceResponseHandler(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) SetDataRequestDto(com.alliander.osgp.dto.valueobjects.microgrids.SetDataRequestDto) SetDataDeviceRequest(com.alliander.osgp.adapter.protocol.iec61850.device.rtu.requests.SetDataDeviceRequest) JMSException(javax.jms.JMSException) RequestMessageData(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)

Example 2 with SetDataDeviceRequest

use of com.alliander.osgp.adapter.protocol.iec61850.device.rtu.requests.SetDataDeviceRequest in project Protocol-Adapter-IEC61850 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.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), 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.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during Set Data", e);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleException(e, deviceResponse);
    }
}
Also used : ServerModel(org.openmuc.openiec61850.ServerModel) Iec61850Connection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) 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) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) JMSException(javax.jms.JMSException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) EmptyDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)

Example 3 with SetDataDeviceRequest

use of com.alliander.osgp.adapter.protocol.iec61850.device.rtu.requests.SetDataDeviceRequest in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850RtuDeviceService method handleSetData.

private void handleSetData(final DeviceConnection connection, final SetDataDeviceRequest deviceRequest) throws ProtocolAdapterException {
    final SetDataRequestDto setDataRequest = deviceRequest.getSetDataRequest();
    final String serverName = this.getServerName(deviceRequest);
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final Iec61850RtuDeviceReportingService reportingService = new Iec61850RtuDeviceReportingService(serverName);
            reportingService.enableReportingOnDevice(connection, deviceRequest.getDeviceIdentification());
            for (final SetDataSystemIdentifierDto identifier : setDataRequest.getSetDataSystemIdentifiers()) {
                final SystemService systemService = Iec61850RtuDeviceService.this.systemServiceFactory.getSystemService(identifier.getSystemType());
                systemService.setData(identifier, Iec61850RtuDeviceService.this.iec61850Client, connection);
            }
            return null;
        }
    };
    this.iec61850Client.sendCommandWithRetry(function, deviceRequest.getDeviceIdentification());
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) SystemService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.SystemService) SetDataRequestDto(com.alliander.osgp.dto.valueobjects.microgrids.SetDataRequestDto) Iec61850RtuDeviceReportingService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850RtuDeviceReportingService) SetDataSystemIdentifierDto(com.alliander.osgp.dto.valueobjects.microgrids.SetDataSystemIdentifierDto)

Aggregations

SetDataRequestDto (com.alliander.osgp.dto.valueobjects.microgrids.SetDataRequestDto)2 JMSException (javax.jms.JMSException)2 SetDataDeviceRequest (com.alliander.osgp.adapter.protocol.iec61850.device.rtu.requests.SetDataDeviceRequest)1 EmptyDeviceResponse (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)1 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)1 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)1 SystemService (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.SystemService)1 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)1 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)1 RequestMessageData (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)1 Iec61850RtuDeviceReportingService (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850RtuDeviceReportingService)1 Iec61850DeviceResponseHandler (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)1 SetDataSystemIdentifierDto (com.alliander.osgp.dto.valueobjects.microgrids.SetDataSystemIdentifierDto)1 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)1 ServerModel (org.openmuc.openiec61850.ServerModel)1