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"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
109 private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
112 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
113 private Set<LoopLog> loopLogs = new HashSet<>();
121 public Loop(String name, String blueprint, String svgRepresentation) {
123 this.svgRepresentation = svgRepresentation;
124 this.blueprint = blueprint;
125 this.lastComputedState = LoopState.DESIGN;
126 this.globalPropertiesJson = new JsonObject();
129 public String getName() {
133 void setName(String name) {
137 String getDcaeDeploymentId() {
138 return dcaeDeploymentId;
141 void setDcaeDeploymentId(String dcaeDeploymentId) {
142 this.dcaeDeploymentId = dcaeDeploymentId;
145 String getDcaeDeploymentStatusUrl() {
146 return dcaeDeploymentStatusUrl;
149 void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
150 this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
153 String getSvgRepresentation() {
154 return svgRepresentation;
157 void setSvgRepresentation(String svgRepresentation) {
158 this.svgRepresentation = svgRepresentation;
161 String getBlueprint() {
165 void setBlueprint(String blueprint) {
166 this.blueprint = blueprint;
169 LoopState getLastComputedState() {
170 return lastComputedState;
173 void setLastComputedState(LoopState lastComputedState) {
174 this.lastComputedState = lastComputedState;
177 Set<OperationalPolicy> getOperationalPolicies() {
178 return operationalPolicies;
181 void setOperationalPolicies(Set<OperationalPolicy> operationalPolicies) {
182 this.operationalPolicies = operationalPolicies;
185 Set<MicroServicePolicy> getMicroServicePolicies() {
186 return microServicePolicies;
189 void setMicroServicePolicies(Set<MicroServicePolicy> microServicePolicies) {
190 this.microServicePolicies = microServicePolicies;
193 JsonObject getGlobalPropertiesJson() {
194 return globalPropertiesJson;
197 void setGlobalPropertiesJson(JsonObject globalPropertiesJson) {
198 this.globalPropertiesJson = globalPropertiesJson;
201 Set<LoopLog> getLoopLogs() {
205 void setLoopLogs(Set<LoopLog> loopLogs) {
206 this.loopLogs = loopLogs;
209 void addOperationalPolicy(OperationalPolicy opPolicy) {
210 operationalPolicies.add(opPolicy);
211 opPolicy.setLoop(this);
214 void addMicroServicePolicy(MicroServicePolicy microServicePolicy) {
215 microServicePolicies.add(microServicePolicy);
216 microServicePolicy.getUsedByLoops().add(this);
219 void addLog(LoopLog log) {
224 String getDcaeBlueprintId() {
225 return dcaeBlueprintId;
228 void setDcaeBlueprintId(String dcaeBlueprintId) {
229 this.dcaeBlueprintId = dcaeBlueprintId;
232 JsonObject getModelPropertiesJson() {
233 return modelPropertiesJson;
236 void setModelPropertiesJson(JsonObject modelPropertiesJson) {
237 this.modelPropertiesJson = modelPropertiesJson;
241 * Generate the loop name.
245 * @param serviceVersion
246 * The service version
247 * @param resourceName
249 * @param blueprintFileName
250 * The blueprint file name
251 * @return The generated loop name
253 static String generateLoopName(String serviceName, String serviceVersion, String resourceName,
254 String blueprintFilename) {
255 StringBuilder buffer = new StringBuilder("LOOP_").append(serviceName).append("_v").append(serviceVersion)
256 .append("_").append(resourceName).append("_").append(blueprintFilename.replaceAll(".yaml", ""));
257 return buffer.toString().replace('.', '_').replaceAll(" ", "");
261 public int hashCode() {
262 final int prime = 31;
264 result = prime * result + ((name == null) ? 0 : name.hashCode());
269 public boolean equals(Object obj) {
276 if (getClass() != obj.getClass()) {
279 Loop other = (Loop) obj;
281 if (other.name != null) {
284 } else if (!name.equals(other.name)) {