Search in sources :

Example 1 with ScheduledTask

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);
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Then(io.cucumber.java.en.Then)

Example 2 with ScheduledTask

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));
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) FirmwareModuleData(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleData) FirmwareUpdateMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer) ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask) Timestamp(java.sql.Timestamp)

Example 3 with ScheduledTask

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);
    }
}
Also used : ProtocolRequestMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolRequestMessage) ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask) JMSException(javax.jms.JMSException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 4 with ScheduledTask

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);
    }
}
Also used : ProtocolRequestMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolRequestMessage) ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask)

Example 5 with ScheduledTask

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);
    }
}
Also used : ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask)

Aggregations

ScheduledTask (org.opensmartgridplatform.domain.core.entities.ScheduledTask)13 Timestamp (java.sql.Timestamp)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)4 ProtocolRequestMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolRequestMessage)4 Serializable (java.io.Serializable)3 Date (java.util.Date)3 Test (org.junit.jupiter.api.Test)3 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)3 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)3 Calendar (java.util.Calendar)2 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)2 RetryHeader (org.opensmartgridplatform.shared.infra.jms.RetryHeader)2 Given (io.cucumber.java.en.Given)1 Then (io.cucumber.java.en.Then)1 ArrayList (java.util.ArrayList)1 TimeUnit (java.util.concurrent.TimeUnit)1 JMSException (javax.jms.JMSException)1 ObjectMessage (javax.jms.ObjectMessage)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1