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.dao.model.jsontype.StringJsonUserType;
50 import org.onap.clamp.loop.log.LoopLog;
51 import org.onap.clamp.policy.microservice.MicroServicePolicy;
52 import org.onap.clamp.policy.operational.OperationalPolicy;
55 @Table(name = "loops")
56 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
57 public class Loop implements Serializable {
60 * The serial version id.
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(columnDefinition = "MEDIUMTEXT", name = "svg_representation")
82 private String svgRepresentation;
86 @Column(columnDefinition = "json", name = "global_properties_json")
87 private JsonObject globalPropertiesJson;
91 @Column(columnDefinition = "json", name = "model_properties_json")
92 private JsonObject modelPropertiesJson;
94 @Column(columnDefinition = "MEDIUMTEXT", nullable = false, name = "blueprint_yaml")
95 private String blueprint;
98 @Column(nullable = false, name = "last_computed_state")
99 @Enumerated(EnumType.STRING)
100 private LoopState lastComputedState;
103 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
104 private Set<OperationalPolicy> operationalPolicies = new HashSet<>();
107 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
108 @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"),
109 inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
110 private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
113 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
114 private Set<LoopLog> loopLogs = new HashSet<>();
122 public Loop(String name, String blueprint, String svgRepresentation) {
124 this.svgRepresentation = svgRepresentation;
125 this.blueprint = blueprint;
126 this.lastComputedState = LoopState.DESIGN;
127 this.globalPropertiesJson = new JsonObject();
130 public String getName() {
134 void setName(String name) {
138 public String getDcaeDeploymentId() {
139 return dcaeDeploymentId;
142 public void setDcaeDeploymentId(String dcaeDeploymentId) {
143 this.dcaeDeploymentId = dcaeDeploymentId;
146 public String getDcaeDeploymentStatusUrl() {
147 return dcaeDeploymentStatusUrl;
150 public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
151 this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
154 public String getSvgRepresentation() {
155 return svgRepresentation;
158 void setSvgRepresentation(String svgRepresentation) {
159 this.svgRepresentation = svgRepresentation;
162 public String getBlueprint() {
166 void setBlueprint(String blueprint) {
167 this.blueprint = blueprint;
170 public LoopState getLastComputedState() {
171 return lastComputedState;
174 public void setLastComputedState(LoopState lastComputedState) {
175 this.lastComputedState = lastComputedState;
178 Set<OperationalPolicy> getOperationalPolicies() {
179 return operationalPolicies;
182 void setOperationalPolicies(Set<OperationalPolicy> operationalPolicies) {
183 this.operationalPolicies = operationalPolicies;
186 public Set<MicroServicePolicy> getMicroServicePolicies() {
187 return microServicePolicies;
190 void setMicroServicePolicies(Set<MicroServicePolicy> microServicePolicies) {
191 this.microServicePolicies = microServicePolicies;
194 JsonObject getGlobalPropertiesJson() {
195 return globalPropertiesJson;
198 void setGlobalPropertiesJson(JsonObject globalPropertiesJson) {
199 this.globalPropertiesJson = globalPropertiesJson;
202 Set<LoopLog> getLoopLogs() {
206 void setLoopLogs(Set<LoopLog> loopLogs) {
207 this.loopLogs = loopLogs;
210 void addOperationalPolicy(OperationalPolicy opPolicy) {
211 operationalPolicies.add(opPolicy);
212 opPolicy.setLoop(this);
215 void addMicroServicePolicy(MicroServicePolicy microServicePolicy) {
216 microServicePolicies.add(microServicePolicy);
217 microServicePolicy.getUsedByLoops().add(this);
220 void addLog(LoopLog log) {
225 public String getDcaeBlueprintId() {
226 return dcaeBlueprintId;
229 void setDcaeBlueprintId(String dcaeBlueprintId) {
230 this.dcaeBlueprintId = dcaeBlueprintId;
233 public JsonObject getModelPropertiesJson() {
234 return modelPropertiesJson;
237 void setModelPropertiesJson(JsonObject modelPropertiesJson) {
238 this.modelPropertiesJson = modelPropertiesJson;
242 * Generate the loop name.
243 * @param serviceName The service name
244 * @param serviceVersion The service version
245 * @param resourceName The resource name
246 * @param blueprintFileName The blueprint file name
247 * @return The generated loop name
249 public static String generateLoopName(String serviceName, String serviceVersion, String resourceName,
250 String blueprintFilename) {
251 StringBuilder buffer = new StringBuilder("LOOP_").append(serviceName).append("_v").append(serviceVersion)
252 .append("_").append(resourceName).append("_").append(blueprintFilename.replaceAll(".yaml", ""));
253 return buffer.toString().replace('.', '_').replaceAll(" ", "");
257 public int hashCode() {
258 final int prime = 31;
260 result = prime * result + ((name == null) ? 0 : name.hashCode());
265 public boolean equals(Object obj) {
272 if (getClass() != obj.getClass()) {
275 Loop other = (Loop) obj;
277 if (other.name != null) {
280 } else if (!name.equals(other.name)) {