diff options
Diffstat (limited to 'participant/participant-impl')
14 files changed, 87 insertions, 313 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, |