use of org.opensmartgridplatform.domain.core.entities.ScheduledTask in project open-smart-grid-platform by OSGP.
the class ReschedulingSteps method bundledRequestIsRescheduled.
@Then("^the bundled request should be rescheduled$")
public void bundledRequestIsRescheduled(final Map<String, String> settings) {
final String deviceIdentification = getString(settings, KEY_DEVICE_IDENTIFICATION);
final String correlationUid = (String) ScenarioContext.current().get(PlatformKeys.KEY_CORRELATION_UID);
final Runnable assertion = () -> {
final ScheduledTask scheduledTask = this.scheduledTaskRepository.findByCorrelationUid(correlationUid);
assertThat(scheduledTask).isNotNull();
assertThat(scheduledTask.getDeviceIdentification()).isEqualTo(deviceIdentification);
};
final int numberOfRetries = 100;
final long delay = 1;
final TimeUnit unit = TimeUnit.SECONDS;
try {
assertWithRetries(assertion, numberOfRetries, delay, unit);
} catch (final AssertionError e) {
throw new AssertionError(String.format("Failed to find a scheduled retry task for bundled request message with correlationUid %s for device %s within %s", correlationUid, deviceIdentification, describeMaxDuration(numberOfRetries, delay, unit)), e);
}
}
use of org.opensmartgridplatform.domain.core.entities.ScheduledTask in project open-smart-grid-platform by OSGP.
the class ScheduledTaskSteps method createUpdateFirmwareScheduledTask.
private static ScheduledTask createUpdateFirmwareScheduledTask(final Map<String, String> settings) {
final String deviceIdentification = ReadSettingsHelper.getString(settings, KEY_DEVICE_IDENTIFICATION, DEFAULT_DEVICE_IDENTIFICATION);
final String organisationIdentification = ReadSettingsHelper.getString(settings, KEY_ORGANIZATION_IDENTIFICATION, DEFAULT_ORGANIZATION_IDENTIFICATION);
final String correlationUid = ReadSettingsHelper.getString(settings, KEY_CORRELATION_UID, DEFAULT_CORRELATION_UID);
final String messageType = MessageType.UPDATE_FIRMWARE.toString();
final int messagePriority = 4;
final Long scheduleTime = DateTimeHelper.getDateTime(ReadSettingsHelper.getString(settings, KEY_SCHEDULED_TIME, DEFAULT_SCHEDULED_TIME)).getMillis();
final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(messageType).withMessagePriority(messagePriority).withScheduleTime(scheduleTime).build();
final FirmwareModuleData firmwareModuleData = new FirmwareModuleData(null, "FW-01", null, null, null, null, null);
final String firmwareUrl = "firmware-url";
final Serializable messageData = new FirmwareUpdateMessageDataContainer(firmwareModuleData, firmwareUrl);
return new ScheduledTask(messageMetadata, "CORE", "1.0", messageData, new Timestamp(scheduleTime));
}
use of org.opensmartgridplatform.domain.core.entities.ScheduledTask 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.domain.core.entities.ScheduledTask in project open-smart-grid-platform by OSGP.
the class DeviceResponseMessageService method handleProtocolResponseMessage.
private void handleProtocolResponseMessage(final ProtocolResponseMessage message) throws FunctionalException {
final boolean allowRetryAttempt = !this.alreadyHasMaxScheduleTimeExceededException(message);
if (allowRetryAttempt && this.mustBeRetried(message)) {
// Create scheduled task for retries.
LOGGER.info("Creating a scheduled retry task for message of type {} for device {}.", message.getMessageType(), message.getDeviceIdentification());
final ScheduledTask task = this.createScheduledRetryTask(message);
this.scheduledTaskService.saveScheduledTask(task);
} else if (allowRetryAttempt && this.shouldRetryBasedOnMessage(message)) {
// Immediate retry based on error message. Should be deprecated.
LOGGER.info("Retrying: {} for device {} for {} time", message.getMessageType(), message.getDeviceIdentification(), message.getRetryCount() + 1);
final ProtocolRequestMessage protocolRequestMessage = this.createProtocolRequestMessage(message);
this.deviceRequestMessageService.processMessage(protocolRequestMessage);
} else {
LOGGER.info("Sending domain response message for message of type {} for device {} with correlationUid {}.", message.getMessageType(), message.getDeviceIdentification(), message.getCorrelationUid());
this.domainResponseMessageSender.send(message);
}
}
use of org.opensmartgridplatform.domain.core.entities.ScheduledTask in project open-smart-grid-platform by OSGP.
the class DeviceResponseMessageService method handleScheduledTask.
private void handleScheduledTask(final ProtocolResponseMessage message) throws FunctionalException {
final ScheduledTask scheduledTask = this.scheduledTaskService.findByCorrelationUid(message.getCorrelationUid());
if (scheduledTask == null) {
LOGGER.error("Scheduled task for device [{}] with correlation uid [{}] not found", message.getDeviceIdentification(), message.getCorrelationUid());
return;
}
if (this.messageIsSuccessful(message, scheduledTask)) {
this.domainResponseMessageSender.send(message);
this.scheduledTaskService.deleteScheduledTask(scheduledTask);
} else {
this.handleUnsuccessfulScheduledTask(message, scheduledTask);
}
}
Aggregations