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.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
28 import java.io.Serializable;
29 import java.util.HashSet;
31 import javax.persistence.Column;
32 import javax.persistence.Entity;
33 import javax.persistence.FetchType;
34 import javax.persistence.Id;
35 import javax.persistence.ManyToMany;
36 import javax.persistence.Table;
37 import org.apache.commons.lang3.RandomStringUtils;
38 import org.hibernate.annotations.TypeDef;
39 import org.hibernate.annotations.TypeDefs;
40 import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
41 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
42 import org.onap.clamp.loop.Loop;
43 import org.onap.clamp.loop.service.Service;
44 import org.onap.clamp.loop.template.LoopElementModel;
45 import org.onap.clamp.loop.template.PolicyModel;
46 import org.onap.clamp.policy.Policy;
49 @Table(name = "micro_service_policies")
50 @TypeDefs({@TypeDef(name = "json", typeClass = StringJsonUserType.class)})
51 public class MicroServicePolicy extends Policy implements Serializable {
53 * The serial version ID.
55 private static final long serialVersionUID = 6271238288583332616L;
59 @Column(nullable = false, name = "name", unique = true)
63 @Column(name = "context")
64 private String context;
67 @Column(name = "device_type_scope")
68 private String deviceTypeScope;
71 @Column(name = "shared", nullable = false)
72 private Boolean shared;
74 @ManyToMany(mappedBy = "microServicePolicies", fetch = FetchType.EAGER)
75 private Set<Loop> usedByLoops = new HashSet<>();
78 @Column(name = "dcae_deployment_id")
79 private String dcaeDeploymentId;
82 @Column(name = "dcae_deployment_status_url")
83 private String dcaeDeploymentStatusUrl;
86 @Column(name = "dcae_blueprint_id")
87 private String dcaeBlueprintId;
90 * Constructor for serialization.
92 public MicroServicePolicy() {
96 * The constructor that does not make use of ToscaYamlToJsonConvertor but take
97 * the jsonRepresentation instead.
99 * @param name The name of the MicroService
100 * @param policyModel The policy model type of the MicroService
101 * @param shared The flag indicate whether the MicroService is
103 * @param jsonRepresentation The UI representation in json format
104 * @param loopElementModel The loop element model from which this instance should be created
105 * @param pdpGroup The Pdp Group info
106 * @param pdpSubgroup The Pdp Subgroup info
108 public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared,
109 JsonObject jsonRepresentation, LoopElementModel loopElementModel, String pdpGroup,
110 String pdpSubgroup) {
112 this.setPolicyModel(policyModel);
113 this.shared = shared;
114 this.setJsonRepresentation(jsonRepresentation);
115 this.setLoopElementModel(loopElementModel);
116 this.setPdpGroup(pdpGroup);
117 this.setPdpSubgroup(pdpSubgroup);
121 * Constructor with tosca converter.
123 * @param loop The loop instance
124 * @param service The service model object
125 * @param loopElementModel The loop element model from which this microservice instance is created
126 * @param toscaConverter The tosca converter that will used to convert the tosca policy model
128 public MicroServicePolicy(Loop loop, Service service, LoopElementModel loopElementModel,
129 ToscaConverterWithDictionarySupport toscaConverter) {
130 this(Policy.generatePolicyName("MICROSERVICE", service.getName(), service.getVersion(),
131 loopElementModel.getPolicyModels().first().getPolicyAcronym() + '_'
132 + loopElementModel.getPolicyModels().first().getVersion(),
133 RandomStringUtils.randomAlphanumeric(3)),
134 loopElementModel.getPolicyModels().first(), false, new JsonObject(), loopElementModel, null, null);
135 this.updateJsonRepresentation(toscaConverter, service);
139 public String getName() {
146 * @param name the name to set
149 public void setName(String name) {
154 public void updateJsonRepresentation(ToscaConverterWithDictionarySupport toscaConverter, Service serviceModel) {
155 this.setJsonRepresentation(
156 toscaConverter.convertToscaToJsonSchemaObject(this.getPolicyModel().getPolicyModelTosca(),
157 this.getPolicyModel().getPolicyModelType(), serviceModel));
160 public Boolean getShared() {
164 void setShared(Boolean shared) {
165 this.shared = shared;
168 public Set<Loop> getUsedByLoops() {
172 void setUsedByLoops(Set<Loop> usedBy) {
173 this.usedByLoops = usedBy;
176 public String getContext() {
180 public void setContext(String context) {
181 this.context = context;
184 public String getDeviceTypeScope() {
185 return deviceTypeScope;
188 public void setDeviceTypeScope(String deviceTypeScope) {
189 this.deviceTypeScope = deviceTypeScope;
193 * dcaeDeploymentId getter.
195 * @return the dcaeDeploymentId
197 public String getDcaeDeploymentId() {
198 return dcaeDeploymentId;
202 * dcaeDeploymentId setter.
204 * @param dcaeDeploymentId the dcaeDeploymentId to set
206 public void setDcaeDeploymentId(String dcaeDeploymentId) {
207 this.dcaeDeploymentId = dcaeDeploymentId;
211 * dcaeDeploymentStatusUrl getter.
213 * @return the dcaeDeploymentStatusUrl
215 public String getDcaeDeploymentStatusUrl() {
216 return dcaeDeploymentStatusUrl;
220 * dcaeDeploymentStatusUrl setter.
222 * @param dcaeDeploymentStatusUrl the dcaeDeploymentStatusUrl to set
224 public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
225 this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
229 * dcaeBlueprintId getter.
231 * @return the dcaeBlueprintId
233 public String getDcaeBlueprintId() {
234 return dcaeBlueprintId;
238 * dcaeBlueprintId setter.
240 * @param dcaeBlueprintId the dcaeBlueprintId to set
242 void setDcaeBlueprintId(String dcaeBlueprintId) {
243 this.dcaeBlueprintId = dcaeBlueprintId;
247 public int hashCode() {
248 final int prime = 31;
250 result = prime * result + ((name == null) ? 0 : name.hashCode());
255 public boolean equals(Object obj) {
262 if (getClass() != obj.getClass()) {
265 MicroServicePolicy other = (MicroServicePolicy) obj;
267 if (other.name != null) {
271 else if (!name.equals(other.name)) {