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.policy.microservice;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.google.gson.JsonObject;
29 import com.google.gson.annotations.Expose;
30 import java.io.IOException;
31 import java.io.Serializable;
32 import java.util.HashSet;
34 import javax.persistence.Column;
35 import javax.persistence.Entity;
36 import javax.persistence.FetchType;
37 import javax.persistence.Id;
38 import javax.persistence.ManyToMany;
39 import javax.persistence.Table;
40 import javax.persistence.Transient;
41 import org.hibernate.annotations.TypeDef;
42 import org.hibernate.annotations.TypeDefs;
43 import org.onap.clamp.clds.tosca.update.UnknownComponentException;
44 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
45 import org.onap.clamp.loop.Loop;
46 import org.onap.clamp.loop.template.LoopElementModel;
47 import org.onap.clamp.loop.template.PolicyModel;
48 import org.onap.clamp.policy.Policy;
51 @Table(name = "micro_service_policies")
52 @TypeDefs({@TypeDef(name = "json", typeClass = StringJsonUserType.class)})
53 public class MicroServicePolicy extends Policy implements Serializable {
55 * The serial version ID.
57 private static final long serialVersionUID = 6271238288583332616L;
60 private static final EELFLogger logger = EELFManager.getInstance().getLogger(MicroServicePolicy.class);
64 @Column(nullable = false, name = "name", unique = true)
68 @Column(name = "context")
69 private String context;
72 @Column(name = "device_type_scope")
73 private String deviceTypeScope;
76 @Column(name = "shared", nullable = false)
77 private Boolean shared;
79 @ManyToMany(mappedBy = "microServicePolicies", fetch = FetchType.EAGER)
80 private Set<Loop> usedByLoops = new HashSet<>();
83 @Column(name = "dcae_deployment_id")
84 private String dcaeDeploymentId;
87 @Column(name = "dcae_deployment_status_url")
88 private String dcaeDeploymentStatusUrl;
91 @Column(name = "dcae_blueprint_id")
92 private String dcaeBlueprintId;
94 public MicroServicePolicy() {
99 * The constructor that creates the json representation from the policyTosca
100 * using the ToscaYamlToJsonConvertor.
102 * @param name The name of the MicroService
103 * @param policyModel The policy model of the MicroService
104 * @param shared The flag indicate whether the MicroService is shared
106 public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared, LoopElementModel loopElementModel) {
108 this.setPolicyModel(policyModel);
109 this.shared = shared;
111 this.setJsonRepresentation(Policy.generateJsonRepresentationFromToscaModel(policyModel.getPolicyModelTosca(),policyModel.getPolicyModelType()));
112 } catch (UnknownComponentException | NullPointerException | IOException e) {
113 logger.error("Unable to generate the microservice policy Schema ... ", e);
114 this.setJsonRepresentation(new JsonObject());
116 this.setLoopElementModel(loopElementModel);
120 * The constructor that does not make use of ToscaYamlToJsonConvertor but take
121 * the jsonRepresentation instead.
123 * @param name The name of the MicroService
124 * @param policyModel The policy model type of the MicroService
125 * @param shared The flag indicate whether the MicroService is
127 * @param jsonRepresentation The UI representation in json format
128 * @param loopElementModel The loop element model from which this instance should be created
129 * @param pdpGroup The Pdp Group info
130 * @param pdpSubgroup The Pdp Subgrouop info
132 public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared,
133 JsonObject jsonRepresentation, LoopElementModel loopElementModel, String pdpGroup, String pdpSubgroup) {
135 this.setPolicyModel(policyModel);
136 this.shared = shared;
137 this.setJsonRepresentation(jsonRepresentation);
138 this.setLoopElementModel(loopElementModel);
139 this.setPdpGroup(pdpGroup);
140 this.setPdpSubgroup(pdpSubgroup);
144 public String getName() {
151 * @param name the name to set
154 public void setName(String name) {
158 public Boolean getShared() {
162 void setShared(Boolean shared) {
163 this.shared = shared;
166 public Set<Loop> getUsedByLoops() {
170 void setUsedByLoops(Set<Loop> usedBy) {
171 this.usedByLoops = usedBy;
174 public String getContext() {
178 public void setContext(String context) {
179 this.context = context;
182 public String getDeviceTypeScope() {
183 return deviceTypeScope;
186 public void setDeviceTypeScope(String deviceTypeScope) {
187 this.deviceTypeScope = deviceTypeScope;
191 * dcaeDeploymentId getter.
193 * @return the dcaeDeploymentId
195 public String getDcaeDeploymentId() {
196 return dcaeDeploymentId;
200 * dcaeDeploymentId setter.
202 * @param dcaeDeploymentId the dcaeDeploymentId to set
204 public void setDcaeDeploymentId(String dcaeDeploymentId) {
205 this.dcaeDeploymentId = dcaeDeploymentId;
209 * dcaeDeploymentStatusUrl getter.
211 * @return the dcaeDeploymentStatusUrl
213 public String getDcaeDeploymentStatusUrl() {
214 return dcaeDeploymentStatusUrl;
218 * dcaeDeploymentStatusUrl setter.
220 * @param dcaeDeploymentStatusUrl the dcaeDeploymentStatusUrl to set
222 public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
223 this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
227 * dcaeBlueprintId getter.
229 * @return the dcaeBlueprintId
231 public String getDcaeBlueprintId() {
232 return dcaeBlueprintId;
236 * dcaeBlueprintId setter.
238 * @param dcaeBlueprintId the dcaeBlueprintId to set
240 void setDcaeBlueprintId(String dcaeBlueprintId) {
241 this.dcaeBlueprintId = dcaeBlueprintId;
245 public int hashCode() {
246 final int prime = 31;
248 result = prime * result + ((name == null) ? 0 : name.hashCode());
253 public boolean equals(Object obj) {
260 if (getClass() != obj.getClass()) {
263 MicroServicePolicy other = (MicroServicePolicy) obj;
265 if (other.name != null) {
268 } else if (!name.equals(other.name)) {