Search in sources :

Example 1 with GetDataResponseDto

use of org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto in project open-smart-grid-platform 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 Function<GetDataResponseDto> function = new Function<GetDataResponseDto>() {

        @Override
        public GetDataResponseDto apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
            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(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function) GetDataRequestDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataRequestDto) DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) SystemFilterDto(org.opensmartgridplatform.dto.valueobjects.microgrids.SystemFilterDto) SystemService(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.SystemService) GetDataResponseDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto) GetDataSystemIdentifierDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataSystemIdentifierDto) ArrayList(java.util.ArrayList)

Example 2 with GetDataResponseDto

use of org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto in project open-smart-grid-platform 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);
        if (getDataResponse == null) {
            throw new ProtocolAdapterException("No valid response received during GetData");
        }
        final GetDataDeviceResponse deviceResponse = new GetDataDeviceResponse(deviceRequest, 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, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during Get Data", e);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleException(e, deviceResponse);
    }
}
Also used : GetDataDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetDataDeviceResponse) ServerModel(com.beanit.openiec61850.ServerModel) Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) GetDataResponseDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto) 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) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) 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 3 with GetDataResponseDto

use of org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto in project open-smart-grid-platform by OSGP.

the class GetDataResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing microgrids get data response message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final GetDataResponseDto dataResponse = (GetDataResponseDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.adHocManagementService.handleGetDataResponse(dataResponse, ids, messageType, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetDataResponseDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 4 with GetDataResponseDto

use of org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto in project open-smart-grid-platform by OSGP.

the class CommunicationRecoveryService method signalConnectionLost.

/**
 * Send a signal that the connection with the device has been lost. This is done by putting a
 * GetDataResponse on the queue with an alarm value. When this response is received by the
 * webservice adapter, it can send a notification to the client.
 */
public void signalConnectionLost(final RtuDevice rtu) {
    LOGGER.info("Sending connection lost signal for device {}.", rtu.getDeviceIdentification());
    final GetDataResponseDto dataResponse = new GetDataResponseDto(Arrays.asList(new GetDataSystemIdentifierDto(SYSTEM_ID, SYSTEM_TYPE, Arrays.asList(new MeasurementDto(MEASUREMENT_ID, MEASUREMENT_NODE, 0, new DateTime(DateTimeZone.UTC), MEASUREMENT_VALUE_ALARM_ON)))), null);
    final String correlationUid = this.createCorrelationUid(rtu);
    final String organisationIdentification = rtu.getOwner().getOrganisationIdentification();
    final String deviceIdentification = rtu.getDeviceIdentification();
    final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
    this.adHocManagementService.handleInternalDataResponse(dataResponse, ids, DeviceFunction.GET_DATA.toString());
}
Also used : GetDataResponseDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto) GetDataSystemIdentifierDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataSystemIdentifierDto) MeasurementDto(org.opensmartgridplatform.dto.valueobjects.microgrids.MeasurementDto) DateTime(org.joda.time.DateTime) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds)

Example 5 with GetDataResponseDto

use of org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto in project open-smart-grid-platform by OSGP.

the class Iec61850ClientRTUEventListener method processReport.

private void processReport(final Report report, final String reportDescription, final Iec61850ReportHandler reportHandler) throws ProtocolAdapterException {
    final List<FcModelNode> dataSetMembers = report.getValues();
    if (CollectionUtils.isEmpty(dataSetMembers)) {
        this.logger.warn("No dataSet members available for {}", reportDescription);
        return;
    }
    final List<MeasurementDto> measurements = this.processMeasurements(reportHandler, reportDescription, dataSetMembers);
    final GetDataSystemIdentifierDto systemResult = reportHandler.createResult(measurements);
    final List<GetDataSystemIdentifierDto> systems = new ArrayList<>();
    systems.add(systemResult);
    final ReportDto reportDto = new ReportDto(report.getSqNum(), new DateTime(report.getTimeOfEntry().getTimestampValue()), report.getRptId());
    this.deviceManagementService.sendMeasurements(this.deviceIdentification, new GetDataResponseDto(systems, reportDto));
    this.reportingService.storeLastReportEntry(report, this.deviceIdentification);
}
Also used : GetDataResponseDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto) GetDataSystemIdentifierDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataSystemIdentifierDto) ArrayList(java.util.ArrayList) FcModelNode(com.beanit.openiec61850.FcModelNode) ReportDto(org.opensmartgridplatform.dto.valueobjects.microgrids.ReportDto) MeasurementDto(org.opensmartgridplatform.dto.valueobjects.microgrids.MeasurementDto) DateTime(org.joda.time.DateTime)

Aggregations

GetDataResponseDto (org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto)6 JMSException (javax.jms.JMSException)3 GetDataSystemIdentifierDto (org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataSystemIdentifierDto)3 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 GetDataDeviceResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetDataDeviceResponse)2 MeasurementDto (org.opensmartgridplatform.dto.valueobjects.microgrids.MeasurementDto)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)2 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)2 ClientAssociation (com.beanit.openiec61850.ClientAssociation)1 FcModelNode (com.beanit.openiec61850.FcModelNode)1 ServerModel (com.beanit.openiec61850.ServerModel)1 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)1 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850ClientAssociation (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)1 Iec61850Connection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection)1 SystemService (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.SystemService)1