From ace0b71ff6e424193ff6d6519a529d279e7ade58 Mon Sep 17 00:00:00 2001 From: "Lott, Christopher (cl778h)" Date: Fri, 3 May 2019 12:20:51 -0400 Subject: [PATCH] Group E2 manager API operations with tags Add draft A1 Mediator API client and config Use nexus3.o-ran-sc.org (not nexus.oranosc.org) Use CONTAINER_PUSH_REGISTRY in the pom (not bogus NEXUS3_PUSH..) Change-Id: Ib96aa2c8eef761ffbcbcecf69f3ab34f10bc3cd7 Signed-off-by: Lott, Christopher (cl778h) --- a1-med-client/.gitignore | 23 +++ a1-med-client/README.md | 29 +++ a1-med-client/pom.xml | 203 +++++++++++++++++++++ .../src/main/resources/a1_mediator_0.3.0.yaml | 85 +++++++++ .../a1med/client/test/A1MediatorClientTest.java | 46 +++++ docs/release-notes.rst | 5 +- e2-mgr-client/pom.xml | 2 +- .../src/main/resources/e2_manager_02052019_2.yaml | 147 +++++++++++++++ .../e2mgr/client/test/E2ManagerClientTest.java | 6 +- pom.xml | 5 +- webapp-backend/pom.xml | 14 +- .../dashboard/config/A1MediatorConfiguration.java | 66 +++++++ .../config/A1MediatorMockConfiguration.java | 74 ++++++++ .../dashboard/config/E2ManagerConfiguration.java | 18 +- .../config/E2ManagerMockConfiguration.java | 30 +-- .../dashboard/controller/E2ManagerController.java | 19 +- 16 files changed, 713 insertions(+), 59 deletions(-) create mode 100644 a1-med-client/.gitignore create mode 100644 a1-med-client/README.md create mode 100644 a1-med-client/pom.xml create mode 100644 a1-med-client/src/main/resources/a1_mediator_0.3.0.yaml create mode 100644 a1-med-client/src/test/java/org/oransc/ric/portal/dashboard/a1med/client/test/A1MediatorClientTest.java create mode 100644 e2-mgr-client/src/main/resources/e2_manager_02052019_2.yaml create mode 100644 webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorConfiguration.java create mode 100644 webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorMockConfiguration.java diff --git a/a1-med-client/.gitignore b/a1-med-client/.gitignore new file mode 100644 index 00000000..27fd4617 --- /dev/null +++ b/a1-med-client/.gitignore @@ -0,0 +1,23 @@ +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# exclude jar for gradle wrapper +!gradle/wrapper/*.jar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# build files +**/target +target +.gradle +build + +logs/ diff --git a/a1-med-client/README.md b/a1-med-client/README.md new file mode 100644 index 00000000..d5780ffb --- /dev/null +++ b/a1-med-client/README.md @@ -0,0 +1,29 @@ +# A1 Mediator Client Generator + +This projects generates a REST client library from the OpenAPI specification +file stored here and packages it in a jar. + +## Eclipse and STS Users + +The Swagger Codegen maven plugin is not supported in Eclipse/STS. You can +limp along by taking these steps: + +1. Generate the code using maven: + mvn install +2. Add this folder to the project build path: + target/generated-sources/swagger/src/main/java + +## License + +Copyright (C) 2019 AT&T Intellectual Property & Nokia. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/a1-med-client/pom.xml b/a1-med-client/pom.xml new file mode 100644 index 00000000..772c462d --- /dev/null +++ b/a1-med-client/pom.xml @@ -0,0 +1,203 @@ + + + + 4.0.0 + + org.o-ran-sc.portal.ric-dashboard + ric-dash-parent + 1.0.1-SNAPSHOT + + + org.o-ran-sc.ric.a1med.client + a1-med-client + RIC A1 Mediator client + 0.3.0-SNAPSHOT + + UTF-8 + UTF-8 + org.oransc.ric.a1med.client + + + + + io.swagger.core.v3 + swagger-annotations + 2.0.8 + + + org.springframework + spring-context + + + + org.springframework + spring-web + + + + + 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 + + + + + org.junit.jupiter + junit-jupiter-api + + test + + + + + + + io.swagger.codegen.v3 + swagger-codegen-maven-plugin + 3.0.8 + + + + generate + + + ${project.basedir}/src/main/resources/a1_mediator_0.3.0.yaml + java + ${client.base.package.name} + ${client.base.package.name}.model + ${client.base.package.name}.api + ${client.base.package.name}.invoker + + ${project.groupId} + ${project.artifactId} + ${project.version} + resttemplate + true + java8 + Apache 2.0 + https://www.apache.org/licenses/LICENSE-2.0 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + attach-javadocs + + jar + + + + + + + org.apache.maven.plugins + maven-source-plugin + + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + + true + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + io.swagger.codegen.v3 + swagger-codegen-maven-plugin + [1.0,) + + generate + + + + + + + + + + + + + + diff --git a/a1-med-client/src/main/resources/a1_mediator_0.3.0.yaml b/a1-med-client/src/main/resources/a1_mediator_0.3.0.yaml new file mode 100644 index 00000000..1fff00a7 --- /dev/null +++ b/a1-med-client/src/main/resources/a1_mediator_0.3.0.yaml @@ -0,0 +1,85 @@ +# ========================LICENSE_START================================= +# ORAN-OSC +# %% +# Copyright (C) 2019 AT&T Intellectual Property and Nokia +# %% +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ========================LICENSE_END=================================== +openapi: 3.0.0 +info: + version: 0.3.0 + title: RIC A1 +paths: + '/ric/policies/{policyname}': + parameters: + - name: policyname + in: path + description: the name of the policy to retrieve or replace + required: true + schema: + type: string + put: + description: > + Replace the current operation of policyname with the new parameters (this replaces the current policy with the new one specified here). + + + Until there are standard policy definitions that are defined OUTSIDE of the scope of xapps, this API will be *very underspecified*. + This is a known gap, do not despair. + The PUT body is specified, *currently* in the xapp manifest that implements this policy; the caller should refer to the message_receives_payload_schema field to make this request. + The return content is also specified as above (in the xapp manifest) in the message_sends_payload_schema field. + + + Eventually, we need concrete policy defintions that are decoupled from xapp, and then this API description will become more fully specified. + + tags: + - A1 Mediator + operationId: a1.controller.put_handler + requestBody: + content: + application/json: + schema: + type: object + + responses: + '200': + description: > + The downstream component responsible for implementing this policy replied with a good response. Check the manifest for response details. + '400': + description: > + Bad PUT body for this policyname + '404': + description: there is no policy with this name + '409': + description: > + The xapp that implements this policy replied, but the reply was a "failure". This should be interpreted that the policy was NOT updated successfully. + '503': + description: > + the downstream component responsible for handling this policy did not respond appropriately in time + + get: + description: Get the current state/value of policyname + tags: + - A1 Mediator + operationId: a1.controller.get_handler + responses: + '200': + description: > + policy state successfully retrieved. + TODO, what describes the format returned here? + content: + application/json: + schema: + type: object + '404': + description: there is no policy with this name + diff --git a/a1-med-client/src/test/java/org/oransc/ric/portal/dashboard/a1med/client/test/A1MediatorClientTest.java b/a1-med-client/src/test/java/org/oransc/ric/portal/dashboard/a1med/client/test/A1MediatorClientTest.java new file mode 100644 index 00000000..d1ffdbf4 --- /dev/null +++ b/a1-med-client/src/test/java/org/oransc/ric/portal/dashboard/a1med/client/test/A1MediatorClientTest.java @@ -0,0 +1,46 @@ +/*- + * ========================LICENSE_START================================= + * ORAN-OSC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard.a1med.client.test; + +import org.junit.jupiter.api.Test; +import org.oransc.ric.a1med.client.api.A1MediatorApi; +import org.oransc.ric.a1med.client.invoker.ApiClient; +import org.springframework.web.client.RestClientException; + +/** + * Demonstrates use of the generated A1 mediator client. + * + * The test fails because no server is available. + */ +public class A1MediatorClientTest { + + @Test + public void demo() { + ApiClient apiClient = new ApiClient(); + apiClient.setBasePath("http://localhost:30099/"); + A1MediatorApi a1Api = new A1MediatorApi(apiClient); + try { + a1Api.a1ControllerGetHandler("policy"); + System.out.println("getPolicy answered: " + apiClient.getStatusCode().toString()); + } catch (RestClientException e) { + System.err.println("getPolicy failed: " + e.toString()); + } + } +} diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 5d37d36d..363c44c2 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -20,9 +20,10 @@ RIC Dashboard Release Notes =========================== -Version 1.0.1, 2 May 2019 +Version 1.0.1, 3 May 2019 ------------------------- -* Use E2 Manager API definition dated 2 May 2019 +* Add draft A1 Mediator API definition +* Use E2 Manager API definition dated 2 May 2019, with tag modifications Version 1.0.0, 30 Apr 2019 -------------------------- diff --git a/e2-mgr-client/pom.xml b/e2-mgr-client/pom.xml index 6e213c7e..0a1f67a3 100644 --- a/e2-mgr-client/pom.xml +++ b/e2-mgr-client/pom.xml @@ -101,7 +101,7 @@ limitations under the License. generate - ${project.basedir}/src/main/resources/e2_manager_02052019.yaml + ${project.basedir}/src/main/resources/e2_manager_02052019_2.yaml java ${client.base.package.name} ${client.base.package.name}.model diff --git a/e2-mgr-client/src/main/resources/e2_manager_02052019_2.yaml b/e2-mgr-client/src/main/resources/e2_manager_02052019_2.yaml new file mode 100644 index 00000000..04721627 --- /dev/null +++ b/e2-mgr-client/src/main/resources/e2_manager_02052019_2.yaml @@ -0,0 +1,147 @@ +# ========================LICENSE_START================================= +# ORAN-OSC +# %% +# Copyright (C) 2019 AT&T Intellectual Property and Nokia +# %% +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ========================LICENSE_END=================================== +openapi: 3.0.0 +info: + title: E2 Manager Service + description: This is a description of E2 manager service APIs + version: 1.0.0 +servers: + - url: http://{apiRoot}/nodeb/v1 + variables: + apiRoot: + default: localhost:3800 + description: >- + E2 manager +paths: + /setup: + post: + summary: X2 Setup Request + tags: + - E2 Manager + operationId: setup + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/SetupRequest' + required: true + responses: + '200': + description: Request was handled successfuly + '400': + description: Invalid input + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '404': + description: Resource not found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + default: + description: Unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + + /endcSetup: + post: + tags: + - E2 Manager + summary: ENDC Setup Request + operationId: endcSetup + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/SetupRequest' + required: true + responses: + '200': + description: Request was handled successfuly + '400': + description: Invalid input + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '404': + description: Resource not found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + default: + description: Unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + + /health: + get: + tags: + - E2 Manager + summary: E2 Manager Service Health Check + operationId: healthCheck + responses: + '200': + description: OK +components: + schemas: + SetupRequest: + type: object + required: + - ranIp + - ranPort + - ranName + properties: + ranIp: + type: string + ranPort: + type: integer + format: uint16 + ranName: + type: string + ErrorResponse: + type: object + required: + - errorCode + - errorMessage + properties: + errorCode: + type: string + description: 401 - corrupted json, 402 - validation error, 501 - internal problem + errorMessage: + type: string + description: Human readable text diff --git a/e2-mgr-client/src/test/java/org/oransc/ric/portal/dashboard/e2mgr/client/test/E2ManagerClientTest.java b/e2-mgr-client/src/test/java/org/oransc/ric/portal/dashboard/e2mgr/client/test/E2ManagerClientTest.java index fa48e693..a740f05e 100644 --- a/e2-mgr-client/src/test/java/org/oransc/ric/portal/dashboard/e2mgr/client/test/E2ManagerClientTest.java +++ b/e2-mgr-client/src/test/java/org/oransc/ric/portal/dashboard/e2mgr/client/test/E2ManagerClientTest.java @@ -20,7 +20,7 @@ package org.oransc.ric.portal.dashboard.e2mgr.client.test; import org.junit.jupiter.api.Test; -import org.oransc.ric.e2mgr.client.api.HealthCheckApi; +import org.oransc.ric.e2mgr.client.api.E2ManagerApi; import org.oransc.ric.e2mgr.client.invoker.ApiClient; import org.springframework.web.client.RestClientException; @@ -35,9 +35,9 @@ public class E2ManagerClientTest { public void demo() { ApiClient apiClient = new ApiClient(); apiClient.setBasePath("http://localhost:30099/"); - HealthCheckApi e2Health = new HealthCheckApi(apiClient); + E2ManagerApi e2Api = new E2ManagerApi(apiClient); try { - e2Health.healthCheck(); + e2Api.healthCheck(); System.out.println("getHealth answered: " + apiClient.getStatusCode().toString()); } catch (RestClientException e) { System.err.println("getHealth failed: " + e.toString()); diff --git a/pom.xml b/pom.xml index 93842b07..8ad5487e 100644 --- a/pom.xml +++ b/pom.xml @@ -43,10 +43,11 @@ limitations under the License. ========================LICENSE_END=================================== + a1-med-client + e2-mgr-client + xapp-mgr-client webapp-frontend webapp-backend - xapp-mgr-client - e2-mgr-client diff --git a/webapp-backend/pom.xml b/webapp-backend/pom.xml index 6f7147c3..26d8f8aa 100644 --- a/webapp-backend/pom.xml +++ b/webapp-backend/pom.xml @@ -31,10 +31,16 @@ limitations under the License. RIC Dashboard Webapp backend 1.8 + + true 2.9.2 - ${env.NEXUS3_PUSH_REGISTRY} + + org.o-ran-sc.ric.a1med.client + a1-med-client + 0.3.0-SNAPSHOT + org.o-ran-sc.ric.e2mgr.client e2-mgr-client @@ -147,9 +153,9 @@ limitations under the License. 0.28.0 true - - nexus3.oran-osc.org:10001 - ${docker.push.registry} + + ${env.CONTAINER_PULL_REGISTRY} + ${env.CONTAINER_PUSH_REGISTRY} diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorConfiguration.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorConfiguration.java new file mode 100644 index 00000000..3cd81ede --- /dev/null +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorConfiguration.java @@ -0,0 +1,66 @@ +/*- + * ========================LICENSE_START================================= + * ORAN-OSC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard.config; + +import java.lang.invoke.MethodHandles; + +import org.oransc.ric.a1med.client.api.A1MediatorApi; +import org.oransc.ric.a1med.client.invoker.ApiClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.util.Assert; +import org.springframework.web.client.RestTemplate; + +/** + * Creates an A1 mediator client as a bean to be managed by the Spring container. + */ +@Configuration +@Profile("!mock") +public class A1MediatorConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + // Populated by the autowired constructor + private final String a1medBasepath; + + @Autowired + public A1MediatorConfiguration(@Value("${a1med.basepath}") final String a1medBasepath) { + Assert.notNull(a1medBasepath, "base path must not be null"); + logger.info("Configuring A1 Mediator at base path {}", a1medBasepath); + this.a1medBasepath = a1medBasepath; + } + + private ApiClient apiClient() { + ApiClient apiClient = new ApiClient(new RestTemplate()); + apiClient.setBasePath(a1medBasepath); + return apiClient; + } + + @Bean + public A1MediatorApi a1MediatorApi() { + return new A1MediatorApi(apiClient()); + } + +} diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorMockConfiguration.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorMockConfiguration.java new file mode 100644 index 00000000..d9301612 --- /dev/null +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorMockConfiguration.java @@ -0,0 +1,74 @@ +/*- + * ========================LICENSE_START================================= + * ORAN-OSC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard.config; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.lang.invoke.MethodHandles; + +import org.oransc.ric.a1med.client.api.A1MediatorApi; +import org.oransc.ric.a1med.client.invoker.ApiClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.http.HttpStatus; + +/** + * Creates a mock implementation of the E2 manager client API. + */ +@Profile("mock") +@Configuration +public class A1MediatorMockConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + public A1MediatorMockConfiguration() { + logger.info("Configuring mock A1 Mediator"); + } + + private ApiClient apiClient() { + ApiClient mockClient = mock(ApiClient.class); + when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK); + return mockClient; + } + + @Bean + public A1MediatorApi a1MediatorApi() { + ApiClient apiClient = apiClient(); + A1MediatorApi mockApi = mock(A1MediatorApi.class); + when(mockApi.getApiClient()).thenReturn(apiClient); + + doAnswer(i -> { + return null; + }).when(mockApi).a1ControllerGetHandler(any(String.class)); + + doAnswer(i -> { + return null; + }).when(mockApi).a1ControllerPutHandler(any(String.class), any(Object.class)); + + return mockApi; + } + +} diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerConfiguration.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerConfiguration.java index 3b610b55..3026e870 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerConfiguration.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerConfiguration.java @@ -21,9 +21,7 @@ package org.oransc.ric.portal.dashboard.config; import java.lang.invoke.MethodHandles; -import org.oransc.ric.e2mgr.client.api.EndcSetupRequestApi; -import org.oransc.ric.e2mgr.client.api.HealthCheckApi; -import org.oransc.ric.e2mgr.client.api.X2SetupRequestApi; +import org.oransc.ric.e2mgr.client.api.E2ManagerApi; import org.oransc.ric.e2mgr.client.invoker.ApiClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,18 +59,8 @@ public class E2ManagerConfiguration { } @Bean - public EndcSetupRequestApi endcSetupRequestApi() { - return new EndcSetupRequestApi(apiClient()); - } - - @Bean - public HealthCheckApi healthCheckApi() { - return new HealthCheckApi(apiClient()); - } - - @Bean - public X2SetupRequestApi x2SetupRequestApi() { - return new X2SetupRequestApi(apiClient()); + public E2ManagerApi e2ManagerApi() { + return new E2ManagerApi(apiClient()); } } diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java index 3df6dc70..f5b59d4e 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java @@ -26,9 +26,7 @@ import static org.mockito.Mockito.when; import java.lang.invoke.MethodHandles; -import org.oransc.ric.e2mgr.client.api.EndcSetupRequestApi; -import org.oransc.ric.e2mgr.client.api.HealthCheckApi; -import org.oransc.ric.e2mgr.client.api.X2SetupRequestApi; +import org.oransc.ric.e2mgr.client.api.E2ManagerApi; import org.oransc.ric.e2mgr.client.invoker.ApiClient; import org.oransc.ric.e2mgr.client.model.SetupRequest; import org.slf4j.Logger; @@ -39,8 +37,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.http.HttpStatus; /** - * Creates an implementation of the E2 manager client that answers requests with - * mock data. + * Creates a mock implementation of the E2 manager client API. */ @Profile("mock") @Configuration @@ -59,32 +56,23 @@ public class E2ManagerMockConfiguration { } @Bean - public EndcSetupRequestApi endcSetupRequestApi() { + public E2ManagerApi e2ManagerApi() { ApiClient apiClient = apiClient(); - EndcSetupRequestApi mockApi = mock(EndcSetupRequestApi.class); + E2ManagerApi mockApi = mock(E2ManagerApi.class); when(mockApi.getApiClient()).thenReturn(apiClient); - return mockApi; - } - @Bean - public HealthCheckApi healthCheckApi() { - ApiClient apiClient = apiClient(); - HealthCheckApi mockApi = mock(HealthCheckApi.class); - when(mockApi.getApiClient()).thenReturn(apiClient); doAnswer(i -> { return null; }).when(mockApi).healthCheck(); - return mockApi; - } - @Bean - public X2SetupRequestApi x2SetupRequestApi() { - ApiClient apiClient = apiClient(); - X2SetupRequestApi mockApi = mock(X2SetupRequestApi.class); - when(mockApi.getApiClient()).thenReturn(apiClient); + doAnswer(i -> { + return null; + }).when(mockApi).endcSetup(any(SetupRequest.class)); + doAnswer(i -> { return null; }).when(mockApi).setup(any(SetupRequest.class)); + return mockApi; } diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java index 53593a64..ad6ba793 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java @@ -25,8 +25,7 @@ import java.util.Set; import javax.servlet.http.HttpServletResponse; -import org.oransc.ric.e2mgr.client.api.HealthCheckApi; -import org.oransc.ric.e2mgr.client.api.X2SetupRequestApi; +import org.oransc.ric.e2mgr.client.api.E2ManagerApi; import org.oransc.ric.e2mgr.client.model.SetupRequest; import org.oransc.ric.portal.dashboard.DashboardConstants; import org.slf4j.Logger; @@ -57,18 +56,16 @@ public class E2ManagerController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // Populated by the autowired constructor - private final HealthCheckApi healthCheckApi; - private final X2SetupRequestApi x2SetupRequestApi; + private final E2ManagerApi e2ManagerApi; // Tracks the requests previously submitted. // TODO remove when the E2 manager is extended. private Set requests = new HashSet<>(); @Autowired - public E2ManagerController(final HealthCheckApi healthCheckApi, final X2SetupRequestApi x2SetupRequestApi) { - Assert.notNull(healthCheckApi, "API must not be null"); - this.healthCheckApi = healthCheckApi; - this.x2SetupRequestApi = x2SetupRequestApi; + public E2ManagerController(final E2ManagerApi e2ManagerApi) { + Assert.notNull(e2ManagerApi, "API must not be null"); + this.e2ManagerApi = e2ManagerApi; } private void assertNotNull(Object o) { @@ -86,8 +83,8 @@ public class E2ManagerController { @RequestMapping(value = "/health", method = RequestMethod.GET) public void getHealth(HttpServletResponse response) { logger.debug("getHealth"); - healthCheckApi.healthCheck(); - response.setStatus(healthCheckApi.getApiClient().getStatusCode().value()); + e2ManagerApi.healthCheck(); + response.setStatus(e2ManagerApi.getApiClient().getStatusCode().value()); } @ApiOperation(value = "Gets the unique requests submitted to the E2 manager.", response = SetupRequest.class, responseContainer = "List") @@ -111,7 +108,7 @@ public class E2ManagerController { } try { requests.add(setupRequest); - x2SetupRequestApi.setup(setupRequest); + e2ManagerApi.setup(setupRequest); } catch (Exception ex) { logger.error("Failed", ex); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); -- 2.16.6