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
@@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetUpdate;
|
||||
@@ -640,4 +641,24 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return target.getControllerAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestControllerAttributes(final String controllerId) {
|
||||
final JpaTarget target = (JpaTarget) getByControllerID(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
target.setRequestControllerAttributes(true);
|
||||
|
||||
eventPublisher.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
||||
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
|
||||
JpaTarget.class.getName(), applicationContext.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControllerAttributesRequested(final String controllerId) {
|
||||
final JpaTarget target = (JpaTarget) getByControllerID(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
return target.isRequestControllerAttributes();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -178,8 +178,7 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
Page<Target> findByAssignedDistributionSetId(final Pageable pageable, final Long setID);
|
||||
|
||||
/**
|
||||
* Counts number of targets with given
|
||||
* {@link Target#getAssignedDistributionSet()}.
|
||||
* Counts number of targets with given distribution set Id.
|
||||
*
|
||||
* @param distId
|
||||
* to search for
|
||||
@@ -189,8 +188,7 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
Long countByAssignedDistributionSetId(final Long distId);
|
||||
|
||||
/**
|
||||
* Counts number of targets with given
|
||||
* {@link Target#getInstalledDistributionSet()}.
|
||||
* Counts number of targets with given distribution set Id.
|
||||
*
|
||||
* @param distId
|
||||
* to search for
|
||||
|
||||
@@ -880,4 +880,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Long> collect = foundDs.stream().map(Target::getId).collect(Collectors.toList());
|
||||
assertThat(collect).containsAll(searchIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that the flag for requesting controller attributes is set correctly.")
|
||||
public void verifyRequestControllerAttributes() {
|
||||
final String knownTargetId = "KnownControllerId";
|
||||
createTargetWithAttributes(knownTargetId);
|
||||
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isFalse();
|
||||
targetManagement.requestControllerAttributes(knownTargetId);
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isTrue();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user