From a01c89adfa3a6fe0918d77282759295a7f0514e5 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 13 Dec 2022 13:57:47 +0000 Subject: Replace ToscaConceptIdentifier with UUID in Participant Messages ACM Replace in all messages the reference to Automation Composition ToscaConceptIdentifier(name, version) with instanceId(UUID). Issue-ID: POLICY-4479 Change-Id: I7bc9a7494103b9c1752a1e2c6f6d5a527196913d Signed-off-by: FrancescoFioraEst --- .../AutomationCompositionElementHandler.java | 23 ++++++++++------------ .../AutomationCompositionElementHandlerTest.java | 22 ++++++++++----------- .../kubernetes/parameters/CommonTestData.java | 9 +++++---- 3 files changed, 25 insertions(+), 29 deletions(-) (limited to 'participant/participant-impl/participant-impl-kubernetes/src') 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 ba49ff1f9..c64bc4906 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 @@ -29,7 +29,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -47,8 +46,6 @@ import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; 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.beans.factory.annotation.Autowired; @@ -92,12 +89,12 @@ public class AutomationCompositionElementHandler implements AutomationCompositio * @param newState the state to which the automation composition element is changing to */ @Override - public synchronized void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId, + public synchronized void automationCompositionElementStateChange(UUID automationCompositionId, UUID automationCompositionElementId, AutomationCompositionState currentState, AutomationCompositionOrderedState newState) { switch (newState) { case UNINITIALISED: - ChartInfo chart = chartMap.get(automationCompositionElementId); + var chart = chartMap.get(automationCompositionElementId); if (chart != null) { LOGGER.info("Helm deployment to be deleted {} ", chart.getReleaseName()); try { @@ -131,15 +128,16 @@ public class AutomationCompositionElementHandler implements AutomationCompositio /** * Callback method to handle an update on a automation composition element. * + * @param automationCompositionId the automationComposition Id * @param element the information on the automation composition element - * @param nodeTemplate toscaNodeTemplate + * @param properties properties Map * @throws PfModelException in case of an exception */ @Override - public synchronized void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId, - AutomationCompositionElement element, ToscaNodeTemplate nodeTemplate) throws PfModelException { + public synchronized void automationCompositionElementUpdate(UUID automationCompositionId, + AutomationCompositionElement element, Map properties) throws PfModelException { @SuppressWarnings("unchecked") - Map chartData = (Map) nodeTemplate.getProperties().get("chart"); + var chartData = (Map) properties.get("chart"); LOGGER.info("Installation request received for the Helm Chart {} ", chartData); try { @@ -147,8 +145,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio if (chartService.installChart(chartInfo)) { chartMap.put(element.getId(), chartInfo); - var config = CODER.convert(nodeTemplate.getProperties(), - ThreadConfig.class); + var config = CODER.convert(properties, ThreadConfig.class); checkPodStatus(automationCompositionId, element.getId(), chartInfo, config.uninitializedToPassiveTimeout, config.podStatusCheckInterval); } @@ -163,10 +160,10 @@ public class AutomationCompositionElementHandler implements AutomationCompositio * * @param chart ChartInfo */ - public void checkPodStatus(ToscaConceptIdentifier automationCompositionId, UUID elementId, + public void checkPodStatus(UUID automationCompositionId, UUID elementId, ChartInfo chart, int timeout, int podStatusCheckInterval) throws ExecutionException, InterruptedException { // Invoke runnable thread to check pod status - Future result = executor.submit(new PodStatusValidator(chart, timeout, + var result = executor.submit(new PodStatusValidator(chart, timeout, podStatusCheckInterval), "Done"); if (!result.get().isEmpty()) { LOGGER.info("Pod Status Validator Completed: {}", result.isDone()); diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java index fbd18ef67..f1357e435 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java @@ -32,7 +32,6 @@ import static org.mockito.Mockito.doThrow; import java.io.File; import java.io.IOException; import java.util.List; -import java.util.Map; import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -59,7 +58,6 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; 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.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -100,8 +98,8 @@ class AutomationCompositionElementHandlerTest { @Test void test_AutomationCompositionElementStateChange() throws ServiceException { - UUID automationCompositionElementId1 = UUID.randomUUID(); - UUID automationCompositionElementId2 = UUID.randomUUID(); + var automationCompositionElementId1 = UUID.randomUUID(); + var automationCompositionElementId2 = UUID.randomUUID(); automationCompositionElementHandler.getChartMap().put(automationCompositionElementId1, charts.get(0)); automationCompositionElementHandler.getChartMap().put(automationCompositionElementId2, charts.get(1)); @@ -133,27 +131,27 @@ class AutomationCompositionElementHandlerTest { ExecutionException, InterruptedException { doReturn(true).when(chartService).installChart(any()); doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt()); - UUID elementId1 = UUID.randomUUID(); - AutomationCompositionElement element = new AutomationCompositionElement(); + var elementId1 = UUID.randomUUID(); + var element = new AutomationCompositionElement(); element.setId(elementId1); element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1")); element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - Map nodeTemplatesMap = + var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); automationCompositionElementHandler.automationCompositionElementUpdate( commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT)); + nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); assertThat(automationCompositionElementHandler.getChartMap()).hasSize(1).containsKey(elementId1); doThrow(new ServiceException("Error installing the chart")).when(chartService).installChart(Mockito.any()); - UUID elementId2 = UUID.randomUUID(); + var elementId2 = UUID.randomUUID(); element.setId(elementId2); automationCompositionElementHandler.automationCompositionElementUpdate( commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT)); + nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); assertThat(automationCompositionElementHandler.getChartMap().containsKey(elementId2)).isFalse(); } @@ -164,8 +162,8 @@ class AutomationCompositionElementHandlerTest { doReturn("Done").when(result).get(); doReturn(true).when(result).isDone(); var chartInfo = charts.get(0); - ToscaConceptIdentifier automationCompositionId = new ToscaConceptIdentifier(); - AutomationCompositionElement element = new AutomationCompositionElement(); + var automationCompositionId = UUID.randomUUID(); + var element = new AutomationCompositionElement(); assertDoesNotThrow( () -> automationCompositionElementHandler.checkPodStatus(automationCompositionId, element.getId(), chartInfo, 1, 1)); diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java index 7ffd68812..97d2fbbd2 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java @@ -24,6 +24,7 @@ package org.onap.policy.clamp.acm.participant.kubernetes.parameters; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.UUID; import org.onap.policy.common.endpoints.parameters.TopicParameters; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -37,7 +38,7 @@ public class CommonTestData { public static final long TIME_INTERVAL = 2000; public static final List TOPIC_PARAMS = List.of(getTopicParams()); public static final Coder CODER = new StandardCoder(); - + private static final UUID AC_ID = UUID.randomUUID(); /** * Get ParticipantK8sParameters. @@ -152,9 +153,9 @@ public class CommonTestData { /** * Get automation composition id. - * @return ToscaConceptIdentifier automationCompositionId + * @return UUID automationCompositionId */ - public ToscaConceptIdentifier getAutomationCompositionId() { - return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0"); + public UUID getAutomationCompositionId() { + return AC_ID; } } -- cgit 1.2.3-korg