diff --git a/docs/src/main/resources/documentation/interfaces/dmf-api.md b/docs/src/main/resources/documentation/interfaces/dmf-api.md index e7c24beee..b61ca21cb 100644 --- a/docs/src/main/resources/documentation/interfaces/dmf-api.md +++ b/docs/src/main/resources/documentation/interfaces/dmf-api.md @@ -113,6 +113,7 @@ Payload Template "message":["String"] } ``` + Possible actionStatus | Header | Description | @@ -155,12 +156,25 @@ Possible actionStatus |-----------------------------|----------------------------------|-------------------------------------|---------------- | content_type | The content type of the payload | String | true -**Example Header** +Payload Template + +```json +{ +"actionId": long +} +``` + +**Example Header and payload** | Headers | MessageProperties | |---------------------------------------|---------------------------------| | type=EVENT
tenant=tenant123
thingId=abc
topic=CANCEL\_DOWNLOAD | content_type=application/json +```json +{ +"actionId":137 +} +``` After this message has been sent, an action status event with either actionStatus=CANCELED or actionStatus=CANCEL_REJECTED has to be returned. diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 46935afaf..eabea05e2 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -23,6 +23,7 @@ import org.eclipse.hawkbit.api.URLPlaceholder.SoftwareData; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; +import org.eclipse.hawkbit.dmf.json.model.DmfActionRequest; import org.eclipse.hawkbit.dmf.json.model.DmfArtifact; import org.eclipse.hawkbit.dmf.json.model.DmfArtifactHash; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest; @@ -241,7 +242,11 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { if (!IpUtil.isAmqpUri(address)) { return; } - final Message message = getMessageConverter().toMessage(actionId, + + final DmfActionRequest actionRequest = new DmfActionRequest(); + actionRequest.setActionId(actionId); + + final Message message = getMessageConverter().toMessage(actionRequest, createConnectorMessagePropertiesEvent(tenant, controllerId, EventTopic.CANCEL_DOWNLOAD)); amqpSenderService.sendMessage(message, address); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index d4ff8d147..2c5c41ef0 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -33,6 +33,7 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; +import org.eclipse.hawkbit.dmf.json.model.DmfActionRequest; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.DmfMetadata; import org.eclipse.hawkbit.repository.SystemManagement; @@ -277,8 +278,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { private void assertCancelMessage(final Message sendMessage) { assertEventMessage(sendMessage); - final Long actionId = convertMessage(sendMessage, Long.class); - assertEquals("Action ID should be 1", actionId, Long.valueOf(1)); + final DmfActionRequest actionId = convertMessage(sendMessage, DmfActionRequest.class); + assertEquals("Action ID should be 1", actionId.getActionId(), Long.valueOf(1)); assertEquals("The topc in the message should be a CANCEL_DOWNLOAD value", EventTopic.CANCEL_DOWNLOAD, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC)); } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java index 3cdb34eb7..0aeb247ce 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; +import org.eclipse.hawkbit.dmf.json.model.DmfActionRequest; import org.eclipse.hawkbit.dmf.json.model.DmfAttributeUpdate; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.DmfMetadata; @@ -128,8 +129,9 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration protected void assertCancelActionMessage(final Long actionId, final String controllerId) { final Message replyMessage = assertReplyMessageHeader(EventTopic.CANCEL_DOWNLOAD, controllerId); - final Long actionUpdateStatus = (Long) getDmfClient().getMessageConverter().fromMessage(replyMessage); - assertThat(actionUpdateStatus).isEqualTo(actionId); + final DmfActionRequest actionUpdateStatus = (DmfActionRequest) getDmfClient().getMessageConverter() + .fromMessage(replyMessage); + assertThat(actionUpdateStatus.getActionId()).isEqualTo(actionId); } protected void assertDeleteMessage(final String target) { diff --git a/hawkbit-dmf/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/DmfActionRequest.java b/hawkbit-dmf/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/DmfActionRequest.java new file mode 100644 index 000000000..c58df146a --- /dev/null +++ b/hawkbit-dmf/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/DmfActionRequest.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.dmf.json.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * JSON representation of an action related request. + * + */ +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class DmfActionRequest { + @JsonProperty + private Long actionId; + + public Long getActionId() { + return actionId; + } + + public void setActionId(final Long correlator) { + this.actionId = correlator; + } +} diff --git a/hawkbit-dmf/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/DmfDownloadAndUpdateRequest.java b/hawkbit-dmf/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/DmfDownloadAndUpdateRequest.java index 2a6d75f07..6e9bd818f 100644 --- a/hawkbit-dmf/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/DmfDownloadAndUpdateRequest.java +++ b/hawkbit-dmf/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/DmfDownloadAndUpdateRequest.java @@ -23,9 +23,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class DmfDownloadAndUpdateRequest { - @JsonProperty - private Long actionId; +public class DmfDownloadAndUpdateRequest extends DmfActionRequest { @JsonProperty private String targetSecurityToken; @@ -33,14 +31,6 @@ public class DmfDownloadAndUpdateRequest { @JsonProperty private List softwareModules; - public Long getActionId() { - return actionId; - } - - public void setActionId(final Long correlator) { - this.actionId = correlator; - } - public String getTargetSecurityToken() { return targetSecurityToken; }