Separate ncmp south-bound endpoints in openapi specs 77/124677/8
authorRenu Kumari <renu.kumari@bell.ca>
Tue, 5 Oct 2021 00:59:18 +0000 (20:59 -0400)
committerRenu Kumari <renu.kumari@bell.ca>
Thu, 7 Oct 2021 18:05:22 +0000 (14:05 -0400)
- existing ncmp-cps swagger ui shows only northbound endpoints
- added cps-ncmp-internal for southbound endpoints

Issue-ID: CPS-722
Signed-off-by: Renu Kumari <renu.kumari@bell.ca>
Change-Id: I6917a9c1cf6d033f7ed76f2172113d5e43ac84a7

12 files changed:
cps-application/src/main/resources/application.yml
cps-ncmp-rest/docs/openapi/ncmp-inventory.yml [new file with mode: 0755]
cps-ncmp-rest/docs/openapi/ncmp.yml [moved from cps-ncmp-rest/docs/openapi/ncmproxy.yml with 92% similarity]
cps-ncmp-rest/docs/openapi/openapi-inventory.yml [new file with mode: 0755]
cps-ncmp-rest/docs/openapi/openapi.yml
cps-ncmp-rest/pom.xml
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java [new file with mode: 0755]
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy [new file with mode: 0644]
cps-ncmp-rest/src/test/resources/application.yml
docker-compose/README.md

index 42addf1..6717d4e 100644 (file)
@@ -25,6 +25,7 @@ rest:
     api:\r
         cps-base-path: /cps/api\r
         ncmp-base-path: /ncmp\r
+        ncmp-inventory-base-path: /ncmpInventory\r
 \r
 spring:\r
     main:\r
@@ -93,10 +94,13 @@ springdoc:
               url: /api-docs/cps-core/openapi.yaml\r
             - name: cps-ncmp\r
               url: /api-docs/cps-ncmp/openapi.yaml\r
+            - name: cps-ncmp-inventory\r
+              url: /api-docs/cps-ncmp/openapi-inventory.yaml\r
+\r
 \r
 security:\r
     # comma-separated uri patterns which do not require authorization\r
