diff options
23 files changed, 499 insertions, 104 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java index 9c65b1eff..a8c069723 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java @@ -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. @@ -20,11 +20,14 @@ package org.onap.policy.clamp.models.acm.concepts; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; +import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @NoArgsConstructor @@ -38,6 +41,13 @@ public class AutomationCompositionDefinition { @NonNull private ToscaServiceTemplate serviceTemplate; + @NonNull + private AcTypeState state; + + @NonNull + // Map used to store prime state with key as NodeTemplate Name and value as NodeTemplateState + private Map<String, NodeTemplateState> elementStateMap = new HashMap<>(); + /** * Copy contructor, does a deep copy. * @@ -45,6 +55,8 @@ public class AutomationCompositionDefinition { */ public AutomationCompositionDefinition(final AutomationCompositionDefinition otherAcmDefinition) { this.compositionId = otherAcmDefinition.compositionId; - this.serviceTemplate = otherAcmDefinition.serviceTemplate; + this.serviceTemplate = new ToscaServiceTemplate(otherAcmDefinition.serviceTemplate); + this.state = otherAcmDefinition.state; + this.elementStateMap = PfUtils.mapMap(otherAcmDefinition.elementStateMap, NodeTemplateState::new); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java new file mode 100644 index 000000000..5d28cd736 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java @@ -0,0 +1,54 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.UUID; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@NoArgsConstructor +@Data +@EqualsAndHashCode +public class NodeTemplateState { + + private UUID nodeTemplateStateId; + + // participantId assigned to this element + private UUID participantId; + + private ToscaConceptIdentifier nodeTemplateId; + + private AcTypeState state; + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param copyConstructor the NodeTemplateState to copy from + */ + public NodeTemplateState(NodeTemplateState copyConstructor) { + this.nodeTemplateStateId = copyConstructor.nodeTemplateStateId; + this.participantId = copyConstructor.participantId; + this.nodeTemplateId = new ToscaConceptIdentifier(copyConstructor.nodeTemplateId); + this.state = copyConstructor.state; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java index 4741bafca..8503516a1 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java @@ -20,12 +20,14 @@ package org.onap.policy.clamp.models.acm.concepts; +import java.util.HashMap; import java.util.Map; import java.util.UUID; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; +import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** @@ -46,7 +48,7 @@ public class Participant { private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(); @NonNull - private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes; + private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes = new HashMap<>(); /** * Copy constructor. @@ -57,5 +59,7 @@ public class Participant { this.participantState = otherParticipant.participantState; this.participantType = otherParticipant.participantType; this.participantId = otherParticipant.participantId; + this.participantSupportedElementTypes = PfUtils.mapMap(otherParticipant.getParticipantSupportedElementTypes(), + ParticipantSupportedElementType::new); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java index 310577167..68d50010c 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java @@ -21,16 +21,14 @@ package org.onap.policy.clamp.models.acm.concepts; import java.util.UUID; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; import org.onap.policy.common.parameters.annotations.NotNull; -import org.springframework.validation.annotation.Validated; @NoArgsConstructor -@Getter -@Setter -@Validated +@Data +@EqualsAndHashCode public class ParticipantSupportedElementType { @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java index c46bdb96c..fcaa6e6db 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java @@ -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. @@ -20,17 +20,26 @@ package org.onap.policy.clamp.models.acm.persistence.concepts; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; +import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Convert; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; import javax.persistence.Lob; +import javax.persistence.OneToMany; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; @@ -55,12 +64,22 @@ public class JpaAutomationCompositionDefinition extends Validated @NotNull private String compositionId; + @Column @NotNull private String name; + @Column @NotNull private String version; + @Column + @NotNull + private AcTypeState state; + + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "compositionId", foreignKey = @ForeignKey(name = "dt_element_fk")) + private Set<JpaNodeTemplateState> elements = new HashSet<>(); + @Lob @Convert(converter = StringToServiceTemplateConverter.class) @NotNull @@ -72,15 +91,26 @@ public class JpaAutomationCompositionDefinition extends Validated var acmDefinition = new AutomationCompositionDefinition(); acmDefinition.setCompositionId(UUID.fromString(compositionId)); acmDefinition.setServiceTemplate(serviceTemplate.toAuthorative()); + for (var element : this.elements) { + var key = element.getNodeTemplateId().getName(); + acmDefinition.getElementStateMap().put(key, element.toAuthorative()); + } return acmDefinition; } @Override public void fromAuthorative(final AutomationCompositionDefinition copyConcept) { - compositionId = copyConcept.getCompositionId().toString(); - serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate()); - setName(serviceTemplate.getName()); - setVersion(serviceTemplate.getVersion()); + this.compositionId = copyConcept.getCompositionId().toString(); + this.state = copyConcept.getState(); + this.serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate()); + setName(this.serviceTemplate.getName()); + setVersion(this.serviceTemplate.getVersion()); + elements = new HashSet<>(copyConcept.getElementStateMap().size()); + for (var element : copyConcept.getElementStateMap().values()) { + var nodeTemplateStateId = element.getNodeTemplateStateId().toString(); + var jpaNodeTemplateState = new JpaNodeTemplateState(nodeTemplateStateId, this.compositionId); + jpaNodeTemplateState.fromAuthorative(element); + } } public JpaAutomationCompositionDefinition(final AutomationCompositionDefinition acmDefinition) { diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java new file mode 100644 index 000000000..a6d13a638 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java @@ -0,0 +1,103 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; +import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.Validated; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@Entity +@Table(name = "NodeTemplateState") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> { + + @Id + @NotNull + private String nodeTemplateStateId; + + @Column + @NotNull + private String compositionId; + + @Column + private String participantId; + + @Column + @NotNull + private ToscaConceptIdentifier nodeTemplateId; + + @Column + @NotNull + private AcTypeState state; + + /** + * The Default Constructor. + */ + public JpaNodeTemplateState() { + this(UUID.randomUUID().toString(), UUID.randomUUID().toString()); + } + + /** + * Constructor. + * + * @param nodeTemplateStateId the nodeTemplateStateId + * @param compositionId the compositionId + */ + public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) { + this.nodeTemplateStateId = nodeTemplateStateId; + this.compositionId = compositionId; + } + + @Override + public void fromAuthorative(NodeTemplateState copyConcept) { + this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString(); + if (copyConcept.getParticipantId() != null) { + this.participantId = copyConcept.getParticipantId().toString(); + } + this.nodeTemplateId = copyConcept.getNodeTemplateId(); + } + + @Override + public NodeTemplateState toAuthorative() { + var nodeTemplateState = new NodeTemplateState(); + nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId)); + if (this.participantId != null) { + nodeTemplateState.setParticipantId(UUID.fromString(this.participantId)); + } + nodeTemplateState.setNodeTemplateId(this.nodeTemplateId); + nodeTemplateState.setState(this.state); + return nodeTemplateState; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java index 054271512..3757f6c7b 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.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. @@ -27,6 +27,7 @@ import java.util.UUID; import java.util.stream.Collectors; import javax.ws.rs.core.Response; import lombok.RequiredArgsConstructor; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition; @@ -55,6 +56,7 @@ public class AcDefinitionProvider { var acmDefinition = new AutomationCompositionDefinition(); var compositionId = UUID.randomUUID(); acmDefinition.setCompositionId(compositionId); + acmDefinition.setState(AcTypeState.COMMISSIONED); if (serviceTemplate.getMetadata() == null) { serviceTemplate.setMetadata(new HashMap<>()); } @@ -68,7 +70,7 @@ public class AcDefinitionProvider { } /** - * Update the ServiceTemplate. + * Update a commissioned ServiceTemplate. * * @param compositionId The UUID of the automation composition definition to delete * @param serviceTemplate the service template to be created @@ -76,8 +78,18 @@ public class AcDefinitionProvider { public void updateServiceTemplate(UUID compositionId, ToscaServiceTemplate serviceTemplate) { var acmDefinition = new AutomationCompositionDefinition(); acmDefinition.setCompositionId(compositionId); + acmDefinition.setState(AcTypeState.COMMISSIONED); acmDefinition.setServiceTemplate(serviceTemplate); - var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new, + updateAcDefinition(acmDefinition); + } + + /** + * Update the AutomationCompositionDefinition. + * + * @param acDefinition the AutomationCompositionDefinition to be updated + */ + public void updateAcDefinition(AutomationCompositionDefinition acDefinition) { + var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acDefinition, JpaAutomationCompositionDefinition::new, "AutomationCompositionDefinition"); acmDefinitionRepository.save(jpaAcmDefinition); } @@ -108,14 +120,14 @@ public class AcDefinitionProvider { * @return the automation composition definition */ @Transactional(readOnly = true) - public ToscaServiceTemplate getAcDefinition(UUID compositionId) { + public AutomationCompositionDefinition getAcDefinition(UUID compositionId) { var jpaGet = acmDefinitionRepository.findById(compositionId.toString()); if (jpaGet.isEmpty()) { String errorMessage = "Get serviceTemplate \"" + compositionId + "\" failed, serviceTemplate does not exist"; throw new PfModelRuntimeException(Response.Status.NOT_FOUND, errorMessage); } - return jpaGet.get().getServiceTemplate().toAuthorative(); + return jpaGet.get().toAuthorative(); } /** diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java new file mode 100644 index 000000000..aa084b4f2 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java @@ -0,0 +1,47 @@ +/*- + * ============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.models.acm.concepts; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.utils.CommonTestData; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionDefinitionTest { + + private static final String TOSCA_SERVICE_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml"; + + @Test + void testCopyContructor() { + var acDefinition = new AutomationCompositionDefinition(); + acDefinition.setCompositionId(UUID.randomUUID()); + var nodeTemplateState = new NodeTemplateState(); + nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier()); + acDefinition.setElementStateMap(Map.of("key", nodeTemplateState)); + acDefinition.setServiceTemplate(CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML)); + acDefinition.setState(AcTypeState.COMMISSIONED); + var result = new AutomationCompositionDefinition(acDefinition); + assertEquals(result, acDefinition); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java new file mode 100644 index 000000000..a850c88dc --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java @@ -0,0 +1,41 @@ +/*- + * ============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.models.acm.concepts; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class NodeTemplateStateTest { + + @Test + void testCopyContructor() { + var nodeTemplateState = new NodeTemplateState(); + nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier()); + nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID()); + nodeTemplateState.setParticipantId(UUID.randomUUID()); + nodeTemplateState.setState(AcTypeState.COMMISSIONED); + var result = new NodeTemplateState(nodeTemplateState); + assertEquals(result, nodeTemplateState); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java index 0ae1a90e2..c6af96742 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java @@ -26,6 +26,8 @@ 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 java.util.Map; +import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.utils.CommonTestData; @@ -34,7 +36,7 @@ class ParticipantTest { @Test void testParticipantLombok() { assertNotNull(new Participant()); - Participant p0 = new Participant(); + var p0 = new Participant(); assertThat(p0.toString()).contains("Participant("); assertThat(p0.hashCode()).isNotZero(); @@ -42,7 +44,7 @@ class ParticipantTest { assertNotEquals(null, p0); - Participant p1 = new Participant(); + var p1 = new Participant(); p1.setParticipantId(CommonTestData.getParticipantId()); p1.setParticipantState(ParticipantState.ON_LINE); @@ -54,7 +56,7 @@ class ParticipantTest { assertNotEquals(p1, p0); - Participant p2 = new Participant(); + var p2 = new Participant(); // @formatter:off assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class); @@ -62,4 +64,19 @@ class ParticipantTest { assertEquals(p2, p0); } + + @Test + void testCopyConstructor() { + var p0 = new Participant(); + p0.setParticipantId(UUID.randomUUID()); + p0.setParticipantState(ParticipantState.ON_LINE); + var supportedElementType = new ParticipantSupportedElementType(); + supportedElementType.setId(UUID.randomUUID()); + supportedElementType.setTypeName("type"); + supportedElementType.setTypeVersion("1.0.0"); + p0.setParticipantSupportedElementTypes(Map.of(supportedElementType.getId(), supportedElementType)); + + var p2 = new Participant(p0); + assertEquals(p2, p0); + } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java index fac98043d..5a82466d6 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java @@ -31,16 +31,15 @@ import org.junit.jupiter.api.Test; public class ParticipantsSupportedElementTypesTest { private static final String ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e"; - private static final String PARTICIPANT_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a"; @Test void testParticipant() { - ParticipantSupportedElementType p0 = new ParticipantSupportedElementType(); + var p0 = new ParticipantSupportedElementType(); p0.setId(UUID.fromString(ID)); assertEquals(ID, p0.getId().toString()); - ParticipantSupportedElementType p1 = new ParticipantSupportedElementType(p0); + var p1 = new ParticipantSupportedElementType(p0); assertThat(p0).usingRecursiveComparison().isEqualTo(p1); } @@ -48,27 +47,27 @@ public class ParticipantsSupportedElementTypesTest { @Test void testParticipantLombok() { assertNotNull(new ParticipantSupportedElementType()); - ParticipantSupportedElementType p0 = new ParticipantSupportedElementType(); + var p0 = new ParticipantSupportedElementType(); - assertThat(p0.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType"); + assertThat(p0.toString()).contains("ParticipantSupportedElementType"); assertThat(p0.hashCode()).isNotZero(); assertThat(p0).usingRecursiveComparison().isEqualTo(new ParticipantSupportedElementType(p0)); assertNotEquals(null, p0); - ParticipantSupportedElementType p1 = new ParticipantSupportedElementType(); + var p1 = new ParticipantSupportedElementType(); p1.setId(UUID.fromString(ID)); p1.setTypeName("name"); p1.setTypeVersion("1.0.0"); - assertThat(p1.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType"); + assertThat(p1.toString()).contains("ParticipantSupportedElementType"); assertNotEquals(0, p1.hashCode()); assertNotEquals(p1, p0); assertNotEquals(null, p1); - ParticipantSupportedElementType p2 = new ParticipantSupportedElementType(); + var p2 = new ParticipantSupportedElementType(); p2.setId(p0.getId()); assertThat(p0).usingRecursiveComparison().isEqualTo(p2); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java index 59e3767d1..a27a74be4 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.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. @@ -22,24 +22,26 @@ package org.onap.policy.clamp.models.acm.persistence.provider; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.fail; 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.util.List; +import java.util.Map; import java.util.Optional; import java.util.UUID; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; +import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardYamlCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.clamp.models.acm.utils.CommonTestData; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.data.domain.Example; @@ -49,19 +51,17 @@ class AcDefinitionProviderTest { private static final String TOSCA_SERVICE_TEMPLATE_YAML_PROP = "clamp/acm/test/tosca-template-additional-properties.yaml"; - private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); - private static ToscaServiceTemplate inputServiceTemplate; @BeforeAll static void loadServiceTemplate() { - inputServiceTemplate = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + inputServiceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); } @Test void testDocCopyCompare() { - var inputServiceTemplateProperties = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP); + var inputServiceTemplateProperties = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP); var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplateProperties); var docServiceTemplateCopy = new DocToscaServiceTemplate(docServiceTemplate); @@ -71,8 +71,8 @@ class AcDefinitionProviderTest { var acmDefinition = getAcDefinition(docServiceTemplate); var acmDefinitionCopy = getAcDefinition(docServiceTemplateCopy); - assertThat(acmDefinition.getServiceTemplate().getName()).isEqualTo( - acmDefinitionCopy.getServiceTemplate().getName()); + assertThat(acmDefinition.getServiceTemplate().getName()) + .isEqualTo(acmDefinitionCopy.getServiceTemplate().getName()); } @@ -92,6 +92,65 @@ class AcDefinitionProviderTest { } @Test + void testUpdateServiceTemplate() { + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + acDefinitionProvider.updateServiceTemplate(UUID.randomUUID(), inputServiceTemplate); + verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class)); + } + + @Test + void testUpdateAcDefinition() { + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acmDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)); + acDefinitionProvider.updateAcDefinition(acmDefinition); + verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class)); + } + + @Test + void testGetAcDefinition() { + var jpa = new JpaAutomationCompositionDefinition(); + jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate))); + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa)); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var result = acDefinitionProvider.getAcDefinition(UUID.fromString(jpa.getCompositionId())); + assertThat(result).isNotNull(); + } + + @Test + void testGetAcDefinitionNotFound() { + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var compositionId = UUID.randomUUID(); + assertThatThrownBy(() -> acDefinitionProvider.getAcDefinition(compositionId)) + .hasMessage("Get serviceTemplate \"" + compositionId + "\" failed, serviceTemplate does not exist"); + } + + @Test + void testFindAcDefinition() { + var jpa = new JpaAutomationCompositionDefinition(); + jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate))); + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa)); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var result = acDefinitionProvider.findAcDefinition(UUID.fromString(jpa.getCompositionId())); + assertThat(result).isNotNull(); + } + + @Test + void testGetAllAcDefinitions() { + var jpa = new JpaAutomationCompositionDefinition(); + jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate))); + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + when(acmDefinitionRepository.findAll()).thenReturn(List.of(jpa)); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var result = acDefinitionProvider.getAllAcDefinitions(); + assertThat(result).hasSize(1); + } + + @Test void testDeleteAcDefintion() { var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate); var acmDefinition = getAcDefinition(docServiceTemplate); @@ -135,22 +194,13 @@ class AcDefinitionProviderTest { private AutomationCompositionDefinition getAcDefinition(DocToscaServiceTemplate docServiceTemplate) { var acmDefinition = new AutomationCompositionDefinition(); acmDefinition.setCompositionId(UUID.randomUUID()); + acmDefinition.setState(AcTypeState.COMMISSIONED); acmDefinition.setServiceTemplate(docServiceTemplate.toAuthorative()); + var nodeTemplateState = new NodeTemplateState(); + nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID()); + nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier("name", "1.0.0")); + nodeTemplateState.setState(AcTypeState.COMMISSIONED); + acmDefinition.setElementStateMap(Map.of(nodeTemplateState.getNodeTemplateId().getName(), nodeTemplateState)); return acmDefinition; } - - /** - * Get ToscaServiceTemplate from resource. - * - * @param path path of the resource - */ - public static ToscaServiceTemplate getToscaServiceTemplate(String path) { - - try { - return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class); - } catch (CoderException e) { - fail("Cannot read or decode " + path); - return null; - } - } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java index 88ace1706..21666e484 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java @@ -20,7 +20,13 @@ package org.onap.policy.clamp.models.acm.utils; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.UUID; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardYamlCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** * Class to hold/create all parameters for test cases. @@ -29,6 +35,8 @@ import java.util.UUID; public class CommonTestData { public static final UUID PARTCICIPANT_ID = UUID.randomUUID(); + private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); + /** * Returns participantId for test cases. @@ -56,4 +64,18 @@ public class CommonTestData { public static UUID getRndParticipantId() { return UUID.randomUUID(); } + + /** + * Get ToscaServiceTemplate from resource. + * + * @param path path of the resource + */ + public static ToscaServiceTemplate getToscaServiceTemplate(String path) { + try { + return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class); + } catch (CoderException e) { + fail("Cannot read or decode " + path); + return null; + } + } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java index 9f898d88d..450c75564 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,10 @@ package org.onap.policy.clamp.acm.runtime.commissioning; import java.util.UUID; import java.util.stream.Collectors; import javax.ws.rs.core.Response.Status; +import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; @@ -42,29 +45,14 @@ import org.springframework.transaction.annotation.Transactional; */ @Service @Transactional +@RequiredArgsConstructor public class CommissioningProvider { public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition"; private final AcDefinitionProvider acDefinitionProvider; private final AutomationCompositionProvider acProvider; - private final ParticipantProvider participantProvider; private final SupervisionHandler supervisionHandler; - - /** - * Create a commissioning provider. - * - * @param acDefinitionProvider the ServiceTemplate Provider - * @param acProvider the AutomationComposition Provider - * @param supervisionHandler the Supervision Handler - * @param participantProvider the Participant Provider - */ - public CommissioningProvider(AcDefinitionProvider acDefinitionProvider, AutomationCompositionProvider acProvider, - SupervisionHandler supervisionHandler, ParticipantProvider participantProvider) { - this.acDefinitionProvider = acDefinitionProvider; - this.acProvider = acProvider; - this.supervisionHandler = supervisionHandler; - this.participantProvider = participantProvider; - } + private final ParticipantProvider participantProvider; private CommissioningResponse createCommissioningResponse(UUID compositionId, ToscaServiceTemplate serviceTemplate) { @@ -83,12 +71,12 @@ public class CommissioningProvider { } /** - * Create automation compositions from a service template. + * Create automation composition from a service template. * * @param serviceTemplate the service template * @return the result of the commissioning operation */ - public CommissioningResponse createAutomationCompositionDefinitions(ToscaServiceTemplate serviceTemplate) { + public CommissioningResponse createAutomationCompositionDefinition(ToscaServiceTemplate serviceTemplate) { var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate); serviceTemplate = acmDefinition.getServiceTemplate(); @@ -107,12 +95,15 @@ public class CommissioningProvider { * @return the result of the commissioning operation */ public CommissioningResponse updateCompositionDefinition(UUID compositionId, ToscaServiceTemplate serviceTemplate) { - - var automationCompositions = acProvider.getAcInstancesByCompositionId(compositionId); - if (!automationCompositions.isEmpty()) { + if (verifyIfInstanceExists(compositionId)) { throw new PfModelRuntimeException(Status.BAD_REQUEST, "There are ACM instances, Update of ACM Definition not allowed"); } + var acDefinition = acDefinitionProvider.getAcDefinition(compositionId); + if (AcTypeState.COMMISSIONED.equals(acDefinition.getState())) { + throw new PfModelRuntimeException(Status.BAD_REQUEST, + "ACM not in COMMISSIONED state, Update of ACM Definition not allowed"); + } acDefinitionProvider.updateServiceTemplate(compositionId, serviceTemplate); return createCommissioningResponse(compositionId, serviceTemplate); @@ -161,7 +152,7 @@ public class CommissioningProvider { * @return automation composition definition */ @Transactional(readOnly = true) - public ToscaServiceTemplate getAutomationCompositionDefinitions(UUID compositionId) { + public AutomationCompositionDefinition getAutomationCompositionDefinition(UUID compositionId) { return acDefinitionProvider.getAcDefinition(compositionId); } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java index 7f9dc8d19..6d7ae7d4d 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.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. @@ -26,6 +26,7 @@ import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider; import org.onap.policy.clamp.acm.runtime.main.rest.gen.AutomationCompositionDefinitionApi; import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -56,7 +57,7 @@ public class CommissioningController extends AbstractRestController implements A UUID requestId) { var compositionId = body.getMetadata() != null ? body.getMetadata().get("compositionId") : null; if (compositionId == null) { - var response = provider.createAutomationCompositionDefinitions(body); + var response = provider.createAutomationCompositionDefinition(body); return ResponseEntity.created(createUri("/compositions/" + response.getCompositionId())).body(response); } else { return ResponseEntity.ok() @@ -91,8 +92,9 @@ public class CommissioningController extends AbstractRestController implements A } @Override - public ResponseEntity<ToscaServiceTemplate> getCompositionDefinition(UUID compositionId, UUID requestId) { - return ResponseEntity.ok().body(provider.getAutomationCompositionDefinitions(compositionId)); + public ResponseEntity<AutomationCompositionDefinition> getCompositionDefinition(UUID compositionId, + UUID requestId) { + return ResponseEntity.ok().body(provider.getAutomationCompositionDefinition(compositionId)); } @Override diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java index 98c71dc6f..adcb1410b 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java @@ -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. @@ -24,6 +24,7 @@ import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.runtime.main.rest.gen.AutomationCompositionDefinitionApi; import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -72,8 +73,9 @@ public class CommissioningControllerStub extends AbstractRestController implemen } @Override - public ResponseEntity<ToscaServiceTemplate> getCompositionDefinition(UUID compositionId, UUID xonaprequestid) { - return stubUtils.getResponse(pathToSingleDefinition, ToscaServiceTemplate.class); + public ResponseEntity<AutomationCompositionDefinition> getCompositionDefinition(UUID compositionId, + UUID xonaprequestid) { + return stubUtils.getResponse(pathToSingleDefinition, AutomationCompositionDefinition.class); } @Override diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java index 761c3800c..2c5d48717 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java @@ -305,7 +305,8 @@ public class SupervisionHandler { } private int getFirstStartPhase(AutomationComposition automationComposition) { - var toscaServiceTemplate = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()); + var toscaServiceTemplate = + acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate(); return ParticipantUtils.getFirstStartPhase(automationComposition, toscaServiceTemplate); } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java index 7b114c920..57556e088 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021,2022 Nordix Foundation. + * Copyright (C) 2021,2023 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -73,7 +73,8 @@ public class AutomationCompositionUpdatePublisher extends AbstractParticipantPub automationCompositionUpdateMsg.setAutomationCompositionId(automationComposition.getInstanceId()); automationCompositionUpdateMsg.setMessageId(UUID.randomUUID()); automationCompositionUpdateMsg.setTimestamp(Instant.now()); - var toscaServiceTemplate = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()); + var toscaServiceTemplate = + acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate(); List<ParticipantUpdates> participantUpdates = new ArrayList<>(); for (var element : automationComposition.getElements().values()) { diff --git a/runtime-acm/src/main/resources/openapi/openapi.yaml b/runtime-acm/src/main/resources/openapi/openapi.yaml index f2692a900..c060fba3f 100644 --- a/runtime-acm/src/main/resources/openapi/openapi.yaml +++ b/runtime-acm/src/main/resources/openapi/openapi.yaml @@ -640,7 +640,7 @@ paths: 200: description: Serialised instance of - [ToscaServiceTemplate](https://github.com/onap/policy-models/blob/master/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java) + [AutomationCompositionDefinition](https://github.com/onap/policy-clamp/blob/master/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java) containing the requested automation composition definition. headers: X-LatestVersion: @@ -659,12 +659,12 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ToscaServiceTemplate' + $ref: '#/components/schemas/AutomationCompositionDefinition' example: externalValue: 'https://raw.githubusercontent.com/onap/policy-clamp/master/runtime-acm/src/main/resources/openapi/examples/getSingleCompositionDefinition.json' application/yaml: schema: - $ref: '#/components/schemas/ToscaServiceTemplate' + $ref: '#/components/schemas/AutomationCompositionDefinition' example: externalValue: 'https://raw.githubusercontent.com/onap/policy-clamp/master/runtime-acm/src/main/resources/openapi/examples/getSingleCompositionDefinition.yaml' 401: @@ -1578,6 +1578,9 @@ components: ToscaServiceTemplate: title: ToscaServiceTemplate type: object + AutomationCompositionDefinition: + title: AutomationCompositionDefinition + type: object AutomationComposition: title: AutomationComposition type: object diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java index fe0180a74..6ecb8e6f2 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -88,7 +88,7 @@ class CommissioningProviderTest { var provider = new CommissioningProvider(acDefinitionProvider, acProvider, supervisionHandler, participantProvider); var affectedDefinitions = provider - .createAutomationCompositionDefinitions(serviceTemplate).getAffectedAutomationCompositionDefinitions(); + .createAutomationCompositionDefinition(serviceTemplate).getAffectedAutomationCompositionDefinitions(); verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate); verify(supervisionHandler).handleSendCommissionMessage(acmDefinition); // Response should return the number of node templates present in the service template diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java index c84d7ea80..53fa945b2 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,6 +39,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; @@ -159,8 +160,8 @@ class CommissioningControllerTest extends CommonRestController { invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId); resp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - var entity = resp.readEntity(ToscaServiceTemplate.class); - assertThat(entity.getDataTypes()).containsKey(toscaDataType.getName()); + var entity = resp.readEntity(AutomationCompositionDefinition.class); + assertThat(entity.getServiceTemplate().getDataTypes()).containsKey(toscaDataType.getName()); } @Test diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java index e6f7118da..461f4ee28 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java @@ -61,7 +61,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles({ "test", "default" }) -public class ParticipantControllerTest extends CommonRestController { +class ParticipantControllerTest extends CommonRestController { private static final String PARTICIPANTS_ENDPOINT = "participants"; @LocalServerPort diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java index 1db95e4b5..10332117c 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java @@ -95,13 +95,15 @@ class SupervisionHandlerTest { automationComposition.setState(AutomationCompositionState.PASSIVE); automationComposition.setCompositionId(UUID.randomUUID()); - var automationCompositionProvider = mock(AutomationCompositionProvider.class); var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class); - when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn( - Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML))); + var acDefinition = new AutomationCompositionDefinition(); + acDefinition.setCompositionId(automationComposition.getCompositionId()); + acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML)); + when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var automationCompositionProvider = mock(AutomationCompositionProvider.class); var handler = new SupervisionHandler(automationCompositionProvider, acDefinitionProvider, mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher, mock(ParticipantUpdatePublisher.class)); @@ -302,8 +304,11 @@ class SupervisionHandlerTest { var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class); when(acDefinitionProvider.getServiceTemplateList(any(), any())).thenReturn(List .of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML)))); - when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())) - .thenReturn(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML)); + + var acDefinition = new AutomationCompositionDefinition(); + acDefinition.setCompositionId(automationComposition.getCompositionId()); + acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML)); + when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition); return new SupervisionHandler(automationCompositionProvider, acDefinitionProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher, |