Add registration improvement in ACM-r 82/141882/2
authorFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 20 Aug 2025 16:09:27 +0000 (17:09 +0100)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Thu, 21 Aug 2025 14:21:40 +0000 (15:21 +0100)
Issue-ID: POLICY-5449
Change-Id: Ib8831bb3fd4168c4f1fbe7f2d0f6f4c90bf0d0fe
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java

index ba223d2..1cae2f8 100644 (file)
 package org.onap.policy.clamp.acm.runtime.supervision;
 
 import io.micrometer.core.annotation.Timed;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import java.util.function.UnaryOperator;
 import java.util.stream.Collectors;
 import lombok.AllArgsConstructor;
-import org.apache.commons.collections4.MapUtils;
 import org.onap.policy.clamp.acm.runtime.main.utils.EncryptionUtils;
 import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
 import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher;
@@ -136,15 +134,17 @@ public class SupervisionParticipantHandler {
             List<ParticipantSupportedElementType> participantSupportedElementType, boolean registration) {
         var replicaId = msgReplicaId != null ? msgReplicaId : participantId;
         var replicaOpt = participantProvider.findParticipantReplica(replicaId);
+        var toRestart = registration;
         if (replicaOpt.isPresent()) {
             var replica = replicaOpt.get();
             checkOnline(replica);
+            toRestart = false;
         } else {
             var participant = getParticipant(participantId, listToMap(participantSupportedElementType));
             participant.getReplicas().put(replicaId, createReplica(replicaId));
             participantProvider.saveParticipant(participant);
         }
-        if (registration) {
+        if (toRestart) {
             handleRestart(participantId, replicaId);
         }
     }
@@ -230,9 +230,8 @@ public class SupervisionParticipantHandler {
     }
 
     private Map<UUID, ParticipantSupportedElementType> listToMap(List<ParticipantSupportedElementType> elementList) {
-        Map<UUID, ParticipantSupportedElementType> map = new HashMap<>();
-        MapUtils.populateMap(map, elementList, ParticipantSupportedElementType::getId);
-        return map;
+        return elementList.stream()
+                .collect(Collectors.toMap(ParticipantSupportedElementType::getId, UnaryOperator.identity()));
     }
 
     /**
index 67ac077..aaa75cc 100644 (file)
@@ -171,7 +171,7 @@ class SupervisionParticipantHandlerTest {
                 .send(participantRegisterMessage.getMessageId(), participantId, replicaId);
         verify(acDefinitionProvider, times(0)).updateAcDefinition(any(AutomationCompositionDefinition.class),
                 eq(CommonTestData.TOSCA_COMP_NAME));
-        verify(participantSyncPublisher)
+        verify(participantSyncPublisher, times(0))
                 .sendRestartMsg(any(), any(), any(AutomationCompositionDefinition.class), any());
     }