2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.loop;
26 import com.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
29 import java.io.Serializable;
30 import java.util.HashSet;
33 import javax.persistence.CascadeType;
34 import javax.persistence.Column;
35 import javax.persistence.Entity;
36 import javax.persistence.EnumType;
37 import javax.persistence.Enumerated;
38 import javax.persistence.FetchType;
39 import javax.persistence.Id;
40 import javax.persistence.JoinColumn;
41 import javax.persistence.JoinTable;
42 import javax.persistence.ManyToMany;
43 import javax.persistence.OneToMany;
44 import javax.persistence.Table;
46 import org.hibernate.annotations.Type;
47 import org.hibernate.annotations.TypeDef;
48 import org.hibernate.annotations.TypeDefs;
49 import org.onap.clamp.loop.log.LoopLog;
50 import org.onap.clamp.policy.microservice.MicroServicePolicy;
51 import org.onap.clamp.policy.operational.OperationalPolicy;
52 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
55 @Table(name = "loops")
56 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
57 public class Loop implements Serializable {
62 private static final long serialVersionUID = -286522707701388642L;
66 @Column(nullable = false, name = "name", unique = true)
70 @Column(name = "dcae_deployment_id")
71 private String dcaeDeploymentId;
74 @Column(name = "dcae_deployment_status_url")
75 private String dcaeDeploymentStatusUrl;
78 @Column(name = "dcae_blueprint_id")
79 private String dcaeBlueprintId;
81 @Column(name = "svg_representation")
82 private String svgRepresentation;
86 @Column(columnDefinition = "json", name = "global_properties_json")
87 private JsonObject globalPropertiesJson;
89 @Column(nullable = false, name = "blueprint_yaml")
90 private String blueprint;
93 @Column(nullable = false, name = "last_computed_state")
94 @Enumerated(EnumType.STRING)
95 private LoopState lastComputedState;
98 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
99 private Set<OperationalPolicy> operationalPolicies = new HashSet<>();
102 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
103 @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
104 private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
107 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
108 private Set<LoopLog> loopLogs = new HashSet<>();
113 public Loop(String name, String blueprint, String svgRepresentation) {
115 this.svgRepresentation = svgRepresentation;
116 this.blueprint = blueprint;
117 this.lastComputedState = LoopState.DESIGN;
118 this.globalPropertiesJson = new JsonObject();
121 public String getName() {
125 void setName(String name) {
129 public String getDcaeDeploymentId() {
130 return dcaeDeploymentId;
133 void setDcaeDeploymentId(String dcaeDeploymentId) {
134 this.dcaeDeploymentId = dcaeDeploymentId;
137 public String getDcaeDeploymentStatusUrl() {
138 return dcaeDeploymentStatusUrl;
141 void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
142 this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
145 public String getSvgRepresentation() {
146 return svgRepresentation;
149 void setSvgRepresentation(String svgRepresentation) {
150 this.svgRepresentation = svgRepresentation;
153 public String getBlueprint() {
157 void setBlueprint(String blueprint) {
158 this.blueprint = blueprint;
161 LoopState getLastComputedState() {
162 return lastComputedState;
165 void setLastComputedState(LoopState lastComputedState) {
166 this.lastComputedState = lastComputedState;
169 Set<OperationalPolicy> getOperationalPolicies() {
170 return operationalPolicies;
173 void setOperationalPolicies(Set<OperationalPolicy> operationalPolicies) {
174 this.operationalPolicies = operationalPolicies;
177 Set<MicroServicePolicy> getMicroServicePolicies() {
178 return microServicePolicies;
181 void setMicroServicePolicies(Set<MicroServicePolicy> microServicePolicies) {
182 this.microServicePolicies = microServicePolicies;
185 JsonObject getGlobalPropertiesJson() {
186 return globalPropertiesJson;
189 void setGlobalPropertiesJson(JsonObject globalPropertiesJson) {
190 this.globalPropertiesJson = globalPropertiesJson;
193 Set<LoopLog> getLoopLogs() {
197 void setLoopLogs(Set<LoopLog> loopLogs) {
198 this.loopLogs = loopLogs;
201 void addOperationalPolicy(OperationalPolicy opPolicy) {
202 operationalPolicies.add(opPolicy);
203 opPolicy.setLoop(this);
206 void addMicroServicePolicy(MicroServicePolicy microServicePolicy) {
207 microServicePolicies.add(microServicePolicy);
208 microServicePolicy.getUsedByLoops().add(this);
211 void addLog(LoopLog log) {
216 public String getDcaeBlueprintId() {
217 return dcaeBlueprintId;
220 public void setDcaeBlueprintId(String dcaeBlueprintId) {
221 this.dcaeBlueprintId = dcaeBlueprintId;
225 public int hashCode() {
226 final int prime = 31;
228 result = prime * result + ((name == null) ? 0 : name.hashCode());
233 public boolean equals(Object obj) {
238 if (getClass() != obj.getClass())
240 Loop other = (Loop) obj;
242 if (other.name != null)
244 } else if (!name.equals(other.name))