diff options
Diffstat (limited to 'models')
4 files changed, 43 insertions, 3 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 548bc4549..987cb8832 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-2023 Nordix Foundation. + * Copyright (C) 2022-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,6 +49,9 @@ public class AutomationCompositionDefinition { private StateChangeResult stateChangeResult; @NonNull + private String lastMsg; + + @NonNull // Map used to store prime state with key as NodeTemplate Name and value as NodeTemplateState private Map<String, NodeTemplateState> elementStateMap = new HashMap<>(); @@ -62,6 +65,7 @@ public class AutomationCompositionDefinition { this.serviceTemplate = new ToscaServiceTemplate(otherAcmDefinition.serviceTemplate); this.restarting = otherAcmDefinition.restarting; this.state = otherAcmDefinition.state; + this.lastMsg = otherAcmDefinition.lastMsg; this.elementStateMap = PfUtils.mapMap(otherAcmDefinition.elementStateMap, NodeTemplateState::new); this.stateChangeResult = otherAcmDefinition.stateChangeResult; } 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 28689e2fd..1cab89d5d 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-2023 Nordix Foundation. + * Copyright (C) 2022-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.Lob; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import java.sql.Timestamp; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -42,8 +43,8 @@ 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.concepts.StateChangeResult; -import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.annotations.NotNull; import org.onap.policy.common.parameters.annotations.Pattern; @@ -87,6 +88,10 @@ public class JpaAutomationCompositionDefinition extends Validated @Column private StateChangeResult stateChangeResult; + @Column + @NotNull + private Timestamp lastMsg; + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "compositionId", foreignKey = @ForeignKey(name = "dt_element_fk")) private Set<JpaNodeTemplateState> elements = new HashSet<>(); @@ -105,6 +110,7 @@ public class JpaAutomationCompositionDefinition extends Validated acmDefinition.setRestarting(this.restarting); acmDefinition.setState(this.state); acmDefinition.setStateChangeResult(this.stateChangeResult); + acmDefinition.setLastMsg(this.lastMsg.toString()); acmDefinition.setServiceTemplate(this.serviceTemplate.toAuthorative()); for (var element : this.elements) { var key = element.getNodeTemplateId().getName(); @@ -119,6 +125,7 @@ public class JpaAutomationCompositionDefinition extends Validated this.restarting = copyConcept.getRestarting(); this.state = copyConcept.getState(); this.stateChangeResult = copyConcept.getStateChangeResult(); + this.lastMsg = TimestampHelper.toTimestamp(copyConcept.getLastMsg()); this.serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate()); setName(this.serviceTemplate.getName()); setVersion(this.serviceTemplate.getVersion()); 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 9eb5e7a32..46b43f950 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 @@ -37,6 +37,7 @@ import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateStat import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository; import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository; import org.onap.policy.clamp.models.acm.utils.AcmUtils; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -68,6 +69,7 @@ public class AcDefinitionProvider { if (serviceTemplate.getMetadata() == null) { serviceTemplate.setMetadata(new HashMap<>()); } + acmDefinition.setLastMsg(TimestampHelper.now()); serviceTemplate.getMetadata().put("compositionId", compositionId); acmDefinition.setServiceTemplate(serviceTemplate); var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, toscaElementName); @@ -100,6 +102,7 @@ public class AcDefinitionProvider { var acmDefinition = new AutomationCompositionDefinition(); acmDefinition.setCompositionId(compositionId); acmDefinition.setState(AcTypeState.COMMISSIONED); + acmDefinition.setLastMsg(TimestampHelper.now()); acmDefinition.setServiceTemplate(serviceTemplate); var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, toscaElementName); 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 1e067c8f6..85dadc3de 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 @@ -45,8 +45,10 @@ import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateStat import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository; import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository; import org.onap.policy.clamp.models.acm.utils.CommonTestData; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; import org.springframework.data.domain.Example; class AcDefinitionProviderTest { @@ -62,6 +64,29 @@ class AcDefinitionProviderTest { private static ToscaServiceTemplate inputServiceTemplate; + @Test + void testBadRequest() { + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); + + var compositionId = UUID.randomUUID(); + var serviceTemplate = new ToscaServiceTemplate(); + serviceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate()); + serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(new HashMap<>()); + assertThatThrownBy(() -> acDefinitionProvider.updateServiceTemplate(compositionId, serviceTemplate, + "ElementName", "CompositionName")) + .hasMessageMatching("NodeTemplate with element type ElementName must exist!"); + + var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate); + var acmDefinition = getAcDefinition(docServiceTemplate); + assertThatThrownBy(() -> acDefinitionProvider.updateAcDefinition(acmDefinition, "CompositionName")) + .hasMessageStartingWith("\"AutomationCompositionDefinition\" INVALID, item has status INVALID"); + + assertThatThrownBy(() -> acDefinitionProvider.updateAcDefinitionState(compositionId, AcTypeState.PRIMED, + StateChangeResult.NO_ERROR, false)) + .hasMessageStartingWith("update of Automation Composition Definition"); + } + @BeforeAll static void loadServiceTemplate() { inputServiceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); @@ -304,6 +329,7 @@ class AcDefinitionProviderTest { var acmDefinition = new AutomationCompositionDefinition(); acmDefinition.setCompositionId(UUID.randomUUID()); acmDefinition.setState(AcTypeState.COMMISSIONED); + acmDefinition.setLastMsg(TimestampHelper.now()); acmDefinition.setServiceTemplate(docServiceTemplate.toAuthorative()); var nodeTemplateState = new NodeTemplateState(); nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID()); |