aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-01-21 12:40:59 +0100
committersebdet <sebastien.determe@intl.att.com>2020-01-23 09:49:29 +0100
commitcef5b582ed8f2f9a64203e737234e29434314b36 (patch)
tree78bb1b416d75ecc210245d10099867f2414d153f /src/main/java/org/onap
parent33fc823baeda6d4e872614b146ab865823a3ca0f (diff)
Modify the template model
Add loopElement to loopTemplate so that operational policy can be added into the template as well Issue-ID: CLAMP-555 Change-Id: I298c05f7f92536e4dab840983c41b0f7ee22daac Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/clamp/loop/CsarInstaller.java3
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java4
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopElementModel.java (renamed from src/main/java/org/onap/clamp/loop/template/MicroServiceModel.java)113
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopElementModelsRepository.java (renamed from src/main/java/org/onap/clamp/loop/template/MicroServiceModelsRepository.java)2
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplate.java41
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplateLoopElementModel.java (renamed from src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModel.java)56
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplateLoopElementModelId.java (renamed from src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModelId.java)24
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModel.java39
-rw-r--r--src/main/java/org/onap/clamp/policy/Policy.java147
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java90
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java2
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java82
12 files changed, 318 insertions, 285 deletions
diff --git a/src/main/java/org/onap/clamp/loop/CsarInstaller.java b/src/main/java/org/onap/clamp/loop/CsarInstaller.java
index 38a6f931..ab8069f3 100644
--- a/src/main/java/org/onap/clamp/loop/CsarInstaller.java
+++ b/src/main/java/org/onap/clamp/loop/CsarInstaller.java
@@ -52,8 +52,6 @@ import org.onap.clamp.policy.operational.OperationalPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
/**
* This class will be instantiated by spring config, and used by Sdc Controller.
@@ -129,7 +127,6 @@ public class CsarInstaller {
* @throws SdcArtifactInstallerException The SdcArtifactInstallerException
* @throws InterruptedException The InterruptedException
*/
- @Transactional(propagation = Propagation.REQUIRES_NEW)
public void installTheLoop(CsarHandler csar, Service service)
throws SdcArtifactInstallerException, InterruptedException {
try {
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 38378304..6b9a924b 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -127,8 +127,8 @@ public class Loop extends AuditEntity implements Serializable {
@Expose
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER)
- @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"),
- inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
+ @JoinTable(name = "loops_to_microservicepolicies", joinColumns = @JoinColumn(name = "loop_name"),
+ inverseJoinColumns = @JoinColumn(name = "microservicepolicy_name"))
private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
@Expose
diff --git a/src/main/java/org/onap/clamp/loop/template/MicroServiceModel.java b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java
index 1e2b140e..c22ca1a6 100644
--- a/src/main/java/org/onap/clamp/loop/template/MicroServiceModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java
@@ -28,6 +28,8 @@ import com.google.gson.annotations.Expose;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@@ -35,11 +37,12 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
-import javax.persistence.JoinColumns;
-import javax.persistence.ManyToOne;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
+import org.hibernate.annotations.SortNatural;
import org.onap.clamp.loop.common.AuditEntity;
/**
@@ -47,9 +50,9 @@ import org.onap.clamp.loop.common.AuditEntity;
*/
@Entity
-@Table(name = "micro_service_models")
-public class MicroServiceModel extends AuditEntity implements Serializable {
-
+@Table(name = "loop_element_models")
+public class LoopElementModel extends AuditEntity implements Serializable {
+ public static final String DEFAULT_GROUP_NAME = "DEFAULT";
/**
* The serial version id.
*/
@@ -61,41 +64,50 @@ public class MicroServiceModel extends AuditEntity implements Serializable {
private String name;
/**
- * This variable is used to store the type mentioned in the micro-service
- * blueprint.
+ * Here we store the blueprint coming from DCAE.
*/
- @Expose
- @Column(nullable = false, name = "policy_type")
- private String policyType;
-
@Column(nullable = false, name = "blueprint_yaml")
private String blueprint;
+ /**
+ * The type of element
+ */
+ @Column(nullable = false, name = "loop_element_type")
+ private String loopElementType;
+
+ /**
+ * This variable is used to store the type mentioned in the micro-service
+ * blueprint.
+ */
@Expose
- @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
- @JoinColumns({ @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
- @JoinColumn(name = "policy_model_version", referencedColumnName = "version") })
- private PolicyModel policyModel;
+ @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
+ @JoinTable(name = "loopelementmodels_to_policymodels",
+ joinColumns = @JoinColumn(name = "loop_element_name", referencedColumnName = "name"),
+ inverseJoinColumns = { @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
+ @JoinColumn(name = "policy_model_version", referencedColumnName = "version") })
+ @SortNatural
+ private SortedSet<PolicyModel> policyModels = new TreeSet<>();
- @OneToMany(fetch = FetchType.LAZY, mappedBy = "microServiceModel", orphanRemoval = true)
- private Set<TemplateMicroServiceModel> usedByLoopTemplates = new HashSet<>();
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "loopElementModel", orphanRemoval = true)
+ private Set<LoopTemplateLoopElementModel> usedByLoopTemplates = new HashSet<>();
/**
- * policyModel getter.
+ * policyModels getter.
*
* @return the policyModel
*/
- public PolicyModel getPolicyModel() {
- return policyModel;
+ public SortedSet<PolicyModel> getPolicyModels() {
+ return policyModels;
}
/**
- * policyModel setter.
+ * Method to add a new policyModel to the list.
*
- * @param policyModel the policyModel to set
+ * @param policyModel
*/
- public void setPolicyModel(PolicyModel policyModel) {
- this.policyModel = policyModel;
+ public void addPolicyModel(PolicyModel policyModel) {
+ policyModels.add(policyModel);
+ policyModel.getUsedByElementModels().add(this);
}
/**
@@ -117,24 +129,6 @@ public class MicroServiceModel extends AuditEntity implements Serializable {
}
/**
- * policyType getter.
- *
- * @return the policyType
- */
- public String getPolicyType() {
- return policyType;
- }
-
- /**
- * policyType setter.
- *
- * @param policyType the policyType to set
- */
- public void setPolicyType(String policyType) {
- this.policyType = policyType;
- }
-
- /**
* blueprint getter.
*
* @return the blueprint
@@ -153,35 +147,46 @@ public class MicroServiceModel extends AuditEntity implements Serializable {
}
/**
+ * @return the loopElementType
+ */
+ public String getLoopElementType() {
+ return loopElementType;
+ }
+
+ /**
+ * @param loopElementType the loopElementType to set
+ */
+ public void setLoopElementType(String loopElementType) {
+ this.loopElementType = loopElementType;
+ }
+
+ /**
* usedByLoopTemplates getter.
*
* @return the usedByLoopTemplates
*/
- public Set<TemplateMicroServiceModel> getUsedByLoopTemplates() {
+ public Set<LoopTemplateLoopElementModel> getUsedByLoopTemplates() {
return usedByLoopTemplates;
}
/**
* Default constructor for serialization.
*/
- public MicroServiceModel() {
+ public LoopElementModel() {
}
/**
* Constructor.
*
- * @param name The name id
- * @param policyType The policy model type like
- * onap.policies.controlloop.operational.common.Apex
- * @param blueprint The blueprint defined for dcae that contains the policy
- * type to use
- * @param policyModel The policy model for the policy type mentioned here
+ * @param name The name id
+ * @param loopElementType The type of loop element
+ * @param blueprint The blueprint defined for dcae that contains the
+ * policy type to use
*/
- public MicroServiceModel(String name, String policyType, String blueprint, PolicyModel policyModel) {
+ public LoopElementModel(String name, String loopElementType, String blueprint) {
this.name = name;
- this.policyType = policyType;
+ this.loopElementType = loopElementType;
this.blueprint = blueprint;
- this.policyModel = policyModel;
}
@Override
@@ -203,7 +208,7 @@ public class MicroServiceModel extends AuditEntity implements Serializable {
if (getClass() != obj.getClass()) {
return false;
}
- MicroServiceModel other = (MicroServiceModel) obj;
+ LoopElementModel other = (LoopElementModel) obj;
if (name == null) {
if (other.name != null) {
return false;
diff --git a/src/main/java/org/onap/clamp/loop/template/MicroServiceModelsRepository.java b/src/main/java/org/onap/clamp/loop/template/LoopElementModelsRepository.java
index 2b187048..27b82189 100644
--- a/src/main/java/org/onap/clamp/loop/template/MicroServiceModelsRepository.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopElementModelsRepository.java
@@ -27,5 +27,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
-public interface MicroServiceModelsRepository extends JpaRepository<MicroServiceModel, String> {
+public interface LoopElementModelsRepository extends JpaRepository<LoopElementModel, String> {
}
diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
index 10367e77..20574ff6 100644
--- a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
@@ -72,7 +72,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
@Expose
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loopTemplate", orphanRemoval = true)
@SortNatural
- private SortedSet<TemplateMicroServiceModel> microServiceModelUsed = new TreeSet<>();
+ private SortedSet<LoopTemplateLoopElementModel> loopElementModelsUsed = new TreeSet<>();
@Expose
@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@@ -138,12 +138,12 @@ public class LoopTemplate extends AuditEntity implements Serializable {
}
/**
- * microServiceModelUsed getter.
+ * loopElementModelsUsed getter.
*
- * @return the microServiceModelUsed
+ * @return the loopElementModelsUsed
*/
- public SortedSet<TemplateMicroServiceModel> getMicroServiceModelUsed() {
- return microServiceModelUsed;
+ public SortedSet<LoopTemplateLoopElementModel> getLoopElementModelsUsed() {
+ return loopElementModelsUsed;
}
/**
@@ -165,29 +165,30 @@ public class LoopTemplate extends AuditEntity implements Serializable {
}
/**
- * Add a microService model to the current template, the microservice is added
- * at the end of the list so the flowOrder is computed automatically.
+ * Add a loopElement to the current template, the loopElementModel is added at
+ * the end of the list so the flowOrder is computed automatically.
*
- * @param microServiceModel The microserviceModel to add
+ * @param loopElementModel The loopElementModel to add
*/
- public void addMicroServiceModel(MicroServiceModel microServiceModel) {
- TemplateMicroServiceModel jointEntry = new TemplateMicroServiceModel(this, microServiceModel,
- this.microServiceModelUsed.size());
- this.microServiceModelUsed.add(jointEntry);
- microServiceModel.getUsedByLoopTemplates().add(jointEntry);
+ public void addLoopElementModel(LoopElementModel loopElementModel) {
+ LoopTemplateLoopElementModel jointEntry = new LoopTemplateLoopElementModel(this, loopElementModel,
+ this.loopElementModelsUsed.size());
+ this.loopElementModelsUsed.add(jointEntry);
+ loopElementModel.getUsedByLoopTemplates().add(jointEntry);
}
/**
- * Add a microService model to the current template, the flow order must be
+ * Add a loopElement model to the current template, the flow order must be
* specified manually.
*
- * @param microServiceModel The microserviceModel to add
- * @param listPosition The position in the flow
+ * @param loopElementModel The loopElementModel to add
+ * @param listPosition The position in the flow
*/
- public void addMicroServiceModel(MicroServiceModel microServiceModel, Integer listPosition) {
- TemplateMicroServiceModel jointEntry = new TemplateMicroServiceModel(this, microServiceModel, listPosition);
- this.microServiceModelUsed.add(jointEntry);
- microServiceModel.getUsedByLoopTemplates().add(jointEntry);
+ public void addLoopElementModel(LoopElementModel loopElementModel, Integer listPosition) {
+ LoopTemplateLoopElementModel jointEntry = new LoopTemplateLoopElementModel(this, loopElementModel,
+ listPosition);
+ this.loopElementModelsUsed.add(jointEntry);
+ loopElementModel.getUsedByLoopTemplates().add(jointEntry);
}
/**
diff --git a/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModel.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplateLoopElementModel.java
index 7547c1f7..aca16bc0 100644
--- a/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplateLoopElementModel.java
@@ -38,8 +38,8 @@ import javax.persistence.MapsId;
import javax.persistence.Table;
@Entity
-@Table(name = "templates_microservicemodels")
-public class TemplateMicroServiceModel implements Serializable, Comparable<TemplateMicroServiceModel> {
+@Table(name = "looptemplates_to_loopelementmodels")
+public class LoopTemplateLoopElementModel implements Serializable, Comparable<LoopTemplateLoopElementModel> {
/**
* Serial ID.
@@ -47,7 +47,7 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
private static final long serialVersionUID = 5924989899078094245L;
@EmbeddedId
- private TemplateMicroServiceModelId templateMicroServiceModelId;
+ private LoopTemplateLoopElementModelId loopTemplateLoopElementModelId;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("loopTemplateName")
@@ -56,9 +56,9 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
@Expose
@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
- @MapsId("microServiceModelName")
- @JoinColumn(name = "micro_service_model_name")
- private MicroServiceModel microServiceModel;
+ @MapsId("loopElementModelName")
+ @JoinColumn(name = "loop_element_model_name")
+ private LoopElementModel loopElementModel;
@Expose
@Column(nullable = false, name = "flow_order")
@@ -67,24 +67,24 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
/**
* Default constructor for serialization.
*/
- public TemplateMicroServiceModel() {
+ public LoopTemplateLoopElementModel() {
}
/**
* Constructor.
*
- * @param loopTemplate The loop template object
- * @param microServiceModel The microServiceModel object
- * @param flowOrder The position of the micro service in the flow
+ * @param loopTemplate The loop template object
+ * @param loopElementModel The loopElementModel object
+ * @param flowOrder The position of the micro service in the flow
*/
- public TemplateMicroServiceModel(LoopTemplate loopTemplate, MicroServiceModel microServiceModel,
+ public LoopTemplateLoopElementModel(LoopTemplate loopTemplate, LoopElementModel loopElementModel,
Integer flowOrder) {
this.loopTemplate = loopTemplate;
- this.microServiceModel = microServiceModel;
+ this.loopElementModel = loopElementModel;
this.flowOrder = flowOrder;
- this.templateMicroServiceModelId = new TemplateMicroServiceModelId(loopTemplate.getName(),
- microServiceModel.getName());
+ this.loopTemplateLoopElementModelId = new LoopTemplateLoopElementModelId(loopTemplate.getName(),
+ loopElementModel.getName());
}
/**
@@ -106,21 +106,21 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
}
/**
- * microServiceModel getter.
+ * loopElementModel getter.
*
- * @return the microServiceModel
+ * @return the loopElementModel
*/
- public MicroServiceModel getMicroServiceModel() {
- return microServiceModel;
+ public LoopElementModel getLoopElementModel() {
+ return loopElementModel;
}
/**
- * microServiceModel setter.
+ * loopElementModel setter.
*
- * @param microServiceModel the microServiceModel to set
+ * @param loopElementModel the loopElementModel to set
*/
- public void setMicroServiceModel(MicroServiceModel microServiceModel) {
- this.microServiceModel = microServiceModel;
+ public void setLoopElementModel(LoopElementModel loopElementModel) {
+ this.loopElementModel = loopElementModel;
}
/**
@@ -142,7 +142,7 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
}
@Override
- public int compareTo(TemplateMicroServiceModel arg0) {
+ public int compareTo(LoopTemplateLoopElementModel arg0) {
// Reverse it, so that by default we have the latest
if (getFlowOrder() == null) {
return 1;
@@ -158,7 +158,7 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
final int prime = 31;
int result = 1;
result = prime * result + ((loopTemplate == null) ? 0 : loopTemplate.hashCode());
- result = prime * result + ((microServiceModel == null) ? 0 : microServiceModel.hashCode());
+ result = prime * result + ((loopElementModel == null) ? 0 : loopElementModel.hashCode());
return result;
}
@@ -173,7 +173,7 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
if (getClass() != obj.getClass()) {
return false;
}
- TemplateMicroServiceModel other = (TemplateMicroServiceModel) obj;
+ LoopTemplateLoopElementModel other = (LoopTemplateLoopElementModel) obj;
if (loopTemplate == null) {
if (other.loopTemplate != null) {
return false;
@@ -181,11 +181,11 @@ public class TemplateMicroServiceModel implements Serializable, Comparable<Templ
} else if (!loopTemplate.equals(other.loopTemplate)) {
return false;
}
- if (microServiceModel == null) {
- if (other.microServiceModel != null) {
+ if (loopElementModel == null) {
+ if (other.loopElementModel != null) {
return false;
}
- } else if (!microServiceModel.equals(other.microServiceModel)) {
+ } else if (!loopElementModel.equals(other.loopElementModel)) {
return false;
}
return true;
diff --git a/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModelId.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplateLoopElementModelId.java
index 74c76897..3e2f8ad4 100644
--- a/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModelId.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplateLoopElementModelId.java
@@ -31,7 +31,7 @@ import javax.persistence.Column;
import javax.persistence.Embeddable;
@Embeddable
-public class TemplateMicroServiceModelId implements Serializable {
+public class LoopTemplateLoopElementModelId implements Serializable {
/**
* Serial ID.
@@ -43,13 +43,13 @@ public class TemplateMicroServiceModelId implements Serializable {
private String loopTemplateName;
@Expose
- @Column(name = "micro_service_model_name")
- private String microServiceModelName;
+ @Column(name = "loop_element_model_name")
+ private String loopElementModelName;
/**
* Default constructor for serialization.
*/
- public TemplateMicroServiceModelId() {
+ public LoopTemplateLoopElementModelId() {
}
@@ -59,9 +59,9 @@ public class TemplateMicroServiceModelId implements Serializable {
* @param loopTemplateName The loop template name id
* @param microServiceModelName THe micro Service name id
*/
- public TemplateMicroServiceModelId(String loopTemplateName, String microServiceModelName) {
+ public LoopTemplateLoopElementModelId(String loopTemplateName, String microServiceModelName) {
this.loopTemplateName = loopTemplateName;
- this.microServiceModelName = microServiceModelName;
+ this.loopElementModelName = microServiceModelName;
}
/**
@@ -87,16 +87,16 @@ public class TemplateMicroServiceModelId implements Serializable {
*
* @return the microServiceModelName
*/
- public String getMicroServiceModelName() {
- return microServiceModelName;
+ public String getLoopElementModelName() {
+ return loopElementModelName;
}
/**
- * microServiceModelName setter.
+ * loopElementModelName setter.
*
- * @param microServiceModelName the microServiceModelName to set
+ * @param loopElementModelName the loopElementModelName to set
*/
- public void setMicroServiceModelName(String microServiceModelName) {
- this.microServiceModelName = microServiceModelName;
+ public void setLoopElementModelName(String loopElementModelName) {
+ this.loopElementModelName = loopElementModelName;
}
}
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
index e6580bee..00d58a82 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
@@ -26,11 +26,15 @@ package org.onap.clamp.loop.template;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
+import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.onap.clamp.loop.common.AuditEntity;
@@ -74,9 +78,15 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
@Column(name = "policy_acronym")
private String policyAcronym;
- @Expose
- @Column(name = "policy_variant")
- private String policyVariant;
+ @ManyToMany(mappedBy = "policyModels", fetch = FetchType.EAGER)
+ private Set<LoopElementModel> usedByElementModels = new HashSet<>();
+
+ /**
+ * @return the usedByElementModels
+ */
+ public Set<LoopElementModel> getUsedByElementModels() {
+ return usedByElementModels;
+ }
/**
* policyModelTosca getter.
@@ -152,24 +162,6 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
}
/**
- * policyVariant getter.
- *
- * @return the policyVariant value
- */
- public String getPolicyVariant() {
- return policyVariant;
- }
-
- /**
- * policyVariant setter.
- *
- * @param policyVariant The policyVariant to set
- */
- public void setPolicyVariant(String policyVariant) {
- this.policyVariant = policyVariant;
- }
-
- /**
* Default constructor for serialization.
*/
public PolicyModel() {
@@ -181,16 +173,13 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
* @param policyType The policyType (referenced in the blueprint)
* @param policyModelTosca The policy tosca model in yaml
* @param version the version like 1.0.0
- * @param policyAcronym Short policy name if it exists
* @param policyVariant Subtype for policy if it exists (could be used by UI)
*/
- public PolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
- String policyVariant) {
+ public PolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym) {
this.policyModelType = policyType;
this.policyModelTosca = policyModelTosca;
this.version = version;
this.policyAcronym = policyAcronym;
- this.policyVariant = policyVariant;
}
@Override
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java
index fc097bd6..c6568205 100644
--- a/src/main/java/org/onap/clamp/policy/Policy.java
+++ b/src/main/java/org/onap/clamp/policy/Policy.java
@@ -24,37 +24,148 @@
package org.onap.clamp.policy;
import com.google.gson.JsonObject;
+import com.google.gson.annotations.Expose;
import java.io.UnsupportedEncodingException;
-public interface Policy {
+import javax.persistence.Column;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.MappedSuperclass;
- String getName();
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.TypeDefs;
+import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
+import org.onap.clamp.loop.common.AuditEntity;
+import org.onap.clamp.loop.template.LoopElementModel;
- JsonObject getJsonRepresentation();
+@MappedSuperclass
+@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
+public abstract class Policy extends AuditEntity {
- String createPolicyPayload() throws UnsupportedEncodingException;
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "json_representation", nullable = false)
+ private JsonObject jsonRepresentation;
+
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "configurations_json")
+ private JsonObject configurationsJson;
+
+ @Expose
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumn(name = "loop_element_model_id")
+ private LoopElementModel loopElementModel;
+
+ @Expose
+ @Column(name = "pdp_group")
+ private String pdpGroup;
+
+ public abstract String createPolicyPayload() throws UnsupportedEncodingException;
+
+ /**
+ * Name getter.
+ *
+ * @return the name
+ */
+ public abstract String getName();
+
+ /**
+ * Name setter.
+ *
+ */
+ public abstract void setName(String name);
+
+ /**
+ * jsonRepresentation getter.
+ *
+ * @return the jsonRepresentation
+ */
+ public JsonObject getJsonRepresentation() {
+ return jsonRepresentation;
+ }
+
+ /**
+ * jsonRepresentation setter.
+ *
+ * @param jsonRepresentation The jsonRepresentation to set
+ */
+ public void setJsonRepresentation(JsonObject jsonRepresentation) {
+ this.jsonRepresentation = jsonRepresentation;
+ }
+
+ /**
+ * configurationsJson getter.
+ *
+ * @return The configurationsJson
+ */
+ public JsonObject getConfigurationsJson() {
+ return configurationsJson;
+ }
+
+ /**
+ * configurationsJson setter.
+ *
+ * @param configurationsJson the configurationsJson to set
+ */
+ public void setConfigurationsJson(JsonObject configurationsJson) {
+ this.configurationsJson = configurationsJson;
+ }
+
+ /**
+ * loopElementModel getter.
+ *
+ * @return the loopElementModel
+ */
+ public LoopElementModel getLoopElementModel() {
+ return loopElementModel;
+ }
+
+ /**
+ * loopElementModel setter.
+ *
+ * @param loopElementModel the loopElementModel to set
+ */
+ public void setLoopElementModel(LoopElementModel loopElementModel) {
+ this.loopElementModel = loopElementModel;
+ }
+
+ /**
+ * pdpGroup getter.
+ *
+ * @return the pdpGroup
+ */
+ public String getPdpGroup() {
+ return pdpGroup;
+ }
+
+ /**
+ * pdpGroup setter.
+ *
+ * @param pdpGroup the pdpGroup to set
+ */
+ public void setPdpGroup(String pdpGroup) {
+ this.pdpGroup = pdpGroup;
+ }
/**
* Generate the policy name.
*
- * @param policyType
- * The policy type
- * @param serviceName
- * The service name
- * @param serviceVersion
- * The service version
- * @param resourceName
- * The resource name
- * @param blueprintFilename
- * The blueprint file name
+ * @param policyType The policy type
+ * @param serviceName The service name
+ * @param serviceVersion The service version
+ * @param resourceName The resource name
+ * @param blueprintFilename The blueprint file name
* @return The generated policy name
*/
- static String generatePolicyName(String policyType, String serviceName, String serviceVersion, String resourceName,
- String blueprintFilename) {
+ public static String generatePolicyName(String policyType, String serviceName, String serviceVersion,
+ String resourceName, String blueprintFilename) {
StringBuilder buffer = new StringBuilder(policyType).append("_").append(serviceName).append("_v")
- .append(serviceVersion).append("_").append(resourceName).append("_")
- .append(blueprintFilename.replaceAll(".yaml", ""));
+ .append(serviceVersion).append("_").append(resourceName).append("_")
+ .append(blueprintFilename.replaceAll(".yaml", ""));
return buffer.toString().replace('.', '_').replaceAll(" ", "");
}
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 3e4dd8fd..445c1d5d 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
@@ -40,13 +40,10 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
-import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
-import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
-import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.json.JSONObject;
@@ -54,15 +51,13 @@ import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
import org.onap.clamp.loop.Loop;
-import org.onap.clamp.loop.common.AuditEntity;
-import org.onap.clamp.loop.template.MicroServiceModel;
import org.onap.clamp.policy.Policy;
import org.yaml.snakeyaml.Yaml;
@Entity
@Table(name = "micro_service_policies")
@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
-public class MicroServicePolicy extends AuditEntity implements Serializable, Policy {
+public class MicroServicePolicy extends Policy implements Serializable {
/**
* The serial version ID.
*/
@@ -89,31 +84,16 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
private String deviceTypeScope;
@Expose
- @Type(type = "json")
- @Column(columnDefinition = "json", name = "properties")
- private JsonObject properties;
-
- @Expose
@Column(name = "shared", nullable = false)
private Boolean shared;
@Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca", nullable = false)
private String policyTosca;
- @Expose
- @Type(type = "json")
- @Column(columnDefinition = "json", name = "json_representation", nullable = false)
- private JsonObject jsonRepresentation;
-
@ManyToMany(mappedBy = "microServicePolicies", fetch = FetchType.EAGER)
private Set<Loop> usedByLoops = new HashSet<>();
@Expose
- @ManyToOne(fetch = FetchType.EAGER)
- @JoinColumn(name = "micro_service_model_id")
- private MicroServiceModel microServiceModel;
-
- @Expose
@Column(name = "dcae_deployment_id")
private String dcaeDeploymentId;
@@ -141,8 +121,8 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
this.modelType = modelType;
this.policyTosca = policyTosca;
this.shared = shared;
- this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL
- .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyTosca, modelType), JsonObject.class);
+ this.setJsonRepresentation(JsonUtils.GSON_JPA_MODEL
+ .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyTosca, modelType), JsonObject.class));
this.usedByLoops = usedByLoops;
}
@@ -171,7 +151,7 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
this.policyTosca = policyTosca;
this.shared = shared;
this.usedByLoops = usedByLoops;
- this.jsonRepresentation = jsonRepresentation;
+ this.setJsonRepresentation(jsonRepresentation);
}
@Override
@@ -179,6 +159,16 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
return name;
}
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
public String getModelType() {
return modelType;
}
@@ -187,14 +177,6 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
this.modelType = modelType;
}
- public JsonObject getProperties() {
- return properties;
- }
-
- public void setProperties(JsonObject properties) {
- this.properties = properties;
- }
-
public Boolean getShared() {
return shared;
}
@@ -211,15 +193,6 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
this.policyTosca = policyTosca;
}
- @Override
- public JsonObject getJsonRepresentation() {
- return jsonRepresentation;
- }
-
- void setJsonRepresentation(JsonObject jsonRepresentation) {
- this.jsonRepresentation = jsonRepresentation;
- }
-
public Set<Loop> getUsedByLoops() {
return usedByLoops;
}
@@ -245,24 +218,8 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
}
/**
- * microServiceModel getter.
- *
- * @return the microServiceModel
- */
- public MicroServiceModel getMicroServiceModel() {
- return microServiceModel;
- }
-
- /**
- * microServiceModel setter.
+ * dcaeDeploymentId getter.
*
- * @param microServiceModel the microServiceModel to set
- */
- public void setMicroServiceModel(MicroServiceModel microServiceModel) {
- this.microServiceModel = microServiceModel;
- }
-
- /**
* @return the dcaeDeploymentId
*/
public String getDcaeDeploymentId() {
@@ -270,6 +227,8 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
}
/**
+ * dcaeDeploymentId setter.
+ *
* @param dcaeDeploymentId the dcaeDeploymentId to set
*/
public void setDcaeDeploymentId(String dcaeDeploymentId) {
@@ -277,6 +236,8 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
}
/**
+ * dcaeDeploymentStatusUrl getter.
+ *
* @return the dcaeDeploymentStatusUrl
*/
public String getDcaeDeploymentStatusUrl() {
@@ -284,21 +245,14 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
}
/**
+ * dcaeDeploymentStatusUrl setter.
+ *
* @param dcaeDeploymentStatusUrl the dcaeDeploymentStatusUrl to set
*/
public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
}
- /**
- * name setter.
- *
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
@Override
public int hashCode() {
final int prime = 31;
@@ -362,7 +316,7 @@ public class MicroServicePolicy extends AuditEntity implements Serializable, Pol
JsonObject policyProperties = new JsonObject();
policyDetails.add("properties", policyProperties);
- policyProperties.add(this.getMicroServicePropertyNameFromTosca(toscaJson), this.getProperties());
+ policyProperties.add(this.getMicroServicePropertyNameFromTosca(toscaJson), this.getConfigurationsJson());
String policyPayload = new GsonBuilder().setPrettyPrinting().create().toJson(policyPayloadResult);
logger.info("Micro service policy payload: " + policyPayload);
return policyPayload;
diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
index 346cdf62..c431767f 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
@@ -73,7 +73,7 @@ public class MicroServicePolicyService implements PolicyService<MicroServicePoli
private MicroServicePolicy updateMicroservicePolicyProperties(MicroServicePolicy oldPolicy,
MicroServicePolicy newPolicy, Loop loop) {
- oldPolicy.setProperties(newPolicy.getProperties());
+ oldPolicy.setConfigurationsJson(newPolicy.getConfigurationsJson());
if (!oldPolicy.getUsedByLoops().contains(loop)) {
oldPolicy.getUsedByLoops().add(loop);
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index d9e8a57d..a1c8cdbd 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -51,7 +51,6 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
-import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
@@ -64,7 +63,7 @@ import org.yaml.snakeyaml.Yaml;
@Entity
@Table(name = "operational_policies")
@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
-public class OperationalPolicy implements Serializable, Policy {
+public class OperationalPolicy extends Policy implements Serializable {
/**
* The serial version ID.
*/
@@ -78,16 +77,6 @@ public class OperationalPolicy implements Serializable, Policy {
@Column(nullable = false, name = "name", unique = true)
private String name;
- @Expose
- @Type(type = "json")
- @Column(columnDefinition = "json", name = "configurations_json")
- private JsonObject configurationsJson;
-
- @Expose
- @Type(type = "json")
- @Column(columnDefinition = "json", name = "json_representation", nullable = false)
- private JsonObject jsonRepresentation;
-
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "loop_id", nullable = false)
private Loop loop;
@@ -113,22 +102,17 @@ public class OperationalPolicy implements Serializable, Policy {
public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson) {
this.name = name;
this.loop = loop;
- this.configurationsJson = configurationsJson;
- LegacyOperationalPolicy.preloadConfiguration(this.configurationsJson, loop);
+ this.setConfigurationsJson(configurationsJson);
+ LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop);
try {
- this.jsonRepresentation = OperationalPolicyRepresentationBuilder
- .generateOperationalPolicySchema(loop.getModelService());
+ this.setJsonRepresentation(
+ OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));
} catch (JsonSyntaxException | IOException | NullPointerException e) {
logger.error("Unable to generate the operational policy Schema ... ", e);
- this.jsonRepresentation = new JsonObject();
+ this.setJsonRepresentation(new JsonObject());
}
}
- @Override
- public String getName() {
- return name;
- }
-
public void setLoop(Loop loopName) {
this.loop = loopName;
}
@@ -137,12 +121,19 @@ public class OperationalPolicy implements Serializable, Policy {
return loop;
}
- public JsonObject getConfigurationsJson() {
- return configurationsJson;
+ @Override
+ public String getName() {
+ return name;
}
- public void setConfigurationsJson(JsonObject configurationsJson) {
- this.configurationsJson = configurationsJson;
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
}
/**
@@ -163,24 +154,6 @@ public class OperationalPolicy implements Serializable, Policy {
this.policyModel = policyModel;
}
- /**
- * name setter.
- *
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public JsonObject getJsonRepresentation() {
- return jsonRepresentation;
- }
-
- void setJsonRepresentation(JsonObject jsonRepresentation) {
- this.jsonRepresentation = jsonRepresentation;
- }
-
@Override
public int hashCode() {
final int prime = 31;
@@ -240,7 +213,7 @@ public class OperationalPolicy implements Serializable, Policy {
metadata.addProperty("policy-id", this.name);
operationalPolicyDetails.add("properties", LegacyOperationalPolicy
- .reworkPayloadAttributes(this.configurationsJson.get("operational_policy").deepCopy()));
+ .reworkPayloadAttributes(this.getConfigurationsJson().get("operational_policy").deepCopy()));
DumperOptions options = new DumperOptions();
options.setIndent(2);
@@ -256,8 +229,11 @@ public class OperationalPolicy implements Serializable, Policy {
// Now using the legacy payload fo Dublin
JsonObject payload = new JsonObject();
payload.addProperty("policy-id", this.getName());
- payload.addProperty("content", URLEncoder.encode(LegacyOperationalPolicy.createPolicyPayloadYamlLegacy(
- this.configurationsJson.get("operational_policy")), StandardCharsets.UTF_8.toString()));
+ payload.addProperty("content",
+ URLEncoder.encode(
+ LegacyOperationalPolicy
+ .createPolicyPayloadYamlLegacy(this.getConfigurationsJson().get("operational_policy")),
+ StandardCharsets.UTF_8.toString()));
String opPayload = new GsonBuilder().setPrettyPrinting().create().toJson(payload);
logger.info("Operational policy payload: " + opPayload);
return opPayload;
@@ -283,16 +259,16 @@ public class OperationalPolicy implements Serializable, Policy {
}
/**
- * Regenerate the Operational Policy Json Representation.
- *
- */
+ * Regenerate the Operational Policy Json Representation.
+ *
+ */
public void updateJsonRepresentation() {
try {
- this.jsonRepresentation = OperationalPolicyRepresentationBuilder
- .generateOperationalPolicySchema(loop.getModelService());
+ this.setJsonRepresentation(
+ OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));
} catch (JsonSyntaxException | IOException | NullPointerException e) {
logger.error("Unable to generate the operational policy Schema ... ", e);
- this.jsonRepresentation = new JsonObject();
+ this.setJsonRepresentation(new JsonObject());
}
}
}