summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2023-06-27 11:49:30 +0000
committerGerrit Code Review <gerrit@onap.org>2023-06-27 11:49:30 +0000
commit01c4bad81e3ce594668fb3315d42e2405c7332d0 (patch)
treeae6972274904e5370acf05159314d9e57784e006
parentf4c3fdc23752733a4c4f670a1cddb460747fd738 (diff)
parent8c178b15ff4c514ba07edd5aea039945b290e1c6 (diff)
Merge "Add Timeuot support in prime/deprime"
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java1
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java42
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java7
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java4
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java49
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java66
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java13
7 files changed, 121 insertions, 61 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
index 3182332d5..56e506470 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
@@ -79,6 +79,7 @@ public class ParticipantAckMessage {
public ParticipantAckMessage(ParticipantAckMessage source) {
this.responseTo = source.responseTo;
this.result = source.result;
+ this.stateChangeResult = source.stateChangeResult;
this.message = source.message;
this.messageType = source.messageType;
this.participantId = source.participantId;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java
deleted file mode 100644
index cb0307742..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java
+++ /dev/null
@@ -1,42 +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.models.acm.messages.dmaap.participant;
-
-/**
- * Class to hold the possible values for participant response status.
- */
-public enum ParticipantResponseStatus {
-
- /**
- * participant operation was successful.
- */
- SUCCESS,
-
- /**
- * participant operation failed.
- */
- FAIL,
-
- /**
- * periodic response.
- */
- PERIODIC
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java
index f1c930955..d80615626 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java
@@ -39,6 +39,7 @@ public class AcTypeStateResolver {
private static final String DEPRIMING = AcTypeState.DEPRIMING.toString();
private static final String NO_ERROR = StateChangeResult.NO_ERROR.name();
private static final String FAILED = StateChangeResult.FAILED.name();
+ private static final String TIMEOUT = StateChangeResult.TIMEOUT.name();
/**
* Construct.
@@ -57,6 +58,12 @@ public class AcTypeStateResolver {
this.graph.put(new String[] {DEPRIME, PRIMING, FAILED}, PrimeOrder.DEPRIME);
this.graph.put(new String[] {DEPRIME, DEPRIMING, FAILED}, PrimeOrder.DEPRIME);
this.graph.put(new String[] {PRIME, DEPRIMING, FAILED}, PrimeOrder.PRIME);
+
+ // timeout
+ this.graph.put(new String[] {PRIME, PRIMING, TIMEOUT}, PrimeOrder.PRIME);
+ this.graph.put(new String[] {DEPRIME, PRIMING, TIMEOUT}, PrimeOrder.DEPRIME);
+ this.graph.put(new String[] {DEPRIME, DEPRIMING, TIMEOUT}, PrimeOrder.DEPRIME);
+ this.graph.put(new String[] {PRIME, DEPRIMING, TIMEOUT}, PrimeOrder.PRIME);
}
/**
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
index 862672f3b..a18ea19a9 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
@@ -89,6 +89,10 @@ public class SupervisionHandler {
if (inProgress && !msgInErrors && completed) {
acDefinition.setState(finalState);
+ if (StateChangeResult.TIMEOUT.equals(acDefinition.getStateChangeResult())) {
+ acDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ }
+
}
acDefinitionProvider.updateAcDefinition(acDefinition);
}
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 b1bd29281..0ccdaed3e 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
@@ -28,7 +28,9 @@ import java.util.UUID;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
@@ -85,15 +87,41 @@ public class SupervisionScanner {
var list = acDefinitionProvider.getAllAcDefinitions();
for (var acDefinition : list) {
- var acList = automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId());
- for (var automationComposition : acList) {
- scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate());
+ if (AcTypeState.PRIMING.equals(acDefinition.getState())
+ || AcTypeState.DEPRIMING.equals(acDefinition.getState())) {
+ scanAutomationCompositionDefinition(acDefinition);
+ } else {
+ acTimeout.clear(acDefinition.getCompositionId());
+ var acList =
+ automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId());
+ for (var automationComposition : acList) {
+ scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate());
+ }
}
}
LOGGER.debug("Automation composition scan complete . . .");
}
+ private void scanAutomationCompositionDefinition(AutomationCompositionDefinition acDefinition) {
+ if (StateChangeResult.FAILED.equals(acDefinition.getStateChangeResult())) {
+ LOGGER.debug("automation definition {} scanned, OK", acDefinition.getCompositionId());
+
+ // Clear Timeout on ac Definition
+ acTimeout.clear(acDefinition.getCompositionId());
+ return;
+ }
+
+ if (acTimeout.isTimeout(acDefinition.getCompositionId())
+ && StateChangeResult.NO_ERROR.equals(acDefinition.getStateChangeResult())) {
+ // retry by the user
+ LOGGER.debug("clearing Timeout for the ac definition");
+ acTimeout.clear(acDefinition.getCompositionId());
+ }
+
+ handleTimeout(acDefinition);
+ }
+
private void scanAutomationComposition(final AutomationComposition automationComposition,
ToscaServiceTemplate serviceTemplate) {
LOGGER.debug("scanning automation composition {} . . .", automationComposition.getInstanceId());
@@ -188,6 +216,21 @@ public class SupervisionScanner {
}
}
+ private void handleTimeout(AutomationCompositionDefinition acDefinition) {
+ var compositionId = acDefinition.getCompositionId();
+ if (acTimeout.isTimeout(compositionId)) {
+ LOGGER.debug("The ac definition is in timeout {}", acDefinition.getCompositionId());
+ return;
+ }
+
+ if (acTimeout.getDuration(compositionId) > acTimeout.getMaxWaitMs()) {
+ LOGGER.debug("Report timeout for the ac definition {}", acDefinition.getCompositionId());
+ acTimeout.setTimeout(compositionId);
+ acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT);
+ acDefinitionProvider.updateAcDefinition(acDefinition);
+ }
+ }
+
private void handleTimeout(AutomationComposition automationComposition) {
var instanceId = automationComposition.getInstanceId();
if (acTimeout.isTimeout(instanceId)) {
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 99af72801..9b596c89a 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
@@ -33,17 +33,18 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -52,18 +53,52 @@ class SupervisionScannerTest {
private static final String AC_JSON = "src/test/resources/rest/acm/AutomationCompositionSmoke.json";
- private static final AcDefinitionProvider acDefinitionProvider = mock(AcDefinitionProvider.class);
+ private static final UUID compositionId = UUID.randomUUID();
- private static UUID compositionId;
-
- @BeforeAll
- public static void setUpBeforeAll() {
+ private AcDefinitionProvider createAcDefinitionProvider(AcTypeState acTypeState,
+ StateChangeResult stateChangeResult) {
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = new AutomationCompositionDefinition();
- compositionId = UUID.randomUUID();
+ acDefinition.setState(acTypeState);
+ acDefinition.setStateChangeResult(stateChangeResult);
acDefinition.setCompositionId(compositionId);
acDefinition.setServiceTemplate(serviceTemplate);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.getAllAcDefinitions()).thenReturn(List.of(Objects.requireNonNull(acDefinition)));
+ return acDefinitionProvider;
+ }
+
+ private AcDefinitionProvider createAcDefinitionProvider() {
+ return createAcDefinitionProvider(AcTypeState.PRIMED, StateChangeResult.NO_ERROR);
+ }
+
+ @Test
+ void testScannerOrderedFailed() {
+ var acDefinitionProvider = createAcDefinitionProvider(AcTypeState.PRIMING, StateChangeResult.FAILED);
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+ var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
+ mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
+ acRuntimeParameterGroup);
+ supervisionScanner.run();
+ verify(acDefinitionProvider, times(0)).updateAcDefinition(any(AutomationCompositionDefinition.class));
+ }
+
+ @Test
+ void testScannerOrderedPriming() {
+ var acDefinitionProvider = createAcDefinitionProvider(AcTypeState.PRIMING, StateChangeResult.NO_ERROR);
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+ var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
+ mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
+ acRuntimeParameterGroup);
+ supervisionScanner.run();
+ verify(acDefinitionProvider, times(0)).updateAcDefinition(any(AutomationCompositionDefinition.class));
+
+ acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
+ supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
+ mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
+ acRuntimeParameterGroup);
+ supervisionScanner.run();
+ verify(acDefinitionProvider).updateAcDefinition(any(AutomationCompositionDefinition.class));
}
@Test
@@ -77,7 +112,7 @@ class SupervisionScannerTest {
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
.thenReturn(List.of(automationComposition));
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
supervisionScanner.run();
@@ -98,7 +133,7 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
supervisionScanner.run();
@@ -106,7 +141,6 @@ class SupervisionScannerTest {
verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
}
-
@Test
void testScannerDelete() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
@@ -120,7 +154,7 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
supervisionScanner.run();
@@ -139,7 +173,7 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
@@ -164,8 +198,8 @@ class SupervisionScannerTest {
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
- //verify timeout scenario
- var scannerObj2 = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
+ // verify timeout scenario
+ var scannerObj2 = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
@@ -198,7 +232,7 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
@@ -232,7 +266,7 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index e0accc4a0..4ff759c13 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -60,6 +60,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionMessagesTest {
+ private static final String AC_INSTANTIATION_UPDATE_JSON =
+ "src/test/resources/rest/acm/AutomationCompositionUpdate.json";
private static final String NOT_ACTIVE = "Not Active!";
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
@@ -207,6 +209,17 @@ class SupervisionMessagesTest {
}
@Test
+ void testAcElementPropertiesPublisher() {
+ var publisher = new AcElementPropertiesPublisher();
+ var topicSink = mock(TopicSink.class);
+ publisher.active(List.of(topicSink));
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ publisher.send(automationComposition);
+ verify(topicSink).send(anyString());
+ }
+
+ @Test
void testParticipantRegisterListener() {
final var participantRegister = new ParticipantRegister();
var supervisionHandler = mock(SupervisionParticipantHandler.class);