use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata in project open-smart-grid-platform by OSGP.
the class AbstractMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.info("Processing message.");
MessageMetadata messageMetadata = null;
try {
messageMetadata = MessageMetadata.fromMessage(message);
final RequestMetadata requestMetadata = RequestMetadata.newBuilder().messageMetadata(messageMetadata).build();
final ClientConnection deviceConnection = this.iec60870DeviceConnectionService.getConnection(requestMetadata);
this.process(deviceConnection, requestMetadata);
} catch (final ProtocolAdapterException e) {
this.handleError(messageMetadata, e);
} catch (final Exception e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
}
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata in project open-smart-grid-platform by OSGP.
the class GeneralInterrogationService method sendGeneralInterrogation.
public void sendGeneralInterrogation(final ClientConnection deviceConnection, final RequestMetadata requestMetadata) throws IOException {
final String connectedDevice = deviceConnection.getConnectionParameters().getDeviceIdentification();
final int commonAddress = deviceConnection.getConnectionParameters().getCommonAddress();
deviceConnection.getConnection().interrogation(commonAddress, CauseOfTransmission.ACTIVATION, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID));
// interrogation command creates this asdu internally, however we
// need it here as well for logging...
final ASdu asdu = new ASdu(ASduType.C_IC_NA_1, false, CauseOfTransmission.ACTIVATION, false, false, ORIGINATOR_ADDRESS, commonAddress, new InformationObject(0, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID)));
final LogItem logItem = new LogItem(connectedDevice, requestMetadata.getOrganisationIdentification(), false, asdu.toString());
this.loggingService.log(logItem);
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata in project open-smart-grid-platform by OSGP.
the class GetLightSensorStatusRequestMessageProcessorTest method testProcessShouldSendGeneralInInterrogation.
@Test
void testProcessShouldSendGeneralInInterrogation() throws Exception {
// Arrange
final ConnectionParameters connectionParameters = ConnectionParameters.newBuilder().deviceIdentification(GATEWAY_IDENTIFICATION).build();
final DeviceConnection deviceConnection = new DeviceConnection(this.connection, connectionParameters);
final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(DEVICE_IDENTIFICATION);
// Act
this.getLightSensorStatusRequestMessageProcessor.process(deviceConnection, requestMetadata);
// Assert
verify(this.generalInterrogationService).sendGeneralInterrogation(deviceConnection, requestMetadata);
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata in project open-smart-grid-platform by OSGP.
the class GeneralInterrogationServiceTest method testSendGeneralInterrogationShouldLogSameAsduAsUsedInInterrogation.
/**
* Test method for {@link
* org.opensmartgridplatform.adapter.protocol.iec60870.infra.messaging.processors.ConnectRequestMessageProcessor#process(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection,
* org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)}.
*
* @throws Exception
*/
@Test
void testSendGeneralInterrogationShouldLogSameAsduAsUsedInInterrogation() throws Exception {
// Arrange
final ConnectionParameters connectionParameters = ConnectionParameters.newBuilder().deviceIdentification(DEVICE_IDENTIFICATION).build();
final DeviceConnection deviceConnection = new DeviceConnection(this.connection, connectionParameters);
final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(DEVICE_IDENTIFICATION);
doCallRealMethod().when(this.connection).interrogation(anyInt(), any(CauseOfTransmission.class), any(IeQualifierOfInterrogation.class));
// Act
this.generalInterrogationService.sendGeneralInterrogation(deviceConnection, requestMetadata);
// Assert
final ArgumentCaptor<ASdu> asduCaptor = ArgumentCaptor.forClass(ASdu.class);
final ArgumentCaptor<LogItem> logItemCaptor = ArgumentCaptor.forClass(LogItem.class);
verify(this.connection).send(asduCaptor.capture());
verify(this.loggingService).log(logItemCaptor.capture());
assertThat(logItemCaptor.getValue().getMessage()).isEqualTo(asduCaptor.getValue().toString());
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata in project open-smart-grid-platform by OSGP.
the class ClientConnectionServiceTest method testGetConnectionShouldReturnNewConnectionWhenNotInCache.
@Test
void testGetConnectionShouldReturnNewConnectionWhenNotInCache() throws Exception {
// Arrange
final String deviceIdentification = "DA_DVC_1";
final Iec60870Device device = Iec60870DeviceFactory.createDistributionAutomationDevice(deviceIdentification);
when(this.iec60870DeviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(Optional.of(device));
final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(deviceIdentification);
final ClientConnection expectedConnection = ClientConnectionFactory.forDevice(deviceIdentification);
when(this.iec60870Client.connect(eq(expectedConnection.getConnectionParameters()), any(ConnectionEventListener.class))).thenReturn(expectedConnection);
// Act
final ClientConnection actualConnection = this.clientConnectionService.getConnection(requestMetadata);
// Assert
assertThat(actualConnection).isEqualTo(expectedConnection);
}
Aggregations