2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
25 import java.io.Serializable;
26 import java.util.List;
27 import java.util.UUID;
28 import javax.persistence.AttributeOverride;
29 import javax.persistence.Column;
30 import javax.persistence.EmbeddedId;
31 import javax.persistence.Entity;
32 import javax.persistence.Inheritance;
33 import javax.persistence.InheritanceType;
34 import javax.persistence.Table;
35 import lombok.AllArgsConstructor;
37 import lombok.EqualsAndHashCode;
38 import lombok.NonNull;
39 import org.apache.commons.lang3.builder.CompareToBuilder;
40 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
41 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
42 import org.onap.policy.common.parameters.annotations.NotNull;
43 import org.onap.policy.models.base.PfAuthorative;
44 import org.onap.policy.models.base.PfConcept;
45 import org.onap.policy.models.base.PfConceptKey;
46 import org.onap.policy.models.base.PfKey;
47 import org.onap.policy.models.base.PfReferenceTimestampKey;
48 import org.onap.policy.models.base.validation.annotations.VerifyKey;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
52 * Class to represent a controlloop element statistics in the database.
54 * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech)
57 @Table(name = "ClElementStatistics")
58 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
61 @EqualsAndHashCode(callSuper = false)
62 public class JpaClElementStatistics extends PfConcept implements PfAuthorative<ClElementStatistics>, Serializable {
64 private static final long serialVersionUID = 621426717868738629L;
69 private PfReferenceTimestampKey key = new PfReferenceTimestampKey();
75 @AttributeOverride(name = "name", column = @Column(name = "participant_name"))
76 @AttributeOverride(name = "version", column = @Column(name = "participant_version"))
77 private PfConceptKey participantId;
82 private ControlLoopState state;
85 private long clElementUptime;
89 * The Default Constructor creates a {@link JpaClElementStatistics} object with a null key.
91 public JpaClElementStatistics() {
92 this(new PfReferenceTimestampKey());
97 * The Key Constructor creates a {@link JpaClElementStatistics} object with the given Reference Timestamp key.
101 public JpaClElementStatistics(@NonNull final PfReferenceTimestampKey key) {
102 this(key, new PfConceptKey(), ControlLoopState.PASSIVE, 0L);
106 * The Key Constructor creates a {@link JpaClElementStatistics} object with all mandatory fields.
109 * @param participantId the TOSCA definition of the control loop element
111 public JpaClElementStatistics(@NonNull final PfReferenceTimestampKey key,
112 @NonNull final PfConceptKey participantId) {
114 this.participantId = participantId;
120 * @param copyConcept the concept to copy from
122 public JpaClElementStatistics(@NonNull final JpaClElementStatistics copyConcept) {
124 this.key = new PfReferenceTimestampKey(copyConcept.key);
125 this.participantId = new PfConceptKey(copyConcept.participantId);
126 this.state = copyConcept.state;
127 this.clElementUptime = copyConcept.clElementUptime;
132 * Authorative constructor.
134 * @param authorativeConcept the authorative concept to copy from
136 public JpaClElementStatistics(@NonNull final ClElementStatistics authorativeConcept) {
137 this.fromAuthorative(authorativeConcept);
143 public ClElementStatistics toAuthorative() {
144 var clElementStatistics = new ClElementStatistics();
145 clElementStatistics.setId(UUID.fromString(getKey().getReferenceKey().getLocalName()));
146 clElementStatistics.setTimeStamp(key.getInstant());
147 clElementStatistics.setParticipantId(new ToscaConceptIdentifier(participantId));
148 clElementStatistics.setControlLoopState(state);
149 clElementStatistics.setClElementUptime(clElementUptime);
151 return clElementStatistics;
155 public void fromAuthorative(@NonNull ClElementStatistics clElementStatistics) {
157 if (this.key == null || this.getKey().isNullKey()) {
158 this.setKey(new PfReferenceTimestampKey(clElementStatistics.getParticipantId().getName(),
159 clElementStatistics.getParticipantId().getVersion(), clElementStatistics.getId().toString(),
160 clElementStatistics.getTimeStamp()));
163 this.setParticipantId(clElementStatistics.getParticipantId().asConceptKey());
164 this.setState(clElementStatistics.getControlLoopState());
165 this.setClElementUptime(clElementStatistics.getClElementUptime());
169 public List<PfKey> getKeys() {
170 return getKey().getKeys();
174 public void clean() {
176 participantId.clean();
181 public int compareTo(PfConcept otherConcept) {
182 if (otherConcept == null) {
185 if (this == otherConcept) {
188 if (getClass() != otherConcept.getClass()) {
189 return getClass().getName().compareTo(otherConcept.getClass().getName());
192 final JpaClElementStatistics other = (JpaClElementStatistics) otherConcept;
193 return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state)
194 .append(this.clElementUptime, other.clElementUptime).toComparison();