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;
}
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.");
}
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);
}
}
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);
}
}
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.");
}
Aggregations