aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-kubernetes/src/main/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-22 16:15:11 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-06-27 11:52:16 +0000
commit567a8fd97c6b434f430d38c2d4af5a95b7cdb711 (patch)
tree0174c86c9eecac1f965950a917e236eae115012b /participant/participant-impl/participant-impl-kubernetes/src/main/java
parent01c4bad81e3ce594668fb3315d42e2405c7332d0 (diff)
Remove Thread support in kubernetes participant
Due the Thread support in Intermediary, Thread support in kubernetes participant could be removed. Issue-ID: POLICY-4741 Change-Id: Ia55697808c541991f99cc7630f25188937e15779 Signed-off-by: FrancescoFioraEst <francesco.fiora@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/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java63
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidator.java17
2 files changed, 51 insertions, 29 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 7050dfd47..7385a1f3b 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
@@ -27,10 +27,8 @@ import java.util.List;
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 javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import lombok.AccessLevel;
import lombok.Getter;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
@@ -39,6 +37,7 @@ import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceExcepti
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.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
@@ -61,8 +60,6 @@ import org.springframework.stereotype.Component;
public class AutomationCompositionElementHandler implements AutomationCompositionElementListener {
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<>();
@@ -118,26 +115,47 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
@Override
public synchronized void deploy(UUID automationCompositionId, AcElementDeploy element,
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 {
- var chartInfo = CODER.convert(chartData, ChartInfo.class);
+ var chartInfo = getChartInfo(properties);
if (chartService.installChart(chartInfo)) {
chartMap.put(element.getId(), chartInfo);
- var config = CODER.convert(properties, ThreadConfig.class);
+ var config = getThreadConfig(properties);
checkPodStatus(automationCompositionId, element.getId(), chartInfo,
config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
+ } else {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Chart not installed");
}
- } catch (ServiceException | CoderException | IOException e) {
- LOGGER.warn("Installation of Helm chart failed", e);
+ } catch (ServiceException | IOException e) {
+ throw new PfModelException(Response.Status.BAD_REQUEST, "Installation of Helm chart failed ", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new PfModelException(Response.Status.BAD_REQUEST, "Error invoking ExecutorService ", e);
- } catch (ExecutionException e) {
- throw new PfModelException(Response.Status.BAD_REQUEST, "Error retrieving pod status result ", e);
+ } catch (AutomationCompositionException e) {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, e.getMessage());
+ }
+ }
+
+ private ThreadConfig getThreadConfig(Map<String, Object> properties) throws AutomationCompositionException {
+ try {
+ return CODER.convert(properties, ThreadConfig.class);
+ } catch (CoderException e) {
+ throw new AutomationCompositionException(Status.BAD_REQUEST, "Error extracting ThreadConfig ", e);
+ }
+ }
+
+ private ChartInfo getChartInfo(Map<String, Object> properties) throws AutomationCompositionException {
+ @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);
}
}
@@ -145,16 +163,17 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* Invoke a new thread to check the status of deployed pods.
*
* @param chart ChartInfo
+ * @throws ServiceException in case of an exception
*/
public void checkPodStatus(UUID automationCompositionId, UUID elementId, ChartInfo chart, int timeout,
- int podStatusCheckInterval) throws ExecutionException, InterruptedException {
- // Invoke runnable thread to check pod status
- var result = executor.submit(new PodStatusValidator(chart, timeout, podStatusCheckInterval), "Done");
- if (!result.get().isEmpty()) {
- LOGGER.info("Pod Status Validator Completed: {}", result.isDone());
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, elementId,
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- }
+ int podStatusCheckInterval) throws InterruptedException, ServiceException {
+
+ 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");
+
}
@Override
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 89eb284eb..0a1424134 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
@@ -25,7 +25,6 @@ import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
-import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException;
@@ -35,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class PodStatusValidator implements Runnable {
+public class PodStatusValidator {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -50,6 +49,7 @@ public class PodStatusValidator implements Runnable {
/**
* Constructor for PodStatusValidator.
+ *
* @param chart chartInfo
* @param timeout timeout for the thread to exit
* @param statusCheckInterval Interval to check pod status
@@ -60,15 +60,18 @@ public class PodStatusValidator implements Runnable {
this.statusCheckInterval = statusCheckInterval;
}
-
- @SneakyThrows
- @Override
- public void run() {
+ /**
+ * Run the execution.
+ *
+ * @throws InterruptedException in case of an exception
+ * @throws ServiceException in case of an exception
+ */
+ public void run() throws InterruptedException, ServiceException {
logger.info("Polling the status of deployed pods for the chart {}", chart.getChartId().getName());
try {
verifyPodStatus();
- } catch (ServiceException | IOException e) {
+ } catch (IOException e) {
throw new ServiceException("Error verifying the status of the pod. Exiting", e);
}
}