-    permit-uri: /manage/**,/swagger-ui/**,/swagger-resources/**,/api-docs\r
+    permit-uri: /manage/**,/swagger-ui.html,/swagger-ui/**,/swagger-resources/**,/api-docs/**\r
     auth:\r
         username: ${CPS_USERNAME}\r
         password: ${CPS_PASSWORD}\r
diff --git a/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml b/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml
new file mode 100755 (executable)
index 0000000..b0a50aa
--- /dev/null
@@ -0,0 +1,40 @@
+#  ============LICENSE_START=======================================================
+#  Copyright (C) 2021 Bell Canada
+#  ================================================================================
+#  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=========================================================
+
+updateDmiRegistration:
+  post:
+    description: Register a DMI Plugin with any new, updated or removed CM Handles.
+    tags:
+      - network-cm-proxy-inventory
+    summary: DMI notifies NCMP of new CM Handles
+    operationId: updateDmiPluginRegistration
+    requestBody:
+      required: true
+      content:
+        application/json:
+          schema:
+            $ref: 'components.yaml#/components/schemas/RestDmiPluginRegistration'
+    responses:
+      201:
+        $ref: 'components.yaml#/components/responses/Created'
+      400:
+        $ref: 'components.yaml#/components/responses/BadRequest'
+      401:
+        $ref: 'components.yaml#/components/responses/Unauthorized'
+      403:
+        $ref: 'components.yaml#/components/responses/Forbidden'
similarity index 92%
rename from cps-ncmp-rest/docs/openapi/ncmproxy.yml
rename to cps-ncmp-rest/docs/openapi/ncmp.yml
index 5a45a5c..52245c3 100755 (executable)
@@ -1,6 +1,7 @@
 #  ============LICENSE_START=======================================================
 #  Copyright (C) 2021 Nordix Foundation
 #  Modifications Copyright (C) 2021 Pantheon.tech
+#  Modifications Copyright (C) 2021 Bell Canada
 #  ================================================================================
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
@@ -179,29 +180,6 @@ listNodeByCmHandleAndXpath:
       404:
         $ref: 'components.yaml#/components/responses/NotFound'
 
-updateDmiRegistration:
-  post:
-    description: Register a DMI Plugin with any new, updated or removed CM Handles.
-    tags:
-      - network-cm-proxy
-    summary: DMI notifies NCMP of new CM Handles
-    operationId: updateDmiPluginRegistration
-    requestBody:
-      required: true
-      content:
-        application/json:
-          schema:
-            $ref: 'components.yaml#/components/schemas/RestDmiPluginRegistration'
-    responses:
-      201:
-        $ref: 'components.yaml#/components/responses/Created'
-      400:
-        $ref: 'components.yaml#/components/responses/BadRequest'
-      401:
-        $ref: 'components.yaml#/components/responses/Unauthorized'
-      403:
-        $ref: 'components.yaml#/components/responses/Forbidden'
-
 getResourceDataForPassthroughOperational:
   get:
     tags:
diff --git a/cps-ncmp-rest/docs/openapi/openapi-inventory.yml b/cps-ncmp-rest/docs/openapi/openapi-inventory.yml
new file mode 100755 (executable)
index 0000000..ee09d05
--- /dev/null
@@ -0,0 +1,28 @@
+#  ============LICENSE_START=======================================================
+#  Copyright (C) 2021 Bell Canada
+#  ================================================================================
+#  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=========================================================
+
+openapi: 3.0.1
+info:
+  title: NCMP Inventory API
+  description: NCMP Inventory API
+  version: "1.0"
+servers:
+  - url: /ncmpInventory
+paths:
+  /v1/ch:
+    $ref: 'ncmp-inventory.yml#/updateDmiRegistration'
index 1620eba..69c2a11 100755 (executable)
@@ -27,25 +27,22 @@ servers:
   - url: /ncmp
 paths:
   /v1/cm-handles/{cm-handle}/node:
-    $ref: 'ncmproxy.yml#/nodeByCmHandleAndXpath'
+    $ref: 'ncmp.yml#/nodeByCmHandleAndXpath'
 
   /v1/cm-handles/{cm-handle}/list-node:
-    $ref: 'ncmproxy.yml#/listNodeByCmHandleAndXpath'
+    $ref: 'ncmp.yml#/listNodeByCmHandleAndXpath'
 
   /v1/cm-handles/{cm-handle}/nodes/query:
-    $ref: 'ncmproxy.yml#/nodesByCmHandleAndCpsPath'
+    $ref: 'ncmp.yml#/nodesByCmHandleAndCpsPath'
 
   /v1/cm-handles/{cm-handle}/nodes:
-    $ref: 'ncmproxy.yml#/nodesByCmHandleAndXpath'
-
-  /v1/ch:
-    $ref: 'ncmproxy.yml#/updateDmiRegistration'
+    $ref: 'ncmp.yml#/nodesByCmHandleAndXpath'
 
   /v1/ch/{cm-handle}/data/ds/ncmp-datastore:passthrough-operational:
-    $ref: 'ncmproxy.yml#/getResourceDataForPassthroughOperational'
+    $ref: 'ncmp.yml#/getResourceDataForPassthroughOperational'
 
   /v1/ch/{cm-handle}/data/ds/ncmp-datastore:passthrough-running:
-    $ref: 'ncmproxy.yml#/resourceDataForPassthroughRunning'
+    $ref: 'ncmp.yml#/resourceDataForPassthroughRunning'
 
   /v1/ch/{cm-handle}/modules:
-    $ref: 'ncmproxy.yml#/fetchModuleReferencesByCmHandle'
\ No newline at end of file
+    $ref: 'ncmp.yml#/fetchModuleReferencesByCmHandle'
\ No newline at end of file
index b47ea17..c4c72bb 100644 (file)
                 <artifactId>swagger-codegen-maven-plugin</artifactId>
                 <executions>
                     <execution>
-                        <id>code-gen</id>
+                        <id>ncmp-code-gen</id>
                         <goals>
                             <goal>generate</goal>
                         </goals>
                             </configOptions>
                         </configuration>
                     </execution>
+                    <execution>
+                        <id>ncmp-code-gen-inventory</id>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                        <configuration>
+                            <inputSpec>${project.basedir}/docs/openapi/openapi-inventory.yml</inputSpec>
+                            <invokerPackage>org.onap.cps.ncmp.rest.controller</invokerPackage>
+                            <modelPackage>org.onap.cps.ncmp.rest.model</modelPackage>
+                            <apiPackage>org.onap.cps.ncmp.rest.api</apiPackage>
+                            <language>spring</language>
+                            <generateSupportingFiles>false</generateSupportingFiles>
+                            <configOptions>
+                                <sourceFolder>src/gen/java</sourceFolder>
+                                <dateLibrary>java11</dateLibrary>
+                                <interfaceOnly>true</interfaceOnly>
+                                <useTags>true</useTags>
+                            </configOptions>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>ncmp-inventory-openapi-yaml-gen</id>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                        <phase>compile</phase>
+                        <configuration>
+                            <inputSpec>${project.basedir}/docs/openapi/openapi-inventory.yml</inputSpec>
+                            <language>openapi-yaml</language>
+                            <configOptions>
+                                <outputFile>openapi-inventory.yaml</outputFile>
+                            </configOptions>
+                        </configuration>
+                    </execution>
                 </executions>
             </plugin>
             <plugin>
                                 <resource>
                                     <directory>${project.basedir}/target/generated-sources/swagger/</directory>
                                     <includes>
-                                        <include>openapi.yaml</include>
+                                        <include>openapi*.yaml</include>
                                     </includes>
                                 </resource>
                             </resources>
index 4a9527a..9b15a78 100755 (executable)
@@ -3,6 +3,7 @@
  *  Copyright (C) 2021 Pantheon.tech
  *  Modifications (C) 2021 Nordix Foundation
  *  Modification Copyright (C) 2021 highstreet technologies GmbH
+ *  Modifications (C) 2021 Bell Canada
  *  ================================================================================
  *  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.cps.ncmp.rest.controller;
 
-
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import java.util.Collection;
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
-import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
 import org.onap.cps.spi.FetchDescendantsOption;
 import org.onap.cps.spi.model.DataNode;
 import org.onap.cps.spi.model.ModuleReference;
@@ -49,17 +46,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
 
     private final NetworkCmProxyDataService networkCmProxyDataService;
 
-    private final ObjectMapper objectMapper;
-
     /**
      * Constructor Injection for Dependencies.
      * @param networkCmProxyDataService Data Service Interface
-     * @param objectMapper Object Mapper
      */
