+++ /dev/null
-*.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/
+++ /dev/null
-# 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.
+++ /dev/null
-<?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>
+++ /dev/null
-# ==================================================================================
-# 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
<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>
<name>sdnc-northbound :: nonrt-ric-api</name>
<modules>
- <module>a1-client</module>
<module>model</module>
<module>provider</module>
<module>features</module>
<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>
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;
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
*
*/
@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);
@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);
@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);
@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);
@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);
@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);
@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);
@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);
@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);
@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);
/**
* This class provides Near-RIC api to invoke the A1 interface
- *
+ *
* @author lathishbabu.ganesan@est.tech
*
*/
private String baseUrl;
public NearRicUrlProvider() {
- // Near ric ip is passed in payload
- baseUrl = "http://localhost:8080/a1-p/";
+ // Near ric ip:port is passed in payload currently
}
/**
* Retrieve the base url of the Near-RIC
- *
+ *
* @return the base url
*/
- public String getBaseUrl() {
+ public String getBaseUrl(final String nearRtRicId) {
+ baseUrl = "http://" + 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();
}
}
/**
* An interface to wrap the generic HTTP methods
- *
+ *
* @author lathishbabu.ganesan@est.tech
*
*/
/**
* 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
/**
* 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
*/
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
*
*/
}
@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);
}
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()) {