Merge "Simulator updates"
authorJohn Keeney <John.Keeney@est.tech>
Fri, 1 Nov 2019 09:24:02 +0000 (09:24 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Fri, 1 Nov 2019 09:24:02 +0000 (09:24 +0000)
14 files changed:
sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/.gitignore [deleted file]
sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/README.md [deleted file]
sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/pom.xml [deleted file]
sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/src/main/resources/a1_mediator_0.11.0.yaml [deleted file]
sdnc-a1-controller/northbound/nonrt-ric-api/features/sdnc-nonrt-ric-api/pom.xml
sdnc-a1-controller/northbound/nonrt-ric-api/model/src/main/yang/NONRT-RIC-API.yang
sdnc-a1-controller/northbound/nonrt-ric-api/pom.xml
sdnc-a1-controller/northbound/nonrt-ric-api/provider/pom.xml
sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/provider/NonrtRicApiProvider.java
sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java
sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapter.java
sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapterImpl.java
sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/resources/NearRtRicList.properties [new file with mode: 0644]
sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/test/java/org/onap/sdnc/northbound/NonrtRicApiProviderTest.java

diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/.gitignore b/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/.gitignore
deleted file mode 100644 (file)
index 27fd461..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-*.class
-
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.ear
-
-# exclude jar for gradle wrapper
-!gradle/wrapper/*.jar
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
-
-# build files
-**/target
-target
-.gradle
-build
-
-logs/
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/README.md b/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/README.md
deleted file mode 100644 (file)
index d5780ff..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-# A1 Mediator Client Generator
-
-This projects generates a REST client library from the OpenAPI specification
-file stored here and packages it in a jar.
-
-## Eclipse and STS Users
-
-The Swagger Codegen maven plugin is not supported in Eclipse/STS. You can
-limp along by taking these steps:
-
-1. Generate the code using maven:
-    mvn install
-2. Add this folder to the project build path:
-    target/generated-sources/swagger/src/main/java
-
-## License
-
-Copyright (C) 2019 AT&T Intellectual Property & Nokia. 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.
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/pom.xml
deleted file mode 100644 (file)
index f0718bf..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ============LICENSE_START=======================================================
-   Copyright (C) 2019-2020 Nordix Foundation.
-  ================================================================================
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-  SPDX-License-Identifier: Apache-2.0
-  ============LICENSE_END=========================================================
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-       <modelVersion>4.0.0</modelVersion>
-
-       <parent>
-               <groupId>org.onap.ccsdk.parent</groupId>
-               <artifactId>binding-parent</artifactId>
-               <version>1.4.3</version>
-               <relativePath />
-       </parent>
-
-       <groupId>org.onap.sdnc.northbound</groupId>
-       <artifactId>nonrt-ric-api-a1-client</artifactId>
-       <version>1.7.3-SNAPSHOT</version>
-       <packaging>bundle</packaging>
-
-       <name>sdnc-northbound :: nonrt-ric-api :: ${project.artifactId}</name>
-
-       <properties>
-               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-               <client.base.package.name>org.oransc.ric.a1med.client</client.base.package.name>
-       </properties>
-
-       <dependencies>
-               <dependency>
-                       <groupId>io.swagger.core.v3</groupId>
-                       <artifactId>swagger-annotations</artifactId>
-                       <version>2.0.8</version>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>org.springframework</groupId>
-                       <artifactId>spring-context</artifactId>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>org.springframework</groupId>
-                       <artifactId>spring-web</artifactId>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>com.fasterxml.jackson.core</groupId>
-                       <artifactId>jackson-core</artifactId>
-                       <version>2.9.0</version>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>com.fasterxml.jackson.core</groupId>
-                       <artifactId>jackson-annotations</artifactId>
-                       <version>2.9.0</version>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>com.fasterxml.jackson.core</groupId>
-                       <artifactId>jackson-databind</artifactId>
-                       <version>2.9.0</version>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>com.fasterxml.jackson.jaxrs</groupId>
-                       <artifactId>jackson-jaxrs-json-provider</artifactId>
-                       <version>2.9.0</version>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>com.fasterxml.jackson.datatype</groupId>
-                       <artifactId>jackson-datatype-jsr310</artifactId>
-                       <version>2.9.0</version>
-                       <scope>provided</scope>
-               </dependency>
-       </dependencies>
-       <build>
-               <plugins>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-compiler-plugin</artifactId>
-                       </plugin>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-dependency-plugin</artifactId>
-                               <configuration>
-                                       <includeGroupIds>org.onap.sdnc.northbound</includeGroupIds>
-                               </configuration>
-                       </plugin>
-                       <plugin>
-                               <groupId>org.apache.felix</groupId>
-                               <artifactId>maven-bundle-plugin</artifactId>
-                               <version>3.0.1</version>
-                               <extensions>true</extensions>
-                               <configuration>
-                                       <instructions>
-                                               <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
-                                               <Bundle-Version>${project.version}</Bundle-Version>
-                                               <Export-Package>*</Export-Package>
-                                               <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
-                                               <Embed-Transitive>true</Embed-Transitive>
-                                               <Embed-Directory>target/dependency</Embed-Directory>
-                                               <Import-Package>*;resolution:=optional</Import-Package>
-                                               <Spring-Context>*</Spring-Context>
-                                       </instructions>
-                               </configuration>
-                       </plugin>
-                       <plugin>
-                               <groupId>io.swagger.codegen.v3</groupId>
-                               <artifactId>swagger-codegen-maven-plugin</artifactId>
-                               <version>3.0.8</version>
-                               <executions>
-                                       <execution>
-                                               <goals>
-                                                       <goal>generate</goal>
-                                               </goals>
-                                               <configuration>
-                                                       <inputSpec>${project.basedir}/src/main/resources/a1_mediator_0.11.0.yaml</inputSpec>
-                                                       <language>java</language>
-                                                       <configOptions>
-                                                               <packageName>${client.base.package.name}</packageName>
-                                                               <modelPackage>${client.base.package.name}.model</modelPackage>
-                                                               <apiPackage>${client.base.package.name}.api</apiPackage>
-                                                               <invokerPackage>${client.base.package.name}.invoker</invokerPackage>
-                                                               <groupId>${project.groupId}</groupId>
-                                                               <artifactId>${project.artifactId}</artifactId>
-                                                               <artifactVersion>${project.version}</artifactVersion>
-                                                               <library>resttemplate</library>
-                                                               <java8>true</java8>
-                                                               <output>${project.build.directory}/generated-sources/swagger</output>
-                                                               <generateApis>false</generateApis>
-                                                               <generateApiTests>false</generateApiTests>
-                                                               <generateModels>true</generateModels>
-                                                               <generateModelTests>false</generateModelTests>
-                                                               <generateSupportingFiles>true</generateSupportingFiles>
-                                                               <sourceFolder>src/main/java</sourceFolder>
-                                                               <dateLibrary>java8</dateLibrary>
-                                                               <licenseName>Apache 2.0</licenseName>
-                                                               <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
-                                                       </configOptions>
-                                               </configuration>
-                                       </execution>
-                               </executions>
-                       </plugin>
-               </plugins>
-               <pluginManagement>
-                       <plugins>
-                               <!--This plugin's configuration is used to store Eclipse m2e settings 
-                                       only. It has no influence on the Maven build itself. -->
-                               <plugin>
-                                       <groupId>org.eclipse.m2e</groupId>
-                                       <artifactId>lifecycle-mapping</artifactId>
-                                       <version>1.0.0</version>
-                                       <configuration>
-                                               <lifecycleMappingMetadata>
-                                                       <pluginExecutions>
-                                                               <pluginExecution>
-                                                                       <pluginExecutionFilter>
-                                                                               <groupId>io.swagger.codegen.v3</groupId>
-                                                                               <artifactId>swagger-codegen-maven-plugin</artifactId>
-                                                                               <versionRange>[1.0,)</versionRange>
-                                                                               <goals>
-                                                                                       <goal>generate</goal>
-                                                                               </goals>
-                                                                       </pluginExecutionFilter>
-                                                                       <action>
-                                                                               <ignore />
-                                                                       </action>
-                                                               </pluginExecution>
-                                                       </pluginExecutions>
-                                               </lifecycleMappingMetadata>
-                                       </configuration>
-                               </plugin>
-                       </plugins>
-               </pluginManagement>
-       </build>
-</project>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/src/main/resources/a1_mediator_0.11.0.yaml b/sdnc-a1-controller/northbound/nonrt-ric-api/a1-client/src/main/resources/a1_mediator_0.11.0.yaml
deleted file mode 100644 (file)
index b8b8f91..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-# ==================================================================================
-#       Copyright (c) 2019 Nokia
-#       Copyright (c) 2018-2019 AT&T Intellectual Property.
-#
-#   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.
-# ==================================================================================
-openapi: 3.0.0
-info:
-  version: 0.11.0
-  title: RIC A1
-paths:
-  '/a1-p/healthcheck':
-    get:
-      description: >
-        Perform a healthcheck on a1
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.get_healthcheck
-      responses:
-        200:
-          description: >
-            A1 is healthy.
-            Anything other than a 200 should be considered a1 as failing
-
-  '/a1-p/policytypes/':
-    get:
-      description: "Get a list of all registered policy type ids"
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.get_all_policy_types
-      responses:
-        200:
-          description: "list of all registered policy type ids"
-          content:
-            application/json:
-              schema:
-                type: array
-                items:
-                  "$ref": "#/components/schemas/policy_type_id"
-              example: [20000, 20020]
-
-  '/a1-p/policytypes/{policy_type_id}':
-    parameters:
-      - name: policy_type_id
-        in: path
-        required: true
-        schema:
-          "$ref": "#/components/schemas/policy_type_id"
-    get:
-      description: >
-        Get this policy type
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.get_policy_type
-      responses:
-        '200':
-          description: "policy type successfully found"
-          content:
-            application/json:
-              schema:
-                "$ref": "#/components/schemas/policy_type_schema"
-        '404':
-          description: >
-            policy type not found
-    delete:
-      description: >
-        Delete this policy type. Can only be performed if there are no instances of this type
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.delete_policy_type
-      responses:
-        '204':
-          description: >
-            policy type successfully deleted
-        '400':
-          description: >
-            Policy type cannot be deleted because there are instances
-            All instances must be removed before a policy type can be deleted
-        '404':
-          description: >
-            policy type not found
-    put:
-      description: >
-        Create a new policy type .
-        Replace is not currently allowed; to replace, for now do a DELETE and then a PUT again.
-
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.create_policy_type
-      requestBody:
-        content:
-          application/json:
-            schema:
-               "$ref": "#/components/schemas/policy_type_schema"
-            example:
-              name: admission_control_policy
-              description: various parameters to control admission of dual connection
-              policy_type_id: 20000
-              create_schema:
-                $schema: 'http://json-schema.org/draft-07/schema#'
-                type: object
-                properties:
-                  enforce:
-                    type: boolean
-                    default: true
-                  window_length:
-                    type: integer
-                    default: 1
-                    minimum: 1
-                    maximum: 60
-                    description: Sliding window length (in minutes)
-                  blocking_rate:
-                    type: number
-                    default: 10
-                    minimum: 1
-                    maximum: 100
-                    description: '% Connections to block'
-                  trigger_threshold:
-                    type: integer
-                    default: 10
-                    minimum: 1
-                    description: Minimum number of events in window to trigger blocking
-                additionalProperties: false
-
-      responses:
-        '201':
-          description: "policy type successfully created"
-        '400':
-          description: "illegal ID, or object already existed"
-
-  '/a1-p/policytypes/{policy_type_id}/policies':
-    parameters:
-      - name: policy_type_id
-        in: path
-        required: true
-        schema:
-          "$ref": "#/components/schemas/policy_type_id"
-    get:
-      description: "get a list of all policy instance ids for this policy type id"
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.get_all_instances_for_type
-      responses:
-        200:
-          description: "list of all policy instance ids for this policy type id"
-          content:
-            application/json:
-              schema:
-                type: array
-                items:
-                  "$ref": "#/components/schemas/policy_instance_id"
-              example: ["3d2157af-6a8f-4a7c-810f-38c2f824bf12", "06911bfc-c127-444a-8eb1-1bffad27cc3d"]
-
-
-  '/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}':
-    parameters:
-      - name: policy_type_id
-        in: path
-        required: true
-        schema:
-          "$ref": "#/components/schemas/policy_type_id"
-
-      - name: policy_instance_id
-        in: path
-        required: true
-        schema:
-          "$ref": "#/components/schemas/policy_instance_id"
-
-    get:
-      description: >
-        Retrieve the policy instance
-
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.get_policy_instance
-      responses:
-        '200':
-          description: >
-            The policy instance.
-            the schema of this object is defined by the create_schema field of the policy type
-          content:
-            application/json:
-              schema:
-                type: object
-        '404':
-          description: >
-            there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id
-
-    delete:
-      description: >
-        Delete this policy instance
-
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.delete_policy_instance
-      responses:
-        '204':
-          description: >
-            policy instance successfully deleted
-        '404':
-          description: >
-            there is no policy instance with this policy_instance_id
-            or there is no policy type with this policy_type_id
-
-    put:
-      description: >
-        Create or replace a policy instance of type policy_type_id.
-        The schema of the PUT body is defined by the create_schema field of the policy type.
-
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.create_or_replace_policy_instance
-      requestBody:
-        content:
-          application/json:
-            schema:
-              type: object
-              description: >
-                  the schema of this object is defined by the create_schema field of the policy type
-            example:
-              enforce: true
-              window_length: 10
-              blocking_rate: 20
-              trigger_threshold: 10
-
-      responses:
-        '201':
-          description: >
-            Policy instance created
-        '400':
-          description: >
-            Bad PUT body for this policy instance
-        '404':
-          description: >
-            There is no policy type with this policy_type_id
-
-  '/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status':
-    parameters:
-      - name: policy_type_id
-        in: path
-        required: true
-        schema:
-          "$ref": "#/components/schemas/policy_type_id"
-
-      - name: policy_instance_id
-        in: path
-        required: true
-        schema:
-          "$ref": "#/components/schemas/policy_instance_id"
-
-    get:
-      description: >
-        Retrieve the policy instance status across all handlers of the policy
-
-      tags:
-        - A1 Mediator
-      operationId: a1.controller.get_policy_instance_status
-      responses:
-        '200':
-          description: >
-            The policy instance status.
-            Returns a vector of statuses, where each contains a handler_id (opaque id of a RIC component that implements this policy) and the policy status as returned by that handler
-          content:
-            application/json:
-              schema:
-                type: array
-                items:
-                  type: object
-                  properties:
-                    handler_id:
-                      type: string
-                    status:
-                      type: string
-              example:
-                [{"handler_id": "1234-5678", "status" : "OK"}, {"handler_id": "abc-def", "status" : "NOT IMPLEMENTED"}]
-        '404':
-          description: >
-            there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id
-
-
-components:
-  schemas:
-    policy_type_schema:
-      type: object
-      required:
-      - name
-      - description
-      - policy_type_id
-      - create_schema
-      additionalProperties: false
-      properties:
-        name:
-          type: string
-          description: name of the policy type
-        description:
-          type: string
-          description: description of the policy type
-        policy_type_id:
-          description: the integer of the policy type
-          type: integer
-        create_schema:
-          type: object
-          description: >
-            jsonschema (following http://json-schema.org/draft-07/schema) of the CREATE payload to be sent to handlers of this policy
-
-    policy_type_id:
-      description: >
-        represents a policy type identifier. Currently this is restricted to an integer range.
-      type: integer
-      minimum: 20000
-      maximum: 21024
-
-    policy_instance_id:
-      description: >
-        represents a policy instance identifier. UUIDs are advisable but can be any string
-      type: string
-      example: "3d2157af-6a8f-4a7c-810f-38c2f824bf12"
-
-    downstream_message_schema:
-      type: object
-      required:
-        - operation
-        - policy_type_id
-        - policy_instance_id
-        - payload
-      additionalProperties: false
-      properties:
-        operation:
-          description: the operation being performed
-          type: string
-          enum:
-            - CREATE
-            - DELETE
-            - UPDATE
-            - READ
-        policy_type_id:
-          "$ref": "#/components/schemas/policy_type_id"
-        policy_instance_id:
-          "$ref": "#/components/schemas/policy_instance_id"
-        payload:
-          description: payload for this operation
-          type: object
-      example:
-        operation: CREATE
-        policy_type_id: 12345678
-        policy_instance_id: 3d2157af-6a8f-4a7c-810f-38c2f824bf12
-        payload:
-          enforce: true
-          window_length: 10
-          blocking_rate: 20
-          trigger_threshold: 10
-
-    downstream_notification_schema:
-      type: object
-      required:
-        - policy_type_id
-        - policy_instance_id
-        - handler_id
-        - status
-      additionalProperties: false
-      properties:
-        policy_type_id:
-          "$ref": "#/components/schemas/policy_type_id"
-        policy_instance_id:
-          "$ref": "#/components/schemas/policy_instance_id"
-        handler_id:
-          description: >
-            id of the policy handler
-          type: string
-        status:
-          description: >
-            the status of this policy instance in this handler
-          type: string
-      example:
-        policy_type_id: 12345678
-        policy_instance_id: 3d2157af-6a8f-4a7c-810f-38c2f824bf12
-        handler_id: 1234-5678
-        status: OK
index f6a6748..d18f0a9 100644 (file)
             <artifactId>nonrt-ric-api-model</artifactId>
             <version>${project.version}</version>
         </dependency>
-               <dependency>
-                       <groupId>${project.groupId}</groupId>
-                       <artifactId>nonrt-ric-api-a1-client</artifactId>
-                       <version>${project.version}</version>
-               </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>nonrt-ric-api-provider</artifactId>
index b6a2869..806bdc1 100644 (file)
@@ -15,8 +15,8 @@ module A1-ADAPTER-API {
 \r
 ///Flattend interface using RPC\r
 \r
-    //Get a comma separated list of near-rt rics, e.g. domain-name1:port1,domainname2:port2\r
-    //Each item in the returned list will be regarded as one near-rt-ric-id.\r
+    //Get an array of near-rt-ric IDs,\r
+    //Each item in the returned array will be regarded as one near-rt-ric-id.\r
     rpc getNearRT-RICs {\r
         output {\r
             leaf-list near-rt-ric-id-list {\r
@@ -37,11 +37,11 @@ module A1-ADAPTER-API {
             leaf health-status {\r
                 type boolean;\r
             }\r
-        }   \r
+        }\r
     }\r
 \r
-    //Get a comma separated list of integer policy type ids\r
-    //Each item in the returned list will be regarded as one policy-type-id.\r
+    //Get an array of integer policy type ids\r
+    //Each item in the returned array will be regarded as one policy-type-id.\r
     rpc getPolicyTypes {\r
         input {\r
             leaf near-rt-ric-id {\r
@@ -120,8 +120,8 @@ module A1-ADAPTER-API {
         }\r
     }\r
 \r
-    //Get a comma separeated list of string policy instance ids\r
-    //Each item in the returned list will be regarded as one policy-instance-id.\r
+    //Get an array of string policy instance ids\r
+    //Each item in the returned array will be regarded as one policy-instance-id.\r
     rpc getPolicyInstances {\r
         input {\r
             leaf near-rt-ric-id {\r
@@ -156,7 +156,7 @@ module A1-ADAPTER-API {
             }\r
         }\r
     }\r
-    \r
+\r
     ///Get a policy instance\r
     rpc getPolicyInstance {\r
         input {\r
@@ -176,7 +176,7 @@ module A1-ADAPTER-API {
             }\r
         }\r
     }\r
-    \r
+\r
     //Delete a policy instance\r
     rpc deletePolicyInstance {\r
         input {\r
index fe26d12..0635dec 100644 (file)
@@ -37,7 +37,6 @@
 
        <name>sdnc-northbound :: nonrt-ric-api</name>
        <modules>
-               <module>a1-client</module>
                <module>model</module>
                <module>provider</module>
                <module>features</module>
index 21aef79..51bcfe7 100644 (file)
             <version>${project.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.onap.sdnc.northbound</groupId>
-            <artifactId>nonrt-ric-api-a1-client</artifactId>
-            <version>${project.version}</version>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-web</artifactId>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
             <version>1.10.19</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+        </dependency>
     </dependencies>
 </project>
index 206b096..66af597 100644 (file)
 
 package org.onap.sdnc.northbound.provider;
 
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.TimeZone;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import org.apache.commons.lang3.StringUtils;
+import org.json.JSONObject;
 import org.onap.sdnc.northbound.restadpter.NearRicUrlProvider;
 import org.onap.sdnc.northbound.restadpter.RestAdapter;
 import org.onap.sdnc.northbound.restadpter.RestAdapterImpl;
@@ -56,6 +61,7 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev19100
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckOutputBuilder;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsInput;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsOutput;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsOutputBuilder;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceInput;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceOutput;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceOutputBuilder;
@@ -73,22 +79,17 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev19100
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusOutputBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.oransc.ric.a1med.client.model.PolicyTypeSchema;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
 
 /**
  * Defines a base implementation for your provider. This class overrides the generated interface
  * from the YANG model and implements the request model for the A1 interface. This class identifies
  * the Near-RIC throught the IP passed over the payload and calls the corresponding Near-RIC over
  * Rest API
- * 
+ *
  * <pre>
- * 
+ *
  * @author lathishbabu.ganesan@est.tech
  *
  */
@@ -199,12 +200,13 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
   @Override
   public ListenableFuture<RpcResult<CreatePolicyInstanceOutput>> createPolicyInstance(
       CreatePolicyInstanceInput input) {
-    log.debug("Start of createPolicyInstance");
-    String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getPolicyTypeId()),
-        String.valueOf(input.getPolicyInstanceId()));
+    log.info("Start of createPolicyInstance");
+    String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getNearRtRicId()),
+            String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId()));
+    log.info("PUT Request input.getPolicyInstance() : {} ", input.getPolicyInstance());
     restAdapter.put(uri, input.getPolicyInstance());
     CreatePolicyInstanceOutputBuilder responseBuilder = new CreatePolicyInstanceOutputBuilder();
-    log.debug("End of createPolicyInstance");
+    log.info("End of createPolicyInstance");
     RpcResult<CreatePolicyInstanceOutput> rpcResult = RpcResultBuilder
         .<CreatePolicyInstanceOutput>status(true).withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -213,14 +215,15 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
   @Override
   public ListenableFuture<RpcResult<CreatePolicyTypeOutput>> createPolicyType(
       CreatePolicyTypeInput input) {
-    log.debug("Start of createPolicyType");
-    String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getPolicyTypeId()));
-    PolicyTypeSchema policyTypeSchema = new PolicyTypeSchema();
-    restAdapter.put(uri, policyTypeSchema);
+    log.info("Start of createPolicyType");
+    String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getNearRtRicId()),
+            String.valueOf(input.getPolicyTypeId()));
+    log.info("PUT Request input.getPolicyType() : {} ", input.getPolicyType());
+    restAdapter.put(uri, input.getPolicyType());
     CreatePolicyTypeOutputBuilder responseBuilder = new CreatePolicyTypeOutputBuilder();
     responseBuilder.setCode(RESPONSE_CODE_SUCCESS);
     responseBuilder.setStatus(RESPONSE_SUCCESS);
-    log.debug("End of createPolicyType");
+    log.info("End of createPolicyType");
     RpcResult<CreatePolicyTypeOutput> rpcResult = RpcResultBuilder
         .<CreatePolicyTypeOutput>status(true).withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -229,12 +232,12 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
   @Override
   public ListenableFuture<RpcResult<DeletePolicyInstanceOutput>> deletePolicyInstance(
       DeletePolicyInstanceInput input) {
-    log.debug("Start of deletePolicyInstance");
-    String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getPolicyTypeId()),
-        String.valueOf(input.getPolicyInstanceId()));
+    log.info("Start of deletePolicyInstance");
+    String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getNearRtRicId()),
+            String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId()));
     restAdapter.delete(uri);
     DeletePolicyInstanceOutputBuilder responseBuilder = new DeletePolicyInstanceOutputBuilder();
-    log.debug("End of deletePolicyInstance");
+    log.info("End of deletePolicyInstance");
     RpcResult<DeletePolicyInstanceOutput> rpcResult = RpcResultBuilder
         .<DeletePolicyInstanceOutput>status(true).withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -243,11 +246,12 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
   @Override
   public ListenableFuture<RpcResult<DeletePolicyTypeOutput>> deletePolicyType(
       DeletePolicyTypeInput input) {
-    log.debug("Start of deletePolicyType");
-    String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getPolicyTypeId()));
+    log.info("Start of deletePolicyType");
+    String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getNearRtRicId()),
+            String.valueOf(input.getPolicyTypeId()));
     restAdapter.delete(uri);
     DeletePolicyTypeOutputBuilder responseBuilder = new DeletePolicyTypeOutputBuilder();
-    log.debug("End of deletePolicyType");
+    log.info("End of deletePolicyType");
     RpcResult<DeletePolicyTypeOutput> rpcResult = RpcResultBuilder
         .<DeletePolicyTypeOutput>status(true).withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -256,14 +260,12 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
   @Override
   public ListenableFuture<RpcResult<GetHealthCheckOutput>> getHealthCheck(
       GetHealthCheckInput input) {
-    log.debug("Start of getHealthCheck");
-    String uri = nearRicUrlProvider.getHealthCheck();
-    Optional<String> heathCheckStatus = restAdapter.get(uri, String.class);
+    log.info("Start of getHealthCheck");
+    String uri = nearRicUrlProvider.getHealthCheck(String.valueOf(input.getNearRtRicId()));
+    restAdapter.get(uri, String.class);
     GetHealthCheckOutputBuilder responseBuilder = new GetHealthCheckOutputBuilder();
-    if (heathCheckStatus.get().equals("")) {
-      responseBuilder.setHealthStatus(true);
-    }
-    log.debug("End of getHealthCheck");
+    responseBuilder.setHealthStatus(true);
+    log.info("End of getHealthCheck");
     RpcResult<GetHealthCheckOutput> rpcResult = RpcResultBuilder.<GetHealthCheckOutput>status(true)
         .withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -271,21 +273,29 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
 
   @Override
   public ListenableFuture<RpcResult<GetNearRTRICsOutput>> getNearRTRICs(GetNearRTRICsInput input) {
-    // TODO Auto-generated method stub
-    return null;
+      log.info("Start of getNearRTRICs");
+      GetNearRTRICsOutputBuilder responseBuilder = new GetNearRTRICsOutputBuilder();
+      responseBuilder.setNearRtRicIdList(nearRicUrlProvider.getNearRTRicIdsList());
+      log.info("End of getNearRTRICs");
+      RpcResult<GetNearRTRICsOutput> rpcResult = RpcResultBuilder.<GetNearRTRICsOutput>status(true)
+          .withResult(responseBuilder.build()).build();
+      return Futures.immediateFuture(rpcResult);
   }
 
   @Override
   public ListenableFuture<RpcResult<GetPolicyInstanceOutput>> getPolicyInstance(
       GetPolicyInstanceInput input) {
-    log.debug("Start of getPolicyInstance");
-    String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getPolicyTypeId()),
-        String.valueOf(input.getPolicyInstanceId()));
+    log.info("Start of getPolicyInstance");
+    log.info("Policy Type Id : {},  Policy Instance Id : {}", input.getPolicyTypeId(), input.getPolicyInstanceId());
+    String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getNearRtRicId()),
+            String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId()));
     Optional<String> policyInstance = restAdapter.get(uri, String.class);
     GetPolicyInstanceOutputBuilder responseBuilder = new GetPolicyInstanceOutputBuilder();
-    responseBuilder
-        .setPolicyInstance(policyInstance.isPresent() ? policyInstance.get() : StringUtils.EMPTY);
-    log.debug("End of getPolicyInstance");
+    if (policyInstance.isPresent()) {
+        log.info("Response policyInstance.get() : {} ", policyInstance.get());
+        responseBuilder.setPolicyInstance(policyInstance.get());
+    }
+    log.info("End of getPolicyInstance");
     RpcResult<GetPolicyInstanceOutput> rpcResult = RpcResultBuilder
         .<GetPolicyInstanceOutput>status(true).withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -294,14 +304,16 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
   @Override
   public ListenableFuture<RpcResult<GetPolicyInstancesOutput>> getPolicyInstances(
       GetPolicyInstancesInput input) {
-    log.debug("Start of getPolicyInstances");
-    String uri = nearRicUrlProvider.getPolicyInstances(String.valueOf(input.getPolicyTypeId()));
+    log.info("Start of getPolicyInstances");
+    String uri = nearRicUrlProvider.getPolicyInstances(String.valueOf(input.getNearRtRicId()),
+            String.valueOf(input.getPolicyTypeId()));
     Optional<List<String>> policyInstances = restAdapter.get(uri, List.class);
     GetPolicyInstancesOutputBuilder responseBuilder = new GetPolicyInstancesOutputBuilder();
     if (policyInstances.isPresent()) {
+      log.info("Response policyInstances.get() : {} ", policyInstances.get());
       responseBuilder.setPolicyInstanceIdList(policyInstances.get());
     }
-    log.debug("End of getPolicyInstances");
+    log.info("End of getPolicyInstances");
     RpcResult<GetPolicyInstancesOutput> rpcResult = RpcResultBuilder
         .<GetPolicyInstancesOutput>status(true).withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -309,17 +321,20 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
 
   @Override
   public ListenableFuture<RpcResult<GetPolicyTypeOutput>> getPolicyType(GetPolicyTypeInput input) {
-    log.debug("Start of getPolicyType");
-    log.debug("Policy Type Id : ", input.getPolicyTypeId());
-    String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getPolicyTypeId()));
-    Optional<PolicyTypeSchema> policyTypeSchema = restAdapter.get(uri, PolicyTypeSchema.class);
+    log.info("Start of getPolicyType");
+    log.info("Policy Type Id : {} ", input.getPolicyTypeId());
+    String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getNearRtRicId()),
+            String.valueOf(input.getPolicyTypeId()));
+    Optional<String> policyType = restAdapter.get(uri, String.class);
     GetPolicyTypeOutputBuilder responseBuilder = new GetPolicyTypeOutputBuilder();
