Search in sources :

Example 1 with FirmwareUpdateMessageDataContainer

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer 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 2 with FirmwareUpdateMessageDataContainer

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

the class FirmwareManagementEndpoint method mapFirmwareModuleTypes.

private FirmwareUpdateMessageDataContainer mapFirmwareModuleTypes(final String firmwareIndentification, final List<FirmwareModuleType> firmwareModuleTypes) {
    String moduleVersionComm = null;
    String moduleVersionFunc = null;
    String moduleVersionMa = null;
    String moduleVersionMbus = null;
    String moduleVersionSec = null;
    String moduleVersionMBusDriverActive = null;
    String moduleVersionSimple = null;
    for (final FirmwareModuleType firmwareModuleType : firmwareModuleTypes) {
        final String firmwareModuleTypeString = firmwareModuleType.toString();
        if (FirmwareModuleType.COMMUNICATION.equals(firmwareModuleType)) {
            moduleVersionComm = firmwareModuleTypeString;
        } else if (FirmwareModuleType.FUNCTIONAL.equals(firmwareModuleType)) {
            moduleVersionFunc = firmwareModuleTypeString;
        } else if (FirmwareModuleType.MODULE_ACTIVE.equals(firmwareModuleType)) {
            moduleVersionMa = firmwareModuleTypeString;
        } else if (FirmwareModuleType.M_BUS.equals(firmwareModuleType)) {
            moduleVersionMbus = firmwareModuleTypeString;
        } else if (FirmwareModuleType.SECURITY.equals(firmwareModuleType)) {
            moduleVersionSec = firmwareModuleTypeString;
        } else if (FirmwareModuleType.M_BUS_DRIVER_ACTIVE.equals(firmwareModuleType)) {
            moduleVersionMBusDriverActive = firmwareModuleTypeString;
        } else if (FirmwareModuleType.SIMPLE_VERSION_INFO.equals(firmwareModuleType)) {
            moduleVersionSimple = firmwareModuleTypeString;
        }
    }
    final FirmwareModuleData firmwareModuleData = new FirmwareModuleData(moduleVersionComm, moduleVersionFunc, moduleVersionMa, moduleVersionMbus, moduleVersionSec, moduleVersionMBusDriverActive, moduleVersionSimple);
    return new FirmwareUpdateMessageDataContainer(firmwareModuleData, firmwareIndentification);
}
Also used : FirmwareModuleData(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleData) FirmwareUpdateMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer) FirmwareModuleType(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.FirmwareModuleType)

Example 3 with FirmwareUpdateMessageDataContainer

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

the class FirmwareManagementEndpoint method updateFirmware.

// === UPDATE FIRMWARE ===
@PayloadRoot(localPart = "UpdateFirmwareRequest", namespace = NAMESPACE)
@ResponsePayload
public UpdateFirmwareAsyncResponse updateFirmware(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateFirmwareRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("UpdateFirmware Request received from organisation {} for device {} with firmware name {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), request.getFirmwareIdentification(), messagePriority);
    final UpdateFirmwareAsyncResponse response = new UpdateFirmwareAsyncResponse();
    try {
        final FirmwareUpdateMessageDataContainer firmwareUpdateMessageDataContainer = this.mapFirmwareModuleTypes(request.getFirmwareIdentification(), request.getFirmwareModuleType());
        // Get the request parameters, make sure that they are in UTC.
        // Maybe add an adapter to the service, so that all datetime are
        // converted to utc automatically.
        final DateTime scheduleTime = request.getScheduledTime() == null ? null : new DateTime(request.getScheduledTime().toGregorianCalendar()).toDateTime(DateTimeZone.UTC);
        final String correlationUid = this.firmwareManagementService.enqueueUpdateFirmwareRequest(organisationIdentification, request.getDeviceIdentification(), firmwareUpdateMessageDataContainer, scheduleTime, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        LOGGER.error("Exception updating firmware", e);
        this.handleException(e);
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : FirmwareUpdateMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer) ConstraintViolationException(javax.validation.ConstraintViolationException) UpdateFirmwareAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.UpdateFirmwareAsyncResponse) SwitchFirmwareAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.SwitchFirmwareAsyncResponse) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse) GetFirmwareVersionAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.GetFirmwareVersionAsyncResponse) UpdateFirmwareAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.UpdateFirmwareAsyncResponse) DateTime(org.joda.time.DateTime) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 4 with FirmwareUpdateMessageDataContainer

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

the class CommonUpdateFirmwareRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing common update firmware request message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    Boolean isScheduled = null;
    Long scheduleTime = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        isScheduled = message.getBooleanProperty(Constants.IS_SCHEDULED);
        if (message.propertyExists(Constants.SCHEDULE_TIME)) {
            scheduleTime = message.getLongProperty(Constants.SCHEDULE_TIME);
        }
    } 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("isScheduled: {}", isScheduled);
        return;
    }
    try {
        final FirmwareUpdateMessageDataContainer firmwareUpdateMessageDataContainer = (FirmwareUpdateMessageDataContainer) message.getObject();
        LOGGER.info("Calling application service function: {}", messageType);
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.firmwareManagementService.updateFirmware(ids, firmwareUpdateMessageDataContainer, scheduleTime, messageType, messagePriority);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : FirmwareUpdateMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer) JMSException(javax.jms.JMSException) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) JMSException(javax.jms.JMSException)

Aggregations

FirmwareUpdateMessageDataContainer (org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer)4 FirmwareModuleData (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleData)2 Serializable (java.io.Serializable)1 Timestamp (java.sql.Timestamp)1 JMSException (javax.jms.JMSException)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 DateTime (org.joda.time.DateTime)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)1 FirmwareModuleType (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.FirmwareModuleType)1 GetFirmwareVersionAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.GetFirmwareVersionAsyncResponse)1 SwitchFirmwareAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.SwitchFirmwareAsyncResponse)1 UpdateFirmwareAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.UpdateFirmwareAsyncResponse)1 ScheduledTask (org.opensmartgridplatform.domain.core.entities.ScheduledTask)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)1 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1