summaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-07 14:25:33 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-06-12 08:47:50 +0100
commit31090c9fbc6c29477acd784a6c9f03766b5cc981 (patch)
tree85b23dd0714707629ba11d190f2237b3ecf7061c /participant
parent5ccedbf315e6879005e1748baaccbfda9e81097e (diff)
Add failure handling support in Intermediary
Add Failure handling support in Intermediary, and refactor the communication between Participant and Intermediary. Issue-ID: POLICY-4707 Change-Id: Ica22e0e820efda372886d6d8da9c3526633321e2 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant')
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/config/ParticipantConfig.java43
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java4
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java52
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/config/ParticipantConfig.java43
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java4
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java55
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/config/ParticipantConfig.java43
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java4
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java7
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java43
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java3
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/ParticipantConfig.java43
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java5
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java51
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java8
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java33
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java511
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java110
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java18
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java319
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java213
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java122
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java9
23 files changed, 517 insertions, 1226 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/config/ParticipantConfig.java
deleted file mode 100755
index 7158b5d53..000000000
--- a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/config/ParticipantConfig.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 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.participant.a1pms.config;
-
-import org.onap.policy.clamp.acm.participant.a1pms.handler.AutomationCompositionElementHandler;
-import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ParticipantConfig {
-
- /**
- * Register AutomationCompositionElementListener.
- *
- * @param intermediaryApi the ParticipantIntermediaryApi
- * @param acElementHandler the AutomationComposition Element Handler
- */
- @Autowired
- public void registerAutomationCompositionElementListener(ParticipantIntermediaryApi intermediaryApi,
- AutomationCompositionElementHandler acElementHandler) {
- intermediaryApi.registerAutomationCompositionElementListener(acElementHandler);
- acElementHandler.setIntermediaryApi(intermediaryApi);
- }
-}
diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
index 665071bdf..d653c5ad3 100755
--- a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
@@ -30,7 +30,6 @@ import javax.validation.ValidationException;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import lombok.Setter;
import org.apache.http.HttpStatus;
import org.onap.policy.clamp.acm.participant.a1pms.exception.A1PolicyServiceException;
import org.onap.policy.clamp.acm.participant.a1pms.models.ConfigurationEntity;
@@ -62,8 +61,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- @Setter
- private ParticipantIntermediaryApi intermediaryApi;
+ private final ParticipantIntermediaryApi intermediaryApi;
private final AcA1PmsClient acA1PmsClient;
diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
index 77f41cb60..50f493299 100755
--- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
@@ -68,9 +68,9 @@ class AcElementHandlerTest {
@Test
void test_automationCompositionElementStateChange() throws A1PolicyServiceException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
var automationCompositionId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
@@ -93,11 +93,11 @@ class AcElementHandlerTest {
@Test
void test_AutomationCompositionElementUpdate() throws A1PolicyServiceException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
- var element = commonTestData.getAutomationCompositionElement();
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+ var element = commonTestData.getAutomationCompositionElement();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
@@ -108,8 +108,10 @@ class AcElementHandlerTest {
@Test
void test_AutomationCompositionElementUpdateWithUnhealthyA1pms() {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
- automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var element = commonTestData.getAutomationCompositionElement();
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
@@ -121,8 +123,10 @@ class AcElementHandlerTest {
@Test
void test_AutomationCompositionElementUpdateWithInvalidConfiguration() {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
- automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var element = commonTestData.getAutomationCompositionElement();
assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
.deploy(commonTestData.getAutomationCompositionId(), element, Map.of()));
@@ -130,9 +134,10 @@ class AcElementHandlerTest {
@Test
void testLock() throws PfModelException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var automationCompositionId = UUID.randomUUID();
var elementId = UUID.randomUUID();
automationCompositionElementHandler.lock(automationCompositionId, elementId);
@@ -143,9 +148,10 @@ class AcElementHandlerTest {
@Test
void testUnlock() throws PfModelException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var automationCompositionId = UUID.randomUUID();
var elementId = UUID.randomUUID();
automationCompositionElementHandler.unlock(automationCompositionId, elementId);
@@ -156,9 +162,10 @@ class AcElementHandlerTest {
@Test
void testUpdate() throws PfModelException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var automationCompositionId = UUID.randomUUID();
var element = commonTestData.getAutomationCompositionElement();
automationCompositionElementHandler.update(automationCompositionId, element, Map.of());
@@ -169,9 +176,10 @@ class AcElementHandlerTest {
@Test
void testDelete() throws PfModelException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var automationCompositionId = UUID.randomUUID();
var elementId = UUID.randomUUID();
automationCompositionElementHandler.delete(automationCompositionId, elementId);
@@ -182,9 +190,10 @@ class AcElementHandlerTest {
@Test
void testPrime() throws PfModelException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var compositionId = UUID.randomUUID();
automationCompositionElementHandler.prime(compositionId, List.of());
@@ -194,9 +203,10 @@ class AcElementHandlerTest {
@Test
void testDeprime() throws PfModelException {
- var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+
var compositionId = UUID.randomUUID();
automationCompositionElementHandler.deprime(compositionId);
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/config/ParticipantConfig.java
deleted file mode 100644
index e2b5d1718..000000000
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/config/ParticipantConfig.java
+++ /dev/null
@@ -1,43 +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.participant.http.config;
-
-import org.onap.policy.clamp.acm.participant.http.main.handler.AutomationCompositionElementHandler;
-import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ParticipantConfig {
-
- /**
- * Register AutomationCompositionElementListener.
- *
- * @param intermediaryApi the ParticipantIntermediaryApi
- * @param acElementHandler the AutomationComposition Element Handler
- */
- @Autowired
- public void registerAutomationCompositionElementListener(ParticipantIntermediaryApi intermediaryApi,
- AutomationCompositionElementHandler acElementHandler) {
- intermediaryApi.registerAutomationCompositionElementListener(acElementHandler);
- acElementHandler.setIntermediaryApi(intermediaryApi);
- }
-}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
index 966aee971..711887423 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
@@ -34,7 +34,6 @@ import java.util.stream.Collectors;
import javax.validation.Validation;
import javax.ws.rs.core.Response.Status;
import lombok.RequiredArgsConstructor;
-import lombok.Setter;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient;
@@ -70,8 +69,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
- @Setter
- private ParticipantIntermediaryApi intermediaryApi;
+ private final ParticipantIntermediaryApi intermediaryApi;
private final AcHttpClient acHttpClient;
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
index 4dca5a58f..12b8ee4c3 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
@@ -54,11 +54,10 @@ class AcElementHandlerTest {
var instanceId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
var acElementId = element.getId();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
automationCompositionElementHandler.undeploy(instanceId, acElementId);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "");
@@ -72,8 +71,8 @@ class AcElementHandlerTest {
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
+
Map<String, Object> map = new HashMap<>();
automationCompositionElementHandler.deploy(instanceId, element, map);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
@@ -89,8 +88,8 @@ class AcElementHandlerTest {
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
+
Map<String, Object> map = new HashMap<>();
map.put("httpHeaders", 1);
automationCompositionElementHandler.deploy(instanceId, element, map);
@@ -108,9 +107,11 @@ class AcElementHandlerTest {
map.putAll(element.getProperties());
var instanceId = commonTestData.getAutomationCompositionId();
var acHttpClient = mock(AcHttpClient.class);
- try (var automationCompositionElementHandler = new AutomationCompositionElementHandler(acHttpClient)) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acHttpClient)) {
+
automationCompositionElementHandler.deploy(instanceId, element, map);
verify(acHttpClient).run(any(ConfigRequest.class), anyMap());
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
@@ -123,11 +124,11 @@ class AcElementHandlerTest {
var instanceId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
var acElementId = element.getId();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
+
automationCompositionElementHandler.update(instanceId, element, Map.of());
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Update not supported");
@@ -138,11 +139,11 @@ class AcElementHandlerTest {
void testLock() throws Exception {
var instanceId = commonTestData.getAutomationCompositionId();
var acElementId = UUID.randomUUID();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
+
automationCompositionElementHandler.lock(instanceId, acElementId);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId, null,
LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
@@ -153,11 +154,11 @@ class AcElementHandlerTest {
void testUnlock() throws Exception {
var instanceId = commonTestData.getAutomationCompositionId();
var acElementId = UUID.randomUUID();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
+
automationCompositionElementHandler.unlock(instanceId, acElementId);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId, null,
LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
@@ -168,11 +169,11 @@ class AcElementHandlerTest {
void testDelete() throws Exception {
var instanceId = commonTestData.getAutomationCompositionId();
var acElementId = UUID.randomUUID();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
+
automationCompositionElementHandler.delete(instanceId, acElementId);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
@@ -182,11 +183,10 @@ class AcElementHandlerTest {
@Test
void testPrime() throws Exception {
var compositionId = UUID.randomUUID();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
automationCompositionElementHandler.prime(compositionId, List.of());
verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
@@ -197,11 +197,10 @@ class AcElementHandlerTest {
@Test
void testDeprime() throws Exception {
var compositionId = UUID.randomUUID();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class))) {
automationCompositionElementHandler.deprime(compositionId);
verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
diff --git a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/config/ParticipantConfig.java
deleted file mode 100755
index 1a671343a..000000000
--- a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/config/ParticipantConfig.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============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.participant.kserve.config;
-
-import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.kserve.handler.AutomationCompositionElementHandler;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ParticipantConfig {
-
- /**
- * Register AutomationCompositionElementListener.
- *
- * @param intermediaryApi the ParticipantIntermediaryApi
- * @param acElementHandler the AutomationComposition Element Handler
- */
- @Autowired
- public void registerAutomationCompositionElementListener(ParticipantIntermediaryApi intermediaryApi,
- AutomationCompositionElementHandler acElementHandler) {
- intermediaryApi.registerAutomationCompositionElementListener(acElementHandler);
- acElementHandler.setIntermediaryApi(intermediaryApi);
- }
-}
diff --git a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
index 4d556579d..ed02314cd 100755
--- a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
@@ -36,7 +36,6 @@ import javax.validation.ValidationException;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import lombok.Setter;
import org.apache.http.HttpStatus;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
@@ -72,8 +71,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
private ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
- @Setter
- private ParticipantIntermediaryApi intermediaryApi;
+ private final ParticipantIntermediaryApi intermediaryApi;
private final KserveClient kserveClient;
diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
index 38db1b8c1..6112488bf 100755
--- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
@@ -58,13 +58,12 @@ class AcElementHandlerTest {
private final KserveClient kserveClient = mock(KserveClient.class);
+ private ParticipantIntermediaryApi participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+
@InjectMocks
@Spy
private AutomationCompositionElementHandler automationCompositionElementHandler =
- new AutomationCompositionElementHandler(kserveClient);
-
- @Mock
- private ParticipantIntermediaryApi participantIntermediaryApi;
+ new AutomationCompositionElementHandler(participantIntermediaryApi, kserveClient);
@Mock
private ExecutorService executor;
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java
deleted file mode 100644
index 878b43f48..000000000
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java
+++ /dev/null
@@ -1,43 +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.participant.kubernetes.configurations;
-
-import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.kubernetes.handler.AutomationCompositionElementHandler;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ParticipantIntermediaryConfig {
-
- /**
- * Register AutomationCompositionElementListener.
- *
- * @param intermediaryApi the ParticipantIntermediaryApi
- * @param acElementHandler the AutomationComposition Element Handler
- */
- @Autowired
- public void registerAutomationCompositionElementListener(ParticipantIntermediaryApi intermediaryApi,
- AutomationCompositionElementHandler acElementHandler) {
- intermediaryApi.registerAutomationCompositionElementListener(acElementHandler);
- acElementHandler.setIntermediaryApi(intermediaryApi);
- }
-}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
index 95ff1e8c3..7050dfd47 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
@@ -33,7 +33,6 @@ import java.util.concurrent.Executors;
import javax.ws.rs.core.Response;
import lombok.AccessLevel;
import lombok.Getter;
-import lombok.Setter;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException;
@@ -72,7 +71,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
@Autowired
private ChartService chartService;
- @Setter
+ @Autowired
private ParticipantIntermediaryApi intermediaryApi;
// Map of acElement Id and installed Helm charts
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/ParticipantConfig.java
deleted file mode 100644
index 7f9ad243d..000000000
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/ParticipantConfig.java
+++ /dev/null
@@ -1,43 +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.participant.policy.config;
-
-import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.policy.main.handler.AutomationCompositionElementHandler;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ParticipantConfig {
-
- /**
- * Register AutomationCompositionElementListener.
- *
- * @param intermediaryApi the ParticipantIntermediaryApi
- * @param acElementHandler the Aotumation Composition Element Handler
- */
- @Autowired
- public void registerAutomationCompositionElementListener(ParticipantIntermediaryApi intermediaryApi,
- AutomationCompositionElementHandler acElementHandler) {
- intermediaryApi.registerAutomationCompositionElementListener(acElementHandler);
- acElementHandler.setIntermediaryApi(intermediaryApi);
- }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index 0b8ffe2a3..29622149a 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -29,7 +29,6 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import javax.ws.rs.core.Response.Status;
import lombok.RequiredArgsConstructor;
-import lombok.Setter;
import org.apache.http.HttpStatus;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
@@ -62,9 +61,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
private final PolicyApiHttpClient apiHttpClient;
private final PolicyPapHttpClient papHttpClient;
-
- @Setter
- private ParticipantIntermediaryApi intermediaryApi;
+ private final ParticipantIntermediaryApi intermediaryApi;
/**
* Callback method to handle a automation composition element state change.
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
index ec55c178f..84ddeed74 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
@@ -57,10 +57,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testHandlerUndeployNoPolicy() throws PfModelException {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
handler.undeploy(AC_ID, automationCompositionElementId);
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
@@ -90,9 +89,8 @@ class AutomationCompositionElementHandlerTest {
var pap = mock(PolicyPapHttpClient.class);
doReturn(Response.accepted().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
- var handler = new AutomationCompositionElementHandler(api, pap);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
handler.deploy(AC_ID, getTestingAcElement(), Map.of());
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
@@ -105,10 +103,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testDeployNoPolicy() throws PfModelException {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
var acElement = getTestingAcElement();
acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
@@ -126,9 +123,9 @@ class AutomationCompositionElementHandlerTest {
var pap = mock(PolicyPapHttpClient.class);
doReturn(Response.accepted().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
- var handler = new AutomationCompositionElementHandler(api, pap);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
+
var element = getTestingAcElement();
// Mock failure in policy type creation
@@ -147,9 +144,9 @@ class AutomationCompositionElementHandlerTest {
var pap = mock(PolicyPapHttpClient.class);
doReturn(Response.serverError().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
- var handler = new AutomationCompositionElementHandler(api, pap);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
+
var element = getTestingAcElement();
assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of()))
.hasMessageMatching("Deploy of Policy failed.");
@@ -157,10 +154,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testUpdate() throws Exception {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
var acElement = getTestingAcElement();
acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
@@ -171,10 +167,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testLock() throws Exception {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
handler.lock(AC_ID, automationCompositionElementId);
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, null,
@@ -183,10 +178,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testUnlock() throws Exception {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
handler.unlock(AC_ID, automationCompositionElementId);
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, null,
@@ -195,10 +189,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testDelete() throws Exception {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
handler.delete(AC_ID, automationCompositionElementId);
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
@@ -207,10 +200,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testPrime() throws Exception {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
handler.prime(AC_ID, List.of());
verify(intermediaryApi).updateCompositionState(AC_ID, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
@@ -218,10 +210,9 @@ class AutomationCompositionElementHandlerTest {
@Test
void testDeprime() throws Exception {
- var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- handler.setIntermediaryApi(intermediaryApi);
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
handler.deprime(AC_ID);
verify(intermediaryApi).updateCompositionState(AC_ID, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
index 1677f5486..c75750c0d 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -35,14 +35,6 @@ import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
public interface ParticipantIntermediaryApi {
/**
- * Register a listener for automation composition elements that are mediated by the intermediary.
- *
- * @param automationCompositionElementListener The automation composition element listener to register
- */
- void registerAutomationCompositionElementListener(
- AutomationCompositionElementListener automationCompositionElementListener);
-
- /**
* Update the state of a automation composition element.
*
* @param automationCompositionId the ID of the automation composition to update the state on
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index 14a653113..592513258 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -23,9 +23,10 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
import java.util.Map;
import java.util.UUID;
-import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
+import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
+import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionOutHandler;
+import org.onap.policy.clamp.acm.participant.intermediary.handler.CacheProvider;
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.DeployState;
@@ -38,31 +39,19 @@ import org.springframework.stereotype.Component;
* This class is api implementation used by participant intermediary.
*/
@Component
+@RequiredArgsConstructor
public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
// The handler for the automationComposition intermediary
- private final AutomationCompositionHandler automationCompositionHandler;
+ private final AutomationCompositionOutHandler automationCompositionHandler;
+ private final CacheProvider cacheProvider;
- /**
- * Constructor.
- *
- * @param automationCompositionHandler AutomationCompositionHandler
- */
- public ParticipantIntermediaryApiImpl(AutomationCompositionHandler automationCompositionHandler) {
- this.automationCompositionHandler = automationCompositionHandler;
- }
-
- @Override
- public void registerAutomationCompositionElementListener(
- AutomationCompositionElementListener automationCompositionElementListener) {
- automationCompositionHandler.registerAutomationCompositionElementListener(automationCompositionElementListener);
- }
@Override
- public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState deployState,
+ public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState,
LockState lockState, StateChangeResult stateChangeResult, String message) {
- automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, deployState,
- lockState, message);
+ automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, newState,
+ lockState, stateChangeResult, message);
}
@Override
@@ -74,12 +63,12 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public Map<UUID, AutomationComposition> getAutomationCompositions() {
- return PfUtils.mapMap(automationCompositionHandler.getAutomationCompositionMap(), AutomationComposition::new);
+ return PfUtils.mapMap(cacheProvider.getAutomationCompositions(), AutomationComposition::new);
}
@Override
public void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
String message) {
- // Auto-generated method stub
+ // TODO Auto-generated method stub
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
index 045677704..0fcd5ecc4 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
@@ -21,41 +21,24 @@
package org.onap.policy.clamp.acm.participant.intermediary.handler;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
-import lombok.Getter;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
-import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
-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.ParticipantDeploy;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.clamp.models.acm.persistence.provider.AcInstanceStateResolver;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -67,125 +50,44 @@ import org.springframework.stereotype.Component;
public class AutomationCompositionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionHandler.class);
- private final UUID participantId;
+ private final CacheProvider cacheProvider;
private final ParticipantMessagePublisher publisher;
+ private final AutomationCompositionElementListener listener;
private final AcInstanceStateResolver acInstanceStateResolver;
- private final List<ParticipantSupportedElementType> supportedAcElementTypes;
- private final List<AutomationCompositionElementListener> listeners = new ArrayList<>();
-
- @Getter
- private final Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
/**
* Constructor, set the participant ID and messageSender.
*
- * @param parameters the parameters of the participant
+ * @param cacheProvider the Cache Provider
* @param publisher the ParticipantMessage Publisher
+ * @param listener the ThreadHandler Listener
*/
- public AutomationCompositionHandler(ParticipantParameters parameters, ParticipantMessagePublisher publisher) {
- this.participantId = parameters.getIntermediaryParameters().getParticipantId();
+ public AutomationCompositionHandler(CacheProvider cacheProvider, ParticipantMessagePublisher publisher,
+ AutomationCompositionElementListener listener) {
+ this.cacheProvider = cacheProvider;
this.publisher = publisher;
+ this.listener = listener;
this.acInstanceStateResolver = new AcInstanceStateResolver();
- this.supportedAcElementTypes = parameters.getIntermediaryParameters().getParticipantSupportedElementTypes();
- }
-
- public void registerAutomationCompositionElementListener(AutomationCompositionElementListener listener) {
- listeners.add(listener);
- }
-
- /**
- * Handle a automation composition element state change message.
- *
- * @param automationCompositionId the automationComposition Id
- * @param id the automationComposition UUID
- * @param deployState the DeployState state
- * @param lockState the LockState state
- */
- public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState deployState,
- LockState lockState, String message) {
-
- if (automationCompositionId == null || id == null) {
- LOGGER.error("Cannot update Automation composition element state, id is null");
- return;
- }
-
- if ((deployState != null && lockState != null) || (deployState == null && lockState == null)) {
- LOGGER.error("state error {} and {} cannot be handled", deployState, lockState);
- return;
- }
-
- var automationComposition = automationCompositionMap.get(automationCompositionId);
- if (automationComposition == null) {
- LOGGER.error("Cannot update Automation composition element state, Automation composition id {} not present",
- automationComposition);
- return;
- }
-
- var element = automationComposition.getElements().get(id);
- if (element == null) {
- var msg = "Cannot update Automation composition element state, AC Element id {} not present";
- LOGGER.error(msg, automationComposition);
- return;
- }
-
- if (deployState != null) {
- element.setDeployState(deployState);
- element.setLockState(
- DeployState.DEPLOYED.equals(element.getDeployState()) ? LockState.LOCKED : LockState.NONE);
- var checkOpt = automationComposition.getElements().values().stream()
- .filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny();
- if (checkOpt.isEmpty()) {
- automationComposition.setDeployState(deployState);
- automationComposition.setLockState(element.getLockState());
-
- if (DeployState.DELETED.equals(deployState)) {
- automationCompositionMap.remove(automationComposition.getInstanceId());
- }
- }
- }
- if (lockState != null) {
- element.setLockState(lockState);
- var checkOpt = automationComposition.getElements().values().stream()
- .filter(acElement -> !lockState.equals(acElement.getLockState())).findAny();
- if (checkOpt.isEmpty()) {
- automationComposition.setLockState(lockState);
- }
- }
-
- var automationCompositionStateChangeAck =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
- automationCompositionStateChangeAck.setParticipantId(participantId);
- automationCompositionStateChangeAck.setMessage(message);
- automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId);
- automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(element.getId(),
- new AcElementDeployAck(element.getDeployState(), element.getLockState(), element.getOperationalState(),
- element.getUseState(), element.getOutProperties(), true,
- "Automation composition element {} state changed to {}\", id, newState)"));
- LOGGER.debug("Automation composition element {} state changed to {}", id, deployState);
- automationCompositionStateChangeAck.setResult(true);
- publisher.sendAutomationCompositionAck(automationCompositionStateChangeAck);
}
/**
* Handle a automation composition state change message.
*
* @param stateChangeMsg the state change message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
- public void handleAutomationCompositionStateChange(AutomationCompositionStateChange stateChangeMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ public void handleAutomationCompositionStateChange(AutomationCompositionStateChange stateChangeMsg) {
if (stateChangeMsg.getAutomationCompositionId() == null) {
return;
}
- var automationComposition = automationCompositionMap.get(stateChangeMsg.getAutomationCompositionId());
+ var automationComposition = cacheProvider.getAutomationComposition(stateChangeMsg.getAutomationCompositionId());
if (automationComposition == null) {
var automationCompositionAck =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
- automationCompositionAck.setParticipantId(participantId);
+ automationCompositionAck.setParticipantId(cacheProvider.getParticipantId());
automationCompositionAck.setMessage("Automation composition " + stateChangeMsg.getAutomationCompositionId()
- + " does not use this participant " + participantId);
+ + " does not use this participant " + cacheProvider.getParticipantId());
automationCompositionAck.setResult(false);
automationCompositionAck.setResponseTo(stateChangeMsg.getMessageId());
automationCompositionAck.setAutomationCompositionId(stateChangeMsg.getAutomationCompositionId());
@@ -204,17 +106,17 @@ public class AutomationCompositionHandler {
if (DeployOrder.NONE.equals(stateChangeMsg.getDeployOrderedState())) {
handleLockOrderState(automationComposition, stateChangeMsg.getLockOrderedState(),
- stateChangeMsg.getStartPhase(), acElementDefinitions);
+ stateChangeMsg.getStartPhase());
} else {
handleDeployOrderState(automationComposition, stateChangeMsg.getDeployOrderedState(),
- stateChangeMsg.getStartPhase(), acElementDefinitions);
+ stateChangeMsg.getStartPhase());
}
}
private boolean checkConsistantOrderState(AutomationComposition automationComposition, DeployOrder deployOrder,
LockOrder lockOrder) {
if (DeployOrder.UPDATE.equals(deployOrder)) {
- return true;
+ return false;
}
return acInstanceStateResolver.resolve(deployOrder, lockOrder, automationComposition.getDeployState(),
automationComposition.getLockState(), automationComposition.getStateChangeResult()) != null;
@@ -226,21 +128,20 @@ public class AutomationCompositionHandler {
* @param automationComposition participant response
* @param orderedState automation composition ordered state
* @param startPhaseMsg startPhase from message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
private void handleDeployOrderState(final AutomationComposition automationComposition, DeployOrder orderedState,
- Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ Integer startPhaseMsg) {
switch (orderedState) {
case UNDEPLOY:
- handleUndeployState(automationComposition, startPhaseMsg, acElementDefinitions);
+ handleUndeployState(automationComposition, startPhaseMsg);
break;
case DELETE:
- handleDeleteState(automationComposition, startPhaseMsg, acElementDefinitions);
+ handleDeleteState(automationComposition, startPhaseMsg);
break;
default:
- LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey());
+ LOGGER.error("StateChange message has no state, state is null {}", automationComposition.getKey());
break;
}
}
@@ -251,20 +152,19 @@ public class AutomationCompositionHandler {
* @param automationComposition participant response
* @param orderedState automation composition ordered state
* @param startPhaseMsg startPhase from message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
private void handleLockOrderState(final AutomationComposition automationComposition, LockOrder orderedState,
- Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ Integer startPhaseMsg) {
switch (orderedState) {
case LOCK:
- handleLockState(automationComposition, startPhaseMsg, acElementDefinitions);
+ handleLockState(automationComposition, startPhaseMsg);
break;
case UNLOCK:
- handleUnlockState(automationComposition, startPhaseMsg, acElementDefinitions);
+ handleUnlockState(automationComposition, startPhaseMsg);
break;
default:
- LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey());
+ LOGGER.error("StateChange message has no state, state is null {}", automationComposition.getKey());
break;
}
}
@@ -273,10 +173,8 @@ public class AutomationCompositionHandler {
* Handle a automation composition properties update message.
*
* @param updateMsg the properties update message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
- public void handleAcPropertyUpdate(PropertiesUpdate updateMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ public void handleAcPropertyUpdate(PropertiesUpdate updateMsg) {
if (updateMsg.getParticipantUpdatesList().isEmpty()) {
LOGGER.warn("No AutomationCompositionElement updates in message {}",
@@ -285,12 +183,11 @@ public class AutomationCompositionHandler {
}
for (var participantDeploy : updateMsg.getParticipantUpdatesList()) {
- if (participantId.equals(participantDeploy.getParticipantId())) {
+ if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) {
- initializeDeploy(updateMsg.getMessageId(), updateMsg.getAutomationCompositionId(), participantDeploy,
- DeployState.UPDATING);
+ updateExistingElementsOnThisParticipant(updateMsg.getAutomationCompositionId(), participantDeploy);
- callParticipantUpdateProperty(participantDeploy.getAcElementList(), acElementDefinitions,
+ callParticipantUpdateProperty(participantDeploy.getAcElementList(),
updateMsg.getAutomationCompositionId());
}
}
@@ -299,128 +196,60 @@ public class AutomationCompositionHandler {
/**
* Handle a automation composition Deploy message.
*
- * @param updateMsg the Deploy message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
+ * @param deployMsg the Deploy message
*/
- public void handleAutomationCompositionDeploy(AutomationCompositionDeploy updateMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ public void handleAutomationCompositionDeploy(AutomationCompositionDeploy deployMsg) {
- if (updateMsg.getParticipantUpdatesList().isEmpty()) {
- LOGGER.warn("No AutomationCompositionElement updates in message {}",
- updateMsg.getAutomationCompositionId());
+ if (deployMsg.getParticipantUpdatesList().isEmpty()) {
+ LOGGER.warn("No AutomationCompositionElement deploy in message {}",
+ deployMsg.getAutomationCompositionId());
return;
}
- for (var participantDeploy : updateMsg.getParticipantUpdatesList()) {
- if (participantId.equals(participantDeploy.getParticipantId())) {
- if (updateMsg.isFirstStartPhase()) {
- initializeDeploy(updateMsg.getMessageId(), updateMsg.getAutomationCompositionId(),
- participantDeploy, DeployState.DEPLOYING);
+ for (var participantDeploy : deployMsg.getParticipantUpdatesList()) {
+ if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) {
+ if (deployMsg.isFirstStartPhase()) {
+ cacheProvider.initializeAutomationComposition(deployMsg.getCompositionId(),
+ deployMsg.getAutomationCompositionId(), participantDeploy);
}
- callParticipantDeploy(participantDeploy.getAcElementList(), acElementDefinitions,
- updateMsg.getStartPhase(), updateMsg.getAutomationCompositionId());
+ callParticipanDeploy(participantDeploy.getAcElementList(), deployMsg.getStartPhase(),
+ deployMsg.getAutomationCompositionId());
}
}
}
- private void initializeDeploy(UUID messageId, UUID instanceId, ParticipantDeploy participantDeploy,
- DeployState deployState) {
- if (automationCompositionMap.containsKey(instanceId)) {
- updateExistingElementsOnThisParticipant(instanceId, participantDeploy, deployState);
- } else {
- var automationComposition = new AutomationComposition();
- automationComposition.setInstanceId(instanceId);
- var acElements = storeElementsOnThisParticipant(participantDeploy, deployState);
- automationComposition.setElements(prepareAcElementMap(acElements));
- automationCompositionMap.put(instanceId, automationComposition);
- }
- }
-
- private void callParticipantDeploy(List<AcElementDeploy> acElements,
- List<AutomationCompositionElementDefinition> acElementDefinitions, Integer startPhaseMsg,
- UUID automationCompositionId) {
+ private void callParticipanDeploy(List<AcElementDeploy> acElements, Integer startPhaseMsg, UUID instanceId) {
try {
for (var element : acElements) {
- var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, element.getDefinition());
- if (acElementNodeTemplate != null) {
- int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
- if (startPhaseMsg.equals(startPhase)) {
- for (var acElementListener : listeners) {
- var map = new HashMap<>(acElementNodeTemplate.getProperties());
- map.putAll(element.getProperties());
- acElementListener.deploy(automationCompositionId, element, map);
- }
- }
+ var commonProperties = cacheProvider.getCommonProperties(instanceId, element.getId());
+ int startPhase = ParticipantUtils.findStartPhase(commonProperties);
+ if (startPhaseMsg.equals(startPhase)) {
+ var map = new HashMap<>(commonProperties);
+ map.putAll(element.getProperties());
+ listener.deploy(instanceId, element, map);
}
}
} catch (PfModelException e) {
- LOGGER.debug("Automation composition element update failed {}", automationCompositionId);
+ LOGGER.debug("Automation composition element Deploy failed {}", instanceId);
}
-
}
- private void callParticipantUpdateProperty(List<AcElementDeploy> acElements,
- List<AutomationCompositionElementDefinition> acElementDefinitions, UUID automationCompositionId) {
+ private void callParticipantUpdateProperty(List<AcElementDeploy> acElements, UUID instanceId) {
try {
for (var element : acElements) {
- var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, element.getDefinition());
- if (acElementNodeTemplate != null) {
- for (var acElementListener : listeners) {
- var map = new HashMap<>(acElementNodeTemplate.getProperties());
- map.putAll(element.getProperties());
- acElementListener.update(automationCompositionId, element, map);
- }
- }
+ listener.update(instanceId, element, element.getProperties());
}
} catch (PfModelException e) {
- LOGGER.error("Automation composition element update failed for {} {}", automationCompositionId, e);
+ LOGGER.debug("Automation composition element update failed {}", instanceId);
}
-
- }
-
- private ToscaNodeTemplate getAcElementNodeTemplate(
- List<AutomationCompositionElementDefinition> acElementDefinitions, ToscaConceptIdentifier acElementDefId) {
-
- for (var acElementDefinition : acElementDefinitions) {
- if (acElementDefId.getName().contains(acElementDefinition.getAcElementDefinitionId().getName())) {
- return acElementDefinition.getAutomationCompositionElementToscaNodeTemplate();
- }
- }
- return null;
}
- private List<AutomationCompositionElement> storeElementsOnThisParticipant(ParticipantDeploy participantDeploy,
- DeployState deployState) {
- List<AutomationCompositionElement> acElementList = new ArrayList<>();
+ private void updateExistingElementsOnThisParticipant(UUID instanceId, ParticipantDeploy participantDeploy) {
+ var acElementList = cacheProvider.getAutomationComposition(instanceId).getElements();
for (var element : participantDeploy.getAcElementList()) {
- var acElement = new AutomationCompositionElement();
- acElement.setId(element.getId());
- acElement.setParticipantId(participantDeploy.getParticipantId());
- acElement.setDefinition(element.getDefinition());
- acElement.setDeployState(deployState);
- acElement.setLockState(LockState.NONE);
- acElementList.add(acElement);
+ var acElement = acElementList.get(element.getId());
+ acElement.getProperties().putAll(element.getProperties());
}
- return acElementList;
- }
-
- private void updateExistingElementsOnThisParticipant(UUID instanceId, ParticipantDeploy participantDeploy,
- DeployState deployState) {
-
- Map<UUID, AutomationCompositionElement> elementList = automationCompositionMap.get(instanceId).getElements();
- for (var element : participantDeploy.getAcElementList()) {
- automationCompositionMap.get(instanceId).getElements().get(element.getId()).getProperties()
- .putAll(element.getProperties());
- automationCompositionMap.get(instanceId).getElements().get(element.getId()).setDeployState(deployState);
- }
- }
-
- private Map<UUID, AutomationCompositionElement> prepareAcElementMap(List<AutomationCompositionElement> acElements) {
- Map<UUID, AutomationCompositionElement> acElementMap = new LinkedHashMap<>();
- for (var element : acElements) {
- acElementMap.put(element.getId(), element);
- }
- return acElementMap;
}
/**
@@ -428,214 +257,72 @@ public class AutomationCompositionHandler {
*
* @param automationComposition participant response
* @param startPhaseMsg startPhase from message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
- */
- private void handleUndeployState(final AutomationComposition automationComposition, Integer startPhaseMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
-
- automationComposition.getElements().values().stream()
- .forEach(acElement -> automationCompositionElementUndeploy(automationComposition.getInstanceId(),
- acElement, startPhaseMsg, acElementDefinitions));
- }
-
- private void handleDeleteState(final AutomationComposition automationComposition, Integer startPhaseMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
-
- automationComposition.getElements().values().stream()
- .forEach(acElement -> automationCompositionElementDelete(automationComposition.getInstanceId(),
- acElement, startPhaseMsg, acElementDefinitions));
- }
-
- /**
- * Method to handle when the new state from participant is PASSIVE state.
- *
- * @param automationComposition participant response
- * @param startPhaseMsg startPhase from message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
- */
- private void handleLockState(final AutomationComposition automationComposition, Integer startPhaseMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
- automationComposition.getElements().values().stream()
- .forEach(acElement -> automationCompositionElementLock(automationComposition.getInstanceId(), acElement,
- startPhaseMsg, acElementDefinitions));
- }
-
- /**
- * Method to handle when the new state from participant is RUNNING state.
- *
- * @param automationComposition participant response
- * @param startPhaseMsg startPhase from message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
- private void handleUnlockState(final AutomationComposition automationComposition, Integer startPhaseMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
- automationComposition.getElements().values().stream()
- .forEach(acElement -> automationCompositionElementUnlock(automationComposition.getInstanceId(),
- acElement, startPhaseMsg, acElementDefinitions));
- }
-
- private void automationCompositionElementLock(UUID instanceId, AutomationCompositionElement acElement,
- Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
- var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
- if (acElementNodeTemplate != null) {
- int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
- if (startPhaseMsg.equals(startPhase)) {
- for (var acElementListener : listeners) {
- try {
- acElementListener.lock(instanceId, acElement.getId());
- } catch (PfModelException e) {
- LOGGER.error("Automation composition element lock failed {}", instanceId);
- }
- }
- }
- }
- }
-
- private void automationCompositionElementUnlock(UUID instanceId, AutomationCompositionElement acElement,
- Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
- var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
- if (acElementNodeTemplate != null) {
- int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
- if (startPhaseMsg.equals(startPhase)) {
- for (var acElementListener : listeners) {
- try {
- acElementListener.unlock(instanceId, acElement.getId());
- } catch (PfModelException e) {
- LOGGER.error("Automation composition element unlock failed {}", instanceId);
- }
+ private void handleUndeployState(final AutomationComposition automationComposition, Integer startPhaseMsg) {
+ try {
+ for (var acElement : automationComposition.getElements().values()) {
+ int startPhase = ParticipantUtils.findStartPhase(
+ cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId()));
+ if (startPhaseMsg.equals(startPhase)) {
+ listener.undeploy(automationComposition.getInstanceId(), acElement.getId());
}
}
+ } catch (PfModelException e) {
+ LOGGER.debug("Automation composition element Undeploy failed {}", automationComposition.getInstanceId());
}
}
- private void automationCompositionElementUndeploy(UUID instanceId, AutomationCompositionElement acElement,
- Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
- var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
- if (acElementNodeTemplate != null) {
- int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
- if (startPhaseMsg.equals(startPhase)) {
- undeployInstanceElements(instanceId, acElement.getId());
- }
- }
- }
-
- private void automationCompositionElementDelete(UUID instanceId, AutomationCompositionElement acElement,
- Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
- var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
- if (acElementNodeTemplate != null) {
- int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
- if (startPhaseMsg.equals(startPhase)) {
- for (var acElementListener : listeners) {
- try {
- acElementListener.delete(instanceId, acElement.getId());
- } catch (PfModelException e) {
- LOGGER.error("Automation composition element unlock failed {}", instanceId);
- }
+ private void handleDeleteState(final AutomationComposition automationComposition, Integer startPhaseMsg) {
+ try {
+ for (var acElement : automationComposition.getElements().values()) {
+ int startPhase = ParticipantUtils.findStartPhase(
+ cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId()));
+ if (startPhaseMsg.equals(startPhase)) {
+ listener.delete(automationComposition.getInstanceId(), acElement.getId());
}
}
+ } catch (PfModelException e) {
+ LOGGER.debug("Automation composition element Delete failed {}", automationComposition.getInstanceId());
}
}
/**
- * Undeploy Instance Elements On Participant.
- */
- public void undeployInstances() {
- automationCompositionMap.values().forEach(this::undeployInstance);
- }
-
- private void undeployInstance(AutomationComposition automationComposition) {
- automationComposition.getElements().values().forEach(element -> {
- if (element.getParticipantId().equals(participantId)) {
- undeployInstanceElements(automationComposition.getInstanceId(), element.getId());
- }
- });
- }
-
- private void undeployInstanceElements(UUID instanceId, UUID elementId) {
- for (var acElementListener : listeners) {
- try {
- acElementListener.undeploy(instanceId, elementId);
- } catch (PfModelException e) {
- LOGGER.error("Automation composition element update failed {}", instanceId);
- }
- }
- }
-
- /**
- * Send Ac Element Info.
+ * Method to handle when the new state from participant is PASSIVE state.
*
- * @param automationCompositionId the automationComposition Id
- * @param elementId the automationComposition Element id
- * @param useState the use State
- * @param operationalState the operational State
- * @param outProperties the output Properties Map
+ * @param automationComposition participant response
+ * @param startPhaseMsg startPhase from message
*/
- public void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState,
- String operationalState, Map<String, Object> outProperties) {
-
- if (automationCompositionId == null || elementId == null) {
- LOGGER.error("Cannot update Automation composition element state, id is null");
- return;
- }
-
- var automationComposition = automationCompositionMap.get(automationCompositionId);
- if (automationComposition == null) {
- LOGGER.error("Cannot update Automation composition element state, Automation composition id {} not present",
- automationComposition);
- return;
- }
-
- var element = automationComposition.getElements().get(elementId);
- if (element == null) {
- var msg = "Cannot update Automation composition element state, AC Element id {} not present";
- LOGGER.error(msg, automationComposition);
- return;
+ private void handleLockState(final AutomationComposition automationComposition, Integer startPhaseMsg) {
+ try {
+ for (var acElement : automationComposition.getElements().values()) {
+ int startPhase = ParticipantUtils.findStartPhase(
+ cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId()));
+ if (startPhaseMsg.equals(startPhase)) {
+ listener.lock(automationComposition.getInstanceId(), acElement.getId());
+ }
+ }
+ } catch (PfModelException e) {
+ LOGGER.debug("Automation composition element Lock failed {}", automationComposition.getInstanceId());
}
- element.setOperationalState(operationalState);
- element.setUseState(useState);
- element.setOutProperties(outProperties);
-
- var statusMsg = new ParticipantStatus();
- statusMsg.setParticipantId(participantId);
- statusMsg.setState(ParticipantState.ON_LINE);
- statusMsg.setParticipantSupportedElementType(new ArrayList<>(supportedAcElementTypes));
- var acInfo = new AutomationCompositionInfo();
- acInfo.setAutomationCompositionId(automationCompositionId);
- acInfo.setDeployState(automationComposition.getDeployState());
- acInfo.setLockState(automationComposition.getLockState());
- acInfo.setElements(List.of(getAutomationCompositionElementInfo(element)));
- statusMsg.setAutomationCompositionInfoList(List.of(acInfo));
- publisher.sendParticipantStatus(statusMsg);
}
/**
- * get AutomationComposition Info List.
+ * Method to handle when the new state from participant is RUNNING state.
*
- * @return list of AutomationCompositionInfo
+ * @param automationComposition participant response
+ * @param startPhaseMsg startPhase from message
*/
- public List<AutomationCompositionInfo> getAutomationCompositionInfoList() {
- List<AutomationCompositionInfo> automationCompositionInfoList = new ArrayList<>();
- for (var entry : automationCompositionMap.entrySet()) {
- var acInfo = new AutomationCompositionInfo();
- acInfo.setAutomationCompositionId(entry.getKey());
- acInfo.setDeployState(entry.getValue().getDeployState());
- acInfo.setLockState(entry.getValue().getLockState());
- for (var element : entry.getValue().getElements().values()) {
- acInfo.getElements().add(getAutomationCompositionElementInfo(element));
+ private void handleUnlockState(final AutomationComposition automationComposition, Integer startPhaseMsg) {
+ try {
+ for (var acElement : automationComposition.getElements().values()) {
+ int startPhase = ParticipantUtils.findStartPhase(
+ cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId()));
+ if (startPhaseMsg.equals(startPhase)) {
+ listener.unlock(automationComposition.getInstanceId(), acElement.getId());
+ }
}
- automationCompositionInfoList.add(acInfo);
+ } catch (PfModelException e) {
+ LOGGER.debug("Automation composition element Unlock failed {}", automationComposition.getInstanceId());
}
- return automationCompositionInfoList;
- }
-
- private AutomationCompositionElementInfo getAutomationCompositionElementInfo(AutomationCompositionElement element) {
- var elementInfo = new AutomationCompositionElementInfo();
- elementInfo.setAutomationCompositionElementId(element.getId());
- elementInfo.setDeployState(element.getDeployState());
- elementInfo.setLockState(element.getLockState());
- elementInfo.setOperationalState(element.getOperationalState());
- elementInfo.setUseState(element.getUseState());
- elementInfo.setOutProperties(element.getOutProperties());
- return elementInfo;
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
index 9e1216cec..1e5caad15 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
@@ -24,17 +24,14 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler;
import io.micrometer.core.annotation.Timed;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
-import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
-import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantAckMessage;
@@ -56,33 +53,14 @@ import org.springframework.stereotype.Component;
* This class is responsible for managing the state of a participant.
*/
@Component
+@RequiredArgsConstructor
public class ParticipantHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantHandler.class);
- @Getter
- private final UUID participantId;
-
private final AutomationCompositionHandler automationCompositionHandler;
+ private final AutomationCompositionOutHandler automationCompositionOutHandler;
private final ParticipantMessagePublisher publisher;
-
- private final Map<UUID, List<AutomationCompositionElementDefinition>> acElementDefsMap = new HashMap<>();
-
- private final List<ParticipantSupportedElementType> supportedAcElementTypes;
-
- /**
- * Constructor, set the participant ID and sender.
- *
- * @param parameters the parameters of the participant
- * @param publisher the publisher for sending responses to messages
- * @param automationCompositionHandler the publisher for sending responses to messages
- */
- public ParticipantHandler(ParticipantParameters parameters, ParticipantMessagePublisher publisher,
- AutomationCompositionHandler automationCompositionHandler) {
- this.participantId = parameters.getIntermediaryParameters().getParticipantId();
- this.publisher = publisher;
- this.automationCompositionHandler = automationCompositionHandler;
- this.supportedAcElementTypes = parameters.getIntermediaryParameters().getParticipantSupportedElementTypes();
- }
+ private final CacheProvider cacheProvider;
/**
* Method which handles a participant health check event from clamp.
@@ -104,8 +82,7 @@ public class ParticipantHandler {
value = "listener.automation_composition_update",
description = "AUTOMATION_COMPOSITION_UPDATE messages received")
public void handleAutomationCompositionDeploy(AutomationCompositionDeploy updateMsg) {
- automationCompositionHandler.handleAutomationCompositionDeploy(updateMsg,
- acElementDefsMap.get(updateMsg.getCompositionId()));
+ automationCompositionHandler.handleAutomationCompositionDeploy(updateMsg);
}
/**
@@ -117,8 +94,7 @@ public class ParticipantHandler {
value = "listener.automation_composition_state_change",
description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages received")
public void handleAutomationCompositionStateChange(AutomationCompositionStateChange stateChangeMsg) {
- automationCompositionHandler.handleAutomationCompositionStateChange(stateChangeMsg,
- acElementDefsMap.get(stateChangeMsg.getCompositionId()));
+ automationCompositionHandler.handleAutomationCompositionStateChange(stateChangeMsg);
}
/**
@@ -126,12 +102,9 @@ public class ParticipantHandler {
*
* @param propertyUpdateMsg the property update message
*/
- @Timed(
- value = "listener.properties_update",
- description = "PROPERTIES_UPDATE message received")
+ @Timed(value = "listener.properties_update", description = "PROPERTIES_UPDATE message received")
public void handleAcPropertyUpdate(PropertiesUpdate propertyUpdateMsg) {
- automationCompositionHandler.handleAcPropertyUpdate(propertyUpdateMsg,
- acElementDefsMap.get(propertyUpdateMsg.getCompositionId()));
+ automationCompositionHandler.handleAcPropertyUpdate(propertyUpdateMsg);
}
/**
@@ -141,7 +114,7 @@ public class ParticipantHandler {
* @return true if it applies, false otherwise
*/
public boolean appliesTo(ParticipantMessage participantMsg) {
- return participantMsg.appliesTo(participantId);
+ return participantMsg.appliesTo(cacheProvider.getParticipantId());
}
/**
@@ -151,7 +124,7 @@ public class ParticipantHandler {
* @return true if it applies, false otherwise
*/
public boolean appliesTo(ParticipantAckMessage participantMsg) {
- return participantMsg.appliesTo(participantId);
+ return participantMsg.appliesTo(cacheProvider.getParticipantId());
}
/**
@@ -159,8 +132,8 @@ public class ParticipantHandler {
*/
public void sendParticipantRegister() {
var participantRegister = new ParticipantRegister();
- participantRegister.setParticipantId(participantId);
- participantRegister.setParticipantSupportedElementType(supportedAcElementTypes);
+ participantRegister.setParticipantId(cacheProvider.getParticipantId());
+ participantRegister.setParticipantSupportedElementType(cacheProvider.getSupportedAcElementTypes());
publisher.sendParticipantRegister(participantRegister);
}
@@ -182,9 +155,8 @@ public class ParticipantHandler {
*/
public void sendParticipantDeregister() {
var participantDeregister = new ParticipantDeregister();
- participantDeregister.setParticipantId(participantId);
+ participantDeregister.setParticipantId(cacheProvider.getParticipantId());
publisher.sendParticipantDeregister(participantDeregister);
- automationCompositionHandler.undeployInstances();
}
/**
@@ -205,22 +177,20 @@ public class ParticipantHandler {
*/
@Timed(value = "listener.participant_prime", description = "PARTICIPANT_PRIME messages received")
public void handleParticipantPrime(ParticipantPrime participantPrimeMsg) {
- LOGGER.debug("ParticipantPrime message received for participantId {}",
- participantPrimeMsg.getParticipantId());
+ LOGGER.debug("ParticipantPrime message received for participantId {}", participantPrimeMsg.getParticipantId());
- acElementDefsMap.putIfAbsent(participantPrimeMsg.getCompositionId(), new ArrayList<>());
if (!participantPrimeMsg.getParticipantDefinitionUpdates().isEmpty()) {
- // This message is to commission the automation composition
+ // prime
+ List<AutomationCompositionElementDefinition> list = new ArrayList<>();
for (var participantDefinition : participantPrimeMsg.getParticipantDefinitionUpdates()) {
- if (participantDefinition.getParticipantId().equals(participantId)) {
- acElementDefsMap.get(participantPrimeMsg.getCompositionId())
- .addAll(participantDefinition.getAutomationCompositionElementDefinitionList());
- break;
+ if (participantDefinition.getParticipantId().equals(cacheProvider.getParticipantId())) {
+ list.addAll(participantDefinition.getAutomationCompositionElementDefinitionList());
}
}
+ cacheProvider.addElementDefinition(participantPrimeMsg.getCompositionId(), list);
} else {
- // This message is to decommission the automation composition
- acElementDefsMap.get(participantPrimeMsg.getCompositionId()).clear();
+ // deprime
+ cacheProvider.removeElementDefinition(participantPrimeMsg.getCompositionId());
}
sendParticipantPrimeAck(participantPrimeMsg.getMessageId(), participantPrimeMsg.getCompositionId());
}
@@ -234,7 +204,7 @@ public class ParticipantHandler {
participantPrimeAck.setCompositionId(compositionId);
participantPrimeAck.setMessage("Participant Prime Ack message");
participantPrimeAck.setResult(true);
- participantPrimeAck.setParticipantId(participantId);
+ participantPrimeAck.setParticipantId(cacheProvider.getParticipantId());
participantPrimeAck.setState(ParticipantState.ON_LINE);
publisher.sendParticipantPrimeAck(participantPrimeAck);
}
@@ -251,17 +221,19 @@ public class ParticipantHandler {
*/
public ParticipantStatus makeHeartbeat(boolean responseToParticipantStatusReq) {
var heartbeat = new ParticipantStatus();
- heartbeat.setParticipantId(participantId);
+ heartbeat.setParticipantId(cacheProvider.getParticipantId());
heartbeat.setState(ParticipantState.ON_LINE);
- heartbeat.setAutomationCompositionInfoList(automationCompositionHandler.getAutomationCompositionInfoList());
- heartbeat.setParticipantSupportedElementType(new ArrayList<>(this.supportedAcElementTypes));
+ heartbeat.setAutomationCompositionInfoList(getAutomationCompositionInfoList());
+ heartbeat.setParticipantSupportedElementType(cacheProvider.getSupportedAcElementTypes());
if (responseToParticipantStatusReq) {
+ var acElementDefsMap = cacheProvider.getAcElementsDefinitions();
List<ParticipantDefinition> participantDefinitionList = new ArrayList<>(acElementDefsMap.size());
- for (var acElementDefsOnThisParticipant : acElementDefsMap.values()) {
+ for (var acElementDefs : acElementDefsMap.values()) {
var participantDefinition = new ParticipantDefinition();
- participantDefinition.setParticipantId(participantId);
- participantDefinition.setAutomationCompositionElementDefinitionList(acElementDefsOnThisParticipant);
+ participantDefinition.setParticipantId(cacheProvider.getParticipantId());
+ participantDefinition
+ .setAutomationCompositionElementDefinitionList(new ArrayList<>(acElementDefs.values()));
participantDefinitionList.add(participantDefinition);
}
heartbeat.setParticipantDefinitionUpdates(participantDefinitionList);
@@ -269,4 +241,24 @@ public class ParticipantHandler {
return heartbeat;
}
+
+ /**
+ * get AutomationComposition Info List.
+ *
+ * @return list of AutomationCompositionInfo
+ */
+ private List<AutomationCompositionInfo> getAutomationCompositionInfoList() {
+ List<AutomationCompositionInfo> automationCompositionInfoList = new ArrayList<>();
+ for (var entry : cacheProvider.getAutomationCompositions().entrySet()) {
+ var acInfo = new AutomationCompositionInfo();
+ acInfo.setAutomationCompositionId(entry.getKey());
+ acInfo.setDeployState(entry.getValue().getDeployState());
+ acInfo.setLockState(entry.getValue().getLockState());
+ for (var element : entry.getValue().getElements().values()) {
+ acInfo.getElements().add(automationCompositionOutHandler.getAutomationCompositionElementInfo(element));
+ }
+ automationCompositionInfoList.add(acInfo);
+ }
+ return automationCompositionInfoList;
+ }
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
index 8f70bc7d9..4213e978b 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
@@ -26,8 +26,7 @@ import static org.mockito.Mockito.verify;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
-import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
+import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionOutHandler;
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;
@@ -41,22 +40,23 @@ class ParticipantIntermediaryApiImplTest {
@Test
void mockParticipantIntermediaryApiImplTest() throws CoderException {
- var automationComposiitonHandler = mock(AutomationCompositionHandler.class);
- var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler);
-
- var acElementListener = mock(AutomationCompositionElementListener.class);
- apiImpl.registerAutomationCompositionElementListener(acElementListener);
- verify(automationComposiitonHandler).registerAutomationCompositionElementListener(acElementListener);
+ var automationComposiitonHandler = mock(AutomationCompositionOutHandler.class);
+ var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler, null);
var uuid = UUID.randomUUID();
var automationCompositionId = UUID.randomUUID();
apiImpl.updateAutomationCompositionElementState(automationCompositionId, uuid, DeployState.UNDEPLOYED,
LockState.NONE, StateChangeResult.NO_ERROR, null);
verify(automationComposiitonHandler).updateAutomationCompositionElementState(automationCompositionId, uuid,
- DeployState.UNDEPLOYED, LockState.NONE, null);
+ DeployState.UNDEPLOYED, LockState.NONE, StateChangeResult.NO_ERROR, null);
apiImpl.sendAcElementInfo(automationCompositionId, uuid, USE_STATE, OPERATIONAL_STATE, MAP);
verify(automationComposiitonHandler).sendAcElementInfo(automationCompositionId, uuid, USE_STATE,
OPERATIONAL_STATE, MAP);
+
+ apiImpl.updateAutomationCompositionElementState(automationCompositionId, uuid, DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "");
+ verify(automationComposiitonHandler).updateAutomationCompositionElementState(automationCompositionId, uuid,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "");
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
index d782ae167..7e0c3da7f 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
@@ -20,17 +20,13 @@
package org.onap.policy.clamp.acm.participant.intermediary.handler;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -39,242 +35,165 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
-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.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
class AutomationCompositionHandlerTest {
- private final CommonTestData commonTestData = new CommonTestData();
-
- private static final String STATE_VALUE = "STATE_VALUE";
-
- @Test
- void automationCompositionHandlerTest() {
- var ach = commonTestData.getMockAutomationCompositionHandler();
- assertNotNull(ach.getAutomationCompositionMap());
- }
-
@Test
- void updateNullAutomationCompositionHandlerTest() {
- var id = UUID.randomUUID();
-
- var ach = commonTestData.getMockAutomationCompositionHandler();
- assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, null,
- "Undeployed"));
-
- assertDoesNotThrow(
- () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, null, null));
+ void handleAutomationCompositionStateChangeNullTest() {
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
+ var cacheProvider = mock(CacheProvider.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher,
+ mock(AutomationCompositionElementListener.class));
+
+ var automationCompositionStateChange = new AutomationCompositionStateChange();
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(automationCompositionStateChange));
+
+ automationCompositionStateChange.setAutomationCompositionId(UUID.randomUUID());
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(automationCompositionStateChange));
+ verify(participantMessagePublisher).sendAutomationCompositionAck(any(AutomationCompositionDeployAck.class));
+
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ automationCompositionStateChange.setAutomationCompositionId(automationComposition.getInstanceId());
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ automationCompositionStateChange.setDeployOrderedState(DeployOrder.UPDATE);
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(automationCompositionStateChange));
}
@Test
- void updateAutomationCompositionHandlerTest() {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
-
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- var acKey = ach.getAutomationCompositionMap().keySet().iterator().next();
- var key = ach.getAutomationCompositionMap().get(acKey).getElements().keySet().iterator().next();
- var value = ach.getAutomationCompositionMap().get(acKey).getElements().get(key);
- value.setDeployState(DeployState.DEPLOYING);
- value.setLockState(LockState.NONE);
- ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED, null,
- "Deployed");
- assertEquals(DeployState.DEPLOYED, value.getDeployState());
+ void handleAutomationCompositionStateChangeUndeployTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.UNDEPLOY, LockOrder.NONE);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value);
- ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, null,
- "Deployed");
- assertEquals(DeployState.DEPLOYED, value.getDeployState());
-
- ach.getAutomationCompositionMap().values().iterator().next().getElements().clear();
- assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, null,
- LockState.UNLOCKED, null));
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
+ var listener = mock(AutomationCompositionElementListener.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).undeploy(any(), any());
}
@Test
- void handleAutomationCompositionStateChangeTest() {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
- var stateChange = commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- assertDoesNotThrow(() -> ach
- .handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of()));
-
- ach.handleAutomationCompositionStateChange(stateChange, List.of());
- var newPartecipantId = CommonTestData.getRndParticipantId();
- stateChange.setAutomationCompositionId(UUID.randomUUID());
- stateChange.setParticipantId(newPartecipantId);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of()));
- }
+ void handleAutomationCompositionStateChangeLockTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.LOCK);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- @Test
- void handleAutomationCompositionDeployTest() throws PfModelException {
- var acd = new AutomationCompositionElementDefinition();
- var definition = CommonTestData.getDefinition();
- acd.setAcElementDefinitionId(definition);
- acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
- var updateMsg = new AutomationCompositionDeploy();
- updateMsg.setAutomationCompositionId(UUID.randomUUID());
- var uuid = UUID.randomUUID();
- updateMsg.setMessageId(uuid);
- var partecipantId = CommonTestData.getParticipantId();
- updateMsg.setParticipantId(partecipantId);
- updateMsg.setFirstStartPhase(true);
- updateMsg.setStartPhase(0);
- var acElementDefinitions = List.of(acd);
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
var listener = mock(AutomationCompositionElementListener.class);
- ach.registerAutomationCompositionElementListener(listener);
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(0)).deploy(any(), any(), anyMap());
- updateMsg.setFirstStartPhase(false);
- updateMsg.setStartPhase(1);
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(0)).deploy(any(), any(), anyMap());
-
- ach.getAutomationCompositionMap().clear();
- updateMsg.setFirstStartPhase(true);
- updateMsg.setStartPhase(0);
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(0)).deploy(any(), any(), anyMap());
-
- updateMsg.setAutomationCompositionId(UUID.randomUUID());
- updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantDeploy.class)));
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(0)).deploy(any(), any(), anyMap());
-
- updateMsg.setStartPhase(1);
- var participantDeploy = new ParticipantDeploy();
- participantDeploy.setParticipantId(partecipantId);
- var element = new AcElementDeploy();
- element.setDefinition(definition);
- participantDeploy.setAcElementList(List.of(element));
- updateMsg.setParticipantUpdatesList(List.of(participantDeploy));
-
- updateMsg.setStartPhase(0);
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(1)).deploy(any(), any(), anyMap());
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).lock(any(), any());
}
@Test
- void acUndeployTest() throws PfModelException {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
-
- var stateChangeUndeploy =
- commonTestData.getStateChange(partecipantId, uuid, DeployOrder.UNDEPLOY, LockOrder.NONE);
+ void handleAutomationCompositionStateChangeUnlockTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.UNLOCK);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- stateChangeUndeploy
- .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
var listener = mock(AutomationCompositionElementListener.class);
- ach.registerAutomationCompositionElementListener(listener);
-
- var acd = new AutomationCompositionElementDefinition();
- acd.setAcElementDefinitionId(definition);
- acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
- ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of(acd));
- verify(listener, times(1)).undeploy(any(), any());
-
- stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID());
- stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId());
- assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()));
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).unlock(any(), any());
}
@Test
- void automationCompositionStateLock() throws PfModelException {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
+ void handleAutomationCompositionStateChangeDeleteTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.DELETE, LockOrder.NONE);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- var stateChangeLock =
- commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.LOCK);
-
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
var listener = mock(AutomationCompositionElementListener.class);
- ach.registerAutomationCompositionElementListener(listener);
- stateChangeLock
- .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
- var acd = new AutomationCompositionElementDefinition();
- acd.setAcElementDefinitionId(definition);
- acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
- ach.handleAutomationCompositionStateChange(stateChangeLock, List.of(acd));
- stateChangeLock.setAutomationCompositionId(UUID.randomUUID());
- stateChangeLock.setParticipantId(CommonTestData.getRndParticipantId());
- ach.handleAutomationCompositionStateChange(stateChangeLock, List.of());
- verify(listener, times(1)).lock(any(), any());
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).delete(any(), any());
}
@Test
- void automationCompositionStateUnlock() throws PfModelException {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
-
- var stateChangeUnlock =
- commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
-
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ void handleAcPropertyUpdateTest() throws PfModelException {
+ var cacheProvider = mock(CacheProvider.class);
var listener = mock(AutomationCompositionElementListener.class);
- ach.registerAutomationCompositionElementListener(listener);
- stateChangeUnlock
- .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
- var acd = new AutomationCompositionElementDefinition();
- acd.setAcElementDefinitionId(definition);
- acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
- ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of(acd));
- stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID());
- stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId());
- ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
- verify(listener, times(1)).unlock(any(), any());
- }
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ var updateMsg = new PropertiesUpdate();
+ assertDoesNotThrow(() -> ach.handleAcPropertyUpdate(updateMsg));
- @Test
- void testgetAutomationCompositionInfoList() {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- var result = ach.getAutomationCompositionInfoList();
- assertThat(result).hasSize(1);
- assertThat(result.get(0).getElements()).hasSize(1);
+ updateMsg.setParticipantId(CommonTestData.getParticipantId());
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantDeploy = new ParticipantDeploy();
+ participantDeploy.setParticipantId(CommonTestData.getParticipantId());
+ updateMsg.getParticipantUpdatesList().add(participantDeploy);
+
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ updateMsg.setAutomationCompositionId(automationComposition.getInstanceId());
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setProperties(Map.of());
+ acElementDeploy.setId(automationComposition.getElements().values().iterator().next().getId());
+ participantDeploy.getAcElementList().add(acElementDeploy);
+
+ ach.handleAcPropertyUpdate(updateMsg);
+ verify(listener).update(any(), any(), any());
}
@Test
- void testsendAcElementInfo() {
+ void handleAutomationCompositionDeployTest() throws PfModelException {
+ var cacheProvider = mock(CacheProvider.class);
+ var listener = mock(AutomationCompositionElementListener.class);
var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
- var ach = new AutomationCompositionHandler(CommonTestData.getParticipantParameters(),
- participantMessagePublisher);
- ach.getAutomationCompositionMap().putAll(commonTestData.getTestAutomationCompositionMap());
- var key = ach.getAutomationCompositionMap().keySet().iterator().next();
- var keyElement = ach.getAutomationCompositionMap().get(key).getElements().keySet().iterator().next();
- ach.sendAcElementInfo(key, keyElement, "useState", "operationalState", Map.of("key", 1));
- verify(participantMessagePublisher).sendParticipantStatus(any());
- }
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
- @Test
- void testUndeployInstances() throws PfModelException {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- var listener = mock(AutomationCompositionElementListener.class);
- ach.registerAutomationCompositionElementListener(listener);
- ach.undeployInstances();
- verify(listener).undeploy(any(), any());
+ var deployMsg = new AutomationCompositionDeploy();
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(deployMsg));
+
+ deployMsg.setParticipantId(CommonTestData.getParticipantId());
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantDeploy = new ParticipantDeploy();
+ participantDeploy.setParticipantId(CommonTestData.getParticipantId());
+ deployMsg.getParticipantUpdatesList().add(participantDeploy);
+
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ deployMsg.setAutomationCompositionId(automationComposition.getInstanceId());
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ for (var element : automationComposition.getElements().values()) {
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setProperties(Map.of());
+ acElementDeploy.setId(element.getId());
+ participantDeploy.getAcElementList().add(acElementDeploy);
+ }
+ ach.handleAutomationCompositionDeploy(deployMsg);
+ verify(listener, times(automationComposition.getElements().size())).deploy(any(), any(), any());
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
index 30860308e..6cad99fa1 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
@@ -20,136 +20,187 @@
package org.onap.policy.clamp.acm.participant.intermediary.handler;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.time.Instant;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantAckMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
class ParticipantHandlerTest {
- private final CommonTestData commonTestData = new CommonTestData();
+ @Test
+ void handleParticipantStatusReqTest() {
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var cacheProvider = mock(CacheProvider.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ participantHandler.handleParticipantStatusReq(new ParticipantStatusReq());
+ verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
+ }
@Test
- void handleUpdateTest() {
- var parameters = CommonTestData.getParticipantParameters();
- var automationCompositionHander = commonTestData.getMockAutomationCompositionHandler();
- var publisher = new ParticipantMessagePublisher();
- var emptyParticipantHandler =
- new ParticipantHandler(parameters, publisher, automationCompositionHander);
- var participantPrimeMsg = new ParticipantPrime();
-
- assertThatThrownBy(() ->
- emptyParticipantHandler.handleParticipantPrime(participantPrimeMsg))
- .isInstanceOf(RuntimeException.class);
-
- var participantHandler = commonTestData.getMockParticipantHandler();
-
- var participantId = CommonTestData.getParticipantId();
- participantPrimeMsg.setCompositionId(CommonTestData.AC_ID_1);
- participantPrimeMsg.setParticipantId(participantId);
- participantPrimeMsg.setMessageId(UUID.randomUUID());
- participantPrimeMsg.setTimestamp(Instant.ofEpochMilli(3000));
-
- var heartbeatF = participantHandler.makeHeartbeat(false);
- assertEquals(participantId, heartbeatF.getParticipantId());
- assertThat(heartbeatF.getAutomationCompositionInfoList()).isEmpty();
-
- participantHandler.handleParticipantPrime(participantPrimeMsg);
-
- var heartbeatT = participantHandler.makeHeartbeat(true);
- assertEquals(participantId, heartbeatT.getParticipantId());
- assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty();
- assertEquals(participantId, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
-
- var pum = setListParticipantDefinition(participantPrimeMsg);
- participantHandler.handleParticipantPrime(pum);
- var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true);
- assertEquals(participantId, heartbeatTAfterUpdate.getParticipantId());
+ void handleAutomationCompositionDeployTest() {
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var automationCompositionDeploy = new AutomationCompositionDeploy();
+ participantHandler.handleAutomationCompositionDeploy(automationCompositionDeploy);
+ verify(acHandler).handleAutomationCompositionDeploy(automationCompositionDeploy);
}
- private ParticipantPrime setListParticipantDefinition(ParticipantPrime participantPrimeMsg) {
- var def = new ParticipantDefinition();
- def.setParticipantId(CommonTestData.getParticipantId());
- participantPrimeMsg.setParticipantDefinitionUpdates(List.of(def));
- return participantPrimeMsg;
+ @Test
+ void handleAutomationCompositionStateChangeTest() {
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var acStateChange = new AutomationCompositionStateChange();
+ participantHandler.handleAutomationCompositionStateChange(acStateChange);
+ verify(acHandler).handleAutomationCompositionStateChange(acStateChange);
+ }
+
+ @Test
+ void handleAcPropertyUpdateTest() {
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var propertyUpdateMsg = new PropertiesUpdate();
+ participantHandler.handleAcPropertyUpdate(propertyUpdateMsg);
+ verify(acHandler).handleAcPropertyUpdate(propertyUpdateMsg);
}
@Test
- void checkAppliesTo() {
- var participantHandler = commonTestData.getMockParticipantHandler();
- var participantAckMsg =
- new ParticipantAckMessage(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
+ void appliesToTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), mock(ParticipantMessagePublisher.class), cacheProvider);
+
+ var participantAckMsg = new ParticipantAckMessage(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
assertTrue(participantHandler.appliesTo(participantAckMsg));
- var participantMsg =
- new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATUS);
+ var participantMsg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATUS);
assertTrue(participantHandler.appliesTo(participantMsg));
- var randomId = UUID.randomUUID();
- participantMsg.setParticipantId(randomId);
+ participantMsg.setParticipantId(UUID.randomUUID());
assertFalse(participantHandler.appliesTo(participantMsg));
-
}
@Test
- void getAutomationCompositionInfoListTest() throws CoderException {
- var automationCompositionHandler = mock(AutomationCompositionHandler.class);
- var participantHandler =
- commonTestData.getParticipantHandlerAutomationCompositions(automationCompositionHandler);
- clearInvocations(automationCompositionHandler);
- participantHandler.sendHeartbeat();
- verify(automationCompositionHandler).getAutomationCompositionInfoList();
+ void sendParticipantRegister() {
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ when(cacheProvider.getSupportedAcElementTypes()).thenReturn(List.of(new ParticipantSupportedElementType()));
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+
+ participantHandler.sendParticipantRegister();
+ verify(publisher).sendParticipantRegister(any(ParticipantRegister.class));
}
@Test
- void testHandleParticipantRegisterAck() {
- var parameters = CommonTestData.getParticipantParameters();
- var automationCompositionHandler = commonTestData.getMockAutomationCompositionHandler();
+ void handleParticipantRegisterAckTest() {
var publisher = mock(ParticipantMessagePublisher.class);
- var participantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHandler);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
participantHandler.handleParticipantRegisterAck(new ParticipantRegisterAck());
- verify(publisher).sendParticipantStatus(any());
+ verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
}
@Test
- void testSendParticipantDeregister() throws PfModelException {
- var commonTestData = new CommonTestData();
- var automationCompositionMap = commonTestData.getTestAutomationCompositionMap();
- var automationCompositionHandler = mock(AutomationCompositionHandler.class);
-
- automationCompositionMap.values().iterator().next().getElements().values().iterator().next()
- .setParticipantId(CommonTestData.getParticipantId());
- when(automationCompositionHandler.getAutomationCompositionMap()).thenReturn(automationCompositionMap);
-
+ void sendParticipantDeregisterTest() {
var publisher = mock(ParticipantMessagePublisher.class);
- var parameters = CommonTestData.getParticipantParameters();
- var participantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHandler);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
participantHandler.sendParticipantDeregister();
verify(publisher).sendParticipantDeregister(any(ParticipantDeregister.class));
- verify(automationCompositionHandler).undeployInstances();
+ }
+
+ @Test
+ void handleParticipantDeregisterAckTest() {
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), mock(ParticipantMessagePublisher.class),
+ mock(CacheProvider.class));
+ var participantDeregisterAck = new ParticipantDeregisterAck();
+ assertDoesNotThrow(() -> participantHandler.handleParticipantDeregisterAck(participantDeregisterAck));
+ }
+
+ @Test
+ void handleParticipantPrimeTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+
+ var participantPrime = new ParticipantPrime();
+ participantPrime.setCompositionId(UUID.randomUUID());
+ participantPrime.setParticipantDefinitionUpdates(List.of(createParticipantDefinition()));
+ participantHandler.handleParticipantPrime(participantPrime);
+ verify(cacheProvider).addElementDefinition(any(), any());
+ verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class));
+ }
+
+ @Test
+ void handleParticipantDeprimeTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ var participantPrime = new ParticipantPrime();
+ var compositionId = UUID.randomUUID();
+ participantPrime.setCompositionId(compositionId);
+ participantHandler.handleParticipantPrime(participantPrime);
+ verify(cacheProvider).removeElementDefinition(compositionId);
+ verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class));
+ }
+
+ @Test
+ void sendHeartbeatTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ when(cacheProvider.getAutomationCompositions()).thenReturn(CommonTestData.getTestAutomationCompositionMap());
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ participantHandler.sendHeartbeat();
+ verify(publisher).sendHeartbeat(any(ParticipantStatus.class));
+ }
+
+ private ParticipantDefinition createParticipantDefinition() {
+ var def = new ParticipantDefinition();
+ def.setParticipantId(CommonTestData.getParticipantId());
+ return def;
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
index 60812c27a..cc2bd7010 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
@@ -22,28 +22,19 @@ package org.onap.policy.clamp.acm.participant.intermediary.main.parameters;
import java.io.File;
import java.time.Instant;
-import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
-import org.mockito.Mockito;
-import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
-import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
import org.onap.policy.clamp.acm.participant.intermediary.handler.DummyParticipantParameters;
-import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -59,7 +50,6 @@ public class CommonTestData {
public static final long TIME_INTERVAL = 2000;
public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
public static final Coder CODER = new StandardCoder();
- private static final Object lockit = new Object();
public static final UUID AC_ID_0 = UUID.randomUUID();
public static final UUID AC_ID_1 = UUID.randomUUID();
public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
@@ -69,7 +59,7 @@ public class CommonTestData {
*
* @return ParticipantIntermediaryParameters
*/
- public ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
+ public static ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
try {
return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
ParticipantIntermediaryParameters.class);
@@ -170,70 +160,6 @@ public class CommonTestData {
}
/**
- * Returns a participantMessagePublisher for MessageSender.
- *
- * @return participant Message Publisher
- */
- private ParticipantMessagePublisher getParticipantMessagePublisher() {
- synchronized (lockit) {
- var participantMessagePublisher = new ParticipantMessagePublisher();
- participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- return participantMessagePublisher;
- }
- }
-
- /**
- * Returns a mocked AutomationCompositionHandler for test cases.
- *
- * @return AutomationCompositionHandler
- */
- public AutomationCompositionHandler getMockAutomationCompositionHandler() {
- return new AutomationCompositionHandler(getParticipantParameters(), getParticipantMessagePublisher());
- }
-
- /**
- * Returns a mocked ParticipantHandler for test cases.
- *
- * @return participant Handler
- */
- public ParticipantHandler getMockParticipantHandler() {
- var parameters = getParticipantParameters();
- var automationCompositionHandler = getMockAutomationCompositionHandler();
- var publisher = new ParticipantMessagePublisher();
- publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- return new ParticipantHandler(parameters, publisher, automationCompositionHandler);
- }
-
- public ParticipantHandler getParticipantHandlerAutomationCompositions() {
- var automationCompositionHandler = Mockito.mock(AutomationCompositionHandler.class);
- return getParticipantHandlerAutomationCompositions(automationCompositionHandler);
- }
-
- /**
- * Returns a mocked ParticipantHandler for test cases.
- *
- * @return participant Handler
- *
- * @throws CoderException if there is an error with .json file.
- */
- public ParticipantHandler getParticipantHandlerAutomationCompositions(
- AutomationCompositionHandler automationCompositionHandler) {
- Mockito.doReturn(getTestAutomationCompositionMap()).when(automationCompositionHandler)
- .getAutomationCompositionMap();
- var publisher = new ParticipantMessagePublisher();
- publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- var parameters = getParticipantParameters();
- var participantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHandler);
- participantHandler.sendParticipantRegister();
- participantHandler.handleParticipantStatusReq(null);
- participantHandler.sendParticipantDeregister();
- var participantDeregisterAckMsg = new ParticipantDeregisterAck();
- participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
- participantHandler.handleParticipantDeregisterAck(participantDeregisterAckMsg);
- return participantHandler;
- }
-
- /**
* Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
*
* @return automationCompositionMap
@@ -269,59 +195,21 @@ public class CommonTestData {
}
/**
- * Returns a map for a elementsOnThisParticipant for test cases.
- *
- * @param uuid UUID
- * @param definition ToscaConceptIdentifier
- * @return a map suitable for elementsOnThisParticipant
- */
- public Map<UUID, AutomationCompositionElement> setAutomationCompositionElementTest(UUID uuid,
- ToscaConceptIdentifier definition, UUID participantId) {
- var acElement = new AutomationCompositionElement();
- acElement.setId(uuid);
- acElement.setParticipantId(participantId);
- acElement.setDefinition(definition);
- acElement.setDeployState(DeployState.UNDEPLOYED);
-
- Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>();
- elementsOnThisParticipant.put(uuid, acElement);
- return elementsOnThisParticipant;
- }
-
- /**
- * Returns a AutomationCompositionHandler with elements on the definition,uuid.
- *
- * @param definition ToscaConceptIdentifier
- * @param uuid UUID
- * @return a AutomationCompositionHander with elements
- */
- public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier definition,
- UUID uuid, UUID participantId) {
- var ach = getMockAutomationCompositionHandler();
- ach.getAutomationCompositionMap().putAll(getTestAutomationCompositionMap());
- var acKey = ach.getAutomationCompositionMap().keySet().iterator().next();
- ach.getAutomationCompositionMap().get(acKey)
- .setElements(setAutomationCompositionElementTest(uuid, definition, participantId));
-
- return ach;
- }
-
- /**
* Return a AutomationCompositionStateChange.
*
* @param participantId the participantId
- * @param uuid UUID
+ * @param instanceId th AutomationComposition Id
* @param deployOrder a DeployOrder
* @param lockOrder a LockOrder
* @return a AutomationCompositionStateChange
*/
- public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid,
+ public static AutomationCompositionStateChange getStateChange(UUID participantId, UUID instanceId,
DeployOrder deployOrder, LockOrder lockOrder) {
var stateChange = new AutomationCompositionStateChange();
stateChange.setStartPhase(0);
- stateChange.setAutomationCompositionId(UUID.randomUUID());
+ stateChange.setAutomationCompositionId(instanceId);
stateChange.setParticipantId(participantId);
- stateChange.setMessageId(uuid);
+ stateChange.setMessageId(UUID.randomUUID());
stateChange.setDeployOrderedState(deployOrder);
stateChange.setLockOrderedState(lockOrder);
stateChange.setTimestamp(Instant.ofEpochMilli(3000));
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
index 2cbe15797..e3631f12e 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
@@ -32,20 +32,19 @@ import org.onap.policy.clamp.acm.participant.intermediary.parameters.Participant
* {@link org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters}.
*/
class TestParticipantIntermediaryParameters {
- private final CommonTestData commonTestData = new CommonTestData();
private final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
@Test
void testParticipantIntermediaryParameterGroup() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty();
}
@Test
void testParticipantIntermediaryParameterGroup_EmptyParameter() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
participantParameters.setClampAutomationCompositionTopics(null);
assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
}
@@ -53,7 +52,7 @@ class TestParticipantIntermediaryParameters {
@Test
void testParticipantIntermediaryParameters_NullTopicSinks() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
participantParameters.getClampAutomationCompositionTopics().setTopicSinks(null);
assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
}
@@ -61,7 +60,7 @@ class TestParticipantIntermediaryParameters {
@Test
void testParticipantIntermediaryParameters_NullTopicSources() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
participantParameters.getClampAutomationCompositionTopics().setTopicSources(null);
assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
}