Remove retry count support in ACM
Due the new timeout implementation, the Retry Count support
could be removed.
Issue-ID: POLICY-4735
Change-Id: I3b9c50a761696e00bcd1ca73dafa382c481e921d
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml
index c4c68f4..a8e45ff 100644
--- a/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml
+++ b/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml
@@ -41,9 +41,6 @@
participantParameters:
heartBeatMs: 20000
maxStatusWaitMs: 100000
- updateParameters:
- maxRetryCount: 3
- maxWaitMs: 20000
topicParameterGroup:
topicSources:
-
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantParameters.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantParameters.java
index 248824f..8c3a707 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantParameters.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantParameters.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021,2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,9 +18,7 @@
package org.onap.policy.clamp.acm.runtime.main.parameters;
-import javax.validation.Valid;
import javax.validation.constraints.Min;
-import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.springframework.validation.annotation.Validated;
@@ -38,8 +36,4 @@
@Min(100)
private long maxStatusWaitMs;
-
- @Valid
- @NotNull
- private ParticipantUpdateParameters updateParameters;
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantUpdateParameters.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantUpdateParameters.java
deleted file mode 100644
index 5ffaf39..0000000
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantUpdateParameters.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.runtime.main.parameters;
-
-import javax.validation.constraints.Min;
-import lombok.Getter;
-import lombok.Setter;
-import org.springframework.validation.annotation.Validated;
-
-/**
- * Parameters for Participant UPDATE requests.
- */
-@Getter
-@Setter
-@Validated
-public class ParticipantUpdateParameters {
-
- /**
- * Maximum number of times to re-send a request to a PDP.
- */
- @Min(value = 1)
- private int maxRetryCount;
-
- /**
- * Maximum time to wait, in milliseconds, for a PDP response.
- */
- @Min(value = 100)
- private long maxWaitMs;
-
-}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/HandleCounter.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/HandleCounter.java
deleted file mode 100644
index 9949f3c..0000000
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/HandleCounter.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.acm.runtime.supervision;
-
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import lombok.Getter;
-import lombok.Setter;
-
-public class HandleCounter<K> {
- @Getter
- @Setter
- private long maxWaitMs;
-
- @Getter
- @Setter
- private int maxRetryCount;
-
- private Map<K, Integer> mapCounter = new HashMap<>();
- private Set<K> mapFault = new HashSet<>();
- private Map<K, Long> mapTimer = new HashMap<>();
-
- public long getDuration(K id) {
- mapTimer.putIfAbsent(id, getEpochMilli());
- return getEpochMilli() - mapTimer.get(id);
- }
-
- /**
- * Reset timer and clear counter and fault by id.
- *
- * @param id the id
- */
- public void clear(K id) {
- mapFault.remove(id);
- mapCounter.put(id, 0);
- mapTimer.put(id, getEpochMilli());
- }
-
- /**
- * Remove counter, timer and fault by id.
- *
- * @param id the id
- */
- public void remove(K id) {
- mapFault.remove(id);
- mapCounter.remove(id);
- mapTimer.remove(id);
- }
-
- public void setFault(K id) {
- mapCounter.put(id, 0);
- mapFault.add(id);
- }
-
- /**
- * Increment RetryCount by id e return true if minor or equal of maxRetryCount.
- *
- * @param id the identifier
- * @return false if count is major of maxRetryCount
- */
- public boolean count(K id) {
- int counter = mapCounter.getOrDefault(id, 0) + 1;
- if (counter <= maxRetryCount) {
- mapCounter.put(id, counter);
- return true;
- }
- return false;
- }
-
- public boolean isFault(K id) {
- return mapFault.contains(id);
- }
-
- public int getCounter(K id) {
- return mapCounter.getOrDefault(id, 0);
- }
-
- protected long getEpochMilli() {
- return Instant.now().toEpochMilli();
- }
-
- public Set<K> keySet() {
- return mapCounter.keySet();
- }
-}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
index ef50a63..7303fc8 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@
}
private void executeScan() {
- supervisionScanner.run(true);
+ supervisionScanner.run();
partecipantScanner.run();
}
@@ -68,7 +68,7 @@
public void doCheck() {
if (executor.getQueue().size() < 2) {
LOGGER.debug("Add scanning Message");
- executor.execute(() -> supervisionScanner.run(false));
+ executor.execute(() -> supervisionScanner.run());
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
index b396e62..092fc35 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
@@ -36,7 +36,7 @@
public class SupervisionPartecipantScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class);
- private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>();
+ private final TimeoutHandler<UUID> participantStatusTimeout = new TimeoutHandler<>();
private final ParticipantProvider participantProvider;
@@ -51,9 +51,7 @@
final AcRuntimeParameterGroup acRuntimeParameterGroup) {
this.participantProvider = participantProvider;
- participantStatusCounter.setMaxRetryCount(
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+ participantStatusTimeout.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
/**
@@ -71,14 +69,13 @@
private void scanParticipantStatus(Participant participant) {
var id = participant.getParticipantId();
- if (participantStatusCounter.isFault(id)) {
+ if (participantStatusTimeout.isTimeout(id)) {
LOGGER.debug("report Participant fault");
return;
}
- if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs()
- && !participantStatusCounter.count(id)) {
+ if (participantStatusTimeout.getDuration(id) > participantStatusTimeout.getMaxWaitMs()) {
LOGGER.debug("report Participant fault");
- participantStatusCounter.setFault(id);
+ participantStatusTimeout.setTimeout(id);
participant.setParticipantState(ParticipantState.OFF_LINE);
participantProvider.updateParticipant(participant);
}
@@ -88,6 +85,6 @@
* handle participant Status message.
*/
public void handleParticipantStatus(UUID id) {
- participantStatusCounter.clear(id);
+ participantStatusTimeout.clear(id);
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
index 41c7b1c..b1bd292 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
@@ -47,7 +47,7 @@
public class SupervisionScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class);
- private final HandleCounter<UUID> automationCompositionCounter = new HandleCounter<>();
+ private final TimeoutHandler<UUID> acTimeout = new TimeoutHandler<>();
private final Map<UUID, Integer> phaseMap = new HashMap<>();
private final AutomationCompositionProvider automationCompositionProvider;
@@ -74,25 +74,20 @@
this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher;
this.automationCompositionDeployPublisher = automationCompositionDeployPublisher;
- automationCompositionCounter.setMaxRetryCount(
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- automationCompositionCounter
- .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+ acTimeout.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
/**
* Run Scanning.
- *
- * @param counterCheck if true activate counter and retry
*/
- public void run(boolean counterCheck) {
+ public void run() {
LOGGER.debug("Scanning automation compositions in the database . . .");
var list = acDefinitionProvider.getAllAcDefinitions();
for (var acDefinition : list) {
var acList = automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId());
for (var automationComposition : acList) {
- scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate(), counterCheck);
+ scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate());
}
}
@@ -100,23 +95,24 @@
}
private void scanAutomationComposition(final AutomationComposition automationComposition,
- ToscaServiceTemplate serviceTemplate, boolean counterCheck) {
+ ToscaServiceTemplate serviceTemplate) {
LOGGER.debug("scanning automation composition {} . . .", automationComposition.getInstanceId());
if (!AcmUtils.isInTransitionalState(automationComposition.getDeployState(),
- automationComposition.getLockState())) {
+ automationComposition.getLockState())
+ || StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())) {
LOGGER.debug("automation composition {} scanned, OK", automationComposition.getInstanceId());
- // Clear missed report counter on automation composition
- clearFaultAndCounter(automationComposition);
+ // Clear Timeout on automation composition
+ clearTimeout(automationComposition, true);
return;
}
- if (automationCompositionCounter.isFault(automationComposition.getInstanceId())
+ if (acTimeout.isTimeout(automationComposition.getInstanceId())
&& StateChangeResult.NO_ERROR.equals(automationComposition.getStateChangeResult())) {
// retry by the user
- LOGGER.debug("clearing fault for the ac instance");
- clearFaultAndCounter(automationComposition);
+ LOGGER.debug("clearing Timeout for the ac instance");
+ clearTimeout(automationComposition, true);
}
var completed = true;
@@ -148,6 +144,7 @@
if (DeployState.UPDATING.equals(automationComposition.getDeployState())) {
// UPDATING do not need phases
+ handleTimeout(automationComposition);
return;
}
@@ -161,10 +158,8 @@
phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted);
sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted,
firstStartPhase == nextSpNotCompleted);
- } else if (counterCheck) {
- phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted);
- handleCounter(automationComposition, serviceTemplate, nextSpNotCompleted,
- firstStartPhase == nextSpNotCompleted);
+ } else {
+ handleTimeout(automationComposition);
}
}
}
@@ -172,42 +167,39 @@
private void complete(final AutomationComposition automationComposition) {
var deployState = automationComposition.getDeployState();
automationComposition.setDeployState(AcmUtils.deployCompleted(deployState));
- automationComposition
- .setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState()));
+ automationComposition.setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState()));
+ if (StateChangeResult.TIMEOUT.equals(automationComposition.getStateChangeResult())) {
+ automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ }
if (DeployState.DELETED.equals(automationComposition.getDeployState())) {
automationCompositionProvider.deleteAutomationComposition(automationComposition.getInstanceId());
} else {
automationCompositionProvider.updateAutomationComposition(automationComposition);
}
- // Clear missed report counter on automation composition
- clearFaultAndCounter(automationComposition);
+ // Clear timeout on automation composition
+ clearTimeout(automationComposition, true);
}
- private void clearFaultAndCounter(AutomationComposition automationComposition) {
- automationCompositionCounter.clear(automationComposition.getInstanceId());
- phaseMap.remove(automationComposition.getInstanceId());
+ private void clearTimeout(AutomationComposition automationComposition, boolean cleanPhase) {
+ acTimeout.clear(automationComposition.getInstanceId());
+ if (cleanPhase) {
+ phaseMap.remove(automationComposition.getInstanceId());
+ }
}
- private void handleCounter(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate,
- int startPhase, boolean firstStartPhase) {
+ private void handleTimeout(AutomationComposition automationComposition) {
var instanceId = automationComposition.getInstanceId();
- if (automationCompositionCounter.isFault(instanceId)) {
- LOGGER.debug("report AutomationComposition fault");
+ if (acTimeout.isTimeout(instanceId)) {
+ LOGGER.debug("The ac instance is in timeout {}", automationComposition.getInstanceId());
return;
}
- if (automationCompositionCounter.getDuration(instanceId) > automationCompositionCounter.getMaxWaitMs()) {
- if (automationCompositionCounter.count(instanceId)) {
- phaseMap.put(instanceId, startPhase);
- sendAutomationCompositionMsg(automationComposition, serviceTemplate, startPhase, firstStartPhase);
- } else {
- LOGGER.debug("report AutomationComposition fault");
- automationCompositionCounter.setFault(instanceId);
- LOGGER.debug("report timeout for the ac instance");
- automationComposition.setStateChangeResult(StateChangeResult.TIMEOUT);
- automationCompositionProvider.updateAutomationComposition(automationComposition);
- }
+ if (acTimeout.getDuration(instanceId) > acTimeout.getMaxWaitMs()) {
+ LOGGER.debug("Report timeout for the ac instance {}", automationComposition.getInstanceId());
+ acTimeout.setTimeout(instanceId);
+ automationComposition.setStateChangeResult(StateChangeResult.TIMEOUT);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
}
}
@@ -221,5 +213,7 @@
LOGGER.debug("retry message AutomationCompositionStateChange");
automationCompositionStateChangePublisher.send(automationComposition, startPhase, firstStartPhase);
}
+ // Clear timeout on automation composition
+ clearTimeout(automationComposition, false);
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java
new file mode 100644
index 0000000..976c914
--- /dev/null
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.acm.runtime.supervision;
+
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
+
+public class TimeoutHandler<K> {
+ @Getter
+ @Setter
+ private long maxWaitMs;
+
+ private Set<K> mapTimeout = new HashSet<>();
+ private Map<K, Long> mapTimer = new HashMap<>();
+
+ public long getDuration(K id) {
+ mapTimer.putIfAbsent(id, getEpochMilli());
+ return getEpochMilli() - mapTimer.get(id);
+ }
+
+ /**
+ * Reset timer and timeout by id.
+ *
+ * @param id the id
+ */
+ public void clear(K id) {
+ mapTimeout.remove(id);
+ mapTimer.put(id, getEpochMilli());
+ }
+
+ /**
+ * Remove timer and timeout by id.
+ *
+ * @param id the id
+ */
+ public void remove(K id) {
+ mapTimeout.remove(id);
+ mapTimer.remove(id);
+ }
+
+ public void setTimeout(K id) {
+ mapTimeout.add(id);
+ }
+
+ public boolean isTimeout(K id) {
+ return mapTimeout.contains(id);
+ }
+
+ protected long getEpochMilli() {
+ return Instant.now().toEpochMilli();
+ }
+}
diff --git a/runtime-acm/src/main/resources/application.yaml b/runtime-acm/src/main/resources/application.yaml
index 771d700..faef54a 100644
--- a/runtime-acm/src/main/resources/application.yaml
+++ b/runtime-acm/src/main/resources/application.yaml
@@ -43,9 +43,6 @@
participantParameters:
heartBeatMs: 20000
maxStatusWaitMs: 100000
- updateParameters:
- maxRetryCount: 4
- maxWaitMs: 20000
topicParameterGroup:
topicSources:
-
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/HandleCounterTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/HandleCounterTest.java
deleted file mode 100644
index e50126d..0000000
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/HandleCounterTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 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.acm.runtime.supervision;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.Test;
-
-class HandleCounterTest {
-
- private static final int ID = 1;
-
- @Test
- void testCount() {
- var handleCounter = new HandleCounter<Integer>();
- handleCounter.setMaxRetryCount(2);
- assertThat(handleCounter.count(ID)).isTrue();
- assertThat(handleCounter.getCounter(ID)).isEqualTo(1);
- assertThat(handleCounter.count(ID)).isTrue();
- assertThat(handleCounter.getCounter(ID)).isEqualTo(2);
- assertThat(handleCounter.count(ID)).isFalse();
- assertThat(handleCounter.getCounter(ID)).isEqualTo(2);
-
- handleCounter.clear(ID);
- assertThat(handleCounter.count(ID)).isTrue();
- assertThat(handleCounter.getCounter(ID)).isEqualTo(1);
- }
-
- @Test
- void testFault() {
- var handleCounter = new HandleCounter<Integer>();
- handleCounter.setFault(ID);
- assertThat(handleCounter.isFault(ID)).isTrue();
- handleCounter.clear(ID);
- assertThat(handleCounter.isFault(ID)).isFalse();
- }
-
- @Test
- void testDuration() {
- var handleCounter = new HandleCounter<Integer>() {
- long epochMilli = 0;
-
- @Override
- protected long getEpochMilli() {
- return epochMilli;
- }
- };
- handleCounter.epochMilli = 100;
- var result = handleCounter.getDuration(ID);
- assertThat(result).isZero();
-
- handleCounter.epochMilli += 100;
- result = handleCounter.getDuration(ID);
- assertThat(result).isEqualTo(100);
-
- handleCounter.epochMilli += 100;
- result = handleCounter.getDuration(ID);
- assertThat(result).isEqualTo(200);
-
- handleCounter.epochMilli += 100;
- handleCounter.clear(ID);
- result = handleCounter.getDuration(ID);
- assertThat(result).isZero();
- }
-}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
index c9985e2..0cee08a 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,7 +37,7 @@
var partecipantScanner = mock(SupervisionPartecipantScanner.class);
try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.schedule();
- verify(supervisionScanner, timeout(500)).run(true);
+ verify(supervisionScanner, timeout(500)).run();
verify(partecipantScanner, timeout(500)).run();
}
}
@@ -49,7 +49,7 @@
try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.doCheck();
supervisionAspect.doCheck();
- verify(supervisionScanner, timeout(500).times(2)).run(false);
+ verify(supervisionScanner, timeout(500).times(2)).run();
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
index 3ad9f81..4bab85b 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
@@ -38,7 +38,6 @@
@Test
void testScanParticipant() throws PfModelException {
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index 7aaa6d2..99af728 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -80,7 +80,7 @@
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
}
@@ -101,7 +101,7 @@
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
}
@@ -123,7 +123,7 @@
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionProvider).deleteAutomationComposition(automationComposition.getInstanceId());
}
@@ -143,12 +143,12 @@
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(true);
+ supervisionScanner.run();
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
}
@Test
- void testScannerForCounterHandling() {
+ void testScannerForTimeout() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setLockState(LockState.NONE);
@@ -164,21 +164,12 @@
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
- //verify retry scenario
- var scannerObj1 = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- acRuntimeParameterGroup);
-
- scannerObj1.run(true);
- verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
-
//verify timeout scenario
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxRetryCount(0);
var scannerObj2 = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- scannerObj2.run(true);
+ scannerObj2.run();
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
}
@@ -211,7 +202,7 @@
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class),
any(ToscaServiceTemplate.class), anyInt(), anyBoolean());
@@ -245,7 +236,7 @@
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), anyInt(),
anyBoolean());
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandlerTest.java
new file mode 100644
index 0000000..21c5b3d
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandlerTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.acm.runtime.supervision;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class TimeoutHandlerTest {
+
+ private static final int ID = 1;
+
+ @Test
+ void testFault() {
+ var timeoutHandler = new TimeoutHandler<Integer>();
+ timeoutHandler.setTimeout(ID);
+ assertThat(timeoutHandler.isTimeout(ID)).isTrue();
+ timeoutHandler.clear(ID);
+ assertThat(timeoutHandler.isTimeout(ID)).isFalse();
+ }
+
+ @Test
+ void testDuration() {
+ var timeoutHandler = new TimeoutHandler<Integer>() {
+ long epochMilli = 0;
+
+ @Override
+ protected long getEpochMilli() {
+ return epochMilli;
+ }
+ };
+ timeoutHandler.epochMilli = 100;
+ var result = timeoutHandler.getDuration(ID);
+ assertThat(result).isZero();
+
+ timeoutHandler.epochMilli += 100;
+ result = timeoutHandler.getDuration(ID);
+ assertThat(result).isEqualTo(100);
+
+ timeoutHandler.epochMilli += 100;
+ result = timeoutHandler.getDuration(ID);
+ assertThat(result).isEqualTo(200);
+
+ timeoutHandler.epochMilli += 100;
+ timeoutHandler.clear(ID);
+ result = timeoutHandler.getDuration(ID);
+ assertThat(result).isZero();
+ }
+}