Feature dispatcher refactoring (#872)
* added target validation for cancel event, allowed from-self check overriding Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * changed methods visibility Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * made isFromSelf a concrete implementation of shouldBeProcessed generic event method Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * changed log level to warn Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
f4475780d6
commit
41cbf23c62
@@ -136,7 +136,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
*/
|
*/
|
||||||
@EventListener(classes = TargetAssignDistributionSetEvent.class)
|
@EventListener(classes = TargetAssignDistributionSetEvent.class)
|
||||||
protected void targetAssignDistributionSet(final TargetAssignDistributionSetEvent assignedEvent) {
|
protected void targetAssignDistributionSet(final TargetAssignDistributionSetEvent assignedEvent) {
|
||||||
if (isNotFromSelf(assignedEvent)) {
|
if (!shouldBeProcessed(assignedEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,15 +161,15 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
* the Multi-Action event to be processed
|
* the Multi-Action event to be processed
|
||||||
*/
|
*/
|
||||||
@EventListener(classes = MultiActionEvent.class)
|
@EventListener(classes = MultiActionEvent.class)
|
||||||
protected void onMultiAction(final MultiActionEvent e) {
|
protected void onMultiAction(final MultiActionEvent multiActionEvent) {
|
||||||
if (isNotFromSelf(e)) {
|
if (!shouldBeProcessed(multiActionEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG.debug("MultiActionEvent received for {}", e.getControllerIds());
|
LOG.debug("MultiActionEvent received for {}", multiActionEvent.getControllerIds());
|
||||||
sendMultiActionRequestMessages(e.getTenant(), e.getControllerIds());
|
sendMultiActionRequestMessages(multiActionEvent.getTenant(), multiActionEvent.getControllerIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendMultiActionRequestMessages(final String tenant, final List<String> controllerIds) {
|
private void sendMultiActionRequestMessages(final String tenant, final List<String> controllerIds) {
|
||||||
|
|
||||||
final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModuleMetadata = new HashMap<>();
|
final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModuleMetadata = new HashMap<>();
|
||||||
targetManagement.getByControllerID(controllerIds).stream()
|
targetManagement.getByControllerID(controllerIds).stream()
|
||||||
@@ -284,12 +284,19 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
*/
|
*/
|
||||||
@EventListener(classes = CancelTargetAssignmentEvent.class)
|
@EventListener(classes = CancelTargetAssignmentEvent.class)
|
||||||
protected void targetCancelAssignmentToDistributionSet(final CancelTargetAssignmentEvent cancelEvent) {
|
protected void targetCancelAssignmentToDistributionSet(final CancelTargetAssignmentEvent cancelEvent) {
|
||||||
if (isNotFromSelf(cancelEvent)) {
|
if (!shouldBeProcessed(cancelEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCancelMessageToTarget(cancelEvent.getTenant(), cancelEvent.getEntity().getControllerId(),
|
final Target target = cancelEvent.getEntity();
|
||||||
cancelEvent.getActionId(), cancelEvent.getEntity().getAddress());
|
if (target != null) {
|
||||||
|
sendCancelMessageToTarget(cancelEvent.getTenant(), target.getControllerId(), cancelEvent.getActionId(),
|
||||||
|
target.getAddress());
|
||||||
|
} else {
|
||||||
|
LOG.warn(
|
||||||
|
"Cannot process the received CancelTargetAssignmentEvent with action ID {} because the referenced target with ID {} does no longer exist.",
|
||||||
|
cancelEvent.getActionId(), cancelEvent.getEntityId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,7 +309,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
*/
|
*/
|
||||||
@EventListener(classes = TargetDeletedEvent.class)
|
@EventListener(classes = TargetDeletedEvent.class)
|
||||||
protected void targetDelete(final TargetDeletedEvent deleteEvent) {
|
protected void targetDelete(final TargetDeletedEvent deleteEvent) {
|
||||||
if (isNotFromSelf(deleteEvent)) {
|
if (!shouldBeProcessed(deleteEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendDeleteMessage(deleteEvent.getTenant(), deleteEvent.getControllerId(), deleteEvent.getTargetAddress());
|
sendDeleteMessage(deleteEvent.getTenant(), deleteEvent.getControllerId(), deleteEvent.getTargetAddress());
|
||||||
@@ -352,7 +359,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
IpUtil.createAmqpUri(virtualHost, ping.getMessageProperties().getReplyTo()));
|
IpUtil.createAmqpUri(virtualHost, ping.getMessageProperties().getReplyTo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendDeleteMessage(final String tenant, final String controllerId, final String targetAddress) {
|
private void sendDeleteMessage(final String tenant, final String controllerId, final String targetAddress) {
|
||||||
|
|
||||||
if (!hasValidAddress(targetAddress)) {
|
if (!hasValidAddress(targetAddress)) {
|
||||||
return;
|
return;
|
||||||
@@ -366,8 +373,12 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
return targetAddress != null && IpUtil.isAmqpUri(URI.create(targetAddress));
|
return targetAddress != null && IpUtil.isAmqpUri(URI.create(targetAddress));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNotFromSelf(final RemoteApplicationEvent event) {
|
protected boolean shouldBeProcessed(final RemoteApplicationEvent event) {
|
||||||
return serviceMatcher != null && !serviceMatcher.isFromSelf(event);
|
return isFromSelf(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFromSelf(final RemoteApplicationEvent event) {
|
||||||
|
return serviceMatcher == null || serviceMatcher.isFromSelf(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendCancelMessageToTarget(final String tenant, final String controllerId, final Long actionId,
|
protected void sendCancelMessageToTarget(final String tenant, final String controllerId, final Long actionId,
|
||||||
@@ -386,7 +397,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendUpdateAttributesMessageToTarget(final String tenant, final String controllerId,
|
private void sendUpdateAttributesMessageToTarget(final String tenant, final String controllerId,
|
||||||
final String targetAddress) {
|
final String targetAddress) {
|
||||||
if (!hasValidAddress(targetAddress)) {
|
if (!hasValidAddress(targetAddress)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user