-    public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService,
-        final ObjectMapper objectMapper) {
+    public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService) {
         this.networkCmProxyDataService = networkCmProxyDataService;
-        this.objectMapper = objectMapper;
     }
 
     /**
@@ -100,19 +92,6 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
         return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
     }
 
-    /**
-     * Update DMI Plugin Registration (used for first registration also).
-     * @param restDmiPluginRegistration the registration data
-     */
-    @Override
-    public ResponseEntity<Void> updateDmiPluginRegistration(
-        final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
-        final DmiPluginRegistration dmiPluginRegistration =
-            convertRestObjectToJavaApiObject(restDmiPluginRegistration);
-        networkCmProxyDataService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration);
-        return new ResponseEntity<>(HttpStatus.CREATED);
-    }
-
     /**
      * Query Data Nodes.
      * @deprecated This Method is no longer used as part of NCMP.
@@ -221,9 +200,4 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
         return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK);
     }
 
-    private DmiPluginRegistration convertRestObjectToJavaApiObject(
-        final RestDmiPluginRegistration restDmiPluginRegistration) {
-        return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);
-    }
-
 }
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
new file mode 100755 (executable)
index 0000000..3b72cec
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Bell Canada
+ *  ================================================================================
+ *  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.cps.ncmp.rest.controller;
+
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import javax.validation.Valid;
+import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
+import org.onap.cps.ncmp.rest.api.NetworkCmProxyInventoryApi;
+import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("${rest.api.ncmp-inventory-base-path}")
+public class NetworkCmProxyInventoryController implements NetworkCmProxyInventoryApi {
+
+    private final NetworkCmProxyDataService networkCmProxyDataService;
+    private final ObjectMapper objectMapper;
+
+    /**
+     * Constructor Injection for Dependencies.
+     * @param networkCmProxyDataService Data Service Interface
+     * @param objectMapper Object Mapper
+     */
+    public NetworkCmProxyInventoryController(final NetworkCmProxyDataService networkCmProxyDataService,
+        final ObjectMapper objectMapper) {
+        this.networkCmProxyDataService = networkCmProxyDataService;
+        this.objectMapper = objectMapper;
+    }
+
+    /**
+     * Update DMI Plugin Registration (used for first registration also).
+     * @param restDmiPluginRegistration the registration data
+     */
+    @Override
+    public ResponseEntity<Void> updateDmiPluginRegistration(
+        final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
+        final DmiPluginRegistration dmiPluginRegistration =
+            convertRestObjectToJavaApiObject(restDmiPluginRegistration);
+        networkCmProxyDataService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration);
+        return new ResponseEntity<>(HttpStatus.CREATED);
+    }
+
+    private DmiPluginRegistration convertRestObjectToJavaApiObject(
+        final RestDmiPluginRegistration restDmiPluginRegistration) {
+        return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);
+    }
+
+}
index b8c68d9..342f41b 100644 (file)
@@ -31,9 +31,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
 
