aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-19 11:14:12 +0100
committerLiam Fallon <liam.fallon@est.tech>2023-06-23 08:35:30 +0000
commit012d85236d4450e47a3ce854e43bdc8fe33d80ed (patch)
treea1ee8919ce6a18c677cc2b8e533db268bfd0cb1f /runtime-acm/src/main/java
parentbd74cd0db2289695fa9514d9d4a4079ed87f3fa1 (diff)
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> (cherry picked from commit a111b9631ec8a1eb3d108e21ebdac8a667cd4362)
Diffstat (limited to 'runtime-acm/src/main/java')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantParameters.java8
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/ParticipantUpdateParameters.java46
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java6
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java15
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java78
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java (renamed from runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/HandleCounter.java)53
6 files changed, 57 insertions, 149 deletions
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 248824f11..8c3a7078a 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 @@ public class ParticipantParameters {
@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 5ffaf39c0..000000000
--- 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/SupervisionAspect.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
index ef50a633e..7303fc84f 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 @@ public class SupervisionAspect implements Closeable {
}
private void executeScan() {
- supervisionScanner.run(true);
+ supervisionScanner.run();
partecipantScanner.run();
}
@@ -68,7 +68,7 @@ public class SupervisionAspect implements Closeable {
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 b396e629c..092fc3572 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 @@ import org.springframework.stereotype.Component;
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 @@ public class SupervisionPartecipantScanner {
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 @@ public class SupervisionPartecipantScanner {
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 @@ public class SupervisionPartecipantScanner {
* 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 41c7b1c74..b1bd29281 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 @@ import org.springframework.stereotype.Component;
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 @@ public class SupervisionScanner {
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 @@ public class SupervisionScanner {
}
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 @@ public class SupervisionScanner {
if (DeployState.UPDATING.equals(automationComposition.getDeployState())) {
// UPDATING do not need phases
+ handleTimeout(automationComposition);
return;
}
@@ -161,10 +158,8 @@ public class SupervisionScanner {
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 @@ public class SupervisionScanner {
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 @@ public class SupervisionScanner {
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/HandleCounter.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java
index 9949f3c89..976c91438 100644
--- 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/TimeoutHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * 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.
@@ -28,17 +28,12 @@ import java.util.Set;
import lombok.Getter;
import lombok.Setter;
-public class HandleCounter<K> {
+public class TimeoutHandler<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 Set<K> mapTimeout = new HashSet<>();
private Map<K, Long> mapTimer = new HashMap<>();
public long getDuration(K id) {
@@ -47,60 +42,34 @@ public class HandleCounter<K> {
}
/**
- * Reset timer and clear counter and fault by id.
+ * Reset timer and timeout by id.
*
* @param id the id
*/
public void clear(K id) {
- mapFault.remove(id);
- mapCounter.put(id, 0);
+ mapTimeout.remove(id);
mapTimer.put(id, getEpochMilli());
}
/**
- * Remove counter, timer and fault by id.
+ * Remove timer and timeout by id.
*
* @param id the id
*/
public void remove(K id) {
- mapFault.remove(id);
- mapCounter.remove(id);
+ mapTimeout.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 void setTimeout(K id) {
+ mapTimeout.add(id);
}
- public int getCounter(K id) {
- return mapCounter.getOrDefault(id, 0);
+ public boolean isTimeout(K id) {
+ return mapTimeout.contains(id);
}
protected long getEpochMilli() {
return Instant.now().toEpochMilli();
}
-
- public Set<K> keySet() {
- return mapCounter.keySet();
- }
}