From: Lathish Date: Thu, 10 Oct 2019 12:30:07 +0000 (+0100) Subject: Near-RT-RIC Simualator & README files X-Git-Tag: 1.7.3~30 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=1279d1964e3a02af70fcc3532928a82b869181be;p=nonrtric.git Near-RT-RIC Simualator & README files Issue-ID: NONRTRIC-29 Change-Id: I8e75b90c7bba5be8db793b671908bf0505ee4546 Signed-off-by: Lathish --- diff --git a/README.md b/README.md index 124a3fce..3e658f64 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,24 @@ -# Non-RealTime RIC (NONRTRIC) root repository +# O-RAN-SC Non-RealTime RIC -This repository acts as root O-RAN-SC NONRTRIC repository. +The O-RAN SC Non-RealTime RIC provides support non-real-time intelligent radio resource management, higher layer procedure optimization, policy optimization in RAN, and providing guidance, parameters, policies and AI/ML models to support the operation of RIC near-RT to achieve higher-level non-real-time objectives. + +Please see the documentation in the docs/ folder For more information about the NONRTRIC project please see the [project website](https://wiki.o-ran-sc.org/display/RICNR "O-RAN-SC NONRTRIC project") ## License +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. -This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE.txt) file for details. \ No newline at end of file +For more information about license please see the [LICENSE](LICENSE.txt) file for details. diff --git a/docs/developer-guide.rst b/docs/developer-guide.rst new file mode 100644 index 00000000..94044d04 --- /dev/null +++ b/docs/developer-guide.rst @@ -0,0 +1,81 @@ +.. ============LICENSE_START======================================================= +.. 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. +.. +.. SPDX-License-Identifier: Apache-2.0 +.. ============LICENSE_END========================================================= + +A1 Mediation: +1. SDNC Controller +2. Near-RT RIC Simulator + +SDNC A1 Controller Developer Guide +================================== + +This document provides a quickstart for developers of the O-RAN SC A1 Controller SDNC Application + +Prerequisites +------------- + +1. Java development kit (JDK), version 8 +2. Maven dependency-management tool, version 3.4 or later +3. Python, version 2 +4. Docker, version 19.03.1 or later +5. Docker Compose, version 1.24.1 or later + +Go to the northbound directory and run this command :: + mvn clean install + +This will build the project and create artifcats in maven repo + +Go to oam/installation directory and run this command :: + mvn clean install -P docker +This will create the docker images required for sdnc + +After this step check for the docker images created by the maven build with this command :: + docker images | grep sdnc + +Go to oam/installation/src/main/yaml and run this command :: + docker-compose up -d sdnc + +This will create the docker containers with the sdnc image, you can check the status of the docker container using :: + docker-compose logs -f sdnc + +The SDNC url to access the Northbound API, + http://localhost:8282/apidoc/explorer/index.html + +Credentails: admin/Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + +Near-RT RIC Simulator Developer Guide +===================================== + +Prerequisites +------------- + +1. Java development kit (JDK), version 8 +2. Maven dependency-management tool, version 3.4 or later + +Go to the nearric-simulator/ directory and run this command :: + mvn clean install + +If you want to genereate the sources from A1 yaml file, Go to nearric-simulator/a1-med-api/ and run this command :: + mvn generate-sources + +This will generate the A1PApi.java you need to call the generate-sources maven life cycle to generate the file + +The backend server listens for requests at this URL: + http://localhost:8080 + +The backend server publishes live API documentation at the URL + http://localhost:8080/swagger-ui.html diff --git a/near-rt-ric-simulator/README.md b/near-rt-ric-simulator/README.md new file mode 100644 index 00000000..88f309b4 --- /dev/null +++ b/near-rt-ric-simulator/README.md @@ -0,0 +1,24 @@ +# O-RAN-SC Near-RealTime RIC Simulator + +The O-RAN SC Near-RealTime RIC simulates the A1 as an generic REST API which can receive and send northbound messages. The simulator validates the payload and applies policy. + +Please see the documentation in the docs/ folder + +For more information about the NONRTRIC project please see the [project website](https://wiki.o-ran-sc.org/display/RICNR "O-RAN-SC NONRTRIC project") + +## License + +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. + +For more information about license please see the [LICENSE](LICENSE.txt) file for details. diff --git a/near-rt-ric-simulator/nearric-simulator/.classpath b/near-rt-ric-simulator/nearric-simulator/.classpath new file mode 100644 index 00000000..315bd1e1 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/.project b/near-rt-ric-simulator/nearric-simulator/.project new file mode 100644 index 00000000..ea2f3747 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/.project @@ -0,0 +1,18 @@ + + + NearRic-simulator + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/near-rt-ric-simulator/nearric-simulator/.settings/org.eclipse.core.resources.prefs b/near-rt-ric-simulator/nearric-simulator/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..99f26c02 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/near-rt-ric-simulator/nearric-simulator/.settings/org.eclipse.m2e.core.prefs b/near-rt-ric-simulator/nearric-simulator/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/near-rt-ric-simulator/nearric-simulator/README.md b/near-rt-ric-simulator/nearric-simulator/README.md new file mode 100644 index 00000000..298b9882 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/README.md @@ -0,0 +1,25 @@ +# O-RAN-SC Near-RealTime RIC Simulator + +The O-RAN SC Near-RealTime RIC simulates the A1 as an generic REST API which can receive and send northbound messages. The simulator validates the payload and applies policy. + +Please see the documentation in the docs/ folder + +The backend server publishes live API documentation at the +URL `http://your-host-name-here:8080/swagger-ui.html` + +## License + +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. + +For more information about license please see the [LICENSE](LICENSE.txt) file for details. diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/.classpath b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.classpath new file mode 100644 index 00000000..a5d95095 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/.gitignore b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/.project b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.project new file mode 100644 index 00000000..cdf3219c --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.project @@ -0,0 +1,23 @@ + + + a1-med-api + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.core.resources.prefs b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..db326978 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/main/resources=UTF-8 +encoding/=UTF-8 diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.jdt.core.prefs b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..71df5229 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.methodParameters=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.m2e.core.prefs b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.iml b/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.iml new file mode 100644 index 00000000..89d40eea --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.iml @@ -0,0 +1,969 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.ipr b/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.ipr new file mode 100644 index 00000000..49d99c05 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.ipr @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.iws b/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.iws new file mode 100644 index 00000000..03c854e9 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/a1-med-api.iws @@ -0,0 +1,418 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/pom.xml b/near-rt-ric-simulator/nearric-simulator/a1-med-api/pom.xml new file mode 100644 index 00000000..8c25392f --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/pom.xml @@ -0,0 +1,152 @@ + + + 4.0.0 + + org.oran.nearric + nearric-simulator + 1.0.0-SNAPSHOT + + + + a1-med-api + ${project.artifactId} + + + UTF-8 + UTF-8 + 1.8.2 + 1.3.6 + org.oransc.ric.a1med.api + + + + javax.annotation + javax.annotation-api + + + io.swagger.core.v3 + swagger-annotations + 2.0.8 + + + io.swagger + swagger-codegen-maven-plugin + 2.4.8 + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.squareup.okhttp + okhttp + 2.7.5 + + + com.squareup.okhttp + logging-interceptor + 2.7.5 + + + io.gsonfire + gson-fire + ${gson-fire-version} + + + org.threeten + threetenbp + ${threetenbp-version} + + + + + + io.swagger.codegen.v3 + swagger-codegen-maven-plugin + 3.0.11 + + + generate-sources-server + generate-sources + + generate + + + ${project.basedir}/src/main/resources/a1_mediator_0.11.0.yaml + java + ${project.basedir}/target/generated-sources/a1med + + ${generated.package.api} + ${generated.package.api}.model + true + true + true + true + true + src/gen/java/main + true + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + io.swagger.codegen.v3 + swagger-codegen-maven-plugin + [1.0,) + + generate + + + + + + + + + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/a1-med-api/src/main/resources/a1_mediator_0.11.0.yaml b/near-rt-ric-simulator/nearric-simulator/a1-med-api/src/main/resources/a1_mediator_0.11.0.yaml new file mode 100644 index 00000000..b8b8f91c --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/a1-med-api/src/main/resources/a1_mediator_0.11.0.yaml @@ -0,0 +1,388 @@ +# ================================================================================== +# 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 diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/.classpath b/near-rt-ric-simulator/nearric-simulator/nearric-service/.classpath new file mode 100644 index 00000000..91d1e295 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/.classpath @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/.gitignore b/near-rt-ric-simulator/nearric-simulator/nearric-service/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/.project b/near-rt-ric-simulator/nearric-simulator/nearric-service/.project new file mode 100644 index 00000000..6fac18ca --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/.project @@ -0,0 +1,23 @@ + + + nearric-service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.core.resources.prefs b/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..839d647e --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.jdt.core.prefs b/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..ebb47b74 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,16 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.m2e.core.prefs b/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/pom.xml b/near-rt-ric-simulator/nearric-simulator/nearric-service/pom.xml new file mode 100644 index 00000000..383e8460 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/pom.xml @@ -0,0 +1,143 @@ + + 4.0.0 + + org.oran.nearric + nearric-simulator + 1.0.0-SNAPSHOT + + nearric-service + ${project.artifactId} + + + UTF-8 + 1.8 + 2.7.5 + 2.8.1 + + + + org.oran.nearric + a1-med-api + 0.10.3-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + runtime + + + junit + junit + test + + + io.swagger + swagger-jaxrs + 1.5.0 + + + org.apache.directory.studio + org.apache.commons.io + 2.4 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + io.springfox + springfox-swagger-ui + 2.6.1 + compile + + + io.springfox + springfox-swagger2 + 2.6.1 + compile + + + com.fasterxml.jackson.core + jackson-databind + + + com.h2database + h2 + + + + commons-beanutils + commons-beanutils + 1.9.3 + + + org.modelmapper + modelmapper + 2.3.0 + + + com.squareup.okio + okio + 1.13.0 + + + com.squareup.okhttp + okhttp + ${okhttp-version} + + + com.squareup.okhttp + logging-interceptor + ${okhttp-version} + + + com.google.code.gson + gson + ${gson-version} + + + com.github.java-json-tools + json-schema-validator + 2.2.11 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + org.onap.nearric.simulator.config.NearRicApplication + + + + + repackage + + + + + + + diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/docker/Dockerfile b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/docker/Dockerfile new file mode 100644 index 00000000..8a862e86 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/docker/Dockerfile @@ -0,0 +1,7 @@ +#Not completed docker file +FROM openjdk:8-jre-alpine + +WORKDIR /opt/app/nearricsimulator + + +ENTRYPOINT ["/usr/bin/java", "-jar", "/opt/app/datafile/datafile-app-server.jar"] \ No newline at end of file diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/ApplicationConfig.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/ApplicationConfig.java new file mode 100644 index 00000000..3c634cc4 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/ApplicationConfig.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.nearric.simulator.config; + +import java.util.HashMap; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * This class provides all the configuration for the Spring boot application + * + * @author lathishbabu.ganesan@est.tech + * + */ +@Configuration +public class ApplicationConfig { + + private final HashMap policyTypeCache = new HashMap<>(); + + @Bean + public HashMap getPolicyTypeCache() { + return policyTypeCache; + } + +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/NearRicApplication.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/NearRicApplication.java new file mode 100644 index 00000000..5b21d1a7 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/NearRicApplication.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.nearric.simulator.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.ComponentScan; + +/** + * This is the Spring Boot Application + * + * @author lathishbabu.ganesan@est.tech + * + */ + +@SpringBootApplication +@ComponentScan({"org.oransc", "org.onap"}) +@EnableCaching +public class NearRicApplication { + public static void main(final String[] args) { + SpringApplication.run(NearRicApplication.class, args); + } +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/SwaggerConfiguration.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/SwaggerConfiguration.java new file mode 100644 index 00000000..f77c1891 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/config/SwaggerConfiguration.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.nearric.simulator.config; + +import org.onap.nearric.simulator.controller.A1PApiController; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * This class provides all the configuration for the Spring boot application + * + * @author lathishbabu.ganesan@est.tech + * + */ +@Configuration +@EnableSwagger2 +public class SwaggerConfiguration { + @Bean + public Docket apiDocket() { + return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("org.onap.nearric.simulator")) + .paths(PathSelectors.any()).build(); + } + +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/controller/A1PApi.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/controller/A1PApi.java new file mode 100644 index 00000000..5254c1de --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/controller/A1PApi.java @@ -0,0 +1,125 @@ +/** + * NOTE: This class is auto generated by the swagger code generator program (3.0.8). + * https://github.com/swagger-api/swagger-codegen + * Do not edit the class manually. + */ +package org.onap.nearric.simulator.controller; + +import org.oransc.ric.a1med.api.model.InlineResponse200; +import org.oransc.ric.a1med.api.model.PolicyTypeSchema; +import io.swagger.annotations.*; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.Valid; +import javax.validation.constraints.*; +import java.util.List; +import java.util.Map; +@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2019-10-04T13:41:42.802+01:00[Europe/Dublin]") +@Api(value = "a1-p", description = "the a1-p API") +public interface A1PApi { + + @ApiOperation(value = "", nickname = "a1ControllerCreateOrReplacePolicyInstance", notes = "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", }) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Policy instance created "), + @ApiResponse(code = 400, message = "Bad PUT body for this policy instance "), + @ApiResponse(code = 404, message = "There is no policy type with this policy_type_id ") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}", + consumes = { "application/json" }, + method = RequestMethod.PUT) + ResponseEntity a1ControllerCreateOrReplacePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId,@ApiParam(value = "" ) @Valid @RequestBody Object body); + + + @ApiOperation(value = "", nickname = "a1ControllerCreatePolicyType", notes = "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", }) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "policy type successfully created"), + @ApiResponse(code = 400, message = "illegal ID, or object already existed") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}", + consumes = { "application/json" }, + method = RequestMethod.PUT) + ResponseEntity a1ControllerCreatePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "" ) @Valid @RequestBody PolicyTypeSchema body); + + + @ApiOperation(value = "", nickname = "a1ControllerDeletePolicyInstance", notes = "Delete this policy instance ", tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 204, message = "policy instance successfully deleted "), + @ApiResponse(code = 404, message = "there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id ") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}", + method = RequestMethod.DELETE) + ResponseEntity a1ControllerDeletePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId); + + + @ApiOperation(value = "", nickname = "a1ControllerDeletePolicyType", notes = "Delete this policy type. Can only be performed if there are no instances of this type ", tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 204, message = "policy type successfully deleted "), + @ApiResponse(code = 400, message = "Policy type cannot be deleted because there are instances All instances must be removed before a policy type can be deleted "), + @ApiResponse(code = 404, message = "policy type not found ") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}", + method = RequestMethod.DELETE) + ResponseEntity a1ControllerDeletePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId); + + + @ApiOperation(value = "", nickname = "a1ControllerGetAllInstancesForType", notes = "get a list of all policy instance ids for this policy type id", response = String.class, responseContainer = "List", tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "list of all policy instance ids for this policy type id", response = String.class, responseContainer = "List") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies", + produces = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity> a1ControllerGetAllInstancesForType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId); + + + @ApiOperation(value = "", nickname = "a1ControllerGetAllPolicyTypes", notes = "Get a list of all registered policy type ids", response = Integer.class, responseContainer = "List", tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "list of all registered policy type ids", response = Integer.class, responseContainer = "List") }) + @RequestMapping(value = "/a1-p/policytypes/", + produces = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity> a1ControllerGetAllPolicyTypes(); + + + @ApiOperation(value = "", nickname = "a1ControllerGetHealthcheck", notes = "Perform a healthcheck on a1 ", tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "A1 is healthy. Anything other than a 200 should be considered a1 as failing ") }) + @RequestMapping(value = "/a1-p/healthcheck", + method = RequestMethod.GET) + ResponseEntity a1ControllerGetHealthcheck(); + + + @ApiOperation(value = "", nickname = "a1ControllerGetPolicyInstance", notes = "Retrieve the policy instance ", response = Object.class, tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "The policy instance. the schema of this object is defined by the create_schema field of the policy type ", response = Object.class), + @ApiResponse(code = 404, message = "there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id ") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}", + produces = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity a1ControllerGetPolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId); + + + @ApiOperation(value = "", nickname = "a1ControllerGetPolicyInstanceStatus", notes = "Retrieve the policy instance status across all handlers of the policy ", response = InlineResponse200.class, responseContainer = "List", tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "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 ", response = InlineResponse200.class, responseContainer = "List"), + @ApiResponse(code = 404, message = "there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id ") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status", + produces = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity> a1ControllerGetPolicyInstanceStatus(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId); + + + @ApiOperation(value = "", nickname = "a1ControllerGetPolicyType", notes = "Get this policy type ", response = PolicyTypeSchema.class, tags={ "A1 Mediator", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "policy type successfully found", response = PolicyTypeSchema.class), + @ApiResponse(code = 404, message = "policy type not found ") }) + @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}", + produces = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity a1ControllerGetPolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId); + +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/controller/A1PApiController.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/controller/A1PApiController.java new file mode 100644 index 00000000..d2a0b3fd --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/controller/A1PApiController.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.nearric.simulator.controller; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +import org.apache.commons.beanutils.BeanUtils; +import org.onap.nearric.simulator.model.PolicyType; +import org.onap.nearric.simulator.service.A1PApiServiceImpl; +import org.oransc.ric.a1med.api.model.InlineResponse200; +import org.oransc.ric.a1med.api.model.PolicyTypeSchema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.swagger.annotations.ApiParam; + +/** + * This class provides all the operation performed by A1 API. + * + * @author lathishbabu.ganesan@est.tech + * + */ +@RestController +public class A1PApiController implements A1PApi { + + private static final Logger log = LoggerFactory.getLogger(A1PApiController.class); + + private final ObjectMapper objectMapper; + + private final HttpServletRequest request; + + //@Autowired + private A1PApiServiceImpl a1pApiService; + //private A1PApiService a1pApiService; + + @Autowired + public A1PApiController(ObjectMapper objectMapper, HttpServletRequest request) { + this.objectMapper = objectMapper; + this.request = request; + a1pApiService = new A1PApiServiceImpl(); + a1pApiService.set(objectMapper, request); + } + + public ResponseEntity a1ControllerCreateOrReplacePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId,@ApiParam(value = "" ) @Valid @RequestBody Object body) { + return a1pApiService.createReplaceInstance(policyTypeId, policyInstanceId, body); + } + + public ResponseEntity a1ControllerCreatePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "" ) @Valid @RequestBody PolicyTypeSchema body) { + return a1pApiService.createReplaceType(policyTypeId, body); + } + + public ResponseEntity a1ControllerDeletePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) { + return a1pApiService.deleteInstance(policyTypeId, policyInstanceId); + } + + public ResponseEntity a1ControllerDeletePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) { + return a1pApiService.deleteType(policyTypeId); + } + + public ResponseEntity> a1ControllerGetAllInstancesForType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) { + return a1pApiService.getAllInstanceForType(policyTypeId); + } + + public ResponseEntity> a1ControllerGetAllPolicyTypes() { + return a1pApiService.getAllTypes(); + } + + public ResponseEntity a1ControllerGetHealthcheck() { + String accept = request.getHeader("Accept"); + return new ResponseEntity(HttpStatus.ACCEPTED); + } + + public ResponseEntity a1ControllerGetPolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) { + return a1pApiService.getPolicyInstance(policyTypeId, policyInstanceId); + } + + public ResponseEntity> a1ControllerGetPolicyInstanceStatus(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) { + return a1pApiService.getStatus(policyTypeId, policyInstanceId); + } + + public ResponseEntity a1ControllerGetPolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) { + return a1pApiService.getPolicyTypeSchema(policyTypeId); + } + +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/model/PolicyInstance.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/model/PolicyInstance.java new file mode 100644 index 00000000..ca797d45 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/model/PolicyInstance.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.nearric.simulator.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + + + public class PolicyInstance implements Serializable { + /** + * + */ + private static final long serialVersionUID = -4903894058377154039L; + private String policyInstanceId; + private Object jsonObject; + + public PolicyInstance(String policyInstanceId, Object jsonObject) { + this.policyInstanceId = policyInstanceId; + this.jsonObject = jsonObject; + } + + public Object getJson() { + return jsonObject; + } + + public String getInstanceId() { + return policyInstanceId; + } +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/model/PolicyType.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/model/PolicyType.java new file mode 100644 index 00000000..f63a3b3b --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/model/PolicyType.java @@ -0,0 +1,76 @@ +package org.onap.nearric.simulator.model; + +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.oransc.ric.a1med.api.model.PolicyTypeSchema; + +public class PolicyType implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 8719589957000170141L; + private Integer policyTypeId; + private PolicyTypeSchema policyTypeSchema; + private HashMap policyInstances = new HashMap(); + + public PolicyType(Integer policyTypeId, PolicyTypeSchema policyTypeSchema) { + this.policyTypeId = policyTypeId; + this.policyTypeSchema = policyTypeSchema; + } + + public int getNumberInstances() { + return policyInstances.size(); + } + + public PolicyInstance getInstance(String policyInstanceId) { + return policyInstances.get(policyInstanceId); + } + + public void delete(String policyInstanceId) { + policyInstances.remove(policyInstanceId); + } + + public PolicyTypeSchema getSchema() { + return policyTypeSchema; + } + + public void createReplaceInstance(String policyTypeId, PolicyInstance policyInstance) { + policyInstances.put(policyTypeId, policyInstance); + } + + public Set getInstances() { + return policyInstances.keySet(); + } + + public Integer getTypeId() { + return policyTypeId; + } + +} \ No newline at end of file diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/service/A1PApiService.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/service/A1PApiService.java new file mode 100644 index 00000000..b875ec7d --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/service/A1PApiService.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.nearric.simulator.service; + +import org.onap.nearric.simulator.model.PolicyType; +import org.oransc.ric.a1med.api.model.PolicyTypeSchema; + +/** + * @author lathishbabu.ganesan@est.tech + * + */ + +public interface A1PApiService { + + public void getHealthCheck(); + + public void getPolicyTypes(); + + public PolicyType getPolicyType(Integer policyTypeId); + + public void deletePolicyTypeId(); + + public void putPolicyType(Integer policyTypeId, PolicyTypeSchema policyTypeSchema); + + public void getPolicyInstances(); + + public void getPolicyInstanceId(); + + public void deletePolicyInstanceId(); + + public void putPolicyInstance(Integer policyTypeId, String policyInstanceId, Object body); + + public void getPolicyInstanceIdStatus(); + +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/service/A1PApiServiceImpl.java b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/service/A1PApiServiceImpl.java new file mode 100644 index 00000000..1521ed79 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/java/org/onap/nearric/simulator/service/A1PApiServiceImpl.java @@ -0,0 +1,441 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.nearric.simulator.service; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.beanutils.BeanUtils; +import org.onap.nearric.simulator.model.PolicyType; +import org.onap.nearric.simulator.model.PolicyInstance; +import org.oransc.ric.a1med.api.model.PolicyTypeSchema; +import org.oransc.ric.a1med.api.model.InlineResponse200; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.fge.jackson.JsonLoader; +import com.github.fge.jsonschema.core.exceptions.ProcessingException; +import com.github.fge.jsonschema.core.report.ProcessingMessage; +import com.github.fge.jsonschema.core.report.ProcessingReport; +import com.github.fge.jsonschema.main.JsonSchema; +import com.github.fge.jsonschema.main.JsonSchemaFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * This class provides the service implementation of all the A1 operation + * + * @author lathishbabu.ganesan@est.tech + * + */ + +@Service +public class A1PApiServiceImpl { // implements A1PApiService { + + private static final Logger log = LoggerFactory.getLogger(A1PApiServiceImpl.class); + + private HashMap policyTypes = new HashMap(); + + private ObjectMapper objectMapper = null; + + private HttpServletRequest request = null; + + public boolean validateSchema(String jsonData, String jsonSchema) { + ProcessingReport report = null; + boolean result = false; + try { + System.out.println("Applying schema: @<@<" + jsonSchema + ">@>@ to data: #<#<" + jsonData + ">#>#"); + JsonNode schemaNode = JsonLoader.fromString(jsonSchema); + JsonNode data = JsonLoader.fromString(jsonData); + JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); + JsonSchema schema = factory.getJsonSchema(schemaNode); + report = schema.validate(data); + } catch (JsonParseException jpex) { + System.out.println("Error. Something went wrong trying to parse json data: #<#<" + jsonData + + ">#># or json schema: @<@<" + jsonSchema + ">@>@. Are the double quotes included? " + + jpex.getMessage()); + // jpex.printStackTrace(); + } catch (ProcessingException pex) { + System.out.println("Error. Something went wrong trying to process json data: #<#<" + jsonData + + ">#># with json schema: @<@<" + jsonSchema + ">@>@ " + pex.getMessage()); + // pex.printStackTrace(); + } catch (IOException e) { + System.out.println("Error. Something went wrong trying to read json data: #<#<" + jsonData + + ">#># or json schema: @<@<" + jsonSchema + ">@>@"); + // e.printStackTrace(); + } + if (report != null) { + Iterator iter = report.iterator(); + while (iter.hasNext()) { + ProcessingMessage pm = iter.next(); + System.out.println("Processing Message: " + pm.getMessage()); + } + result = report.isSuccess(); + } + System.out.println(" Result=" + result); + return result; + } + + public A1PApiServiceImpl() { + } + + public void set(ObjectMapper objectMapper, HttpServletRequest request) { + this.objectMapper = objectMapper; + this.request = request; + } + + + public ResponseEntity createReplaceType(Integer policyTypeId, PolicyTypeSchema body) { + + System.out.println("createReplaceType - policyTypeId: " + policyTypeId); + System.out.println("createReplaceType - body: " + body); + + String accept = request.getHeader("Accept"); + + if (body != null && body.getName() != null) { + if (body.getPolicyTypeId().intValue() != policyTypeId.intValue()) { + System.out.println("createReplaceType - policytype mismatch between request and body"); + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + + if (policyTypes.containsKey(policyTypeId.toString())) { + System.out.println("createReplaceType - policytype already exists"); + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + + PolicyType policyType = new PolicyType(policyTypeId, body); + policyTypes.put(policyTypeId.toString(), policyType); + } + System.out.println("createReplaceType - created ok"); + return new ResponseEntity(HttpStatus.CREATED); + + } + + public ResponseEntity deleteType(Integer policyTypeId) { + + System.out.println("deleteType - policyTypeId: " + policyTypeId); + + String accept = request.getHeader("Accept"); + + PolicyType policyType = policyTypes.get(policyTypeId.toString()); + + if (policyType == null) { + System.out.println("deleteType - policytype does not exists"); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + + if (policyType.getNumberInstances() > 0) { + System.out.println("deleteType - cannot delete, instances exists"); + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + policyTypes.remove(policyTypeId.toString()); + + System.out.println("deleteType - deleted ok"); + return new ResponseEntity(HttpStatus.NO_CONTENT); + } + + public ResponseEntity deleteInstance(Integer policyTypeId, String policyInstanceId) { + + System.out.println("deleteInstance - policyTypeId: " + policyTypeId); + System.out.println("deleteInstance - policyInstanceId: " + policyInstanceId); + + PolicyType policyType = policyTypes.get(policyTypeId.toString()); + + if (policyType == null) { + System.out.println("deleteType - policytype does not exists"); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + PolicyInstance policyInstance = policyType.getInstance(policyInstanceId); + if (policyInstance == null) { + System.out.println("deleteType - instance does not exists"); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + policyType.delete(policyInstanceId); + + System.out.println("deleteInstance - deleted ok"); + return new ResponseEntity(HttpStatus.NO_CONTENT); + + } + + public ResponseEntity getPolicyTypeSchema(Integer policyTypeId) { + System.out.println("getPolicyTypeSchema - policyTypeId: " + policyTypeId); + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + String res = null; + try { + PolicyType policyType = policyTypes.get(policyTypeId.toString()); + + if (policyType == null) { + System.out.println("getPolicyTypeSchema - policytype does not exists"); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + + String json = "{}"; + PolicyTypeSchema schema = policyType.getSchema(); + String createSchema = "{}"; + try { + // Convert Map to JSON + json = objectMapper.writeValueAsString(schema); + // Print JSON output + System.out.println("getPolicyTypeSchema - schema: " + json); + + createSchema = objectMapper.writeValueAsString(schema.getCreateSchema()); + System.out.println("getPolicyTypeSchema - createSchema: " + createSchema); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("getPolicyTypeSchema - schema corrupt"); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + res = "{\n \"name\" : \"" + schema.getName() + "\",\n \"description\" : \"" + schema.getDescription() + + "\",\n \"create_schema\" : " + createSchema + ",\n \"policy_type_id\" : " + + schema.getPolicyTypeId().intValue() + "\n}"; + System.out.println("getPolicyTypeSchema - json schema: " + res); + objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + return new ResponseEntity(objectMapper.readValue(res, PolicyTypeSchema.class), + HttpStatus.ACCEPTED); + } catch (Exception e) { + e.printStackTrace(); + System.out + .println("getPolicyTypeSchema - Couldn't serialize response for content type application/json"); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + System.out.println("getPolicyTypeSchema - not implemented"); + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } + + public ResponseEntity> getAllTypes() { + System.out.println("getAllTypes"); + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + Set types = policyTypes.keySet(); + String res = ""; + for (Iterator iterator = types.iterator(); iterator.hasNext();) { + String tid = (String) iterator.next(); + if (res.length() > 0) { + res = res + ","; + } + res = res + tid; + } + return new ResponseEntity>(objectMapper.readValue("[" + res + "]", List.class), + HttpStatus.ACCEPTED); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("getAllTypes - Couldn't serialize response for content type application/json"); + return new ResponseEntity>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + System.out.println("getAllTypes - not implemented"); + return new ResponseEntity>(HttpStatus.NOT_IMPLEMENTED); + } + + public ResponseEntity createReplaceInstance(Integer policyTypeId, String policyInstanceId, Object body) { + System.out.println("createReplaceInstance - policyTypeId:" + policyTypeId); + System.out.println("createReplaceInstance - policyInstanceId:" + policyInstanceId); + System.out.println("createReplaceInstance - body:" + body); + System.out.println("createReplaceInstance - bodyclass:" + body.getClass().toString()); + + String accept = request.getHeader("Accept"); + + PolicyType policyType = policyTypes.get(policyTypeId.toString()); + + if (policyType == null) { + System.out.println("createReplaceInstance - policytype does not exists"); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + + // Create json string from schema + String createSchema = null; + try { + PolicyTypeSchema schema = policyType.getSchema(); + // Convert Map to JSON + String json = objectMapper.writeValueAsString(schema); + // Print JSON output + System.out.println("createReplaceInstance - schema - json: " + json); + createSchema = objectMapper.writeValueAsString(schema.getCreateSchema()); + System.out.println("createReplaceInstance - createSchema - string: " + createSchema); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("createReplaceInstance - schema corrupt"); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + + // Create json string from instance + String jsonInstance = null; + try { + System.out.println("createReplaceInstance - raw: " + body); + // Convert Map to JSON + jsonInstance = objectMapper.writeValueAsString(body); + // Print JSON output + System.out.println("createReplaceInstance - instance: " + jsonInstance); + + } catch (Exception e) { + e.printStackTrace(); + System.out.println("createReplaceInstance - instancce corrupt"); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + + if (!validateSchema(jsonInstance, createSchema)) { + System.out.println("createReplaceInstance - schema validation failed"); + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + PolicyInstance policyInstance = new PolicyInstance(policyInstanceId, body); + policyType.createReplaceInstance(policyInstanceId, policyInstance); + + System.out.println("createReplaceInstance - created/replaced ok"); + return new ResponseEntity(HttpStatus.CREATED); + + } + + public ResponseEntity> getAllInstanceForType(Integer policyTypeId) { + System.out.println("getAllInstanceForType - policyTypeId:" + policyTypeId); + + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + PolicyType policyType = policyTypes.get(policyTypeId.toString()); + if (policyType == null) { + System.out.println("getAllInstanceForType - policytype does not exists"); + return new ResponseEntity>(HttpStatus.NOT_FOUND); + } + Set instances = policyType.getInstances(); + String res = ""; + for (Iterator iterator = instances.iterator(); iterator.hasNext();) { + String iid = (String) iterator.next(); + iid = "\"" + iid + "\""; + if (res.length() > 0) { + res = res + ","; + } + res = res + iid; + } + System.out.println("getAllInstanceForType - " + res); + return new ResponseEntity>(objectMapper.readValue("[" + res + "]", List.class), + HttpStatus.ACCEPTED); + } catch (IOException e) { + e.printStackTrace(); + System.out.println( + "getAllInstanceForType - Couldn't serialize response for content type application/json"); + return new ResponseEntity>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + System.out.println("getAllInstanceForType - not implemented"); + return new ResponseEntity>(HttpStatus.NOT_IMPLEMENTED); + + } + + public ResponseEntity getPolicyInstance(Integer policyTypeId, String policyInstanceId) { + System.out.println("getPolicyInstance - policyTypeId:" + policyTypeId); + System.out.println("getPolicyInstance - policyInstanceId:" + policyInstanceId); + + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + PolicyType policyType = policyTypes.get(policyTypeId.toString()); + if (policyType == null) { + System.out.println("getPolicyInstance - policytype does not exists"); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + PolicyInstance policyInstance = policyType.getInstance(policyInstanceId); + if (policyInstance == null) { + System.out.println("getPolicyInstance - policyinstance does not exists"); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + + String json = "{}"; + try { + System.out.println("getPolicyInstance - rawschema: " + policyInstance.getJson()); + // Convert Map to JSON + json = objectMapper.writeValueAsString(policyInstance.getJson()); + // Print JSON output + System.out.println("getPolicyInstance - schema: " + json); + + } catch (Exception e) { + e.printStackTrace(); + System.out.println("getPolicyInstance - schema corrupt"); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + + return new ResponseEntity(objectMapper.readValue(json, Object.class), HttpStatus.ACCEPTED); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("getPolicyInstance - policyinstance corrupt"); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } + + public ResponseEntity> getStatus(Integer policyTypeId, String policyInstanceId) { + System.out.println("getStatus - policyTypeId:" + policyTypeId); + System.out.println("getStatus - policyInstanceId:" + policyInstanceId); + + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + PolicyType policyType = policyTypes.get(policyTypeId.toString()); + if (policyType == null) { + System.out.println("getStatus - policytype does not exists"); + return new ResponseEntity>(HttpStatus.NOT_FOUND); + } + PolicyInstance policyInstance = policyType.getInstance(policyInstanceId); + if (policyInstance == null) { + System.out.println("getStatus - policyinstance does not exists"); + return new ResponseEntity>(HttpStatus.NOT_FOUND); + } + + + return new ResponseEntity>( + objectMapper.readValue("[ {\n \"handler_id\" : \"X-APP-1\",\n \"status\" : \"enforced\"\n} ]", + List.class), + HttpStatus.ACCEPTED); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("getStatus - Couldn't serialize response for content type application/json"); + return new ResponseEntity>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + return new ResponseEntity>(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/resources/application.properties b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/resources/application.properties new file mode 100644 index 00000000..cbb8218b --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/nearric-service/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.security.user.name=admin +spring.security.user.password=admin +spring.jackson.property-naming-strategy=SNAKE_CASE \ No newline at end of file diff --git a/near-rt-ric-simulator/nearric-simulator/pom.xml b/near-rt-ric-simulator/nearric-simulator/pom.xml new file mode 100644 index 00000000..e57caef7 --- /dev/null +++ b/near-rt-ric-simulator/nearric-simulator/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + org.oran.nearric + nearric-simulator + 1.0.0-SNAPSHOT + pom + ${project.artifactId} + + + org.springframework.boot + spring-boot-starter-parent + 2.1.9.RELEASE + + + + + 2.1.9.RELEASE + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + + + + org.springframework + spring-context + + + org.springframework + spring-web + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + a1-med-api + nearric-service + + \ No newline at end of file diff --git a/sdnc-a1-controller/README.md b/sdnc-a1-controller/README.md new file mode 100644 index 00000000..85fe58f1 --- /dev/null +++ b/sdnc-a1-controller/README.md @@ -0,0 +1,24 @@ +# O-RAN-SC Non-RealTime RIC - A1 Controller + +SDNC provides Northbound Interface for A1 operation to do policy management on XAPPS's in Near-RealTime RIC's. + +Please see the documentation in the docs/ folder + +For more information about the NONRTRIC project please see the [project website](https://wiki.o-ran-sc.org/display/RICNR "O-RAN-SC NONRTRIC project") + +## License + +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. + +For more information about license please see the [LICENSE](LICENSE.txt) file for details.