aboutsummaryrefslogtreecommitdiffstats
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
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>
-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
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java2
-rw-r--r--src/test/java/org/onap/clamp/loop/DcaeComponentTest.java2
-rw-r--r--src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java26
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopToJsonTest.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/PolicyComponentTest.java13
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java6
-rw-r--r--ui-react/src/api/LoopCache.js87
-rw-r--r--ui-react/src/api/LoopCache.test.js11
-rw-r--r--ui-react/src/components/dialogs/Policy/PolicyModal.js111
24 files changed, 248 insertions, 105 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;
}
}
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
index 2ccecf3e..184a391d 100644
--- a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
@@ -70,7 +70,7 @@ public class ClampGraphBuilderTest {
null);
OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(),
- new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"), null);
+ new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"), null, null, null);
final Set<OperationalPolicy> opPolicies = Set.of(opPolicy);
final Set<MicroServicePolicy> microServices = Set.of(ms1, ms2);
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
index 7b83a4c3..a320131c 100644
--- a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
@@ -44,7 +44,7 @@ public class SvgLoopGeneratorTest {
new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0", "short.ms2"),
false, null);
OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(),
- new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"), null);
+ new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"), null, null, null);
Loop loop = new Loop();
loop.addMicroServicePolicy(ms1);
loop.addMicroServicePolicy(ms2);
diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
index 50e2e8d3..fc7e1c90 100644
--- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
@@ -54,7 +54,7 @@ public class DcaeComponentTest {
MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", new PolicyModel("policy1",
"tosca_definitions_version: tosca_simple_yaml_1_0_0","1.0.0"), true,
- new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null);
+ new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null, null, null);
microServicePolicy.setConfigurationsJson(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class));
loopTest.addMicroServicePolicy(microServicePolicy);
diff --git a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
index 3c2ce17e..f1d29922 100644
--- a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
@@ -297,7 +297,7 @@ public class DeployFlowTestItCase {
policyModelsService.saveOrUpdatePolicyModel(policyModel);
MicroServicePolicy microService = new MicroServicePolicy(name, policyModel,
shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), null);
+ gson.fromJson(jsonRepresentation, JsonObject.class), null, null, null);
microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
diff --git a/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
index 714cbd59..f017dd89 100644
--- a/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
@@ -135,7 +135,7 @@ public class LoopControllerTestItCase {
"tosca_definitions_version: tosca_simple_yaml_1_0_0","1.0.0");
policyModelsService.saveOrUpdatePolicyModel(policyModel);
MicroServicePolicy policy = new MicroServicePolicy("policyName", policyModel, false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
loopController.updateMicroservicePolicy(EXAMPLE_LOOP_NAME, policy);
assertThat(microServicePolicyService.isExisting("policyName")).isTrue();
}
diff --git a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
index acde66d9..47b4b65c 100644
--- a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
@@ -90,7 +90,7 @@ public class LoopRepositoriesItCase {
}
private OperationalPolicy getOperationalPolicy(String configJson, String name, PolicyModel policyModel) {
- return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel, null);
+ return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel, null, null, null);
}
private LoopElementModel getLoopElementModel(String yaml, String name, String policyType, String createdBy,
@@ -130,7 +130,7 @@ public class LoopRepositoriesItCase {
private MicroServicePolicy getMicroServicePolicy(String name, String jsonRepresentation, String jsonProperties,
boolean shared, PolicyModel policyModel) {
MicroServicePolicy microService = new MicroServicePolicy(name, policyModel, shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), null);
+ gson.fromJson(jsonRepresentation, JsonObject.class), null, null, null);
microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
}
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index 849ca5cf..5449ada1 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -101,7 +101,7 @@ public class LoopServiceTestItCase {
// given
saveTestLoopToDb();
OperationalPolicy operationalPolicy = new OperationalPolicy("policyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null, null);
// when
Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
@@ -129,7 +129,7 @@ public class LoopServiceTestItCase {
"tosca_definitions_version: tosca_simple_yaml_1_0_0", "1.0.0", "policyModel1");
policyModelsService.saveOrUpdatePolicyModel(policyModel);
MicroServicePolicy microServicePolicy = new MicroServicePolicy("policyName", policyModel,
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
// when
Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME,
@@ -159,11 +159,11 @@ public class LoopServiceTestItCase {
"tosca_definitions_version: tosca_simple_yaml_1_0_0", "1.0.0", "secondPolicyName");
policyModelsService.saveOrUpdatePolicyModel(policyModel2);
MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy("firstPolicyName", policyModel1, false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy("secondPolicyName", policyModel2, false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
// when
firstMicroServicePolicy
@@ -203,11 +203,11 @@ public class LoopServiceTestItCase {
"tosca_definitions_version: tosca_simple_yaml_1_0_0", "1.0.0", "secondPolicyName");
policyModelsService.saveOrUpdatePolicyModel(policyModel2);
MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy("firstPolicyName", policyModel1,
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy("secondPolicyName", policyModel2,
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
// when
Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME,
@@ -232,11 +232,11 @@ public class LoopServiceTestItCase {
JsonObject newJsonConfiguration = JsonUtils.GSON.fromJson("{}", JsonObject.class);
OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null, null);
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy("secondPolicyName", null,
- newJsonConfiguration, null, null);
+ newJsonConfiguration, null, null, null, null);
// when
firstOperationalPolicy.setConfigurationsJson(newJsonConfiguration);
@@ -263,11 +263,11 @@ public class LoopServiceTestItCase {
saveTestLoopToDb();
OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null, null);
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy("policyName", null,
- JsonUtils.GSON.fromJson("{}", JsonObject.class), null, null);
+ JsonUtils.GSON.fromJson("{}", JsonObject.class), null, null, "pdpGroup1", "pdpSubgroup1");
// when
Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
@@ -319,7 +319,7 @@ public class LoopServiceTestItCase {
loop = loopService.saveOrUpdateLoop(loop);
// Add op policy
OperationalPolicy operationalPolicy = new OperationalPolicy("opPolicy", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null, null);
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy));
PolicyModel policyModel = new PolicyModel("org.policies.microPolicy",
@@ -327,7 +327,7 @@ public class LoopServiceTestItCase {
policyModelsService.saveOrUpdatePolicyModel(policyModel);
// Add Micro service policy
MicroServicePolicy microServicePolicy = new MicroServicePolicy("microPolicy", policyModel,
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(microServicePolicy));
// Verify it's there
@@ -371,7 +371,7 @@ public class LoopServiceTestItCase {
"tosca_definitions_version: tosca_simple_yaml_1_0_0", "1.0.0", "policyName");
policyModelsService.saveOrUpdatePolicyModel(policyModel);
MicroServicePolicy microServicePolicy = new MicroServicePolicy("policyName", policyModel,
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null, null);
loopService.updateMicroservicePolicy(EXAMPLE_LOOP_NAME, microServicePolicy);
assertThat(microServicePolicyService.isExisting("policyName")).isTrue();
}
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
index 6c6fb0c8..de2ef145 100644
--- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
+++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
@@ -52,7 +52,7 @@ public class LoopToJsonTest {
private OperationalPolicy getOperationalPolicy(String configJson, String name) {
return new OperationalPolicy(name, null, gson.fromJson(configJson, JsonObject.class),
- getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"), null);
+ getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"), null, null, null);
}
private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
@@ -70,7 +70,7 @@ public class LoopToJsonTest {
String policyTosca, String jsonProperties, boolean shared) {
MicroServicePolicy microService = new MicroServicePolicy(name, new PolicyModel(modelType, policyTosca, "1.0.0"),
shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), null);
+ gson.fromJson(jsonRepresentation, JsonObject.class), null, null, null);
microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
}
diff --git a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
index 52e10d2d..370c319b 100644
--- a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
@@ -26,7 +26,9 @@ package org.onap.clamp.loop;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
+
import java.io.IOException;
+import java.util.HashSet;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.junit.Test;
@@ -258,18 +260,12 @@ public class PolicyComponentTest {
PolicyModel policyModel1 = new PolicyModel("onap.policies.monitoring.test", null, "1.0.0");
MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", policyModel1, true,
- new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null);
- microServicePolicy.setPdpGroup("pdpGroup1");
- microServicePolicy.setPdpSubGroup("pdpSubgroup1");
-
+ new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null, "pdpGroup1", "pdpSubgroup1");
loopTest.addMicroServicePolicy(microServicePolicy);
PolicyModel policyModel2 = new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0");
OperationalPolicy opPolicy = new OperationalPolicy("opPolicy", loopTest,
- new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), policyModel2, null);
- opPolicy.setPdpGroup("pdpGroup2");
- opPolicy.setPdpSubGroup("pdpSubgroup2");
-
+ new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), policyModel2, null, "pdpGroup2", "pdpSubgroup2");
loopTest.addOperationalPolicy(opPolicy);
LoopTemplate loopTemplate = new LoopTemplate("test", "yaml", "svg", 1, null);
@@ -278,6 +274,7 @@ public class PolicyComponentTest {
String payload = PolicyComponent.createPoliciesPayloadPdpGroup(loopTest);
String expectedRes = ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json");
+
assertThat(payload).isEqualTo(expectedRes);
}
}
diff --git a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
index bdc7e80d..5686bc16 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -41,7 +41,7 @@ public class OperationalPolicyPayloadTest {
public void testOperationalPolicyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
- OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null, null, null);
assertThat(policy.createPolicyPayloadYaml())
.isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));
@@ -63,7 +63,7 @@ public class OperationalPolicyPayloadTest {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"),
JsonObject.class);
- OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null, null, null);
Map<String, String> guardsMap = policy.createGuardPolicyPayloads();
assertThat(guardsMap).isEmpty();
assertThat(guardsMap.entrySet()).isEmpty();
@@ -73,7 +73,7 @@ public class OperationalPolicyPayloadTest {
public void testGuardPolicyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
- OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null, null, null);
Map<String, String> guardsMap = policy.createGuardPolicyPayloads();
diff --git a/ui-react/src/api/LoopCache.js b/ui-react/src/api/LoopCache.js
index 03cec9fa..c8ecca2f 100644
--- a/ui-react/src/api/LoopCache.js
+++ b/ui-react/src/api/LoopCache.js
@@ -36,12 +36,34 @@ export default class LoopCache {
}
}
+ updateMicroServicePdpGroup(name, pdpGroup, pdpSubgroup) {
+ for (var policy in this.loopJsonCache["microServicePolicies"]) {
+ if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) {
+ this.loopJsonCache["microServicePolicies"][policy]["pdpGroup"] = pdpGroup;
+ this.loopJsonCache["microServicePolicies"][policy]["pdpSubgroup"] = pdpSubgroup;
+ }
+ }
+ }
+
updateGlobalProperties(newGlobalProperties) {
this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties;
}
- updateOperationalPolicyProperties(newOpProperties) {
- this.loopJsonCache["operationalPolicies"] = newOpProperties;
+ updateOperationalPolicyProperties(name, newOpProperties) {
+ for (var policy in this.loopJsonCache["operationalPolicies"]) {
+ if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) {
+ this.loopJsonCache["operationalPolicies"][policy]["configurationsJson"] = newOpProperties;
+ }
+ }
+ }
+
+ updateOperationalPolicyPdpGroup(name, pdpGroup, pdpSubgroup) {
+ for (var policy in this.loopJsonCache["operationalPolicies"]) {
+ if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) {
+ this.loopJsonCache["operationalPolicies"][policy]["pdpGroup"] = pdpGroup;
+ this.loopJsonCache["operationalPolicies"][policy]["pdpSubgroup"] = pdpSubgroup;
+ }
+ }
}
getLoopName() {
@@ -51,7 +73,7 @@ export default class LoopCache {
getOperationalPolicyConfigurationJson() {
return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"];
}
-
+
getOperationalPolicyJsonSchema() {
return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"];
}
@@ -97,13 +119,60 @@ export default class LoopCache {
}
getOperationalPolicyJsonRepresentationForName(name) {
- var opConfig = this.getOperationalPolicyForName(name);
- if (opConfig !== null) {
- return opConfig["jsonRepresentation"];
- }
- return null;
- }
+ var opConfig = this.getOperationalPolicyForName(name);
+ if (opConfig !== null) {
+ return opConfig["jsonRepresentation"];
+ }
+ return null;
+ }
+
+ getOperationalPolicySupportedPdpgroup(name) {
+ var opConfig=this.getOperationalPolicyForName(name);
+ if (opConfig !== null) {
+ return opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
+ }
+ return null;
+ }
+
+ getOperationalPolicyPdpGroup(name) {
+ var opConfig=this.getOperationalPolicyForName(name);
+ if (opConfig !== null) {
+ return opConfig["pdpGroup"];
+ }
+ return null;
+ }
+
+ getOperationalPolicyPdpSubgroup(name) {
+ var opConfig=this.getOperationalPolicyForName(name);
+ if (opConfig !== null) {
+ return opConfig["pdpSubgroup"];
+ }
+ return null;
+ }
+ getMicroServiceSupportedPdpgroup(name) {
+ var microService=this.getMicroServiceForName(name);
+ if (microService !== null) {
+ return microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
+ }
+ return null;
+ }
+
+ getMicroServicePdpGroup(name) {
+ var microService=this.getMicroServiceForName(name);
+ if (microService !== null) {
+ return microService["pdpGroup"];
+ }
+ return null;
+ }
+
+ getMicroServicePdpSubgroup(name) {
+ var microService=this.getMicroServiceForName(name);
+ if (microService !== null) {
+ return microService["pdpSubgroup"];
+ }
+ return null;
+ }
getMicroServiceForName(name) {
var msProperties=this.getMicroServicePolicies();
diff --git a/ui-react/src/api/LoopCache.test.js b/ui-react/src/api/LoopCache.test.js
index 97c09fa3..fc756814 100644
--- a/ui-react/src/api/LoopCache.test.js
+++ b/ui-react/src/api/LoopCache.test.js
@@ -206,18 +206,15 @@ describe('Verify LoopCache functions', () => {
});
it('updateOperationalPolicyProperties', () => {
- const newOpPolicy = [{
- "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca_new",
- "configurationsJson": {
+ const newOpPolicy = {
"guard_policies": {},
"operational_policy": {
"controlLoop": {},
"policies": []
}
- }
- }];
- loopCache.updateOperationalPolicyProperties(newOpPolicy);
- expect(loopCache.getOperationalPolicies()).toStrictEqual(newOpPolicy);
+ };
+ loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy);
+ expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy);
});
it('updateMicroServiceProperties', () => {
diff --git a/ui-react/src/components/dialogs/Policy/PolicyModal.js b/ui-react/src/components/dialogs/Policy/PolicyModal.js
index 51a6464c..caae70ef 100644
--- a/ui-react/src/components/dialogs/Policy/PolicyModal.js
+++ b/ui-react/src/components/dialogs/Policy/PolicyModal.js
@@ -23,6 +23,10 @@
import React from 'react'
import Button from 'react-bootstrap/Button';
+import Form from 'react-bootstrap/Form';
+import Col from 'react-bootstrap/Col';
+import Row from 'react-bootstrap/Row';
+import Select from 'react-select';
import Modal from 'react-bootstrap/Modal';
import styled from 'styled-components';
import LoopService from '../../../api/LoopService';
@@ -40,7 +44,12 @@ export default class PolicyModal extends React.Component {
jsonEditor: null,
policyName: this.props.match.params.policyName,
// This is to indicate whether it's an operational or config policy (in terms of loop instance)
- policyInstanceType: this.props.match.params.policyInstanceType
+ policyInstanceType: this.props.match.params.policyInstanceType,
+ pdpGroup: null,
+ pdpGroupList: [],
+ pdpSubgroupList: [],
+ chosenPdpGroup: '',
+ chosenPdpSubgroup: ''
};
constructor(props, context) {
@@ -48,6 +57,8 @@ export default class PolicyModal extends React.Component {
this.handleClose = this.handleClose.bind(this);
this.handleSave = this.handleSave.bind(this);
this.renderJsonEditor = this.renderJsonEditor.bind(this);
+ this.handlePdpGroupChange = this.handlePdpGroupChange.bind(this);
+ this.handlePdpSubgroupChange = this.handlePdpSubgroupChange.bind(this);
}
handleSave() {
@@ -63,18 +74,20 @@ export default class PolicyModal extends React.Component {
console.info("NO validation errors found in policy data");
if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') {
this.state.loopCache.updateMicroServiceProperties(this.state.policyName, editorData[0]);
+ this.state.loopCache.updateMicroServicePdpGroup(this.state.policyName, this.state.chosenPdpGroup, this.state.chosenPdpSubgroup);
LoopService.setMicroServiceProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getMicroServiceForName(this.state.policyName)).then(resp => {
this.setState({ show: false });
this.props.history.push('/');
this.props.loadLoopFunction(this.state.loopCache.getLoopName());
});
} else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') {
- this.state.loopCache.updateOperationalPolicyProperties(editorData);
- LoopService.setOperationalPolicyProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getOperationalPolicyForName(this.state.policyName)).then(resp => {
- this.setState({ show: false });
- this.props.history.push('/');
- this.props.loadLoopFunction(this.state.loopCache.getLoopName());
- });
+ this.state.loopCache.updateOperationalPolicyProperties(this.state.policyName, editorData[0]);
+ this.state.loopCache.updateOperationalPolicyPdpGroup(this.state.policyName, this.state.chosenPdpGroup, this.state.chosenPdpSubgroup);
+ LoopService.setOperationalPolicyProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getOperationalPolicies()).then(resp => {
+ this.setState({ show: false });
+ this.props.history.push('/');
+ this.props.loadLoopFunction(this.state.loopCache.getLoopName());
+ });
}
}
}
@@ -91,14 +104,22 @@ export default class PolicyModal extends React.Component {
renderJsonEditor() {
console.debug("Rendering PolicyModal ", this.state.policyName);
var toscaModel = {};
- var editorData = {};
- if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') {
- toscaModel = this.state.loopCache.getMicroServiceJsonRepresentationForName(this.state.policyName);
- editorData = this.state.loopCache.getMicroServicePropertiesForName(this.state.policyName);
- } else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') {
- toscaModel = this.state.loopCache.getOperationalPolicyJsonRepresentationForName(this.state.policyName);
- editorData = this.state.loopCache.getOperationalPolicyPropertiesForName(this.state.policyName);
- }
+ var editorData = {};
+ var pdpGroupValues = {};
+ var chosenPdpGroupValue, chosenPdpSubgroupValue;
+ if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') {
+ toscaModel = this.state.loopCache.getMicroServiceJsonRepresentationForName(this.state.policyName);
+ editorData = this.state.loopCache.getMicroServicePropertiesForName(this.state.policyName);
+ pdpGroupValues = this.state.loopCache.getMicroServiceSupportedPdpgroup(this.state.policyName);
+ chosenPdpGroupValue = this.state.loopCache.getMicroServicePdpGroup(this.state.policyName);
+ chosenPdpSubgroupValue = this.state.loopCache.getMicroServicePdpSubgroup(this.state.policyName);
+ } else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') {
+ toscaModel = this.state.loopCache.getOperationalPolicyJsonRepresentationForName(this.state.policyName);
+ editorData = this.state.loopCache.getOperationalPolicyPropertiesForName(this.state.policyName);
+ pdpGroupValues = this.state.loopCache.getOperationalPolicySupportedPdpgroup(this.state.policyName);
+ chosenPdpGroupValue = this.state.loopCache.getOperationalPolicyPdpGroup(this.state.policyName);
+ chosenPdpSubgroupValue = this.state.loopCache.getOperationalPolicyPdpSubgroup(this.state.policyName);
+ }
if (toscaModel == null) {
return;
@@ -114,10 +135,48 @@ export default class PolicyModal extends React.Component {
JSONEditor.defaults.options.disable_array_delete_all_rows = false;
JSONEditor.defaults.options.show_errors = 'always';
- this.setState({
- jsonEditor: new JSONEditor(document.getElementById("editor"),
- { schema: toscaModel.schema, startval: editorData })
- })
+ var pdpGroupListValues = pdpGroupValues.map(entry => {
+ return { label: Object.keys(entry)[0], value: Object.keys(entry)[0] };
+ });
+
+ if (typeof(chosenPdpGroupValue) === "undefined") {
+ this.setState({
+ jsonEditor: new JSONEditor(document.getElementById("editor"),
+ { schema: toscaModel.schema, startval: editorData }),
+ pdpGroup: pdpGroupValues,
+ pdpGroupList: pdpGroupListValues,
+ chosenPdpGroup: chosenPdpGroupValue,
+ chosenPdpSubgroup: chosenPdpSubgroupValue
+ })
+ } else {
+ var selectedPdpGroup = pdpGroupValues.filter(entry => (Object.keys(entry)[0] === chosenPdpGroupValue));
+ const pdpSubgroupValues = selectedPdpGroup[0][chosenPdpGroupValue].map((pdpSubgroup) => { return { label: pdpSubgroup, value: pdpSubgroup } });
+ this.setState({
+ jsonEditor: new JSONEditor(document.getElementById("editor"),
+ { schema: toscaModel.schema, startval: editorData }),
+ pdpGroup: pdpGroupValues,
+ pdpGroupList: pdpGroupListValues,
+ pdpSubgroupList: pdpSubgroupValues,
+ chosenPdpGroup: chosenPdpGroupValue,
+ chosenPdpSubgroup: chosenPdpSubgroupValue
+ })
+ }
+ }
+
+ handlePdpGroupChange(e) {
+ var selectedPdpGroup = this.state.pdpGroup.filter(entry => (Object.keys(entry)[0] === e.value));
+ const pdpSubgroupValues = selectedPdpGroup[0][e.value].map((pdpSubgroup) => { return { label: pdpSubgroup, value: pdpSubgroup } });
+ if (this.state.chosenPdpGroup !== e.value) {
+ this.setState({
+ chosenPdpGroup: e.value,
+ chosenPdpSubgroup: '',
+ pdpSubgroupList: pdpSubgroupValues
+ });
+ }
+ }
+
+ handlePdpSubgroupChange(e) {
+ this.setState({ chosenPdpSubgroup: e.value });
}
render() {
@@ -128,15 +187,23 @@ export default class PolicyModal extends React.Component {
</Modal.Header>
<Modal.Body>
<div id="editor" />
-
+ <Form.Group as={Row} controlId="formPlaintextEmail">
+ <Form.Label column sm="2">Pdp Group Info</Form.Label>
+ <Col sm="3">
+ <Select value={{ label: this.state.chosenPdpGroup, value: this.state.chosenPdpGroup }} onChange={this.handlePdpGroupChange} options={this.state.pdpGroupList} />
+ </Col>
+ <Col sm="3">
+ <Select value={{ label: this.state.chosenPdpSubgroup, value: this.state.chosenPdpSubgroup }} onChange={this.handlePdpSubgroupChange} options={this.state.pdpSubgroupList} />
+ </Col>
+ </Form.Group>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={this.handleClose}>
Close
- </Button>
+ </Button>
<Button variant="primary" onClick={this.handleSave}>
Save Changes
- </Button>
+ </Button>
</Modal.Footer>
</ModalStyled>