aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java43
-rw-r--r--src/main/java/org/onap/clamp/tosca/Dictionary.java13
-rw-r--r--src/main/java/org/onap/clamp/tosca/DictionaryService.java26
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml7
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java6
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopTemplatesServiceItCase.java13
-rw-r--r--src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java143
-rw-r--r--src/test/resources/tosca/tosca_with_metadata.yaml162
-rwxr-xr-xui-react-lib/libIndex.js2
-rw-r--r--ui-react/src/api/PolicyToscaService.js4
-rw-r--r--ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.js20
-rw-r--r--ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.test.js16
-rw-r--r--ui-react/src/components/dialogs/Tosca/__snapshots__/UploadToscaPolicyModal.test.js.snap111
13 files changed, 328 insertions, 238 deletions
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
index 7e21cc390..aeea55dbb 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
@@ -44,7 +44,7 @@ public class PolicyModelsService {
@Autowired
public PolicyModelsService(PolicyModelsRepository policyModelrepo,
- ToscaYamlToJsonConvertor convertor) {
+ ToscaYamlToJsonConvertor convertor) {
policyModelsRepository = policyModelrepo;
toscaYamlToJsonConvertor = convertor;
}
@@ -72,40 +72,37 @@ public class PolicyModelsService {
/**
* Creates or updates the Tosca Policy Model.
*
- * @param policyModelType The policyModeltype in Tosca yaml
* @param policyModelTosca The Policymodel object
* @return The Policy Model created
*/
- public PolicyModel createNewPolicyModelFromTosca(String policyModelType,
- String policyModelTosca) {
+ public PolicyModel createNewPolicyModelFromTosca(String policyModelTosca) {
JsonObject jsonObject = toscaYamlToJsonConvertor.validateAndConvertToJson(policyModelTosca);
String policyModelTypeFromTosca = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_POLICY_MODEL_TYPE);
- String policyModelTypeToUse = policyModelTypeFromTosca != null ? policyModelTypeFromTosca : policyModelType;
- Iterable<PolicyModel> models = getAllPolicyModelsByType(policyModelTypeToUse);
+ ToscaSchemaConstants.METADATA_POLICY_MODEL_TYPE);
+ Iterable<PolicyModel> models = getAllPolicyModelsByType(policyModelTypeFromTosca);
Collections.sort((List<PolicyModel>) models);
- PolicyModel newPolicyModel = new PolicyModel(policyModelTypeToUse, policyModelTosca,
- SemanticVersioning.incrementMajorVersion(
- ((ArrayList) models).isEmpty() ? null : ((ArrayList<PolicyModel>) models).get(0).getVersion()),
- toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_ACRONYM));
+ PolicyModel newPolicyModel = new PolicyModel(policyModelTypeFromTosca, policyModelTosca,
+ SemanticVersioning.incrementMajorVersion(((ArrayList) models).isEmpty() ? null
+ : ((ArrayList<PolicyModel>) models).get(0).getVersion()),
+ toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
+ ToscaSchemaConstants.METADATA_ACRONYM));
return saveOrUpdatePolicyModel(newPolicyModel);
}
/**
* Update an existing Tosca Policy Model.
*
- * @param policyModelType The policy Model type in Tosca yaml
+ * @param policyModelType The policy Model type in Tosca yaml
* @param policyModelVersion The policy Version to update
- * @param policyModelTosca The Policy Model tosca
+ * @param policyModelTosca The Policy Model tosca
* @return The Policy Model updated
*/
public PolicyModel updatePolicyModelTosca(String policyModelType, String policyModelVersion,
- String policyModelTosca) {
+ String policyModelTosca) {
JsonObject jsonObject = toscaYamlToJsonConvertor.validateAndConvertToJson(policyModelTosca);
PolicyModel thePolicyModel = getPolicyModelByType(policyModelType, policyModelVersion);
thePolicyModel.setPolicyAcronym(toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_ACRONYM));
+ ToscaSchemaConstants.METADATA_ACRONYM));
thePolicyModel.setPolicyModelTosca(policyModelTosca);
return saveOrUpdatePolicyModel(thePolicyModel);
}
@@ -133,13 +130,13 @@ public class PolicyModelsService {
/**
* Retrieves the Tosca model Yaml string.
*
- * @param type The Policy Model Type
+ * @param type The Policy Model Type
* @param version The policy model version
* @return The Tosca model Yaml string
*/
public String getPolicyModelTosca(String type, String version) {
- return policyModelsRepository.findById(new PolicyModelId(type, version)).orElse(new PolicyModel())
- .getPolicyModelTosca();
+ return policyModelsRepository.findById(new PolicyModelId(type, version))
+ .orElse(new PolicyModel()).getPolicyModelTosca();
}
/**
@@ -149,8 +146,8 @@ public class PolicyModelsService {
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createPolicyInDbIfNeeded(PolicyModel policyModel) {
- if (!policyModelsRepository
- .existsById(new PolicyModelId(policyModel.getPolicyModelType(), policyModel.getVersion()))) {
+ if (!policyModelsRepository.existsById(
+ new PolicyModelId(policyModel.getPolicyModelType(), policyModel.getVersion()))) {
policyModelsRepository.save(policyModel);
}
}
@@ -165,8 +162,8 @@ public class PolicyModelsService {
for (PolicyModel policyModel : policyModelList) {
JsonArray supportedPdpGroups = new JsonArray();
for (PdpGroup pdpGroup : pdpGroupList) {
- JsonObject supportedPdpGroup = pdpGroup.getSupportedSubgroups(policyModel.getPolicyModelType(),
- policyModel.getVersion());
+ JsonObject supportedPdpGroup = pdpGroup.getSupportedSubgroups(
+ policyModel.getPolicyModelType(), policyModel.getVersion());
if (supportedPdpGroup != null) {
supportedPdpGroups.add(supportedPdpGroup);
}
diff --git a/src/main/java/org/onap/clamp/tosca/Dictionary.java b/src/main/java/org/onap/clamp/tosca/Dictionary.java
index 44b5b6f68..cf514c4bd 100644
--- a/src/main/java/org/onap/clamp/tosca/Dictionary.java
+++ b/src/main/java/org/onap/clamp/tosca/Dictionary.java
@@ -65,9 +65,7 @@ public class Dictionary extends AuditEntity implements Serializable {
private String subDictionaryType;
@Expose
- @ManyToMany(
- fetch = FetchType.EAGER,
- cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
+ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
@JoinTable(
name = "dictionary_to_dictionaryelements",
joinColumns = @JoinColumn(name = "dictionary_name", referencedColumnName = "name"),
@@ -150,6 +148,15 @@ public class Dictionary extends AuditEntity implements Serializable {
}
/**
+ * Method to set dictionaryElements.
+ *
+ * @param dictionaryElements The dictionary elements set
+ */
+ public void setDictionaryElements(Set<DictionaryElement> dictionaryElements) {
+ this.dictionaryElements = dictionaryElements;
+ }
+
+ /**
* Method to delete a dictionaryElement from the list.
*
* @param dictionaryElement The dictionary element
diff --git a/src/main/java/org/onap/clamp/tosca/DictionaryService.java b/src/main/java/org/onap/clamp/tosca/DictionaryService.java
index 5b24def98..98e3516fa 100644
--- a/src/main/java/org/onap/clamp/tosca/DictionaryService.java
+++ b/src/main/java/org/onap/clamp/tosca/DictionaryService.java
@@ -26,6 +26,7 @@ package org.onap.clamp.tosca;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.persistence.EntityNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -63,20 +64,19 @@ public class DictionaryService {
Set<DictionaryElement> newDictionaryElements = dictionary.getDictionaryElements();
- for (DictionaryElement dictionaryElement : newDictionaryElements) {
- if (dict.getDictionaryElements().contains(dictionaryElement)) {
- // Update the Dictionary Element
- getAndUpdateDictionaryElement(dict, dictionaryElement);
- } else {
- // Create the Dictionary Element
- dict.addDictionaryElements(getAndUpdateDictionaryElement(dict, dictionaryElement));
- dictionaryRepository.save(dict);
- }
+ if (newDictionaryElements != null && !newDictionaryElements.isEmpty()) {
+ Set<DictionaryElement> updatedDictionaryElements = newDictionaryElements.stream()
+ .map(dictionaryElement -> getAndUpdateDictionaryElement(dict, dictionaryElement))
+ .collect(Collectors.toSet());
+
+ dict.getDictionaryElements().forEach(dictElement -> {
+ if (!updatedDictionaryElements.contains(dictElement)) {
+ updatedDictionaryElements.add(dictElement);
+ }
+ });
+ dict.setDictionaryElements(updatedDictionaryElements);
}
-
- // Fetch again to get Dictionary with most recent updates.
- return dictionaryRepository.findById(dictionaryName).orElseThrow(
- () -> new EntityNotFoundException("Couldn't find Dictionary named: " + dictionaryName));
+ return dictionaryRepository.save(dict);
}
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 280b808c3..ce76d300c 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -923,13 +923,12 @@
</route>
</get>
- <post uri="/v2/policyToscaModels/{policyModelType}"
+ <post uri="/v2/policyToscaModels"
type="java.lang.String"
outType="org.onap.clamp.loop.template.PolicyModel"
consumes="plain/text" produces="application/json">
<route>
- <removeHeaders pattern="*"
- excludePattern="policyModelType" />
+ <removeHeaders pattern="*"/>
<doTry>
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Upload New or Update Tosca Policy Model')" />
@@ -939,7 +938,7 @@
<simple>${body}</simple>
</setProperty>
<to
- uri="bean:org.onap.clamp.loop.template.PolicyModelsService?method=createNewPolicyModelFromTosca(${header.policyModelType},${exchangeProperty[PolicyModelTosca]})" />
+ uri="bean:org.onap.clamp.loop.template.PolicyModelsService?method=createNewPolicyModelFromTosca(${exchangeProperty[PolicyModelTosca]})" />
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
<doCatch>
diff --git a/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java b/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java
index f426c7625..db6fd5c03 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java
@@ -24,6 +24,9 @@
package org.onap.clamp.clds.tosca;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import com.google.gson.JsonObject;
import java.io.IOException;
import javax.transaction.Transactional;
@@ -39,9 +42,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class ToscaYamlToJsonConvertorTestItCase {
diff --git a/src/test/java/org/onap/clamp/loop/LoopTemplatesServiceItCase.java b/src/test/java/org/onap/clamp/loop/LoopTemplatesServiceItCase.java
index 3a36a5d82..cabc778b8 100644
--- a/src/test/java/org/onap/clamp/loop/LoopTemplatesServiceItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopTemplatesServiceItCase.java
@@ -130,6 +130,19 @@ public class LoopTemplatesServiceItCase {
.isEqualTo("microService1");
assertThat(loopTemplateLoopElementModel.getLoopTemplate().getName())
.isEqualTo("TemplateName");
+ assertNull(actualLoopTemplate.getBlueprint());
+ assertNull(actualLoopTemplate.getModelService());
+ }
+
+ @Test
+ @Transactional
+ public void shouldReturnLoopemplateSvg() {
+ LoopTemplate loopTemplate = getLoopTemplate("TemplateName", null, "svg", "xyz", -1);
+ loopTemplatesService.saveOrUpdateLoopTemplate(loopTemplate);
+ String svgRepresentation = loopTemplatesService.getSvgRepresentation("TemplateName");
+
+ assertNotNull(svgRepresentation);
+ assertThat(svgRepresentation).isEqualTo(loopTemplate.getSvgRepresentation());
}
@Test
diff --git a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
index 80545c112..d918a8e6d 100644
--- a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
+++ b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
@@ -26,6 +26,7 @@ package org.onap.clamp.loop;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.gson.JsonObject;
+import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
@@ -36,6 +37,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.Application;
import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.template.PolicyModel;
import org.onap.clamp.loop.template.PolicyModelId;
import org.onap.clamp.loop.template.PolicyModelsRepository;
@@ -66,8 +68,8 @@ public class PolicyModelServiceItCase {
private static final String POLICY_MODEL_TYPE_3_VERSION_1 = "1.0.0";
private static final String POLICY_MODEL_TYPE_2_VERSION_2 = "2.0.0";
- private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
- String policyVariant, String createdBy) {
+ private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version,
+ String policyAcronym, String policyVariant, String createdBy) {
PolicyModel policyModel = new PolicyModel();
policyModel.setCreatedBy(createdBy);
policyModel.setPolicyAcronym(policyAcronym);
@@ -85,8 +87,8 @@ public class PolicyModelServiceItCase {
@Transactional
public void shouldCreatePolicyModel() {
// given
- PolicyModel policyModel = getPolicyModel(POLICY_MODEL_TYPE_1, "yaml", POLICY_MODEL_TYPE_1_VERSION_1, "TEST",
- "VARIANT", "user");
+ PolicyModel policyModel = getPolicyModel(POLICY_MODEL_TYPE_1, "yaml",
+ POLICY_MODEL_TYPE_1_VERSION_1, "TEST", "VARIANT", "user");
// when
PolicyModel actualPolicyModel = policyModelsService.saveOrUpdatePolicyModel(policyModel);
@@ -94,19 +96,63 @@ public class PolicyModelServiceItCase {
// then
assertThat(actualPolicyModel).isNotNull();
assertThat(actualPolicyModel).isEqualTo(policyModelsRepository
- .findById(new PolicyModelId(actualPolicyModel.getPolicyModelType(), actualPolicyModel.getVersion()))
- .get());
- assertThat(actualPolicyModel.getPolicyModelType()).isEqualTo(policyModel.getPolicyModelType());
+ .findById(new PolicyModelId(actualPolicyModel.getPolicyModelType(),
+ actualPolicyModel.getVersion()))
+ .get());
+ assertThat(actualPolicyModel.getPolicyModelType())
+ .isEqualTo(policyModel.getPolicyModelType());
assertThat(actualPolicyModel.getCreatedBy()).isEqualTo("Not found");
assertThat(actualPolicyModel.getCreatedDate()).isNotNull();
assertThat(actualPolicyModel.getPolicyAcronym()).isEqualTo(policyModel.getPolicyAcronym());
- assertThat(actualPolicyModel.getPolicyModelTosca()).isEqualTo(policyModel.getPolicyModelTosca());
+ assertThat(actualPolicyModel.getPolicyModelTosca())
+ .isEqualTo(policyModel.getPolicyModelTosca());
assertThat(actualPolicyModel.getUpdatedBy()).isEqualTo("Not found");
assertThat(actualPolicyModel.getUpdatedDate()).isNotNull();
assertThat(actualPolicyModel.getVersion()).isEqualTo(policyModel.getVersion());
- assertThat(policyModelsService.getPolicyModel(POLICY_MODEL_TYPE_1, POLICY_MODEL_TYPE_1_VERSION_1))
- .isEqualToIgnoringGivenFields(policyModel, "createdDate", "updatedDate", "createdBy", "updatedBy");
+ assertThat(
+ policyModelsService.getPolicyModel(POLICY_MODEL_TYPE_1, POLICY_MODEL_TYPE_1_VERSION_1))
+ .isEqualToIgnoringGivenFields(policyModel, "createdDate", "updatedDate",
+ "createdBy", "updatedBy");
+ }
+
+ /**
+ * This tests a create Policy Model from Tosca.
+ *
+ * @throws IOException
+ */
+ @Test
+ @Transactional
+ public void shouldCreatePolicyModelFromTosca() throws IOException {
+ String toscaModelYaml =
+ ResourceFileUtil.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);
+ }
+
+ /**
+ * This tests a update Policy Model.
+ *
+ * @throws IOException
+ */
+ @Test
+ @Transactional
+ public void shouldUpdatePolicyModel() throws IOException {
+ String toscaModelYaml =
+ ResourceFileUtil.getResourceAsString("tosca/tosca_with_metadata.yaml");
+ PolicyModel policyModel = policyModelsService.createNewPolicyModelFromTosca(toscaModelYaml);
+ String newToscaModelYaml =
+ ResourceFileUtil.getResourceAsString("tosca/tosca_metadata_clamp_possible_values.yaml");
+
+ PolicyModel updatedPolicyModel = policyModelsService.updatePolicyModelTosca(
+ policyModel.getPolicyModelType(), policyModel.getVersion(), newToscaModelYaml);
+
+ assertThat(updatedPolicyModel.getPolicyModelTosca()).isEqualTo(newToscaModelYaml);
+
}
/**
@@ -116,15 +162,16 @@ public class PolicyModelServiceItCase {
@Transactional
public void shouldReturnAllPolicyModelTypes() {
// given
- PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", POLICY_MODEL_TYPE_2_VERSION_1, "TEST",
- "VARIANT", "user");
+ PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ 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");
+ PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user");
policyModelsService.saveOrUpdatePolicyModel(policyModel2);
List<String> policyModelTypesList = policyModelsService.getAllPolicyModelTypes();
- assertThat(policyModelTypesList).contains(policyModel1.getPolicyModelType(), policyModel2.getPolicyModelType());
+ assertThat(policyModelTypesList).contains(policyModel1.getPolicyModelType(),
+ policyModel2.getPolicyModelType());
}
/**
@@ -133,11 +180,11 @@ public class PolicyModelServiceItCase {
@Test
@Transactional
public void shouldReturnAllPolicyModels() {
- PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", POLICY_MODEL_TYPE_2_VERSION_1, "TEST",
- "VARIANT", "user");
+ PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ 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");
+ PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user");
policyModelsService.saveOrUpdatePolicyModel(policyModel2);
assertThat(policyModelsService.getAllPolicyModels()).contains(policyModel1, policyModel2);
@@ -149,15 +196,15 @@ public class PolicyModelServiceItCase {
@Test
@Transactional
public void shouldReturnAllModelsByType() {
- PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", POLICY_MODEL_TYPE_2_VERSION_1, "TEST",
- "VARIANT", "user");
+ PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ 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");
+ PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user");
policyModelsService.saveOrUpdatePolicyModel(policyModel2);
- assertThat(policyModelsService.getAllPolicyModelsByType(POLICY_MODEL_TYPE_2)).contains(policyModel1,
- policyModel2);
+ assertThat(policyModelsService.getAllPolicyModelsByType(POLICY_MODEL_TYPE_2))
+ .contains(policyModel1, policyModel2);
}
/**
@@ -166,21 +213,23 @@ public class PolicyModelServiceItCase {
@Test
@Transactional
public void shouldReturnSortedSet() {
- PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml", POLICY_MODEL_TYPE_2_VERSION_1, "TEST",
- "VARIANT", "user");
+ PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ 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");
+ PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ 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");
+ PolicyModel policyModel3 = getPolicyModel(POLICY_MODEL_TYPE_3, "yaml",
+ POLICY_MODEL_TYPE_3_VERSION_1, "TEST", "VARIANT", "user");
policyModelsService.saveOrUpdatePolicyModel(policyModel3);
SortedSet<PolicyModel> sortedSet = new TreeSet<>();
policyModelsService.getAllPolicyModels().forEach(sortedSet::add);
- List<PolicyModel> listToCheck = sortedSet.stream()
- .filter(policy -> policy.equals(policyModel3) || policy.equals(policyModel2)
- || policy.equals(policyModel1)).collect(Collectors.toList());
+ List<PolicyModel> listToCheck =
+ 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);
@@ -192,17 +241,16 @@ public class PolicyModelServiceItCase {
@Test
@Transactional
public void shouldAddPdpGroupInfo() {
- PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_1, "yaml", POLICY_MODEL_TYPE_1_VERSION_1, "TEST",
- "VARIANT", "user");
+ PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_1, "yaml",
+ POLICY_MODEL_TYPE_1_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");
+ PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ 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");
+ PolicyModel policyModel3 = getPolicyModel(POLICY_MODEL_TYPE_3, "yaml",
+ POLICY_MODEL_TYPE_3_VERSION_1, "TEST", "VARIANT", "user");
policyModelsService.saveOrUpdatePolicyModel(policyModel3);
-
PolicyModelKey type1 = new PolicyModelKey("org.onap.testos", "1.0.0");
PolicyModelKey type2 = new PolicyModelKey("org.onap.testos2", "2.0.0");
@@ -242,19 +290,22 @@ public class PolicyModelServiceItCase {
pdpGroupList.add(pdpGroup2);
policyModelsService.updatePdpGroupInfo(pdpGroupList);
- JsonObject res1 = policyModelsService.getPolicyModel("org.onap.testos", "1.0.0").getPolicyPdpGroup();
+ JsonObject res1 =
+ 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();
+ JsonObject res2 =
+ 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();
+ JsonObject res3 =
+ policyModelsService.getPolicyModel("org.onap.testos3", "1.0.0").getPolicyPdpGroup();
assertThat(res3).isNull();
}
}
diff --git a/src/test/resources/tosca/tosca_with_metadata.yaml b/src/test/resources/tosca/tosca_with_metadata.yaml
new file mode 100644
index 000000000..5967d1569
--- /dev/null
+++ b/src/test/resources/tosca/tosca_with_metadata.yaml
@@ -0,0 +1,162 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+ onap.policies.Monitoring:
+ derived_from: tosca.policies.Root
+ description: a base policy type for all policies that governs monitoring provisioning
+ onap.policies.monitoring.cdap.tca.hi.lo.app:
+ derived_from: onap.policies.Monitoring
+ version: 1.0.0
+ properties:
+ tca_policy:
+ type: map
+ description: TCA Policy JSON
+ entry_schema:
+ type: onap.datatypes.monitoring.tca_policy
+ metadata:
+ policy_model_type: onap.policies.monitoring.cdap.tca.hi.lo.app
+ acronym: tca
+
+data_types:
+ onap.datatypes.monitoring.metricsPerEventName:
+ derived_from: tosca.datatypes.Root
+ properties:
+ controlLoopSchemaType:
+ type: string
+ required: true
+ description: Specifies Control Loop Schema Type for the event Name e.g. VNF, VM
+ constraints:
+ - valid_values:
+ - VM
+ - VNF
+ eventName:
+ type: string
+ required: true
+ description: Event name to which thresholds need to be applied
+ policyName:
+ type: string
+ required: true
+ description: TCA Policy Scope Name
+ policyScope:
+ type: string
+ required: true
+ description: TCA Policy Scope
+ policyVersion:
+ type: string
+ required: true
+ description: TCA Policy Scope Version
+ thresholds:
+ type: list
+ required: true
+ description: Thresholds associated with eventName
+ entry_schema:
+ type: onap.datatypes.monitoring.thresholds
+ onap.datatypes.monitoring.tca_policy:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain:
+ type: string
+ required: true
+ description: Domain name to which TCA needs to be applied
+ default: measurementsForVfScaling
+ constraints:
+ - equal: measurementsForVfScaling
+ metricsPerEventName:
+ type: list
+ required: true
+ description: Contains eventName and threshold details that need to be applied to given eventName
+ entry_schema:
+ type: onap.datatypes.monitoring.metricsPerEventName
+ onap.datatypes.monitoring.thresholds:
+ derived_from: tosca.datatypes.Root
+ properties:
+ closedLoopControlName:
+ type: string
+ required: true
+ description: Closed Loop Control Name associated with the threshold
+ closedLoopEventStatus:
+ type: string
+ required: true
+ description: Closed Loop Event Status of the threshold
+ constraints:
+ - valid_values:
+ - ONSET
+ - ABATED
+ direction:
+ type: string
+ required: true
+ description: Direction of the threshold
+ constraints:
+ - valid_values:
+ - LESS
+ - LESS_OR_EQUAL
+ - GREATER
+ - GREATER_OR_EQUAL
+ - EQUAL
+ fieldPath:
+ type: string
+ required: true
+ description: Json field Path as per CEF message which needs to be analyzed for TCA
+ constraints:
+ - valid_values:
+ - $.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
+ required: true
+ description: Threshold Event Severity
+ constraints:
+ - valid_values:
+ - CRITICAL
+ - MAJOR
+ - MINOR
+ - WARNING
+ - NORMAL
+ thresholdValue:
+ type: integer
+ required: true
+ description: Threshold value for the field Path inside CEF message
+ version:
+ type: string
+ required: true
+ description: Version number associated with the threshold
diff --git a/ui-react-lib/libIndex.js b/ui-react-lib/libIndex.js
index 89bf831d9..20dc074e3 100755
--- a/ui-react-lib/libIndex.js
+++ b/ui-react-lib/libIndex.js
@@ -22,6 +22,7 @@
*/
export { default as ConfigurationPolicyModal } from './src/components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
+export { default as PolicyModal } from './src/components/dialogs/Policy/PolicyModal';
export { default as DeployLoopModal } from './src/components/dialogs/Loop/DeployLoopModal';
export { default as LoopActionService } from './src/api/LoopActionService';
export { default as LoopCache } from './src/api/LoopCache';
@@ -35,6 +36,7 @@ export { default as LoopUI } from './src/LoopUI';
export { default as MenuBar } from './src/components/menu/MenuBar';
export { default as NotFound } from './src/NotFound';
export { default as OpenLoopModal } from './src/components/dialogs/Loop/OpenLoopModal';
+export { default as CreateLoopModal } from './src/components/dialogs/Loop/CreateLoopModal';
export { default as OperationalPolicyModal } from './src/components/dialogs/OperationalPolicy/OperationalPolicyModal';
export { default as PerformActions } from './src/components/dialogs/PerformActions';
export { default as RefreshStatus } from './src/components/dialogs/RefreshStatus';
diff --git a/ui-react/src/api/PolicyToscaService.js b/ui-react/src/api/PolicyToscaService.js
index 52e68fac4..610a11418 100644
--- a/ui-react/src/api/PolicyToscaService.js
+++ b/ui-react/src/api/PolicyToscaService.js
@@ -78,8 +78,8 @@ export default class PolicyToscaService {
});
}
- static createPolicyModelFromToscaModel(policyModelType, jsonData) {
- return fetch('/restservices/clds/v2/policyToscaModels/' + policyModelType, {
+ static createPolicyModelFromToscaModel(jsonData) {
+ return fetch('/restservices/clds/v2/policyToscaModels', {
method: 'POST',
credentials: 'same-origin',
headers: {
diff --git a/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.js b/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.js
index 2e0460f61..1937485b0 100644
--- a/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.js
+++ b/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.js
@@ -39,12 +39,10 @@ export default class UploadToscaPolicyModal extends React.Component {
this.handleCreateFromToscaPolicyModel = this.handleCreateFromToscaPolicyModel.bind(this);
this.handleClose = this.handleClose.bind(this);
- this.handlePolicyModelType = this.handlePolicyModelType.bind(this);
this.fileSelectedHandler = this.fileSelectedHandler.bind(this);
this.state = {
show: true,
selectedFile: '',
- policyModelType: '',
policyModelTosca: [],
apiResponseStatus: '',
apiResponseMessage: '',
@@ -56,7 +54,7 @@ export default class UploadToscaPolicyModal extends React.Component {
if (event.target.files && event.target.files[0]) {
const scope = this;
let reader = new FileReader();
- this.setState({policyModelType: '', policyModelTosca: '' });
+ this.setState({policyModelTosca: '' });
reader.onload = function(e) {
scope.setState({ policyModelTosca: reader.result});
};
@@ -73,9 +71,8 @@ export default class UploadToscaPolicyModal extends React.Component {
handleCreateFromToscaPolicyModel(e) {
e.preventDefault();
- console.log("Policy Model Type is", this.state.policyModelType);
- if(this.state.policyModelType && this.state.policyModelTosca) {
- PolicyToscaService.createPolicyModelFromToscaModel(this.state.policyModelType, this.state.policyModelTosca).then(resp => {
+ if(this.state.policyModelTosca) {
+ PolicyToscaService.createPolicyModelFromToscaModel(this.state.policyModelTosca).then(resp => {
if(resp.status === 200) {
this.setState({apiResponseStatus: resp.status, apiResponseMessage: resp.message, upldBtnClicked: true});
} else {
@@ -87,12 +84,6 @@ export default class UploadToscaPolicyModal extends React.Component {
}
}
- handlePolicyModelType = event => {
- this.setState({
- policyModelType: event.target.value
- })
- }
-
render() {
return (
<ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
@@ -108,11 +99,6 @@ export default class UploadToscaPolicyModal extends React.Component {
<Alert variant="secondary">
<p>{this.state.selectedFile.name}</p>
</Alert>
- <Form.Label column sm="2">Policy Model Type:</Form.Label>
- <input type="text" style={{width: '50%'}}
- value={this.state.policyModelType}
- onChange={this.handlePolicyModelType}
- />
</Col>
</Form.Group>
</Modal.Body>
diff --git a/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.test.js b/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.test.js
index dac8ac920..e4842062a 100644
--- a/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.test.js
+++ b/ui-react/src/components/dialogs/Tosca/UploadToscaPolicyModal.test.js
@@ -27,22 +27,6 @@ import UploadToscaPolicyModal from './UploadToscaPolicyModal';
describe('Test Upload Tosca Policy Model', () => {
- it('Test handleMicroServiceName', () => {
-
- const component = shallow(<UploadToscaPolicyModal />);
-
- const inputValue = 'TCA'
-
- const button = component.find('input').at(1);
-
- button.simulate('change', { target: { value: inputValue }});
-
- expect(component.state('policyModelType')).toEqual(inputValue);
-
- expect(component).toMatchSnapshot();
-
- });
-
it('Test handleUploadToscaPolicyModel for Tosca Model', () => {
const component = shallow(<UploadToscaPolicyModal />);
diff --git a/ui-react/src/components/dialogs/Tosca/__snapshots__/UploadToscaPolicyModal.test.js.snap b/ui-react/src/components/dialogs/Tosca/__snapshots__/UploadToscaPolicyModal.test.js.snap
deleted file mode 100644
index 8e801367b..000000000
--- a/ui-react/src/components/dialogs/Tosca/__snapshots__/UploadToscaPolicyModal.test.js.snap
+++ /dev/null
@@ -1,111 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Test Upload Tosca Policy Model Test handleMicroServiceName 1`] = `
-<Styled(Bootstrap(Modal))
- onHide={[Function]}
- show={true}
- size="lg"
->
- <ModalHeader
- closeButton={true}
- closeLabel="Close"
- >
- <ModalTitle>
- Upload Tosca Model
- </ModalTitle>
- </ModalHeader>
- <ModalBody>
- <FormGroup
- as={
- Object {
- "$$typeof": Symbol(react.forward_ref),
- "defaultProps": Object {
- "noGutters": false,
- },
- "render": [Function],
- }
- }
- controlId="formPlaintextEmail"
- >
- <Col
- sm="10"
- >
- <input
- accept=".yaml"
- name="file"
- onChange={[Function]}
- style={
- Object {
- "display": "none",
- }
- }
- type="file"
- />
- <button
- onClick={[Function]}
- >
- Pick Tosca File
- </button>
- <Alert
- closeLabel="Close alert"
- show={true}
- transition={
- Object {
- "$$typeof": Symbol(react.forward_ref),
- "defaultProps": Object {
- "appear": false,
- "in": false,
- "mountOnEnter": false,
- "timeout": 300,
- "unmountOnExit": false,
- },
- "displayName": "Fade",
- "render": [Function],
- }
- }
- variant="secondary"
- >
- <p />
- </Alert>
- <FormLabel
- column={true}
- sm="2"
- srOnly={false}
- >
- Policy Model Type:
- </FormLabel>
- <input
- onChange={[Function]}
- style={
- Object {
- "width": "50%",
- }
- }
- type="text"
- value="TCA"
- />
- </Col>
- </FormGroup>
- </ModalBody>
- <ModalFooter>
- <Button
- active={false}
- disabled={false}
- onClick={[Function]}
- type="null"
- variant="secondary"
- >
- Cancel
- </Button>
- <Button
- active={false}
- disabled={true}
- onClick={[Function]}
- type="submit"
- variant="primary"
- >
- Create
- </Button>
- </ModalFooter>
-</Styled(Bootstrap(Modal))>
-`;