From 3718a16bedbc4a5ecf2593abcb2075238fa99767 Mon Sep 17 00:00:00 2001 From: sebdet Date: Fri, 12 Feb 2021 17:18:47 +0100 Subject: Modify Backend for listing the policies Improve Ui components to list policies + changes an existing camel route to expose the policy json schema properly. New files added to emulator for testing + comments added. Now the Ui can show the policy config Issue-ID: POLICY-3061 Signed-off-by: sebdet Change-Id: Iacf9577a4ab2cc927d05ff267e7356d8410eb77a Signed-off-by: sebdet --- .../policy/clamp/clds/config/AafConfiguration.java | 3 +- .../clamp/clds/tosca/ToscaYamlToJsonConvertor.java | 3 +- .../ToscaConverterWithDictionarySupport.java | 9 +- .../update/parser/ToscaConverterToJsonSchema.java | 14 +- .../clamp/loop/template/PolicyModelsService.java | 28 ++++ .../clamp/policy/pdpgroup/PoliciesPdpMerger.java | 4 +- .../resources/clds/camel/rest/clamp-api-v2.xml | 5 +- .../clamp/loop/PolicyModelServiceItCase.java | 91 +++++++---- .../api/v1/blueprint-model/workflow-spec/.header | 2 +- .../baseconfiguration/version/1.0.0/.header | 2 +- .../example/policy/api/v1/policies/.header | 2 +- .../example/policy/api/v1/policytypes/.file | 7 + .../example/policy/api/v1/policytypes/.header | 2 +- .../onap.policies.Naming/versions/1.0.0/.file | 101 ++++++++++++ .../onap.policies.Naming/versions/1.0.0/.header | 1 + .../versions/1.0.0/.header | 2 +- .../versions/1.0.0/.header | 2 +- .../versions/1.0.0/.header | 2 +- .../versions/2.0.0/.header | 2 +- .../versions/1.0.0/.header | 2 +- .../versions/1.0.0/.header | 2 +- .../versions/1.0.0/.header | 2 +- .../versions/1.0.0/.header | 2 +- .../http-cache/example/policy/pap/v1/pdps/.header | 2 +- src/test/resources/tosca/tca_hi_lo.json | 179 +++++++++++++++++++++ ui-react/src/api/PolicyToscaService.js | 6 +- .../components/dialogs/Policy/ViewAllPolicies.js | 68 +++++++- 27 files changed, 479 insertions(+), 66 deletions(-) create mode 100644 src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.file create mode 100644 src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.header create mode 100644 src/test/resources/tosca/tca_hi_lo.json diff --git a/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java b/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java index 30ba6e6ae..9b6338e00 100644 --- a/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java +++ b/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights + * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -58,6 +58,7 @@ public class AafConfiguration { registration.addUrlPatterns("/restservices/clds/v2/templates/*"); registration.addUrlPatterns("/restservices/clds/v2/clampInformation/*"); registration.addUrlPatterns("/restservices/clds/v2/policyToscaModels/*"); + registration.addUrlPatterns("/restservices/clds/v2/policies/*"); registration.addUrlPatterns("/restservices/clds/v2/loop/*"); registration.setName("cadiFilter"); registration.setOrder(0); diff --git a/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java b/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java index d6b0a031f..4f718d5d7 100644 --- a/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java +++ b/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights + * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -51,6 +51,7 @@ import org.yaml.snakeyaml.Yaml; * */ @Component +@Deprecated public class ToscaYamlToJsonConvertor { @Autowired diff --git a/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java b/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java index 3505c8b86..6702a6200 100644 --- a/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java +++ b/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,6 +36,13 @@ import org.onap.policy.clamp.loop.service.Service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +/** + * This is the main class that must be used to convert a tosca to a json schema. + * This class adds feature to support the dictionary mechanism that enables json possible values extracted + * from the dictionary DB table. + * + * @see org.onap.policy.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport#convertToscaToJsonSchemaObject + */ @Component public class ToscaConverterWithDictionarySupport { diff --git a/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java b/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java index c7cc7e7fa..5a9720a00 100644 --- a/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java +++ b/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +35,15 @@ import org.onap.policy.clamp.clds.tosca.update.parser.metadata.ToscaMetadataPars import org.onap.policy.clamp.clds.tosca.update.templates.JsonTemplate; import org.onap.policy.clamp.loop.service.Service; +/** + * This class can be used to convert a tosca to a json schema. + * This class is not supposed to be used directly because it requires the json Schema templates + * (template conversion tosca type to json schema entry) but also the supported Tosca main type file. + * The class ToscaConverterWithDictionarySupport is more complete for the end user to be used (in the clamp context). + * + * @see org.onap.policy.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport#convertToscaToJsonSchemaObject + * @see org.onap.policy.clamp.clds.tosca.update.parser.ToscaConverterToJsonSchema#getJsonSchemaOfToscaElement + */ public class ToscaConverterToJsonSchema { private LinkedHashMap components; private LinkedHashMap templates; @@ -266,11 +275,12 @@ public class ToscaConverterToJsonSchema { // Native cases JsonObject itemContainer = new JsonObject(); String valueInEntrySchema = - this.extractSpecificFieldFromMap(toscaElementProperty, "entry_schema"); + this.extractSpecificFieldFromMap(toscaElementProperty, "entry_schema"); itemContainer.addProperty("type", valueInEntrySchema); propertiesInJson.add("items", itemContainer); propertiesInJson.addProperty("format", "tabs-top"); } + // MAP Case, for now nothing break; diff --git a/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java index c4182bd2f..fea58c552 100644 --- a/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java +++ b/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java @@ -29,6 +29,9 @@ import java.util.Collections; import java.util.List; import org.onap.policy.clamp.clds.tosca.ToscaSchemaConstants; import org.onap.policy.clamp.clds.tosca.ToscaYamlToJsonConvertor; +import org.onap.policy.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport; +import org.onap.policy.clamp.clds.tosca.update.parser.ToscaConverterToJsonSchema; +import org.onap.policy.clamp.clds.util.JsonUtils; import org.onap.policy.clamp.policy.pdpgroup.PdpGroupsAnalyzer; import org.onap.policy.clamp.util.SemanticVersioning; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -43,8 +46,17 @@ import org.springframework.transaction.annotation.Transactional; @Service public class PolicyModelsService { private final PolicyModelsRepository policyModelsRepository; + /** + * This variable is there to support legacy saving of the tosca from the clamp UI. + */ private ToscaYamlToJsonConvertor toscaYamlToJsonConvertor; + /** + * This is the new tosca converter that must be used in clamp. + */ + @Autowired + private ToscaConverterWithDictionarySupport toscaConverterWithDictionarySupport; + @Autowired public PolicyModelsService(PolicyModelsRepository policyModelrepo, ToscaYamlToJsonConvertor convertor) { @@ -110,6 +122,22 @@ public class PolicyModelsService { return saveOrUpdatePolicyModel(thePolicyModel); } + /** + * This method retrieves the tosca model and convert it to a Json schema. + * That json schema is normally used by the UI. + * + * @param policyType The policy model type id + * @param policyTypeVersion The policy model type version + * @return A JsonObject with the json schema describing the tosca + */ + public JsonObject getPolicyModelJson(String policyType, String policyTypeVersion) { + PolicyModel thePolicyModel = getPolicyModel(policyType, policyTypeVersion); + // In the following use case we are not in the context of a closed loop, so the enrichment + // of the json cannot be done, that's why the serviceModel provided is NULL. + return toscaConverterWithDictionarySupport + .convertToscaToJsonSchemaObject(thePolicyModel.getPolicyModelTosca(), policyType, null); + } + public List getAllPolicyModelTypes() { return policyModelsRepository.getAllPolicyModelType(); } diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java index 0bd45cd33..7e3fe8cf4 100644 --- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java @@ -55,7 +55,7 @@ public class PoliciesPdpMerger { } /** - * This method merges 2 JsonElement together. If the jsonToMerge is null nothign is changed. + * This method merges 2 JsonElement together. If the jsonToMerge is null nothing is changed. * * @param json The initial json that will received the data * @param jsonToMerge The json that will be added to the first json object @@ -101,4 +101,4 @@ public class PoliciesPdpMerger { policyJsonNode.get("type_version").getAsString()); mergeJsonElement(policyJsonNode, supportedPdpGroupsJson); } -} +} \ No newline at end of file diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml index e1f138b1d..7ca4f081e 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -1075,8 +1075,7 @@ + outType="com.google.gson.JsonObject" produces="application/json"> @@ -1086,7 +1085,7 @@ + uri="bean:org.onap.policy.clamp.loop.template.PolicyModelsService?method=getPolicyModelJson(${header.policyModelType},${header.policyModelVersion})"/> diff --git a/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java index a98291be0..35ae9ed64 100644 --- a/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java +++ b/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java @@ -48,6 +48,7 @@ import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; +import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -91,7 +92,7 @@ public class PolicyModelServiceItCase { public void shouldCreatePolicyModel() { // given PolicyModel policyModel = getPolicyModel(POLICY_MODEL_TYPE_1, "yaml", - POLICY_MODEL_TYPE_1_VERSION_1, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_1_VERSION_1, "TEST", "VARIANT", "user"); // when PolicyModel actualPolicyModel = policyModelsService.saveOrUpdatePolicyModel(policyModel); @@ -99,24 +100,24 @@ public class PolicyModelServiceItCase { // then assertThat(actualPolicyModel).isNotNull(); assertThat(actualPolicyModel).isEqualTo(policyModelsRepository - .findById(new PolicyModelId(actualPolicyModel.getPolicyModelType(), - actualPolicyModel.getVersion())) - .get()); + .findById(new PolicyModelId(actualPolicyModel.getPolicyModelType(), + actualPolicyModel.getVersion())) + .get()); assertThat(actualPolicyModel.getPolicyModelType()) - .isEqualTo(policyModel.getPolicyModelType()); + .isEqualTo(policyModel.getPolicyModelType()); Assertions.assertThat(actualPolicyModel.getCreatedBy()).isEqualTo("Not found"); Assertions.assertThat(actualPolicyModel.getCreatedDate()).isNotNull(); assertThat(actualPolicyModel.getPolicyAcronym()).isEqualTo(policyModel.getPolicyAcronym()); assertThat(actualPolicyModel.getPolicyModelTosca()) - .isEqualTo(policyModel.getPolicyModelTosca()); + .isEqualTo(policyModel.getPolicyModelTosca()); Assertions.assertThat(actualPolicyModel.getUpdatedBy()).isEqualTo("Not found"); Assertions.assertThat(actualPolicyModel.getUpdatedDate()).isNotNull(); assertThat(actualPolicyModel.getVersion()).isEqualTo(policyModel.getVersion()); assertThat( - policyModelsService.getPolicyModel(POLICY_MODEL_TYPE_1, POLICY_MODEL_TYPE_1_VERSION_1)) + policyModelsService.getPolicyModel(POLICY_MODEL_TYPE_1, POLICY_MODEL_TYPE_1_VERSION_1)) .isEqualToIgnoringGivenFields(policyModel, "createdDate", "updatedDate", - "createdBy", "updatedBy"); + "createdBy", "updatedBy"); } /** @@ -128,13 +129,36 @@ public class PolicyModelServiceItCase { @Transactional public void shouldCreatePolicyModelFromTosca() throws IOException { String toscaModelYaml = - ResourceFileUtils.getResourceAsString("tosca/tosca_with_metadata.yaml"); + ResourceFileUtils.getResourceAsString("tosca/tosca_with_metadata.yaml"); PolicyModel policyModel = policyModelsService.createNewPolicyModelFromTosca(toscaModelYaml); assertThat(policyModelsService.getAllPolicyModels()).contains(policyModel); assertThat(policyModelsService.getPolicyModelTosca(policyModel.getPolicyModelType(), - policyModel.getVersion())).contains(toscaModelYaml); + policyModel.getVersion())).contains(toscaModelYaml); + } + + /** + * This tests the getPolicyModelJson. A json is expected. + * + * @throws IOException In case of failure + */ + @Test + @Transactional + public void shouldGetPolicyModelInJson() throws IOException { + PolicyModel policyModel = getPolicyModel("onap.policies.monitoring.cdap.tca.hi.lo.app", + ResourceFileUtils.getResourceAsString( + "http-cache/example/policy/api/v1/policytypes/" + + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/.file"), + "1.0.0", "TEST", "VARIANT", "user"); + policyModelsService.saveOrUpdatePolicyModel(policyModel); + + JsonObject policyTypeJson = + policyModelsService.getPolicyModelJson("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0"); + assertThat(policyTypeJson).isNotNull(); + JSONAssert.assertEquals(ResourceFileUtils.getResourceAsString("tosca/tca_hi_lo.json"), + policyTypeJson.toString(), + true); } /** @@ -146,13 +170,13 @@ public class PolicyModelServiceItCase { @Transactional public void shouldUpdatePolicyModel() throws IOException { String toscaModelYaml = - ResourceFileUtils.getResourceAsString("tosca/tosca_with_metadata.yaml"); + ResourceFileUtils.getResourceAsString("tosca/tosca_with_metadata.yaml"); PolicyModel policyModel = policyModelsService.createNewPolicyModelFromTosca(toscaModelYaml); String newToscaModelYaml = - ResourceFileUtils.getResourceAsString("tosca/tosca_metadata_clamp_possible_values.yaml"); + ResourceFileUtils.getResourceAsString("tosca/tosca_metadata_clamp_possible_values.yaml"); PolicyModel updatedPolicyModel = policyModelsService.updatePolicyModelTosca( - policyModel.getPolicyModelType(), policyModel.getVersion(), newToscaModelYaml); + policyModel.getPolicyModelType(), policyModel.getVersion(), newToscaModelYaml); assertThat(updatedPolicyModel.getPolicyModelTosca()).isEqualTo(newToscaModelYaml); @@ -166,15 +190,15 @@ public class PolicyModelServiceItCase { public void shouldReturnAllPolicyModelTypes() { // given PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel1); PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel2); List policyModelTypesList = policyModelsService.getAllPolicyModelTypes(); assertThat(policyModelTypesList).contains(policyModel1.getPolicyModelType(), - policyModel2.getPolicyModelType()); + policyModel2.getPolicyModelType()); } /** @@ -184,10 +208,10 @@ public class PolicyModelServiceItCase { @Transactional public void shouldReturnAllPolicyModels() { PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel1); PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel2); assertThat(policyModelsService.getAllPolicyModels()).contains(policyModel1, policyModel2); @@ -200,14 +224,14 @@ public class PolicyModelServiceItCase { @Transactional public void shouldReturnAllModelsByType() { PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel1); PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel2); assertThat(policyModelsService.getAllPolicyModelsByType(POLICY_MODEL_TYPE_2)) - .contains(policyModel1, policyModel2); + .contains(policyModel1, policyModel2); } /** @@ -217,22 +241,22 @@ public class PolicyModelServiceItCase { @Transactional public void shouldReturnSortedSet() { PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_1, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel1); PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", - POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel2); PolicyModel policyModel3 = getPolicyModel(POLICY_MODEL_TYPE_3, "yaml", - POLICY_MODEL_TYPE_3_VERSION_1, "TEST", "VARIANT", "user"); + POLICY_MODEL_TYPE_3_VERSION_1, "TEST", "VARIANT", "user"); policyModelsService.saveOrUpdatePolicyModel(policyModel3); SortedSet sortedSet = new TreeSet<>(); policyModelsService.getAllPolicyModels().forEach(sortedSet::add); List listToCheck = - sortedSet - .stream().filter(policy -> policy.equals(policyModel3) - || policy.equals(policyModel2) || policy.equals(policyModel1)) - .collect(Collectors.toList()); + sortedSet + .stream().filter(policy -> policy.equals(policyModel3) + || policy.equals(policyModel2) || policy.equals(policyModel1)) + .collect(Collectors.toList()); assertThat(listToCheck.get(0)).isEqualByComparingTo(policyModel2); assertThat(listToCheck.get(1)).isEqualByComparingTo(policyModel1); assertThat(listToCheck.get(2)).isEqualByComparingTo(policyModel3); @@ -294,21 +318,22 @@ public class PolicyModelServiceItCase { policyModelsService.updatePdpGroupInfo(pdpGroups); JsonObject res1 = - policyModelsService.getPolicyModel("org.onap.testos", "1.0.0").getPolicyPdpGroup(); + policyModelsService.getPolicyModel("org.onap.testos", "1.0.0").getPolicyPdpGroup(); String expectedRes1 = - "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\"]}]}"; + "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\"]}]}"; JsonObject expectedJson1 = JsonUtils.GSON.fromJson(expectedRes1, JsonObject.class); assertThat(res1).isEqualTo(expectedJson1); JsonObject res2 = - policyModelsService.getPolicyModel("org.onap.testos2", "2.0.0").getPolicyPdpGroup(); + policyModelsService.getPolicyModel("org.onap.testos2", "2.0.0").getPolicyPdpGroup(); String expectedRes2 = - "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\"]}]}"; + "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]}," + + "{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\"]}]}"; JsonObject expectedJson2 = JsonUtils.GSON.fromJson(expectedRes2, JsonObject.class); assertThat(res2).isEqualTo(expectedJson2); JsonObject res3 = - policyModelsService.getPolicyModel("org.onap.testos3", "1.0.0").getPolicyPdpGroup(); + policyModelsService.getPolicyModel("org.onap.testos3", "1.0.0").getPolicyPdpGroup(); assertThat(res3).isNull(); } } diff --git a/src/test/resources/http-cache/example/api/v1/blueprint-model/workflow-spec/.header b/src/test/resources/http-cache/example/api/v1/blueprint-model/workflow-spec/.header index 6a280d972..5464a754d 100644 --- a/src/test/resources/http-cache/example/api/v1/blueprint-model/workflow-spec/.header +++ b/src/test/resources/http-cache/example/api/v1/blueprint-model/workflow-spec/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/api/v1/blueprint-model/workflows/blueprint-name/baseconfiguration/version/1.0.0/.header b/src/test/resources/http-cache/example/api/v1/blueprint-model/workflows/blueprint-name/baseconfiguration/version/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/api/v1/blueprint-model/workflows/blueprint-name/baseconfiguration/version/1.0.0/.header +++ b/src/test/resources/http-cache/example/api/v1/blueprint-model/workflows/blueprint-name/baseconfiguration/version/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policies/.header b/src/test/resources/http-cache/example/policy/api/v1/policies/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policies/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policies/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/.file b/src/test/resources/http-cache/example/policy/api/v1/policytypes/.file index 7f5b897bf..50fcf9135 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/.file +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/.file @@ -28,6 +28,13 @@ policy_types: properties: # Omitted for brevity, see Section 1 + onap.policies.Naming: + version: 1.0.0 + description: Supports blacklist of VNF's from performing control loop actions on. + derived_from: tosca.policies.Root + properties: + # Omitted for brevity, see Section 1 + onap.policies.controlloop.guard.common.MinMax: version: 1.0.0 description: Supports Min/Max number of VF Modules diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.file b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.file new file mode 100644 index 000000000..a44435111 --- /dev/null +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.file @@ -0,0 +1,101 @@ +tosca_definitions_version: tosca_simple_yaml_1_1_0 +policy_types: + onap.policies.Naming: + derived_from: tosca.policies.Root + version: 1.0.0 + name: onap.policies.Naming + description: Virtual policy node for naming + properties: + policy-instance-name: + type: string + naming-models: + type: list + entry_schema: + type: policy.data.naming-model-entity +data_types: + policy.data.naming-model-entity: + derived_from: tosca.datatypes.Root + properties: + nfRole: + type: string + required: false + metadata: + matchable: true + naming-type: + type: string + required: true + metadata: + matchable: true + naming-recipe: + type: string + required: true + name-operation: + type: string + required: false + naming-properties: + type: list + required: true + entry_schema: + type: policy.data.naming-property + policy.data.naming-property: + derived_from: tosca.datatypes.Root + properties: + property-name: + type: string + required: true + metadata: + matchable: true + property-value: + type: string + required: false + property-operation: + type: string + required: false + source-system: + type: string + required: false + source-endpoint: + type: string + required: false + increment-sequence: + type: policy.data.increment-sequence + required: false + policy.data.increment-sequence: + derived_from: tosca.nodes.Root + properties: + scope: + type: list + required: true + entry_schema: + type: string + constraints: + - valid_values: + - CLOUD_REGION_ID + - LOCATION_CLLI + - VNF + - VM + - VFMODULE + - PRECEEDING + - TRAILING + - ENTIRETY + sequence-type: + type: string + require: true + entry_schema: + type: string + constraints: + - valid_values: + - numeric + - alpha-numeric + start-value: + type: string + required: true + max: + type: string + required: false + increment: + type: string + required: true + length: + type: string + required: true \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.header new file mode 100644 index 000000000..b11784a21 --- /dev/null +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.header @@ -0,0 +1 @@ +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.Blacklist/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.Blacklist/versions/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.Blacklist/versions/1.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.Blacklist/versions/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/1.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/2.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/2.0.0/.header index 6a280d972..5464a754d 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/2.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.guard.common.MinMax/versions/2.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Apex/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Apex/versions/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Apex/versions/1.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Apex/versions/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Drools/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Drools/versions/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Drools/versions/1.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Drools/versions/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/.header b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/.header +++ b/src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/pap/v1/pdps/.header b/src/test/resources/http-cache/example/policy/pap/v1/pdps/.header index 6a280d972..b11784a21 100644 --- a/src/test/resources/http-cache/example/policy/pap/v1/pdps/.header +++ b/src/test/resources/http-cache/example/policy/pap/v1/pdps/.header @@ -1 +1 @@ -{"Transfer-Encoding": "chunked", "Set-Cookie": "JSESSIONID=158qxkdtdobkd1umr3ikkgrmlx;Path=/", "Expires": "Thu, 01 Jan 1970 00:00:00 GMT", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file +{"Transfer-Encoding": "chunked", "Server": "Jetty(9.3.21.v20170918)", "Content-Type": "application/json", "X-ECOMP-RequestID": "e2ddb3c8-994f-47df-b4dc-097d4fb55c08"} \ No newline at end of file diff --git a/src/test/resources/tosca/tca_hi_lo.json b/src/test/resources/tosca/tca_hi_lo.json new file mode 100644 index 000000000..cb3ed893f --- /dev/null +++ b/src/test/resources/tosca/tca_hi_lo.json @@ -0,0 +1,179 @@ +{ + "title": "onap.policies.monitoring.cdap.tca.hi.lo.app", + "type": "object", + "required": [ + "tca_policy" + ], + "properties": { + "tca_policy": { + "title": "onap.datatypes.monitoring.tca_policy", + "type": "object", + "required": [ + "domain", + "metricsPerEventName" + ], + "properties": { + "domain": { + "type": "string", + "description": "Domain name to which TCA needs to be applied", + "default": "measurementsForVfScaling", + "const": "measurementsForVfScaling" + }, + "metricsPerEventName": { + "type": "array", + "description": "Contains eventName and threshold details that need to be applied to given eventName", + "items": { + "title": "onap.datatypes.monitoring.metricsPerEventName", + "type": "object", + "required": [ + "controlLoopSchemaType", + "eventName", + "policyName", + "policyScope", + "policyVersion", + "thresholds" + ], + "properties": { + "controlLoopSchemaType": { + "type": "string", + "description": "Specifies Control Loop Schema Type for the event Name e.g. VNF, VM", + "enum": [ + "VM", + "VNF" + ] + }, + "eventName": { + "type": "string", + "description": "Event name to which thresholds need to be applied" + }, + "policyName": { + "type": "string", + "description": "TCA Policy Scope Name" + }, + "policyScope": { + "type": "string", + "description": "TCA Policy Scope" + }, + "policyVersion": { + "type": "string", + "description": "TCA Policy Scope Version" + }, + "thresholds": { + "type": "array", + "description": "Thresholds associated with eventName", + "items": { + "title": "onap.datatypes.monitoring.thresholds", + "type": "object", + "required": [ + "closedLoopControlName", + "closedLoopEventStatus", + "direction", + "fieldPath", + "severity", + "thresholdValue", + "version" + ], + "properties": { + "closedLoopControlName": { + "type": "string", + "description": "Closed Loop Control Name associated with the threshold" + }, + "closedLoopEventStatus": { + "type": "string", + "description": "Closed Loop Event Status of the threshold", + "enum": [ + "ONSET", + "ABATED" + ] + }, + "direction": { + "type": "string", + "description": "Direction of the threshold", + "enum": [ + "LESS", + "LESS_OR_EQUAL", + "GREATER", + "GREATER_OR_EQUAL", + "EQUAL" + ] + }, + "fieldPath": { + "type": "string", + "description": "Json field Path as per CEF message which needs to be analyzed for TCA", + "enum": [ + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsAccumulated", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuIdle", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageInterrupt", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageNice", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSoftIrq", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSteal", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSystem", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuWait", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].percentUsage", + "$.event.measurementsForVfScalingFields.meanRequestLatency", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryBuffered", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryCached", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryConfigured", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryFree", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryUsed", + "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value" + ] + }, + "severity": { + "type": "string", + "description": "Threshold Event Severity", + "enum": [ + "CRITICAL", + "MAJOR", + "MINOR", + "WARNING", + "NORMAL" + ] + }, + "thresholdValue": { + "type": "integer", + "description": "Threshold value for the field Path inside CEF message" + }, + "version": { + "type": "string", + "description": "Version number associated with the threshold" + } + } + }, + "format": "tabs-top" + } + } + }, + "format": "tabs-top" + } + } + } + } +} \ No newline at end of file diff --git a/ui-react/src/api/PolicyToscaService.js b/ui-react/src/api/PolicyToscaService.js index a7bc140b6..351126328 100644 --- a/ui-react/src/api/PolicyToscaService.js +++ b/ui-react/src/api/PolicyToscaService.js @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,12 +69,12 @@ export default class PolicyToscaService { return response.json(); } else { console.error("getToscaPolicyModel query failed"); - return ""; + return {}; } }) .catch(function (error) { console.error("getToscaPolicyModel error received", error); - return ""; + return {}; }); } diff --git a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js index 216a8abd2..a93aa3534 100644 --- a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js +++ b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js @@ -33,11 +33,17 @@ import FirstPage from '@material-ui/icons/FirstPage'; import LastPage from '@material-ui/icons/LastPage'; import Search from '@material-ui/icons/Search'; import MaterialTable from "material-table"; -import LoopCache from '../../../api/LoopCache'; import PolicyService from '../../../api/PolicyService'; +import PolicyToscaService from '../../../api/PolicyToscaService'; import Select from 'react-select'; +import JSONEditor from '@json-editor/json-editor'; const ModalStyled = styled(Modal)` + @media (min-width: 1200px) { + .modal-xl { + max-width: 96%; + } + } background-color: transparent; ` @@ -45,9 +51,6 @@ const standardCellStyle = { border: '1px solid black' }; const cellPdpGroupStyle = { backgroundColor: '#039be5', color: '#FFF', border: '1px solid black'}; const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; -const selectPdpGroupStyle = { - width: 2000 -} export default class ViewAllPolicies extends React.Component { state = { @@ -114,7 +117,7 @@ export default class ViewAllPolicies extends React.Component { this.handleClose = this.handleClose.bind(this); this.renderPdpGroupDropBox = this.renderPdpGroupDropBox.bind(this); this.handlePdpGroupChange = this.handlePdpGroupChange.bind(this); - + this.createJsonEditor = this.createJsonEditor.bind(this); this.getAllPolicies(); } @@ -124,12 +127,51 @@ export default class ViewAllPolicies extends React.Component { let selectedPdpGroup = pdpSplit[0]; let selectedSubPdpGroup = pdpSplit[1]; if (typeof selectedSubPdpGroup !== "undefined") { - this.state.policiesListData[this.state.selectedRow]["pdpGroupInfo"] = {"pdpGroup":selectedPdpGroup,"pdpSubGroup":selectedSubPdpGroup}; + let temp = this.state.policiesListData; + temp[this.state.selectedRow]["pdpGroupInfo"] = {"pdpGroup":selectedPdpGroup,"pdpSubGroup":selectedSubPdpGroup}; + this.setState({policiesListData: temp}); } else { delete this.state.policiesListData[this.state.selectedRow]["pdpGroupInfo"]; } } + createJsonEditor(toscaModel, editorData) { + JSONEditor.defaults.themes.myBootstrap4 = JSONEditor.defaults.themes.bootstrap4.extend({ + getTab: function(text,tabId) { + var liel = document.createElement('li'); + liel.classList.add('nav-item'); + var ael = document.createElement("a"); + ael.classList.add("nav-link"); + ael.setAttribute("style",'padding:10px;max-width:160px;'); + ael.setAttribute("href", "#" + tabId); + ael.setAttribute('data-toggle', 'tab'); + text.setAttribute("style",'word-wrap:break-word;'); + ael.appendChild(text); + liel.appendChild(ael); + return liel; + } + }); + return new JSONEditor(document.getElementById("policy-editor"), + { schema: toscaModel, + startval: editorData, + theme: 'myBootstrap4', + object_layout: 'grid', + disable_properties: false, + disable_edit_json: false, + disable_array_reorder: true, + disable_array_delete_last_row: true, + disable_array_delete_all_rows: false, + array_controls_top: true, + keep_oneof_values: false, + collapsed:true, + show_errors: 'always', + display_required_only: false, + show_opt_in: false, + prompt_before_delete: true, + required_by_default: false + }) + } + renderPdpGroupDropBox(dataRow) { let optionItems = [{label: "NOT DEPLOYED", value: "NOT DEPLOYED"}]; let selectedItem = {label: "NOT DEPLOYED", value: "NOT DEPLOYED"}; @@ -159,6 +201,17 @@ export default class ViewAllPolicies extends React.Component { this.props.history.push('/') } + handleOnRowClick(rowData) { + PolicyToscaService.getToscaPolicyModel(rowData["type"], rowData["type_version"]).then(respJsonPolicyTosca => { + this.setState({ + selectedRow: rowData.tableData.id, + selectedRowJsonSchema: respJsonPolicyTosca, + selectedRowPolicyProperties: rowData["properties"], + jsonEditorForPolicy: this.createJsonEditor(respJsonPolicyTosca, rowData["properties"]) + }); + }); + } + render() { return ( @@ -170,7 +223,7 @@ export default class ViewAllPolicies extends React.Component { data={this.state.policiesListData} columns={this.state.policyColumnsDefinition} icons={this.state.tableIcons} - onRowClick={(event, rowData) => {this.setState({selectedRow: rowData.tableData.id})}} + onRowClick={(event, rowData) => {this.handleOnRowClick(rowData)}} options={{ headerStyle:rowHeaderStyle, rowStyle: rowData => ({ @@ -178,6 +231,7 @@ export default class ViewAllPolicies extends React.Component { }) }} /> +
-- cgit 1.2.3-korg