aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-kubernetes/src/main/java
diff options
context:
space:
mode:
authorLathish <lathishbabu.ganesan@est.tech>2022-02-02 20:31:32 +0530
committerLathish <lathishbabu.ganesan@est.tech>2022-02-04 13:25:48 +0530
commitddfb2ef4b1308349910b9f9436bc1bdcc10fce6a (patch)
tree852f9868cf8d4b8684c1c34900cd79035abcb76a /participant/participant-impl/participant-impl-kubernetes/src/main/java
parentc97a6c0428998103906472725d34b9951a0ff559 (diff)
Fix K8s State change from Uninitialized to Passive only when pod deployment is successful
Issue-ID: POLICY-3874 Change-Id: Ib2ca3a5df8b15a0fa544fea8d0cbe794292d3d09 Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-kubernetes/src/main/java')
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java31
1 files changed, 21 insertions, 10 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 3f2113d98..a8a746254 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-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.
@@ -27,6 +27,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
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;
@@ -59,6 +63,8 @@ import org.springframework.stereotype.Component;
public class ControlLoopElementHandler implements ControlLoopElementListener {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+
// Map of helm installation and the status of corresponding pods
@Getter
private static Map<String, Map<String, String>> podStatusMap = new ConcurrentHashMap<>();
@@ -145,13 +151,11 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
chartMap.put(element.getId(), chartInfo);
var config = CODER.convert(nodeTemplate.getProperties(), ThreadConfig.class);
- checkPodStatus(chartInfo, config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
-
- intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(),
- ControlLoopOrderedState.PASSIVE, ControlLoopState.PASSIVE,
- ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ checkPodStatus(controlLoopId, element.getId(), chartInfo, config.uninitializedToPassiveTimeout,
+ config.podStatusCheckInterval);
- } catch (ServiceException | CoderException | IOException e) {
+ } catch (ServiceException | CoderException | IOException | ExecutionException
+ | InterruptedException e) {
LOGGER.warn("Installation of Helm chart failed", e);
}
}
@@ -160,10 +164,17 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
* Invoke a new thread to check the status of deployed pods.
* @param chart ChartInfo
*/
- public void checkPodStatus(ChartInfo chart, int timeout, int podStatusCheckInterval) {
+ public void checkPodStatus(ToscaConceptIdentifier controlLoopId, UUID elementId,
+ ChartInfo chart, int timeout, int podStatusCheckInterval) throws ExecutionException, InterruptedException {
// Invoke runnable thread to check pod status
- var runnableThread = new Thread(new PodStatusValidator(chart, timeout, podStatusCheckInterval));
- runnableThread.start();
+ Future<String> result = executor.submit(new PodStatusValidator(chart, timeout,
+ podStatusCheckInterval), "Done");
+ if (!result.get().isEmpty()) {
+ LOGGER.info("Pod Status Validator Completed: {}", result.isDone());
+ intermediaryApi.updateControlLoopElementState(controlLoopId, elementId,
+ ControlLoopOrderedState.PASSIVE, ControlLoopState.PASSIVE,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ }
}
/**