diff options
Diffstat (limited to 'participant')
14 files changed, 249 insertions, 40 deletions
diff --git a/participant/participant-impl/participant-impl-cds/pom.xml b/participant/participant-impl/participant-impl-cds/pom.xml index ccdd8bee7..170a800da 100644 --- a/participant/participant-impl/participant-impl-cds/pom.xml +++ b/participant/participant-impl/participant-impl-cds/pom.xml @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-cds</artifactId> diff --git a/participant/participant-impl/participant-impl-http/pom.xml b/participant/participant-impl/participant-impl-http/pom.xml index 85d65e707..5cfb30f6a 100644 --- a/participant/participant-impl/participant-impl-http/pom.xml +++ b/participant/participant-impl/participant-impl-http/pom.xml @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-http</artifactId> diff --git a/participant/participant-impl/participant-impl-kubernetes/pom.xml b/participant/participant-impl/participant-impl-kubernetes/pom.xml index ebaa7a198..68c1a1418 100644 --- a/participant/participant-impl/participant-impl-kubernetes/pom.xml +++ b/participant/participant-impl/participant-impl-kubernetes/pom.xml @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-kubernetes</artifactId> diff --git a/participant/participant-impl/participant-impl-policy/pom.xml b/participant/participant-impl/participant-impl-policy/pom.xml index 367e3d664..bed42b081 100644 --- a/participant/participant-impl/participant-impl-policy/pom.xml +++ b/participant/participant-impl/participant-impl-policy/pom.xml @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-policy</artifactId> diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java new file mode 100644 index 000000000..3cce3bd8a --- /dev/null +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.participant.policy.client; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameters; +import org.springframework.stereotype.Component; + +@Component +public class PolicyPapHttpClient extends AbstractHttpClient { + + private static final String PAP_URI = "/policy/pap/v1/"; + private final String pdpGroup; + private final String pdpType; + + /** + * Constructor. + * + * @param parameters the policy participant parameters + */ + public PolicyPapHttpClient(ParticipantPolicyParameters parameters) { + super(parameters.getPolicyPapParameters()); + this.pdpGroup = parameters.getPdpGroup(); + this.pdpType = parameters.getPdpType(); + } + + /** + * Deploy or undeploy Policies. + * + * @param policyName the name of the policy to be deployed/undeployed + * @param policyVersion the version of the policy to be deployed/undeployed + * @param action the action to deploy/undeploy policy + * @return Response + */ + public Response handlePolicyDeployOrUndeploy(final String policyName, final String policyVersion, + final String action) { + // policies + JsonObject policyArrayBody = new JsonObject(); + policyArrayBody.addProperty("name", policyName); + policyArrayBody.addProperty("version", policyVersion); + JsonArray policyArr = new JsonArray(); + policyArr.add(policyArrayBody); + + // deploymentSubgroups + JsonObject deploymentSubGrpBody = new JsonObject(); + deploymentSubGrpBody.addProperty("pdpType", pdpType); + deploymentSubGrpBody.addProperty("action", action); + deploymentSubGrpBody.add("policies", policyArr); + JsonArray deployArr = new JsonArray(); + deployArr.add(deploymentSubGrpBody); + + // groups + JsonObject groupArrayBody = new JsonObject(); + groupArrayBody.addProperty("name", pdpGroup); + groupArrayBody.add("deploymentSubgroups", deployArr); + JsonArray groupArr = new JsonArray(); + groupArr.add(groupArrayBody); + + // main json + JsonObject mainJson = new JsonObject(); + mainJson.add("groups", groupArr); + + return executePost(PAP_URI + "pdps/deployments/batch", Entity.entity(mainJson, MediaType.APPLICATION_JSON)); + } +} 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 9054788f9..29a7852f1 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 @@ -36,6 +36,7 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener; import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyApiHttpClient; +import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyPapHttpClient; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -58,6 +59,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { private final Map<String, String> policyMap = new LinkedHashMap<>(); private final PolicyApiHttpClient apiHttpClient; + private final PolicyPapHttpClient papHttpClient; @Setter private ParticipantIntermediaryApi intermediaryApi; @@ -66,49 +68,62 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * constructor. * * @param apiHttpClient the Policy Api Http Client + * @param papHttpClient the Policy Pap Http Client */ - public ControlLoopElementHandler(PolicyApiHttpClient apiHttpClient) { + public ControlLoopElementHandler(PolicyApiHttpClient apiHttpClient, PolicyPapHttpClient papHttpClient) { + this.papHttpClient = papHttpClient; this.apiHttpClient = apiHttpClient; } /** * Callback method to handle a control loop element state change. * + * @param controlLoopId the ID of the control loop * @param controlLoopElementId the ID of the control loop element * @param currentState the current state of the control loop element - * @param newState the state to which the control loop element is changing to + * @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 newState) throws PfModelException { - switch (newState) { + ControlLoopOrderedState orderedState) throws PfModelException { + switch (orderedState) { case UNINITIALISED: try { - deletePolicyData(controlLoopId, controlLoopElementId, newState); + 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); } break; case PASSIVE: + try { + undeployPolicies(controlLoopElementId, orderedState); + } catch (PfModelRuntimeException e) { + LOGGER.debug("Undeploying policies failed - no policies to undeploy {}", controlLoopElementId); + } intermediaryApi.updateControlLoopElementState(controlLoopId, - controlLoopElementId, newState, ControlLoopState.PASSIVE, - ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + controlLoopElementId, orderedState, ControlLoopState.PASSIVE, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); break; case RUNNING: - intermediaryApi.updateControlLoopElementState(controlLoopId, - controlLoopElementId, newState, ControlLoopState.RUNNING, - ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + try { + deployPolicies(controlLoopId, controlLoopElementId, orderedState); + } catch (PfModelRuntimeException e) { + LOGGER.debug("Deploying policies failed {}", controlLoopElementId); + } break; default: - LOGGER.debug("Unknown orderedstate {}", newState); + LOGGER.debug("Unknown orderedstate {}", orderedState); break; } } private void deletePolicyData(ToscaConceptIdentifier controlLoopId, - UUID controlLoopElementId, ControlLoopOrderedState newState) { + UUID controlLoopElementId, ControlLoopOrderedState newState) { // Delete all policies of this controlLoop from policy framework for (Entry<String, String> policy : policyMap.entrySet()) { apiHttpClient.deletePolicy(policy.getKey(), policy.getValue()); @@ -120,8 +135,36 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { } policyTypeMap.clear(); intermediaryApi.updateControlLoopElementState(controlLoopId, - controlLoopElementId, newState, ControlLoopState.UNINITIALISED, - ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + controlLoopElementId, newState, ControlLoopState.UNINITIALISED, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + } + + private void deployPolicies(ToscaConceptIdentifier controlLoopId, UUID controlLoopElementId, + ControlLoopOrderedState newState) { + // Deploy all policies of this controlLoop from Policy Framework + if (policyMap.entrySet() != null) { + for (Entry<String, String> policy : policyMap.entrySet()) { + papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(), "POST"); + } + LOGGER.debug("Policies deployed to {} successfully", controlLoopElementId); + } else { + LOGGER.debug("No policies to deploy to {}", controlLoopElementId); + } + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.RUNNING, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + } + + private void undeployPolicies(UUID controlLoopElementId, ControlLoopOrderedState newState) { + // Undeploy all policies of this controlloop from Policy Framework + if (policyMap.entrySet() != null) { + for (Entry<String, String> policy : policyMap.entrySet()) { + papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(), "DELETE"); + } + LOGGER.debug("Undeployed policies from {} successfully", controlLoopElementId); + } else { + LOGGER.debug("No policies are deployed to {}", controlLoopElementId); + } } /** @@ -133,7 +176,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { */ @Override public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element, - ToscaNodeTemplate clElementDefinition) + ToscaNodeTemplate clElementDefinition) throws PfModelException { intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), element.getOrderedState(), ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE); @@ -176,4 +219,4 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { intermediaryApi.updateControlLoopElementStatistics(controlLoopElementId, clElementStatistics); } } -} +}
\ No newline at end of file diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java index ced9d1bd0..8e1de36b9 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java @@ -21,6 +21,7 @@ package org.onap.policy.clamp.controlloop.participant.policy.main.parameters; import javax.validation.Valid; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -48,4 +49,14 @@ public class ParticipantPolicyParameters implements ParticipantParameters { @NotNull @ParameterGroupConstraint private RestClientParameters policyApiParameters; + + @NotNull + @ParameterGroupConstraint + private RestClientParameters policyPapParameters; + + @NotBlank + private String pdpGroup; + + @NotBlank + private String pdpType; } diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml index 32cd28cd3..e5b2b2ab1 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml @@ -2,6 +2,8 @@ server: port: 8082 participant: + pdpGroup: defaultGroup + pdpType: apex policyApiParameters: clientName: api hostname: policy-api @@ -10,6 +12,14 @@ participant: password: zb!XztG34 https: true allowSelfSignedCerts: true + policyPapParameters: + clientName: pap + hostname: policy-pap + port: 6969 + userName: healthcheck + password: zb!XztG34 + https: true + allowSelfSignedCerts: true intermediaryParameters: reportingTimeIntervalMs: 120000 description: Participant Description diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java index a34c9cda5..41af8a6ec 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java @@ -68,6 +68,26 @@ public class CommonTestData { map.put("name", name); map.put("intermediaryParameters", getIntermediaryParametersMap(false)); map.put("policyApiParameters", getPolicyApiParametersMap()); + map.put("policyPapParameters", getPolicyPapParametersMap()); + map.put("pdpGroup", "defaultGroup"); + map.put("pdpType", "apex"); + return map; + } + + /** + * Returns a property map for a policyPapParameters map for test cases. + * + * @return a property map suitable for constructing an object + */ + public Map<String, Object> getPolicyPapParametersMap() { + final Map<String, Object> map = new TreeMap<>(); + map.put("clientName", "pap"); + map.put("hostname", "localhost"); + map.put("port", 6968); + map.put("userName", "healthcheck"); + map.put("password", "zb!XztG34"); + map.put("https", false); + map.put("allowSelfSignedCerts", true); return map; } diff --git a/participant/participant-impl/participant-impl-simulator/pom.xml b/participant/participant-impl/participant-impl-simulator/pom.xml index 5e315ba9e..d0d364605 100644 --- a/participant/participant-impl/participant-impl-simulator/pom.xml +++ b/participant/participant-impl/participant-impl-simulator/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-simulator</artifactId> diff --git a/participant/participant-impl/pom.xml b/participant/participant-impl/pom.xml index 006d38def..3d1acb0f0 100644 --- a/participant/participant-impl/pom.xml +++ b/participant/participant-impl/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl</artifactId> diff --git a/participant/participant-intermediary/pom.xml b/participant/participant-intermediary/pom.xml index aac80a4a2..0b111fbcc 100644 --- a/participant/participant-intermediary/pom.xml +++ b/participant/participant-intermediary/pom.xml @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-intermediary</artifactId> diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java index 8bdf91824..30a06ba22 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java @@ -103,9 +103,11 @@ public class ControlLoopHandler { return null; } + // Update states of ControlLoopElement in controlLoopMap for (var controlLoop : controlLoopMap.values()) { var element = controlLoop.getElements().get(id); if (element != null) { + element.setOrderedState(orderedState); element.setState(newState); } var checkOpt = controlLoop.getElements().values().stream() @@ -116,6 +118,7 @@ public class ControlLoopHandler { } } + // Update states of ControlLoopElement in elementsOnThisParticipant var clElement = elementsOnThisParticipant.get(id); if (clElement != null) { var controlLoopStateChangeAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK); @@ -339,16 +342,16 @@ public class ControlLoopHandler { return; } - for (var clElementListener : listeners) { - try { - for (var element : controlLoop.getElements().values()) { - clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), element.getId(), - element.getState(), orderedState); + controlLoop.getElements().values().stream().forEach(clElement -> { + for (var clElementListener : listeners) { + try { + clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), + clElement.getId(), clElement.getState(), orderedState); + } catch (PfModelException e) { + LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition()); } - } catch (PfModelException e) { - LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition()); } - } + }); } /** diff --git a/participant/pom.xml b/participant/pom.xml index 015308bbe..77108fbf5 100644 --- a/participant/pom.xml +++ b/participant/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>6.1.2-SNAPSHOT</version> + <version>6.1.3-SNAPSHOT</version> </parent> <groupId>org.onap.policy.clamp.participant</groupId> @@ -40,6 +40,49 @@ <module>participant-impl</module> </modules> + <profiles> + <!-- These profiles are required because the tests jar from policy-clamp-common is not available in staging + Jenkins jobs --> + <profile> + <id>ExcludeTestJar1</id> + <activation> + <property> + <name>maven.test.skip</name> + <value>false</value> + </property> + </activation> + <dependencies> + <dependency> + <groupId>org.onap.policy.clamp</groupId> + <artifactId>policy-clamp-common</artifactId> + <classifier>tests</classifier> + <type>test-jar</type> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + <profile> + <id>ExcludeTestJar2</id> + <activation> + <property> + <name>skipTests</name> + <value>false</value> + </property> + </activation> + <dependencies> + <dependency> + <groupId>org.onap.policy.clamp</groupId> + <artifactId>policy-clamp-common</artifactId> + <classifier>tests</classifier> + <type>test-jar</type> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + </profiles> + <dependencies> <dependency> <groupId>org.onap.policy.clamp</groupId> @@ -51,14 +94,6 @@ <artifactId>policy-clamp-models</artifactId> <version>${project.version}</version> </dependency> - <dependency> - <groupId>org.onap.policy.clamp</groupId> - <artifactId>policy-clamp-common</artifactId> - <classifier>tests</classifier> - <type>test-jar</type> - <version>${project.version}</version> - <scope>test</scope> - </dependency> </dependencies> <build> |