Add spring repository and service layer for tosca node templates 82/127382/5
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>
Mon, 28 Feb 2022 16:55:31 +0000 (16:55 +0000)
committerAjith Sreekumar <ajith.sreekumar@bell.ca>
Tue, 1 Mar 2022 16:01:04 +0000 (16:01 +0000)
Removed policy, policyType providers along with models provider
configurations.

Issue-ID: POLICY-3923
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: I696be6380758dbcc5b53cef635f3065eb0ce9a70

21 files changed:
main/pom.xml
main/src/main/java/org/onap/policy/api/main/config/PolicyApiConfig.java
main/src/main/java/org/onap/policy/api/main/repository/NodeTemplateRepository.java [new file with mode: 0644]
main/src/main/java/org/onap/policy/api/main/repository/NodeTypeRepository.java [new file with mode: 0644]
main/src/main/java/org/onap/policy/api/main/rest/NodeTemplateController.java
main/src/main/java/org/onap/policy/api/main/rest/provider/CommonModelProvider.java [deleted file]
main/src/main/java/org/onap/policy/api/main/rest/provider/NodeTemplateProvider.java [deleted file]
main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java [deleted file]
main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java [deleted file]
main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java [new file with mode: 0644]
main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java
main/src/main/resources/application.yaml
main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java
main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java
main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java [new file with mode: 0644]
main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java [new file with mode: 0644]
main/src/test/resources/application-test.yaml
main/src/test/resources/nodetemplates/dummy.apex.decisionmaker.policy.yaml [new file with mode: 0644]
main/src/test/resources/nodetemplates/nodetemplates.metadatasets.update.json
packages/policy-api-tarball/src/main/resources/etc/apiParameters.yaml
testsuites/stability/src/main/resources/apisetup/config/api/etc/defaultConfig.json

index 963f6d4..ebd7cb5 100644 (file)
@@ -38,7 +38,7 @@
     <dependencies>
         <dependency>
             <groupId>org.onap.policy.models</groupId>
-            <artifactId>policy-models-provider</artifactId>
+            <artifactId>policy-models-pdp</artifactId>
             <version>${policy.models.version}</version>
         </dependency>
         <dependency>
index e1cc58c..48202a8 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.policy.api.main.config;
 
 import org.onap.policy.api.main.rest.StatisticsReport;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.provider.PolicyModelsProvider;
