diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-06-04 15:08:42 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-06-06 16:14:28 +0000 |
commit | 8d4778eb89eed2da8ba3998d04063775360dd3e2 (patch) | |
tree | 6563915ce082e514dcba30bb73b9123cac9ff852 /models/src/main | |
parent | a48f784beca5e7aa189217c52cfa83452cf8fc47 (diff) |
Create model in clamp runtime for the replica table
Issue-ID: POLICY-5034
Change-Id: Id412b392e994e3ac18f03ccde0b69481b0fd48f6
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main')
4 files changed, 173 insertions, 4 deletions
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 5bdf4d312..6ddec6179 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 @@ -49,6 +49,9 @@ public class Participant { @NonNull private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes = new HashMap<>(); + @NonNull + private Map<UUID, ParticipantReplica> replicas = new HashMap<>(); + /** * Copy constructor. * @@ -60,5 +63,6 @@ public class Participant { this.lastMsg = otherParticipant.lastMsg; this.participantSupportedElementTypes = PfUtils.mapMap(otherParticipant.getParticipantSupportedElementTypes(), ParticipantSupportedElementType::new); + this.replicas = PfUtils.mapMap(otherParticipant.replicas, ParticipantReplica::new); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java new file mode 100644 index 000000000..23f72191a --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * 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 lombok.NonNull; + +@NoArgsConstructor +@Data +@EqualsAndHashCode +public class ParticipantReplica { + + @NonNull + private UUID replicaId; + + @NonNull + private ParticipantState participantState = ParticipantState.ON_LINE; + + @NonNull + private String lastMsg; + + /** + * Copy constructor. + * + * @param other the ParticipantReplica to copy from + */ + public ParticipantReplica(ParticipantReplica other) { + this.replicaId = other.replicaId; + this.participantState = other.participantState; + this.lastMsg = other.lastMsg; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java index cfde55767..f35fff9e7 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java @@ -41,6 +41,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; 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.utils.TimestampHelper; @@ -84,11 +86,18 @@ public class JpaParticipant extends Validated foreignKey = @ForeignKey(name = "supported_element_fk")) private List<@NotNull @Valid JpaParticipantSupportedElementType> supportedElements; + @NotNull + @OneToMany + @LazyCollection(LazyCollectionOption.FALSE) + @JoinColumn(name = "participantId", referencedColumnName = "participantId", + foreignKey = @ForeignKey(name = "participant_replica_fk")) + private List<@NotNull @Valid JpaParticipantReplica> replicas; + /** * The Default Constructor creates a {@link JpaParticipant} object with a null key. */ public JpaParticipant() { - this(UUID.randomUUID().toString(), ParticipantState.ON_LINE, new ArrayList<>()); + this(UUID.randomUUID().toString(), ParticipantState.ON_LINE, new ArrayList<>(), new ArrayList<>()); } /** @@ -96,13 +105,17 @@ public class JpaParticipant extends Validated * * @param participantId the participant id * @param participantState the state of the participant + * @param supportedElements the list of supported Element Type + * @param replicas the list of replica */ public JpaParticipant(@NonNull String participantId, @NonNull final ParticipantState participantState, - @NonNull final List<JpaParticipantSupportedElementType> supportedElements) { + @NonNull final List<JpaParticipantSupportedElementType> supportedElements, + @NonNull final List<JpaParticipantReplica> replicas) { this.participantId = participantId; this.participantState = participantState; this.supportedElements = supportedElements; this.lastMsg = TimestampHelper.nowTimestamp(); + this.replicas = replicas; } /** @@ -115,6 +128,7 @@ public class JpaParticipant extends Validated this.description = copyConcept.description; this.participantId = copyConcept.participantId; this.supportedElements = copyConcept.supportedElements; + this.replicas = copyConcept.replicas; this.lastMsg = copyConcept.lastMsg; } @@ -139,7 +153,9 @@ public class JpaParticipant extends Validated participant.getParticipantSupportedElementTypes() .put(UUID.fromString(element.getId()), element.toAuthorative()); } - + for (var replica : this.replicas) { + participant.getReplicas().put(UUID.fromString(replica.getReplicaId()), replica.toAuthorative()); + } return participant; } @@ -148,14 +164,22 @@ public class JpaParticipant extends Validated this.setParticipantState(participant.getParticipantState()); this.participantId = participant.getParticipantId().toString(); this.lastMsg = TimestampHelper.toTimestamp(participant.getLastMsg()); - this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size()); + this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size()); for (var elementEntry : participant.getParticipantSupportedElementTypes().entrySet()) { var jpaParticipantSupportedElementType = new JpaParticipantSupportedElementType(); jpaParticipantSupportedElementType.setParticipantId(this.participantId); jpaParticipantSupportedElementType.fromAuthorative(elementEntry.getValue()); this.supportedElements.add(jpaParticipantSupportedElementType); } + + this.replicas = new ArrayList<>(participant.getReplicas().size()); + for (var replicaEntry : participant.getReplicas().entrySet()) { + var jpaReplica = new JpaParticipantReplica(); + jpaReplica.setParticipantId(this.participantId); + jpaReplica.fromAuthorative(replicaEntry.getValue()); + this.replicas.add(jpaReplica); + } } @Override diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplica.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplica.java new file mode 100644 index 000000000..beaab601f --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplica.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * 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 jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.Table; +import java.sql.Timestamp; +import java.util.UUID; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.Validated; + +@Entity +@Table(name = "ParticipantReplica") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaParticipantReplica extends Validated implements PfAuthorative<ParticipantReplica> { + + @Id + @NotNull + private String replicaId; + + @NotNull + @Column + private String participantId; + + @Column + @NotNull + private ParticipantState participantState; + + @Column + @NotNull + private Timestamp lastMsg; + + public JpaParticipantReplica() { + this(UUID.randomUUID().toString(), UUID.randomUUID().toString()); + } + + public JpaParticipantReplica(@NonNull String replicaId, @NonNull String participantId) { + this.replicaId = replicaId; + this.participantId = participantId; + } + + @Override + public ParticipantReplica toAuthorative() { + var participantReplica = new ParticipantReplica(); + participantReplica.setReplicaId(UUID.fromString(replicaId)); + participantReplica.setParticipantState(participantState); + participantReplica.setLastMsg(lastMsg.toString()); + return participantReplica; + } + + @Override + public void fromAuthorative(@NonNull ParticipantReplica participantReplica) { + this.replicaId = participantReplica.getReplicaId().toString(); + this.participantState = participantReplica.getParticipantState(); + this.lastMsg = TimestampHelper.toTimestamp(participantReplica.getLastMsg()); + } +} |