Add E2 manager client and controller 83/83/8
authorLott, Christopher (cl778h) <cl778h@att.com>
Wed, 24 Apr 2019 16:48:44 +0000 (12:48 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Thu, 25 Apr 2019 17:59:11 +0000 (13:59 -0400)
Change-Id: I025007db900524ec1247fbea471f27fa82ebc76b
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
18 files changed:
e2-mgr-client/.gitignore [new file with mode: 0644]
e2-mgr-client/README.md [new file with mode: 0644]
e2-mgr-client/pom.xml [new file with mode: 0644]
e2-mgr-client/src/main/resources/e2_mgr_rest_api_v0_0_1.yaml [new file with mode: 0644]
e2-mgr-client/src/test/java/org/oranosc/ric/portal/dashboard/e2mgr/demo/E2ManagerClientTest.java [new file with mode: 0644]
pom.xml
webapp-backend/pom.xml
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/DashboardApplication.java
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/E2ManagerConfiguration.java [new file with mode: 0644]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/XappManagerConfiguration.java
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/E2ManagerController.java [new file with mode: 0644]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/SimpleErrorController.java [new file with mode: 0644]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/XappCatalogController.java [moved from webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/CatalogController.java with 91% similarity]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/XappManagerController.java
webapp-backend/src/main/resources/application.properties
xapp-mgr-client/pom.xml
xapp-mgr-client/src/main/resources/xapp_manager_rest_api_v0_0_10.json [moved from xapp-mgr-client/xapp_manager_rest_api_v0_0_10.json with 100% similarity]
xapp-mgr-client/src/test/java/org/oranosc/ric/portal/dashboard/xmc/demo/XappManagerClientTest.java [moved from xapp-mgr-client/XappManagerClientDemo.java with 65% similarity]

diff --git a/e2-mgr-client/.gitignore b/e2-mgr-client/.gitignore
new file mode 100644 (file)
index 0000000..27fd461
--- /dev/null
@@ -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/e2-mgr-client/README.md b/e2-mgr-client/README.md
new file mode 100644 (file)
index 0000000..50cab55
--- /dev/null
@@ -0,0 +1,19 @@
+# E2 Manager Client Generator
+
+This projects generates a REST client library from the Swagger specification
+file stored here and packages it in a jar.
+
+## 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/e2-mgr-client/pom.xml b/e2-mgr-client/pom.xml
new file mode 100644 (file)
index 0000000..57d9405
--- /dev/null
@@ -0,0 +1,172 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--<![CDATA[
+========================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===================================
+]]>-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.oranosc.ric.portal.dashboard</groupId>
+               <artifactId>ric-dash-parent</artifactId>
+               <version>1.0.0-SNAPSHOT</version>
+       </parent>
+       <groupId>org.oranosc.ric.e2mgr.client</groupId>
+       <artifactId>e2-mgr-client</artifactId>
+       <name>RIC E2 Manager client</name>
+       <version>0.0.1-SNAPSHOT</version>
+       <properties>
+               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+               <swagger-annotations-version>1.5.15</swagger-annotations-version>
+               <client.base.package.name>org.oranosc.ric.e2mgr.client</client.base.package.name>
+       </properties>
+       <!-- Successful compilation requires generated code dependencies -->
+       <dependencies>
+               <dependency>
+                       <groupId>io.swagger</groupId>
+                       <artifactId>swagger-annotations</artifactId>
+                       <version>${swagger-annotations-version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>spring-context</artifactId>
+               </dependency>
+               <!-- HTTP client: Spring RestTemplate -->
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>spring-web</artifactId>
+                       <!-- <version>${spring-web-version}</version> -->
+               </dependency>
+               <!-- JSON processing: jackson -->
+               <dependency>
+                       <groupId>com.fasterxml.jackson.core</groupId>
+                       <artifactId>jackson-core</artifactId>
+                       <!-- <version>${jackson-version}</version> -->
+               </dependency>
+               <dependency>
+                       <groupId>com.fasterxml.jackson.core</groupId>
+                       <artifactId>jackson-annotations</artifactId>
+                       <!-- <version>${jackson-version}</version> -->
+               </dependency>
+               <dependency>
+                       <groupId>com.fasterxml.jackson.core</groupId>
+                       <artifactId>jackson-databind</artifactId>
+                       <!-- <version>${jackson-version}</version> -->
+               </dependency>
+               <dependency>
+                       <groupId>com.fasterxml.jackson.jaxrs</groupId>
+                       <artifactId>jackson-jaxrs-json-provider</artifactId>
+                       <!-- <version>${jackson-version}</version> -->
+               </dependency>
+               <dependency>
+                       <groupId>com.fasterxml.jackson.datatype</groupId>
+                       <artifactId>jackson-datatype-jsr310</artifactId>
+                       <!-- <version>${jackson-version}</version> -->
+               </dependency>
+               <!-- test dependencies -->
+               <dependency>
+                       <groupId>org.junit.jupiter</groupId>
+                       <artifactId>junit-jupiter-api</artifactId>
+                       <!-- spring sets the <version>5.4.2</version> -->
+                       <scope>test</scope>
+               </dependency>
+       </dependencies>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>io.swagger</groupId>
+                               <artifactId>swagger-codegen-maven-plugin</artifactId>
+                               <version>2.3.1</version>
+                               <executions>
+                                       <execution>
+                                               <goals>
+                                                       <goal>generate</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <inputSpec>${project.basedir}/src/main/resources/e2_mgr_rest_api_v0_0_1.yaml</inputSpec>
+                                                       <language>java</language>
+                                                       <configOptions>
+                                                               <groupId>${project.groupId}</groupId>
+                                                               <artifactId>${project.artifactId}</artifactId>
+                                                               <artifactVersion>${project.version}</artifactVersion>
+                                                               <artifactUrl>www.oran-osc.org</artifactUrl>
+                                                               <artifactDescription>E2 manager client library</artifactDescription>
+                                                               <library>resttemplate</library>
+                                                               <java8>true</java8>
+                                                               <dateLibrary>java8</dateLibrary>
+                                                               <licenseName>Apache 2.0</licenseName>
+                                                               <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
+                                                               <scmConnection></scmConnection>
+                                                               <scmDeveloperConnection></scmDeveloperConnection>
+                                                               <scmUrl>http://gerrit.oran-osc.org</scmUrl>
+                                                               <developerName>RIC Team</developerName>
+                                                               <developerEmail></developerEmail>
+                                                               <developerOrganization>AT&amp;T and Nokia</developerOrganization>
+                                                               <developerOrganizationUrl></developerOrganizationUrl>
+                                                       </configOptions>
+                                                       <packageName>${client.base.package.name}</packageName>
+                                                       <modelPackage>${client.base.package.name}.model</modelPackage>
+                                                       <apiPackage>${client.base.package.name}.api</apiPackage>
+                                                       <invokerPackage>${client.base.package.name}.invoker</invokerPackage>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+                       <!-- Require Java 1.8 -->
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                               <!-- Spring sets the <version></version> -->
+                               <configuration>
+                                       <source>1.8</source>
+                                       <target>1.8</target>
+                               </configuration>
+                       </plugin>
+                       <!-- Generate javadoc jar; see profile for Java 8 -->
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-javadoc-plugin</artifactId>
+                               <!-- <version>2.10.3</version> -->
+                               <executions>
+                                       <execution>
+                                               <id>attach-javadocs</id>
+                                               <goals>
+                                                       <goal>jar</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+                       <!-- Generate source jar -->
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-source-plugin</artifactId>
+                               <!-- <version>3.0.0</version> -->
+                               <executions>
+                                       <execution>
+                                               <id>attach-sources</id>
+                                               <goals>
+                                                       <goal>jar</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
diff --git a/e2-mgr-client/src/main/resources/e2_mgr_rest_api_v0_0_1.yaml b/e2-mgr-client/src/main/resources/e2_mgr_rest_api_v0_0_1.yaml
new file mode 100644 (file)
index 0000000..2ab547e
--- /dev/null
@@ -0,0 +1,76 @@
+###
+# ========================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===================================
+###
+---
+swagger: "2.0"
+info:
+  description: "Draft API for RIC e2-manager"
+  version: "0.0.1"
+  title: "RIC e2-manager"
+  license:
+    name: "Apache 2.0"
+    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
+host: "localhost"
+basePath: "/e2/v1"
+schemes:
+  - "http"
+paths:
+  /e2/v1/health:
+    get:
+      summary: "Health check of E2 Manager"
+      operationId: "getHealth"
+      responses:
+        200:
+          description: "Health is good"
+        500:
+          description: "Health is poor"
+  /e2/v1/setup:
+    post:
+      summary: "Set up connection to a RAN element"
+      operationId: "setupRan"
+      consumes:
+        - "application/json"
+      produces:
+        - "application/json"
+      parameters:
+        - in: "body"
+          name: "ranSetupRequest"
+          description: "Setup request with host and port"
+          required: true
+          schema:
+            $ref: "#/definitions/ranSetupRequest"
+      responses:
+        200:
+          description: "Setup successful"
+        400:
+          description: "Invalid input"
+definitions:
+  ranSetupRequest:
+    type: "object"
+    properties:
+      ranIp:
+        type: "string"
+        description: "IPv4/IPv6 address"
+      ranPort:
+        type: "integer"
+        format: "int32"
+        example: 80
+      ranName:
+        type: "string"
+        description: "eNodeB/gNodeB name"
diff --git a/e2-mgr-client/src/test/java/org/oranosc/ric/portal/dashboard/e2mgr/demo/E2ManagerClientTest.java b/e2-mgr-client/src/test/java/org/oranosc/ric/portal/dashboard/e2mgr/demo/E2ManagerClientTest.java
new file mode 100644 (file)
index 0000000..065a76c
--- /dev/null
@@ -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.oranosc.ric.portal.dashboard.e2mgr.demo;
+
+import org.junit.jupiter.api.Test;
+import org.oranosc.ric.e2mgr.client.api.DefaultApi;
+import org.oranosc.ric.e2mgr.client.invoker.ApiClient;
+import org.springframework.web.client.RestClientException;
+
+/**
+ * Demonstrates use of the generated E2 manager client.
+ * 
+ * The test fails because no server is available.
+ */
+public class E2ManagerClientTest {
+
+       @Test
+       public void demo() {
+               ApiClient apiClient = new ApiClient();
+               apiClient.setBasePath("http://localhost:30099/");
+               DefaultApi e2Mgr = new DefaultApi(apiClient);
+               try {
+                       e2Mgr.getHealth();
+                       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 a6d0af7..9928ca0 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,7 @@ limitations under the License.
                <module>webapp-frontend</module>
                <module>webapp-backend</module>
                <module>xapp-mgr-client</module>
+               <module>e2-mgr-client</module>
        </modules>
        <build>
                <plugins>
index b8657ca..b604eed 100644 (file)
@@ -36,7 +36,12 @@ limitations under the License.
        </properties>
        <dependencies>
                <dependency>
-                       <groupId>${project.groupId}</groupId>
+                       <groupId>org.oranosc.ric.e2mgr.client</groupId>
+                       <artifactId>e2-mgr-client</artifactId>
+                       <version>0.0.1-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.oranosc.ric.xappmgr.client</groupId>
                        <artifactId>xapp-mgr-client</artifactId>
                        <version>0.0.10-SNAPSHOT</version>
                </dependency>
@@ -74,6 +79,12 @@ limitations under the License.
                        <artifactId>springfox-swagger-ui</artifactId>
                        <version>${springfox.version}</version>
                </dependency>
+               <dependency>
+                       <groupId>org.junit.jupiter</groupId>
+                       <artifactId>junit-jupiter-api</artifactId>
+                       <!-- spring sets the <version>5.4.2</version> -->
+                       <scope>test</scope>
+               </dependency>
        </dependencies>
        <build>
                <plugins>
index 6f41392..e3ab004 100644 (file)
@@ -25,8 +25,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
 
 @SpringBootApplication
+// Limit the annotation scan to the dashboard classes;
+// exclude the generated client classes!
+@ComponentScan("org.oranosc.ric.portal.dashboard")
 public class DashboardApplication {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
diff --git a/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/E2ManagerConfiguration.java b/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/E2ManagerConfiguration.java
new file mode 100644 (file)
index 0000000..cf750da
--- /dev/null
@@ -0,0 +1,47 @@
+/*-
+ * ========================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.oranosc.ric.portal.dash;
+
+import org.oranosc.ric.e2mgr.client.api.DefaultApi;
+import org.oranosc.ric.e2mgr.client.invoker.ApiClient;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+@Configuration
+public class E2ManagerConfiguration {
+
+       @Value("${e2.manager.base.url}")
+       private String e2ManagerBaseUrl;
+
+       /**
+        * Required by autowired constructor {@link DefaultApi#DefaultApi(ApiClient)}
+        * 
+        * @return Instance of E2 Manager client configured from properties
+        */
+       @Bean
+       public ApiClient e2ManagerClient() {
+               ApiClient apiClient = new ApiClient(new RestTemplate());
+               apiClient.setBasePath(e2ManagerBaseUrl);
+               return apiClient;
+       }
+
+}
index b0f04a7..bdee12c 100644 (file)
  */
 package org.oranosc.ric.portal.dash;
 
-import org.oranosc.ric.portal.dashboard.xmc.api.DefaultApi;
-import org.oranosc.ric.portal.dashboard.xmc.invoker.ApiClient;
+import org.oranosc.ric.xappmgr.client.api.DefaultApi;
+import org.oranosc.ric.xappmgr.client.invoker.ApiClient;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.client.RestTemplate;
 
 @Configuration
-@ComponentScan("org.oranosc.ric.portal")
 public class XappManagerConfiguration {
 
        @Value("${xapp.manager.base.url}")
@@ -40,20 +38,10 @@ public class XappManagerConfiguration {
         * @return Instance of ApiClient configured from properties
         */
        @Bean
-       public ApiClient apiClient() {
-               ApiClient apiClient = new ApiClient();
+       public ApiClient xappApiClient() {
+               ApiClient apiClient = new ApiClient(new RestTemplate());
                apiClient.setBasePath(xappManagerBaseUrl);
                return apiClient;
        }
 
-       /**
-        * Required by autowired constructor {@link ApiClient#ApiClient(RestTemplate)}
-        * 
-        * @return Instance of RestTemplate
-        */
-       @Bean
-       public RestTemplate restTemplate() {
-               return new RestTemplate();
-       }
-
 }
diff --git a/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/E2ManagerController.java b/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/E2ManagerController.java
new file mode 100644 (file)
index 0000000..c76d4aa
--- /dev/null
@@ -0,0 +1,111 @@
+/*-
+ * ========================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.oranosc.ric.portal.dash.controller;
+
+import java.lang.invoke.MethodHandles;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.oranosc.ric.e2mgr.client.api.DefaultApi;
+import org.oranosc.ric.e2mgr.client.model.RanSetupRequest;
+import org.oranosc.ric.portal.dash.DashboardConstants;
+import org.oranosc.ric.portal.dash.model.SuccessTransport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * Provides methods to contact the E2 Manager.
+ * 
+ * As of this writing the E2 interface only supports setup connection and check
+ * health actions; it does not support query or close operations on existing
+ * connections. So this class mocks up some of that needed functionality.
+ */
+@Configuration
+@RestController
+@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr", produces = MediaType.APPLICATION_JSON_VALUE)
+public class E2ManagerController {
+
+       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+       @Autowired
+       private DefaultApi e2ManagerClient;
+
+       // Tracks the requests previously submitted.
+       // TODO remove when the E2 manager is extended.
+       private Set<RanSetupRequest> requests = new HashSet<>();
+
+       private void assertNotNull(Object o) {
+               if (o == null)
+                       throw new IllegalArgumentException("Null not permitted");
+       }
+
+       private void assertNotEmpty(String s) {
+               assertNotNull(s);
+               if (s.isEmpty())
+                       throw new IllegalArgumentException("Empty not permitted");
+       }
+
+       @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.", response = String.class)
+       @RequestMapping(value = "/health", method = RequestMethod.GET)
+       public SuccessTransport getHealth() {
+               logger.debug("getHealth");
+               return new SuccessTransport();
+       }
+
+       @ApiOperation(value = "Gets the unique requests submitted to the E2 manager.", response = RanSetupRequest.class, responseContainer = "List")
+       @RequestMapping(value = "/setup", method = RequestMethod.GET)
+       public Iterable<RanSetupRequest> getRequests() {
+               logger.debug("getRequests");
+               return requests;
+       }
+
+       @ApiOperation(value = "Sets up a RAN connection via the E2 manager.")
+       @RequestMapping(value = "/setup", method = RequestMethod.POST)
+       public void setup(@RequestBody RanSetupRequest rsr, HttpServletResponse response) {
+               logger.debug("setup {}", rsr);
+               try {
+                       assertNotEmpty(rsr.getRanIp());
+                       assertNotEmpty(rsr.getRanName());
+                       assertNotNull(rsr.getRanPort());
+               } catch (Exception ex) {
+                       logger.error("Bad request", ex);
+                       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+               }
+               try {
+                       requests.add(rsr);
+                       e2ManagerClient.setupRan(rsr);
+               } catch (Exception ex) {
+                       logger.error("Failed", ex);
+                       response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+               }
+       }
+
+}
diff --git a/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/SimpleErrorController.java b/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/SimpleErrorController.java
new file mode 100644 (file)
index 0000000..f7180d3
--- /dev/null
@@ -0,0 +1,100 @@
+/*-
+ * ========================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.oranosc.ric.portal.dash.controller;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.web.servlet.error.ErrorAttributes;
+import org.springframework.boot.web.servlet.error.ErrorController;
+import org.springframework.util.Assert;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.context.request.ServletWebRequest;
+import org.springframework.web.context.request.WebRequest;
+
+import springfox.documentation.annotations.ApiIgnore;
+
+/**
+ * Returns JSON on error within the Spring-managed context. Does not fire for
+ * anything else; e.g., resource not found outside the context. If trace is
+ * requested via request parameter ("?trace=true") and available, adds stack
+ * trace information to the standard JSON error response.
+ * 
+ * Excluded from Swagger API documentation.
+ * 
+ * https://stackoverflow.com/questions/25356781/spring-boot-remove-whitelabel-error-page
+ * https://www.baeldung.com/spring-boot-custom-error-page
+ */
+@ApiIgnore
+@RestController
+public class SimpleErrorController implements ErrorController {
+
+       private static final String ERROR_PATH = "/error";
+       private static final String TRACE = "trace";
+       private final ErrorAttributes errorAttributes;
+
+       /**
+        * Constructor
+        * 
+        * @param errorAttributes
+        *                            error attributes must not be null
+        */
+       @Autowired
+       public SimpleErrorController(ErrorAttributes errorAttributes) {
+               Assert.notNull(errorAttributes, "ErrorAttributes must not be null");
+               this.errorAttributes = errorAttributes;
+       }
+
+       @Override
+       public String getErrorPath() {
+               return ERROR_PATH;
+       }
+
+       /**
+        * Builds a map with error details
+        * 
+        * @param aRequest
+        *                     HttpServletRequest
+        * @return Map of String to Object
+        */
+       @RequestMapping(ERROR_PATH)
+       public Map<String, Object> error(HttpServletRequest aRequest) {
+               Map<String, Object> body = getErrorAttributes(aRequest, getTraceParameter(aRequest));
+               body.put("decorated-by", SimpleErrorController.class.getName());
+               body.computeIfPresent(TRACE, (key, value) -> body.put(TRACE, ((String) value).split("\n\t")));
+               return body;
+       }
+
+       private boolean getTraceParameter(HttpServletRequest request) {
+               String parameter = request.getParameter(TRACE);
+               if (parameter == null)
+                       return false;
+               return !"false".equalsIgnoreCase(parameter);
+       }
+
+       private Map<String, Object> getErrorAttributes(HttpServletRequest aRequest, boolean includeStackTrace) {
+               WebRequest webRequest = new ServletWebRequest(aRequest);
+               return errorAttributes.getErrorAttributes(webRequest, includeStackTrace);
+       }
+
+}
@@ -22,9 +22,9 @@ package org.oranosc.ric.portal.dash.controller;
 import java.lang.invoke.MethodHandles;
 
 import org.oranosc.ric.portal.dash.DashboardConstants;
-import org.oranosc.ric.portal.dashboard.xmc.model.AllXapps;
-import org.oranosc.ric.portal.dashboard.xmc.model.Xapp;
-import org.oranosc.ric.portal.dashboard.xmc.model.Xapp.StatusEnum;
+import org.oranosc.ric.xappmgr.client.model.AllXapps;
+import org.oranosc.ric.xappmgr.client.model.Xapp;
+import org.oranosc.ric.xappmgr.client.model.Xapp.StatusEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.MediaType;
@@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 @RestController
 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/catalog", produces = MediaType.APPLICATION_JSON_VALUE)
-public class CatalogController {
+public class XappCatalogController {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
index 1e4e522..c70958c 100644 (file)
@@ -22,8 +22,8 @@ package org.oranosc.ric.portal.dash.controller;
 import java.lang.invoke.MethodHandles;
 
 import org.oranosc.ric.portal.dash.DashboardConstants;
-import org.oranosc.ric.portal.dashboard.xmc.api.DefaultApi;
-import org.oranosc.ric.portal.dashboard.xmc.model.AllXapps;
+import org.oranosc.ric.xappmgr.client.api.DefaultApi;
+import org.oranosc.ric.xappmgr.client.model.AllXapps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
index 1c2f09b..5e8ba9d 100644 (file)
 ###
 # Default properties for the RIC Dashboard backend REST server
 
+# This lacks any spring prefix
+# The server port number is chosen RANDOMLY when running a test
+server.port = 8080
+
 # A1 mediation URL is editable
 a1.mediation.url = http://localhost:12345
 a1.mediation.delay.path = /a1ric/delay
 a1.mediation.load.path = /a1ric/load
 a1.mediation.metrics.path = /a1ric/metrics
 
-xapp.manager.base.url = http://localhost:30099
\ No newline at end of file
+# E2
+e2.manager.base.url = http://localhost:30098
+
+# Xapp Manager (not A1 mediator)
+xapp.manager.base.url = http://localhost:30099
index cc54940..2659dbf 100644 (file)
@@ -27,6 +27,7 @@ limitations under the License.
                <artifactId>ric-dash-parent</artifactId>
                <version>1.0.0-SNAPSHOT</version>
        </parent>
+        <groupId>org.oranosc.ric.xappmgr.client</groupId>
        <artifactId>xapp-mgr-client</artifactId>
        <name>RIC xApp Manager client</name>
        <version>0.0.10-SNAPSHOT</version>
@@ -34,7 +35,7 @@ limitations under the License.
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <swagger-annotations-version>1.5.15</swagger-annotations-version>
-               <client.base.package.name>${project.groupId}.xmc</client.base.package.name>
+               <client.base.package.name>org.oranosc.ric.xappmgr.client</client.base.package.name>
        </properties>
        <!-- Successful compilation requires generated code dependencies -->
        <dependencies>
@@ -81,9 +82,9 @@ limitations under the License.
                </dependency>
                <!-- test dependencies -->
                <dependency>
-                       <groupId>junit</groupId>
-                       <artifactId>junit</artifactId>
-                       <!-- <version>${junit-version}</version> -->
+                       <groupId>org.junit.jupiter</groupId>
+                       <artifactId>junit-jupiter-api</artifactId>
+                       <!-- spring sets the <version>5.4.2</version> -->
                        <scope>test</scope>
                </dependency>
        </dependencies>
@@ -99,7 +100,7 @@ limitations under the License.
                                                        <goal>generate</goal>
                                                </goals>
                                                <configuration>
-                                                       <inputSpec>${project.basedir}/xapp_manager_rest_api_v0_0_10.json</inputSpec>
+                                                       <inputSpec>${project.basedir}/src/main/resources/xapp_manager_rest_api_v0_0_10.json</inputSpec>
                                                        <language>java</language>
                                                        <configOptions>
                                                                <groupId>${project.groupId}</groupId>
  */
 package org.oranosc.ric.portal.dashboard.xmc.demo;
 
-import org.oranosc.ric.portal.dashboard.api.DefaultApi;
-import org.oranosc.ric.portal.dashboard.model.AllXapps;
-import org.oranosc.ric.portal.dashboard.invoker.ApiClient;
-import org.oranosc.ric.portal.dashboard.model.Xapp;
+import org.junit.jupiter.api.Test;
+import org.oranosc.ric.xappmgr.client.api.DefaultApi;
+import org.oranosc.ric.xappmgr.client.invoker.ApiClient;
+import org.oranosc.ric.xappmgr.client.model.AllXapps;
+import org.oranosc.ric.xappmgr.client.model.Xapp;
 import org.springframework.web.client.RestClientException;
 
-public class XappManagerClientDemo {
+/**
+ * Demonstrates use of the generated xApp manager client.
+ * 
+ * The test fails because no server is available.
+ */
+public class XappManagerClientTest {
 
-       public static void main(String[] args) {
+       @Test
+       public void demo() {
                ApiClient apiClient = new ApiClient();
                apiClient.setBasePath("http://localhost:30099/");
                DefaultApi apiInstance = new DefaultApi(apiClient);
                try {
                        apiInstance.getHealth();
-                       System.out.println("Healthcheck answered " + apiClient.getStatusCode().toString());
+                       System.out.println("getHealth answered: " + apiClient.getStatusCode().toString());
                } catch (RestClientException e) {
-                       System.err.println("Failed on DefaultApi#getHealth: " + e.toString());
+                       System.err.println("getHealth failed: " + e.toString());
                }
                try {
                        AllXapps allXapps = apiInstance.getAllXapps();
-                       System.out.println("getAllXapps answered " + apiClient.getStatusCode().toString());
+                       System.out.println("getAllXapps answered: " + apiClient.getStatusCode().toString());
                        System.out.println("xApp count: " + allXapps.size());
                        for (Xapp x : allXapps)
                                System.out.println("xApp: " + x.toString());
                } catch (RestClientException e) {
-                       System.err.println("Failed on DefaultApi#getAllXapps: " + e.toString());
+                       System.err.println("getAllXapps failed: " + e.toString());
                }
        }