-import org.onap.policy.models.provider.PolicyModelsProviderFactory;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 @Configuration
 public class PolicyApiConfig {
 
-    @Value("${policy-api.name}")
-    private String groupName;
-    @Value("${database.name}")
-    private String databaseName;
-    @Value("${database.implementation}")
-    private String databaseImplementation;
-    @Value("${database.driver}")
-    private String databaseDriver;
-    @Value("${database.url}")
-    private String databaseUrl;
-    @Value("${database.user}")
-    private String databaseUser;
-    @Value("${database.password}")
-    private String databasePassword;
-    @Value("${database.persistenceUnit}")
-    private String databasePersistenceUnit;
-
-    /**
-     * Initialize database configuration.
-     *
-     * @return PolicyModelsProvider
-     * @throws PfModelException Policy exception
-     */
-    @Bean(destroyMethod = "close")
-    public PolicyModelsProvider policyModelsProvider() throws PfModelException {
-        PolicyModelsProviderParameters modelsProviderParameters = new PolicyModelsProviderParameters();
-        modelsProviderParameters.setName(databaseName);
-        modelsProviderParameters.setImplementation(databaseImplementation);
-        modelsProviderParameters.setDatabaseDriver(databaseDriver);
-        modelsProviderParameters.setDatabaseUrl(databaseUrl);
-        modelsProviderParameters.setDatabaseUser(databaseUser);
-        modelsProviderParameters.setDatabasePassword(databasePassword);
-        modelsProviderParameters.setPersistenceUnit(databasePersistenceUnit);
-        modelsProviderParameters.setDatabaseDriver(databaseDriver);
-        return new PolicyModelsProviderFactory().createPolicyModelsProvider(modelsProviderParameters);
-    }
-
     /**
      * Initialize the statistics report bean.
      *
diff --git a/main/src/main/java/org/onap/policy/api/main/repository/NodeTemplateRepository.java b/main/src/main/java/org/onap/policy/api/main/repository/NodeTemplateRepository.java
new file mode 100644 (file)
index 0000000..9fdecbd
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.api.main.repository;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface NodeTemplateRepository extends JpaRepository<JpaToscaNodeTemplate, PfConceptKey> {
+}
diff --git a/main/src/main/java/org/onap/policy/api/main/repository/NodeTypeRepository.java b/main/src/main/java/org/onap/policy/api/main/repository/NodeTypeRepository.java
new file mode 100644 (file)
index 0000000..144dff2
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.api.main.repository;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface NodeTypeRepository extends JpaRepository<JpaToscaNodeType, PfConceptKey> {
+}
index 90e03da..19b3798 100644 (file)
@@ -38,8 +38,9 @@ import io.swagger.annotations.SwaggerDefinition;
 import java.net.HttpURLConnection;
 import java.util.List;
 import java.util.UUID;
+import lombok.RequiredArgsConstructor;
 import org.onap.policy.api.main.exception.PolicyApiRuntimeException;
-import org.onap.policy.api.main.rest.provider.NodeTemplateProvider;
+import org.onap.policy.api.main.service.ToscaServiceTemplateService;
 import org.onap.policy.common.endpoints.event.comm.Topic;
 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
 import org.onap.policy.models.base.PfModelException;
@@ -48,10 +49,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -79,12 +78,12 @@ import org.springframework.web.bind.annotation.RestController;
             @ExtensionProperty(name = "component", value = "Policy Framework")})}),
     schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
     securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
+@RequiredArgsConstructor
 public class NodeTemplateController extends CommonRestController {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(NodeTemplateController.class);
 
-    @Autowired
-    private NodeTemplateProvider provider;
+    private final ToscaServiceTemplateService toscaServiceTemplateService;
 
     /**
      * Creates one or more new tosca node templates in one call.
@@ -130,7 +129,7 @@ public class NodeTemplateController extends CommonRestController {
                 toJson(body));
         }
         try {
-            ToscaServiceTemplate nodeTemplates = provider.createNodeTemplates(body);
+            ToscaServiceTemplate nodeTemplates = toscaServiceTemplateService.createToscaNodeTemplates(body);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             final var msg = "POST /nodetemplates";
@@ -183,7 +182,7 @@ public class NodeTemplateController extends CommonRestController {
                 toJson(body));
         }
         try {
-            ToscaServiceTemplate nodeTemplates = provider.updateToscaNodeTemplates(body);
+            ToscaServiceTemplate nodeTemplates = toscaServiceTemplateService.updateToscaNodeTemplates(body);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             final var msg = "PUT /nodetemplates";
@@ -233,7 +232,7 @@ public class NodeTemplateController extends CommonRestController {
         @RequestHeader(name = REQUEST_ID_NAME, required = false)
         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
         try {
-            ToscaServiceTemplate nodeTemplates = provider.deleteToscaNodeTemplate(name, version);
+            ToscaServiceTemplate nodeTemplates = toscaServiceTemplateService.deleteToscaNodeTemplate(name, version);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             final var msg = String.format("DELETE /nodetemplates/%s/versions/%s", name, version);
@@ -287,7 +286,7 @@ public class NodeTemplateController extends CommonRestController {
         @RequestHeader(name = REQUEST_ID_NAME, required = false)
         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
         try {
-            List<ToscaNodeTemplate> nodeTemplates = provider.fetchToscaNodeTemplates(name, version);
+            List<ToscaNodeTemplate> nodeTemplates = toscaServiceTemplateService.fetchToscaNodeTemplates(name, version);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             var msg = String.format("GET /nodetemplates/%s/versions/%s", name, version);
@@ -335,7 +334,7 @@ public class NodeTemplateController extends CommonRestController {
         @RequestHeader(name = REQUEST_ID_NAME, required = false)
         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
         try {
-            List<ToscaNodeTemplate> nodeTemplates = provider.fetchToscaNodeTemplates(null, null);
+            List<ToscaNodeTemplate> nodeTemplates = toscaServiceTemplateService.fetchToscaNodeTemplates(null, null);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             var msg = "GET /nodetemplates";
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/CommonModelProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/CommonModelProvider.java
deleted file mode 100644 (file)
index 287c0b2..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP Policy API\r
- * ================================================================================\r
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.\r
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.\r
- * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * SPDX-License-Identifier: Apache-2.0\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.policy.api.main.rest.provider;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.function.BiConsumer;\r
-import javax.ws.rs.core.Response;\r
-import org.apache.commons.lang3.tuple.Pair;\r
-import org.onap.policy.models.base.PfConceptKey;\r
-import org.onap.policy.models.base.PfModelException;\r
-import org.onap.policy.models.pdp.concepts.PdpGroup;\r
-import org.onap.policy.models.pdp.concepts.PdpGroupFilter;\r
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;\r
-import org.onap.policy.models.pdp.enums.PdpState;\r
-import org.onap.policy.models.provider.PolicyModelsProvider;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;\r
-\r
-/**\r
- * Super class for providers that use a model provider.\r
- */\r
-public class CommonModelProvider {\r
-\r
-    protected final PolicyModelsProvider modelsProvider;\r
-\r
-    /**\r
-     * Constructs the object, populating {@link #modelsProvider}.\r
-     *\r
-     */\r
-    public CommonModelProvider(PolicyModelsProvider modelsProvider) {\r
-        this.modelsProvider = modelsProvider;\r
-    }\r
-\r
-    /**\r
-     * Collects all deployed versions of specified policy in all pdp groups.\r
-     *\r
-     * @param policyId the ID of policy\r
-     * @param policyType the concept key of policy type\r
-     * @param getter the custom generic getter Bifunction\r
-     * @param consumer the BiConsumer\r
-     * @param data the data structure storing retrieved deployed policies\r
-     *\r
-     * @return a map between pdp group and deployed versions of specified policy in that group\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    protected <T, R> Map<Pair<String, String>, T> collectDeployedPolicies(String policyId, PfConceptKey policyType,\r
-            BiFunctionWithEx<String, String, R> getter, BiConsumer<T, R> consumer, T data) throws PfModelException {\r
-\r
-        List<PdpGroup> pdpGroups = getPolicyTypeFilteredPdpGroups(policyType);\r
-        hasActivePdpGroup(pdpGroups, policyType, policyId);\r
-        return constructDeployedPolicyMap(pdpGroups, policyId, policyType, getter, consumer, data);\r
-    }\r
-\r
-    @FunctionalInterface\r
-    protected interface BiFunctionWithEx<T, U, R> {\r
-        public R apply(T value1, U value2) throws PfModelException;\r
-    }\r
-\r
-    /**\r
-     * Checks if the list of pdp groups is empty. If so, throws exception saying specified policy deployment is not\r
-     * found in all existing pdp groups.\r
-     *\r
-     * @param pdpGroups the list of pdp groups to check against\r
-     * @param policyType the concept key of policy type\r
-     * @param policyId the ID of policy\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private void hasActivePdpGroup(List<PdpGroup> pdpGroups, PfConceptKey policyType, String policyId)\r
-            throws PfModelException {\r
-\r
-        if (pdpGroups.isEmpty()) {\r
-            throw new PfModelException(Response.Status.NOT_FOUND,\r
-                    constructDeploymentNotFoundMessage(policyType, policyId));\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Retrieves all pdp groups supporting specified policy type.\r
-     *\r
-     * @param policyType the policy type\r
-     *\r
-     * @return a list of pdp groups supporting specified policy type\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private List<PdpGroup> getPolicyTypeFilteredPdpGroups(PfConceptKey policyType) throws PfModelException {\r
-\r
-        List<ToscaConceptIdentifier> policyTypes = new ArrayList<>();\r
-        policyTypes.add(new ToscaConceptIdentifier(policyType.getName(), policyType.getVersion()));\r
-        var pdpGroupFilter = PdpGroupFilter.builder().policyTypeList(policyTypes).groupState(PdpState.ACTIVE)\r
-                .pdpState(PdpState.ACTIVE).build();\r
-        return modelsProvider.getFilteredPdpGroups(pdpGroupFilter);\r
-    }\r
-\r
-    /**\r
-     * Constructs the map of deployed pdp groups and deployed policies.\r
-     *\r
-     * @param pdpGroups the list of pdp groups that contain the specified policy\r
-     * @param policyId the ID of policy\r
-     * @param policyType the concept key of policy type\r
-     * @param getter the custom generic getter BiFunction\r
-     * @param consumer the BiConsumer\r
-     * @param data the data structure storing retrieved deployed policies\r
-     *\r
-     * @return the constructed map of pdp groups and deployed policies\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private <T, R> Map<Pair<String, String>, T> constructDeployedPolicyMap(List<PdpGroup> pdpGroups, String policyId,\r
-            PfConceptKey policyType, BiFunctionWithEx<String, String, R> getter, BiConsumer<T, R> consumer, T data)\r
-            throws PfModelException {\r
-\r
-        Map<Pair<String, String>, T> deployedPolicyMap = new HashMap<>();\r
-        for (PdpGroup pdpGroup : pdpGroups) {\r
-            List<ToscaConceptIdentifier> policyIdentifiers = extractPolicyIdentifiers(policyId, pdpGroup, policyType);\r
-            var deployedPolicies = getDeployedPolicies(policyIdentifiers, policyType, getter, consumer, data);\r
-            deployedPolicyMap.put(Pair.of(pdpGroup.getName(), pdpGroup.getVersion()), deployedPolicies);\r
-        }\r
-        return deployedPolicyMap;\r
-    }\r
-\r
-    /**\r
-     * Extracts policy identifiers matching specified policy ID from specified pdp group.\r
-     *\r
-     * @param policyId the ID of policy to match\r
-     * @param pdpGroup the target pdp group to search\r
-     * @param policyType the concept key of policy type\r
-     *\r
-     * @return the list of policy identifiers\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private List<ToscaConceptIdentifier> extractPolicyIdentifiers(String policyId, PdpGroup pdpGroup,\r
-            PfConceptKey policyType) throws PfModelException {\r
-\r
-        List<ToscaConceptIdentifier> policyIdentifiers = new ArrayList<>();\r
-        for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {\r
-            for (ToscaConceptIdentifier policyIdentifier : pdpSubGroup.getPolicies()) {\r
-                if (policyId.equalsIgnoreCase(policyIdentifier.getName())) {\r
-                    policyIdentifiers.add(policyIdentifier);\r
-                }\r
-            }\r
-        }\r
-        if (policyIdentifiers.isEmpty()) {\r
-            throw new PfModelException(Response.Status.NOT_FOUND,\r
-                    constructDeploymentNotFoundMessage(policyType, policyId));\r
-        }\r
-        return policyIdentifiers;\r
-    }\r
-\r
-    /**\r
-     * Retrieves deployed policies in a generic way.\r
-     *\r
-     * @param policyIdentifiers the identifiers of the policies to return\r
-     * @param policyType the concept key of current policy type\r
-     * @param getter the method reference of getting deployed policies\r
-     * @param consumer the method reference of consuming the returned policies\r
-     * @param data the data structure of deployed policies to return\r
-     *\r
-     * @return the generic type of policy data structure to return\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private <T, R> T getDeployedPolicies(List<ToscaConceptIdentifier> policyIdentifiers, PfConceptKey policyType,\r
-            BiFunctionWithEx<String, String, R> getter, BiConsumer<T, R> consumer, T data) throws PfModelException {\r
-\r
-        for (ToscaConceptIdentifier policyIdentifier : policyIdentifiers) {\r
-            var result = getter.apply(policyIdentifier.getName(),\r
-                    getTrimedVersionForLegacyType(policyIdentifier.getVersion(), policyType));\r
-            consumer.accept(data, result);\r
-        }\r
-        return data;\r
-    }\r
-\r
-    /**\r
-     * Trims the version for legacy policies.\r
-     *\r
-     * @param fullVersion the full version format with major, minor, patch\r
-     * @param policyType the concept key of policy type\r
-     *\r
-     * @return the trimmed version\r
-     */\r
-    private String getTrimedVersionForLegacyType(String fullVersion, PfConceptKey policyType) {\r
-        return (policyType.getName().contains("guard") || policyType.getName().contains("Operational"))\r
-                ? fullVersion.split("\\.")[0]\r
-                : fullVersion;\r
-    }\r
-\r
-    /**\r
-     * Constructs returned message for not found policy deployment.\r
-     *\r
-     * @param policyType the concept key of policy type\r
-     * @param policyId the ID of policy\r
-     *\r
-     * @return constructed message\r
-     */\r
-    private String constructDeploymentNotFoundMessage(PfConceptKey policyType, String policyId) {\r
-\r
-        return "could not find policy with ID " + policyId + " and type " + policyType.getName() + ":"\r
-                + policyType.getVersion() + " deployed in any pdp group";\r
-    }\r
-}
\ No newline at end of file
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/NodeTemplateProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/NodeTemplateProvider.java
deleted file mode 100644 (file)
index 2ff5024..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2022 Nordix Foundation. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * 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.api.main.rest.provider;
-
-import java.util.List;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.provider.PolicyModelsProvider;
-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.stereotype.Service;
-
-@Service
-public class NodeTemplateProvider extends CommonModelProvider {
-
-    /**
-     * Default constructor.
-     */
-    @Autowired
-    public NodeTemplateProvider(PolicyModelsProvider modelsProvider) throws PfModelException {
-        super(modelsProvider);
-    }
-
-
-    /**
-     * Retrieves a node template matching specified ID and version.
-     *
-     * @param name the name of the node template, null to return all entries
-     * @param version the version of node template, null to return all entries
-     *
-     * @return the List of node templates
-     *
-     * @throws PfModelException the PfModel parsing exception
-     */
-    public List<ToscaNodeTemplate> fetchToscaNodeTemplates(final String name, final String version)
-        throws PfModelException {
-
-        return modelsProvider.getToscaNodeTemplate(name, version);
-    }
-
-
-    /**
-     * Creates one or more new node templates.
-     *
-     * @param serviceTemplate service template containing node template definitions
-     *
-     * @return the ToscaServiceTemplate object
-     *
-     * @throws PfModelException the PfModel parsing exception
-     */
-    public ToscaServiceTemplate createNodeTemplates(ToscaServiceTemplate serviceTemplate)
-        throws PfModelException {
-
-        return modelsProvider.createToscaNodeTemplates(serviceTemplate);
-    }
-
-
-    /**
-     * Update one or more node templates.
-     *
-     * @param serviceTemplate service template with updated node templates
-     * @return the ToscaServiceTemplate object
-     *
-     * @throws PfModelException the PfModel parsing exception
-     */
-    public ToscaServiceTemplate updateToscaNodeTemplates(ToscaServiceTemplate serviceTemplate)
-        throws PfModelException {
-
-        return modelsProvider.updateToscaNodeTemplates(serviceTemplate);
-    }
-
-
-    /**
-     * Deletes the node template matching specified ID and version.
-     *
-     * @param name the name of the node template
-     * @param version the version of the node template
-     *
-     * @return the ToscaServiceTemplate object
-     *
-     * @throws PfModelException the PfModel parsing exception
-     */
-    public ToscaServiceTemplate deleteToscaNodeTemplate(String name, String version)
-        throws PfModelException {
-
-        return modelsProvider.deleteToscaNodeTemplate(name, version);
-    }
-
-
-}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
deleted file mode 100644 (file)
index 1e5ed47..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP Policy API\r
- * ================================================================================\r
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.\r
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.\r
- * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * SPDX-License-Identifier: Apache-2.0\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.policy.api.main.rest.provider;\r
-\r
-import org.onap.policy.api.main.rest.PolicyFetchMode;\r
-import org.onap.policy.models.base.PfModelException;\r
-import org.onap.policy.models.provider.PolicyModelsProvider;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Service;\r
-\r
-/**\r
- * Class to provide all kinds of policy operations.\r
- *\r
- * @author Chenfei Gao (cgao@research.att.com)\r
- */\r
-@Service\r
-public class PolicyProvider extends CommonModelProvider {\r
-\r
-    /**\r
-     * Default constructor.\r
-     */\r
-    @Autowired\r
-    public PolicyProvider(PolicyModelsProvider modelsProvider) throws PfModelException {\r
-        super(modelsProvider);\r
-    }\r
-\r
-    /**\r
-     * Retrieves a list of policies matching specified ID and version of both policy type and policy.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     * @param policyId the ID of policy\r
-     * @param policyVersion the version of policy\r
-     * @param mode the fetch mode for policies\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate fetchPolicies(final String policyTypeId, final String policyTypeVersion,\r
-            final String policyId, final String policyVersion, final PolicyFetchMode mode) throws PfModelException {\r
-\r
-        return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);\r
-    }\r
-\r
-    /**\r
-     * Retrieves a list of policies with the latest versions that match specified policy type id and version.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     * @param policyId the ID of the policy\r
-     * @param mode the fetch mode for policies\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate fetchLatestPolicies(final String policyTypeId, final String policyTypeVersion,\r
-            final String policyId, final PolicyFetchMode mode) throws PfModelException {\r
-\r
-        return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaTypedEntityFilter.LATEST_VERSION,\r
-                mode);\r
-    }\r
-\r
-    /**\r
-     * Creates one or more new policies for the same policy type ID and version.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     * @param body the entity body of polic(ies)\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate createPolicy(String policyTypeId, String policyTypeVersion, ToscaServiceTemplate body)\r
-            throws PfModelException {\r
-\r
-        return modelsProvider.createPolicies(body);\r
-    }\r
-\r
-    /**\r
-     * Creates one or more new policies.\r
-     *\r
-     * @param body the entity body of policy\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate createPolicies(ToscaServiceTemplate body) throws PfModelException {\r
-        return modelsProvider.createPolicies(body);\r
-    }\r
-\r
-    /**\r
-     * Deletes the policy matching specified ID and version of both policy type and policy.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     * @param policyId the ID of policy\r
-     * @param policyVersion the version of policy\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate deletePolicy(String policyTypeId, String policyTypeVersion, String policyId,\r
-            String policyVersion) throws PfModelException {\r
-\r
-        return modelsProvider.deletePolicy(policyId, policyVersion);\r
-    }\r
-\r
-    /**\r
-     * Retrieves the specified version of the policy.\r
-     *\r
-     * @param policyTypeName the name of the policy type\r
-     * @param policyTypeVersion the version of the policy type\r
-     * @param policyName the name of the policy\r
-     * @param policyVersion the version of the policy\r
-     * @param mode the fetch mode for policies\r
-     *\r
-     * @return the TOSCA service template containing the specified version of the policy\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private ToscaServiceTemplate getFilteredPolicies(final String policyTypeName, final String policyTypeVersion,\r
-            final String policyName, final String policyVersion, final PolicyFetchMode mode) throws PfModelException {\r
-\r
-        ToscaTypedEntityFilter<ToscaPolicy> policyFilter = ToscaTypedEntityFilter.<ToscaPolicy>builder()\r
-                .name(policyName).version(policyVersion).type(policyTypeName).typeVersion(policyTypeVersion).build();\r
-\r
-        ToscaServiceTemplate serviceTemplate = modelsProvider.getFilteredPolicies(policyFilter);\r
-\r
-        if (mode == null || PolicyFetchMode.BARE.equals(mode)) {\r
-            serviceTemplate.setPolicyTypes(null);\r
-            serviceTemplate.setDataTypes(null);\r
-        }\r
-\r
-        return serviceTemplate;\r
-    }\r
-}
\ No newline at end of file
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
deleted file mode 100644 (file)
index 4db1698..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP Policy API\r
- * ================================================================================\r
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.\r
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.\r
- * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * SPDX-License-Identifier: Apache-2.0\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.policy.api.main.rest.provider;\r
-\r
-import org.onap.policy.models.base.PfModelException;\r
-import org.onap.policy.models.provider.PolicyModelsProvider;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Service;\r
-\r
-/**\r
- * Class to provide all kinds of policy type operations.\r
- *\r
- * @author Chenfei Gao (cgao@research.att.com)\r
- */\r
-@Service\r
-public class PolicyTypeProvider extends CommonModelProvider {\r
-\r
-    /**\r
-     * Default constructor.\r
-     */\r
-    @Autowired\r
-    public PolicyTypeProvider(PolicyModelsProvider modelsProvider) throws PfModelException {\r
-        super(modelsProvider);\r
-    }\r
-\r
-    /**\r
-     * Retrieves a list of policy types matching specified policy type ID and version.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate fetchPolicyTypes(String policyTypeId, String policyTypeVersion)\r
-            throws PfModelException {\r
-\r
-        return getFilteredPolicyTypes(policyTypeId, policyTypeVersion);\r
-    }\r
-\r
-    /**\r
-     * Retrieves a list of policy types with the latest versions.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate fetchLatestPolicyTypes(String policyTypeId) throws PfModelException {\r
-\r
-        return getFilteredPolicyTypes(policyTypeId, ToscaEntityFilter.LATEST_VERSION);\r
-    }\r
-\r
-    /**\r
-     * Creates a new policy type.\r
-     *\r
-     * @param body the entity body of policy type\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate createPolicyType(ToscaServiceTemplate body) throws PfModelException {\r
-\r
-        return modelsProvider.createPolicyTypes(body);\r
-    }\r
-\r
-    /**\r
-     * Delete the policy type matching specified policy type ID and version.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     *\r
-     * @return the ToscaServiceTemplate object\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public ToscaServiceTemplate deletePolicyType(String policyTypeId, String policyTypeVersion)\r
-            throws PfModelException {\r
-\r
-        return modelsProvider.deletePolicyType(policyTypeId, policyTypeVersion);\r
-    }\r
-\r
-    /**\r
-     * Retrieves the specified version of the policy type.\r
-     *\r
-     * @param policyTypeName the name of the policy type\r
-     * @param policyTypeVersion the version of the policy type\r
-     *\r
-     * @return the TOSCA service template containing the specified version of the policy type\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private ToscaServiceTemplate getFilteredPolicyTypes(String policyTypeName, String policyTypeVersion)\r
-            throws PfModelException {\r
-\r
-        ToscaEntityFilter<ToscaPolicyType> policyTypeFilter =\r
-                ToscaEntityFilter.<ToscaPolicyType>builder().name(policyTypeName).version(policyTypeVersion).build();\r
-        return modelsProvider.getFilteredPolicyTypes(policyTypeFilter);\r
-    }\r
-}
\ No newline at end of file
diff --git a/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java b/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java
new file mode 100644 (file)
index 0000000..b4eec37
--- /dev/null
@@ -0,0 +1,144 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.api.main.service;
+
+import java.util.Optional;
+import javax.ws.rs.core.Response;
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import org.onap.policy.api.main.repository.NodeTemplateRepository;
+import org.onap.policy.api.main.repository.NodeTypeRepository;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.utils.ToscaUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class NodeTemplateService {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(NodeTemplateService.class);
+
+    private final NodeTemplateRepository nodeTemplateRepository;
+    private final NodeTypeRepository nodeTypeRepository;
+
+    /**
+     * Delete the specified node template.
+     *
+     * @param nodeTemplateKey the node template key containing name and version
+     */
+    public void deleteNodeTemplate(final PfConceptKey nodeTemplateKey) {
+        nodeTemplateRepository.deleteById(nodeTemplateKey);
+    }
+
+
+    /**
+     * Update the specified tosca node template.
+     * @param incomingServiceTemplate incoming service template
+     */
+    public void updateToscaNodeTemplates(@NonNull final JpaToscaServiceTemplate incomingServiceTemplate)
+        throws PfModelRuntimeException, PfModelException {
+        for (JpaToscaNodeTemplate nodeTemplate : incomingServiceTemplate.getTopologyTemplate().getNodeTemplates()
+            .getAll(null)) {
+            //verify if the node template is referenced in the metadata of created policies
+            assertNodeTemplateNotUsedInPolicy(nodeTemplate.getName(), nodeTemplate.getVersion(),
+                incomingServiceTemplate);
+            verifyNodeTypeInDbTemplate(nodeTemplate);
+            Optional<JpaToscaNodeTemplate> dbNodeTemplate = nodeTemplateRepository.findById(nodeTemplate.getKey());
+            if (dbNodeTemplate.isPresent()) {
+                nodeTemplateRepository.save(nodeTemplate);
+            } else {
+                throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, "node template "
+                    + nodeTemplate.getName() + " version " + nodeTemplate.getVersion() + " does not exist in database");
+            }
+        }
+
+        // Return the service template with updated node templates
+        var updatedNodeTemplates = new JpaToscaNodeTemplates();
+        updatedNodeTemplates.setKey(incomingServiceTemplate.getTopologyTemplate().getNodeTemplates().getKey());
+
+        for (PfConceptKey key : incomingServiceTemplate.getTopologyTemplate().getNodeTemplates()
+            .getConceptMap().keySet()) {
+            Optional<JpaToscaNodeTemplate> jpaNodeTemplate = nodeTemplateRepository.findById(key);
+            jpaNodeTemplate.ifPresent(
+                jpaToscaNodeTemplate -> updatedNodeTemplates.getConceptMap().put(key, jpaToscaNodeTemplate));
+        }
+        incomingServiceTemplate.getTopologyTemplate().setNodeTemplates(updatedNodeTemplates);
+
+    }
+
+
+    /**
+     * Verify the node type for a toscaNodeTemplate .
+     *
+     * @param toscaNodeTemplate the toscaNodeTemplate to check the toscaNodeTemplate type for
+     */
+    public void verifyNodeTypeInDbTemplate(final JpaToscaNodeTemplate toscaNodeTemplate) throws
+        PfModelException {
+        PfConceptKey nodeTypeKey = toscaNodeTemplate.getType();
+
+        Optional<JpaToscaNodeType> nodeType = nodeTypeRepository.findById(nodeTypeKey);
+
+        if (nodeType.isEmpty()) {
+            String errorMessage =
+                "NODE_TYPE " + nodeTypeKey + " for toscaNodeTemplate " + toscaNodeTemplate.getId()
+                    + " does not exist";
+            throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage);
+        }
+    }
+
+    /**
+     * Assert that the node template is not referenced in any Tosca policy.
+     *
+     * @param name the name of node template
+     * @param version the version of node template
+     * @throws PfModelException if node template referenced in a policy
+     */
+    public void assertNodeTemplateNotUsedInPolicy(String name, String version, JpaToscaServiceTemplate dbTemplate)
+        throws PfModelException {
+        try {
+            //Retrieve all the policies from db, return if policies doesn't exist
+            ToscaUtils.assertPoliciesExist(dbTemplate);
+        } catch (PfModelRuntimeException e) {
+            LOGGER.debug("Could not verify the node template reference in created policies ", e);
+            return;
+        }
+        for (JpaToscaPolicy policy : dbTemplate.getTopologyTemplate().getPolicies().getConceptMap().values()) {
+            if (policy.getMetadata().getOrDefault("metadataSetName", "").equals(name)
+                && policy.getMetadata().getOrDefault("metadataSetVersion", "").equals(version)) {
+                throw new PfModelException(Response.Status.NOT_ACCEPTABLE,
+                    "Node template is in use, it is referenced in Tosca Policy " + policy.getName() + " version "
+                        + policy.getVersion());
+            }
+        }
+
+    }
+}
index 0fa0225..d578d0d 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.api.main.service;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
+import javax.annotation.Nonnull;
 import javax.ws.rs.core.Response;
 import lombok.NonNull;
 import lombok.RequiredArgsConstructor;
