participantParameters:
heartBeatMs: 20000
maxStatusWaitMs: 100000
- updateParameters:
- maxRetryCount: 3
- maxWaitMs: 20000
topicParameterGroup:
topicSources:
-
/*-
* ============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.
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;
@Min(100)
private long maxStatusWaitMs;
-
- @Valid
- @NotNull
- private ParticipantUpdateParameters updateParameters;
}
+++ /dev/null
-/*
- * ============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;
-
-}
/*-
* ============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.
}
private void executeScan() {
- supervisionScanner.run(true);
+ supervisionScanner.run();
partecipantScanner.run();
}
public void doCheck() {
if (executor.getQueue().size() < 2) {
LOGGER.debug("Add scanning Message");
- executor.execute(() -> supervisionScanner.run(false));
+ executor.execute(() -> supervisionScanner.run());
}
}
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;
final AcRuntimeParameterGroup acRuntimeParameterGroup) {
this.participantProvider = participantProvider;
- participantStatusCounter.setMaxRetryCount(
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+ participantStatusTimeout.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
/**
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);
}
* handle participant Status message.
*/
public void handleParticipantStatus(UUID id) {
- participantStatusCounter.clear(id);
+ participantStatusTimeout.clear(id);
}
}
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;
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());
}
}
}
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;
if (DeployState.UPDATING.equals(automationComposition.getDeployState())) {
// UPDATING do not need phases
+ handleTimeout(automationComposition);
return;
}
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);
}
}
}
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);
}
}
LOGGER.debug("retry message AutomationCompositionStateChange");
automationCompositionStateChangePublisher.send(automationComposition, startPhase, firstStartPhase);
}
+ // Clear timeout on automation composition
+ clearTimeout(automationComposition, false);
}
}
/*-
* ============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.
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) {
}
/**
- * 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();
- }
}
participantParameters:
heartBeatMs: 20000
maxStatusWaitMs: 100000
- updateParameters:
- maxRetryCount: 4
- maxWaitMs: 20000
topicParameterGroup:
topicSources:
-
/*-
* ============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");
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();
}
}
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();
}
}
@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());
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
}
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
}
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionProvider).deleteAutomationComposition(automationComposition.getInstanceId());
}
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);
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));
}
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class),
any(ToscaServiceTemplate.class), anyInt(), anyBoolean());
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
- supervisionScanner.run(false);
+ supervisionScanner.run();
verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), anyInt(),
anyBoolean());
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 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.
import org.junit.jupiter.api.Test;
-class HandleCounterTest {
+class TimeoutHandlerTest {
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();
+ 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 handleCounter = new HandleCounter<Integer>() {
+ var timeoutHandler = new TimeoutHandler<Integer>() {
long epochMilli = 0;
@Override
return epochMilli;
}
};
- handleCounter.epochMilli = 100;
- var result = handleCounter.getDuration(ID);
+ timeoutHandler.epochMilli = 100;
+ var result = timeoutHandler.getDuration(ID);
assertThat(result).isZero();
- handleCounter.epochMilli += 100;
- result = handleCounter.getDuration(ID);
+ timeoutHandler.epochMilli += 100;
+ result = timeoutHandler.getDuration(ID);
assertThat(result).isEqualTo(100);
- handleCounter.epochMilli += 100;
- result = handleCounter.getDuration(ID);
+ timeoutHandler.epochMilli += 100;
+ result = timeoutHandler.getDuration(ID);
assertThat(result).isEqualTo(200);
- handleCounter.epochMilli += 100;
- handleCounter.clear(ID);
- result = handleCounter.getDuration(ID);
+ timeoutHandler.epochMilli += 100;
+ timeoutHandler.clear(ID);
+ result = timeoutHandler.getDuration(ID);
assertThat(result).isZero();
}
}