diff options
72 files changed, 898 insertions, 746 deletions
diff --git a/common/src/main/resources/tosca/HttpAutomationCompositionElementType.yaml b/common/src/main/resources/tosca/HttpAutomationCompositionElementType.yaml index ca9d577f1..097288e08 100644 --- a/common/src/main/resources/tosca/HttpAutomationCompositionElementType.yaml +++ b/common/src/main/resources/tosca/HttpAutomationCompositionElementType.yaml @@ -64,7 +64,7 @@ data_types: description: A sequence of REST commands to send to the REST endpoint node_types: org.onap.policy.clamp.acm.HttpAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: baseUrl: diff --git a/common/src/main/resources/tosca/PolicyAutomationCompositionElementType.yaml b/common/src/main/resources/tosca/PolicyAutomationCompositionElementType.yaml index 3968b3471..1aac3f1ce 100644 --- a/common/src/main/resources/tosca/PolicyAutomationCompositionElementType.yaml +++ b/common/src/main/resources/tosca/PolicyAutomationCompositionElementType.yaml @@ -18,7 +18,7 @@ tosca_definitions_version: tosca_simple_yaml_1_3 node_types: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: policyType: diff --git a/examples/pom.xml b/examples/pom.xml index 4605ba51a..80fb18b8b 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2022 Nordix Foundation. + Copyright (C) 2022-2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -39,7 +39,6 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> - <version>1.7.0</version> <executions> <execution> <goals> diff --git a/examples/src/main/resources/clamp/acm/acm-demo/toscaServiceTemplate.yaml b/examples/src/main/resources/clamp/acm/acm-demo/toscaServiceTemplate.yaml index 525583b59..f062115ad 100644 --- a/examples/src/main/resources/clamp/acm/acm-demo/toscaServiceTemplate.yaml +++ b/examples/src/main/resources/clamp/acm/acm-demo/toscaServiceTemplate.yaml @@ -355,7 +355,7 @@ node_types: type: onap.datatypes.ToscaConceptIdentifier description: Specifies a list of automation composition element definitions that make up this automation composition definition org.onap.policy.clamp.acm.PolicyAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: policy_type_id: @@ -365,7 +365,7 @@ node_types: type: onap.datatypes.ToscaConceptIdentifier required: false org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: chart: @@ -385,7 +385,7 @@ node_types: type: string required: true org.onap.policy.clamp.acm.HttpAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: baseUrl: @@ -445,7 +445,7 @@ topology_template: # Chart from any chart repository configured on helm client. version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for AC Element Starter properties: provider: ONAP @@ -469,7 +469,7 @@ topology_template: # Chart from any chart repository configured on helm client. version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for AC Element Bridge properties: provider: ONAP @@ -493,7 +493,7 @@ topology_template: # Chart from any chart repository configured on helm client. version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for AC Element Sink properties: provider: ONAP @@ -524,7 +524,7 @@ topology_template: # Http config for AC Element Starter. version: 1.2.3 type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the http requests of AC Element Starter microservice properties: provider: ONAP @@ -550,7 +550,7 @@ topology_template: # Http config for AC Element Bridge. version: 1.2.3 type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the http requests of AC Element Bridge microservice properties: provider: ONAP @@ -576,7 +576,7 @@ topology_template: # Http config for AC Element Sink. version: 1.2.3 type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the http requests of AC Element Sink microservice properties: provider: ONAP diff --git a/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml b/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml index 9d8a37519..4587e31e8 100644 --- a/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml +++ b/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml @@ -342,7 +342,7 @@ node_types: type: onap.datatypes.ToscaConceptIdentifier description: Specifies a list of automation composition element definitions that make up this automation composition definition org.onap.policy.clamp.acm.PolicyAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: policy_type_id: @@ -359,7 +359,7 @@ node_types: type: onap.datatypes.ToscaConceptIdentifier required: true org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: chart: @@ -379,7 +379,7 @@ node_types: type: string required: true org.onap.policy.clamp.acm.HttpAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: baseUrl: @@ -419,7 +419,7 @@ topology_template: org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement: version: 1.2.3 type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the operational policy for Performance Management Subscription Handling properties: provider: Ericsson @@ -441,7 +441,7 @@ topology_template: # Chart from new repository version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for PMSH properties: provider: ONAP @@ -470,7 +470,7 @@ topology_template: # Http config for PMSH. version: 1.2.3 type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the http requests of PMSH microservice properties: provider: ONAP diff --git a/examples/src/main/resources/clamp/acm/test/participant-http.yaml b/examples/src/main/resources/clamp/acm/test/participant-http.yaml index 2bc3828bb..39e1fa63d 100644 --- a/examples/src/main/resources/clamp/acm/test/participant-http.yaml +++ b/examples/src/main/resources/clamp/acm/test/participant-http.yaml @@ -112,7 +112,7 @@ node_types: entry_schema: type: onap.datatypes.ToscaConceptIdentifier org.onap.policy.clamp.acm.HttpAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: baseUrl: @@ -146,7 +146,7 @@ topology_template: # Http config for PMSH. version: 1.2.3 type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the http requests of PMSH microservice properties: provider: ONAP diff --git a/examples/src/main/resources/clamp/acm/test/participant-kubernetes-helm.yaml b/examples/src/main/resources/clamp/acm/test/participant-kubernetes-helm.yaml index b6aab8747..4034debba 100644 --- a/examples/src/main/resources/clamp/acm/test/participant-kubernetes-helm.yaml +++ b/examples/src/main/resources/clamp/acm/test/participant-kubernetes-helm.yaml @@ -65,7 +65,7 @@ node_types: entry_schema: type: onap.datatypes.ToscaConceptIdentifier org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: chart: @@ -98,7 +98,7 @@ topology_template: # Chart from any chart repository configured on helm client. version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for Hello World properties: provider: ONAP @@ -117,7 +117,7 @@ topology_template: # Chart from local file system version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for PMSH properties: provider: ONAP @@ -137,7 +137,7 @@ topology_template: # Chart installation without passing repository name version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for local chart properties: provider: ONAP diff --git a/models/pom.xml b/models/pom.xml index c4678586d..e68a680c7 100644 --- a/models/pom.xml +++ b/models/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2022 Nordix Foundation. + Copyright (C) 2021-2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -46,7 +46,6 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> - <version>1.7.0</version> <configuration> <resourceBundles> <resourceBundle>org.onap.policy.clamp:policy-clamp-examples:${project.version}</resourceBundle> diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java index 363668619..dc8a39b34 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -26,7 +26,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; -import org.apache.commons.collections4.MapUtils; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @@ -44,12 +43,6 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut private UUID compositionId; @NonNull - private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; - - @NonNull - private AutomationCompositionOrderedState orderedState = AutomationCompositionOrderedState.UNINITIALISED; - - @NonNull private DeployState deployState = DeployState.UNDEPLOYED; @NonNull @@ -66,8 +59,6 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut super(otherAutomationComposition); this.instanceId = otherAutomationComposition.instanceId; this.compositionId = otherAutomationComposition.compositionId; - this.state = otherAutomationComposition.state; - this.orderedState = otherAutomationComposition.orderedState; this.deployState = otherAutomationComposition.deployState; this.lockState = otherAutomationComposition.lockState; this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new); @@ -77,19 +68,4 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut public int compareTo(final AutomationComposition other) { return compareNameVersion(this, other); } - - /** - * Set the ordered state on the automation composition and on all its automation composition elements. - * - * @param orderedState the state we want the automation composition to transition to - */ - public void setCascadedOrderedState(final AutomationCompositionOrderedState orderedState) { - this.orderedState = orderedState; - - if (MapUtils.isEmpty(elements)) { - return; - } - - elements.values().forEach(element -> element.setOrderedState(orderedState)); - } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java index ab234f604..018031624 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java @@ -31,7 +31,6 @@ import lombok.ToString; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** * Class to represent a automation composition instance. @@ -50,19 +49,11 @@ public class AutomationCompositionElement { private UUID participantId = UUID.randomUUID(); @NonNull - private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; - - @NonNull private DeployState deployState = DeployState.UNDEPLOYED; @NonNull private LockState lockState = LockState.LOCKED; - @NonNull - private AutomationCompositionOrderedState orderedState = AutomationCompositionOrderedState.UNINITIALISED; - - private ToscaServiceTemplate toscaServiceTemplateFragment; - private String description; // A map indexed by the property name. Each map entry is the serialized value of the property, @@ -78,9 +69,6 @@ public class AutomationCompositionElement { this.id = otherElement.id; this.definition = new ToscaConceptIdentifier(otherElement.definition); this.participantId = otherElement.participantId; - this.state = otherElement.state; - this.orderedState = otherElement.orderedState; - this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment; this.description = otherElement.description; this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity()); this.deployState = otherElement.deployState; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java index 954665bfb..17875c429 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java @@ -35,8 +35,6 @@ public class AutomationCompositionInfo { private UUID automationCompositionId; - private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; - private DeployState deployState = DeployState.UNDEPLOYED; private LockState lockState = LockState.LOCKED; @@ -48,7 +46,6 @@ public class AutomationCompositionInfo { */ public AutomationCompositionInfo(final AutomationCompositionInfo otherElement) { this.automationCompositionId = otherElement.automationCompositionId; - this.state = otherElement.state; this.deployState = otherElement.deployState; this.lockState = otherElement.lockState; } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionOrderedState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionOrderedState.java deleted file mode 100644 index 3be5ffa2f..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionOrderedState.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============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.models.acm.concepts; - -public enum AutomationCompositionOrderedState { - /** - * The automation composition or automation composition element should become uninitialised on participants, it - * should not exist on participants. - */ - UNINITIALISED, - /** - * The automation composition or automation composition element should initialised on the participants and be - * passive, that is, it is not handling automation composition messages yet. - */ - PASSIVE, - /** - * The automation composition or automation composition element should running and is executing automation - * compositions. - */ - RUNNING; - - public boolean equalsAutomationCompositionState(final AutomationCompositionState automationCompositionState) { - return this.name().equals(automationCompositionState.name()); - } - - public AutomationCompositionState asState() { - return AutomationCompositionState.valueOf(this.name()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionState.java deleted file mode 100644 index aa6fcfd1d..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionState.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============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.models.acm.concepts; - -public enum AutomationCompositionState { - /** - * The automation composition or automation composition element is not initialised on participants, it does not - * exist on participants. - */ - UNINITIALISED, - /** - * The automation composition or automation composition element is changing from unitialised to passive, it is being - * initialised onto participants. - */ - UNINITIALISED2PASSIVE, - /** - * The automation composition or automation composition element is initialised on the participants but is passive, - * that is, it is not handling automation composition messages yet. - */ - PASSIVE, - /** - * The automation composition or automation composition element is changing from passive to running, the - * participants are preparing to execute automation compositions. - */ - PASSIVE2RUNNING, - /** - * The automation composition or automation composition element is running and is executing automation compositions. - */ - RUNNING, - /** - * The automation composition or automation composition element is completing execution of current automation - * compositions but will not start running any more automation compositions and will become passive. - */ - RUNNING2PASSIVE, - /** - * The automation composition or automation composition element is changing from passive to unitialised, the - * automation composition is being removed from participants. - */ - PASSIVE2UNINITIALISED; - - public boolean equalsAutomationCompositionOrderedState( - final AutomationCompositionOrderedState automationCompositionOrderedState) { - return this.name().equals(automationCompositionOrderedState.name()); - } - - public AutomationCompositionOrderedState asOrderedState() { - return AutomationCompositionOrderedState.valueOf(this.name()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDeploy.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDeploy.java index 337a09d17..7d3b4ca98 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDeploy.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDeploy.java @@ -40,9 +40,6 @@ public class ParticipantDeploy { private UUID participantId; - // List of AutomationCompositionElement values for a particular participant - private List<AutomationCompositionElement> automationCompositionElementList = new ArrayList<>(); - // List of Automation Composition Element Deploy for a particular participant private List<AcElementDeploy> acElementList = new ArrayList<>(); @@ -53,8 +50,6 @@ public class ParticipantDeploy { */ public ParticipantDeploy(final ParticipantDeploy copyConstructor) { this.participantId = copyConstructor.participantId; - this.automationCompositionElementList = PfUtils.mapList( - copyConstructor.automationCompositionElementList, AutomationCompositionElement::new); this.acElementList = PfUtils.mapList(copyConstructor.acElementList, AcElementDeploy::new); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java index 64102e607..2b4c9f996 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java @@ -23,8 +23,6 @@ package org.onap.policy.clamp.models.acm.messages.dmaap.participant; import lombok.Getter; import lombok.Setter; import lombok.ToString; -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.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; @@ -36,8 +34,6 @@ import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; @Setter @ToString(callSuper = true) public class AutomationCompositionStateChange extends ParticipantMessage { - private AutomationCompositionOrderedState orderedState; - private AutomationCompositionState currentState; private DeployOrder deployOrderedState = DeployOrder.NONE; private LockOrder lockOrderedState = LockOrder.NONE; private Integer startPhase; @@ -58,9 +54,6 @@ public class AutomationCompositionStateChange extends ParticipantMessage { */ public AutomationCompositionStateChange(AutomationCompositionStateChange source) { super(source); - - this.orderedState = source.orderedState; - this.currentState = source.currentState; this.deployOrderedState = source.deployOrderedState; this.lockOrderedState = source.lockOrderedState; this.startPhase = source.startPhase; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java index 65b72c436..25d72cb06 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java @@ -29,6 +29,8 @@ import javax.ws.rs.core.Response.Status; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; @@ -180,4 +182,19 @@ public class ParticipantProvider { return ProviderUtils.asEntityList(nodeTemplateStateRepository .findByParticipantId(participantId.toString())); } + + /** + * Reset the Deploy and Lock states of all the ac elements associated with a participant. + * + * @param participantId the participant id associated with the automation composition elements + */ + public void resetParticipantAcElementState(@NonNull final UUID participantId) { + var participantAcElementList = automationCompositionElementRepository + .findByParticipantId(participantId.toString()); + participantAcElementList.forEach(e -> { + e.setDeployState(DeployState.UNDEPLOYED); + e.setLockState(LockState.NONE); + }); + automationCompositionElementRepository.saveAll(participantAcElementList); + } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java index af29deb3f..35482b9bb 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -37,13 +37,13 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; -import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationResult; @@ -67,38 +67,6 @@ public final class AcmUtils { public static final String ENTRY = "entry "; /** - * Prepare participant updates map. - * - * @param acElement automation composition element - * @param participantUpdates list of participantUpdates - */ - public static void prepareParticipantUpdate(AutomationCompositionElement acElement, - List<ParticipantDeploy> participantUpdates) { - if (participantUpdates.isEmpty()) { - participantUpdates.add(getAutomationCompositionElementList(acElement)); - return; - } - - var participantExists = false; - for (ParticipantDeploy participantUpdate : participantUpdates) { - if (participantUpdate.getParticipantId().equals(acElement.getParticipantId())) { - participantUpdate.getAutomationCompositionElementList().add(acElement); - participantExists = true; - } - } - if (!participantExists) { - participantUpdates.add(getAutomationCompositionElementList(acElement)); - } - } - - private static ParticipantDeploy getAutomationCompositionElementList(AutomationCompositionElement acElement) { - var participantUpdate = new ParticipantDeploy(); - participantUpdate.setParticipantId(acElement.getParticipantId()); - participantUpdate.getAutomationCompositionElementList().add(acElement); - return participantUpdate; - } - - /** * Get the Policy information in the service template for the deploy message to participants. * * @param toscaServiceTemplate ToscaServiceTemplate @@ -196,7 +164,7 @@ public final class AcmUtils { public static List<Entry<String, ToscaNodeTemplate>> extractAcElementsFromServiceTemplate( ToscaServiceTemplate serviceTemplate) { return serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet().stream().filter( - nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), + nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), serviceTemplate)) .collect(Collectors.toList()); } @@ -309,7 +277,6 @@ public final class AcmUtils { // @formatter:on } - /** * Return true if DeployState and LockState are in a Transitional State. * @@ -321,6 +288,79 @@ public final class AcmUtils { } /** + * Get DeployOrder from transitional DeployState. + * + * @param deployState the Deploy State + * @return the DeployOrder + */ + public static DeployOrder stateDeployToOrder(DeployState deployState) { + if (DeployState.DEPLOYING.equals(deployState)) { + return DeployOrder.DEPLOY; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return DeployOrder.UNDEPLOY; + } + return DeployOrder.NONE; + } + + /** + * Get LockOrder from transitional LockState. + * + * @param lockState the Lock State + * @return the LockOrder + */ + public static LockOrder stateLockToOrder(LockState lockState) { + if (LockState.LOCKING.equals(lockState)) { + return LockOrder.LOCK; + } else if (LockState.UNLOCKING.equals(lockState)) { + return LockOrder.UNLOCK; + } + return LockOrder.NONE; + } + + /** + * Get final DeployState from transitional DeployState. + * + * @param deployState the DeployState + * @return the DeployState + */ + public static DeployState deployCompleted(DeployState deployState) { + if (DeployState.DEPLOYING.equals(deployState)) { + return DeployState.DEPLOYED; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return DeployState.UNDEPLOYED; + } + return deployState; + } + + /** + * Get final LockState from transitional LockState. + * + * @param lockState the LockState + * @return the LockState + */ + public static LockState lockCompleted(DeployState deployState, LockState lockState) { + if (LockState.LOCKING.equals(lockState) || DeployState.DEPLOYING.equals(deployState)) { + return LockState.LOCKED; + } else if (LockState.UNLOCKING.equals(lockState)) { + return LockState.UNLOCKED; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return LockState.NONE; + } + return lockState; + } + + /** + * Return true if transition states is Forward. + * + * @param deployState the DeployState + * @param lockState the LockState + * @return true if transition if Forward + */ + public static boolean isForward(DeployState deployState, LockState lockState) { + return DeployState.DEPLOYING.equals(deployState) || LockState.UNLOCKING.equals(lockState); + } + + /** * Set the states on the automation composition and on all its automation composition elements. * * @param deployState the DeployState we want the automation composition to transition to diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java index 9f235d6ac..e044a2f22 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java @@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -43,28 +42,13 @@ class AutomationCompositionElementTest { ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); ace1.setDescription("Description"); ace1.setId(UUID.randomUUID()); - ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); ace1.setParticipantId(CommonTestData.getParticipantId()); - ace1.setState(AutomationCompositionState.UNINITIALISED); var ace2 = new AutomationCompositionElement(ace1); assertEquals(ace1, ace2); } @Test - void testAutomationCompositionState() { - var ace0 = new AutomationCompositionElement(); - - assertTrue( - ace0.getOrderedState() - .equalsAutomationCompositionState(AutomationCompositionState.UNINITIALISED)); - - assertTrue( - ace0.getOrderedState().asState() - .equalsAutomationCompositionOrderedState(AutomationCompositionOrderedState.UNINITIALISED)); - } - - @Test void testAutomationCompositionElementLombok() { var ace0 = new AutomationCompositionElement(); @@ -78,9 +62,7 @@ class AutomationCompositionElementTest { ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); ace1.setDescription("Description"); ace1.setId(UUID.randomUUID()); - ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); ace1.setParticipantId(CommonTestData.getParticipantId()); - ace1.setState(AutomationCompositionState.UNINITIALISED); assertThat(ace1.toString()).contains("AutomationCompositionElement("); assertNotEquals(0, ace1.hashCode()); @@ -94,9 +76,7 @@ class AutomationCompositionElementTest { // @formatter:off assertThatThrownBy(() -> ace2.setDefinition(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> ace2.setId(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ace2.setOrderedState(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> ace2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ace2.setState(null)). isInstanceOf(NullPointerException.class); // @formatter:on assertNotEquals(ace2, ace0); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java index e32735f07..64dc6f792 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java @@ -60,8 +60,6 @@ class AutomationCompositionTest { ac1.setDescription("Description"); ac1.setElements(new LinkedHashMap<>()); ac1.setName("Name"); - ac1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - ac1.setState(AutomationCompositionState.UNINITIALISED); ac1.setVersion("0.0.1"); assertThat(ac1.toString()).contains("AutomationComposition("); @@ -76,20 +74,11 @@ class AutomationCompositionTest { // @formatter:off assertThatThrownBy(() -> ac2.setCompositionId(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ac2.setOrderedState(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ac2.setState(null)). isInstanceOf(NullPointerException.class); // @formatter:on assertEquals(ac2, ac0); - ac1.setCascadedOrderedState(AutomationCompositionOrderedState.PASSIVE); - assertEquals(AutomationCompositionOrderedState.PASSIVE, ac1.getOrderedState()); - ac1.getElements().put(UUID.randomUUID(), new AutomationCompositionElement()); - ac1.setCascadedOrderedState(AutomationCompositionOrderedState.RUNNING); - assertEquals(AutomationCompositionOrderedState.RUNNING, ac1.getOrderedState()); - assertEquals(AutomationCompositionOrderedState.RUNNING, - ac1.getElements().values().iterator().next().getOrderedState()); assertNull(ac0.getElements().get(UUID.randomUUID())); assertNull(ac1.getElements().get(UUID.randomUUID())); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java index 2912dee9b..3f64eadd5 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java @@ -30,9 +30,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; -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.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.utils.CommonTestData; import org.onap.policy.common.utils.coder.CoderException; @@ -55,16 +53,10 @@ class AutomationCompositionDeployTest { orig.setMessageId(UUID.randomUUID()); orig.setTimestamp(Instant.ofEpochMilli(3000)); - var acElement = new AutomationCompositionElement(); + var acElement = new AcElementDeploy(); acElement.setId(UUID.randomUUID()); var id = new ToscaConceptIdentifier("id", "1.2.3"); acElement.setDefinition(id); - acElement.setDescription("Description"); - acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - acElement.setState(AutomationCompositionState.PASSIVE); - - var participantId = CommonTestData.getParticipantId(); - acElement.setParticipantId(participantId); var property = new ToscaProperty(); property.setName("test"); @@ -75,8 +67,8 @@ class AutomationCompositionDeployTest { acElement.setProperties(propertiesMap); var participantDeploy = new ParticipantDeploy(); - participantDeploy.setParticipantId(participantId); - participantDeploy.setAutomationCompositionElementList(List.of(acElement)); + participantDeploy.setParticipantId(CommonTestData.getParticipantId()); + participantDeploy.setAcElementList(List.of(acElement)); orig.setParticipantUpdatesList(List.of(participantDeploy)); var other = new AutomationCompositionDeploy(orig); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java index 52e90b53a..968ad31bb 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java @@ -36,6 +36,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; @@ -57,6 +59,9 @@ class ParticipantProviderTest { private static final String AUTOMATION_COMPOSITION_JSON = "src/test/resources/providers/TestAutomationCompositions.json"; + private static final String AUTOMATION_COMPOSITION_JSON_DEREGISTER = + "src/test/resources/providers/TestAutomationCompositionsDeregister.json"; + private static final String NODE_TEMPLATE_STATE_JSON = "src/test/resources/providers/NodeTemplateState.json"; private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; private static final UUID INVALID_ID = UUID.randomUUID(); @@ -69,6 +74,10 @@ class ParticipantProviderTest { private List<JpaAutomationComposition> inputAutomationCompositionsJpa; private final String originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON); + private AutomationCompositions inputAutomationCompositionsDeregister; + private List<JpaAutomationComposition> inputAutomationCompositionsJpaDeregister; + private final String deregisterAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON_DEREGISTER); + private final String nodeTemplateStatesJson = ResourceUtils.getResourceAsString(NODE_TEMPLATE_STATE_JSON); private List<NodeTemplateState> nodeTemplateStateList = new ArrayList<>(); @@ -84,6 +93,11 @@ class ParticipantProviderTest { ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(), JpaAutomationComposition::new, "automation compositions"); + inputAutomationCompositionsDeregister = CODER.decode(deregisterAcJson, AutomationCompositions.class); + inputAutomationCompositionsJpaDeregister = + ProviderUtils.getJpaAndValidateList(inputAutomationCompositionsDeregister.getAutomationCompositionList(), + JpaAutomationComposition::new, "automation compositions"); + nodeTemplateStateList.add(CODER.decode(nodeTemplateStatesJson, NodeTemplateState.class)); nodeTemplateStateList.get(0).setState(AcTypeState.COMMISSIONED); jpaNodeTemplateStateList = ProviderUtils.getJpaAndValidateList(nodeTemplateStateList, @@ -238,8 +252,7 @@ class ParticipantProviderTest { assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null)); assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null)); assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null)); - - + assertThrows(NullPointerException.class, () -> participantProvider.resetParticipantAcElementState(null)); } @Test @@ -254,4 +267,32 @@ class ParticipantProviderTest { var result = participantProvider.getSupportedElementMap(); assertThat(result).hasSize(2); } + + @Test + void testResetParticipantAcElementState() { + var participantRepository = mock(ParticipantRepository.class); + var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class); + + var acElementList = inputAutomationCompositionsJpaDeregister + .stream().map(c -> c.getElements()).collect(Collectors.toList()); + + when(automationCompositionElementRepository.findByParticipantId(any())).thenReturn(acElementList.get(0)); + + var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class); + var participantProvider = new ParticipantProvider(participantRepository, + automationCompositionElementRepository, nodeTemplateStateRepository); + + acElementList.get(0).stream().forEach(e -> { + assertThat(e.getDeployState().equals(DeployState.DEPLOYED)); + assertThat(e.getLockState().equals(LockState.LOCKED)); + }); + + participantProvider.resetParticipantAcElementState(UUID.randomUUID()); + + acElementList.get(0).stream().forEach(e -> { + assertThat(e.getDeployState().equals(DeployState.UNDEPLOYED)); + assertThat(e.getLockState().equals(LockState.NONE)); + }); + + } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java index c16beaf87..b332d7d44 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java @@ -24,13 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -41,8 +40,9 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; @@ -69,25 +69,6 @@ class AcmUtilsTest { } @Test - void testCommonUtilsParticipantUpdate() { - var acElement = new AutomationCompositionElement(); - List<ParticipantDeploy> participantUpdates = new ArrayList<>(); - assertThat(participantUpdates).isEmpty(); - - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - assertThat(participantUpdates).isNotEmpty(); - assertEquals(acElement, participantUpdates.get(0).getAutomationCompositionElementList().get(0)); - - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - var participantId = CommonTestData.getParticipantId(); - assertNotEquals(participantId, participantUpdates.get(0).getParticipantId()); - - acElement.setParticipantId(participantId); - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - assertEquals(participantId, participantUpdates.get(1).getParticipantId()); - } - - @Test void testCheckIfNodeTemplateIsAutomationCompositionElement() { var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML); var nodeTemplate = new ToscaNodeTemplate(); @@ -109,12 +90,12 @@ class AcmUtilsTest { Map<ToscaConceptIdentifier, UUID> map = new HashMap<>(); var participantId = UUID.randomUUID(); assertThatThrownBy(() -> AcmUtils.prepareParticipantPriming(acElements, map)).hasMessageMatching( - "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.1 not supported"); - map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"), + "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.0 not supported"); + map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"), participantId); map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", - "1.0.1"), participantId); - map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"), + "1.0.0"), participantId); + map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"), participantId); var result = AcmUtils.prepareParticipantPriming(acElements, map); assertThat(result).isNotEmpty().hasSize(1); @@ -159,6 +140,47 @@ class AcmUtilsTest { assertFalse(result.isValid()); } + @Test + void testStateDeployToOrder() { + // from transitional state to order state + assertEquals(DeployOrder.DEPLOY, AcmUtils.stateDeployToOrder(DeployState.DEPLOYING)); + assertEquals(DeployOrder.UNDEPLOY, AcmUtils.stateDeployToOrder(DeployState.UNDEPLOYING)); + assertEquals(DeployOrder.NONE, AcmUtils.stateDeployToOrder(DeployState.DEPLOYED)); + } + + @Test + void testStateLockToOrder() { + // from transitional state to order state + assertEquals(LockOrder.LOCK, AcmUtils.stateLockToOrder(LockState.LOCKING)); + assertEquals(LockOrder.UNLOCK, AcmUtils.stateLockToOrder(LockState.UNLOCKING)); + assertEquals(LockOrder.NONE, AcmUtils.stateLockToOrder(LockState.NONE)); + } + + @Test + void testDeployCompleted() { + // from transitional state to final state + assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYING)); + assertEquals(DeployState.UNDEPLOYED, AcmUtils.deployCompleted(DeployState.UNDEPLOYING)); + assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYED)); + } + + @Test + void testLockCompleted() { + // from transitional state to final state + assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYING, LockState.NONE)); + assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.LOCKING)); + assertEquals(LockState.UNLOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.UNLOCKING)); + assertEquals(LockState.NONE, AcmUtils.lockCompleted(DeployState.UNDEPLOYING, LockState.LOCKED)); + } + + @Test + void testIsForward() { + assertTrue(AcmUtils.isForward(DeployState.DEPLOYING, LockState.NONE)); + assertTrue(AcmUtils.isForward(DeployState.DEPLOYED, LockState.UNLOCKING)); + assertFalse(AcmUtils.isForward(DeployState.DEPLOYED, LockState.LOCKING)); + assertFalse(AcmUtils.isForward(DeployState.UNDEPLOYING, LockState.LOCKED)); + } + private AutomationComposition getDummyAutomationComposition() { var automationComposition = new AutomationComposition(); automationComposition.setCompositionId(UUID.randomUUID()); diff --git a/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml b/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml index 595755a03..2b0b4feff 100644 --- a/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml +++ b/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml @@ -356,7 +356,7 @@ node_types: entry_schema: type: org.onap.datatypes.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElementConsulInfo org.onap.policy.clamp.acm.PolicyAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: policy_type_id: @@ -632,7 +632,7 @@ topology_template: org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement: version: 1.2.3 type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the monitoring policy for Performance Management Subscription Handling properties: provider: Ericsson @@ -644,7 +644,7 @@ topology_template: org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement: version: 1.2.3 type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the operational policy for Performance Management Subscription Handling properties: provider: Ericsson diff --git a/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json b/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json new file mode 100644 index 000000000..0da9cdeef --- /dev/null +++ b/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json @@ -0,0 +1,55 @@ +{ + "automationCompositionList": [ + { + "compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c40", + "instanceId": "809c62b3-8918-41b9-a748-e21eb79c6c89", + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "elements": { + "709c62b3-8918-41b9-a747-e21eb79c6c20": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c20", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "DCAE automation composition element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c21": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c21", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "Monitoring Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c22": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c22", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "Operational Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c23": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c23", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "CDS automation composition element for the PMSH instance 0 automation composition" + } + }, + "name": "PMSHInstance0", + "version": "1.0.1", + "description": "PMSH automation composition instance 0" + } + ] +} diff --git a/packages/policy-clamp-docker/pom.xml b/packages/policy-clamp-docker/pom.xml index 1b9b5e1fd..3c74a1c34 100755 --- a/packages/policy-clamp-docker/pom.xml +++ b/packages/policy-clamp-docker/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2022 Nordix Foundation. + Copyright (C) 2021-2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -92,7 +92,6 @@ <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>groovy-maven-plugin</artifactId> - <version>2.1.1</version> <executions> <execution> <phase>validate</phase> diff --git a/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile index 9f393107c..ff08d8ee1 100755 --- a/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation. +# Copyright (C) 2021-2023 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ ARG POLICY_LOGS=/var/log/onap/policy/a1pms-participant ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/clamp +USER root RUN mkdir -p $POLICY_LOGS $POLICY_HOME && \ chown -R policy:policy $POLICY_HOME $POLICY_LOGS diff --git a/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile b/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile index 3f36f3d36..c77f48b5d 100644 --- a/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation. +# Copyright (C) 2021-2023 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ ARG POLICY_LOGS=/var/log/onap/policy/policy-clamp-runtime-acm ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/clamp +USER root RUN mkdir -p $POLICY_HOME $POLICY_LOGS && \ chown -R policy:policy $POLICY_HOME $POLICY_LOGS diff --git a/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile index 0a92cee2e..adfa00d59 100644 --- a/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # ============LICENSE_START======================================================= -# Copyright (C) 2022 Nordix Foundation. +# Copyright (C) 2022-2023 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ ARG POLICY_LOGS=/var/log/onap/policy/element-participant ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/clamp +USER root RUN mkdir -p $POLICY_LOGS $POLICY_HOME && \ chown -R policy:policy $POLICY_HOME $POLICY_LOGS diff --git a/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile index 17dccaa1d..720927bfc 100644 --- a/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation. +# Copyright (C) 2021-2023 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ ARG POLICY_LOGS=/var/log/onap/policy/http-participant ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/clamp +USER root RUN mkdir -p $POLICY_LOGS $POLICY_HOME && \ chown -R policy:policy $POLICY_HOME $POLICY_LOGS diff --git a/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile index 1395a678c..72250e8af 100644 --- a/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation. +# Copyright (C) 2021-2023 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ ARG POLICY_LOGS=/var/log/onap/policy/k8s-participant ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/clamp +USER root RUN mkdir -p $POLICY_HOME $POLICY_LOGS && \ chown -R policy:policy $POLICY_HOME $POLICY_LOGS diff --git a/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile index fe08785e6..c82754b17 100644 --- a/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation. +# Copyright (C) 2021-2023 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ ARG POLICY_LOGS=/var/log/onap/policy/pf-participant ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/clamp +USER root RUN mkdir -p $POLICY_HOME $POLICY_LOGS && \ chown -R policy:policy $POLICY_HOME $POLICY_LOGS diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml index a924ec18b..ddb4b9224 100755 --- a/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml @@ -42,9 +42,6 @@ participant: - typeName: org.onap.policy.clamp.acm.A1PMSAutomationCompositionElement typeVersion: 1.0.1 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 management: endpoints: diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml index 8b3061ee6..ed5fbbed8 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml @@ -35,9 +35,6 @@ participant: - typeName: org.onap.policy.clamp.acm.HttpAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 management: endpoints: diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml index 0fb7cf5ce..89a42d069 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml @@ -40,9 +40,6 @@ participant: - typeName: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 management: endpoints: diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml index 7ac11f2e3..8b7e5440c 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml @@ -53,9 +53,6 @@ participant: - typeName: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 management: endpoints: diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-a1pms/src/main/resources/config/application.yaml index 417159671..efa2a6e9e 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-a1pms/src/main/resources/config/application.yaml @@ -42,9 +42,6 @@ participant: - typeName: org.onap.policy.clamp.acm.A1PMSAutomationCompositionElement typeVersion: 1.0.1 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 management: endpoints: diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-a1pms/src/test/resources/application-test.yaml index cd3a54e78..4a179d11a 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/test/resources/application-test.yaml +++ b/participant/participant-impl/participant-impl-a1pms/src/test/resources/application-test.yaml @@ -21,6 +21,3 @@ participant: - typeName: org.onap.policy.clamp.acm.A1PMSAutomationCompositionElement typeVersion: 1.0.1 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 diff --git a/participant/participant-impl/participant-impl-acelement/pom.xml b/participant/participant-impl/participant-impl-acelement/pom.xml index 3424c6d87..ed2d5bae4 100644 --- a/participant/participant-impl/participant-impl-acelement/pom.xml +++ b/participant/participant-impl/participant-impl-acelement/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2022 Nordix Foundation. + Copyright (C) 2021-2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -38,7 +38,6 @@ <plugin> <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> - <version>${version.swagger.codegen.v3}</version> <executions> <execution> <id>code-gen</id> diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java index c62216dfc..0568d3b98 100644 --- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java @@ -31,7 +31,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; import javax.validation.Validation; -import javax.validation.ValidationException; +import javax.ws.rs.core.Response.Status; +import lombok.RequiredArgsConstructor; import lombok.Setter; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest; @@ -55,6 +56,7 @@ import org.springframework.stereotype.Component; * This class handles implementation of automationCompositionElement updates. */ @Component +@RequiredArgsConstructor public class AutomationCompositionElementHandler implements AutomationCompositionElementListener, Closeable { private static final Coder CODER = new StandardCoder(); @@ -63,22 +65,20 @@ public class AutomationCompositionElementHandler implements AutomationCompositio private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - private final Map<ToscaConceptIdentifier, Pair<Integer, String>> restResponseMap = new ConcurrentHashMap<>(); - @Setter private ParticipantIntermediaryApi intermediaryApi; + private final AcHttpClient acHttpClient; + /** * Handle a automation composition element state change. * * @param automationCompositionElementId the ID of the automation composition element - * @throws PfModelException in case of a model exception */ @Override - public void undeploy(UUID automationCompositionId, - UUID automationCompositionElementId) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE); + public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) { + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, automationCompositionElementId, + DeployState.UNDEPLOYED, LockState.NONE); } /** @@ -87,31 +87,36 @@ public class AutomationCompositionElementHandler implements AutomationCompositio * @param automationCompositionId the automationComposition Id * @param element the information on the automation composition element * @param properties properties Map + * @throws PfModelException in case of a exception */ @Override - public void deploy(UUID automationCompositionId, - AcElementDeploy element, Map<String, Object> properties) { + public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException { + var configRequest = getConfigRequest(properties); + var restResponseMap = invokeHttpClient(configRequest); + var failedResponseStatus = restResponseMap.values().stream() + .filter(response -> !HttpStatus.valueOf(response.getKey()).is2xxSuccessful()) + .collect(Collectors.toList()); + if (failedResponseStatus.isEmpty()) { + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), + DeployState.DEPLOYED, LockState.LOCKED); + } else { + throw new PfModelException(Status.BAD_REQUEST, "Error on Invoking the http request: {}", + failedResponseStatus); + } + } + + private ConfigRequest getConfigRequest(Map<String, Object> properties) throws PfModelException { try { var configRequest = CODER.convert(properties, ConfigRequest.class); - var violations = - Validation.buildDefaultValidatorFactory().getValidator().validate(configRequest); - if (violations.isEmpty()) { - invokeHttpClient(configRequest); - var failedResponseStatus = restResponseMap.values().stream() - .filter(response -> !HttpStatus.valueOf(response.getKey()) - .is2xxSuccessful()).collect(Collectors.toList()); - if (failedResponseStatus.isEmpty()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, LockState.LOCKED); - } else { - LOGGER.error("Error on Invoking the http request: {}", failedResponseStatus); - } - } else { + var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configRequest); + if (!violations.isEmpty()) { LOGGER.error("Violations found in the config request parameters: {}", violations); - throw new ValidationException("Constraint violations in the config request"); + throw new PfModelException(Status.BAD_REQUEST, "Constraint violations in the config request"); } - } catch (CoderException | ValidationException | InterruptedException | ExecutionException e) { - LOGGER.error("Error invoking the http request for the config ", e); + return configRequest; + } catch (CoderException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error extracting ConfigRequest ", e); } } @@ -120,11 +125,21 @@ public class AutomationCompositionElementHandler implements AutomationCompositio * * @param configRequest ConfigRequest */ - public void invokeHttpClient(ConfigRequest configRequest) throws ExecutionException, InterruptedException { - // Invoke runnable thread to execute https requests of all config entities - var result = executor.submit(new AcHttpClient(configRequest, restResponseMap), restResponseMap); - if (!result.get().isEmpty()) { - LOGGER.debug("Http Request Completed: {}", result.isDone()); + private Map<ToscaConceptIdentifier, Pair<Integer, String>> invokeHttpClient(ConfigRequest configRequest) + throws PfModelException { + try { + Map<ToscaConceptIdentifier, Pair<Integer, String>> restResponseMap = new ConcurrentHashMap<>(); + // Invoke runnable thread to execute https requests of all config entities + var result = executor.submit(() -> acHttpClient.run(configRequest, restResponseMap), restResponseMap); + if (!result.get().isEmpty()) { + LOGGER.debug("Http Request Completed: {}", result.isDone()); + } + return restResponseMap; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new PfModelException(Status.BAD_REQUEST, "Error invoking ExecutorService ", e); + } catch (ExecutionException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error invoking the http request for the config ", e); } } diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java index 563daecd9..c71d73f22 100644 --- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java +++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021,2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,83 +35,69 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.util.UriComponentsBuilder; import reactor.core.publisher.Mono; -public class AcHttpClient implements Runnable { +@Component +public class AcHttpClient { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final ConfigRequest configRequest; - - private Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap; - - /** - * Constructor. - */ - public AcHttpClient(ConfigRequest configRequest, Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap) { - this.configRequest = configRequest; - this.responseMap = responseMap; - } - /** * Runnable to execute http requests. */ - @Override - public void run() { + public void run(ConfigRequest configRequest, Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap) { - var webClient = WebClient.builder() - .baseUrl(configRequest.getBaseUrl()) - .defaultHeaders(httpHeaders -> httpHeaders.addAll(createHeaders(configRequest))) - .build(); + var webClient = WebClient.builder().baseUrl(configRequest.getBaseUrl()) + .defaultHeaders(httpHeaders -> httpHeaders.addAll(createHeaders(configRequest))).build(); - for (ConfigurationEntity configurationEntity : configRequest.getConfigurationEntities()) { + for (var configurationEntity : configRequest.getConfigurationEntities()) { LOGGER.info("Executing http requests for the config entity {}", - configurationEntity.getConfigurationEntityId()); + configurationEntity.getConfigurationEntityId()); - executeRequest(webClient, configurationEntity); + executeRequest(webClient, configRequest, configurationEntity, responseMap); } } - private void executeRequest(WebClient client, ConfigurationEntity configurationEntity) { + private void executeRequest(WebClient client, ConfigRequest configRequest, ConfigurationEntity configurationEntity, + Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap) { // Iterate the sequence of http requests - for (RestParams request: configurationEntity.getRestSequence()) { - String response = null; + for (var request : configurationEntity.getRestSequence()) { try { var httpMethod = Objects.requireNonNull(HttpMethod.resolve(request.getHttpMethod())); var uri = createUriString(request); LOGGER.info("Executing HTTP request: {} for the Rest request id: {}", httpMethod, request.getRestRequestId()); - response = client.method(httpMethod) - .uri(uri) - .body(request.getBody() == null ? BodyInserters.empty() - : BodyInserters.fromValue(request.getBody())) - .exchangeToMono(clientResponse -> - clientResponse.statusCode().value() == request.getExpectedResponse() - ? clientResponse.bodyToMono(String.class) - : Mono.error(new HttpWebClientException(clientResponse.statusCode().value(), - clientResponse.bodyToMono(String.class).toString()))) - .block(Duration.ofMillis(configRequest.getUninitializedToPassiveTimeout() * 1000L)); + var response = client.method(httpMethod).uri(uri) + .body(request.getBody() == null ? BodyInserters.empty() + : BodyInserters.fromValue(request.getBody())) + .exchangeToMono( + clientResponse -> clientResponse.statusCode().value() == request.getExpectedResponse() + ? clientResponse.bodyToMono(String.class) + : Mono.error(new HttpWebClientException(clientResponse.statusCode().value(), + clientResponse.bodyToMono(String.class).toString()))) + .block(Duration.ofMillis(configRequest.getUninitializedToPassiveTimeout() * 1000L)); LOGGER.info("HTTP response for the {} request : {}", httpMethod, response); - responseMap.put(request.getRestRequestId(), new ImmutablePair<>(request.getExpectedResponse(), - response)); + responseMap.put(request.getRestRequestId(), + new ImmutablePair<>(request.getExpectedResponse(), response)); } catch (HttpWebClientException ex) { LOGGER.error("Error occurred on the HTTP request ", ex); - responseMap.put(request.getRestRequestId(), new ImmutablePair<>(ex.getStatusCode().value(), - ex.getResponseBodyAsString())); + responseMap.put(request.getRestRequestId(), + new ImmutablePair<>(ex.getStatusCode().value(), ex.getResponseBodyAsString())); } } } private HttpHeaders createHeaders(ConfigRequest request) { var headers = new HttpHeaders(); - for (Map.Entry<String, String> entry: request.getHttpHeaders().entrySet()) { + for (var entry : request.getHttpHeaders().entrySet()) { headers.add(entry.getKey(), entry.getValue()); } return headers; @@ -125,7 +111,7 @@ public class AcHttpClient implements Runnable { } // Add query params if present if (restParams.getQueryParams() != null) { - for (Map.Entry<String, String> entry : restParams.getQueryParams().entrySet()) { + for (var entry : restParams.getQueryParams().entrySet()) { uriComponentsBuilder.queryParam(entry.getKey(), entry.getValue()); } } diff --git a/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml index 68905c36d..791299545 100644 --- a/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml @@ -33,9 +33,7 @@ participant: - typeName: org.onap.policy.clamp.acm.HttpAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 + management: endpoints: web: diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java index 857490ef5..e48fdf91c 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java @@ -20,76 +20,78 @@ package org.onap.policy.clamp.acm.participant.http.handler; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import java.io.IOException; import java.util.HashMap; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; +import java.util.Map; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mockito; -import org.mockito.Spy; import org.onap.policy.clamp.acm.participant.http.main.handler.AutomationCompositionElementHandler; import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest; +import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient; import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData; import org.onap.policy.clamp.acm.participant.http.utils.ToscaUtils; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; -@ExtendWith(SpringExtension.class) class AcElementHandlerTest { - @InjectMocks - @Spy - private AutomationCompositionElementHandler automationCompositionElementHandler = - new AutomationCompositionElementHandler(); - private final CommonTestData commonTestData = new CommonTestData(); - - private static ToscaServiceTemplate serviceTemplate; private static final String HTTP_AUTOMATION_COMPOSITION_ELEMENT = "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"; - @BeforeAll - static void init() { - serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca(); - } - - @BeforeEach - void startMocks() { - automationCompositionElementHandler.setIntermediaryApi(Mockito.mock(ParticipantIntermediaryApi.class)); + @Test + void testUndeploy() throws IOException { + var instanceId = commonTestData.getAutomationCompositionId(); + var element = commonTestData.getAutomationCompositionElement(); + var acElementId = element.getId(); + + try (var automationCompositionElementHandler = + new AutomationCompositionElementHandler(mock(AcHttpClient.class))) { + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi); + automationCompositionElementHandler.undeploy(instanceId, acElementId); + verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId, + DeployState.UNDEPLOYED, LockState.NONE); + } } @Test - void test_automationCompositionElementStateChange() throws IOException { - var automationCompositionId = commonTestData.getAutomationCompositionId(); + void testDeployError() throws IOException { + var instanceId = commonTestData.getAutomationCompositionId(); var element = commonTestData.getAutomationCompositionElement(); - var automationCompositionElementId = element.getId(); - var config = Mockito.mock(ConfigRequest.class); - assertDoesNotThrow(() -> automationCompositionElementHandler.invokeHttpClient(config)); - - assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy( - automationCompositionId, automationCompositionElementId)); - - automationCompositionElementHandler.close(); + try (var automationCompositionElementHandler = + new AutomationCompositionElementHandler(mock(AcHttpClient.class))) { + automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class)); + Map<String, Object> map = new HashMap<>(); + assertThatThrownBy(() -> automationCompositionElementHandler.deploy(instanceId, element, map)) + .hasMessage("Constraint violations in the config request"); + } } @Test - void test_AutomationCompositionElementUpdate() throws Exception { - doNothing().when(automationCompositionElementHandler).invokeHttpClient(any()); - var element = commonTestData.getAutomationCompositionElement(); - + void testDeploy() throws Exception { + var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca(); var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); + var element = commonTestData.getAutomationCompositionElement(); map.putAll(element.getProperties()); + var instanceId = commonTestData.getAutomationCompositionId(); + var acHttpClient = mock(AcHttpClient.class); + try (var automationCompositionElementHandler = new AutomationCompositionElementHandler(acHttpClient)) { + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi); + automationCompositionElementHandler.deploy(instanceId, element, map); + verify(acHttpClient).run(any(ConfigRequest.class), anyMap()); + verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.DEPLOYED, LockState.LOCKED); + } - assertDoesNotThrow(() -> automationCompositionElementHandler - .deploy(commonTestData.getAutomationCompositionId(), element, map)); } } diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java index 3ddd7b17c..d8e0c9b58 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,8 +78,8 @@ class AcHttpClientTest { var configRequest = new ConfigRequest(testMockUrl + ":" + mockServerPort, headers, List.of(configurationEntity), 10); - var client = new AcHttpClient(configRequest, responseMap); - assertDoesNotThrow(client::run); + var client = new AcHttpClient(); + assertDoesNotThrow(() -> client.run(configRequest, responseMap)); assertThat(responseMap).hasSize(2).containsKey(commonTestData.restParamsWithGet().getRestRequestId()); var restResponseMap = responseMap.get(commonTestData.restParamsWithGet().getRestRequestId()); @@ -96,8 +96,8 @@ class AcHttpClientTest { var configRequest = new ConfigRequest(testMockUrl + ":" + mockServerPort, headers, List.of(configurationEntity), 10); - var client = new AcHttpClient(configRequest, responseMap); - assertDoesNotThrow(client::run); + var client = new AcHttpClient(); + assertDoesNotThrow(() -> client.run(configRequest, responseMap)); assertThat(responseMap).hasSize(2).containsKey(commonTestData.restParamsWithGet().getRestRequestId()); var response = responseMap.get(commonTestData.restParamsWithInvalidPost().getRestRequestId()); assertThat(response.getKey()).isEqualTo(404); diff --git a/participant/participant-impl/participant-impl-http/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-http/src/test/resources/application-test.yaml index 000ebc7a6..c77c2db23 100644 --- a/participant/participant-impl/participant-impl-http/src/test/resources/application-test.yaml +++ b/participant/participant-impl/participant-impl-http/src/test/resources/application-test.yaml @@ -20,5 +20,3 @@ participant: participantSupportedElementTypes: - typeName: org.onap.policy.clamp.acm.HttpAutomationCompositionElement typeVersion: 1.0.0 - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 diff --git a/participant/participant-impl/participant-impl-kubernetes/pom.xml b/participant/participant-impl/participant-impl-kubernetes/pom.xml index 503816e5f..b3c880273 100644 --- a/participant/participant-impl/participant-impl-kubernetes/pom.xml +++ b/participant/participant-impl/participant-impl-kubernetes/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021 Nordix Foundation. + Copyright (C) 2021,2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -54,7 +54,6 @@ <plugin> <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> - <version>${version.swagger.codegen.v3}</version> <executions> <execution> <id>code-gen</id> 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 9642b40e6..d032d3512 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 @@ -38,9 +38,6 @@ participant: - typeName: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 management: endpoints: diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-kubernetes/src/test/resources/application-test.yaml index d8e4cb075..8d27aa93e 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/resources/application-test.yaml +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/resources/application-test.yaml @@ -28,6 +28,3 @@ participant: - typeName: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 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 37391f116..6b0eed116 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 @@ -51,9 +51,6 @@ participant: - typeName: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 management: endpoints: diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-policy/src/test/resources/application-test.yaml index d9051c2cf..6c78c07dc 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/application-test.yaml +++ b/participant/participant-impl/participant-impl-policy/src/test/resources/application-test.yaml @@ -21,6 +21,3 @@ participant: - typeName: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement typeVersion: 1.0.0 - - - typeName: org.onap.policy.clamp.acm.AutomationCompositionElement - typeVersion: 1.0.0 diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java index 2d845d4c8..d76700171 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java @@ -333,6 +333,7 @@ public class AutomationCompositionHandler { for (var element : participantDeploy.getAcElementList()) { var acElement = new AutomationCompositionElement(); acElement.setId(element.getId()); + acElement.setParticipantId(participantDeploy.getParticipantId()); acElement.setDefinition(element.getDefinition()); acElement.setDeployState(DeployState.DEPLOYING); acElement.setLockState(LockState.NONE); diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java index 719c428be..ff967791d 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java @@ -31,6 +31,7 @@ import java.util.UUID; import lombok.Getter; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; @@ -48,6 +49,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRe import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq; +import org.onap.policy.models.base.PfModelException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -170,8 +172,33 @@ public class ParticipantHandler { public void sendParticipantDeregister() { var participantDeregister = new ParticipantDeregister(); participantDeregister.setParticipantId(participantId); - publisher.sendParticipantDeregister(participantDeregister); + undeployInstancesOnParticipant(); + } + + private void undeployInstancesOnParticipant() { + automationCompositionHandler.getAutomationCompositionMap().values().forEach(ac -> + undeployInstanceOnParticipant(ac) + ); + } + + private void undeployInstanceOnParticipant(AutomationComposition automationComposition) { + automationComposition.getElements().values().forEach(element -> { + if (element.getParticipantId().equals(participantId)) { + undeployInstanceElementsOnParticipant(automationComposition.getInstanceId(), element.getId()); + } + }); + } + + private void undeployInstanceElementsOnParticipant(UUID instanceId, UUID elementId) { + var acElementListeners = automationCompositionHandler.getListeners(); + for (var acElementListener : acElementListeners) { + try { + acElementListener.undeploy(instanceId, elementId); + } catch (PfModelException e) { + LOGGER.debug("Automation composition element update failed {}", instanceId); + } + } } /** diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java new file mode 100644 index 000000000..b88ea03e5 --- /dev/null +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.acm.participant.intermediary.handler; + +import java.util.Map; +import java.util.UUID; +import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; +import org.onap.policy.models.base.PfModelException; + +public class DummyAcElementListener implements AutomationCompositionElementListener { + @Override + public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { + + } + + @Override + public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException { + + } +} diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java index 7349ab9c0..3fed5bb56 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java @@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.time.Instant; import java.util.List; @@ -37,11 +38,13 @@ import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessag import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantAckMessage; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.base.PfModelException; class ParticipantHandlerTest { @@ -131,4 +134,25 @@ class ParticipantHandlerTest { participantHandler.handleParticipantRegisterAck(new ParticipantRegisterAck()); verify(publisher).sendParticipantStatus(any()); } + + @Test + void testSendParticipantDeregister() throws PfModelException { + var commonTestData = new CommonTestData(); + var automationCompositionMap = commonTestData.getTestAutomationCompositionMap(); + var automationCompositionHandler = mock(AutomationCompositionHandler.class); + var listener = mock(DummyAcElementListener.class); + + when(automationCompositionHandler.getListeners()).thenReturn(List.of(listener)); + automationCompositionMap.values().iterator().next().getElements().values().iterator().next() + .setParticipantId(CommonTestData.getParticipantId()); + when(automationCompositionHandler.getAutomationCompositionMap()).thenReturn(automationCompositionMap); + + var publisher = mock(ParticipantMessagePublisher.class); + var parameters = CommonTestData.getParticipantParameters(); + var participantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHandler); + + participantHandler.sendParticipantDeregister(); + verify(publisher).sendParticipantDeregister(any(ParticipantDeregister.class)); + verify(listener).undeploy(any(), any()); + } } diff --git a/participant/pom.xml b/participant/pom.xml index 81e8ee274..12d2ff558 100644 --- a/participant/pom.xml +++ b/participant/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021 Nordix Foundation. + Copyright (C) 2021,2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -106,7 +106,6 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> - <version>1.7.0</version> <configuration> <resourceBundles> <resourceBundle>org.onap.policy.clamp:policy-clamp-examples:${project.version}</resourceBundle> @@ -15,24 +15,23 @@ limitations under the License. ============LICENSE_END========================================================= --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> <groupId>org.onap.policy.parent</groupId> <artifactId>integration</artifactId> <version>3.7.1-SNAPSHOT</version> <relativePath /> </parent> - <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> <version>6.4.1-SNAPSHOT</version> <name>${project.artifactId}</name> - <packaging>pom</packaging> - <description> This is the root Maven module for the policy-clamp project. @@ -51,12 +50,10 @@ o policy-clamp-participant-impl-a1pms: A standard participant for accessing A1-Policy Management Service o policy-clamp-participant-impl-kserve: A standard participant for Kserve </description> - <properties> <policy.common.version>1.12.1-SNAPSHOT</policy.common.version> <policy.models.version>2.8.1-SNAPSHOT</policy.models.version> </properties> - <modules> <module>common</module> <module>examples</module> @@ -65,7 +62,6 @@ <module>runtime-acm</module> <module>participant</module> </modules> - <dependencies> <dependency> <groupId>junit</groupId> @@ -75,7 +71,7 @@ <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> - <version>5.7.1</version> + <version>${version.junit.jupiter}</version> <scope>test</scope> </dependency> <dependency> diff --git a/runtime-acm/pom.xml b/runtime-acm/pom.xml index efc13f37c..e5f223749 100644 --- a/runtime-acm/pom.xml +++ b/runtime-acm/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2022 Nordix Foundation. + Copyright (C) 2021-2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -55,7 +55,6 @@ <plugin> <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> - <version>3.0.27</version> <executions> <execution> <id>code-gen</id> @@ -97,7 +96,6 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> - <version>1.7.0</version> <configuration> <resourceBundles> <resourceBundle>org.onap.policy.clamp:policy-clamp-examples:${project.version}</resourceBundle> diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java index 3e79e78c1..5fcb3837f 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java @@ -79,7 +79,7 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYING, LockState.NONE); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.undeploy(automationComposition, startPhase, true); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); } /** @@ -92,7 +92,7 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.UNLOCKING); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.unlock(automationComposition, startPhase, true); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); } /** @@ -105,7 +105,7 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKING); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.lock(automationComposition, startPhase, true); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); } /** diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java index 8d1f98388..ef50a633e 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java @@ -43,6 +43,7 @@ public class SupervisionAspect implements Closeable { private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionAspect.class); private final SupervisionScanner supervisionScanner; + private final SupervisionPartecipantScanner partecipantScanner; private ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); @@ -52,7 +53,12 @@ public class SupervisionAspect implements Closeable { initialDelayString = "${runtime.participantParameters.heartBeatMs}") public void schedule() { LOGGER.info("Add scheduled scanning"); - executor.execute(() -> supervisionScanner.run(true)); + executor.execute(this::executeScan); + } + + private void executeScan() { + supervisionScanner.run(true); + partecipantScanner.run(); } /** @@ -68,7 +74,7 @@ public class SupervisionAspect implements Closeable { @Before("@annotation(MessageIntercept) && args(participantStatusMessage,..)") public void handleParticipantStatus(ParticipantStatus participantStatusMessage) { - executor.execute(() -> supervisionScanner.handleParticipantStatus(participantStatusMessage.getParticipantId())); + executor.execute(() -> partecipantScanner.handleParticipantStatus(participantStatusMessage.getParticipantId())); } @Override diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java new file mode 100644 index 000000000..b396e629c --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.acm.runtime.supervision; + +import java.util.UUID; +import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * This class is used to scan the automation compositions in the database and check if they are in the correct state. + */ +@Component +public class SupervisionPartecipantScanner { + private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class); + + private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>(); + + private final ParticipantProvider participantProvider; + + /** + * Constructor for instantiating SupervisionPartecipantScanner. + * + * @param participantProvider the Participant Provider + * @param acRuntimeParameterGroup the parameters for the automation composition runtime + */ + public SupervisionPartecipantScanner( + final ParticipantProvider participantProvider, + final AcRuntimeParameterGroup acRuntimeParameterGroup) { + this.participantProvider = participantProvider; + + participantStatusCounter.setMaxRetryCount( + acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); + participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); + } + + /** + * Run Scanning. + */ + public void run() { + LOGGER.debug("Scanning participans in the database . . ."); + + for (var participant : participantProvider.getParticipants()) { + scanParticipantStatus(participant); + } + + LOGGER.debug("Participans scan complete . . ."); + } + + private void scanParticipantStatus(Participant participant) { + var id = participant.getParticipantId(); + if (participantStatusCounter.isFault(id)) { + LOGGER.debug("report Participant fault"); + return; + } + if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs() + && !participantStatusCounter.count(id)) { + LOGGER.debug("report Participant fault"); + participantStatusCounter.setFault(id); + participant.setParticipantState(ParticipantState.OFF_LINE); + participantProvider.updateParticipant(participant); + } + } + + /** + * handle participant Status message. + */ + public void handleParticipantStatus(UUID id) { + participantStatusCounter.clear(id); + } +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java index 75fed71e0..6cf75ccb6 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java @@ -83,6 +83,7 @@ public class SupervisionParticipantHandler { var participant = participantOpt.get(); participant.setParticipantState(ParticipantState.OFF_LINE); participantProvider.updateParticipant(participant); + participantProvider.resetParticipantAcElementState(participant.getParticipantId()); } participantDeregisterAckPublisher.send(participantDeregisterMsg.getMessageId()); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java index 68ec44dc0..7ee7267e2 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java @@ -29,13 +29,11 @@ import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; -import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,15 +47,12 @@ public class SupervisionScanner { private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class); private final HandleCounter<UUID> automationCompositionCounter = new HandleCounter<>(); - private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>(); - private final Map<UUID, Integer> phaseMap = new HashMap<>(); private final AutomationCompositionProvider automationCompositionProvider; private final AcDefinitionProvider acDefinitionProvider; private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher; private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher; - private final ParticipantProvider participantProvider; /** * Constructor for instantiating SupervisionScanner. @@ -66,29 +61,22 @@ public class SupervisionScanner { * @param acDefinitionProvider the Policy Models Provider * @param automationCompositionStateChangePublisher the AutomationComposition StateChange Publisher * @param automationCompositionDeployPublisher the AutomationCompositionUpdate Publisher - * @param participantProvider the Participant Provider * @param acRuntimeParameterGroup the parameters for the automation composition runtime */ public SupervisionScanner(final AutomationCompositionProvider automationCompositionProvider, - AcDefinitionProvider acDefinitionProvider, - final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher, - AutomationCompositionDeployPublisher automationCompositionDeployPublisher, - ParticipantProvider participantProvider, - final AcRuntimeParameterGroup acRuntimeParameterGroup) { + final AcDefinitionProvider acDefinitionProvider, + final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher, + final AutomationCompositionDeployPublisher automationCompositionDeployPublisher, + final AcRuntimeParameterGroup acRuntimeParameterGroup) { this.automationCompositionProvider = automationCompositionProvider; this.acDefinitionProvider = acDefinitionProvider; this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher; this.automationCompositionDeployPublisher = automationCompositionDeployPublisher; - this.participantProvider = participantProvider; automationCompositionCounter.setMaxRetryCount( - acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); + acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); automationCompositionCounter - .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); - - participantStatusCounter.setMaxRetryCount( - acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); - participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); + .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); } /** @@ -99,12 +87,6 @@ public class SupervisionScanner { public void run(boolean counterCheck) { LOGGER.debug("Scanning automation compositions in the database . . ."); - if (counterCheck) { - for (var participant : participantProvider.getParticipants()) { - scanParticipantStatus(participant); - } - } - var list = acDefinitionProvider.getAllAcDefinitions(); for (var acDefinition : list) { var acList = automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId()); @@ -116,33 +98,12 @@ public class SupervisionScanner { LOGGER.debug("Automation composition scan complete . . ."); } - private void scanParticipantStatus(Participant participant) { - var id = participant.getParticipantId(); - if (participantStatusCounter.isFault(id)) { - LOGGER.debug("report Participant fault"); - return; - } - if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs() - && !participantStatusCounter.count(id)) { - LOGGER.debug("report Participant fault"); - participantStatusCounter.setFault(id); - participant.setParticipantState(ParticipantState.OFF_LINE); - participantProvider.updateParticipant(participant); - } - } - - /** - * handle participant Status message. - */ - public void handleParticipantStatus(UUID id) { - participantStatusCounter.clear(id); - } - private void scanAutomationComposition(final AutomationComposition automationComposition, - ToscaServiceTemplate toscaServiceTemplate, boolean counterCheck) { + ToscaServiceTemplate serviceTemplate, boolean counterCheck) { LOGGER.debug("scanning automation composition {} . . .", automationComposition.getInstanceId()); - if (automationComposition.getState().equals(automationComposition.getOrderedState().asState())) { + if (!AcmUtils.isInTransitionalState(automationComposition.getDeployState(), + automationComposition.getLockState())) { LOGGER.debug("automation composition {} scanned, OK", automationComposition.getInstanceId()); // Clear missed report counter on automation composition @@ -156,12 +117,12 @@ public class SupervisionScanner { var defaultMin = 1000; // min startPhase var defaultMax = 0; // max startPhase for (var element : automationComposition.getElements().values()) { - var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates() - .get(element.getDefinition().getName()); + var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates() + .get(element.getDefinition().getName()); int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()); defaultMin = Math.min(defaultMin, startPhase); defaultMax = Math.max(defaultMax, startPhase); - if (!element.getState().equals(element.getOrderedState().asState())) { + if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState())) { completed = false; minSpNotCompleted = Math.min(minSpNotCompleted, startPhase); maxSpNotCompleted = Math.max(maxSpNotCompleted, startPhase); @@ -169,36 +130,35 @@ public class SupervisionScanner { } if (completed) { - LOGGER.debug("automation composition scan: transition from state {} to {} completed", - automationComposition.getState(), automationComposition.getOrderedState()); + LOGGER.debug("automation composition scan: transition state {} {} ", automationComposition.getDeployState(), + automationComposition.getLockState()); - automationComposition.setState(automationComposition.getOrderedState().asState()); + var deployState = automationComposition.getDeployState(); + automationComposition.setDeployState(AcmUtils.deployCompleted(deployState)); + automationComposition + .setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState())); automationCompositionProvider.updateAutomationComposition(automationComposition); // Clear missed report counter on automation composition clearFaultAndCounter(automationComposition); } else { LOGGER.debug("automation composition scan: transition from state {} to {} not completed", - automationComposition.getState(), automationComposition.getOrderedState()); + automationComposition.getDeployState(), automationComposition.getLockState()); - var nextSpNotCompleted = - AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState()) - || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState()) - ? minSpNotCompleted - : maxSpNotCompleted; + var isForward = + AcmUtils.isForward(automationComposition.getDeployState(), automationComposition.getLockState()); - var firstStartPhase = - AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState()) - || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState()) - ? defaultMin - : defaultMax; + var nextSpNotCompleted = isForward ? minSpNotCompleted : maxSpNotCompleted; + var firstStartPhase = isForward ? defaultMin : defaultMax; if (nextSpNotCompleted != phaseMap.getOrDefault(automationComposition.getInstanceId(), firstStartPhase)) { phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted); - sendAutomationCompositionMsg(automationComposition, nextSpNotCompleted); + sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted, + firstStartPhase == nextSpNotCompleted); } else if (counterCheck) { phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted); - handleCounter(automationComposition, nextSpNotCompleted); + handleCounter(automationComposition, serviceTemplate, nextSpNotCompleted, + firstStartPhase == nextSpNotCompleted); } } } @@ -208,7 +168,8 @@ public class SupervisionScanner { phaseMap.remove(automationComposition.getInstanceId()); } - private void handleCounter(AutomationComposition automationComposition, int startPhase) { + private void handleCounter(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate, + int startPhase, boolean firstStartPhase) { var instanceId = automationComposition.getInstanceId(); if (automationCompositionCounter.isFault(instanceId)) { LOGGER.debug("report AutomationComposition fault"); @@ -218,7 +179,7 @@ public class SupervisionScanner { if (automationCompositionCounter.getDuration(instanceId) > automationCompositionCounter.getMaxWaitMs()) { if (automationCompositionCounter.count(instanceId)) { phaseMap.put(instanceId, startPhase); - sendAutomationCompositionMsg(automationComposition, startPhase); + sendAutomationCompositionMsg(automationComposition, serviceTemplate, startPhase, firstStartPhase); } else { LOGGER.debug("report AutomationComposition fault"); automationCompositionCounter.setFault(instanceId); @@ -226,13 +187,15 @@ public class SupervisionScanner { } } - private void sendAutomationCompositionMsg(AutomationComposition automationComposition, int startPhase) { - if (AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())) { + private void sendAutomationCompositionMsg(AutomationComposition automationComposition, + ToscaServiceTemplate serviceTemplate, int startPhase, boolean firstStartPhase) { + if (DeployState.DEPLOYING.equals(automationComposition.getDeployState())) { LOGGER.debug("retry message AutomationCompositionUpdate"); - automationCompositionDeployPublisher.send(automationComposition, startPhase); + automationCompositionDeployPublisher.send(automationComposition, serviceTemplate, startPhase, + firstStartPhase); } else { LOGGER.debug("retry message AutomationCompositionStateChange"); - automationCompositionStateChangePublisher.send(automationComposition, startPhase); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, firstStartPhase); } } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java index cc4a05939..2628f030d 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java @@ -36,7 +36,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; -import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -53,53 +52,13 @@ import org.springframework.stereotype.Component; public class AutomationCompositionDeployPublisher extends AbstractParticipantPublisher<AutomationCompositionDeploy> { private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionDeployPublisher.class); - private final AcDefinitionProvider acDefinitionProvider; - - /** - * Send AutomationCompositionDeploy to Participant. - * - * @param automationComposition the AutomationComposition - */ - @Timed(value = "publisher.automation_composition_deploy", - description = "AUTOMATION_COMPOSITION_DEPLOY messages published") - public void send(AutomationComposition automationComposition) { - send(automationComposition, 0); - } - - /** - * Send AutomationCompositionDeploy to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the Start Phase - */ - @Timed(value = "publisher.automation_composition_deploy", - description = "AUTOMATION_COMPOSITION_DEPLOY messages published") - public void send(AutomationComposition automationComposition, int startPhase) { - var acDeployMsg = new AutomationCompositionDeploy(); - acDeployMsg.setCompositionId(automationComposition.getCompositionId()); - acDeployMsg.setStartPhase(startPhase); - acDeployMsg.setAutomationCompositionId(automationComposition.getInstanceId()); - acDeployMsg.setMessageId(UUID.randomUUID()); - acDeployMsg.setTimestamp(Instant.now()); - var toscaServiceTemplate = - acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate(); - - List<ParticipantDeploy> participantDeploys = new ArrayList<>(); - for (var element : automationComposition.getElements().values()) { - element.setToscaServiceTemplateFragment(AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate)); - AcmUtils.prepareParticipantUpdate(element, participantDeploys); - } - acDeployMsg.setParticipantUpdatesList(participantDeploys); - - LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg); - super.send(acDeployMsg); - } /** * Send AutomationCompositionDeploy to Participant. * * @param automationComposition the AutomationComposition * @param startPhase the Start Phase + * @param firstStartPhase true if the first StartPhase */ @Timed(value = "publisher.automation_composition_deploy", description = "AUTOMATION_COMPOSITION_DEPLOY messages published") diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java index 56a62e13b..e59c2ac18 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java @@ -24,8 +24,7 @@ import io.micrometer.core.annotation.Timed; import java.util.UUID; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; +import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.springframework.stereotype.Component; /** @@ -36,7 +35,7 @@ public class AutomationCompositionStateChangePublisher extends AbstractParticipantPublisher<AutomationCompositionStateChange> { /** - * Send undeploy message to to Participant. + * Send AutomationCompositionStateChange message to to Participant. * * @param automationComposition the AutomationComposition * @param startPhase the startPhase @@ -44,75 +43,16 @@ public class AutomationCompositionStateChangePublisher @Timed( value = "publisher.automation_composition_state_change", description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void undeploy(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { - send(automationComposition, startPhase, firstStartPhase, DeployOrder.UNDEPLOY, LockOrder.NONE); - } - - /** - * Send unlock message to to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - */ - @Timed( - value = "publisher.automation_composition_state_change", - description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void unlock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { - send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.UNLOCK); - } - - /** - * Send lock message to to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - */ - @Timed( - value = "publisher.automation_composition_state_change", - description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void lock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { - send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.LOCK); - } - - /** - * Send undeploy message to to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - * @param deployOrder the DeployOrder - * @param lockOrder the LockOrder - */ - private void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase, - DeployOrder deployOrder, LockOrder lockOrder) { + public void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { var acsc = new AutomationCompositionStateChange(); acsc.setCompositionId(automationComposition.getCompositionId()); acsc.setAutomationCompositionId(automationComposition.getInstanceId()); acsc.setMessageId(UUID.randomUUID()); - acsc.setDeployOrderedState(deployOrder); - acsc.setLockOrderedState(lockOrder); + acsc.setDeployOrderedState(AcmUtils.stateDeployToOrder(automationComposition.getDeployState())); + acsc.setLockOrderedState(AcmUtils.stateLockToOrder(automationComposition.getLockState())); acsc.setStartPhase(startPhase); acsc.setFirstStartPhase(firstStartPhase); super.send(acsc); } - - /** - * Send AutomationCompositionStateChange to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - */ - @Timed( - value = "publisher.automation_composition_state_change", - description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void send(AutomationComposition automationComposition, int startPhase) { - var acsc = new AutomationCompositionStateChange(); - acsc.setCompositionId(automationComposition.getCompositionId()); - acsc.setAutomationCompositionId(automationComposition.getInstanceId()); - acsc.setMessageId(UUID.randomUUID()); - acsc.setOrderedState(automationComposition.getOrderedState()); - acsc.setStartPhase(startPhase); - - super.send(acsc); - } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java index fb285a84c..153f7a0e0 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java @@ -21,9 +21,12 @@ package org.onap.policy.clamp.acm.runtime.supervision; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML; import java.util.Map; import java.util.Optional; @@ -34,6 +37,7 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionD import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; @@ -97,4 +101,55 @@ class SupervisionAcHandlerTest { verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); } + + @Test + void testUndeploy() { + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var handler = new SupervisionAcHandler(automationCompositionProvider, + mock(AutomationCompositionDeployPublisher.class), + acStateChangePublisher); + var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Undeploy"); + handler.undeploy(automationComposition, acDefinition); + + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + } + + @Test + void testUnlock() { + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var handler = new SupervisionAcHandler(automationCompositionProvider, + mock(AutomationCompositionDeployPublisher.class), + acStateChangePublisher); + var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnLock"); + handler.unlock(automationComposition, acDefinition); + + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + } + + @Test + void testLock() { + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var handler = new SupervisionAcHandler(automationCompositionProvider, + mock(AutomationCompositionDeployPublisher.class), + acStateChangePublisher); + var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock"); + handler.lock(automationComposition, acDefinition); + + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java index b913cfac9..c9985e203 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java @@ -34,16 +34,19 @@ class SupervisionAspectTest { @Test void testSchedule() throws Exception { var supervisionScanner = mock(SupervisionScanner.class); - try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) { + var partecipantScanner = mock(SupervisionPartecipantScanner.class); + try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) { supervisionAspect.schedule(); verify(supervisionScanner, timeout(500)).run(true); + verify(partecipantScanner, timeout(500)).run(); } } @Test void testDoCheck() throws Exception { var supervisionScanner = mock(SupervisionScanner.class); - try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) { + var partecipantScanner = mock(SupervisionPartecipantScanner.class); + try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) { supervisionAspect.doCheck(); supervisionAspect.doCheck(); verify(supervisionScanner, timeout(500).times(2)).run(false); @@ -56,9 +59,10 @@ class SupervisionAspectTest { participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); var supervisionScanner = mock(SupervisionScanner.class); - try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) { + var partecipantScanner = mock(SupervisionPartecipantScanner.class); + try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) { supervisionAspect.handleParticipantStatus(participantStatusMessage); - verify(supervisionScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId()); + verify(partecipantScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId()); } } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java index f47e2372a..246ba7dc7 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java @@ -57,6 +57,7 @@ class SupervisionParticipantHandlerTest { handler.handleParticipantMessage(participantDeregisterMessage); verify(participantProvider).updateParticipant(any()); + verify(participantProvider).resetParticipantAcElementState(any()); verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId()); } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java new file mode 100644 index 000000000..3ad9f813c --- /dev/null +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.acm.runtime.supervision; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.runtime.util.CommonTestData; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.onap.policy.models.base.PfModelException; + +class SupervisionParticipantScannerTest { + + @Test + void testScanParticipant() throws PfModelException { + var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant"); + acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1); + acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); + + var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); + participant.setParticipantState(ParticipantState.OFF_LINE); + var participantProvider = mock(ParticipantProvider.class); + when(participantProvider.getParticipants()).thenReturn(List.of(participant)); + + var supervisionScanner = new SupervisionPartecipantScanner(participantProvider, acRuntimeParameterGroup); + + supervisionScanner.handleParticipantStatus(participant.getParticipantId()); + supervisionScanner.run(); + verify(participantProvider, times(0)).saveParticipant(any()); + + supervisionScanner.run(); + verify(participantProvider, times(1)).updateParticipant(any()); + } +} diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java index fe34c6b04..032468a56 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java @@ -21,6 +21,7 @@ package org.onap.policy.clamp.acm.runtime.supervision; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -39,13 +40,11 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionS import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; -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.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; -import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; -import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; class SupervisionScannerTest { @@ -70,16 +69,15 @@ class SupervisionScannerTest { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); - var participantProvider = mock(ParticipantProvider.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); + .thenReturn(List.of(automationComposition)); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); supervisionScanner.run(false); verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); @@ -88,20 +86,19 @@ class SupervisionScannerTest { @Test void testScannerOrderedStateDifferentToState() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); - automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE); - automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + automationComposition.setDeployState(DeployState.UNDEPLOYING); + automationComposition.setLockState(LockState.NONE); var automationCompositionProvider = mock(AutomationCompositionProvider.class); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); + .thenReturn(List.of(automationComposition)); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); - var participantProvider = mock(ParticipantProvider.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); supervisionScanner.run(false); verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class)); @@ -112,21 +109,16 @@ class SupervisionScannerTest { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var automationComposition = new AutomationComposition(); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); - - var participantProvider = mock(ParticipantProvider.class); - var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); - when(participantProvider.getParticipants()).thenReturn(List.of(participant)); + .thenReturn(List.of(automationComposition)); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); - supervisionScanner.handleParticipantStatus(participant.getParticipantId()); supervisionScanner.run(true); verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); } @@ -134,65 +126,68 @@ class SupervisionScannerTest { @Test void testSendAutomationCompositionMsgUpdate() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); - automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE); - automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + automationComposition.setDeployState(DeployState.DEPLOYING); + automationComposition.setLockState(LockState.NONE); for (var element : automationComposition.getElements().values()) { if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement" - .equals(element.getDefinition().getName())) { - element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - element.setState(AutomationCompositionState.UNINITIALISED); + .equals(element.getDefinition().getName())) { + element.setDeployState(DeployState.DEPLOYING); + element.setLockState(LockState.NONE); } else { - element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - element.setState(AutomationCompositionState.PASSIVE); + element.setDeployState(DeployState.DEPLOYED); + element.setLockState(LockState.LOCKED); } } var automationCompositionProvider = mock(AutomationCompositionProvider.class); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); + .thenReturn(List.of(automationComposition)); - var participantProvider = mock(ParticipantProvider.class); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); supervisionScanner.run(false); - verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class), anyInt()); + verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class), + any(ToscaServiceTemplate.class), anyInt(), anyBoolean()); } @Test - void testScanParticipant() throws PfModelException { + void testSendAutomationCompositionMsgUnlocking() { + var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.UNLOCKING); + for (var element : automationComposition.getElements().values()) { + if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement" + .equals(element.getDefinition().getName())) { + element.setDeployState(DeployState.DEPLOYED); + element.setLockState(LockState.UNLOCKING); + } else { + element.setDeployState(DeployState.DEPLOYED); + element.setLockState(LockState.UNLOCKED); + } + } + var automationCompositionProvider = mock(AutomationCompositionProvider.class); - var automationComposition = new AutomationComposition(); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); - - var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant"); - acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1); - acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); - - var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); - participant.setParticipantState(ParticipantState.OFF_LINE); - var participantProvider = mock(ParticipantProvider.class); - when(participantProvider.getParticipants()).thenReturn(List.of(participant)); + .thenReturn(List.of(automationComposition)); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); - supervisionScanner.handleParticipantStatus(participant.getParticipantId()); - supervisionScanner.run(true); - verify(participantProvider, times(0)).saveParticipant(any()); + supervisionScanner.run(false); - supervisionScanner.run(true); - verify(participantProvider, times(1)).updateParticipant(any()); + verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), anyInt(), + anyBoolean()); } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java index 0072a1042..e0accc4a0 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java @@ -42,7 +42,8 @@ import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; @@ -117,14 +118,15 @@ class SupervisionMessagesTest { @Test void testSendAutomationCompositionStateChangePublisherNotActive() { var publisher = new AutomationCompositionStateChangePublisher(); - assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0)).hasMessage(NOT_ACTIVE); + assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0, true)).hasMessage(NOT_ACTIVE); } private AutomationComposition getAutomationComposition() { var automationComposition = new AutomationComposition(); automationComposition.setName("NAME"); automationComposition.setVersion("0.0.1"); - automationComposition.setState(AutomationCompositionState.UNINITIALISED); + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.UNLOCKING); return automationComposition; } @@ -133,7 +135,7 @@ class SupervisionMessagesTest { var publisher = new AutomationCompositionStateChangePublisher(); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); - publisher.send(getAutomationComposition(), 0); + publisher.send(getAutomationComposition(), 0, true); verify(topicSink).send(anyString()); publisher.stop(); } @@ -152,12 +154,12 @@ class SupervisionMessagesTest { var participantId = UUID.randomUUID(); Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>(); supportedElementMap.put( - new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"), + new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"), participantId); supportedElementMap.put(new ToscaConceptIdentifier( - "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.1"), participantId); + "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.0"), participantId); supportedElementMap.put( - new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"), + new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"), participantId); var participantProvider = mock(ParticipantProvider.class); when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap); diff --git a/testsuites/performance/src/main/resources/testplans/performance.jmx b/testsuites/performance/src/main/resources/testplans/performance.jmx index b8a07e82f..f8aaf41c5 100644 --- a/testsuites/performance/src/main/resources/testplans/performance.jmx +++ b/testsuites/performance/src/main/resources/testplans/performance.jmx @@ -10,22 +10,22 @@ <collectionProp name="Arguments.arguments"> <elementProp name="RUNTIME_HOST" elementType="Argument"> <stringProp name="Argument.name">RUNTIME_HOST</stringProp> - <stringProp name="Argument.value">192.168.32.9</stringProp> + <stringProp name="Argument.value">localhost</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="RUNTIME_PORT" elementType="Argument"> <stringProp name="Argument.name">RUNTIME_PORT</stringProp> - <stringProp name="Argument.value">6969</stringProp> + <stringProp name="Argument.value">30007</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="POLICY_PARTICIPANT_HOST" elementType="Argument"> <stringProp name="Argument.name">POLICY_PARTICIPANT_HOST</stringProp> - <stringProp name="Argument.value">192.168.32.8</stringProp> + <stringProp name="Argument.value">localhost</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="POLICY_PARTICIPANT_PORT" elementType="Argument"> <stringProp name="Argument.name">POLICY_PARTICIPANT_PORT</stringProp> - <stringProp name="Argument.value">6970</stringProp> + <stringProp name="Argument.value">30008</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="HOME_PATH" elementType="Argument"> diff --git a/testsuites/run-s3p-test.sh b/testsuites/run-s3p-test.sh new file mode 100755 index 000000000..9a4d044f0 --- /dev/null +++ b/testsuites/run-s3p-test.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# ============LICENSE_START======================================================= +# Copyright (C) 2023 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. +# 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========================================================= + +#===MAIN===# +if [ -z "${WORKSPACE}" ]; then + export WORKSPACE=$(git rev-parse --show-toplevel) +fi + +export TESTDIR=${WORKSPACE}/testsuites +export ACM_PERF_TEST_FILE=$TESTDIR/performance/src/main/resources/testplans/performance.jmx +export ACM_STAB_TEST_FILE=$TESTDIR/stability/src/main/resources/testplans/stability.jmx + +if [ $1 == "run" ] +then + + mkdir automate-performance;cd automate-performance; + git clone "https://gerrit.onap.org/r/policy/docker" + cd docker/csit + + if [ $2 == "performance" ] + then + bash start-s3p-tests.sh run $ACM_PERF_TEST_FILE; + elif [ $2 == "stability" ] + then + bash start-s3p-tests.sh run $ACM_STAB_TEST_FILE; + else + echo "echo Invalid arguments provided. Usage: $0 [option..] {performance | stability}" + fi + +else + echo "Invalid arguments provided. Usage: $0 [option..] {run | uninstall}" +fi + diff --git a/testsuites/stability/src/main/resources/testplans/stability.jmx b/testsuites/stability/src/main/resources/testplans/stability.jmx index 3e90be285..8fe84c86c 100644 --- a/testsuites/stability/src/main/resources/testplans/stability.jmx +++ b/testsuites/stability/src/main/resources/testplans/stability.jmx @@ -10,22 +10,22 @@ <collectionProp name="Arguments.arguments"> <elementProp name="RUNTIME_HOST" elementType="Argument"> <stringProp name="Argument.name">RUNTIME_HOST</stringProp> - <stringProp name="Argument.value">192.168.48.9</stringProp> + <stringProp name="Argument.value">localhost</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="RUNTIME_PORT" elementType="Argument"> <stringProp name="Argument.name">RUNTIME_PORT</stringProp> - <stringProp name="Argument.value">6969</stringProp> + <stringProp name="Argument.value">30007</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="POLICY_PARTICIPANT_HOST" elementType="Argument"> <stringProp name="Argument.name">POLICY_PARTICIPANT_HOST</stringProp> - <stringProp name="Argument.value">192.168.48.8</stringProp> + <stringProp name="Argument.value">localhost</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="POLICY_PARTICIPANT_HOST_PORT" elementType="Argument"> <stringProp name="Argument.name">POLICY_PARTICIPANT_HOST_PORT</stringProp> - <stringProp name="Argument.value">6973</stringProp> + <stringProp name="Argument.value">20008</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> </collectionProp> |