X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fpolicy%2Fmicroservice%2FMicroServicePolicy.java;h=321c12f6a7ab773520617c16c2e04ea4b9a45332;hb=723de7f63f0951d0cfe7a23956cf9d00128809b1;hp=b8093ccf1fa7be7870e240eea58a78b2b62b3373;hpb=774b4ba65f0d23ae34d3bddb63058796121c1ae3;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 b8093ccf..321c12f6 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -27,7 +27,6 @@ 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.IOException; import java.io.Serializable; import java.util.HashSet; import java.util.Set; @@ -38,11 +37,13 @@ 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.update.UnknownComponentException; +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; @@ -91,31 +92,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 = name; - this.setPolicyModel(policyModel); - this.shared = shared; - try { - this.setJsonRepresentation( - Policy.generateJsonRepresentationFromToscaModel(policyModel.getPolicyModelTosca(), - policyModel.getPolicyModelType())); - } catch (UnknownComponentException | NullPointerException | IOException e) { - logger.error("Unable to generate the microservice policy Schema ... ", e); - this.setJsonRepresentation(new JsonObject()); - } - this.setLoopElementModel(loopElementModel); + public MicroServicePolicy() { } /** @@ -129,7 +109,7 @@ public class MicroServicePolicy extends Policy implements Serializable { * @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, @@ -143,6 +123,25 @@ 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, + toscaConverter.convertToscaToJsonSchemaObject( + loopElementModel.getPolicyModels().first().getPolicyModelTosca(), + loopElementModel.getPolicyModels().first().getPolicyModelType()), + loopElementModel, null, null); + } + @Override public String getName() { return name;