aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2020-03-02 11:37:20 +0100
committerxuegao <xg353y@intl.att.com>2020-03-03 12:09:34 +0100
commit635445a5f262464c88287e5b5ceace4abf9cc4bc (patch)
tree81e772e47ed5deff4ab873e4ee148ac2aed6a373 /src/main/java/org/onap
parentae6a9829f0c572cb4789812ea65871132ec861fd (diff)
Update UI to define Pdp Group
Update teh UI, adding the possibilities to define Pdp Group and Pdp Subgroup info. Issue-ID: CLAMP-654 Change-Id: I3660c491d3a4c730a7414f9c6de9e3859f3c3601 Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java2
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java2
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopController.java4
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopService.java2
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java7
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModel.java1
-rw-r--r--src/main/java/org/onap/clamp/policy/Policy.java18
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java13
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java4
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java18
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java10
11 files changed, 47 insertions, 34 deletions
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
index 8e3b06a4..846b3ab2 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
@@ -91,7 +91,7 @@ public class ClampGraphBuilder {
loopElementModel.getPolicyModels().first(), false, loopElementModel));
} else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(loopElementModel.getLoopElementType())) {
policies.add(new OperationalPolicy(loopElementModel.getName(), null, null,
- loopElementModel.getPolicyModels().first(), loopElementModel));
+ loopElementModel.getPolicyModels().first(), loopElementModel, null, null));
}
return this;
}
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index b3fe58f9..122b4c77 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -173,7 +173,7 @@ public class Loop extends AuditEntity implements Serializable {
} else if (LoopElementModel.OPERATIONAL_POLICY_TYPE
.equals(element.getLoopElementModel().getLoopElementType())) {
this.addOperationalPolicy(new OperationalPolicy(name, null, new JsonObject(),
- element.getLoopElementModel().getPolicyModels().first(), element.getLoopElementModel()));
+ element.getLoopElementModel().getPolicyModels().first(), element.getLoopElementModel(), null, null));
}
});
}
diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java
index 7ee088c4..59b97e1a 100644
--- a/src/main/java/org/onap/clamp/loop/LoopController.java
+++ b/src/main/java/org/onap/clamp/loop/LoopController.java
@@ -69,7 +69,7 @@ public class LoopController {
* @return The updated loop
*/
public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
- List<OperationalPolicy> operationalPolicies = JsonUtils.GSON.fromJson(operationalPoliciesJson,
+ List<OperationalPolicy> operationalPolicies = JsonUtils.GSON_JPA_MODEL.fromJson(operationalPoliciesJson,
OPERATIONAL_POLICY_TYPE);
return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies);
}
@@ -83,7 +83,7 @@ public class LoopController {
* @return The updated loop
*/
public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
- List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON.fromJson(microServicePoliciesJson,
+ List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON_JPA_MODEL.fromJson(microServicePoliciesJson,
MICROSERVICE_POLICY_TYPE);
return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies);
}
diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java
index 0be3132b..98a2fbdd 100644
--- a/src/main/java/org/onap/clamp/loop/LoopService.java
+++ b/src/main/java/org/onap/clamp/loop/LoopService.java
@@ -119,7 +119,7 @@ public class LoopService {
loop.addOperationalPolicy(
new OperationalPolicy(Policy.generatePolicyName("OPERATIONAL", loop.getModelService().getName(),
loop.getModelService().getVersion(), RandomStringUtils.randomAlphanumeric(3),
- RandomStringUtils.randomAlphanumeric(4)), loop, null, policyModel, null));
+ RandomStringUtils.randomAlphanumeric(4)), loop, null, policyModel, null, null, null));
return loopsRepository.save(loop);
}
diff --git a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java
index d47bc964..4cabe7f1 100644
--- a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java
+++ b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java
@@ -35,7 +35,6 @@ import java.util.List;
import javax.persistence.Transient;
import org.apache.camel.Exchange;
-import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.loop.Loop;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -85,18 +84,18 @@ public class PolicyComponent extends ExternalComponent {
jsonObject.add("groups", jsonArray);
for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) {
- jsonArray.add(createPdpDeploymentPayload(opPolicy.getPdpGroup(), opPolicy.getPdpSubGroup(),
+ jsonArray.add(createPdpDeploymentPayload(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(),
opPolicy.getPolicyModel().getPolicyModelType(), opPolicy.getPolicyModel().getVersion()));
}
for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) {
- jsonArray.add(createPdpDeploymentPayload(msPolicy.getPdpGroup(), msPolicy.getPdpSubGroup(),
+ jsonArray.add(createPdpDeploymentPayload(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(),
msPolicy.getPolicyModel().getPolicyModelType(), msPolicy.getPolicyModel().getVersion()));
}
String payload = new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject);
logger.info("PdpGroup policy payload: " + payload);
- return new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject);
+ return payload;
}
private static JsonObject createPdpDeploymentPayload(String pdpGroup, String pdpSubGroup,
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 66b05f65..3f45d055 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
@@ -84,6 +84,7 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
@ManyToMany(mappedBy = "policyModels", fetch = FetchType.EAGER)
private Set<LoopElementModel> usedByElementModels = new HashSet<>();
+ @Expose
@Type(type = "json")
@Column(columnDefinition = "json", name = "policy_pdp_group")
private JsonObject policyPdpGroup;
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java
index cce9e567..47dee1ae 100644
--- a/src/main/java/org/onap/clamp/policy/Policy.java
+++ b/src/main/java/org/onap/clamp/policy/Policy.java
@@ -70,7 +70,7 @@ public abstract class Policy extends AuditEntity {
@Expose
@Column(name = "pdp_sub_group")
- private String pdpSubGroup;
+ private String pdpSubgroup;
public abstract String createPolicyPayload() throws UnsupportedEncodingException;
@@ -159,21 +159,21 @@ public abstract class Policy extends AuditEntity {
}
/**
- * pdpSubGroup getter.
+ * pdpSubgroup getter.
*
- * @return the pdpSubGroup
+ * @return the pdpSubgroup
*/
- public String getPdpSubGroup() {
- return pdpSubGroup;
+ public String getPdpSubgroup() {
+ return pdpSubgroup;
}
/**
- * pdpSubGroup setter.
+ * pdpSubgroup setter.
*
- * @param pdpSubGroup the pdpSubGroup to set
+ * @param pdpSubgroup the pdpSubgroup to set
*/
- public void setPdpSubGroup(String pdpSubGroup) {
- this.pdpSubGroup = pdpSubGroup;
+ public void setPdpSubgroup(String pdpSubgroup) {
+ this.pdpSubgroup = pdpSubgroup;
}
/**
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 75efca76..7fd752c3 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
@@ -121,7 +121,7 @@ public class MicroServicePolicy extends Policy implements Serializable {
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);
+ policyModel.getPolicyModelType()), JsonObject.class),loopElementModel, null, null);
}
private JsonObject createJsonFromPolicyTosca() {
@@ -138,15 +138,19 @@ public class MicroServicePolicy extends Policy implements Serializable {
* @param shared The flag indicate whether the MicroService is
* shared
* @param jsonRepresentation The UI representation in json format
- * @param loopElementModel The loop element model from which this instance should be created
+ * @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
*/
public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared,
- JsonObject jsonRepresentation, LoopElementModel loopElementModel) {
+ JsonObject jsonRepresentation, LoopElementModel loopElementModel, String pdpGroup, String pdpSubgroup) {
this.name = name;
this.policyModel = policyModel;
this.shared = shared;
this.setJsonRepresentation(jsonRepresentation);
this.setLoopElementModel(loopElementModel);
+ this.setPdpGroup(pdpGroup);
+ this.setPdpSubgroup(pdpSubgroup);
}
@Override
@@ -284,8 +288,7 @@ public class MicroServicePolicy extends Policy implements Serializable {
}
} else if (!name.equals(other.name)) {
return false;
- }
- return true;
+ } return true;
}
private String getMicroServicePropertyNameFromTosca(JsonObject object) {
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 2af8ec72..3ad97c59 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
@@ -63,7 +63,7 @@ public class MicroServicePolicyService implements PolicyService<MicroServicePoli
return repository.save(
repository.findById(policy.getName()).map(p -> updateMicroservicePolicyProperties(p, policy, loop))
.orElse(new MicroServicePolicy(policy.getName(), policy.getPolicyModel(),
- policy.getShared(), policy.getJsonRepresentation(),null)));
+ policy.getShared(), policy.getJsonRepresentation(),null, policy.getPdpGroup(), policy.getPdpSubgroup())));
}
private MicroServicePolicy updateMicroservicePolicyProperties(MicroServicePolicy oldPolicy,
@@ -72,6 +72,8 @@ public class MicroServicePolicyService implements PolicyService<MicroServicePoli
if (!oldPolicy.getUsedByLoops().contains(loop)) {
oldPolicy.getUsedByLoops().add(loop);
}
+ oldPolicy.setPdpGroup(newPolicy.getPdpGroup());
+ oldPolicy.setPdpSubgroup(newPolicy.getPdpSubgroup());
return oldPolicy;
}
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 1c784057..aab30bfb 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -98,20 +98,24 @@ public class OperationalPolicy extends Policy implements Serializable {
* json
* @param policyModel The policy model associated if any, can be null
* @param loopElementModel The loop element from which this instance is supposed to be created
+ * @param pdpGroup The Pdp Group info
+ * @param pdpSubgroup The Pdp Subgroup info
*/
public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson, PolicyModel policyModel,
- LoopElementModel loopElementModel) {
+ LoopElementModel loopElementModel, String pdpGroup, String pdpSubgroup) {
this.name = name;
this.loop = loop;
this.setPolicyModel(policyModel);
this.setConfigurationsJson(configurationsJson);
+ this.setPdpGroup(pdpGroup);
+ this.setPdpSubgroup(pdpSubgroup);
this.setLoopElementModel(loopElementModel);
if (policyModel != null && policyModel.getPolicyModelType().contains("legacy")) {
LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop);
}
try {
this.setJsonRepresentation(
- OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));
+ OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));
} catch (JsonSyntaxException | IOException | NullPointerException e) {
logger.error("Unable to generate the operational policy Schema ... ", e);
this.setJsonRepresentation(new JsonObject());
@@ -252,11 +256,13 @@ public class OperationalPolicy extends Policy implements Serializable {
public Map<String, String> createGuardPolicyPayloads() {
Map<String, String> result = new HashMap<>();
- JsonElement guardsList = this.getConfigurationsJson().get("guard_policies");
- if (guardsList != null) {
- for (JsonElement guardElem : guardsList.getAsJsonArray()) {
- result.put(guardElem.getAsJsonObject().get("policy-id").getAsString(),
+ if (this.getConfigurationsJson() != null) {
+ JsonElement guardsList = this.getConfigurationsJson().get("guard_policies");
+ if (guardsList != null) {
+ for (JsonElement guardElem : guardsList.getAsJsonArray()) {
+ result.put(guardElem.getAsJsonObject().get("policy-id").getAsString(),
new GsonBuilder().create().toJson(guardElem));
+ }
}
}
logger.info("Guard policy payload: " + result);
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
index cc636bab..357a96d2 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
@@ -49,10 +49,10 @@ public class OperationalPolicyService implements PolicyService<OperationalPolicy
.map(policy ->
operationalPolicyRepository
.findById(policy.getName())
- .map(p -> setConfigurationJson(p, policy.getConfigurationsJson()))
+ .map(p -> setConfigurationJson(p, policy))
.orElse(new OperationalPolicy(policy.getName(), loop,
policy.getConfigurationsJson(),
- policy.getPolicyModel(), null)))
+ policy.getPolicyModel(), null, policy.getPdpGroup(), policy.getPdpSubgroup())))
.collect(Collectors.toSet());
}
@@ -61,8 +61,10 @@ public class OperationalPolicyService implements PolicyService<OperationalPolicy
return operationalPolicyRepository.existsById(policyName);
}
- private OperationalPolicy setConfigurationJson(OperationalPolicy policy, JsonObject configurationsJson) {
- policy.setConfigurationsJson(configurationsJson);
+ private OperationalPolicy setConfigurationJson(OperationalPolicy policy, OperationalPolicy newPolicy) {
+ policy.setConfigurationsJson(newPolicy.getConfigurationsJson());
+ policy.setPdpGroup(newPolicy.getPdpGroup());
+ policy.setPdpSubgroup(newPolicy.getPdpSubgroup());
return policy;
}
}