@@ -33,10 +36,14 @@ import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
 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.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTypes;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -63,6 +70,7 @@ public class ToscaServiceTemplateService {
     public static final String DO_NOT_EXIST_MSG = " do not exist";
 
     private final ToscaServiceTemplateRepository toscaServiceTemplateRepository;
+    private final NodeTemplateService nodeTemplateService;
     private final PdpGroupService pdpGroupService;
     private final PolicyTypeService policyTypeService;
     private final PolicyService policyService;
@@ -428,6 +436,142 @@ public class ToscaServiceTemplateService {
         return returnServiceTemplate.toAuthorative();
     }
 
+    /**
+     * Write a node template to the database.
+     *
+     * @param serviceTemplate the service template to be written
+     * @return the service template created by this method
+     * @throws PfModelException on errors writing the metadataSets
+     */
+    public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
+        throws PfModelException {
+
+        LOGGER.debug("->write: tosca nodeTemplates={}", serviceTemplate);
+        final var incomingServiceTemplate = new JpaToscaServiceTemplate(serviceTemplate);
+
+        ToscaUtils.assertNodeTemplatesExist(incomingServiceTemplate);
+
+        Optional<JpaToscaNodeTypes> nodeTypes = Optional.ofNullable(incomingServiceTemplate.getNodeTypes());
+        for (JpaToscaNodeTemplate nodeTemplate : incomingServiceTemplate.getTopologyTemplate().getNodeTemplates()
+            .getAll(null)) {
+            // verify node types in the db if mismatch/empty entities in the template
+            if (! (nodeTypes.isPresent() && nodeTypes.get().getKeys().contains(nodeTemplate.getType()))) {
+                nodeTemplateService.verifyNodeTypeInDbTemplate(nodeTemplate);
+            }
+        }
+        // append the incoming fragment to the DB TOSCA service template
+        final var serviceTemplateToWrite =
+            ToscaServiceTemplateUtils.addFragment(getDefaultJpaToscaServiceTemplate(), incomingServiceTemplate);
+
+        final var result = serviceTemplateToWrite.validate("service template.");
+        if (!result.isValid()) {
+            throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.getResult());
+        }
+        toscaServiceTemplateRepository.save(serviceTemplateToWrite);
+        LOGGER.debug("<-createdToscaNodeTemplates: writtenServiceTemplate={}", serviceTemplateToWrite);
+
+        return serviceTemplate;
+    }
+
+    /**
+     * Update tosca node template.
+     *
+     * @param serviceTemplate the service template containing the definitions of the node templates to be updated.
+     * @return the TOSCA service template containing the node templates that were updated
+     * @throws PfModelRuntimeException on errors updating node templates
+     */
+    public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
+        throws PfModelException {
+        LOGGER.debug("->updateToscaNodeTemplates: serviceTemplate={}", serviceTemplate);
+        final var incomingServiceTemplate = new JpaToscaServiceTemplate(serviceTemplate);
+
+        ToscaUtils.assertNodeTemplatesExist(incomingServiceTemplate);
+        nodeTemplateService.updateToscaNodeTemplates(incomingServiceTemplate);
+
+        LOGGER.debug("<-updatedToscaNodeTemplates: serviceTemplate={}", serviceTemplate);
+        return incomingServiceTemplate.toAuthorative();
+    }
+
+
+    /**
+     * Delete a tosca node template.
+     *
+     * @param name the name of node template
+     * @param version the version of node template
+     * @return the TOSCA service template containing the node template that were deleted
+     * @throws PfModelException on errors deleting node templates
+     */
+    public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @Nonnull final String version)
+        throws PfModelException {
+        LOGGER.debug("->deleteToscaNodeTemplate: name={}, version={}", name, version);
+
+        JpaToscaServiceTemplate dbServiceTemplate = getDefaultJpaToscaServiceTemplate();
+        final var nodeTemplateKey = new PfConceptKey(name, version);
+
+        if (!ToscaUtils.doNodeTemplatesExist(dbServiceTemplate)) {
+            throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "no node templates found");
+        }
+        JpaToscaNodeTemplate nodeTemplate4Deletion = dbServiceTemplate.getTopologyTemplate().getNodeTemplates()
+            .get(new PfConceptKey(name, version));
+        if (nodeTemplate4Deletion == null) {
+            throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "node template " + name + ":" + version
+                + NOT_FOUND);
+        }
+        //Verify if the node template is referenced in the metadata of created policies
+        nodeTemplateService.assertNodeTemplateNotUsedInPolicy(name, version, dbServiceTemplate);
+
+        dbServiceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap().remove(nodeTemplateKey);
+        toscaServiceTemplateRepository.save(dbServiceTemplate);
+
+        // remove the entry from the tosca node template table
+        nodeTemplateService.deleteNodeTemplate(nodeTemplateKey);
+
+        // prepare the return service template
+        var deletedServiceTemplate = new JpaToscaServiceTemplate();
+        deletedServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+        deletedServiceTemplate.getTopologyTemplate().setNodeTemplates(new JpaToscaNodeTemplates());
+        deletedServiceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap()
+            .put(nodeTemplateKey, nodeTemplate4Deletion);
+
+        LOGGER.debug("<-deleteToscaNodeTemplate: key={}, serviceTemplate={}", nodeTemplateKey, deletedServiceTemplate);
+        return deletedServiceTemplate.toAuthorative();
+    }
+
+
+    /**
+     * Get tosca node templates.
+     *
+     * @param name the name of the node template to get, set to null to get all node templates
+     * @param version the version of the node template to get, set to null to get all versions
+     * @return the node templates with the specified key
+     * @throws PfModelException on errors getting node templates
+     */
+    public List<ToscaNodeTemplate> fetchToscaNodeTemplates(final String name, final String version)
+        throws PfModelException {
+        LOGGER.debug("->getNodeTemplate: name={}, version={}", name, version);
+        List<ToscaNodeTemplate> nodeTemplates = new ArrayList<>();
+        var jpaNodeTemplates = new JpaToscaNodeTemplates();
+
+        var dbServiceTemplate = getDefaultJpaToscaServiceTemplate();
+        //Return empty if no nodeTemplates present in db
+        if (!ToscaUtils.doNodeTemplatesExist(dbServiceTemplate)) {
+            return nodeTemplates;
+        }
+        jpaNodeTemplates = dbServiceTemplate.getTopologyTemplate().getNodeTemplates();
+
+        //Filter specific nodeTemplates
+        if (name != null && version != null) {
+            var filterKey = new PfConceptKey(name, version);
+            jpaNodeTemplates.getConceptMap().entrySet().removeIf(entity -> !entity.getKey().equals(filterKey));
+        }
+        jpaNodeTemplates.getConceptMap().forEach((key, value) -> nodeTemplates.add(value.toAuthorative()));
+        LOGGER.debug("<-getNodeTemplateMetadataSet: name={}, version={}, nodeTemplates={}", name, version,
+            nodeTemplates);
+
+        return nodeTemplates;
+    }
+
+
     /**
      * Get Service Template.
      *
index f46810e..35ca4ed 100644 (file)
@@ -25,15 +25,6 @@ policy-api:
   name: ApiGroup
   aaf: false
 
-database:
-  name: PolicyProviderParameterGroup
-  implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
-  driver: org.mariadb.jdbc.Driver
-  url: jdbc:mariadb://mariadb:3306/policyadmin
-  user: policy_user
-  password: policy_user
-  persistenceUnit: PolicyDb
-
 policy-preload:
   policyTypes:
     - policytypes/onap.policies.monitoring.tcagen2.yaml
index 5244f3c..993fbee 100644 (file)
@@ -36,11 +36,9 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.onap.policy.api.main.PolicyApiApplication;
-import org.onap.policy.api.main.rest.provider.NodeTemplateProvider;
 import org.onap.policy.api.main.rest.utils.CommonTestRestController;
+import org.onap.policy.api.main.service.ToscaServiceTemplateService;
 import org.onap.policy.common.utils.security.SelfSignedKeyStore;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.errors.concepts.ErrorResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -86,7 +84,7 @@ public class TestNodeTemplateController extends CommonTestRestController {
     private int apiPort;
 
     @Autowired
-    private NodeTemplateProvider provider;
+    private ToscaServiceTemplateService toscaServiceTemplateService;
 
     /**
      * Initializes parameters and set up test environment.
@@ -107,8 +105,8 @@ public class TestNodeTemplateController extends CommonTestRestController {
     public void clearDb() {
         for (String name : nodeTemplateKeys) {
             try {
-                provider.deleteToscaNodeTemplate(name, "1.0.0");
-            } catch (PfModelException | PfModelRuntimeException e) {
+                toscaServiceTemplateService.deleteToscaNodeTemplate(name, "1.0.0");
+            } catch (Exception e) {
                 //do nothing
             }
         }
index 8d80cac..4af3093 100644 (file)
@@ -47,6 +47,8 @@ public class TestCommonToscaServiceTemplateService {
     protected PolicyTypeService policyTypeService;
     @Mock
     protected PolicyService policyService;
+    @Mock
+    protected NodeTemplateService nodeTemplateService;
 
     /**
      * Setup the DB TOSCA service template object post create, and delete request.
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java b/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java
new file mode 100644 (file)
index 0000000..7d85eef
--- /dev/null
@@ -0,0 +1,120 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy API
+ * ================================================================================
+ * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.api.main.service;
+
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.policy.api.main.repository.NodeTemplateRepository;
+import org.onap.policy.api.main.repository.NodeTypeRepository;
+import org.onap.policy.common.utils.coder.CoderException;
+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.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestNodeTemplateService {
+
+    @Mock
+    private NodeTemplateRepository nodeTemplateRepository;
+
+    @Mock
+    private NodeTypeRepository nodeTypeRepository;
+
+    @InjectMocks
+    private NodeTemplateService nodeTemplateService;
+
+    private static final String POLICY_WITH_METADATA_SET_REF = "nodetemplates/dummy.apex.decisionmaker.policy.yaml";
+    private static final String UPDATED_NODE_TEMPLATE_JSON = "nodetemplates/nodetemplates.metadatasets.update.json";
+
+    private static ToscaServiceTemplate updatedToscaServiceTemplate;
+    private StandardCoder standardCoder;
+    private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator();
+    ToscaServiceTemplate policyServiceTemplate;
+
+    /**
+     * Set up for tests.
+     * @throws CoderException if error in json parsing
+     */
+    @Before
+    public void setUp() throws CoderException {
+        standardCoder = new StandardCoder();
+        policyServiceTemplate =
+            yamlJsonTranslator.fromYaml(ResourceUtils.getResourceAsString(POLICY_WITH_METADATA_SET_REF),
+                ToscaServiceTemplate.class);
+        updatedToscaServiceTemplate =
+            standardCoder.decode(ResourceUtils.getResourceAsString(UPDATED_NODE_TEMPLATE_JSON),
+                ToscaServiceTemplate.class);
+    }
+
+    @Test
+    public void testVerifyNodeType() {
+        assertThatThrownBy(() -> {
+            nodeTemplateService.verifyNodeTypeInDbTemplate(new JpaToscaNodeTemplate());
+        }).hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$");
+
+        JpaToscaNodeTemplate jpaToscaNodeTemplate = new JpaToscaNodeTemplate();
+        PfConceptKey nodeType = new PfConceptKey("dummyType", "1.0.0");
+        jpaToscaNodeTemplate.setType(nodeType);
+        jpaToscaNodeTemplate.setKey(new PfConceptKey("dummyName", "1.0.0"));
+        Mockito.when(nodeTypeRepository.findById(nodeType)).thenReturn(Optional.of(new JpaToscaNodeType()));
+        assertDoesNotThrow(() -> nodeTemplateService.verifyNodeTypeInDbTemplate(jpaToscaNodeTemplate));
+    }
+
+    @Test
+    public void testNodeTemplateUsedInPolicy() {
+        assertDoesNotThrow(() -> nodeTemplateService.assertNodeTemplateNotUsedInPolicy("dummyName", "1.0.0",
+            new JpaToscaServiceTemplate(policyServiceTemplate)));
+
+        assertThatThrownBy(() -> {
+            nodeTemplateService.assertNodeTemplateNotUsedInPolicy("apexMetadata_decisionMaker", "1.0.0",
+                new JpaToscaServiceTemplate(policyServiceTemplate));
+        }).hasMessage("Node template is in use, it is referenced in Tosca Policy operational.apex.decisionMaker "
+            + "version 1.0.0");
+    }
+
+    @Test
+    public void testNodeTemplateUpdate() throws PfModelException {
+
+        Mockito.when(nodeTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(new JpaToscaNodeType()));
+        Mockito.when(nodeTemplateRepository.findById(Mockito.any())).thenReturn(Optional.of(
+            new JpaToscaNodeTemplate()));
+        assertDoesNotThrow(() -> nodeTemplateService.updateToscaNodeTemplates(
+            new JpaToscaServiceTemplate(updatedToscaServiceTemplate)));
+    }
+}
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java
new file mode 100644 (file)
index 0000000..6c6f016
--- /dev/null
@@ -0,0 +1,160 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy API
+ * ================================================================================
+ * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.api.main.service;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServiceTemplateService {
+
+    private static final String NODE_TEMPLATES_JSON = "nodetemplates/nodetemplates.metadatasets.input.tosca.json";
+    private static final String UPDATED_NODE_TEMPLATE_JSON = "nodetemplates/nodetemplates.metadatasets.update.json";
+    private static ToscaServiceTemplate toscaServiceTemplate;
+    private static ToscaServiceTemplate updatedToscaServiceTemplate;
+    private StandardCoder standardCoder;
+
+    @InjectMocks
+    private ToscaServiceTemplateService toscaServiceTemplateService;
+
+
+    @Before
+    public void setUp() {
+        super.setUp();
+    }
+
+    /**
+     * Fetch json files required for the tests.
+     *
+     * @throws CoderException when error parsing the json
+     */
+    @Before
+    public void fetchToscaNodeTemplateJson() throws CoderException {
+        standardCoder = new StandardCoder();
+        toscaServiceTemplate =
+            standardCoder.decode(ResourceUtils.getResourceAsString(NODE_TEMPLATES_JSON), ToscaServiceTemplate.class);
+        updatedToscaServiceTemplate =
+            standardCoder.decode(ResourceUtils.getResourceAsString(UPDATED_NODE_TEMPLATE_JSON),
+                ToscaServiceTemplate.class);
+    }
+
+    @Test
+    public void testToscaNodeTemplatesGet() throws Exception {
+
+        assertNotNull(toscaServiceTemplate);
+        var createdTemplate = toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate);
+        mockDbServiceTemplate(createdTemplate, null, null);
+
+        //Fetch all node templates if id is null
+        List<ToscaNodeTemplate> gotToscaNodeTemplates = toscaServiceTemplateService
+            .fetchToscaNodeTemplates(null, null);
+        assertEquals(3, gotToscaNodeTemplates.size());
+
+        // Get filtered node templates
+        List<ToscaNodeTemplate> filteredNodeTemplates = toscaServiceTemplateService
+            .fetchToscaNodeTemplates("apexMetadata_adaptive", "1.0.0");
+        assertEquals(1, filteredNodeTemplates.size());
+
+        //Get invalid node template
+        List<ToscaNodeTemplate> filteredNodeTemplatesInvalid = toscaServiceTemplateService
+            .fetchToscaNodeTemplates("invalidname", "1.0.0");
+        assertThat(filteredNodeTemplatesInvalid).isEmpty();
+    }
+
+    @Test
+    public void testToscaNodeTemplatesCreate() throws Exception {
+
+        assertThatThrownBy(() -> {
+            toscaServiceTemplateService.createToscaNodeTemplates(null);
+        }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
+
+        ToscaServiceTemplate createdNodeTemplates =
+            toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate);
+        assertThat(createdNodeTemplates.getToscaTopologyTemplate().getNodeTemplates()).hasSize(3);
+        assertThat(createdNodeTemplates.getToscaTopologyTemplate().getNodeTemplates().get("apexMetadata_grpc")
+            .getMetadata()).containsKey("threshold");
+    }
+
+    @Test
+    public void testToscaNodeTemplateUpdate() throws Exception {
+
+        assertThatThrownBy(() -> {
+            toscaServiceTemplateService.updateToscaNodeTemplates(null);
+        }).hasMessageMatching("^serviceTemplate is marked non-null but is null$");
+
+        JpaToscaNodeTemplate jpaNodeTemplate = new JpaToscaNodeTemplate();
+        PfConceptKey key = new PfConceptKey("apexMetadata_grpc", "1.0.0");
+        jpaNodeTemplate.setKey(key);
+        jpaNodeTemplate.setDescription("Updated Metadata set for GRPC");
+        ToscaServiceTemplate updatedTemplate =
+            toscaServiceTemplateService.updateToscaNodeTemplates(updatedToscaServiceTemplate);
+        assertEquals("Updated Metadata set for GRPC",
+            updatedTemplate.getToscaTopologyTemplate().getNodeTemplates().get("apexMetadata_grpc")
+                .getDescription());
+    }
+
+    @Test
+    public void testToscaNodeTemplateDelete() throws Exception {
+
+        assertThatThrownBy(() -> {
+            toscaServiceTemplateService.deleteToscaNodeTemplate(null, null);
+        }).hasMessageMatching("^name is marked .*on.*ull but is null$");
+
+        assertThatThrownBy(() -> {
+            toscaServiceTemplateService.deleteToscaNodeTemplate("name", null);
+        }).hasMessageMatching("^version is marked .*on.*ull but is null$");
+
+        var createdTemplate = toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate);
+        mockDbServiceTemplate(createdTemplate, null, null);
+        assertThatThrownBy(() -> {
+            toscaServiceTemplateService.deleteToscaNodeTemplate("dummyname", "1.0.1");
+        }).hasMessage("node template dummyname:1.0.1 not found");
+
+        ToscaServiceTemplate responseTemplate =
+            toscaServiceTemplateService.deleteToscaNodeTemplate("apexMetadata_decisionMaker", "1.0.0");
+
+        assertTrue(responseTemplate.getToscaTopologyTemplate().getNodeTemplates()
+            .containsKey("apexMetadata_decisionMaker"));
+        assertThat(responseTemplate.getToscaTopologyTemplate().getNodeTemplates()).hasSize(1);
+
+        assertThat(toscaServiceTemplateService.fetchToscaNodeTemplates(null, null)).hasSize(2);
+    }
+
+}
index 6ed69ea..f47873b 100644 (file)
@@ -11,12 +11,3 @@ spring:
       naming:
         physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
         implicit-strategy: org.onap.policy.common.spring.utils.CustomImplicitNamingStrategy
