diff options
Diffstat (limited to 'models/src/main/java/org')
7 files changed, 232 insertions, 19 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(); } /** |