-    if (policyTypeSchema.isPresent()) {
-      responseBuilder.setDescription(policyTypeSchema.get().getDescription());
-      responseBuilder.setName(policyTypeSchema.get().getName());
-      responseBuilder.setPolicyType(policyTypeSchema.get().getCreateSchema().toString());
+    if (policyType.isPresent()) {
+      log.info("Response policyType.get() : {} ", policyType.get());
+      JSONObject policyTypeObj = new JSONObject(policyType.get());
+      responseBuilder.setDescription(policyTypeObj.getString("description"));
+      responseBuilder.setName(policyTypeObj.getString("name"));
+      responseBuilder.setPolicyType(policyTypeObj.getJSONObject("create_schema").toString());
     }
-    log.debug("End of getPolicyType");
+    log.info("End of getPolicyType");
     RpcResult<GetPolicyTypeOutput> rpcResult = RpcResultBuilder.<GetPolicyTypeOutput>status(true)
         .withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -328,12 +343,20 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
   @Override
   public ListenableFuture<RpcResult<GetPolicyTypesOutput>> getPolicyTypes(
       GetPolicyTypesInput input) {
-    log.debug("Start of getPolicyTypes");
-    String uri = nearRicUrlProvider.getPolicyTypes();
-    Optional<List<Long>> policyTypes = restAdapter.get(uri, List.class);
+    log.info("Start of getPolicyTypes");
+    String uri = nearRicUrlProvider.getPolicyTypes(String.valueOf(input.getNearRtRicId()));
+    Optional<List<Integer>> policyTypes = restAdapter.get(uri, List.class);
     GetPolicyTypesOutputBuilder responseBuilder = new GetPolicyTypesOutputBuilder();
-    responseBuilder.setPolicyTypeIdList(policyTypes.get());
-    log.debug("End of getPolicyTypes");
+    if (policyTypes.isPresent()) {
+        log.info("Response policyTypes.get() : {} ", policyTypes.get());
+        List<Integer> policyTypesListInteger = policyTypes.get();
+        List<Long> policyTypesListLong = new ArrayList<>();
+        for(Integer i : policyTypesListInteger){
+            policyTypesListLong.add(i.longValue());
+        }
+        responseBuilder.setPolicyTypeIdList(policyTypesListLong);
+    }
+    log.info("End of getPolicyTypes");
     RpcResult<GetPolicyTypesOutput> rpcResult = RpcResultBuilder.<GetPolicyTypesOutput>status(true)
         .withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
@@ -341,18 +364,17 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService {
 
   @Override
   public ListenableFuture<RpcResult<GetStatusOutput>> getStatus(GetStatusInput input) {
-    log.debug("Start of getStatus");
-    String uri = nearRicUrlProvider.getPolicyInstanceIdStatus(
+    log.info("Start of getStatus");
+    String uri = nearRicUrlProvider.getPolicyInstanceIdStatus(String.valueOf(input.getNearRtRicId()),
         String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId()));
-    Optional<List<String>> policyTypes = restAdapter.get(uri, List.class);
+    Optional<String> status = restAdapter.get(uri, String.class);
     GetStatusOutputBuilder responseBuilder = new GetStatusOutputBuilder();
-    // TODO:
-    /*
-     * No Schema defined for the response so Identify a way to parse the schema or create the java
-     * object
-     */
-    responseBuilder.setStatus(RESPONSE_SUCCESS);
-    log.debug("End of getStatus");
+    if (status.isPresent()) {
+        log.info("Response status.get() : {} ", status.get());
+        JSONObject statusObj = new JSONObject(status.get());
+        responseBuilder.setStatus(statusObj.getString("status"));
+    }
+    log.info("End of getStatus");
     RpcResult<GetStatusOutput> rpcResult =
         RpcResultBuilder.<GetStatusOutput>status(true).withResult(responseBuilder.build()).build();
     return Futures.immediateFuture(rpcResult);
index 469e407..14c34e4 100644 (file)
 
 package org.onap.sdnc.northbound.restadpter;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.web.util.UriComponentsBuilder;
 
 /**
  * This class provides Near-RIC api to invoke the A1 interface
- * 
+ *
  * @author lathishbabu.ganesan@est.tech
  *
  */
 
 public class NearRicUrlProvider {
 
-  private String baseUrl;
+  // nearRicMap provides mapping from nearRtRicId to domainname:port of nearRTRics
+  private HashMap<String, String> nearRicMap = new HashMap<>();
+  private static final String NEAR_RIC_LIST_FILE = "NearRtRicList.properties";
+  private final Logger log = LoggerFactory.getLogger(NearRicUrlProvider.class);
 
   public NearRicUrlProvider() {
-    // Near ric ip is passed in payload
-    baseUrl = "http://localhost:8080/a1-p/";
+      try {
+        readNearRtRicConfigFile();
+      } catch (IOException ex) {
+        log.error("Exception while reading nearRtRicConfigFile: {}", ex);
+      }
+  }
+
+  private void readNearRtRicConfigFile() throws IOException {
+      InputStream inputStream = NearRicUrlProvider.class.getClassLoader().getResourceAsStream(NEAR_RIC_LIST_FILE);
+      if (inputStream == null) {
+          log.error("The file {} not found in classpath", NEAR_RIC_LIST_FILE);
+      } else {
+          Properties properties = new Properties();
+          properties.load(inputStream);
+          Enumeration<?> keys = properties.propertyNames();
+          while (keys.hasMoreElements()) {
+              String key = (String) keys.nextElement();
+              nearRicMap.put(key, properties.getProperty(key));
+          }
+          inputStream.close();
+      }
+  }
+
+  /**
+   * Retrieve the list of Near-RICs
+   *
+   * @return the list of Near-RICs
+   */
+  public List<String> getNearRTRicIdsList () {
+      return new ArrayList<>(nearRicMap.keySet());
   }
 
   /**
    * Retrieve the base url of the Near-RIC
-   * 
+   *
    * @return the base url
    */
-  public String getBaseUrl() {
+  public String getBaseUrl(final String nearRtRicId) {
+    String baseUrl = "http://" + nearRicMap.get(nearRtRicId) + "/a1-p/";
     return UriComponentsBuilder.fromUriString(baseUrl).build().toString();
   }
 
   /**
    * Retrieve the url of A1 healthcheck
-   * 
+   *
    * @return the health check url
    */
-  public String getHealthCheck() {
-    return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("healthcheck").build()
+  public String getHealthCheck(final String nearRtRicId) {
+    return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("healthcheck").build()
         .toString();
   }
 
   /**
    * Retrieve the policy type url
-   * 
+   *
    * @return the base url with the policytypes
    */
-  public String getPolicyTypes() {
-    return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("policytypes").build()
+  public String getPolicyTypes(final String nearRtRicId) {
+    return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes/").build()
         .toString();
   }
 
   /**
    * Retrieve the url of policy type id
-   * 
+   *
    * @param policyTypeId Policy Type Id
    * @return the policy type id url
    */
-  public String getPolicyTypeId(final String policyTypeId) {
-    return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("policytypes")
+  public String getPolicyTypeId(final String nearRtRicId, final String policyTypeId) {
+    return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes")
         .pathSegment(policyTypeId).build().toString();
   }
 
   /**
    * Retrieve the url of the policy instances
-   * 
+   *
    * @param policyTypeId Policy Type Id
    * @return the policy instances for the given policy type
    */
-  public String getPolicyInstances(final String policyTypeId) {
-    return UriComponentsBuilder.fromUriString(getPolicyTypeId(policyTypeId)).pathSegment("policies")
+  public String getPolicyInstances(final String nearRtRicId, final String policyTypeId) {
+    return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies")
         .build().toString();
   }
 
   /**
    * Retrieve the url of the policy instance id
-   * 
+   *
    * @param policyTypeId Policy Type Id
    * @param policyInstanceId Policy Instance Id
    * @return the policy instance id for the given policy type
    */
-  public String getPolicyInstanceId(final String policyTypeId, final String policyInstanceId) {
-    return UriComponentsBuilder.fromUriString(getPolicyTypeId(policyTypeId)).pathSegment("policies")
+  public String getPolicyInstanceId(final String nearRtRicId, final String policyTypeId, final String policyInstanceId) {
+    return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies")
         .pathSegment(policyInstanceId).build().toString();
   }
 
   /**
    * Retrieve the url of the policy instance id status
-   * 
+   *
    * @param policyTypeId Policy Type Id
    * @param policyInstanceId Policy Instance Id
    * @return the policy instance id status for the given policy type
    */
-  public String getPolicyInstanceIdStatus(final String policyTypeId,
+  public String getPolicyInstanceIdStatus(final String nearRtRicId, final String policyTypeId,
       final String policyInstanceId) {
-    return UriComponentsBuilder.fromUriString(getPolicyInstanceId(policyTypeId, policyInstanceId))
+    return UriComponentsBuilder.fromUriString(getPolicyInstanceId(nearRtRicId, policyTypeId, policyInstanceId))
         .pathSegment("status").build().toString();
   }
 }
index 98759fd..504c128 100644 (file)
@@ -25,7 +25,7 @@ import com.google.common.base.Optional;
 
 /**
  * An interface to wrap the generic HTTP methods
- * 
+ *
  * @author lathishbabu.ganesan@est.tech
  *
  */
@@ -34,7 +34,7 @@ public interface RestAdapter {
   /**
    * Retrieve a representation by doing a GET on the specified URL. The response (if any) is
    * converted and returned.
-   * 
+   *
    * @param uri the URL
    * @param clazz responseType the type of the return value
    * @return the converted object
@@ -44,16 +44,16 @@ public interface RestAdapter {
 
   /**
    * Create or update a resource by PUTting the given object to the URI.
-   * 
+   *
    * @param url the URL
-   * @param request the Object to be PUT (may be {@code null})
+   * @param request the String to be PUT (may be {@code null})
    * @return the response code
    */
-  <T> Optional<T> put(final String url, final Object object);
+  <T> Optional<T> put(final String url, final String body);
 
   /**
    * Delete resource for the given object to the URI.
-   * 
+   *
    * @param url the URL
    * @return the response code
    */
index bbdcb00..215ebad 100644 (file)
 
 package org.onap.sdnc.northbound.restadpter;
 
+import com.google.common.base.Optional;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.RestTemplate;
-import com.google.common.base.Optional;
 
 /**
  * This class provides the Generic Rest Adapter interface to the RestTemplate
- * 
+ *
  * @author lathishbabu.ganesan@est.tech
  *
  */
@@ -58,8 +60,10 @@ public class RestAdapterImpl implements RestAdapter {
   }
 
   @Override
-  public <T> Optional<T> put(String uri, Object object) {
-    HttpEntity<?> entity = getHttpEntity(object);
+  public <T> Optional<T> put(String uri, String body) {
+    HttpHeaders headers = new HttpHeaders();
+    headers.setContentType(MediaType.APPLICATION_JSON);
+    HttpEntity<String> entity = new HttpEntity<String>(body, headers);
     final ResponseEntity<T> response = invokeHttpRequest(uri, HttpMethod.PUT, null, entity);
     return buildOptional(response);
   }
@@ -79,9 +83,9 @@ public class RestAdapterImpl implements RestAdapter {
 
   private <T> Optional<T> buildOptional(ResponseEntity<T> response) {
     if (!response.getStatusCode().equals(HttpStatus.OK)
-        | !response.getStatusCode().equals(HttpStatus.CREATED)
-        | !response.getStatusCode().equals(HttpStatus.NO_CONTENT)) {
-      log.error("Failed to get the Response");
+        & !response.getStatusCode().equals(HttpStatus.CREATED)
+        & !response.getStatusCode().equals(HttpStatus.NO_CONTENT)) {
+      log.error("Failed to get the Response, Status Code = {}", response.getStatusCode());
       return Optional.absent();
     }
     if (response.hasBody()) {
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/resources/NearRtRicList.properties b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/resources/NearRtRicList.properties
new file mode 100644 (file)
index 0000000..948c2f7
--- /dev/null
@@ -0,0 +1,23 @@
+# ========================LICENSE_START=================================
+# O-RAN-SC
+# %%
+# Copyright (C) 2019 Nordix Foundation
+# %%
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========================LICENSE_END===================================
+
+# Defines the list of nearRTRics that the SDNC can contact,
+# where key is nearRTRicId and value is domainname:port of a nearRTRic.
+
+NearRtRic1 = nearRtRic-sim1:8080
+NearRtRic2 = nearRtRic-sim2:8080
\ No newline at end of file
index 9c40a88..e67304c 100644 (file)
@@ -23,6 +23,8 @@ package org.onap.sdnc.northbound;
 import static org.mockito.Matchers.anyObject;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
@@ -40,14 +42,8 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyInstanceInputBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyInstanceOutput;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyTypeInputBuilder;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyTypeOutput;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyInstanceInputBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyInstanceOutput;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyTypeInputBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyTypeOutput;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckInputBuilder;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckOutput;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceInputBuilder;
@@ -61,15 +57,12 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev19100
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusInputBuilder;
 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusOutput;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.oransc.ric.a1med.client.model.PolicyTypeSchema;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
 
 /**
  * This class Tests all the methods in NonrtRicApiProvider
- * 
+ *
  * @author lathishbabu.ganesan@est.tech
  *
  */
@@ -87,6 +80,7 @@ public class NonrtRicApiProviderTest extends AbstractConcurrentDataBrokerTest {
   @Mock
   private RestAdapter restAdapter;
   private NearRicUrlProvider nearRicUrlProvider;
+  private static String nearRtRicId = "NearRtRic1";
   private static Long policyTypeId = 11L;
   private static String policyTypeInstanceId = "12";
 
@@ -102,10 +96,11 @@ public class NonrtRicApiProviderTest extends AbstractConcurrentDataBrokerTest {
   @Test
   public void testCreatePolicyType() throws InterruptedException, ExecutionException {
     CreatePolicyTypeInputBuilder inputBuilder = new CreatePolicyTypeInputBuilder();
+    inputBuilder.setNearRtRicId(nearRtRicId);
     inputBuilder.setPolicyTypeId(policyTypeId);
     Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri =
-        nearRicUrlProvider.getPolicyTypeId(String.valueOf(inputBuilder.build().getPolicyTypeId()));
+    String uri = nearRicUrlProvider.getPolicyTypeId(inputBuilder.build().getNearRtRicId(),
+                String.valueOf(inputBuilder.build().getPolicyTypeId()));
     Optional<Object> createPolicyTyperesponse = null;
     when(restAdapter.put(eq(uri), anyObject())).thenReturn(createPolicyTyperesponse);
     ListenableFuture<RpcResult<CreatePolicyTypeOutput>> result =
@@ -116,127 +111,93 @@ public class NonrtRicApiProviderTest extends AbstractConcurrentDataBrokerTest {
   @Test
   public void testGetPolicyType() throws InterruptedException, ExecutionException {
     GetPolicyTypeInputBuilder inputBuilder = new GetPolicyTypeInputBuilder();
+    inputBuilder.setNearRtRicId(nearRtRicId);
     inputBuilder.setPolicyTypeId(policyTypeId);
     Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri =
-        nearRicUrlProvider.getPolicyTypeId(String.valueOf(inputBuilder.build().getPolicyTypeId()));
-    PolicyTypeSchema policyTypeSchema = new PolicyTypeSchema();
-    policyTypeSchema.setName("AdmissionControlPolicy");
-    policyTypeSchema.setCreateSchema("{}");
-    when(restAdapter.get(eq(uri), anyObject())).thenReturn(Optional.of(policyTypeSchema));
+    String uri = nearRicUrlProvider.getPolicyTypeId(inputBuilder.build().getNearRtRicId(),
+            String.valueOf(inputBuilder.build().getPolicyTypeId()));
+    String policyType =
+            "{\"name\":\"Policy type 1\",\"description\":\"PT 1\",\"policy_type_id\":1,\"create_schema\":{}}";
+    when(restAdapter.get(eq(uri), anyObject())).thenReturn(Optional.of(policyType));
     ListenableFuture<RpcResult<GetPolicyTypeOutput>> result =
         nonrtRicApiProvider.getPolicyType(inputBuilder.build());
-    Assert.assertEquals(policyTypeSchema.getName(), result.get().getResult().getName());
+    Assert.assertEquals("Policy type 1", result.get().getResult().getName());
   }
 
   @Test
   public void testGetPolicyTypes() throws InterruptedException, ExecutionException {
     GetPolicyTypesInputBuilder inputBuilder = new GetPolicyTypesInputBuilder();
+    inputBuilder.setNearRtRicId(nearRtRicId);
     Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri = nearRicUrlProvider.getPolicyTypes();
-    List<Long> policyTypes = new ArrayList<>();
-    policyTypes.add(20001L);
-    when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(Optional.of(policyTypes));
+    String uri = nearRicUrlProvider.getPolicyTypes(inputBuilder.build().getNearRtRicId());
+    List<Integer> policyTypesInteger = new ArrayList<>();
+    policyTypesInteger.add(20001);
+    List<Long> policyTypesLong = new ArrayList<>();
+    policyTypesLong.add(20001L);
+    when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(Optional.of(policyTypesInteger));
     ListenableFuture<RpcResult<GetPolicyTypesOutput>> result =
         nonrtRicApiProvider.getPolicyTypes(inputBuilder.build());
-    Assert.assertEquals(policyTypes, result.get().getResult().getPolicyTypeIdList());
-  }
-
-  @Test
-  public void testDeletePolicyType() throws InterruptedException, ExecutionException {
-    DeletePolicyTypeInputBuilder inputBuilder = new DeletePolicyTypeInputBuilder();
-    inputBuilder.setPolicyTypeId(policyTypeId);
-    Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri =
-        nearRicUrlProvider.getPolicyTypeId(String.valueOf(inputBuilder.build().getPolicyTypeId()));
-    Optional<Object> deletePolicyTyperesponse = null;
-    when(restAdapter.delete(uri)).thenReturn(deletePolicyTyperesponse);
-    ListenableFuture<RpcResult<DeletePolicyTypeOutput>> result =
-        nonrtRicApiProvider.deletePolicyType(inputBuilder.build());
-  }
-
-  @Test
-  public void testCreatePolicyInstance() throws InterruptedException, ExecutionException {
-    CreatePolicyInstanceInputBuilder inputBuilder = new CreatePolicyInstanceInputBuilder();
-    inputBuilder.setPolicyTypeId(policyTypeId);
-    inputBuilder.setPolicyInstanceId(policyTypeInstanceId);
-    Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri = nearRicUrlProvider.getPolicyInstanceId(
-        String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId());
-    Optional<Object> createPolicyInstanceresponse = null;
-    when(restAdapter.put(eq(uri), anyObject())).thenReturn(createPolicyInstanceresponse);
-    ListenableFuture<RpcResult<CreatePolicyInstanceOutput>> result =
-        nonrtRicApiProvider.createPolicyInstance(inputBuilder.build());
-  }
-
-  @Test
-  public void testDeletePolicyInstance() throws InterruptedException, ExecutionException {
-    DeletePolicyInstanceInputBuilder inputBuilder = new DeletePolicyInstanceInputBuilder();
-    inputBuilder.setPolicyTypeId(policyTypeId);
-    inputBuilder.setPolicyInstanceId(policyTypeInstanceId);
-    Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri = nearRicUrlProvider.getPolicyInstanceId(
-        String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId());
-    Optional<Object> deletePolicyInstanceresponse = null;
-    when(restAdapter.delete(uri)).thenReturn(deletePolicyInstanceresponse);
-    ListenableFuture<RpcResult<DeletePolicyInstanceOutput>> result =
-        nonrtRicApiProvider.deletePolicyInstance(inputBuilder.build());
+    Assert.assertEquals(policyTypesLong, result.get().getResult().getPolicyTypeIdList());
   }
 
   @Test
   public void testGetPolicyInstance() throws InterruptedException, ExecutionException {
     GetPolicyInstanceInputBuilder inputBuilder = new GetPolicyInstanceInputBuilder();
+    inputBuilder.setNearRtRicId(nearRtRicId);
     inputBuilder.setPolicyTypeId(policyTypeId);
     inputBuilder.setPolicyInstanceId(policyTypeInstanceId);
     Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri = nearRicUrlProvider.getPolicyInstanceId(
+    String uri = nearRicUrlProvider.getPolicyInstanceId(inputBuilder.build().getNearRtRicId(),
         String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId());
-    String getPolicyInstanceresponse = "{}";
+    String policyInstance =
+            "{\"scope\":{\"ue_id\":\"2\"},\"statement\":{\"priority_level\":\"1\"},\"policy_id\":\"pi12\"}";
     when(restAdapter.get(eq(uri), eq(String.class)))
-        .thenReturn(Optional.of(getPolicyInstanceresponse));
+        .thenReturn(Optional.of(policyInstance));
     ListenableFuture<RpcResult<GetPolicyInstanceOutput>> result =
         nonrtRicApiProvider.getPolicyInstance(inputBuilder.build());
+    Assert.assertEquals(policyInstance, result.get().getResult().getPolicyInstance());
   }
 
   @Test
   public void testGetPolicyInstances() throws InterruptedException, ExecutionException {
     GetPolicyInstancesInputBuilder inputBuilder = new GetPolicyInstancesInputBuilder();
+    inputBuilder.setNearRtRicId(nearRtRicId);
     inputBuilder.setPolicyTypeId(policyTypeId);
     Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri = nearRicUrlProvider
-        .getPolicyInstances(String.valueOf(inputBuilder.build().getPolicyTypeId()));
-    List<String> getPolicyInstances = new ArrayList<>();
-    getPolicyInstances.add("3d2157af-6a8f-4a7c-810f-38c2f824bf12");
-    when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(Optional.of(getPolicyInstances));
+    String uri = nearRicUrlProvider.getPolicyInstances(inputBuilder.build().getNearRtRicId(),
+            String.valueOf(inputBuilder.build().getPolicyTypeId()));
+    List<String> policyInstances = new ArrayList<>();
+    policyInstances.add("3d2157af-6a8f-4a7c-810f-38c2f824bf12");
+    when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(Optional.of(policyInstances));
     ListenableFuture<RpcResult<GetPolicyInstancesOutput>> result =
         nonrtRicApiProvider.getPolicyInstances(inputBuilder.build());
+    Assert.assertEquals(policyInstances, result.get().getResult().getPolicyInstanceIdList());
   }
 
   @Test
   public void testGetStatus() throws InterruptedException, ExecutionException {
     GetStatusInputBuilder inputBuilder = new GetStatusInputBuilder();
+    inputBuilder.setNearRtRicId(nearRtRicId);
     inputBuilder.setPolicyTypeId(policyTypeId);
     inputBuilder.setPolicyInstanceId(policyTypeInstanceId);
     Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri = nearRicUrlProvider.getPolicyInstanceIdStatus(
+    String uri = nearRicUrlProvider.getPolicyInstanceIdStatus(inputBuilder.build().getNearRtRicId(),
         String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId());
-    List<String> getPolicyInstanceIdStatus = new ArrayList<>();
-    getPolicyInstanceIdStatus.add("");
-    when(restAdapter.get(eq(uri), eq(List.class)))
-        .thenReturn(Optional.of(getPolicyInstanceIdStatus));
+    String policyInstanceStatus = "{\"status\":\"enforced\"}";
+    when(restAdapter.get(eq(uri), eq(String.class))).thenReturn(Optional.of(policyInstanceStatus));
     ListenableFuture<RpcResult<GetStatusOutput>> result =
         nonrtRicApiProvider.getStatus(inputBuilder.build());
-    // TODO: Define the proper response message for get policy instance status
-    Assert.assertEquals("Success", result.get().getResult().getStatus());
+    Assert.assertEquals("enforced", result.get().getResult().getStatus());
   }
 
   @Test
   public void testHealthCheck() throws InterruptedException, ExecutionException {
     GetHealthCheckInputBuilder inputBuilder = new GetHealthCheckInputBuilder();
+    inputBuilder.setNearRtRicId(nearRtRicId);
     Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
-    String uri = nearRicUrlProvider.getHealthCheck();
+    String uri = nearRicUrlProvider.getHealthCheck(inputBuilder.build().getNearRtRicId());
     String healthCheckStatus = "";
-    when(restAdapter.get(eq(uri), eq(String.class))).thenReturn(Optional.of(healthCheckStatus));
+    when(restAdapter.get(eq(uri), eq(String.class))).thenReturn(null);
     ListenableFuture<RpcResult<GetHealthCheckOutput>> result =
         nonrtRicApiProvider.getHealthCheck(inputBuilder.build());
     Assert.assertEquals(true, result.get().getResult().isHealthStatus());