Search in sources :

Example 46 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850RtuDeviceService method handleGetData.

// ========================
// PRIVATE HELPER METHODS =
// ========================
private GetDataResponseDto handleGetData(final DeviceConnection connection, final GetDataDeviceRequest deviceRequest) throws ProtocolAdapterException {
    final GetDataRequestDto requestedData = deviceRequest.getDataRequest();
    final String serverName = this.getServerName(deviceRequest);
    final Function<GetDataResponseDto> function = new Function<GetDataResponseDto>() {

        @Override
        public GetDataResponseDto apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final Iec61850RtuDeviceReportingService reportingService = new Iec61850RtuDeviceReportingService(serverName);
            reportingService.enableReportingOnDevice(connection, deviceRequest.getDeviceIdentification());
            final List<GetDataSystemIdentifierDto> identifiers = new ArrayList<>();
            for (final SystemFilterDto systemFilter : requestedData.getSystemFilters()) {
                final SystemService systemService = Iec61850RtuDeviceService.this.systemServiceFactory.getSystemService(systemFilter);
                final GetDataSystemIdentifierDto getDataSystemIdentifier = systemService.getData(systemFilter, Iec61850RtuDeviceService.this.iec61850Client, connection);
                identifiers.add(getDataSystemIdentifier);
            }
            return new GetDataResponseDto(identifiers, null);
        }
    };
    return this.iec61850Client.sendCommandWithRetry(function, deviceRequest.getDeviceIdentification());
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) GetDataRequestDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataRequestDto) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) SystemFilterDto(com.alliander.osgp.dto.valueobjects.microgrids.SystemFilterDto) SystemService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.SystemService) GetDataResponseDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto) GetDataSystemIdentifierDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataSystemIdentifierDto) Iec61850RtuDeviceReportingService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850RtuDeviceReportingService) ArrayList(java.util.ArrayList)

Example 47 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection 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)

Example 48 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850RtuDeviceService method getData.

@Override
public void getData(final GetDataDeviceRequest 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());
        final GetDataResponseDto getDataResponse = this.handleGetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest);
        final GetDataDeviceResponse deviceResponse = new GetDataDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.OK, getDataResponse);
        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 Get Data", e);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleException(e, deviceResponse);
    }
}
Also used : GetDataDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetDataDeviceResponse) 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) GetDataResponseDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto) 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 49 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SsldDeviceService method setSchedule.

@Override
public void setSchedule(final SetScheduleDeviceRequest 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());
        new Iec61850SetScheduleCommand().setScheduleOnDevice(this.iec61850Client, deviceConnection, deviceRequest.getRelayType(), deviceRequest.getScheduleMessageDataContainer().getScheduleList(), ssld, this.ssldDataService);
        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
    } catch (final ProtocolAdapterException e) {
        this.handleProtocolAdapterException(deviceRequest, deviceResponseHandler, e);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
    }
    this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
Also used : Iec61850SetScheduleCommand(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetScheduleCommand) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) 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)

Example 50 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SsldDeviceService method getStatus.

@Override
public void getStatus(final DeviceRequest 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 DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand().getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
        final GetStatusDeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), deviceStatus);
        deviceResponseHandler.handleResponse(deviceResponse);
        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 : Iec61850GetStatusCommand(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand) GetStatusDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetStatusDeviceResponse) DeviceStatusDto(com.alliander.osgp.dto.valueobjects.DeviceStatusDto) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) 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)

Aggregations

NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)55 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)22 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)18 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)17 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)17 JMSException (javax.jms.JMSException)16 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)15 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)15 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)14 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)13 ArrayList (java.util.ArrayList)8 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)7 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)6 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)6 DateTime (org.joda.time.DateTime)6 BdaBoolean (org.openmuc.openiec61850.BdaBoolean)5 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)4 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)4 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)4 ServerModel (org.openmuc.openiec61850.ServerModel)4