aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java53
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java80
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java29
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java66
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java15
5 files changed, 7 insertions, 236 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
index 760613026..5ee7d02f6 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
@@ -22,9 +22,7 @@
package org.onap.policy.clamp.models.acm.persistence.provider;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import javax.persistence.EntityNotFoundException;
import javax.ws.rs.core.Response;
@@ -35,15 +33,12 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository;
-import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplatesRepository;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -57,7 +52,6 @@ public class AutomationCompositionProvider {
private final AutomationCompositionRepository automationCompositionRepository;
private final ToscaNodeTemplateRepository toscaNodeTemplateRepository;
- private final ToscaNodeTemplatesRepository toscaNodeTemplatesRepository;
/**
* Get automation composition.
@@ -136,10 +130,9 @@ public class AutomationCompositionProvider {
* Get all automation compositions.
*
* @return all automation compositions found
- * @throws PfModelException on errors getting automation compositions
*/
@Transactional(readOnly = true)
- public List<AutomationComposition> getAutomationCompositions() throws PfModelException {
+ public List<AutomationComposition> getAutomationCompositions() {
return ProviderUtils.asEntityList(automationCompositionRepository.findAll());
}
@@ -150,11 +143,9 @@ public class AutomationCompositionProvider {
* @param name the name of the automation composition to get, null to get all automation compositions
* @param version the version of the automation composition to get, null to get all automation compositions
* @return the automation compositions found
- * @throws PfModelException on errors getting automation compositions
*/
@Transactional(readOnly = true)
- public List<AutomationComposition> getAutomationCompositions(final String name, final String version)
- throws PfModelException {
+ public List<AutomationComposition> getAutomationCompositions(final String name, final String version) {
return ProviderUtils
.asEntityList(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version));
@@ -182,24 +173,6 @@ public class AutomationCompositionProvider {
}
/**
- * Saves Instance Properties to the database.
- *
- * @param serviceTemplate the service template
- * @return a Map of tosca node templates
- */
- public Map<String, ToscaNodeTemplate> saveInstanceProperties(ToscaServiceTemplate serviceTemplate) {
- Map<String, ToscaNodeTemplate> savedNodeTemplates = new HashMap<>();
-
- var jpaToscaNodeTemplates = new JpaToscaNodeTemplates();
- jpaToscaNodeTemplates.fromAuthorative(List.of(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()));
-
- toscaNodeTemplatesRepository.save(jpaToscaNodeTemplates);
- serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach(savedNodeTemplates::put);
-
- return savedNodeTemplates;
- }
-
- /**
* Delete a automation composition.
*
* @param name the name of the automation composition to delete
@@ -225,31 +198,9 @@ public class AutomationCompositionProvider {
}
/**
- * Deletes Instance Properties on the database.
- *
- * @param filteredToscaNodeTemplateMap filtered node templates map to delete
- * @param filteredToscaNodeTemplateList filtered node template list to delete
- */
- public void deleteInstanceProperties(Map<String, ToscaNodeTemplate> filteredToscaNodeTemplateMap,
- List<ToscaNodeTemplate> filteredToscaNodeTemplateList) {
-
- var jpaToscaNodeTemplates = new JpaToscaNodeTemplates();
- jpaToscaNodeTemplates.fromAuthorative(List.of(filteredToscaNodeTemplateMap));
-
- toscaNodeTemplatesRepository.save(jpaToscaNodeTemplates);
-
- filteredToscaNodeTemplateList.forEach(template -> {
- var jpaToscaNodeTemplate = new JpaToscaNodeTemplate(template);
-
- toscaNodeTemplateRepository.delete(jpaToscaNodeTemplate);
- });
- }
-
- /**
* Get All Node Templates.
*
* @return the list of node templates found
- * @throws PfModelException on errors getting node templates
*/
@Transactional(readOnly = true)
public List<ToscaNodeTemplate> getAllNodeTemplates() {
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java
index 942fe8d46..4661c74c7 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java
@@ -29,7 +29,6 @@ import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.persistence.repository.ToscaServiceTemplateRepository;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -214,56 +213,6 @@ public class ServiceTemplateProvider {
}
/**
- * Get the node types derived from those that have been saved by instantiation.
- *
- * @param initialNodeTypes map of all the node types in the specified template
- * @param filteredNodeTypes map of all the node types that have common or instance properties
- * @param instanceName automation composition name
- * @return all node types that have common properties including their children
- */
- private Map<String, ToscaNodeType> getFinalSavedInstanceNodeTypesMap(
- Map<String, ToscaNodeType> initialNodeTypes,
- Map<String, ToscaNodeType> filteredNodeTypes, String instanceName) {
-
- for (var i = 0; i < initialNodeTypes.size(); i++) {
- initialNodeTypes.forEach((key, nodeType) -> {
- var tempToscaNodeType = new ToscaNodeType();
- tempToscaNodeType.setName(key);
-
- if (filteredNodeTypes.get(nodeType.getDerivedFrom()) != null) {
- tempToscaNodeType.setName(key);
-
- var finalProps = new HashMap<String, ToscaProperty>(
- filteredNodeTypes.get(nodeType.getDerivedFrom()).getProperties());
-
- tempToscaNodeType.setProperties(finalProps);
- } else {
- return;
- }
- filteredNodeTypes.putIfAbsent(key, tempToscaNodeType);
-
- });
- }
- return filteredNodeTypes;
- }
-
- /**
- * Get the requested node types by automation composition.
- *
- * @param instanceName automation composition name
- * @param serviceTemplate the ToscaServiceTemplate
- * @return the node types with common or instance properties
- */
- public Map<String, ToscaNodeType> getSavedInstanceInstancePropertiesFromNodeTypes(
- String instanceName, ToscaServiceTemplate serviceTemplate) {
- var tempNodeTypesMap =
- this.getInitialNodeTypesMap(serviceTemplate.getNodeTypes(), false);
-
- return this.getFinalSavedInstanceNodeTypesMap(serviceTemplate.getNodeTypes(), tempNodeTypesMap, instanceName);
-
- }
-
- /**
* Get the requested node types with common or instance properties.
*
* @param common boolean indicating common or instance properties
@@ -278,33 +227,4 @@ public class ServiceTemplateProvider {
return this.getFinalNodeTypesMap(serviceTemplate.getNodeTypes(), tempNodeTypesMap);
}
-
- /**
- * Get node templates with appropriate common or instance properties added.
- *
- * @param initialNodeTemplates map of all the node templates in the specified template
- * @param nodeTypeProps map of all the node types that have common or instance properties including children
- * @return all node templates with appropriate common or instance properties added
- * @throws PfModelException on errors getting map of node templates with common or instance properties added
- */
- public Map<String, ToscaNodeTemplate> getDerivedCommonOrInstanceNodeTemplates(
- Map<String, ToscaNodeTemplate> initialNodeTemplates, Map<String, ToscaNodeType> nodeTypeProps) {
-
- var finalNodeTemplatesMap = new HashMap<String, ToscaNodeTemplate>();
-
- initialNodeTemplates.forEach((templateKey, template) -> {
- if (nodeTypeProps.containsKey(template.getType())) {
- var finalMergedProps = new HashMap<String, Object>();
-
- nodeTypeProps.get(template.getType()).getProperties().forEach(finalMergedProps::putIfAbsent);
-
- template.setProperties(finalMergedProps);
-
- finalNodeTemplatesMap.put(templateKey, template);
- } else {
- return;
- }
- });
- return finalNodeTemplatesMap;
- }
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java
deleted file mode 100644
index f0ab40bf7..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.models.acm.persistence.repository;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-public interface ToscaNodeTemplatesRepository extends JpaRepository<JpaToscaNodeTemplates, PfConceptKey> {
-
-}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
index 3228347e9..e381693ee 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
@@ -27,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
@@ -40,15 +39,12 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository;
-import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplatesRepository;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
@@ -65,9 +61,6 @@ class AutomationCompositionProviderTest {
private static final Coder CODER = new StandardCoder();
private static final String AUTOMATION_COMPOSITION_JSON =
"src/test/resources/providers/TestAutomationCompositions.json";
- private static final String TOSCA_TEMPLATE_YAML = "examples/acm/test-pm-subscription-handling.yaml";
-
- private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private AutomationCompositions inputAutomationCompositions;
private List<JpaAutomationComposition> inputAutomationCompositionsJpa;
@@ -85,7 +78,7 @@ class AutomationCompositionProviderTest {
void testAutomationCompositionsSave() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class));
+ mock(ToscaNodeTemplateRepository.class));
assertThatThrownBy(() -> automationCompositionProvider.saveAutomationCompositions(null))
.hasMessageMatching(LIST_IS_NULL);
@@ -110,7 +103,7 @@ class AutomationCompositionProviderTest {
void testAutomationCompositionSave() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class));
+ mock(ToscaNodeTemplateRepository.class));
assertThatThrownBy(() -> automationCompositionProvider.saveAutomationComposition(null))
.hasMessageMatching(OBJECT_IS_NULL);
@@ -134,7 +127,7 @@ class AutomationCompositionProviderTest {
void testGetAutomationCompositions() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class));
+ mock(ToscaNodeTemplateRepository.class));
// Return empty list when no data present in db
List<AutomationComposition> getResponse = automationCompositionProvider.getAutomationCompositions();
@@ -193,7 +186,7 @@ class AutomationCompositionProviderTest {
void testDeleteAutomationComposition() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class));
+ mock(ToscaNodeTemplateRepository.class));
assertThatThrownBy(() -> automationCompositionProvider
.deleteAutomationComposition(ID_NAME_NOT_EXTST, ID_VERSION))
@@ -211,49 +204,10 @@ class AutomationCompositionProviderTest {
}
@Test
- void testDeleteAllInstanceProperties() throws Exception {
- var automationCompositionProvider =
- new AutomationCompositionProvider(mock(AutomationCompositionRepository.class),
- mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class));
- var toscaServiceTemplate = testAutomationCompositionRead();
- automationCompositionProvider.deleteInstanceProperties(
- automationCompositionProvider.saveInstanceProperties(toscaServiceTemplate),
- automationCompositionProvider.getAllNodeTemplates());
- assertThat(automationCompositionProvider.getAutomationCompositions()).isEmpty();
- }
-
- @Test
- void testSaveAndDeleteInstanceProperties() {
- var toscaNodeTemplatesRepository = mock(ToscaNodeTemplatesRepository.class);
- var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(
- mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository, toscaNodeTemplatesRepository);
- var toscaServiceTest = testAutomationCompositionRead();
-
- automationCompositionProvider.saveInstanceProperties(toscaServiceTest);
- verify(toscaNodeTemplatesRepository).save(any());
-
- var name = "org.onap.policy.acm.PolicyAutomationCompositionParticipant";
- var version = "2.3.1";
- var elem = toscaServiceTest.getToscaTopologyTemplate().getNodeTemplates().get(name);
- when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version))
- .thenReturn(List.of(new JpaToscaNodeTemplate(elem)));
-
- var filtered = automationCompositionProvider.getNodeTemplates(name, version);
- verify(toscaNodeTemplateRepository).getFiltered(JpaToscaNodeTemplate.class, name, version);
-
- automationCompositionProvider
- .deleteInstanceProperties(automationCompositionProvider.saveInstanceProperties(toscaServiceTest), filtered);
-
- verify(toscaNodeTemplateRepository).delete(any());
- }
-
- @Test
void testGetNodeTemplates() {
var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class);
var automationCompositionProvider =
- new AutomationCompositionProvider(mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository,
- mock(ToscaNodeTemplatesRepository.class));
+ new AutomationCompositionProvider(mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository);
var toscaNodeTemplate0 = new JpaToscaNodeTemplate(new PfConceptKey(ID_NAME, ID_VERSION));
var toscaNodeTemplate1 = new JpaToscaNodeTemplate(new PfConceptKey("PMSHInstance2", ID_VERSION));
@@ -287,14 +241,4 @@ class AutomationCompositionProviderTest {
assertThatThrownBy(() -> automationCompositionProvider.getFilteredNodeTemplates(null))
.hasMessageMatching("filter is marked non-null but is null");
}
-
- private static ToscaServiceTemplate testAutomationCompositionRead() {
- return testAutomationCompositionYamlSerialization();
- }
-
- private static ToscaServiceTemplate testAutomationCompositionYamlSerialization() {
- var automationCompositionString = ResourceUtils.getResourceAsString(
- AutomationCompositionProviderTest.TOSCA_TEMPLATE_YAML);
- return yamlTranslator.fromYaml(automationCompositionString, ToscaServiceTemplate.class);
- }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java
index aa95a79d4..9e4133da5 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java
@@ -65,21 +65,6 @@ class ServiceTemplateProviderTest {
}
@Test
- void testGetDerivedCommonOrInstanceNodeTemplates() throws PfModelException {
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
-
- var commonOrInstanceNodeTypeProps =
- serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate);
-
- var result = serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates(
- inputServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(), commonOrInstanceNodeTypeProps);
-
- assertNotNull(result);
- assertThat(result).hasSize(4);
- }
-
- @Test
void testCreateServiceTemplate() throws PfModelException {
var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);