Target attributes update can be (re-)triggered by management API (#690)
* extend Management API with attribute `requestAttributes` * introduce new DMF Event Topic `REQUEST_ATTRIBUTES_UPDATE` * enhance REST documentation by new functionality * add tests for: * Management API * Amqp Message Dispatcher Service * Repository (Target Management) Signed-off-by: Jeroen Jan Laverman (INST/ESY3) <jeroen.laverman@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
f4340098d9
commit
ecfe774e53
@@ -36,6 +36,7 @@ import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -157,8 +158,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
* window available, the topic {@link EventTopic#DOWNLOAD_AND_INSTALL} is
|
||||
* returned else {@link EventTopic#DOWNLOAD} is returned.
|
||||
*
|
||||
* @param target
|
||||
* for which to find the event type
|
||||
* @param maintenanceWindowAvailable
|
||||
* valid maintenance window or not.
|
||||
*
|
||||
* @return {@link EventTopic} to use for message.
|
||||
*/
|
||||
@@ -199,6 +200,12 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
sendDeleteMessage(deleteEvent.getTenant(), deleteEvent.getControllerId(), deleteEvent.getTargetAddress());
|
||||
}
|
||||
|
||||
@EventListener(classes = TargetAttributesRequestedEvent.class)
|
||||
protected void targetTriggerUpdateAttributes(final TargetAttributesRequestedEvent updateAttributesEvent) {
|
||||
sendUpdateAttributesMessageToTarget(updateAttributesEvent.getTenant(), updateAttributesEvent.getControllerId(),
|
||||
updateAttributesEvent.getTargetAddress());
|
||||
}
|
||||
|
||||
protected void sendUpdateMessageToTarget(final String tenant, final Target target, final Long actionId,
|
||||
final Map<SoftwareModule, List<SoftwareModuleMetadata>> modules, final boolean maintenanceWindowAvailable) {
|
||||
|
||||
@@ -270,6 +277,18 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
|
||||
}
|
||||
|
||||
protected void sendUpdateAttributesMessageToTarget(final String tenant, final String controllerId,
|
||||
final String targetAddress) {
|
||||
if (!hasValidAddress(targetAddress)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Message message = new Message(null,
|
||||
createConnectorMessagePropertiesEvent(tenant, controllerId, EventTopic.REQUEST_ATTRIBUTES_UPDATE));
|
||||
|
||||
amqpSenderService.sendMessage(message, URI.create(targetAddress));
|
||||
}
|
||||
|
||||
private static MessageProperties createConnectorMessagePropertiesEvent(final String tenant,
|
||||
final String controllerId, final EventTopic topic) {
|
||||
final MessageProperties messageProperties = createConnectorMessageProperties(tenant, controllerId);
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
|
||||
import org.eclipse.hawkbit.dmf.json.model.DmfMetadata;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
|
||||
@@ -213,6 +214,19 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that sending update controller attributes event works.")
|
||||
public void sendUpdateAttributesRequest() {
|
||||
final String amqpUri = "amqp://anyhost";
|
||||
final TargetAttributesRequestedEvent targetAttributesRequestedEvent = new TargetAttributesRequestedEvent(TENANT,
|
||||
1L, CONTROLLER_ID, amqpUri, Target.class.getName(), serviceMatcher.getServiceId());
|
||||
|
||||
amqpMessageDispatcherService.targetTriggerUpdateAttributes(targetAttributesRequestedEvent);
|
||||
|
||||
final Message sendMessage = createArgumentCapture(URI.create(amqpUri));
|
||||
assertUpdateAttributesMessage(sendMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that send cancel event works")
|
||||
@@ -299,7 +313,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(sendMessage,
|
||||
DmfDownloadAndUpdateRequest.class);
|
||||
assertEquals(downloadAndUpdateRequest.getActionId(), action);
|
||||
assertEquals("The topic of the event shuold contain DOWNLOAD_AND_INSTALL", EventTopic.DOWNLOAD_AND_INSTALL,
|
||||
assertEquals("The topic of the event should contain DOWNLOAD_AND_INSTALL", EventTopic.DOWNLOAD_AND_INSTALL,
|
||||
sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC));
|
||||
assertEquals("Security token of target", TEST_TOKEN, downloadAndUpdateRequest.getTargetSecurityToken());
|
||||
|
||||
@@ -307,6 +321,14 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
private void assertUpdateAttributesMessage(final Message sendMessage) {
|
||||
assertEventMessage(sendMessage);
|
||||
|
||||
assertEquals("The topic of the event should contain REQUEST_ATTRIBUTES_UPDATE",
|
||||
EventTopic.REQUEST_ATTRIBUTES_UPDATE,
|
||||
sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC));
|
||||
}
|
||||
|
||||
private void assertEventMessage(final Message sendMessage) {
|
||||
assertNotNull("The message should not be null", sendMessage);
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ public enum EventTopic {
|
||||
/**
|
||||
* Topic when sending a download only task, skipping the install.
|
||||
*/
|
||||
DOWNLOAD;
|
||||
DOWNLOAD,
|
||||
/**
|
||||
* Topic when an update of device attributes is requested.
|
||||
*/
|
||||
REQUEST_ATTRIBUTES_UPDATE;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user