2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
23 import java.io.Serializable;
24 import java.util.List;
25 import javax.persistence.AttributeOverride;
26 import javax.persistence.Column;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Inheritance;
30 import javax.persistence.InheritanceType;
31 import javax.persistence.Table;
33 import lombok.EqualsAndHashCode;
34 import lombok.NoArgsConstructor;
35 import lombok.NonNull;
36 import org.apache.commons.lang3.builder.CompareToBuilder;
37 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
38 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
39 import org.onap.policy.common.parameters.annotations.NotNull;
40 import org.onap.policy.models.base.PfAuthorative;
41 import org.onap.policy.models.base.PfConcept;
42 import org.onap.policy.models.base.PfConceptKey;
43 import org.onap.policy.models.base.PfKey;
44 import org.onap.policy.models.base.PfTimestampKey;
45 import org.onap.policy.models.base.validation.annotations.VerifyKey;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
49 * Class to represent a controlloop element statistics in the database.
51 * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech)
54 @Table(name = "ClElementStatistics")
55 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
58 @EqualsAndHashCode(callSuper = false)
59 public class JpaClElementStatistics extends PfConcept implements PfAuthorative<ClElementStatistics>, Serializable {
61 private static final long serialVersionUID = 621426717868738629L;
66 private PfTimestampKey key = new PfTimestampKey();
71 @AttributeOverride(name = "name", column = @Column(name = "cl_element_name"))
72 @AttributeOverride(name = "version", column = @Column(name = "cl_element_version"))
73 private PfConceptKey clElementId;
78 private ControlLoopState state;
81 private long clElementUptime;
84 * The Key Constructor creates a {@link JpaClElementStatistics} object with the given Timestamp key.
88 public JpaClElementStatistics(@NonNull final PfTimestampKey key) {
89 this(key, new PfConceptKey());
93 * The Key Constructor creates a {@link JpaClElementStatistics} object with all mandatory fields.
96 * @param clElementId the TOSCA definition of the control loop element
98 public JpaClElementStatistics(@NonNull final PfTimestampKey key, @NonNull final PfConceptKey clElementId) {
100 this.clElementId = clElementId;
106 * @param copyConcept the concept to copy from
108 public JpaClElementStatistics(@NonNull final JpaClElementStatistics copyConcept) {
110 this.key = new PfTimestampKey(copyConcept.key);
111 this.clElementId = new PfConceptKey(copyConcept.clElementId);
112 this.state = copyConcept.state;
113 this.clElementUptime = copyConcept.clElementUptime;
118 * Authorative constructor.
120 * @param authorativeConcept the authorative concept to copy from
122 public JpaClElementStatistics(@NonNull final ClElementStatistics authorativeConcept) {
123 this.fromAuthorative(authorativeConcept);
127 public ClElementStatistics toAuthorative() {
128 ClElementStatistics clElementStatistics = new ClElementStatistics();
129 clElementStatistics.setTimeStamp(key.getTimeStamp().toInstant());
130 clElementStatistics.setControlLoopElementId(new ToscaConceptIdentifier(clElementId));
131 clElementStatistics.setControlLoopState(state);
132 clElementStatistics.setClElementUptime(clElementUptime);
134 return clElementStatistics;
138 public void fromAuthorative(@NonNull ClElementStatistics clElementStatistics) {
140 if (this.key == null || this.getKey().isNullKey()) {
143 clElementStatistics.getControlLoopElementId().getName(),
144 clElementStatistics.getControlLoopElementId().getVersion(),
145 clElementStatistics.getTimeStamp()));
148 this.setClElementId(clElementStatistics.getControlLoopElementId().asConceptKey());
149 this.setState(clElementStatistics.getControlLoopState());
150 this.setClElementUptime(clElementStatistics.getClElementUptime());
154 public List<PfKey> getKeys() {
155 return getKey().getKeys();
159 public void clean() {
166 public int compareTo(PfConcept otherConcept) {
167 if (otherConcept == null) {
170 if (this == otherConcept) {
173 if (getClass() != otherConcept.getClass()) {
174 return getClass().getName().compareTo(otherConcept.getClass().getName());
177 final JpaClElementStatistics other = (JpaClElementStatistics) otherConcept;
178 return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state)
179 .append(this.clElementUptime, other.clElementUptime).toComparison();