use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DomainRequestMessageListener method onMessage.
@Override
public void onMessage(final Message message) {
try {
LOGGER.info("Received domain request message of type: {} for domain: {} and domainVersion: {}", message.getJMSType(), this.domainInfo.getDomain(), this.domainInfo.getDomainVersion());
if (message.propertyExists(Constants.SCHEDULE_TIME)) {
final ScheduledTask scheduledTask = this.createScheduledTask(message);
this.scheduledTaskRepository.save(scheduledTask);
LOGGER.info("Scheduled task for device [{}] at [{}] created.", scheduledTask.getDeviceIdentification(), scheduledTask.getScheduledTime());
} else {
final ProtocolRequestMessage protocolRequestMessage = this.createProtocolRequestMessage(message);
this.deviceRequestMessageService.processMessage(protocolRequestMessage);
LOGGER.info("Domain request for device [{}] processed.", protocolRequestMessage.getDeviceIdentification());
}
} catch (final JMSException | FunctionalException e) {
LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceResponseMessageService method handleMessageRetry.
private void handleMessageRetry(final ProtocolResponseMessage message, final ScheduledTask scheduledTask) throws FunctionalException {
final Date scheduledRetryTime = message.getRetryHeader().getScheduledRetryTime();
final Long maxScheduleTime = message.getMaxScheduleTime();
if (this.timeForRetryExceedsMaxScheduleTime(scheduledRetryTime, maxScheduleTime)) {
this.scheduledTaskService.deleteScheduledTask(scheduledTask);
throw new FunctionalException(FunctionalExceptionType.MAX_SCHEDULE_TIME_EXCEEDED, ComponentType.OSGP_CORE, message.getOsgpException());
}
scheduledTask.setFailed(this.determineErrorMessage(message));
scheduledTask.retryOn(scheduledRetryTime);
this.scheduledTaskService.saveScheduledTask(scheduledTask);
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class Iec61850SetScheduleCommand method setScheduleOnDevice.
public void setScheduleOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final SetScheduleDeviceRequest deviceRequest, final Ssld ssld) throws ProtocolAdapterException {
final ScheduleDto scheduleDto = deviceRequest.getSchedule();
final RelayTypeDto relayType = deviceRequest.getRelayType();
final List<ScheduleEntryDto> scheduleList = scheduleDto.getScheduleList();
try {
// Creating a list of all Schedule entries, grouped by relay index.
final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = this.createScheduleEntries(scheduleList, ssld, relayType);
final Function<Void> function = new Iec61850SetScheduleFunction(iec61850Client, deviceConnection, deviceRequest, ssld, relaySchedulesEntries, this.loggingService, this.ssldDataService);
iec61850Client.sendCommandWithRetry(function, "SetSchedule", deviceConnection.getDeviceIdentification());
} catch (final FunctionalException e) {
throw new ProtocolAdapterException(e.getMessage(), e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class Iec61850SetScheduleCommand method setScheduleEntry.
private ScheduleEntry setScheduleEntry(final Ssld ssld, final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries, final RelayType relayType, final List<DeviceOutputSetting> settings, final ScheduleEntryDto schedule, final LightValueDto lightValue) throws FunctionalException {
final List<Integer> indexes = new ArrayList<>();
if (lightValue.getIndex() == 0 && (RelayType.TARIFF.equals(relayType) || RelayType.TARIFF_REVERSED.equals(relayType))) {
// Index 0 is not allowed for tariff switching.
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850);
} else if (lightValue.getIndex() == 0 && RelayType.LIGHT.equals(relayType)) {
// internal indexes to the indexes list.
for (final DeviceOutputSetting deviceOutputSetting : settings) {
indexes.add(deviceOutputSetting.getInternalId());
}
} else {
// Index != 0, adding just the one index to the list.
indexes.add(this.ssldDataService.convertToInternalIndex(ssld, lightValue.getIndex()));
}
final ScheduleEntry scheduleEntry;
try {
scheduleEntry = this.convertToScheduleEntry(schedule, lightValue);
} catch (final ProtocolAdapterException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850, e);
}
for (final Integer internalIndex : indexes) {
if (relaySchedulesEntries.containsKey(internalIndex)) {
// Internal index already in the Map, adding to the List
relaySchedulesEntries.get(internalIndex).add(scheduleEntry);
} else {
// First time we come across this relay, checking its
// type.
this.checkRelayForSchedules(this.ssldDataService.getDeviceOutputSettingForInternalIndex(ssld, internalIndex).getRelayType(), relayType, internalIndex);
// Adding it to scheduleEntries.
final List<ScheduleEntry> scheduleEntries = new ArrayList<>();
scheduleEntries.add(scheduleEntry);
relaySchedulesEntries.put(internalIndex, scheduleEntries);
}
}
return scheduleEntry;
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleResponseMessageReceived.
private void handleResponseMessageReceived(final String deviceIdentification) throws FunctionalException {
try {
final RtuDevice device = this.rtuDeviceRepository.findByDeviceIdentification(deviceIdentification).orElseThrow(() -> new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, COMPONENT_TYPE, new UnknownEntityException(RtuDevice.class, deviceIdentification)));
if (this.shouldUpdateCommunicationTime(device)) {
device.messageReceived();
this.rtuDeviceRepository.save(device);
} else {
LOGGER.info("Last communication time within duration: {}. Skipping last communication date update.", this.minimumDurationBetweenCommunicationTimeUpdates);
}
} catch (final OptimisticLockException ex) {
LOGGER.warn("Last communication time not updated due to optimistic lock exception", ex);
}
}
Aggregations