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.Date;
25 import java.util.List;
26 import javax.persistence.AttributeOverride;
27 import javax.persistence.AttributeOverrides;
28 import javax.persistence.Column;
29 import javax.persistence.EmbeddedId;
30 import javax.persistence.Entity;
31 import javax.persistence.Inheritance;
32 import javax.persistence.InheritanceType;
33 import javax.persistence.Table;
35 import lombok.EqualsAndHashCode;
36 import lombok.NoArgsConstructor;
37 import lombok.NonNull;
38 import org.apache.commons.lang3.builder.CompareToBuilder;
39 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
40 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
41 import org.onap.policy.common.parameters.annotations.NotNull;
42 import org.onap.policy.models.base.PfAuthorative;
43 import org.onap.policy.models.base.PfConcept;
44 import org.onap.policy.models.base.PfConceptKey;
45 import org.onap.policy.models.base.PfKey;
46 import org.onap.policy.models.base.PfTimestampKey;
47 import org.onap.policy.models.base.validation.annotations.VerifyKey;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
51 * Class to represent a controlloop element statistics in the database.
53 * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech)
56 @Table(name = "ClElementStatistics")
57 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
60 @EqualsAndHashCode(callSuper = false)
61 public class JpaClElementStatistics extends PfConcept implements PfAuthorative<ClElementStatistics>, Serializable {
63 private static final long serialVersionUID = 621426717868738629L;
68 private PfTimestampKey key = new PfTimestampKey();
74 @AttributeOverride(name = "name", column = @Column(name = "cl_element_name")),
75 @AttributeOverride(name = "version", column = @Column(name = "cl_element_version"))
77 private PfConceptKey clElementId;
82 private ControlLoopState state;
85 private long clElementUptime;
88 * The Key Constructor creates a {@link JpaClElementStatistics} object with the given Timestamp key.
92 public JpaClElementStatistics(@NonNull final PfTimestampKey key) {
93 this(key, new PfConceptKey());
97 * The Key Constructor creates a {@link JpaClElementStatistics} object with all mandatory fields.
100 * @param clElementId the TOSCA definition of the control loop element
102 public JpaClElementStatistics(@NonNull final PfTimestampKey key, @NonNull final PfConceptKey clElementId) {
104 this.clElementId = clElementId;
110 * @param copyConcept the concept to copy from
112 public JpaClElementStatistics(@NonNull final JpaClElementStatistics copyConcept) {
114 this.key = new PfTimestampKey(copyConcept.key);
115 this.clElementId = new PfConceptKey(copyConcept.clElementId);
116 this.state = copyConcept.state;
117 this.clElementUptime = copyConcept.clElementUptime;
122 * Authorative constructor.
124 * @param authorativeConcept the authorative concept to copy from
126 public JpaClElementStatistics(@NonNull final ClElementStatistics authorativeConcept) {
127 this.fromAuthorative(authorativeConcept);
133 public ClElementStatistics toAuthorative() {
134 ClElementStatistics clElementStatistics = new ClElementStatistics();
135 clElementStatistics.setTimeStamp(new Date(key.getTimeStamp().getTime()));
136 clElementStatistics.setControlLoopElementId(new ToscaConceptIdentifier(clElementId));
137 clElementStatistics.setControlLoopState(state);
138 clElementStatistics.setClElementUptime(clElementUptime);
140 return clElementStatistics;
144 public void fromAuthorative(@NonNull ClElementStatistics clElementStatistics) {
146 if (this.key == null || this.getKey().isNullKey()) {
149 clElementStatistics.getControlLoopElementId().getName(),
150 clElementStatistics.getControlLoopElementId().getVersion(),
151 clElementStatistics.getTimeStamp()));
154 this.setClElementId(clElementStatistics.getControlLoopElementId().asConceptKey());
155 this.setState(clElementStatistics.getControlLoopState());
156 this.setClElementUptime(clElementStatistics.getClElementUptime());
160 public List<PfKey> getKeys() {
161 return getKey().getKeys();
165 public void clean() {
172 public int compareTo(PfConcept otherConcept) {
173 if (otherConcept == null) {
176 if (this == otherConcept) {
179 if (getClass() != otherConcept.getClass()) {
180 return getClass().getName().compareTo(otherConcept.getClass().getName());
183 final JpaClElementStatistics other = (JpaClElementStatistics) otherConcept;
184 return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state)
185 .append(this.clElementUptime, other.clElementUptime).toComparison();