aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl
diff options
context:
space:
mode:
Diffstat (limited to 'participant/participant-impl')
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java4
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java31
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml8
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java27
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/rest/ChartControllerTest.java4
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java19
6 files changed, 62 insertions, 31 deletions
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java
index d041300a8..e2ccda4d5 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/controller/ChartController.java
@@ -1,6 +1,6 @@
/*-
* ========================LICENSE_START=================================
- * Copyright (C) 2021 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2021-2022 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.
@@ -33,6 +33,7 @@ import org.onap.policy.clamp.controlloop.participant.kubernetes.service.ChartSer
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -48,6 +49,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController("chartController")
+@ConditionalOnExpression("${chart.api.enabled:false}")
@RequestMapping("helm")
@Api(tags = {"k8s-participant"})
public class ChartController {
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);
+ }
}
/**
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
index 8b9d7e496..b266fe337 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
@@ -46,9 +46,15 @@ server:
logging:
# Configuration of logging
level:
- ROOT: INFO
+ ROOT: ERROR
org.springframework: ERROR
org.springframework.data: ERROR
org.springframework.web.reactive.function.client.ExchangeFunctions: ERROR
+ org.onap.policy.clamp.controlloop.participant.kubernetes: INFO
+
file:
name: /var/log/onap/policy/clamp/application.log
+
+chart:
+ api:
+ enabled: false
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 d7f09705b..805404b90 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
@@ -34,6 +35,9 @@ 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;
+import java.util.concurrent.Future;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -83,6 +87,12 @@ class ControlLoopElementHandlerTest {
@Mock
private ParticipantIntermediaryApi participantIntermediaryApi;
+ @Mock
+ private ExecutorService executor;
+
+ @Mock
+ private Future<String> result;
+
@BeforeAll
static void init() throws CoderException {
charts = CODER.decode(new File(CHART_INFO_YAML), ChartList.class).getCharts();
@@ -121,8 +131,9 @@ class ControlLoopElementHandlerTest {
}
@Test
- void test_ControlLoopElementUpdate() throws PfModelException, IOException, ServiceException {
- doNothing().when(controlLoopElementHandler).checkPodStatus(any(), anyInt(), anyInt());
+ void test_ControlLoopElementUpdate() throws PfModelException, IOException, ServiceException,
+ ExecutionException, InterruptedException {
+ doNothing().when(controlLoopElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
UUID elementId1 = UUID.randomUUID();
ControlLoopElement element = new ControlLoopElement();
element.setId(elementId1);
@@ -156,8 +167,14 @@ class ControlLoopElementHandlerTest {
}
@Test
- void test_checkPodStatus() {
+ void test_checkPodStatus() throws ExecutionException, InterruptedException {
+ doReturn(result).when(executor).submit(any(Runnable.class), any());
+ doReturn("Done").when(result).get();
+ doReturn(true).when(result).isDone();
var chartInfo = charts.get(0);
- assertDoesNotThrow(() -> controlLoopElementHandler.checkPodStatus(chartInfo, 1, 1));
+ ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier();
+ ControlLoopElement element = new ControlLoopElement();
+ assertDoesNotThrow(() -> controlLoopElementHandler.checkPodStatus(controlLoopId, element.getId(), chartInfo,
+ 1, 1));
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/rest/ChartControllerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/rest/ChartControllerTest.java
index 2af2a0171..8048b19ce 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/rest/ChartControllerTest.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/rest/ChartControllerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,7 +61,7 @@ import org.springframework.web.context.WebApplicationContext;
@ExtendWith(SpringExtension.class)
-@WebMvcTest(value = ChartController.class)
+@WebMvcTest(value = ChartController.class, properties = "chart.api.enabled=true")
@EnableConfigurationProperties(value = ParticipantK8sParameters.class)
class ChartControllerTest {
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
index 901fb682b..663d6d5e9 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -83,21 +83,21 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
* @param controlLoopElementId the ID of the control loop element
* @param currentState the current state of the control loop element
* @param orderedState the state to which the control loop element is changing to
- * @throws PfModelException in case of an exception
*/
@Override
public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId,
UUID controlLoopElementId, ControlLoopState currentState,
- ControlLoopOrderedState orderedState) throws PfModelException {
+ ControlLoopOrderedState orderedState) {
switch (orderedState) {
case UNINITIALISED:
try {
+ undeployPolicies(controlLoopElementId);
deletePolicyData(controlLoopId, controlLoopElementId, orderedState);
intermediaryApi.updateControlLoopElementState(controlLoopId,
controlLoopElementId, orderedState, ControlLoopState.UNINITIALISED,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
} catch (PfModelRuntimeException e) {
- LOGGER.debug("Deleting policy data failed", e);
+ LOGGER.debug("Undeploying/Deleting policy failed {}", controlLoopElementId, e);
}
break;
case PASSIVE:
@@ -111,11 +111,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
break;
case RUNNING:
- try {
- deployPolicies(controlLoopId, controlLoopElementId, orderedState);
- } catch (PfModelRuntimeException e) {
- LOGGER.debug("Deploying policies failed {}", controlLoopElementId);
- }
+ LOGGER.info("Running state is not supported");
break;
default:
LOGGER.debug("Unknown orderedstate {}", orderedState);
@@ -153,7 +149,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
LOGGER.debug("No policies to deploy to {}", controlLoopElementId);
}
intermediaryApi.updateControlLoopElementState(controlLoopId,
- controlLoopElementId, newState, ControlLoopState.RUNNING,
+ controlLoopElementId, newState, ControlLoopState.PASSIVE,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
}
@@ -181,8 +177,6 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element,
ToscaNodeTemplate clElementDefinition)
throws PfModelException {
- intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), element.getOrderedState(),
- ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
ToscaServiceTemplate controlLoopDefinition = element.getToscaServiceTemplateFragment();
if (controlLoopDefinition.getToscaTopologyTemplate() != null) {
if (controlLoopDefinition.getPolicyTypes() != null) {
@@ -205,6 +199,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
apiHttpClient.createPolicy(controlLoopDefinition);
}
}
+ deployPolicies(controlLoopId, element.getId(), element.getOrderedState());
}
/**