TargetManagement over RepositoryManagement (#2599)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -97,30 +97,18 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
private final AmqpMessageSenderService amqpSenderService;
|
||||
private final SystemSecurityContext systemSecurityContext;
|
||||
private final SystemManagement systemManagement;
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
|
||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
private final TenantConfigurationManagement tenantConfigurationManagement;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param rabbitTemplate the rabbitTemplate
|
||||
* @param amqpSenderService to send AMQP message
|
||||
* @param artifactUrlHandler for generating download URLs
|
||||
* @param systemSecurityContext for execution with system permissions
|
||||
* @param systemManagement the systemManagement
|
||||
* @param targetManagement to access target information
|
||||
* @param distributionSetManagement to retrieve modules
|
||||
* @param tenantConfigurationManagement to access tenant configuration
|
||||
*/
|
||||
@SuppressWarnings("java:S107")
|
||||
protected AmqpMessageDispatcherService(
|
||||
final RabbitTemplate rabbitTemplate,
|
||||
final AmqpMessageSenderService amqpSenderService, final ArtifactUrlHandler artifactUrlHandler,
|
||||
final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement,
|
||||
final TargetManagement targetManagement,
|
||||
final TargetManagement<? extends Target> targetManagement,
|
||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
||||
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||
final DeploymentManagement deploymentManagement,
|
||||
@@ -209,15 +197,13 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
protected void targetCancelAssignmentToDistributionSet(final CancelTargetAssignmentServiceEvent cancelTargetAssignmentServiceEvent) {
|
||||
final CancelTargetAssignmentEvent cancelEvent = cancelTargetAssignmentServiceEvent.getRemoteEvent();
|
||||
final List<Target> eventTargets = partitionedParallelExecution(
|
||||
cancelEvent.getActions().keySet(), targetManagement::getByControllerID);
|
||||
cancelEvent.getActions().keySet(), targetManagement::getByControllerId);
|
||||
|
||||
eventTargets.forEach(target ->
|
||||
cancelEvent.getActionPropertiesForController(target.getControllerId())
|
||||
.map(ActionProperties::getId)
|
||||
.ifPresent(actionId ->
|
||||
sendCancelMessageToTarget(cancelEvent.getTenant(), target.getControllerId(), actionId, target.getAddress())
|
||||
)
|
||||
);
|
||||
.ifPresent(actionId -> sendCancelMessageToTarget
|
||||
(cancelEvent.getTenant(), target.getControllerId(), actionId, IpUtil.addressToUri(target.getAddress()))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +266,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
void sendMultiActionRequestToTarget(
|
||||
final Target target, final List<Action> actions,
|
||||
final Function<SoftwareModule, Map<String, String>> getSoftwareModuleMetaData) {
|
||||
final URI targetAddress = target.getAddress();
|
||||
final URI targetAddress = IpUtil.addressToUri(target.getAddress());
|
||||
if (!IpUtil.isAmqpUri(targetAddress) || CollectionUtils.isEmpty(actions)) {
|
||||
return;
|
||||
}
|
||||
@@ -406,7 +392,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
|
||||
private List<Target> getTargetsWithoutPendingCancellations(final Set<String> controllerIds) {
|
||||
return partitionedParallelExecution(controllerIds, partition ->
|
||||
targetManagement.getByControllerID(partition).stream()
|
||||
targetManagement.getByControllerId(partition).stream()
|
||||
.filter(target -> {
|
||||
if (hasPendingCancellations(target.getId())) {
|
||||
log.debug("Target {} has pending cancellations. Will not send update message to it.",
|
||||
@@ -456,7 +442,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
? Collections.emptyMap()
|
||||
: softwareModuleManagement.findMetaDataBySoftwareModuleIdsAndTargetVisible(allSmIds);
|
||||
|
||||
targetManagement.getByControllerID(controllerIds).forEach(target ->
|
||||
targetManagement.getByControllerId(controllerIds).forEach(target ->
|
||||
sendMultiActionRequestToTarget(
|
||||
target, controllerIdToActions.get(target.getControllerId()), module -> getSoftwareModuleMetadata.get(module.getId())));
|
||||
}
|
||||
@@ -476,7 +462,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final ActionProperties action, final Target target, final Map<SoftwareModule, Map<String, String>> modules) {
|
||||
final String tenant = action.getTenant();
|
||||
|
||||
final URI targetAddress = target.getAddress();
|
||||
final URI targetAddress = IpUtil.addressToUri(target.getAddress());
|
||||
if (!IpUtil.isAmqpUri(targetAddress)) {
|
||||
return;
|
||||
}
|
||||
@@ -575,7 +561,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<SoftwareModule, Map<String, String>> getSoftwareModulesWithMetadata(final DistributionSet distributionSet) {
|
||||
final Map<Long, Map<String, String>> softwareModuleMetadata =
|
||||
softwareModuleManagement.findMetaDataBySoftwareModuleIdsAndTargetVisible(
|
||||
@@ -592,7 +577,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final Map<String, ActionProperties> actions, final List<Target> targets,
|
||||
final Map<SoftwareModule, Map<String, String>> modules) {
|
||||
final List<DmfTarget> dmfTargets = targets.stream()
|
||||
.filter(target -> IpUtil.isAmqpUri(target.getAddress()))
|
||||
.filter(target -> IpUtil.isAmqpUri(IpUtil.addressToUri(target.getAddress())))
|
||||
.map(t -> convertToDmfTarget(t, actions.get(t.getControllerId()).getId()))
|
||||
.toList();
|
||||
|
||||
@@ -613,6 +598,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final Message message = getMessageConverter().toMessage(
|
||||
batchRequest,
|
||||
createMessagePropertiesBatch(firstAction.getTenant(), getBatchEventTopicForAction(firstAction)));
|
||||
amqpSenderService.sendMessage(message, firstTarget.getAddress());
|
||||
amqpSenderService.sendMessage(message, IpUtil.addressToUri(firstTarget.getAddress()));
|
||||
}
|
||||
}
|
||||
@@ -365,7 +365,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
final Action action = actionOptional.get();
|
||||
if (action.isCancelingOrCanceled()) {
|
||||
amqpMessageDispatcherService.sendCancelMessageToTarget(
|
||||
target.getTenant(), target.getControllerId(), action.getId(), target.getAddress());
|
||||
target.getTenant(), target.getControllerId(), action.getId(), IpUtil.addressToUri(target.getAddress()));
|
||||
} else {
|
||||
amqpMessageDispatcherService.sendUpdateMessageToTarget(
|
||||
new ActionProperties(action), action.getTarget(), getSoftwareModulesWithMetadata(action.getDistributionSet()));
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.artifact.ArtifactFilesystem;
|
||||
import org.eclipse.hawkbit.repository.artifact.model.AbstractDbArtifact;
|
||||
import org.eclipse.hawkbit.repository.artifact.model.DbArtifactHash;
|
||||
@@ -91,8 +93,8 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
testTarget = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID)
|
||||
.securityToken(TEST_TOKEN).address(AMQP_URI.toString()));
|
||||
testTarget = targetManagement.create(
|
||||
Create.builder().controllerId(CONTROLLER_ID).securityToken(TEST_TOKEN).address(AMQP_URI.toString()).build());
|
||||
|
||||
this.rabbitTemplate = Mockito.mock(RabbitTemplate.class);
|
||||
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||
@@ -308,9 +310,8 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
private Message getCaptureAddressEvent(final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent) {
|
||||
final Target target = targetManagement
|
||||
.getByControllerID(targetAssignDistributionSetEvent.getActions().keySet().iterator().next()).get();
|
||||
return createArgumentCapture(target.getAddress());
|
||||
final Target target = targetManagement.getByControllerId(targetAssignDistributionSetEvent.getActions().keySet().iterator().next()).get();
|
||||
return createArgumentCapture(IpUtil.addressToUri(target.getAddress()));
|
||||
}
|
||||
|
||||
private Action createAction(final DistributionSet testDs) {
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionProperties;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
|
||||
@@ -188,7 +188,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
protected void assertDmfDownloadAndUpdateRequest(
|
||||
final DmfDownloadAndUpdateRequest request, final Set<SoftwareModule> softwareModules, final String controllerId) {
|
||||
assertSoftwareModules(softwareModules, request.getSoftwareModules());
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerID(controllerId));
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerId(controllerId));
|
||||
assertThat(updatedTarget).isNotNull();
|
||||
assertThat(updatedTarget.getSecurityToken()).isEqualTo(request.getTargetSecurityToken());
|
||||
}
|
||||
@@ -267,7 +267,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
final int existingTargetsAfterCreation, final TargetUpdateStatus expectedTargetStatus,
|
||||
final String createdBy, final Map<String, String> attributes) {
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, name, existingTargetsAfterCreation,
|
||||
expectedTargetStatus, createdBy, attributes, () -> targetManagement.getByControllerID(controllerId));
|
||||
expectedTargetStatus, createdBy, attributes, () -> targetManagement.getByControllerId(controllerId));
|
||||
}
|
||||
|
||||
protected void registerSameTargetAndAssertBasedOnVersion(final String controllerId,
|
||||
@@ -413,7 +413,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
|
||||
protected void assertConfirmRequest(final DmfConfirmRequest request, final Set<SoftwareModule> softwareModules, final String controllerId) {
|
||||
assertSoftwareModules(softwareModules, request.getSoftwareModules());
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerID(controllerId));
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerId(controllerId));
|
||||
assertThat(updatedTarget).isNotNull();
|
||||
assertThat(updatedTarget.getSecurityToken()).isEqualTo(request.getTargetSecurityToken());
|
||||
}
|
||||
@@ -459,7 +459,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
assertThat(target.getDescription()).contains(target.getControllerId());
|
||||
assertThat(target.getCreatedBy()).isEqualTo(createdBy);
|
||||
assertThat(target.getUpdateStatus()).isEqualTo(updateStatus);
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createAmqpUri(getVirtualHost(), DmfTestConfiguration.REPLY_TO_EXCHANGE));
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createAmqpUri(getVirtualHost(), DmfTestConfiguration.REPLY_TO_EXCHANGE).toString());
|
||||
assertThat(targetManagement.getControllerAttributes(target.getControllerId())).isEqualTo(attributes);
|
||||
}
|
||||
}
|
||||
@@ -787,7 +787,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
|
||||
private void waitUntilTargetHasStatus(final String controllerId, final TargetUpdateStatus status) {
|
||||
waitUntil(() -> {
|
||||
final Optional<Target> findTargetByControllerID = targetManagement.getByControllerID(controllerId);
|
||||
final Optional<Target> findTargetByControllerID = targetManagement.getByControllerId(controllerId);
|
||||
return findTargetByControllerID.isPresent()
|
||||
&& status.equals(findTargetByControllerID.get().getUpdateStatus());
|
||||
});
|
||||
|
||||
@@ -950,7 +950,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
amqpMessageHandlerService.setControllerManagement(mockedControllerManagement);
|
||||
createAndSendThingCreated(controllerId);
|
||||
verifyOneDeadLetterMessage();
|
||||
assertThat(targetManagement.getByControllerID(controllerId)).isEmpty();
|
||||
assertThat(targetManagement.getByControllerId(controllerId)).isEmpty();
|
||||
}
|
||||
} finally {
|
||||
amqpMessageHandlerService.setControllerManagement(controllerManagement);
|
||||
|
||||
Reference in New Issue
Block a user