Remove Map in ACM-R for timeout Participant 06/138106/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Tue, 28 May 2024 13:28:52 +0000 (14:28 +0100)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 29 May 2024 09:44:16 +0000 (10:44 +0100)
Issue-ID: POLICY-5024
Change-Id: Ibb8a93be55380b110c84ec4580690f43e624d125
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
15 files changed:
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
models/src/main/java/org/onap/policy/clamp/models/acm/utils/TimestampHelper.java [new file with mode: 0644]
models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java [new file with mode: 0644]
models/src/test/resources/providers/TestParticipant.json
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
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/SupervisionAspectTest.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
runtime-acm/src/test/resources/providers/TestParticipant.json
runtime-acm/src/test/resources/providers/TestParticipant2.json

index c045c92..5bdf4d3 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,6 +43,9 @@ public class Participant {
     @NonNull
     private ParticipantState participantState = ParticipantState.ON_LINE;
 
+    @NonNull
+    private String lastMsg;
+
     @NonNull
     private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes = new HashMap<>();
 
@@ -54,6 +57,7 @@ public class Participant {
     public Participant(Participant otherParticipant) {
         this.participantState = otherParticipant.participantState;
         this.participantId = otherParticipant.participantId;
+        this.lastMsg = otherParticipant.lastMsg;
         this.participantSupportedElementTypes = PfUtils.mapMap(otherParticipant.getParticipantSupportedElementTypes(),
                 ParticipantSupportedElementType::new);
     }
index e5eade3..cfde557 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import jakarta.persistence.JoinColumn;
 import jakarta.persistence.OneToMany;
 import jakarta.persistence.Table;
 import java.io.Serializable;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -42,6 +43,7 @@ import lombok.NonNull;
 import org.apache.commons.lang3.ObjectUtils;
 import org.onap.policy.clamp.models.acm.concepts.Participant;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
 import org.onap.policy.common.parameters.annotations.NotNull;
 import org.onap.policy.common.parameters.annotations.Valid;
 import org.onap.policy.models.base.PfAuthorative;
@@ -72,6 +74,10 @@ public class JpaParticipant extends Validated
     @Column
     private String description;
 
+    @Column
+    @NotNull
+    private Timestamp lastMsg;
+
     @NotNull
     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
     @JoinColumn(name = "participantId", referencedColumnName = "participantId",
@@ -96,6 +102,7 @@ public class JpaParticipant extends Validated
         this.participantId = participantId;
         this.participantState = participantState;
         this.supportedElements = supportedElements;
+        this.lastMsg = TimestampHelper.nowTimestamp();
     }
 
     /**
@@ -108,6 +115,7 @@ public class JpaParticipant extends Validated
         this.description = copyConcept.description;
         this.participantId = copyConcept.participantId;
         this.supportedElements = copyConcept.supportedElements;
+        this.lastMsg = copyConcept.lastMsg;
     }
 
     /**
@@ -125,6 +133,7 @@ public class JpaParticipant extends Validated
 
         participant.setParticipantState(participantState);
         participant.setParticipantId(UUID.fromString(participantId));
+        participant.setLastMsg(this.lastMsg.toString());
         participant.setParticipantSupportedElementTypes(new LinkedHashMap<>(this.supportedElements.size()));
         for (var element : this.supportedElements) {
             participant.getParticipantSupportedElementTypes()
@@ -138,6 +147,7 @@ public class JpaParticipant extends Validated
     public void fromAuthorative(@NonNull final Participant participant) {
         this.setParticipantState(participant.getParticipantState());
         this.participantId = participant.getParticipantId().toString();
+        this.lastMsg = TimestampHelper.toTimestamp(participant.getLastMsg());
         this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size());
 
         for (var elementEntry : participant.getParticipantSupportedElementTypes().entrySet()) {
@@ -162,6 +172,11 @@ public class JpaParticipant extends Validated
             return result;
         }
 
+        result = lastMsg.compareTo(other.lastMsg);
+        if (result != 0) {
+            return result;
+        }
+
         result = ObjectUtils.compare(participantState, other.participantState);
         if (result != 0) {
             return result;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/TimestampHelper.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/TimestampHelper.java
new file mode 100644 (file)
index 0000000..d430f76
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.utils;
+
+import java.sql.Timestamp;
+import java.time.Instant;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class TimestampHelper {
+
+    public static String now() {
+        return Timestamp.from(Instant.now()).toString();
+    }
+
+    public static Timestamp nowTimestamp() {
+        return Timestamp.from(Instant.now());
+    }
+
+    public static Timestamp toTimestamp(String time) {
+        return Timestamp.valueOf(time);
+    }
+
+    public static long nowEpochMilli() {
+        return Instant.now().toEpochMilli();
+    }
+
+    public static long toEpochMilli(String time) {
+        return Timestamp.valueOf(time).toInstant().toEpochMilli();
+    }
+}
index fd06b39..a843c82 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation.
+ *  Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import java.util.HashMap;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
 
 class ParticipantInformationTest {
 
@@ -33,6 +34,7 @@ class ParticipantInformationTest {
         var participant = new Participant();
         participant.setParticipantId(UUID.randomUUID());
         participant.setParticipantState(ParticipantState.ON_LINE);
+        participant.setLastMsg(TimestampHelper.now());
         participant.setParticipantSupportedElementTypes(new HashMap<>());
         var participantInfo1 = new ParticipantInformation();
         participantInfo1.setParticipant(participant);
index 05ab495..e64a689 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
+ *  Copyright (C) 2021-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,12 +27,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.sql.Timestamp;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.models.acm.concepts.Participant;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
 
 /**
  * Test the {@link JpaParticipant} class.
@@ -43,6 +46,9 @@ class JpaParticipantTest {
 
     @Test
     void testJpaParticipantConstructor() {
+        assertThatThrownBy(() -> new JpaParticipant((Participant) null))
+                .hasMessageMatching("authorativeConcept is marked .*ull but is null");
+
         assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null))
             .hasMessageMatching("copyConcept is marked .*ull but is null");
 
@@ -64,11 +70,8 @@ class JpaParticipantTest {
 
     @Test
     void testJpaParticipant() {
-        var testJpaParticipant = createJpaParticipantInstance();
-
         var participant = createParticipantInstance();
-
-        participant.setParticipantId(testJpaParticipant.toAuthorative().getParticipantId());
+        var testJpaParticipant = new JpaParticipant(participant);
 
         assertEquals(participant, testJpaParticipant.toAuthorative());
 
@@ -89,7 +92,7 @@ class JpaParticipantTest {
 
     @Test
     void testJpaParticipantValidation() {
-        var testJpaParticipant = createJpaParticipantInstance();
+        var testJpaParticipant = new JpaParticipant(createParticipantInstance());
 
         assertThatThrownBy(() -> testJpaParticipant.validate(null))
             .hasMessageMatching("fieldName is marked .*ull but is null");
@@ -99,7 +102,7 @@ class JpaParticipantTest {
 
     @Test
     void testJpaParticipantCompareTo() {
-        var testJpaParticipant = createJpaParticipantInstance();
+        var testJpaParticipant = new JpaParticipant(createParticipantInstance());
 
         var otherJpaParticipant = new JpaParticipant(testJpaParticipant);
         otherJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
@@ -114,6 +117,12 @@ class JpaParticipantTest {
         assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
         assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
 
+        testJpaParticipant.setLastMsg(Timestamp.from(Instant.EPOCH));
+        assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+        testJpaParticipant.setLastMsg(otherJpaParticipant.getLastMsg());
+        assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+        assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
+
         var newJpaParticipant = new JpaParticipant(testJpaParticipant);
         newJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
         assertEquals(testJpaParticipant, newJpaParticipant);
@@ -140,22 +149,14 @@ class JpaParticipantTest {
 
         var p2 = new JpaParticipant();
         p2.setParticipantId(p0.getParticipantId());
+        p2.setLastMsg(p0.getLastMsg());
         assertEquals(p2, p0);
     }
 
-    private JpaParticipant createJpaParticipantInstance() {
-        var testParticipant = createParticipantInstance();
-        var testJpaParticipant = new JpaParticipant();
-        testParticipant.setParticipantId(UUID.fromString(testJpaParticipant.getParticipantId()));
-        testJpaParticipant.fromAuthorative(testParticipant);
-        testJpaParticipant.fromAuthorative(testParticipant);
-
-        return testJpaParticipant;
-    }
-
     private Participant createParticipantInstance() {
         var testParticipant = new Participant();
         testParticipant.setParticipantId(UUID.randomUUID());
+        testParticipant.setLastMsg(TimestampHelper.now());
         testParticipant.setParticipantSupportedElementTypes(new LinkedHashMap<>());
 
         return testParticipant;
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java
new file mode 100644 (file)
index 0000000..aaba0bc
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class TimestampHelperTest {
+
+    @Test
+    void testNow() {
+        assertThat(TimestampHelper.nowTimestamp()).isNotNull();
+        assertThat(TimestampHelper.now()).isNotNull();
+        assertThat(TimestampHelper.nowEpochMilli()).isNotNull();
+    }
+
+    @Test
+    void testToEpochMilli() {
+        var timeStr = TimestampHelper.now();
+        var milli = TimestampHelper.toTimestamp(timeStr).toInstant().toEpochMilli();
+        var result = TimestampHelper.toEpochMilli(timeStr);
+        assertThat(milli).isEqualTo(result);
+    }
+}
index 689c6a2..3f19baa 100644 (file)
@@ -8,6 +8,7 @@
   "participantState": "ON_LINE",
   "description": "A dummy PMSH participant1",
   "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6",
+  "lastMsg": "2024-05-22 10:04:37.6020187",
   "participantSupportedElementTypes": {
     "68fe8c61-7629-4be7-99d8-18bc6a92d178": {
       "id": "68fe8c61-7629-4be7-99d8-18bc6a92d178",
index 0d814bf..8f3a4c2 100644 (file)
@@ -28,8 +28,6 @@ import java.util.concurrent.TimeUnit;
 import lombok.RequiredArgsConstructor;
 import org.aspectj.lang.annotation.After;
 import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -72,11 +70,6 @@ public class SupervisionAspect implements Closeable {
         }
     }
 
-    @Before("@annotation(MessageIntercept) && args(participantStatusMsg,..)")
-    public void handleParticipantStatus(ParticipantStatus participantStatusMsg) {
-        executor.execute(() -> partecipantScanner.handleParticipantStatus(participantStatusMsg.getParticipantId()));
-    }
-
     @Override
     public void close() throws IOException {
         executor.shutdown();
index c07c584..4d2a22f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation.
+ *  Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.runtime.supervision;
 
-import java.util.UUID;
 import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
 import org.onap.policy.clamp.models.acm.concepts.Participant;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -36,7 +36,7 @@ import org.springframework.stereotype.Component;
 public class SupervisionPartecipantScanner {
     private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class);
 
-    private final TimeoutHandler<UUID> participantStatusTimeout = new TimeoutHandler<>();
+    private final long maxWaitMs;
 
     private final ParticipantProvider participantProvider;
 
@@ -49,8 +49,7 @@ public class SupervisionPartecipantScanner {
     public SupervisionPartecipantScanner(final ParticipantProvider participantProvider,
             final AcRuntimeParameterGroup acRuntimeParameterGroup) {
         this.participantProvider = participantProvider;
-
-        participantStatusTimeout.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+        this.maxWaitMs = acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs();
     }
 
     /**
@@ -68,29 +67,16 @@ public class SupervisionPartecipantScanner {
 
     private void scanParticipantStatus(Participant participant) {
         var id = participant.getParticipantId();
-        if (participantStatusTimeout.isTimeout(id)) {
-            if (ParticipantState.ON_LINE.equals(participant.getParticipantState())) {
-                // restart scenario
-                LOGGER.debug("Participant is back ON_LINE {}", id);
-                participantStatusTimeout.clear(id);
-            } else {
-                LOGGER.debug("report Participant is still OFF_LINE {}", id);
-                return;
-            }
+        if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) {
+            LOGGER.debug("report Participant is still OFF_LINE {}", id);
+            return;
         }
-        if (participantStatusTimeout.getDuration(id) > participantStatusTimeout.getMaxWaitMs()) {
+        var now = TimestampHelper.nowEpochMilli();
+        var lastMsg = TimestampHelper.toEpochMilli(participant.getLastMsg());
+        if ((now - lastMsg) > maxWaitMs) {
             LOGGER.debug("report Participant OFF_LINE {}", id);
-            participantStatusTimeout.setTimeout(id);
             participant.setParticipantState(ParticipantState.OFF_LINE);
             participantProvider.updateParticipant(participant);
         }
     }
-
-    /**
-     * handle participant Status message.
-     */
-    public void handleParticipantStatus(UUID id) {
-        LOGGER.debug("Participant is ON_LINE {}", id);
-        participantStatusTimeout.clear(id);
-    }
 }
index 24c256f..d1efb6a 100644 (file)
@@ -46,6 +46,7 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantSt
 import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
 import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -159,8 +160,9 @@ public class SupervisionParticipantHandler {
     private void checkOnline(Participant participant) {
         if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) {
             participant.setParticipantState(ParticipantState.ON_LINE);
-            participantProvider.saveParticipant(participant);
         }
+        participant.setLastMsg(TimestampHelper.now());
+        participantProvider.saveParticipant(participant);
     }
 
     private void handleRestart(UUID participantId) {
@@ -226,6 +228,7 @@ public class SupervisionParticipantHandler {
         participant.setParticipantId(participantId);
         participant.setParticipantSupportedElementTypes(participantSupportedElementType);
         participant.setParticipantState(ParticipantState.ON_LINE);
+        participant.setLastMsg(TimestampHelper.now());
         return participant;
     }
 
index 35dedb7..f78344b 100644 (file)
@@ -26,8 +26,6 @@ import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 
 import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
-import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
 
 class SupervisionAspectTest {
 
@@ -52,17 +50,4 @@ class SupervisionAspectTest {
             verify(supervisionScanner, timeout(500).times(2)).run();
         }
     }
-
-    @Test
-    void testHandleParticipantStatus() throws Exception {
-        var participantStatusMessage = new ParticipantStatus();
-        participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
-
-        var supervisionScanner = mock(SupervisionScanner.class);
-        var partecipantScanner = mock(SupervisionPartecipantScanner.class);
-        try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
-            supervisionAspect.handleParticipantStatus(participantStatusMessage);
-            verify(partecipantScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId());
-        }
-    }
 }
