aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java106
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java17
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java132
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java23
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java25
5 files changed, 167 insertions, 136 deletions
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 1c40c7281..b93085e91 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
@@ -24,20 +24,16 @@ import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
-import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import lombok.AccessLevel;
-import lombok.Getter;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1;
+import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2;
import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException;
import org.onap.policy.clamp.acm.participant.kubernetes.helm.PodStatusValidator;
import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo;
import org.onap.policy.clamp.acm.participant.kubernetes.service.ChartService;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.common.utils.coder.Coder;
@@ -53,25 +49,19 @@ import org.springframework.stereotype.Component;
* This class handles implementation of automationCompositionElement updates.
*/
@Component
-public class AutomationCompositionElementHandler extends AcElementListenerV1 {
+public class AutomationCompositionElementHandler extends AcElementListenerV2 {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- // Map of helm installation and the status of corresponding pods
- @Getter
- private static Map<String, Map<String, String>> podStatusMap = new ConcurrentHashMap<>();
private static final Coder CODER = new StandardCoder();
- @Autowired
- private ChartService chartService;
+ private final ChartService chartService;
- // Map of acElement Id and installed Helm charts
- @Getter(AccessLevel.PACKAGE)
- private final Map<UUID, ChartInfo> chartMap = new HashMap<>();
-
- public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi) {
+ public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi, ChartService chartService) {
super(intermediaryApi);
+ this.chartService = chartService;
}
+
// Default thread config values
private static class ThreadConfig {
private int uninitializedToPassiveTimeout = 60;
@@ -79,97 +69,99 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
}
/**
- * Callback method to handle a automation composition element state change.
+ * Handle an undeploy on a automation composition element.
*
- * @param automationCompositionElementId the ID of the automation composition element
+ * @param compositionElement the information of the Automation Composition Definition Element
+ * @param instanceElement the information of the Automation Composition Instance Element
+ * @throws PfModelException in case of a model exception
*/
@Override
- public synchronized void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) {
- var chart = chartMap.get(automationCompositionElementId);
+ public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+ throws PfModelException {
+
+ var chart = getChartInfo(instanceElement.inProperties());
if (chart != null) {
LOGGER.info("Helm deployment to be deleted {} ", chart.getReleaseName());
try {
chartService.uninstallChart(chart);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+ intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+ instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
"Undeployed");
- chartMap.remove(automationCompositionElementId);
- podStatusMap.remove(chart.getReleaseName());
+ instanceElement.outProperties().remove(chart.getReleaseName());
+ intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(),
+ null, null, instanceElement.outProperties());
} catch (ServiceException se) {
- LOGGER.warn("Deletion of Helm deployment failed", se);
+ throw new PfModelException(Status.EXPECTATION_FAILED, "Deletion of Helm deployment failed", se);
}
}
+
}
/**
- * Callback method to handle an update on a automation composition element.
+ * Handle a deploy on a automation composition element.
*
- * @param automationCompositionId the automationComposition Id
- * @param element the information on the automation composition element
- * @param properties properties Map
- * @throws PfModelException in case of an exception
+ * @param compositionElement the information of the Automation Composition Definition Element
+ * @param instanceElement the information of the Automation Composition Instance Element
+ * @throws PfModelException from Policy framework
*/
@Override
- public synchronized void deploy(UUID automationCompositionId, AcElementDeploy element,
- Map<String, Object> properties) throws PfModelException {
-
+ public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+ throws PfModelException {
try {
- var chartInfo = getChartInfo(properties);
+ var chartInfo = getChartInfo(instanceElement.inProperties());
if (chartService.installChart(chartInfo)) {
- chartMap.put(element.getId(), chartInfo);
-
- var config = getThreadConfig(properties);
- checkPodStatus(automationCompositionId, element.getId(), chartInfo,
- config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
+ var config = getThreadConfig(compositionElement.inProperties());
+ checkPodStatus(instanceElement.instanceId(), instanceElement.elementId(), chartInfo,
+ config.uninitializedToPassiveTimeout, config.podStatusCheckInterval, instanceElement);
} else {
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Chart not installed");
+ throw new PfModelException(Response.Status.BAD_REQUEST, "Installation of Helm chart failed ");
}
- } catch (ServiceException | IOException e) {
- throw new PfModelException(Response.Status.BAD_REQUEST, "Installation of Helm chart failed ", e);
- } catch (InterruptedException e) {
+ } catch (ServiceException | IOException | InterruptedException e) {
Thread.currentThread().interrupt();
- throw new PfModelException(Response.Status.BAD_REQUEST, "Error invoking ExecutorService ", e);
- } catch (AutomationCompositionException e) {
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, e.getMessage());
+ throw new PfModelException(Response.Status.BAD_REQUEST, "Installation of Helm chart failed ", e);
}
+
}
- private ThreadConfig getThreadConfig(Map<String, Object> properties) throws AutomationCompositionException {
+ private ThreadConfig getThreadConfig(Map<String, Object> properties) throws PfModelException {
try {
return CODER.convert(properties, ThreadConfig.class);
} catch (CoderException e) {
- throw new AutomationCompositionException(Status.BAD_REQUEST, "Error extracting ThreadConfig ", e);
+ throw new PfModelException(Status.BAD_REQUEST, "Error extracting ThreadConfig ", e);
}
}
- private ChartInfo getChartInfo(Map<String, Object> properties) throws AutomationCompositionException {
+ private ChartInfo getChartInfo(Map<String, Object> properties) throws PfModelException {
@SuppressWarnings("unchecked")
var chartData = (Map<String, Object>) properties.get("chart");
-
LOGGER.info("Installation request received for the Helm Chart {} ", chartData);
try {
return CODER.convert(chartData, ChartInfo.class);
} catch (CoderException e) {
- throw new AutomationCompositionException(Status.BAD_REQUEST, "Error extracting ChartInfo ", e);
+ throw new PfModelException(Status.BAD_REQUEST, "Error extracting ChartInfo", e);
}
+
}
/**
* Invoke a new thread to check the status of deployed pods.
*
* @param chart ChartInfo
- * @throws ServiceException in case of an exception
+ * @throws PfModelException in case of an exception
*/
public void checkPodStatus(UUID automationCompositionId, UUID elementId, ChartInfo chart, int timeout,
- int podStatusCheckInterval) throws InterruptedException, ServiceException {
+ int podStatusCheckInterval, InstanceElementDto instanceElement) throws InterruptedException,
+ PfModelException {
var result = new PodStatusValidator(chart, timeout, podStatusCheckInterval);
result.run();
LOGGER.info("Pod Status Validator Completed");
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, elementId,
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
+ instanceElement.outProperties().put(chart.getReleaseName(), "Running");
+
+ intermediaryApi.sendAcElementInfo(automationCompositionId, elementId, null, null,
+ instanceElement.outProperties());
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java
index 6c9656b78..3eba9427d 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java
@@ -1,6 +1,6 @@
/*-
* ========================LICENSE_START=================================
- * Copyright (C) 2021-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2021-2024 Nordix Foundation. All rights reserved.
* ======================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
package org.onap.policy.clamp.acm.participant.kubernetes.helm;
+import jakarta.ws.rs.core.Response;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -28,8 +29,8 @@ import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException;
-import org.onap.policy.clamp.acm.participant.kubernetes.handler.AutomationCompositionElementHandler;
import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo;
+import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,17 +67,17 @@ public class PodStatusValidator {
* @throws InterruptedException in case of an exception
* @throws ServiceException in case of an exception
*/
- public void run() throws InterruptedException, ServiceException {
+ public void run() throws InterruptedException, PfModelException {
logger.info("Polling the status of deployed pods for the chart {}", chart.getChartId().getName());
try {
verifyPodStatus();
- } catch (IOException e) {
- throw new ServiceException("Error verifying the status of the pod. Exiting", e);
+ } catch (IOException | ServiceException e) {
+ throw new PfModelException(Response.Status.BAD_REQUEST, "Error verifying the status of the pod. Exiting");
}
}
- private void verifyPodStatus() throws ServiceException, IOException, InterruptedException {
+ private void verifyPodStatus() throws ServiceException, IOException, InterruptedException, PfModelException {
var isVerified = false;
long endTime = System.currentTimeMillis() + (timeout * 1000L);
@@ -92,11 +93,11 @@ public class PodStatusValidator {
Thread.sleep(statusCheckInterval * 1000L);
} else {
logger.info("All pods are in running state for the helm chart {}", chart.getChartId().getName());
- AutomationCompositionElementHandler.getPodStatusMap().put(chart.getReleaseName(), podStatusMap);
}
}
if (!isVerified) {
- throw new ServiceException("Time out Exception verifying the status of the pod");
+ throw new PfModelException(Response.Status.GATEWAY_TIMEOUT,
+ "Time out Exception verifying the status of the pod");
}
}
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 26dcb05ff..260ef9918 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
@@ -21,7 +21,6 @@
package org.onap.policy.clamp.acm.participant.kubernetes.handler;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
@@ -30,7 +29,10 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -38,11 +40,8 @@ import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.Spy;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException;
import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo;
@@ -55,28 +54,18 @@ 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.ToscaServiceTemplate;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-@ExtendWith(SpringExtension.class)
class AutomationCompositionElementHandlerTest {
private static final Coder CODER = new StandardCoder();
private static final String CHART_INFO_YAML = "src/test/resources/ChartList.json";
- private static final String KEY_NAME =
- "org.onap.domain.database.HelloWorld_K8SMicroserviceAutomationCompositionElement";
private static List<ChartInfo> charts;
private static ToscaServiceTemplate toscaServiceTemplate;
private static final String K8S_AUTOMATION_COMPOSITION_ELEMENT =
"org.onap.domain.database.PMSH_K8SMicroserviceAutomationCompositionElement";
private final CommonTestData commonTestData = new CommonTestData();
- @InjectMocks
- @Spy
- private AutomationCompositionElementHandler automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class));
- @Mock
- private ChartService chartService;
@BeforeAll
static void init() throws CoderException {
@@ -85,98 +74,139 @@ class AutomationCompositionElementHandlerTest {
}
@Test
- void test_AutomationCompositionElementStateChange() throws ServiceException {
- var automationCompositionElementId1 = UUID.randomUUID();
- var automationCompositionElementId2 = UUID.randomUUID();
-
- automationCompositionElementHandler.getChartMap().put(automationCompositionElementId1, charts.get(0));
- automationCompositionElementHandler.getChartMap().put(automationCompositionElementId2, charts.get(1));
+ void test_AutomationCompositionElementStateChange() throws ServiceException, PfModelException {
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
doNothing().when(chartService).uninstallChart(charts.get(0));
- automationCompositionElementHandler.undeploy(commonTestData.getAutomationCompositionId(),
- automationCompositionElementId1);
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map<String, Object> inPropertiesMap = objectMapper.convertValue(charts.get(0), new TypeReference<>() {});
+
+ automationCompositionElementHandler.undeploy(commonTestData.createCompositionElementDto(),
+ commonTestData.createInstanceElementDto(Map.of("chart", inPropertiesMap)));
doThrow(new ServiceException("Error uninstalling the chart")).when(chartService).uninstallChart(charts.get(0));
assertDoesNotThrow(() -> automationCompositionElementHandler
- .undeploy(commonTestData.getAutomationCompositionId(), automationCompositionElementId1));
+ .undeploy(commonTestData.createCompositionElementDto(),
+ commonTestData.createInstanceElementDto(inPropertiesMap)));
}
@Test
void test_AutomationCompositionElementUpdate()
throws PfModelException, IOException, ServiceException, InterruptedException {
- doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
- var element = CommonTestData.createAcElementDeploy();
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ spy(new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService));
+
+ doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt(),
+ any());
var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ var instanceElementDto = commonTestData.createInstanceElementDto(nodeTemplatesMap
+ .get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ var compositionElementDto = commonTestData.createCompositionElementDto();
doReturn(false).when(chartService).installChart(any());
- assertDoesNotThrow(() -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(),
- element, nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+ assertThrows(PfModelException.class, () -> automationCompositionElementHandler.deploy(compositionElementDto,
+ instanceElementDto));
doReturn(true).when(chartService).installChart(any());
- automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
-
- assertThat(automationCompositionElementHandler.getChartMap()).hasSize(1).containsKey(element.getId());
+ automationCompositionElementHandler.deploy(compositionElementDto, instanceElementDto);
doThrow(new ServiceException("Error installing the chart")).when(chartService).installChart(Mockito.any());
- var elementId2 = UUID.randomUUID();
- element.setId(elementId2);
assertThrows(PfModelException.class,
- () -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+ () -> automationCompositionElementHandler.deploy(compositionElementDto, instanceElementDto));
- assertThat(automationCompositionElementHandler.getChartMap().containsKey(elementId2)).isFalse();
}
@Test
void test_checkPodStatus() {
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
+
var chartInfo = charts.get(0);
var automationCompositionId = UUID.randomUUID();
- assertThrows(ServiceException.class, () -> automationCompositionElementHandler
- .checkPodStatus(automationCompositionId, UUID.randomUUID(), chartInfo, 1, 1));
+ assertThrows(PfModelException.class, () -> automationCompositionElementHandler
+ .checkPodStatus(automationCompositionId, UUID.randomUUID(), chartInfo, 1, 1,
+ commonTestData.createInstanceElementDto(Map.of())));
}
@Test
void testUpdate() {
- var element = CommonTestData.createAcElementDeploy();
- var automationCompositionId = commonTestData.getAutomationCompositionId();
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
assertDoesNotThrow(
- () -> automationCompositionElementHandler.update(automationCompositionId, element, Map.of()));
+ () -> automationCompositionElementHandler.update(commonTestData.createCompositionElementDto(),
+ commonTestData.createInstanceElementDto(Map.of()),
+ commonTestData.createInstanceElementDto(Map.of())));
}
@Test
void testLock() {
- assertDoesNotThrow(() -> automationCompositionElementHandler.lock(UUID.randomUUID(), UUID.randomUUID()));
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler.lock(commonTestData.createCompositionElementDto(),
+ commonTestData.createInstanceElementDto(Map.of())));
}
@Test
void testUnlock() {
- assertDoesNotThrow(() -> automationCompositionElementHandler.unlock(UUID.randomUUID(), UUID.randomUUID()));
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler
+ .unlock(commonTestData.createCompositionElementDto(),
+ commonTestData.createInstanceElementDto(Map.of())));
}
@Test
void testDelete() {
- assertDoesNotThrow(() -> automationCompositionElementHandler.delete(UUID.randomUUID(), UUID.randomUUID()));
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler
+ .delete(commonTestData.createCompositionElementDto(),
+ commonTestData.createInstanceElementDto(Map.of())));
}
@Test
void testPrime() {
- assertDoesNotThrow(() -> automationCompositionElementHandler.prime(UUID.randomUUID(), List.of()));
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler.prime(new CompositionDto(UUID.randomUUID(),
+ Map.of(), Map.of())));
}
@Test
void testDeprime() {
- assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID()));
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(new CompositionDto(UUID.randomUUID(),
+ Map.of(), Map.of())));
}
@Test
void testMigrate() {
- var element = CommonTestData.createAcElementDeploy();
- var automationCompositionId = commonTestData.getAutomationCompositionId();
- assertDoesNotThrow(() -> automationCompositionElementHandler.migrate(automationCompositionId, element,
- UUID.randomUUID(), Map.of()));
+ var chartService = Mockito.mock(ChartService.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class), chartService);
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler
+ .migrate(commonTestData.createCompositionElementDto(),
+ commonTestData.createCompositionElementDto(), commonTestData.createInstanceElementDto(Map.of()),
+ commonTestData.createInstanceElementDto(Map.of())));
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java
index 91aff830f..5640ac4be 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022,2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,6 @@
package org.onap.policy.clamp.acm.participant.kubernetes.helm;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
@@ -29,20 +28,18 @@ import static org.mockito.Mockito.doReturn;
import java.io.File;
import java.util.List;
-import java.util.Map;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException;
-import org.onap.policy.clamp.acm.participant.kubernetes.handler.AutomationCompositionElementHandler;
import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo;
import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartList;
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.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@@ -71,29 +68,19 @@ class PodStatusValidatorTest {
charts = CODER.decode(new File(CHART_INFO_YAML), ChartList.class).getCharts();
}
- @AfterEach
- void clearPodStatusMap() {
- AutomationCompositionElementHandler.getPodStatusMap().clear();
- }
-
@Test
void test_RunningPodState() throws ServiceException {
String runningPod = "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\r\nHelloWorld-54777df9f8-qpzqr\t1/1\tRunning\t0\t9h";
doReturn(runningPod).when(client).executeCommand(any());
assertDoesNotThrow(() -> podStatusValidator.run());
- assertThat(AutomationCompositionElementHandler.getPodStatusMap()).hasSize(1);
- assertThat(AutomationCompositionElementHandler.getPodStatusMap()).containsKey(charts.get(0).getReleaseName());
- assertThat(AutomationCompositionElementHandler.getPodStatusMap())
- .containsValue(Map.of("HelloWorld-54777df9f8-qpzqr", "Running"));
}
@Test
void test_InvalidPodState() throws ServiceException {
String invalidPod = "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\nhellofromdocker-54777df9f8-qpzqr\t1/1\tInit\t0\t9h";
doReturn(invalidPod).when(client).executeCommand(any());
- assertThrows(ServiceException.class, () -> podStatusValidator.run());
- assertThat(AutomationCompositionElementHandler.getPodStatusMap()).isEmpty();
+ assertThrows(PfModelException.class, () -> podStatusValidator.run());
}
// Use case scenario: Hard coded pod name
@@ -102,9 +89,5 @@ class PodStatusValidatorTest {
String runningPod = "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\r\nhelloallworld-54777df9f8-qpzqr\t1/1\tRunning\t0\t9h";
doReturn(runningPod).when(client).executeCommand(any());
assertDoesNotThrow(() -> podValidatorWithPodName.run());
- assertThat(AutomationCompositionElementHandler.getPodStatusMap()).hasSize(1);
- assertThat(AutomationCompositionElementHandler.getPodStatusMap()).containsKey(charts.get(2).getReleaseName());
- assertThat(AutomationCompositionElementHandler.getPodStatusMap())
- .containsValue(Map.of("helloallworld-54777df9f8-qpzqr", "Running"));
}
}
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 3bb6009a8..7c0c56a1d 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
@@ -22,10 +22,13 @@
package org.onap.policy.clamp.acm.participant.kubernetes.parameters;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
@@ -34,6 +37,7 @@ 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.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
public class CommonTestData {
@@ -188,4 +192,25 @@ public class CommonTestData {
element.setOrderedState(DeployOrder.DEPLOY);
return element;
}
+
+ /**
+ * Create an InstanceElementDto.
+ *
+ * @return an InstanceElementDto
+ */
+ public InstanceElementDto createInstanceElementDto(Map<String, Object> inProperties) {
+ return new InstanceElementDto(getAutomationCompositionId(), UUID.randomUUID(),
+ new ToscaServiceTemplate(), inProperties, new HashMap<>());
+ }
+
+
+ /**
+ * Create an compositionElementDto.
+ *
+ * @return an compositionElementDto
+ */
+ public CompositionElementDto createCompositionElementDto() {
+ return new CompositionElementDto(getAutomationCompositionId(), null,
+ Map.of("uninitializedToPassiveTimeout", 100, "podStatusCheckInterval", "30"), null);
+ }
}