summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>2022-11-15 12:37:49 +0000
committerGerrit Code Review <gerrit@onap.org>2022-11-15 12:37:49 +0000
commitaf8ef619877bfe7ab17b8e3f1d9cacc6a3f9ca67 (patch)
tree5e588798d2aa117c8a88f9adf169a3f216437f19
parent5353ee0e99762e3b37c4cc491faa3c16936ebf92 (diff)
parentc32d7926409b4c164e2a5097e7ba1bc4d766bd5b (diff)
Merge "Remove redundant endpoints in ACM"
-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
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java39
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java425
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java138
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java317
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java41
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java57
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java182
12 files changed, 7 insertions, 1435 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);
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
index 0a78c54de..55d7b0c13 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
@@ -44,7 +44,6 @@ 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.ToscaServiceTemplates;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -206,44 +205,6 @@ public class CommissioningProvider {
}
/**
- * Get node templates with common properties added.
- *
- * @param name the name of the definition to use, null for all definitions
- * @param version the version of the definition to use, null for all definitions
- * @param instanceName automation composition name
- * @param common boolean indicating common or instance properties to be used
- * @return the nodes templates with common or instance properties
- * @throws PfModelException on errors getting common or instance properties from node_templates
- */
- @Transactional(readOnly = true)
- public Map<String, ToscaNodeTemplate> getNodeTemplatesWithCommonOrInstanceProperties(
- final String name, final String version, final String instanceName, final boolean common)
- throws PfModelException {
-
- if (common && verifyIfInstancePropertiesExists()) {
- throw new PfModelException(Status.BAD_REQUEST,
- "Cannot create or edit common properties, delete all the instantiations first");
- }
-
- var serviceTemplateList = serviceTemplateProvider.getServiceTemplateList(name, version);
-
- if (serviceTemplateList.isEmpty()) {
- throw new PfModelException(Status.BAD_REQUEST,
- "Tosca service template has to be commissioned before saving instance properties");
- }
-
- var commonOrInstanceNodeTypeProps =
- serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(common, serviceTemplateList.get(0));
-
- var serviceTemplates = new ToscaServiceTemplates();
- serviceTemplates.setServiceTemplates(filterToscaNodeTemplateInstance(serviceTemplateList, instanceName));
-
- return serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates(
- serviceTemplates.getServiceTemplates().get(0).getToscaTopologyTemplate().getNodeTemplates(),
- commonOrInstanceNodeTypeProps);
- }
-
- /**
* Get the requested automation composition definitions.
*
* @param name the name of the definition to get, null for all definitions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
index 98b59aed7..18fd1f938 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
@@ -21,20 +21,12 @@
package org.onap.policy.clamp.acm.runtime.instantiation;
-import com.google.gson.Gson;
-import com.google.gson.internal.LinkedTreeMap;
-import com.google.gson.reflect.TypeToken;
-import java.lang.reflect.Type;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
@@ -43,15 +35,9 @@ import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.messages.rest.GenericNameVersion;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionOrderStateResponse;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimed;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimedResponse;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstancePropertiesResponse;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
@@ -62,9 +48,7 @@ import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNameVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -75,15 +59,7 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
@AllArgsConstructor
public class AutomationCompositionInstantiationProvider {
- private static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
private static final String AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE = "AutomationCompositionElement";
- private static final String PARTICIPANT_ID_PROPERTY_KEY = "participant_id";
- private static final String PARTICIPANT_TYPE_PROPERTY_KEY = "participantType";
- private static final String AC_ELEMENT_NAME = "name";
- private static final String AC_ELEMENT_VERSION = "version";
- private static final String HYPHEN = "-";
-
- private static final Gson GSON = new Gson();
private final AutomationCompositionProvider automationCompositionProvider;
private final CommissioningProvider commissioningProvider;
@@ -92,145 +68,6 @@ public class AutomationCompositionInstantiationProvider {
private static final String ENTRY = "entry ";
/**
- * Creates Instance Properties and automation composition.
- *
- * @param serviceTemplate the service template
- * @return the result of the instantiation operation
- * @throws PfModelException on creation errors
- */
- public InstancePropertiesResponse createInstanceProperties(ToscaServiceTemplate serviceTemplate)
- throws PfModelException {
-
- String instanceName = serviceTemplate.getName();
- AutomationComposition automationComposition = new AutomationComposition();
- Map<UUID, AutomationCompositionElement> automationCompositionElements = new HashMap<>();
-
- ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getAllToscaServiceTemplate().get(0);
-
- Map<String, ToscaNodeTemplate> persistedNodeTemplateMap =
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
-
- Map<String, ToscaNodeTemplate> nodeTemplates = deepCloneNodeTemplate(serviceTemplate);
-
- nodeTemplates.forEach((key, template) -> {
- ToscaNodeTemplate newNodeTemplate = new ToscaNodeTemplate();
- String name = key + "-" + instanceName;
- String version = template.getVersion();
- String description = template.getDescription() + " " + instanceName;
- newNodeTemplate.setName(name);
- newNodeTemplate.setVersion(version);
- newNodeTemplate.setDescription(description);
- newNodeTemplate.setProperties(new HashMap<>(template.getProperties()));
- newNodeTemplate.setType(template.getType());
- newNodeTemplate.setTypeVersion(template.getTypeVersion());
- newNodeTemplate.setMetadata(template.getMetadata());
-
- crateNewAutomationCompositionInstance(instanceName, automationComposition, automationCompositionElements,
- template, newNodeTemplate);
-
- persistedNodeTemplateMap.put(name, newNodeTemplate);
- });
-
- AutomationCompositions automationCompositions = new AutomationCompositions();
-
- serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(persistedNodeTemplateMap);
-
- automationComposition.setElements(automationCompositionElements);
- automationCompositions.getAutomationCompositionList().add(automationComposition);
-
- return saveInstancePropertiesAndAutomationComposition(serviceTemplate, automationCompositions);
- }
-
- /**
- * Updates Instance Properties and Automation Composition Instance.
- *
- * @param name the name of the automation composition to update
- * @param version the version of the automation composition to update
- * @param serviceTemplate tosca service template body
- * @return InstancePropertiesResponse response from updating instance properties
- * @throws PfModelException exception if incorrect instance name
- */
- public InstancePropertiesResponse updatesInstanceProperties(
- String name, String version, ToscaServiceTemplate serviceTemplate) throws PfModelException {
-
- if (name.length() < 3) {
- throw new PfModelException(Status.BAD_REQUEST, "Instance Name cannot be empty or less than 3 characters!");
- }
-
- Map<String, ToscaNodeTemplate> nodeTemplates = deepCloneNodeTemplate(serviceTemplate);
- Map<String, ToscaNodeTemplate> updatedNodeTemplates = new HashMap<>();
-
- String instanceName = serviceTemplate.getName();
-
- nodeTemplates.forEach((key, template) -> {
- ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate();
-
- String updatedName = updateInstanceNameDescription(instanceName, name, key);
- String updatedDescription = updateInstanceNameDescription(
- instanceName, name, template.getDescription());
-
- toscaNodeTemplate.setName(updatedName);
- toscaNodeTemplate.setDescription(updatedDescription);
- toscaNodeTemplate.setCapabilities(template.getCapabilities());
- toscaNodeTemplate.setRequirements(template.getRequirements());
- toscaNodeTemplate.setMetadata(template.getMetadata());
- toscaNodeTemplate.setProperties(template.getProperties());
- toscaNodeTemplate.setDerivedFrom(template.getDerivedFrom());
- toscaNodeTemplate.setVersion(template.getVersion());
- toscaNodeTemplate.setType(template.getType());
- toscaNodeTemplate.setTypeVersion(template.getTypeVersion());
-
- String updatedKey = updateInstanceNameDescription(instanceName, name, key);
-
- updatedNodeTemplates.put(updatedKey, toscaNodeTemplate);
- });
-
- serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().clear();
- serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(updatedNodeTemplates);
-
- AutomationCompositions automationCompositions = updateAutomationComposition(
- name, instanceName);
-
- deleteInstanceProperties(name, version);
-
- return saveInstancePropertiesAndAutomationComposition(serviceTemplate, automationCompositions);
- }
-
- /**
- * Deletes Instance Properties.
- *
- * @param name the name of the automation composition to delete
- * @param version the version of the automation composition to delete
- * @return the result of the deletion
- * @throws PfModelException on deletion errors
- */
- public InstantiationResponse deleteInstanceProperties(String name, String version) throws PfModelException {
-
- String instanceName = getInstancePropertyName(name, version);
-
- Map<String, ToscaNodeTemplate> filteredToscaNodeTemplateMap = new HashMap<>();
-
- ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getAllToscaServiceTemplate().get(0);
-
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, nodeTemplate) -> {
- if (!nodeTemplate.getName().contains(instanceName)) {
- filteredToscaNodeTemplateMap.put(key, nodeTemplate);
- }
- });
-
- List<ToscaNodeTemplate> filteredToscaNodeTemplateList =
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().values().stream()
- .filter(nodeTemplate -> nodeTemplate.getName().contains(instanceName)).collect(Collectors.toList());
-
- InstantiationResponse response = this.deleteAutomationComposition(name, version);
-
- automationCompositionProvider.deleteInstanceProperties(filteredToscaNodeTemplateMap,
- filteredToscaNodeTemplateList);
-
- return response;
- }
-
- /**
* Create automation compositions.
*
* @param automationCompositions the automation composition
@@ -469,266 +306,4 @@ public class AutomationCompositionInstantiationProvider {
return result;
}
-
- /**
- * Gets a list of automation compositions with it's ordered state.
- *
- * @param name the name of the automation composition to get, null for all automation compositions
- * @param version the version of the automation composition to get, null for all automation compositions
- * @return a list of Instantiation Command
- * @throws PfModelException on errors getting automation compositions
- */
- @Transactional(readOnly = true)
- public AutomationCompositionOrderStateResponse getInstantiationOrderState(String name, String version)
- throws PfModelException {
-
- List<AutomationComposition> automationCompositions =
- automationCompositionProvider.getAutomationCompositions(name, version);
-
- var response = new AutomationCompositionOrderStateResponse();
-
- automationCompositions.forEach(automationComposition -> {
- var genericNameVersion = new GenericNameVersion();
- genericNameVersion.setName(automationComposition.getName());
- genericNameVersion.setVersion(automationComposition.getVersion());
- response.getAutomationCompositionIdentifierList().add(genericNameVersion);
- });
-
- return response;
- }
-
- /**
- * Saves Instance Properties and automation composition.
- * Gets a list of automation compositions which are primed or de-primed.
- *
- * @param name the name of the automation composition to get, null for all automation compositions
- * @param version the version of the automation composition to get, null for all automation compositions
- * @return a list of Instantiation Command
- * @throws PfModelException on errors getting automation compositions
- */
- @Transactional(readOnly = true)
- public AutomationCompositionPrimedResponse getAutomationCompositionPriming(String name, String version)
- throws PfModelException {
-
- List<AutomationComposition> automationCompositions =
- automationCompositionProvider.getAutomationCompositions(name, version);
-
- var response = new AutomationCompositionPrimedResponse();
-
- automationCompositions.forEach(automationComposition -> {
- var primed = new AutomationCompositionPrimed();
- primed.setName(automationComposition.getName());
- primed.setVersion(automationComposition.getVersion());
- primed.setPrimed(automationComposition.getPrimed());
- response.getPrimedAutomationCompositionsList().add(primed);
- });
-
- return response;
- }
-
- /**
- * Creates instance element name.
- *
- * @param serviceTemplate the service template
- * @param automationCompositions a list of automation compositions
- * @return the result of the instance properties and instantiation operation
- * @throws PfModelException on creation errors
- */
- private InstancePropertiesResponse saveInstancePropertiesAndAutomationComposition(
- ToscaServiceTemplate serviceTemplate, AutomationCompositions automationCompositions) throws PfModelException {
-
- for (var automationComposition : automationCompositions.getAutomationCompositionList()) {
- var checkAutomationCompositionOpt =
- automationCompositionProvider.findAutomationComposition(automationComposition.getKey().asIdentifier());
- if (checkAutomationCompositionOpt.isPresent()) {
- throw new PfModelException(Response.Status.BAD_REQUEST, "Automation composition with id "
- + automationComposition.getKey().asIdentifier() + " already defined");
- }
- }
- Map<String, ToscaNodeTemplate> toscaSavedNodeTemplate =
- automationCompositionProvider.saveInstanceProperties(serviceTemplate);
- automationCompositionProvider.saveAutomationCompositions(automationCompositions.getAutomationCompositionList());
- List<ToscaConceptIdentifier> affectedAutomationCompositions = automationCompositions
- .getAutomationCompositionList().stream().map(ac -> ac.getKey().asIdentifier()).collect(Collectors.toList());
-
- List<ToscaConceptIdentifier> toscaAffectedProperties = toscaSavedNodeTemplate.values().stream()
- .map(template -> template.getKey().asIdentifier()).collect(Collectors.toList());
-
- var response = new InstancePropertiesResponse();
- response.setAffectedInstanceProperties(Stream.of(affectedAutomationCompositions, toscaAffectedProperties)
- .flatMap(Collection::stream).collect(Collectors.toList()));
-
- return response;
- }
-
- /**
- * Crates a new automation composition instance.
- *
- * @param instanceName automation composition Instance name
- * @param automationComposition empty automation composition
- * @param automationCompositionElements new automation composition Element map
- * @param template original Cloned Tosca Node Template
- * @param newNodeTemplate new Tosca Node Template
- */
- private void crateNewAutomationCompositionInstance(String instanceName, AutomationComposition automationComposition,
- Map<UUID, AutomationCompositionElement> automationCompositionElements, ToscaNodeTemplate template,
- ToscaNodeTemplate newNodeTemplate) {
- if (template.getType().equals(AUTOMATION_COMPOSITION_NODE_TYPE)) {
- automationComposition.setDefinition(getAutomationCompositionDefinition(newNodeTemplate));
- }
-
- if (template.getType().contains(AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE)) {
- AutomationCompositionElement automationCompositionElement =
- getAutomationCompositionElement(newNodeTemplate);
- automationCompositionElements.put(automationCompositionElement.getId(), automationCompositionElement);
- }
-
- automationComposition.setName(instanceName);
- automationComposition.setVersion(template.getVersion());
- automationComposition.setDescription("Automation composition " + instanceName);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- }
-
- /**
- * Get's the instance property name of the automation composition.
- *
- * @param name the name of the automation composition to get, null for all automation compositions
- * @param version the version of the automation composition to get, null for all automation compositions
- * @return the instance name of the automation composition instance properties
- * @throws PfModelException on errors getting automation compositions
- */
- private String getInstancePropertyName(String name, String version) throws PfModelException {
- List<String> toscaDefinitionsNames =
- automationCompositionProvider.getAutomationCompositions(name, version).stream()
- .map(AutomationComposition::getDefinition).map(ToscaNameVersion::getName).collect(Collectors.toList());
-
- return toscaDefinitionsNames.stream().reduce("", (s1, s2) -> {
-
- if (s2.contains(HYPHEN)) {
- String[] instances = s2.split(HYPHEN);
-
- return HYPHEN + instances[1];
- }
-
- return s1;
- });
- }
-
- /**
- * Retrieves automation composition Definition.
- *
- * @param template tosca node template
- * @return automation composition definition
- */
- private ToscaConceptIdentifier getAutomationCompositionDefinition(ToscaNodeTemplate template) {
- ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
- definition.setName(template.getName());
- definition.setVersion(template.getVersion());
- return definition;
- }
-
- /**
- * Retrieves automation composition Element.
- *
- * @param template tosca node template
- * @return a automation composition element
- */
- @SuppressWarnings("unchecked")
- private AutomationCompositionElement getAutomationCompositionElement(ToscaNodeTemplate template) {
- AutomationCompositionElement automationCompositionElement = new AutomationCompositionElement();
- ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
- definition.setName(template.getName());
- definition.setVersion(template.getVersion());
- automationCompositionElement.setDefinition(definition);
- LinkedTreeMap<String, Object> participantId =
- (LinkedTreeMap<String, Object>) template.getProperties().get(PARTICIPANT_ID_PROPERTY_KEY);
- if (participantId != null) {
- ToscaConceptIdentifier participantIdProperty = new ToscaConceptIdentifier();
- participantIdProperty.setName(String.valueOf(participantId.get(AC_ELEMENT_NAME)));
- participantIdProperty.setVersion(String.valueOf(participantId.get(AC_ELEMENT_VERSION)));
- automationCompositionElement.setParticipantId(participantIdProperty);
- }
- LinkedTreeMap<String, Object> participantType =
- (LinkedTreeMap<String, Object>) template.getProperties().get(PARTICIPANT_TYPE_PROPERTY_KEY);
- if (participantType != null) {
- ToscaConceptIdentifier participantTypeProperty = new ToscaConceptIdentifier();
- participantTypeProperty.setName(String.valueOf(participantType.get(AC_ELEMENT_NAME)));
- participantTypeProperty.setVersion(participantType.get(AC_ELEMENT_VERSION).toString());
- automationCompositionElement.setParticipantType(participantTypeProperty);
- }
- return automationCompositionElement;
- }
-
- /**
- * Deep clones ToscaNodeTemplate.
- *
- * @param serviceTemplate ToscaServiceTemplate
- * @return a cloned Hash Map of ToscaNodeTemplate
- */
- private Map<String, ToscaNodeTemplate> deepCloneNodeTemplate(ToscaServiceTemplate serviceTemplate) {
- String jsonString = GSON.toJson(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates());
- Type type = new TypeToken<HashMap<String, ToscaNodeTemplate>>() {}.getType();
- return GSON.fromJson(jsonString, type);
- }
-
- /**
- * Updates Automation composition instance name.
- *
- * @param oldInstanceName previous saved instance name
- * @param newInstanceName new instance name to replace the previous one
- * @return AutomationCompositions updated
- * @throws PfModelException exception to compositions is not defined
- */
- private AutomationCompositions updateAutomationComposition(
- String oldInstanceName, String newInstanceName) throws PfModelException {
-
- List<AutomationComposition> filteredAcmList = automationCompositionProvider.getAutomationCompositions()
- .stream().filter(acm -> acm.getName().contains(oldInstanceName)).collect(Collectors.toList());
-
- if (filteredAcmList.isEmpty()) {
- throw new PfModelException(Status.BAD_REQUEST, "Automation compositions not defined!");
- }
-
- AutomationComposition automationComposition = filteredAcmList.get(0);
-
- automationComposition.getDefinition()
- .setName(updateInstanceNameDescription(newInstanceName, oldInstanceName,
- automationComposition.getDefinition().getName()));
-
- automationComposition.setName(newInstanceName);
-
- automationComposition.setDescription(
- updateInstanceNameDescription(newInstanceName, oldInstanceName,
- automationComposition.getDescription()));
-
- automationComposition.getElements().forEach((uuid, automationCompositionElement) -> {
- automationCompositionElement.getDefinition()
- .setName(updateInstanceNameDescription(newInstanceName, oldInstanceName,
- automationCompositionElement.getDefinition().getName()));
- });
-
- AutomationCompositions automationCompositions = new AutomationCompositions();
- automationCompositions.getAutomationCompositionList().add(automationComposition);
-
- return automationCompositions;
-
- }
-
- /**
- * Updates instance and description.
- *
- * @param newInstanceName new instance name to replace the previous one
- * @param oldInstanceName previous saved instance name
- * @param value to be updated
- * @return String updated instance name or description
- */
- private String updateInstanceNameDescription(
- String newInstanceName, String oldInstanceName, String value) {
- String toBeReplaced = value.substring(value.indexOf(oldInstanceName));
-
- String replace = value.replace(toBeReplaced, newInstanceName);
-
- return replace;
- }
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java
index 4cd384ede..fef1e6de9 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java
@@ -29,9 +29,7 @@ import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
-import javax.ws.rs.core.Response.Status;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController;
@@ -312,140 +310,4 @@ public class CommissioningController extends AbstractRestController {
return ResponseEntity.ok().body(provider.getToscaServiceTemplateReduced(name, version, instanceName));
}
-
- /**
- * Retrieves the Common or Instance Properties for the specified Tosca Service Template.
- *
- * @param requestId request ID used in ONAP logging
- * @param common a flag, true to get common properties, false to get instance properties
- * @param name the name of the tosca service template to retrieve
- * @param version the version of the tosca service template to get
- * @return the specified tosca service template or section Json Schema
- * @throws PfModelException on errors getting the Common or Instance Properties
- */
- // @formatter:off
- @GetMapping(value = "/commission/getCommonOrInstanceProperties",
- produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Query details of the requested tosca service template common or instance properties",
- notes = "Queries details of the requested commissioned tosca service template json common"
- + "or instance properties, returning all tosca service template common or instance property details",
- response = ToscaServiceTemplate.class,
- tags = {"Clamp Automation Composition Commissioning API"},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
- // @formatter:on
- public ResponseEntity<Map<String, ToscaNodeTemplate>> queryToscaServiceCommonOrInstanceProperties(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Tosca service template name", required = false) @RequestParam(
- value = "name",
- required = false) String name,
- @ApiParam(value = "Tosca service template version", required = false) @RequestParam(
- value = "version",
- required = false) String version,
- @ApiParam(value = "Automation composition name", required = false) @RequestParam(
- value = "instanceName",
- required = false) String instanceName,
- @ApiParam(
- value = "Flag, true for common properties, false for instance",
- required = false)
- @RequestParam(value = "common", defaultValue = "false", required = false) boolean common)
- throws PfModelException {
-
- return ResponseEntity.ok().body(provider
- .getNodeTemplatesWithCommonOrInstanceProperties(name, version, instanceName, common));
- }
-
- /**
- * Queries the elements of a specific automation composition.
- *
- * @param requestId request ID used in ONAP logging
- * @param name the name of the automation composition definition to get
- * @param version the version of the automation composition definition to get
- * @return the automation composition element definitions
- * @throws PfModelException on errors getting the elements of a specific automation composition
- */
- // @formatter:off
- @GetMapping(value = "/commission/elements",
- produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Query details of the requested commissioned automation composition element definitions",
- notes = "Queries details of the requested commissioned automation composition element definitions, "
- + "returning all automation composition elements' details",
- response = ToscaNodeTemplate.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
- // @formatter:on
- public ResponseEntity<List<ToscaNodeTemplate>> queryElements(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Automation composition definition name", required = false) @RequestParam(
- value = "name",
- required = false) String name,
- @ApiParam(value = "Automation composition definition version", required = false) @RequestParam(
- value = "version",
- required = false) String version)
- throws PfModelException {
-
- List<ToscaNodeTemplate> nodeTemplate = provider.getAutomationCompositionDefinitions(name, version);
- // Prevent ambiguous queries with multiple returns
- if (nodeTemplate.size() > 1) {
- throw new PfModelException(Status.NOT_ACCEPTABLE, "Multiple automation compositions are not supported");
- }
-
- List<ToscaNodeTemplate> response = provider.getAutomationCompositionElementDefinitions(nodeTemplate.get(0));
- return ResponseEntity.ok().body(response);
- }
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
index b4d978d77..ba00c0ede 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
@@ -35,13 +35,9 @@ import org.onap.policy.clamp.acm.runtime.instantiation.AutomationCompositionInst
import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionOrderStateResponse;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimedResponse;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstancePropertiesResponse;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -131,201 +127,6 @@ public class InstantiationController extends AbstractRestController {
}
/**
- * Saves instance properties.
- *
- * @param requestId request ID used in ONAP logging
- * @param body the body of automation composition following TOSCA definition
- * @return a response
- */
- // @formatter:off
- @PostMapping(value = "/instanceProperties",
- consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
- produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(
- value = "Saves instance properties",
- notes = "Saves instance properties, returning the saved instances properties and it's version",
- response = InstancePropertiesResponse.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_LATEST_NAME,
- description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)
- },
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
- // @formatter:on
- public ResponseEntity<InstancePropertiesResponse> createInstanceProperties(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body)
- throws PfModelException {
-
- return ResponseEntity.ok().body(provider.createInstanceProperties(body));
- }
-
- /**
- * Updates instance properties.
- *
- * @param name the name of the automation composition to update
- * @param version the version of the automation composition to update
- * @param body the body of automation composition following TOSCA definition
- * @return a response
- */
- // @formatter:off
- @PutMapping(value = "/instanceProperties",
- consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
- produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(
- value = "Updates instance properties",
- notes = "Updates instance properties, returning the saved instances properties and it's version",
- response = InstancePropertiesResponse.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_LATEST_NAME,
- description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)
- },
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
- // @formatter:on
- public ResponseEntity<InstancePropertiesResponse> updatesInstanceProperties(
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Automation composition definition name", required = true)
- @RequestParam("name") String name,
- @ApiParam(value = "Automation composition definition version", required = true)
- @RequestParam("version") String version,
- @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body)
- throws PfModelException {
-
- return ResponseEntity.ok().body(provider.updatesInstanceProperties(name, version, body));
- }
-
- /**
- * Deletes a automation composition definition and instance properties.
- *
- * @param requestId request ID used in ONAP logging
- * @param name the name of the automation composition to delete
- * @param version the version of the automation composition to delete
- * @return a response
- * @throws PfModelException on errors deleting of automation composition and instance properties
- */
- // @formatter:off
- @DeleteMapping(value = "/instanceProperties",
- produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Delete a automation composition and instance properties",
- notes = "Deletes a automation composition and instance properties, returning optional error details",
- response = InstantiationResponse.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_LATEST_NAME,
- description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
- // @formatter:on
-
- public ResponseEntity<InstantiationResponse> deleteInstanceProperties(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Automation composition definition name", required = true) @RequestParam("name") String name,
- @ApiParam(value = "Automation composition definition version") @RequestParam(
- value = "version",
- required = true) String version)
- throws PfModelException {
-
- return ResponseEntity.ok().body(provider.deleteInstanceProperties(name, version));
- }
-
- /**
* Queries details of all automation compositions.
*
* @param requestId request ID used in ONAP logging
@@ -570,122 +371,4 @@ public class InstantiationController extends AbstractRestController {
return ResponseEntity.accepted().body(provider.issueAutomationCompositionCommand(command));
}
-
- /**
- * Queries details of all automation compositions.
- *
- * @param requestId request ID used in ONAP logging
- * @param name the name of the automation composition to get, null for all automation compositions
- * @param version the version of the automation composition to get, null for all automation compositions
- * @return the automation compositions
- * @throws PfModelException on errors getting commissioning of automation composition
- */
- // @formatter:off
- @GetMapping(value = "/instantiationState",
- produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Query details of the requested automation compositions",
- notes = "Queries details of requested automation compositions, returning all automation composition details",
- response = AutomationCompositions.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
- // @formatter:on
- public ResponseEntity<AutomationCompositionOrderStateResponse> getInstantiationOrderState(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Automation composition name", required = false) @RequestParam(
- value = "name",
- required = false) String name,
- @ApiParam(value = "Automation composition version", required = false) @RequestParam(
- value = "version",
- required = false) String version)
- throws PfModelException {
-
- return ResponseEntity.ok().body(provider.getInstantiationOrderState(name, version));
- }
-
- /**
- * Queries Primed/De-Primed status of a automation composition.
- *
- * @param requestId request ID used in ONAP logging
- * @param name the name of the automation composition to get, null for all automation compositions
- * @param version the version of the automation composition to get, null for all automation compositions
- * @return the automation compositions
- * @throws PfModelException on errors getting priming of automation composition
- */
- // @formatter:off
- @GetMapping(value = "/automationCompositionPriming",
- produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Query priming details of the requested automation compositions",
- notes = "Queries priming details of requested automation compositions, returning primed/deprimed compositions",
- response = AutomationCompositionPrimedResponse.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
- // @formatter:on
- public ResponseEntity<AutomationCompositionPrimedResponse> getAutomationCompositionPriming(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Automation composition definition name", required = false) @RequestParam(
- value = "name",
- required = false) String name,
- @ApiParam(value = "Automation composition definition version", required = false) @RequestParam(
- value = "version",
- required = false) String version)
- throws PfModelException {
-
- return ResponseEntity.ok().body(provider.getAutomationCompositionPriming(name, version));
- }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
index 0cc2036e7..f34e5eff0 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -30,7 +30,6 @@ import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVIC
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML;
import java.util.List;
-import java.util.Map;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
@@ -45,7 +44,6 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -142,22 +140,6 @@ class CommissioningControllerTest extends CommonRestController {
}
@Test
- void testQueryCommonOrInstanceProperties() throws Exception {
- createFullEntryInDbWithCommonProps();
-
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
- + "/getCommonOrInstanceProperties?common=true");
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-
- @SuppressWarnings("unchecked")
- Map<String, ToscaNodeTemplate> commonProperties = rawresp.readEntity(Map.class);
-
- assertNotNull(commonProperties);
- assertThat(commonProperties).hasSize(4);
- }
-
- @Test
void testCreateBadRequest() {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response resp = invocationBuilder.post(Entity.json("NotToscaServiceTempalte"));
@@ -209,29 +191,6 @@ class CommissioningControllerTest extends CommonRestController {
}
@Test
- void testQueryElementsBadRequest() throws Exception {
- createEntryInDB();
-
- // Call get elements with no info
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements");
- Response resp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), resp.getStatus());
- }
-
- @Test
- void testQueryElements() throws Exception {
- createEntryInDB();
-
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements"
- + "?name=org.onap.domain.pmsh.PMSHAutomationCompositionDefinition");
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List<?> entityList = rawresp.readEntity(List.class);
- assertNotNull(entityList);
- assertThat(entityList).hasSize(4);
- }
-
- @Test
void testDeleteBadRequest() throws Exception {
createEntryInDB();
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index b826eebbc..016ec6c5e 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -23,17 +23,13 @@ package org.onap.policy.clamp.acm.runtime.instantiation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import java.util.List;
import java.util.Optional;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider;
@@ -41,24 +37,19 @@ import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-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;
/**
* Class to perform unit test of {@link AutomationCompositionInstantiationProvider}}.
*
*/
class AutomationCompositionInstantiationProviderTest {
- private static final String ID_NAME = "PMSH_Test_Instance";
- private static final String ID_VERSION = "1.2.3";
private static final String AC_INSTANTIATION_CREATE_JSON =
"src/test/resources/rest/acm/AutomationCompositions.json";
private static final String AC_INSTANTIATION_UPDATE_JSON =
@@ -89,54 +80,6 @@ class AutomationCompositionInstantiationProviderTest {
+ " {4}item \"AutomationComposition\" value \"org.onap.domain.PMSHAutomationCompositionDefinition\""
+ " INVALID, Commissioned automation composition definition not found\n";
- private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
-
- @BeforeAll
- public static void setUpBeforeClass() {
- serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- }
-
- @Test
- void testInstanceResponse() throws Exception {
- var participantProvider = Mockito.mock(ParticipantProvider.class);
- var acProvider = mock(AutomationCompositionProvider.class);
- var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
-
- when(commissioningProvider.getAllToscaServiceTemplate()).thenReturn(List.of(serviceTemplate));
- when(commissioningProvider.getToscaServiceTemplate(ID_NAME, ID_VERSION)).thenReturn(serviceTemplate);
-
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
- var instancePropertyList = instantiationProvider.createInstanceProperties(serviceTemplate);
- assertNull(instancePropertyList.getErrorDetails());
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0));
-
- AutomationCompositions automationCompositions =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- var automationComposition = automationCompositions.getAutomationCompositionList().get(0);
- automationComposition.setName(ID_NAME);
- automationComposition.setVersion(ID_VERSION);
- when(acProvider.getAutomationCompositions(ID_NAME, ID_VERSION)).thenReturn(List.of(automationComposition));
-
- var updatedInstancePropertyList = instantiationProvider.createInstanceProperties(serviceTemplate);
- assertNull(updatedInstancePropertyList.getErrorDetails());
- var updatedId = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- assertEquals(updatedId, instancePropertyList.getAffectedInstanceProperties().get(0));
-
- var instanceOrderState = instantiationProvider.getInstantiationOrderState(ID_NAME, ID_VERSION);
- assertEquals(AutomationCompositionOrderedState.UNINITIALISED, instanceOrderState.getOrderedState());
- assertEquals(ID_NAME, instanceOrderState.getAutomationCompositionIdentifierList().get(0).getName());
-
- when(acProvider.findAutomationComposition(ID_NAME, ID_VERSION)).thenReturn(Optional.of(automationComposition));
- when(acProvider.deleteAutomationComposition(ID_NAME, ID_VERSION)).thenReturn(automationComposition);
-
- var instanceResponse = instantiationProvider.deleteInstanceProperties(ID_NAME, ID_VERSION);
- assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName());
-
- }
-
@Test
void testInstantiationCrud() throws Exception {
var participantProvider = Mockito.mock(ParticipantProvider.class);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index 35a3094cd..7cdc8a975 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -23,7 +23,6 @@ package org.onap.policy.clamp.acm.runtime.instantiation.rest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
@@ -42,11 +41,7 @@ import org.onap.policy.clamp.acm.runtime.main.rest.InstantiationController;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionOrderStateResponse;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimedResponse;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstancePropertiesResponse;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
@@ -83,9 +78,6 @@ class InstantiationControllerTest extends CommonRestController {
private static final String INSTANTIATION_ENDPOINT = "instantiation";
private static final String INSTANTIATION_COMMAND_ENDPOINT = "instantiation/command";
- private static final String PRIMING_ENDPOINT = "automationCompositionPriming";
- private static final String INSTANTIATION_PROPERTIES = "instanceProperties";
- private static final String INSTANTIATION_STATE = "instantiationState";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
@@ -185,14 +177,6 @@ class InstantiationControllerTest extends CommonRestController {
assertEquals(automationCompositionFromRsc,
automationCompositionsFromDb.getAutomationCompositionList().get(0));
}
-
- invocationBuilder =
- super.sendRequest(PRIMING_ENDPOINT + "?name=" + "PMSHInstance0Create" + "&version=" + "1.0.1");
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- AutomationCompositionPrimedResponse primResponse =
- rawresp.readEntity(AutomationCompositionPrimedResponse.class);
- assertFalse(primResponse.getPrimedAutomationCompositionsList().get(0).isPrimed());
}
@Test
@@ -273,17 +257,6 @@ class InstantiationControllerTest extends CommonRestController {
}
@Test
- void testDelete_NoResultWithThisName() {
- Invocation.Builder invocationBuilder =
- super.sendRequest(INSTANTIATION_ENDPOINT + "?name=noResultWithThisName&version=1.0.1");
- Response resp = invocationBuilder.delete();
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
- InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
- assertNotNull(instResponse.getErrorDetails());
- assertNull(instResponse.getAffectedAutomationCompositions());
- }
-
- @Test
void testDelete() throws Exception {
AutomationCompositions automationCompositionsFromRsc =
@@ -325,89 +298,6 @@ class InstantiationControllerTest extends CommonRestController {
}
@Test
- void testCreateInstanceProperties() {
- Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
- Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- var instancePropertyList = resp.readEntity(InstancePropertiesResponse.class);
- assertNull(instancePropertyList.getErrorDetails());
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0));
-
- invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT);
- resp = invocationBuilder.get();
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- var automationCompositionsGet = resp.readEntity(AutomationCompositions.class);
- assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
- }
-
- @Test
- void testDeleteInstanceProperties() throws Exception {
- Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
- Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
-
- invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME + "&version=" + ID_VERSION);
- resp = invocationBuilder.delete();
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- var instanceResponse = resp.readEntity(InstantiationResponse.class);
- assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName());
- AutomationCompositions automationCompositionsGet =
- instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION);
- assertThat(automationCompositionsGet.getAutomationCompositionList()).isEmpty();
- }
-
- @Test
- void testDeleteInstancePropertiesBadRequest() {
- Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
- Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
-
- invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME);
- resp = invocationBuilder.delete();
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
- }
-
- @Test
- void testDeleteInstancePropertiesPassiveMode() throws Exception {
- Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
- Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
-
- var automationCompositions =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Command");
- instantiationProvider.createAutomationCompositions(automationCompositions);
-
- var participants = CommonTestData.createParticipants();
- for (var participant : participants) {
- participantProvider.saveParticipant(participant);
- }
-
- InstantiationCommand command =
- InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Command");
-
- invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
- resp = invocationBuilder.put(Entity.json(command));
- assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
- InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
- InstantiationUtils.assertInstantiationResponse(instResponse, command);
-
- // check passive state on DB and delete properties
- for (ToscaConceptIdentifier toscaConceptIdentifier : command.getAutomationCompositionIdentifierList()) {
- AutomationCompositions automationCompositionsGet = instantiationProvider
- .getAutomationCompositions(toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion());
- assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
- assertEquals(command.getOrderedState(),
- automationCompositionsGet.getAutomationCompositionList().get(0).getOrderedState());
-
- invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + toscaConceptIdentifier.getName()
- + "&version=" + toscaConceptIdentifier.getVersion());
- resp = invocationBuilder.delete();
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
- }
- }
-
- @Test
void testCommand_NotFound1() {
Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
Response resp = invocationBuilder.put(Entity.json(new InstantiationCommand()));
@@ -455,78 +345,6 @@ class InstantiationControllerTest extends CommonRestController {
}
}
- @Test
- void testIntanceProperties() throws Exception {
- Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
- Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- var instancePropertyList = resp.readEntity(InstancePropertiesResponse.class);
- assertNull(instancePropertyList.getErrorDetails());
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0));
-
- invocationBuilder = super.sendRequest(INSTANTIATION_STATE + "?name=" + ID_NAME + "&version=" + ID_VERSION);
- resp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- var instanceOrderState = resp.readEntity(AutomationCompositionOrderStateResponse.class);
- assertEquals(AutomationCompositionOrderedState.UNINITIALISED, instanceOrderState.getOrderedState());
- assertEquals(ID_NAME, instanceOrderState.getAutomationCompositionIdentifierList().get(0).getName());
- AutomationCompositions automationCompositionsGet =
- instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION);
- assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
-
- invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME + "&version=" + ID_VERSION);
- resp = invocationBuilder.delete();
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- var instanceResponse = resp.readEntity(InstantiationResponse.class);
- assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName());
- automationCompositionsGet = instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION);
- assertThat(automationCompositionsGet.getAutomationCompositionList()).isEmpty();
- }
-
- @Test
- void testChangeOrderStateFromUninitializedPassiveMode() throws Exception {
- Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
- Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
-
- var automationCompositions =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "CommandPassive");
- instantiationProvider.createAutomationCompositions(automationCompositions);
-
- var participants = CommonTestData.createParticipants();
- for (var participant : participants) {
- participantProvider.saveParticipant(participant);
- }
-
- InstantiationCommand command = InstantiationUtils
- .getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "CommandPassive");
-
- invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
- resp = invocationBuilder.put(Entity.json(command));
- assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
- InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
- InstantiationUtils.assertInstantiationResponse(instResponse, command);
- }
-
- @Test
- void testChangeOrderStateWithoutRegisteredParticipants() throws Exception {
- Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
- Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
-
- var automationCompositions =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "CommandPassive");
- instantiationProvider.createAutomationCompositions(automationCompositions);
-
- InstantiationCommand command = InstantiationUtils
- .getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "CommandPassive");
-
- invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
- resp = invocationBuilder.put(Entity.json(command));
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
- }
-
private synchronized void deleteEntryInDB() throws Exception {
automationCompositionRepository.deleteAll();
var list = serviceTemplateProvider.getAllServiceTemplates();