Search in sources :

Example 6 with RtuDevice

use of org.opensmartgridplatform.domain.core.entities.RtuDevice in project open-smart-grid-platform by OSGP.

the class MicrogridsService method enqueueGetDataRequest.

public String enqueueGetDataRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, @NotNull final GetDataRequest dataRequest) throws OsgpException {
    LOGGER.debug("enqueueGetDataRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final RtuDevice device = this.domainHelperService.findDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.GET_DATA);
    final MicrogridsRequestMessage message = new MicrogridsRequestMessage(MessageType.GET_DATA, correlationUid, organisationIdentification, deviceIdentification, dataRequest);
    try {
        this.requestMessageSender.send(message);
    } catch (final ArgumentNullOrEmptyException e) {
        throw new TechnicalException(ComponentType.WS_MICROGRIDS, e);
    }
    return correlationUid;
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) ArgumentNullOrEmptyException(org.opensmartgridplatform.domain.core.exceptions.ArgumentNullOrEmptyException) MicrogridsRequestMessage(org.opensmartgridplatform.adapter.ws.microgrids.infra.jms.MicrogridsRequestMessage)

Example 7 with RtuDevice

use of org.opensmartgridplatform.domain.core.entities.RtuDevice in project open-smart-grid-platform by OSGP.

the class CommunicationMonitoringJob method execute.

@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
    LOGGER.info("Executing communication monitoring job.");
    final Instant startTime = Instant.now().minus(this.maximumDurationWithoutCommunication);
    final List<RtuDevice> rtuDevices = this.getDevicesWithLastCommunicationBefore(startTime);
    LOGGER.info("Found {} device(s) for which communication should be restored.", rtuDevices.size());
    for (final RtuDevice rtu : rtuDevices) {
        LOGGER.debug("Restoring communication for device {}.", rtu.getDeviceIdentification());
        this.communicationRecoveryService.signalConnectionLost(rtu);
        this.communicationRecoveryService.restoreCommunication(rtu);
    }
    LOGGER.info("Finished executing communication monitoring job.");
}
Also used : RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Instant(java.time.Instant)

Example 8 with RtuDevice

use of org.opensmartgridplatform.domain.core.entities.RtuDevice in project open-smart-grid-platform by OSGP.

the class PublicLightingConnectResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting set transition response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
    } 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("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Received message of type: {}", messageType);
        switch(responseMessageResultType) {
            case OK:
                final RtuDevice rtu = this.rtuDeviceRepository.findByDeviceIdentification(deviceIdentification).orElse(null);
                if (rtu != null && this.shouldUpdateCommunicationTime(rtu)) {
                    rtu.messageReceived();
                    this.rtuDeviceRepository.save(rtu);
                } else {
                    LOGGER.info("No RTU found with device identification {}", deviceIdentification);
                }
                break;
            case NOT_FOUND:
                // Should never happen
                LOGGER.warn("Received result not found while connecting to device {}", deviceIdentification);
                break;
            case NOT_OK:
                LOGGER.error("Received result NOT OK while trying to connect to device {}", deviceIdentification, osgpException);
        }
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 9 with RtuDevice

use of org.opensmartgridplatform.domain.core.entities.RtuDevice in project open-smart-grid-platform by OSGP.

the class RtuResponseService method handleResponseMessageReceived.

@Transactional(value = "transactionManager")
public void handleResponseMessageReceived(final Logger logger, final String deviceIdentification, final boolean expectDeviceToBeKnown) throws FunctionalException {
    try {
        final RtuDevice device = this.rtuDeviceRepository.findByDeviceIdentification(deviceIdentification).orElse(null);
        if (device == null && expectDeviceToBeKnown) {
            throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, COMPONENT_TYPE, new UnknownEntityException(RtuDevice.class, deviceIdentification));
        } else if (device == null) {
            logger.info("No RTU device {} found to update communication time information for." + " This may be appropriate as the device could be expected to be unknown to GXF.", deviceIdentification);
            return;
        }
        if (this.shouldUpdateCommunicationTime(device, this.minimumDurationBetweenCommunicationTimeUpdates)) {
            device.messageReceived();
            this.rtuDeviceRepository.save(device);
        } else {
            logger.info("Last communication time within duration: {}. Skipping last communication date update.", this.minimumDurationBetweenCommunicationTimeUpdates);
        }
    } catch (final OptimisticLockException | JpaOptimisticLockingFailureException ex) {
        logger.warn("Last communication time not updated due to optimistic lock exception", ex);
    }
}
Also used : RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) JpaOptimisticLockingFailureException(org.springframework.orm.jpa.JpaOptimisticLockingFailureException) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) OptimisticLockException(javax.persistence.OptimisticLockException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with RtuDevice

use of org.opensmartgridplatform.domain.core.entities.RtuDevice in project open-smart-grid-platform by OSGP.

the class CommunicationMonitoringJob method execute.

@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
    LOGGER.info("Executing communication monitoring job.");
    final Instant startTime = Instant.now().minus(this.maximumDurationWithoutCommunication);
    final List<RtuDevice> rtuDevices = this.getDevicesWithLastCommunicationBefore(startTime);
    LOGGER.info("Found {} device(s) for which communication should be restored.", rtuDevices.size());
    for (final RtuDevice rtu : rtuDevices) {
        LOGGER.debug("Restoring communication for device {}.", rtu.getDeviceIdentification());
        this.communicationRecoveryService.signalConnectionLost(rtu);
        this.communicationRecoveryService.restoreCommunication(rtu);
    }
    LOGGER.info("Finished executing communication monitoring job.");
}
Also used : RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Instant(java.time.Instant)

Aggregations

RtuDevice (org.opensmartgridplatform.domain.core.entities.RtuDevice)10 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)3 ArgumentNullOrEmptyException (org.opensmartgridplatform.domain.core.exceptions.ArgumentNullOrEmptyException)3 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)3 Instant (java.time.Instant)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 MicrogridsRequestMessage (org.opensmartgridplatform.adapter.ws.microgrids.infra.jms.MicrogridsRequestMessage)2 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Given (io.cucumber.java.en.Given)1 JMSException (javax.jms.JMSException)1 DistributionAutomationRequestMessage (org.opensmartgridplatform.adapter.ws.da.infra.jms.DistributionAutomationRequestMessage)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)1 JpaOptimisticLockingFailureException (org.springframework.orm.jpa.JpaOptimisticLockingFailureException)1