index 4bab85b..3c9f917 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation.
+ *  Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,26 +31,25 @@ import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.models.base.PfModelException;
 
 class SupervisionParticipantScannerTest {
 
     @Test
-    void testScanParticipant() throws PfModelException {
+    void testScanParticipant() {
         var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
         acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
 
         var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
-        participant.setParticipantState(ParticipantState.OFF_LINE);
         var participantProvider = mock(ParticipantProvider.class);
         when(participantProvider.getParticipants()).thenReturn(List.of(participant));
 
         var supervisionScanner = new SupervisionPartecipantScanner(participantProvider, acRuntimeParameterGroup);
 
-        supervisionScanner.handleParticipantStatus(participant.getParticipantId());
+        participant.setParticipantState(ParticipantState.OFF_LINE);
         supervisionScanner.run();
-        verify(participantProvider, times(0)).saveParticipant(any());
+        verify(participantProvider, times(0)).updateParticipant(any());
 
+        participant.setParticipantState(ParticipantState.ON_LINE);
         supervisionScanner.run();
         verify(participantProvider, times(1)).updateParticipant(any());
     }
index 8329d05..431a1ba 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
+ *  Copyright (C) 2021-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
 package org.onap.policy.clamp.acm.runtime.util;
 
 import jakarta.ws.rs.core.Response.Status;
-import java.util.List;
 import java.util.UUID;
 import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
 import org.onap.policy.clamp.acm.runtime.main.parameters.AcmParameters;
@@ -32,6 +31,7 @@ import org.onap.policy.clamp.models.acm.concepts.Participant;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -79,18 +79,6 @@ public class CommonTestData {
                 .replace("${dbName}", "jdbc:h2:mem:" + dbName);
     }
 
-    /**
-     * Create a List of Participants.
-     *
-     * @return a List of Participants
-     */
-    public static List<Participant> createParticipants() {
-        var participant1 = createParticipant(UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c02"));
-        var participant2 = createParticipant(UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c01"));
-        var participant3 = createParticipant(UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c03"));
-        return List.of(participant1, participant2, participant3);
-    }
-
     /**
      * Create a new Participant.
      *
@@ -101,6 +89,7 @@ public class CommonTestData {
         var participant = new Participant();
         participant.setParticipantId(participantId);
         participant.setParticipantState(ParticipantState.ON_LINE);
+        participant.setLastMsg(TimestampHelper.now());
         return participant;
     }
 
index fe06ba0..b900242 100644 (file)
@@ -8,6 +8,7 @@
   "participantState": "ON_LINE",
   "description": "A dummy PMSH participant1",
   "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6",
+  "lastMsg": "2024-05-22 10:04:37.6020187",
   "participantType": {
     "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition",
     "version": "1.0.0"
index 9a34184..f1495bd 100644 (file)
@@ -8,6 +8,7 @@
   "participantState": "ON_LINE",
   "description": "A dummy PMSH participant2",
   "participantId": "cac01d0a-7ba8-4dda-b9be-6983c46c0546",
+  "lastMsg": "2024-05-22 10:04:37.6020187",
   "participantType": {
     "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition2",
     "version": "1.0.0"