summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSébastien Determe <sebastien.determe@intl.att.com>2020-03-02 12:31:54 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-02 12:31:54 +0000
commit47caef3827de362e7b6204b01d73238fb6faa714 (patch)
tree33c17bd972a64b39d15fe000040aef754c6da61f /src
parent2d28cbf6954c50de004a0d8f1a2ada7ec400fea3 (diff)
parent393bbb59b975747723c6801da2a5b151c542a0b5 (diff)
Merge "Upload Tosca Model changes to remove policy model type parsing from UI. Dictionary API fix to allow bulk create or update of dictionary elements."
Diffstat (limited to 'src')
-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
8 files changed, 321 insertions, 92 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 7e21cc39..aeea55db 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 44b5b6f6..cf514c4b 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 5b24def9..98e3516f 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 fe3f6bda..3ed272e7 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -910,13 +910,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')" />
@@ -926,7 +925,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 f426c762..db6fd5c0 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 3a36a5d8..cabc778b 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 80545c11..d918a8e6 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 00000000..5967d156
--- /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