-import com.fasterxml.jackson.databind.ObjectMapper
 import com.google.gson.Gson
-import org.onap.cps.TestUtils
 import org.onap.cps.ncmp.api.NetworkCmProxyDataService
 import org.onap.cps.spi.model.DataNodeBuilder
 import org.spockframework.spring.SpringBean
@@ -54,9 +52,6 @@ class NetworkCmProxyControllerSpec extends Specification {
     @SpringBean
     NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
 
-    @SpringBean
-    ObjectMapper objectMapper = new ObjectMapper()
-
     @Value('${rest.api.ncmp-base-path}/v1')
     def ncmpBasePathV1
 
@@ -175,21 +170,6 @@ class NetworkCmProxyControllerSpec extends Specification {
             response.contentAsString.contains('"leaf":"value"')
     }
 
-    def 'Register CM Handle Event' () {
-        given: 'jsonData'
-            def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
-        when: 'post request is performed'
-            def response = mvc.perform(
-                post("$ncmpBasePathV1/ch")
-                .contentType(MediaType.APPLICATION_JSON)
-                .content(jsonData)
-            ).andReturn().response
-        then: 'the cm handles are registered with the service'
-            1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(_)
-        and: 'response status is created'
-            response.status == HttpStatus.CREATED.value()
-    }
-
     def 'Get Resource Data from pass-through operational.' () {
         given: 'resource data url'
             def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" +
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy
new file mode 100644 (file)
index 0000000..e558ac4
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Bell Canada
+ *  ================================================================================
+ *  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.cps.ncmp.rest.controller
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.cps.TestUtils
+import org.onap.cps.ncmp.api.NetworkCmProxyDataService
+import org.spockframework.spring.SpringBean
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
+import org.springframework.context.annotation.Import
+import org.springframework.http.HttpStatus
+import org.springframework.http.MediaType
+import org.springframework.test.web.servlet.MockMvc
+import spock.lang.Specification
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
+
+@WebMvcTest(NetworkCmProxyInventoryController)
+@Import(ObjectMapper)
+class NetworkCmProxyInventoryControllerSpec extends Specification {
+
+    @Autowired
+    MockMvc mvc
+
+    @SpringBean
+    NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
+
+    @Value('${rest.api.ncmp-inventory-base-path}/v1')
+    def ncmpBasePathV1
+
+    def 'Register CM Handle Event' () {
+        given: 'jsonData'
+            def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
+        when: 'post request is performed'
+            def response = mvc.perform(
+                post("$ncmpBasePathV1/ch")
+                .contentType(MediaType.APPLICATION_JSON)
+                .content(jsonData)
+            ).andReturn().response
+        then: 'the cm handles are registered with the service'
+            1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(_)
+        and: 'response status is created'
+            response.status == HttpStatus.CREATED.value()
+    }
+
+}
+
index 848738a..f2ca8c7 100644 (file)
@@ -20,4 +20,4 @@
 rest:
     api:
         ncmp-base-path: /ncmp
-spring:
+        ncmp-inventory-base-path: /ncmpInventory
index ae26868..3e6ab83 100644 (file)
@@ -106,6 +106,7 @@ Swagger UI and Open API specifications are available to discover service endpoin
 * `http://localhost:<port-number>/swagger-ui.html`
 * `http://localhost:<port-number>/api-docs/cps-core/openapi.yaml`
 * `http://localhost:<port-number>/api-docs/cps-ncmp/openapi.yaml`
+* `http://localhost:<port-number>/api-docs/cps-ncmp/openapi-inventory.yaml`
 
 with <port-number> being either `8080` if running the plain Java build or retrieved using following command
 if running from `docker-compose`: