Search in sources :

Example 81 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class SystemEventServiceTest method verifyInvocationCounterIsNull.

@Test
void verifyInvocationCounterIsNull() {
    final DlmsDevice device = new DlmsDeviceBuilder().withInvocationCounter(null).build();
    final MessageMetadata messageMetadata = new Builder().withOrganisationIdentification("org-id").build();
    this.service.verifySystemEventThresholdReachedEvent(device, messageMetadata);
    verifyNoInteractions(this.correlationIdProviderService);
    verify(this.osgpRequestMessageSender, never()).send(any(RequestMessage.class), eq(MessageType.SYSTEM_EVENT.name()), any(MessageMetadata.class));
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 82 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class SystemEventServiceTest method verifyMaxValueReachedEvent.

@Test
void verifyMaxValueReachedEvent() {
    final DlmsDevice device = new DlmsDeviceBuilder().withDeviceIdentification("device-1").withInvocationCounter(this.invocationCounterEventThreshold).build();
    final MessageMetadata messageMetadata = new Builder().withIpAddress("127.0-.0.1").withOrganisationIdentification("org-id").withDomain("domain").withDomainVersion("1.0").build();
    when(this.correlationIdProviderService.getCorrelationId(messageMetadata.getOrganisationIdentification(), device.getDeviceIdentification())).thenReturn("corr-id");
    this.service.verifySystemEventThresholdReachedEvent(device, messageMetadata);
    final ArgumentCaptor<MessageMetadata> messageMetadataCaptor = ArgumentCaptor.forClass(MessageMetadata.class);
    final ArgumentCaptor<RequestMessage> requestMessageCaptor = ArgumentCaptor.forClass(RequestMessage.class);
    verify(this.osgpRequestMessageSender).send(requestMessageCaptor.capture(), eq(MessageType.SYSTEM_EVENT.name()), messageMetadataCaptor.capture());
    final RequestMessage requestMessage = requestMessageCaptor.getValue();
    assertThat(requestMessage.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
    assertThat(requestMessage.getCorrelationUid()).isEqualTo("corr-id");
    assertThat(requestMessage.getOrganisationIdentification()).isEqualTo(messageMetadata.getOrganisationIdentification());
    assertThat(requestMessage.getIpAddress()).isEqualTo(messageMetadata.getIpAddress());
    assertThat(requestMessage.getRequest()).isInstanceOf(SystemEventDto.class);
    final SystemEventDto systemEventDto = (SystemEventDto) requestMessage.getRequest();
    assertThat(systemEventDto.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
    assertThat(systemEventDto.getSystemEventType()).isEqualTo(SystemEventTypeDto.INVOCATION_COUNTER_THRESHOLD_REACHED);
    assertThat(systemEventDto.getTimestamp()).isNotNull();
    final MessageMetadata metadata = messageMetadataCaptor.getValue();
    assertThat(metadata.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
    assertThat(metadata.getCorrelationUid()).isEqualTo("corr-id");
    assertThat(metadata.getOrganisationIdentification()).isEqualTo(messageMetadata.getOrganisationIdentification());
    assertThat(metadata.getIpAddress()).isEqualTo(messageMetadata.getIpAddress());
    assertThat(metadata.getMessagePriority()).isEqualTo(MessagePriorityEnum.HIGH.getPriority());
    assertThat(metadata.getMessageType()).isEqualTo(MessageType.SYSTEM_EVENT.name());
    assertThat(metadata.getDomain()).isEqualTo(messageMetadata.getDomain());
    assertThat(metadata.getDomainVersion()).isEqualTo(messageMetadata.getDomainVersion());
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) SystemEventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto) Test(org.junit.jupiter.api.Test)

Example 83 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class OsgpResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing {} request message", this.messageType);
    final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
    final Serializable messageObject = message.getObject();
    final ThrowingConsumer<DlmsConnectionManager> taskForConnectionManager = conn -> this.processMessageTask(messageObject, messageMetadata, conn);
    try {
        if (this.usesDeviceConnection()) {
            this.createAndHandleConnectionForDevice(this.domainHelperService.findDlmsDevice(messageMetadata), messageMetadata, taskForConnectionManager);
        } else {
            this.processMessageTask(messageObject, messageMetadata, null);
        }
    } catch (final OsgpException e) {
        LOGGER.error("Something went wrong with the DlmsConnection", e);
    }
}
Also used : DomainHelperService(org.opensmartgridplatform.adapter.protocol.dlms.application.services.DomainHelperService) MessageProcessorMap(org.opensmartgridplatform.shared.infra.jms.MessageProcessorMap) MessageProcessor(org.opensmartgridplatform.shared.infra.jms.MessageProcessor) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) Logger(org.slf4j.Logger) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) LoggerFactory(org.slf4j.LoggerFactory) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) JMSException(javax.jms.JMSException) Serializable(java.io.Serializable) PostConstruct(javax.annotation.PostConstruct) DeviceResponseMessageSender(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DeviceResponseMessageSender) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ThrowingConsumer(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsConnectionMessageProcessor(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsConnectionMessageProcessor) Message(javax.jms.Message) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)

Example 84 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class FirmwareServiceTest method updateFirmwareShouldCallExecutorWhenFirmwareFileInCache.

@Test
public void updateFirmwareShouldCallExecutorWhenFirmwareFileInCache() throws OsgpException {
    // Arrange
    final byte[] firmwareFile = firmwareIdentification.getBytes();
    final byte[] firmwareImageIdentifier = Hex.decode("496d6167654964656e746966696572");
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    when(this.firmwareFileCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true);
    when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile);
    when(this.firmwareImageIdentifierCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true);
    when(this.firmwareImageIdentifierCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareImageIdentifier);
    // Act
    this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, updateFirmwareRequestDto, messageMetadata);
    // Assert
    verify(this.updateFirmwareCommandExecutor, times(1)).execute(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, updateFirmwareRequestDto, messageMetadata);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Test(org.junit.jupiter.api.Test)

Example 85 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    ObjectMessage objectMessage = null;
    MessageMetadata messageMetadata = null;
    try {
        objectMessage = (ObjectMessage) message;
        messageMetadata = MessageMetadata.fromMessage(objectMessage);
    } catch (final Exception e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read JMS message instance, giving up.", e);
        return;
    }
    final String correlationUid = messageMetadata.getCorrelationUid();
    final String deviceIdentification = messageMetadata.getDeviceIdentification();
    try {
        LOGGER.info("Received message [correlationUid={}, messageType={}, messagePriority={}] for device {}", correlationUid, messageMetadata.getMessageType(), messageMetadata.getMessagePriority(), deviceIdentification);
        this.pendingRequestsQueue.enqueue(deviceIdentification, correlationUid);
        final MessageProcessor processor = this.messageProcessorMap.getMessageProcessor(objectMessage);
        processor.processMessage(objectMessage);
    } catch (final IllegalArgumentException | JMSException e) {
        this.pendingRequestsQueue.remove(deviceIdentification, correlationUid);
        LOGGER.error("Unexpected exception for message [correlationUid={}]", correlationUid, e);
        this.sendNotSupportedException(objectMessage, messageMetadata);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) MessageProcessor(org.opensmartgridplatform.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) NotSupportedException(org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)

Aggregations

MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)147 JMSException (javax.jms.JMSException)65 Device (org.opensmartgridplatform.domain.core.entities.Device)29 Test (org.junit.jupiter.api.Test)25 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)23 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)22 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)20 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)20 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)20 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)19 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)18 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)14 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)14 ObjectMessage (javax.jms.ObjectMessage)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)13 Serializable (java.io.Serializable)12 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)12 UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)10