diff options
author | liamfallon <liam.fallon@est.tech> | 2022-01-25 19:55:43 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2022-02-18 15:54:40 +0000 |
commit | 43098043c4ef31d9d5dead66568d7d9482a6b165 (patch) | |
tree | 6f6ea4812ff93d65e7c64e12a3ec6ab4462a64e2 /participant/participant-impl/participant-impl-policy/src/main | |
parent | f401b5099bcb64f3e21de608d0207dd69d8043cd (diff) |
Rename TOSCA Control Loop to ACM
This commit renames the TOSCA Control Loop functionality in CLAMP to
Automation Composition Management.
This review is a direct renaming review and, as everything is renamed
together it is large.
Issue-ID: POLICY-3939
Change-Id: I28f0a6dd889bf3570a4c1365ae9e71fc58db6d6c
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-policy/src/main')
11 files changed, 263 insertions, 255 deletions
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/PolicyParticipantApplication.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/PolicyParticipantApplication.java index 4869b7c2f..0ba2aa2ea 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/PolicyParticipantApplication.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/PolicyParticipantApplication.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.controlloop.participant.policy; +package org.onap.policy.clamp.acm.participant.policy; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -31,9 +31,10 @@ import org.springframework.context.annotation.ComponentScan; */ @SpringBootApplication @ComponentScan({ - "org.onap.policy.clamp.controlloop.participant.policy", - "org.onap.policy.clamp.controlloop.participant.intermediary"}) -@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.policy.main.parameters") + "org.onap.policy.clamp.acm.participant.policy", + "org.onap.policy.clamp.acm.participant.intermediary" +}) +@ConfigurationPropertiesScan("org.onap.policy.clamp.acm.participant.policy.main.parameters") public class PolicyParticipantApplication { public static void main(String[] args) { diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/AbstractHttpClient.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/AbstractHttpClient.java index 2579585e5..4920d6550 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/AbstractHttpClient.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/AbstractHttpClient.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.controlloop.participant.policy.client; +package org.onap.policy.clamp.acm.participant.policy.client; import java.io.Closeable; import java.io.IOException; @@ -29,7 +29,7 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException; +import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; @@ -45,13 +45,13 @@ public abstract class AbstractHttpClient implements Closeable { * Constructor. * * @param policyParticipantParameters the parameters for the policy participant - * @throws ControlLoopRuntimeException on client start errors + * @throws AutomationCompositionRuntimeException on client start errors */ protected AbstractHttpClient(BusTopicParams policyParticipantParameters) { try { httpclient = HttpClientFactoryInstance.getClientFactory().build(policyParticipantParameters); } catch (final Exception e) { - throw new ControlLoopRuntimeException(Status.INTERNAL_SERVER_ERROR, " Client failed to start", e); + throw new AutomationCompositionRuntimeException(Status.INTERNAL_SERVER_ERROR, " Client failed to start", e); } } diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyApiHttpClient.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/PolicyApiHttpClient.java index 38a79f7f6..a86576eed 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyApiHttpClient.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/PolicyApiHttpClient.java @@ -18,12 +18,12 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.controlloop.participant.policy.client; +package org.onap.policy.clamp.acm.participant.policy.client; 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.onap.policy.clamp.acm.participant.policy.main.parameters.ParticipantPolicyParameters; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.stereotype.Component; 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/acm/participant/policy/client/PolicyPapHttpClient.java index f835c6e04..584170ae4 100644 --- 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/acm/participant/policy/client/PolicyPapHttpClient.java @@ -18,14 +18,14 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.controlloop.participant.policy.client; +package org.onap.policy.clamp.acm.participant.policy.client; import java.util.LinkedList; import java.util.List; 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.onap.policy.clamp.acm.participant.policy.main.parameters.ParticipantPolicyParameters; import org.onap.policy.models.pdp.concepts.DeploymentGroup; import org.onap.policy.models.pdp.concepts.DeploymentGroups; import org.onap.policy.models.pdp.concepts.DeploymentSubGroup; diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/ParticipantConfig.java index 7b49a9a6b..7f9ad243d 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/ParticipantConfig.java @@ -18,10 +18,10 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.controlloop.participant.policy.config; +package org.onap.policy.clamp.acm.participant.policy.config; -import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.controlloop.participant.policy.main.handler.ControlLoopElementHandler; +import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.acm.participant.policy.main.handler.AutomationCompositionElementHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -29,15 +29,15 @@ import org.springframework.context.annotation.Configuration; public class ParticipantConfig { /** - * Register ControlLoopElementListener. + * Register AutomationCompositionElementListener. * * @param intermediaryApi the ParticipantIntermediaryApi - * @param clElementHandler the ControlLoop Element Handler + * @param acElementHandler the Aotumation Composition Element Handler */ @Autowired - public void registerControlLoopElementListener(ParticipantIntermediaryApi intermediaryApi, - ControlLoopElementHandler clElementHandler) { - intermediaryApi.registerControlLoopElementListener(clElementHandler); - clElementHandler.setIntermediaryApi(intermediaryApi); + public void registerAutomationCompositionElementListener(ParticipantIntermediaryApi intermediaryApi, + AutomationCompositionElementHandler acElementHandler) { + intermediaryApi.registerAutomationCompositionElementListener(acElementHandler); + acElementHandler.setIntermediaryApi(intermediaryApi); } } diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/SecurityConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/SecurityConfig.java index 4ee8c41b0..d7ce925e2 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/SecurityConfig.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/SecurityConfig.java @@ -16,7 +16,7 @@ * ========================LICENSE_END=================================== */ -package org.onap.policy.clamp.controlloop.participant.policy.config; +package org.onap.policy.clamp.acm.participant.policy.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java new file mode 100644 index 000000000..42d7526f8 --- /dev/null +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java @@ -0,0 +1,227 @@ +/*- + * ============LICENSE_START======================================================= + * 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"); + * 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.acm.participant.policy.main.handler; + +import java.time.Instant; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import lombok.Setter; +import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient; +import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.pdp.concepts.DeploymentSubGroup; +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.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * This class handles implementation of automationCompositionElement updates. + */ +@Component +public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandler.class); + private final Map<String, String> policyTypeMap = new LinkedHashMap<>(); + private final Map<String, String> policyMap = new LinkedHashMap<>(); + + private final PolicyApiHttpClient apiHttpClient; + private final PolicyPapHttpClient papHttpClient; + + @Setter + private ParticipantIntermediaryApi intermediaryApi; + + /** + * constructor. + * + * @param apiHttpClient the Policy Api Http Client + * @param papHttpClient the Policy Pap Http Client + */ + public AutomationCompositionElementHandler(PolicyApiHttpClient apiHttpClient, PolicyPapHttpClient papHttpClient) { + this.papHttpClient = papHttpClient; + this.apiHttpClient = apiHttpClient; + } + + /** + * Callback method to handle a automation composition element state change. + * + * @param automationCompositionId the ID of the automation composition + * @param automationCompositionElementId the ID of the automation composition element + * @param currentState the current state of the automation composition element + * @param orderedState the state to which the automation composition element is changing to + */ + @Override + public void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId, + UUID automationCompositionElementId, + AutomationCompositionState currentState, + AutomationCompositionOrderedState orderedState) { + switch (orderedState) { + case UNINITIALISED: + try { + undeployPolicies(automationCompositionElementId); + deletePolicyData(automationCompositionId, automationCompositionElementId, orderedState); + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, + automationCompositionElementId, orderedState, AutomationCompositionState.UNINITIALISED, + ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); + } catch (PfModelRuntimeException e) { + LOGGER.debug("Undeploying/Deleting policy failed {}", automationCompositionElementId, e); + } + break; + case PASSIVE: + try { + undeployPolicies(automationCompositionElementId); + } catch (PfModelRuntimeException e) { + LOGGER.debug("Undeploying policies failed - no policies to undeploy {}", + automationCompositionElementId); + } + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, + automationCompositionElementId, orderedState, AutomationCompositionState.PASSIVE, + ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); + break; + case RUNNING: + LOGGER.info("Running state is not supported"); + break; + default: + LOGGER.debug("Unknown orderedstate {}", orderedState); + break; + } + } + + private void deletePolicyData(ToscaConceptIdentifier automationCompositionId, + UUID automationCompositionElementId, AutomationCompositionOrderedState newState) { + // Delete all policies of this automationComposition from policy framework + for (Entry<String, String> policy : policyMap.entrySet()) { + apiHttpClient.deletePolicy(policy.getKey(), policy.getValue()); + } + policyMap.clear(); + // Delete all policy types of this automation composition from policy framework + for (Entry<String, String> policyType : policyTypeMap.entrySet()) { + apiHttpClient.deletePolicyType(policyType.getKey(), policyType.getValue()); + } + policyTypeMap.clear(); + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, + automationCompositionElementId, newState, AutomationCompositionState.UNINITIALISED, + ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); + } + + private void deployPolicies(ToscaConceptIdentifier automationCompositionId, UUID automationCompositionElementId, + AutomationCompositionOrderedState newState) { + // Deploy all policies of this automationComposition from Policy Framework + if (!policyMap.entrySet().isEmpty()) { + for (Entry<String, String> policy : policyMap.entrySet()) { + papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(), + DeploymentSubGroup.Action.POST); + } + LOGGER.debug("Policies deployed to {} successfully", automationCompositionElementId); + } else { + LOGGER.debug("No policies to deploy to {}", automationCompositionElementId); + } + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, + automationCompositionElementId, newState, AutomationCompositionState.PASSIVE, + ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); + } + + private void undeployPolicies(UUID automationCompositionElementId) { + // Undeploy all policies of this automation composition from Policy Framework + if (!policyMap.entrySet().isEmpty()) { + for (Entry<String, String> policy : policyMap.entrySet()) { + papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(), + DeploymentSubGroup.Action.DELETE); + } + LOGGER.debug("Undeployed policies from {} successfully", automationCompositionElementId); + } else { + LOGGER.debug("No policies are deployed to {}", automationCompositionElementId); + } + } + + /** + * Callback method to handle an update on a automation composition element. + * + * @param element the information on the automation composition element + * @param acElementDefinition toscaNodeTemplate + * @throws PfModelException in case of an exception + */ + @Override + public void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId, + AutomationCompositionElement element, + ToscaNodeTemplate acElementDefinition) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), + element.getOrderedState(), + AutomationCompositionState.PASSIVE, ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE); + ToscaServiceTemplate automationCompositionDefinition = element.getToscaServiceTemplateFragment(); + if (automationCompositionDefinition.getToscaTopologyTemplate() != null) { + if (automationCompositionDefinition.getPolicyTypes() != null) { + for (ToscaPolicyType policyType : automationCompositionDefinition.getPolicyTypes().values()) { + policyTypeMap.put(policyType.getName(), policyType.getVersion()); + } + LOGGER.debug("Found Policy Types in automation composition definition: {} , Creating Policy Types", + automationCompositionDefinition.getName()); + apiHttpClient.createPolicyType(automationCompositionDefinition); + } + if (automationCompositionDefinition.getToscaTopologyTemplate().getPolicies() != null) { + for (Map<String, ToscaPolicy> gotPolicyMap : automationCompositionDefinition.getToscaTopologyTemplate() + .getPolicies()) { + for (ToscaPolicy policy : gotPolicyMap.values()) { + policyMap.put(policy.getName(), policy.getVersion()); + } + } + LOGGER.debug("Found Policies in automation composition definition: {} , Creating Policies", + automationCompositionDefinition.getName()); + apiHttpClient.createPolicy(automationCompositionDefinition); + } + } + deployPolicies(automationCompositionId, element.getId(), element.getOrderedState()); + } + + /** + * Handle automationCompositionElement statistics. + * + * @param automationCompositionElementId automation composition element id + */ + @Override + public void handleStatistics(UUID automationCompositionElementId) { + var acElement = intermediaryApi.getAutomationCompositionElement(automationCompositionElementId); + if (acElement != null) { + var acElementStatistics = new AcElementStatistics(); + acElementStatistics.setState(acElement.getState()); + acElementStatistics.setTimeStamp(Instant.now()); + intermediaryApi.updateAutomationCompositionElementStatistics(automationCompositionElementId, + acElementStatistics); + } + } +}
\ 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/acm/participant/policy/main/parameters/ParticipantPolicyParameters.java index 8e1de36b9..a57198126 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/acm/participant/policy/main/parameters/ParticipantPolicyParameters.java @@ -18,15 +18,15 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.controlloop.participant.policy.main.parameters; +package org.onap.policy.clamp.acm.participant.policy.main.parameters; import javax.validation.Valid; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; -import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; -import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters; +import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters; +import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; import org.onap.policy.common.endpoints.parameters.RestClientParameters; import org.onap.policy.common.parameters.validation.ParameterGroupConstraint; import org.springframework.boot.context.properties.ConfigurationProperties; 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 deleted file mode 100644 index 663d6d5e9..000000000 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java +++ /dev/null @@ -1,220 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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"); - * 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.main.handler; - -import java.time.Instant; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; -import lombok.Setter; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType; -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.pdp.concepts.DeploymentSubGroup; -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.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -/** - * This class handles implementation of controlLoopElement updates. - */ -@Component -public class ControlLoopElementHandler implements ControlLoopElementListener { - - private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopElementHandler.class); - private final Map<String, String> policyTypeMap = new LinkedHashMap<>(); - private final Map<String, String> policyMap = new LinkedHashMap<>(); - - private final PolicyApiHttpClient apiHttpClient; - private final PolicyPapHttpClient papHttpClient; - - @Setter - private ParticipantIntermediaryApi intermediaryApi; - - /** - * constructor. - * - * @param apiHttpClient the Policy Api Http Client - * @param papHttpClient the Policy Pap Http Client - */ - 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 orderedState the state to which the control loop element is changing to - */ - @Override - public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, - UUID controlLoopElementId, ControlLoopState currentState, - 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("Undeploying/Deleting policy failed {}", controlLoopElementId, e); - } - break; - case PASSIVE: - try { - undeployPolicies(controlLoopElementId); - } catch (PfModelRuntimeException e) { - LOGGER.debug("Undeploying policies failed - no policies to undeploy {}", controlLoopElementId); - } - intermediaryApi.updateControlLoopElementState(controlLoopId, - controlLoopElementId, orderedState, ControlLoopState.PASSIVE, - ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); - break; - case RUNNING: - LOGGER.info("Running state is not supported"); - break; - default: - LOGGER.debug("Unknown orderedstate {}", orderedState); - break; - } - } - - private void deletePolicyData(ToscaConceptIdentifier controlLoopId, - 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()); - } - policyMap.clear(); - // Delete all policy types of this control loop from policy framework - for (Entry<String, String> policyType : policyTypeMap.entrySet()) { - apiHttpClient.deletePolicyType(policyType.getKey(), policyType.getValue()); - } - policyTypeMap.clear(); - intermediaryApi.updateControlLoopElementState(controlLoopId, - 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(), - DeploymentSubGroup.Action.POST); - } - LOGGER.debug("Policies deployed to {} successfully", controlLoopElementId); - } else { - LOGGER.debug("No policies to deploy to {}", controlLoopElementId); - } - intermediaryApi.updateControlLoopElementState(controlLoopId, - controlLoopElementId, newState, ControlLoopState.PASSIVE, - ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); - } - - private void undeployPolicies(UUID controlLoopElementId) { - // 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(), - DeploymentSubGroup.Action.DELETE); - } - LOGGER.debug("Undeployed policies from {} successfully", controlLoopElementId); - } else { - LOGGER.debug("No policies are deployed to {}", controlLoopElementId); - } - } - - /** - * Callback method to handle an update on a control loop element. - * - * @param element the information on the control loop element - * @param clElementDefinition toscaNodeTemplate - * @throws PfModelException in case of an exception - */ - @Override - public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element, - ToscaNodeTemplate clElementDefinition) - throws PfModelException { - ToscaServiceTemplate controlLoopDefinition = element.getToscaServiceTemplateFragment(); - if (controlLoopDefinition.getToscaTopologyTemplate() != null) { - if (controlLoopDefinition.getPolicyTypes() != null) { - for (ToscaPolicyType policyType : controlLoopDefinition.getPolicyTypes().values()) { - policyTypeMap.put(policyType.getName(), policyType.getVersion()); - } - LOGGER.debug("Found Policy Types in control loop definition: {} , Creating Policy Types", - controlLoopDefinition.getName()); - apiHttpClient.createPolicyType(controlLoopDefinition); - } - if (controlLoopDefinition.getToscaTopologyTemplate().getPolicies() != null) { - for (Map<String, ToscaPolicy> foundPolicyMap : controlLoopDefinition.getToscaTopologyTemplate() - .getPolicies()) { - for (ToscaPolicy policy : foundPolicyMap.values()) { - policyMap.put(policy.getName(), policy.getVersion()); - } - } - LOGGER.debug("Found Policies in control loop definition: {} , Creating Policies", - controlLoopDefinition.getName()); - apiHttpClient.createPolicy(controlLoopDefinition); - } - } - deployPolicies(controlLoopId, element.getId(), element.getOrderedState()); - } - - /** - * Handle controlLoopElement statistics. - * - * @param controlLoopElementId controlloop element id - */ - @Override - public void handleStatistics(UUID controlLoopElementId) throws PfModelException { - var clElement = intermediaryApi.getControlLoopElement(controlLoopElementId); - if (clElement != null) { - var clElementStatistics = new ClElementStatistics(); - clElementStatistics.setControlLoopState(clElement.getState()); - clElementStatistics.setTimeStamp(Instant.now()); - intermediaryApi.updateControlLoopElementStatistics(controlLoopElementId, clElementStatistics); - } - } -}
\ No newline at end of file diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml b/participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml index 46db712b6..383bc7418 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml +++ b/participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml @@ -52,11 +52,11 @@ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class> <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class> <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class> - <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop</class> - <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoopElement</class> - <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant</class> - <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics</class> - <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics</class> + <class>org.onap.policy.clamp.acm.models.acm.persistence.concepts.JpaAutomationComposition</class> + <class>org.onap.policy.clamp.acm.models.acm.persistence.concepts.JpaAutomationCompositionElement</class> + <class>org.onap.policy.clamp.acm.models.acm.persistence.concepts.JpaParticipant</class> + <class>org.onap.policy.clamp.acm.models.acm.persistence.concepts.JpaParticipantStatistics</class> + <class>org.onap.policy.clamp.acm.models.acm.persistence.concepts.JpaAcElementStatistics</class> <properties> <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> <property name="eclipselink.ddl-generation.output-mode" value="database" /> 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 2aa33c1c4..c3338a993 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 @@ -30,19 +30,19 @@ participant: name: org.onap.PM_Policy version: 1.0.0 participantType: - name: org.onap.policy.controlloop.PolicyControlLoopParticipant + name: org.onap.policy.clamp.acm.PolicyParticipant version: 2.3.1 - clampControlLoopTopics: + clampAutomationCompositionTopics: topicSources: - - topic: POLICY-CLRUNTIME-PARTICIPANT + topic: POLICY-ACRUNTIME-PARTICIPANT servers: - ${topicServer:localhost} topicCommInfrastructure: dmaap fetchTimeout: 15000 topicSinks: - - topic: POLICY-CLRUNTIME-PARTICIPANT + topic: POLICY-ACRUNTIME-PARTICIPANT servers: - ${topicServer:localhost} topicCommInfrastructure: dmaap @@ -54,4 +54,4 @@ management: server: port: 8085 servlet: - context-path: /onap/policyparticipant + context-path: /onap/policy/clamp/acm/policyparticipant |