aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-kubernetes
diff options
context:
space:
mode:
Diffstat (limited to 'participant/participant-impl/participant-impl-kubernetes')
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java49
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/handler/ControlLoopElementHandlerTest.java10
2 files changed, 27 insertions, 32 deletions
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java
index 20a23ca32..3f59c0822 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java
@@ -44,7 +44,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.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -122,41 +121,31 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
* Callback method to handle an update on a control loop element.
*
* @param element the information on the control loop element
- * @param controlLoopDefinition toscaServiceTemplate
+ * @param nodeTemplate toscaNodeTemplate
* @throws PfModelException in case of an exception
*/
@Override
public synchronized void controlLoopElementUpdate(ControlLoopElement element,
- ToscaServiceTemplate controlLoopDefinition)
- throws PfModelException {
-
- for (Map.Entry<String, ToscaNodeTemplate> nodeTemplate : controlLoopDefinition.getToscaTopologyTemplate()
- .getNodeTemplates().entrySet()) {
-
- // Fetching the node template of corresponding CL element
- if (element.getDefinition().getName().equals(nodeTemplate.getKey())
- && nodeTemplate.getValue().getProperties().containsKey("chart")) {
- @SuppressWarnings("unchecked")
- Map<String, Object> chartData =
- (Map<String, Object>) nodeTemplate.getValue().getProperties().get("chart");
-
- LOGGER.info("Installation request received for the Helm Chart {} ", chartData);
- try {
- var chartInfo = CODER.decode(String.valueOf(chartData), ChartInfo.class);
- var repositoryValue = chartData.get("repository");
- if (repositoryValue != null) {
- chartInfo.setRepository(repositoryValue.toString());
- }
- chartService.installChart(chartInfo);
- chartMap.put(element.getId(), chartInfo);
+ ToscaNodeTemplate nodeTemplate) throws PfModelException {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> chartData =
+ (Map<String, Object>) nodeTemplate.getProperties().get("chart");
+
+ LOGGER.info("Installation request received for the Helm Chart {} ", chartData);
+ try {
+ var chartInfo = CODER.convert(chartData, ChartInfo.class);
+ var repositoryValue = chartData.get("repository");
+ if (repositoryValue != null) {
+ chartInfo.setRepository(repositoryValue.toString());
+ }
+ chartService.installChart(chartInfo);
+ chartMap.put(element.getId(), chartInfo);
- var config = CODER.convert(nodeTemplate.getValue().getProperties(), ThreadConfig.class);
- checkPodStatus(chartInfo, config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
+ var config = CODER.convert(nodeTemplate.getProperties(), ThreadConfig.class);
+ checkPodStatus(chartInfo, config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
- } catch (ServiceException | CoderException | IOException e) {
- LOGGER.warn("Installation of Helm chart failed", e);
- }
- }
+ } catch (ServiceException | CoderException | IOException e) {
+ LOGGER.warn("Installation of Helm chart failed", e);
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/handler/ControlLoopElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/handler/ControlLoopElementHandlerTest.java
index f8381ee7f..03d5b31f8 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/handler/ControlLoopElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/handler/ControlLoopElementHandlerTest.java
@@ -30,6 +30,7 @@ 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 org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -52,6 +53,7 @@ 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;
@@ -64,6 +66,8 @@ class ControlLoopElementHandlerTest {
private static final String KEY_NAME = "org.onap.domain.database.HelloWorld_K8SMicroserviceControlLoopElement";
private static List<ChartInfo> charts;
private static ToscaServiceTemplate toscaServiceTemplate;
+ private static final String K8S_CONTROL_LOOP_ELEMENT =
+ "org.onap.domain.database.PMSH_K8SMicroserviceControlLoopElement";
@InjectMocks
@@ -118,7 +122,9 @@ class ControlLoopElementHandlerTest {
element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
element.setOrderedState(ControlLoopOrderedState.PASSIVE);
- controlLoopElementHandler.controlLoopElementUpdate(element, toscaServiceTemplate);
+ Map<String, ToscaNodeTemplate> nodeTemplatesMap =
+ toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ controlLoopElementHandler.controlLoopElementUpdate(element, nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT));
assertThat(controlLoopElementHandler.getChartMap()).hasSize(1).containsKey(elementId1);
@@ -127,7 +133,7 @@ class ControlLoopElementHandlerTest {
UUID elementId2 = UUID.randomUUID();
element.setId(elementId2);
- controlLoopElementHandler.controlLoopElementUpdate(element, toscaServiceTemplate);
+ controlLoopElementHandler.controlLoopElementUpdate(element, nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT));
assertThat(controlLoopElementHandler.getChartMap().containsKey(elementId2)).isFalse();
}