-
-database:
-  name: PolicyProviderParameterGroup
-  implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
-  driver: org.h2.Driver
-  url: jdbc:h2:mem:testdb
-  user: policy_user
-  password: policy_user
-  persistenceUnit: ToscaConceptTest
\ No newline at end of file
diff --git a/main/src/test/resources/nodetemplates/dummy.apex.decisionmaker.policy.yaml b/main/src/test/resources/nodetemplates/dummy.apex.decisionmaker.policy.yaml
new file mode 100644 (file)
index 0000000..c2e96b5
--- /dev/null
@@ -0,0 +1,14 @@
+---
+# Representation of apex decision maker policy with metadataSet reference in the metadata field.
+
+tosca_definitions_version: tosca_simple_yaml_1_1_0
+topology_template:
+  policies:
+    - operational.apex.decisionMaker:
+        type: onap.policies.Test
+        type_version: 1.0.0
+        name: operational.apex.decisionMaker
+        version: 1.0.0
+        metadata:
+          metadataSetName: apexMetadata_decisionMaker
+          metadataSetVersion:  1.0.0
\ No newline at end of file
index 767f1fb..c6aa65b 100644 (file)
@@ -13,7 +13,7 @@
         "version": "1.0.0",
         "type": "org.onap.nodetypes.policy.MetadataSet",
         "type_version": "1.0.0",
