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