From 31090c9fbc6c29477acd784a6c9f03766b5cc981 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Wed, 7 Jun 2023 14:25:33 +0100 Subject: 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 --- .../a1pms/config/ParticipantConfig.java | 43 ------------------ .../AutomationCompositionElementHandler.java | 4 +- .../a1pms/handler/AcElementHandlerTest.java | 52 +++++++++++++--------- 3 files changed, 32 insertions(+), 67 deletions(-) delete mode 100755 participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/config/ParticipantConfig.java (limited to 'participant/participant-impl/participant-impl-a1pms') 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); -- cgit 1.2.3-korg