-        "description": "Metadata set for GRPC",
+        "description": "Updated Metadata set for GRPC",
         "metadata": {
           "policyModel": {
             "key": {
index fcb6d9f..2c19199 100644 (file)
@@ -25,15 +25,6 @@ policy-api:
   name: ApiGroup
   aaf: false
 
-database:
-  name: PolicyProviderParameterGroup
-  implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
-  driver: org.mariadb.jdbc.Driver
-  url: jdbc:mariadb://mariadb:3306/policyadmin
-  user: policy_user
-  password: policy_user
-  persistenceUnit: PolicyDb
-
 policy-preload:
   policyTypes:
     - policytypes/onap.policies.monitoring.tcagen2.yaml
index 59e6fc4..c463ac6 100644 (file)
@@ -8,15 +8,6 @@
         "https": true,
         "aaf": false
     },
-    "databaseProviderParameters": {
-        "name": "PolicyProviderParameterGroup",
-        "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
-        "databaseDriver": "org.mariadb.jdbc.Driver",
-        "databaseUrl": "jdbc:mariadb://mariadb:3306/policyadmin",
-        "databaseUser": "policy_user",
-        "databasePassword": "policy_user",
-        "persistenceUnit": "PolicyDb"
-    },
     "preloadPolicyTypes": [
         "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml",
         "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",