X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fpolicy%2Fmicroservice%2FMicroServicePolicy.java;h=e997b43092019ee74adc176484f39ed246ac15db;hb=afac3121bfacc4d81903b1d8492613b0b77d3298;hp=c4037ffb659dee70879ca174183237b6a600c6a6;hpb=5c6d23852ea949335eb7f85d787eb24ac6dbab2a;p=clamp.git diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java index c4037ffb..e997b430 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -23,8 +23,6 @@ package org.onap.clamp.policy.microservice; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; import java.io.Serializable; @@ -36,13 +34,13 @@ import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; -import javax.persistence.Transient; +import org.apache.commons.lang3.RandomStringUtils; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; -import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor; -import org.onap.clamp.clds.util.JsonUtils; +import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport; import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.Loop; +import org.onap.clamp.loop.service.Service; import org.onap.clamp.loop.template.LoopElementModel; import org.onap.clamp.loop.template.PolicyModel; import org.onap.clamp.policy.Policy; @@ -56,9 +54,6 @@ public class MicroServicePolicy extends Policy implements Serializable { */ private static final long serialVersionUID = 6271238288583332616L; - @Transient - private static final EELFLogger logger = EELFManager.getInstance().getLogger(MicroServicePolicy.class); - @Expose @Id @Column(nullable = false, name = "name", unique = true) @@ -91,22 +86,10 @@ public class MicroServicePolicy extends Policy implements Serializable { @Column(name = "dcae_blueprint_id") private String dcaeBlueprintId; - public MicroServicePolicy() { - // serialization - } - /** - * The constructor that creates the json representation from the policyTosca - * using the ToscaYamlToJsonConvertor. - * - * @param name The name of the MicroService - * @param policyModel The policy model of the MicroService - * @param shared The flag indicate whether the MicroService is shared + * Constructor for serialization. */ - public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared, LoopElementModel loopElementModel) { - this(name, policyModel, shared, JsonUtils.GSON_JPA_MODEL - .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyModel.getPolicyModelTosca(), - policyModel.getPolicyModelType()), JsonObject.class), loopElementModel,null,null); + public MicroServicePolicy() { } /** @@ -116,14 +99,15 @@ public class MicroServicePolicy extends Policy implements Serializable { * @param name The name of the MicroService * @param policyModel The policy model type of the MicroService * @param shared The flag indicate whether the MicroService is - * shared + * shared * @param jsonRepresentation The UI representation in json format * @param loopElementModel The loop element model from which this instance should be created * @param pdpGroup The Pdp Group info - * @param pdpSubgroup The Pdp Subgrouop info + * @param pdpSubgroup The Pdp Subgroup info */ public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared, - JsonObject jsonRepresentation, LoopElementModel loopElementModel, String pdpGroup, String pdpSubgroup) { + JsonObject jsonRepresentation, LoopElementModel loopElementModel, String pdpGroup, + String pdpSubgroup) { this.name = name; this.setPolicyModel(policyModel); this.shared = shared; @@ -133,6 +117,22 @@ public class MicroServicePolicy extends Policy implements Serializable { this.setPdpSubgroup(pdpSubgroup); } + /** + * Constructor with tosca converter. + * + * @param loop The loop instance + * @param service The service model object + * @param loopElementModel The loop element model from which this microservice instance is created + * @param toscaConverter The tosca converter that will used to convert the tosca policy model + */ + public MicroServicePolicy(Loop loop, Service service, LoopElementModel loopElementModel, + ToscaConverterWithDictionarySupport toscaConverter) { + this(Policy.generatePolicyName("MICROSERVICE", service.getName(), service.getVersion(), + RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), + loopElementModel.getPolicyModels().first(), false, new JsonObject(), loopElementModel, null, null); + this.updateJsonRepresentation(toscaConverter, service); + } + @Override public String getName() { return name; @@ -148,6 +148,13 @@ public class MicroServicePolicy extends Policy implements Serializable { this.name = name; } + @Override + public void updateJsonRepresentation(ToscaConverterWithDictionarySupport toscaConverter, Service serviceModel) { + this.setJsonRepresentation( + toscaConverter.convertToscaToJsonSchemaObject(this.getPolicyModel().getPolicyModelTosca(), + this.getPolicyModel().getPolicyModelType(), serviceModel)); + } + public Boolean getShared() { return shared; } @@ -258,7 +265,8 @@ public class MicroServicePolicy extends Policy implements Serializable { if (other.name != null) { return false; } - } else if (!name.equals(other.name)) { + } + else if (!name.equals(other.name)) { return false; } return true;