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.IOException;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
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;
*/
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)
@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() {
}
/**
* @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,
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(),
+ loopElementModel.getPolicyModels().first().getPolicyAcronym() + '_'
+ + loopElementModel.getPolicyModels().first().getVersion(),
+ RandomStringUtils.randomAlphanumeric(3)),
+ loopElementModel.getPolicyModels().first(), false, new JsonObject(), loopElementModel, null, null);
+ this.updateJsonRepresentation(toscaConverter, service);
+ }
+
@Override
public String getName() {
return name;
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;
}