Add (un)deploy actions in xapp mgr controller 85/85/7
authorLott, Christopher (cl778h) <cl778h@att.com>
Thu, 25 Apr 2019 18:59:15 +0000 (14:59 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Fri, 26 Apr 2019 19:46:26 +0000 (15:46 -0400)
Add mock implementations of E2, xapp.
Also adjust config keys to match configmap

Change-Id: I0427160c9d2018e509064d9afe5746f596363945
Issue-Id: RICPLT-959
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
21 files changed:
e2-mgr-client/README.md
e2-mgr-client/pom.xml
e2-mgr-client/src/test/java/org/oranosc/ric/portal/dashboard/e2mgr/demo/E2ManagerClientTest.java
webapp-backend/README.md [new file with mode: 0644]
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/config/E2ManagerConfiguration.java [moved from webapp-backend/src/main/java/org/oranosc/ric/portal/dash/E2ManagerConfiguration.java with 64% similarity]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/E2ManagerMockConfiguration.java [new file with mode: 0644]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/SwaggerConfiguration.java [moved from webapp-backend/src/main/java/org/oranosc/ric/portal/dash/SwaggerConfiguration.java with 93% similarity]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/XappManagerConfiguration.java [moved from webapp-backend/src/main/java/org/oranosc/ric/portal/dash/XappManagerConfiguration.java with 63% similarity]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/XappManagerMockConfiguration.java [new file with mode: 0644]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/A1MediationController.java
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/E2ManagerController.java
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/XappCatalogController.java [deleted file]
webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/XappManagerController.java
webapp-backend/src/main/resources/application.properties
webapp-backend/src/test/java/org/oranosc/ric/portal/dash/DashboardApplicationTest.java [moved from webapp-backend/src/test/java/org/oranosc/ric/portal/dash/test/DashboardApplicationTests.java with 92% similarity]
webapp-frontend/README.md
webapp-frontend/package.json
xapp-mgr-client/README.md
xapp-mgr-client/pom.xml

index 50cab55..ed478dd 100644 (file)
@@ -3,6 +3,16 @@
 This projects generates a REST client library from the Swagger 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.
index 57d9405..372f9da 100644 (file)
@@ -93,7 +93,7 @@ limitations under the License.
                        <plugin>
                                <groupId>io.swagger</groupId>
                                <artifactId>swagger-codegen-maven-plugin</artifactId>
-                               <version>2.3.1</version>
+                               <version>2.4.5</version>
                                <executions>
                                        <execution>
                                                <goals>
@@ -167,6 +167,45 @@ limitations under the License.
                                        </execution>
                                </executions>
                        </plugin>
+                       <!-- Skip the deploy-jar-to-nexus step -->
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-deploy-plugin</artifactId>
+                               <!-- Spring sets the <version>2.8</version> -->
+                               <configuration>
+                                       <skip>true</skip>
+                               </configuration>
+                       </plugin>
                </plugins>
+               <pluginManagement>
+                       <plugins>
+                               <!--This plugin's configuration is used to store Eclipse m2e settings 
+                                       only. It has no influence on the Maven build itself. -->
+                               <plugin>
+                                       <groupId>org.eclipse.m2e</groupId>
+                                       <artifactId>lifecycle-mapping</artifactId>
+                                       <version>1.0.0</version>
+                                       <configuration>
+                                               <lifecycleMappingMetadata>
+                                                       <pluginExecutions>
+                                                               <pluginExecution>
+                                                                       <pluginExecutionFilter>
+                                                                               <groupId>io.swagger</groupId>
+                                                                               <artifactId>swagger-codegen-maven-plugin</artifactId>
+                                                                               <versionRange>[1.0,)</versionRange>
+                                                                               <goals>
+                                                                                       <goal>generate</goal>
+                                                                               </goals>
+                                                                       </pluginExecutionFilter>
+                                                                       <action>
+                                                                               <ignore />
+                                                                       </action>
+                                                               </pluginExecution>
+                                                       </pluginExecutions>
+                                               </lifecycleMappingMetadata>
+                                       </configuration>
+                               </plugin>
+                       </plugins>
+               </pluginManagement>
        </build>
 </project>
index 065a76c..56e6cfc 100644 (file)
@@ -40,7 +40,7 @@ public class E2ManagerClientTest {
                        e2Mgr.getHealth();
                        System.out.println("getHealth answered: " + apiClient.getStatusCode().toString());
                } catch (RestClientException e) {
-                       System.err.println("getHealth failed: " +  e.toString());
+                       System.err.println("getHealth failed: " + e.toString());
                }
        }
 }
diff --git a/webapp-backend/README.md b/webapp-backend/README.md
new file mode 100644 (file)
index 0000000..04da1a9
--- /dev/null
@@ -0,0 +1,20 @@
+# RIC Dashboard Web Application Backend
+
+## Development server
+
+Run `mvn -Dspring.profiles.active=mock spring-boot:run` for a dev server. Navigate to `http://localhost:8080/swagger-ui.html`. 
+
+## 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.
index b604eed..3b06ab9 100644 (file)
@@ -49,25 +49,17 @@ limitations under the License.
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
-               <dependency>
-                       <groupId>org.springframework.boot</groupId>
-                       <artifactId>spring-boot-starter-test</artifactId>
-                       <scope>test</scope>
-               </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
-                       <!-- Spring-boot sets the version -->
                </dependency>
                <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
-                       <!-- Spring-boot sets the version -->
                </dependency>
                <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-core</artifactId>
-                       <!-- Spring-boot sets the version -->
                </dependency>
                <dependency>
                        <groupId>io.springfox</groupId>
@@ -79,10 +71,15 @@ limitations under the License.
                        <artifactId>springfox-swagger-ui</artifactId>
                        <version>${springfox.version}</version>
                </dependency>
+               <!-- Mockito supports development, not just testing -->
                <dependency>
-                       <groupId>org.junit.jupiter</groupId>
-                       <artifactId>junit-jupiter-api</artifactId>
-                       <!-- spring sets the <version>5.4.2</version> -->
+                       <groupId>org.mockito</groupId>
+                       <artifactId>mockito-core</artifactId>
+               </dependency>
+               <!-- Test dependencies -->
+               <dependency>
+                       <groupId>org.springframework.boot</groupId>
+                       <artifactId>spring-boot-starter-test</artifactId>
                        <scope>test</scope>
                </dependency>
        </dependencies>
index e3ab004..bac38b8 100644 (file)
@@ -30,7 +30,7 @@ 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")
+@ComponentScan("org.oranosc.ric.portal.dash")
 public class DashboardApplication {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oranosc.ric.portal.dash;
+package org.oranosc.ric.portal.dash.config;
 
 import org.oranosc.ric.e2mgr.client.api.DefaultApi;
 import org.oranosc.ric.e2mgr.client.invoker.ApiClient;
+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.util.Assert;
 import org.springframework.web.client.RestTemplate;
 
+/**
+ * Creates an E2 manager client as a bean to be managed by the Spring container.
+ */
 @Configuration
 public class E2ManagerConfiguration {
 
-       @Value("${e2.manager.base.url}")
-       private String e2ManagerBaseUrl;
+       // Populated by the autowired constructor
+       private final String e2mgrBasepath;
+
+       @Autowired
+       public E2ManagerConfiguration(@Value("${e2mgr.basepath}") final String e2mgrBasepath) {
+               Assert.notNull(e2mgrBasepath, "base path must not be null");
+               this.e2mgrBasepath = e2mgrBasepath;
+       }
 
        /**
-        * Required by autowired constructor {@link DefaultApi#DefaultApi(ApiClient)}
-        * 
-        * @return Instance of E2 Manager client configured from properties
+        * @return A DefaultApi with an ApiClient configured from properties
         */
        @Bean
-       public ApiClient e2ManagerClient() {
+       public DefaultApi e2ManagerClient() {
                ApiClient apiClient = new ApiClient(new RestTemplate());
-               apiClient.setBasePath(e2ManagerBaseUrl);
-               return apiClient;
+               apiClient.setBasePath(e2mgrBasepath);
+               return new DefaultApi(apiClient);
        }
 
 }
diff --git a/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/E2ManagerMockConfiguration.java b/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/E2ManagerMockConfiguration.java
new file mode 100644 (file)
index 0000000..e57992a
--- /dev/null
@@ -0,0 +1,64 @@
+/*-
+ * ========================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.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 org.oranosc.ric.e2mgr.client.api.DefaultApi;
+import org.oranosc.ric.e2mgr.client.invoker.ApiClient;
+import org.oranosc.ric.e2mgr.client.model.RanSetupRequest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+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.
+ */
+@Profile("mock")
+@Configuration
+public class E2ManagerMockConfiguration {
+
+       @Bean
+       @Primary
+       public DefaultApi e2ManagerMockClient() {
+               ApiClient mockClient = mock(ApiClient.class);
+               when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
+
+               DefaultApi mockApi = mock(DefaultApi.class);
+               when(mockApi.getApiClient()).thenReturn(mockClient);
+
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).getHealth();
+
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).setupRan(any(RanSetupRequest.class));
+
+               return mockApi;
+       }
+
+}
@@ -18,8 +18,9 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oranosc.ric.portal.dash;
+package org.oranosc.ric.portal.dash.config;
 
+import org.oranosc.ric.portal.dash.DashboardApplication;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -55,7 +56,7 @@ public class SwaggerConfiguration {
                final String version = DashboardApplication.class.getPackage().getImplementationVersion();
                return new ApiInfoBuilder() //
                                .title("RIC Dashboard backend") //
-                               .description("Provides demonstration services.")//
+                               .description("Proxies access to RIC services.")//
                                .termsOfServiceUrl("Terms of service") //
                                .contact(new Contact("RIC Dashboard Dev Team", //
                                                "http://no-docs-yet.org/", //
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oranosc.ric.portal.dash;
+package org.oranosc.ric.portal.dash.config;
 
 import org.oranosc.ric.xappmgr.client.api.DefaultApi;
 import org.oranosc.ric.xappmgr.client.invoker.ApiClient;
+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.util.Assert;
 import org.springframework.web.client.RestTemplate;
 
+/**
+ * Creates an xApp manager client as a bean to be managed by the Spring
+ * container.
+ */
 @Configuration
 public class XappManagerConfiguration {
 
-       @Value("${xapp.manager.base.url}")
-       private String xappManagerBaseUrl;
+       // Populated by the autowired constructor
+       private final String xappMgrBasepath;
+
+       @Autowired
+       public XappManagerConfiguration(@Value("${xappmgr.basepath}") final String xappMgrBasepath) {
+               Assert.notNull(xappMgrBasepath, "base path must not be null");
+               this.xappMgrBasepath = xappMgrBasepath;
+       }
 
        /**
-        * Required by autowired constructor {@link DefaultApi#DefaultApi(ApiClient)}
-        * 
-        * @return Instance of ApiClient configured from properties
+        * @return A DefaultApi with an ApiClient configured from properties
         */
        @Bean
-       public ApiClient xappApiClient() {
+       public DefaultApi xappClient() {
                ApiClient apiClient = new ApiClient(new RestTemplate());
-               apiClient.setBasePath(xappManagerBaseUrl);
-               return apiClient;
+               apiClient.setBasePath(xappMgrBasepath);
+               return new DefaultApi(apiClient);
        }
 
 }
diff --git a/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/XappManagerMockConfiguration.java b/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/config/XappManagerMockConfiguration.java
new file mode 100644 (file)
index 0000000..4829097
--- /dev/null
@@ -0,0 +1,94 @@
+/*-
+ * ========================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.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 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.SubscriptionRequest;
+import org.oranosc.ric.xappmgr.client.model.SubscriptionResponse;
+import org.oranosc.ric.xappmgr.client.model.XAppInfo;
+import org.oranosc.ric.xappmgr.client.model.Xapp;
+import org.oranosc.ric.xappmgr.client.model.Xapp.StatusEnum;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.context.annotation.Profile;
+import org.springframework.http.HttpStatus;
+
+/**
+ * Creates an implementation of the xApp manager client that answers requests
+ * with mock data.
+ */
+@Profile("mock")
+@Configuration
+public class XappManagerMockConfiguration {
+
+       private final AllXapps allXapps;
+
+       public XappManagerMockConfiguration() {
+               allXapps = new AllXapps();
+               allXapps.add(new Xapp().name("Pendulum Control").version("v1").status(StatusEnum.DEPLOYED));
+               allXapps.add(new Xapp().name("Dual Connectivity").version("v2").status(StatusEnum.DELETED));
+               allXapps.add(new Xapp().name("Admission Control").version("v3").status(StatusEnum.FAILED));
+               allXapps.add(new Xapp().name("ANR Control").version("v0").status(StatusEnum.SUPERSEDED));
+       }
+
+       @Bean
+       @Primary
+       public DefaultApi xappManagerMockClient() {
+               ApiClient mockClient = mock(ApiClient.class);
+               when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
+
+               DefaultApi mockApi = mock(DefaultApi.class);
+               when(mockApi.getApiClient()).thenReturn(mockClient);
+
+               SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
+                               .id("subid").version(1);
+               when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
+
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).deleteSubscription(any(Integer.class));
+
+               when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp());
+
+               when(mockApi.getAllXapps()).thenReturn(allXapps);
+
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).getHealth();
+
+               Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1");
+               when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName);
+
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).undeployXapp(any(String.class));
+
+               return mockApi;
+       }
+
+}
index f498729..68b4292 100644 (file)
@@ -71,13 +71,13 @@ public class A1MediationController {
        private static final String A1_MEDIATION_METRICS = "metrics";
        private static final String A1_MEDIATION_METRICS_PATH = A1_MEDIATION_METRICS + "path";
 
-       @Value("${a1.mediation.url}")
+       @Value("${a1med.basepath}")
        private String a1MediationUrl;
-       @Value("${a1.mediation.delay.path}")
+       @Value("${a1med.delaypath}")
        private String a1MediationDelayPath;
-       @Value("${a1.mediation.load.path}")
+       @Value("${a1med.loadpath}")
        private String a1MediationLoadPath;
-       @Value("${a1.mediation.metrics.path}")
+       @Value("${a1med.metricspath}")
        private String a1MediationMetricsPath;
 
        // For demo purposes
index c76d4aa..67cfadf 100644 (file)
@@ -28,12 +28,12 @@ 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.util.Assert;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -55,13 +55,19 @@ public class E2ManagerController {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-       @Autowired
-       private DefaultApi e2ManagerClient;
+       // Populated by the autowired constructor
+       private final DefaultApi e2MgrClient;
 
        // Tracks the requests previously submitted.
        // TODO remove when the E2 manager is extended.
        private Set<RanSetupRequest> requests = new HashSet<>();
 
+       @Autowired
+       public E2ManagerController(final DefaultApi e2MgrClient) {
+               Assert.notNull(e2MgrClient, "client must not be null");
+               this.e2MgrClient = e2MgrClient;
+       }
+
        private void assertNotNull(Object o) {
                if (o == null)
                        throw new IllegalArgumentException("Null not permitted");
@@ -73,11 +79,12 @@ public class E2ManagerController {
                        throw new IllegalArgumentException("Empty not permitted");
        }
 
-       @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.", response = String.class)
+       @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.")
        @RequestMapping(value = "/health", method = RequestMethod.GET)
-       public SuccessTransport getHealth() {
+       public void getHealth(HttpServletResponse response) {
                logger.debug("getHealth");
-               return new SuccessTransport();
+               e2MgrClient.getHealth();
+               response.setStatus(e2MgrClient.getApiClient().getStatusCode().value());
        }
 
        @ApiOperation(value = "Gets the unique requests submitted to the E2 manager.", response = RanSetupRequest.class, responseContainer = "List")
@@ -101,7 +108,7 @@ public class E2ManagerController {
                }
                try {
                        requests.add(rsr);
-                       e2ManagerClient.setupRan(rsr);
+                       e2MgrClient.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/XappCatalogController.java b/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/XappCatalogController.java
deleted file mode 100644 (file)
index b36740a..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * ========================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 org.oranosc.ric.portal.dash.DashboardConstants;
-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;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/catalog", produces = MediaType.APPLICATION_JSON_VALUE)
-public class XappCatalogController {
-
-       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-       @RequestMapping(method = RequestMethod.GET)
-       public AllXapps getXapps() {
-               logger.debug("getXapps: enter");
-               return populateCatalog();
-       }
-
-       // @TODO This method to be removed when endpoint for data fetch from RIC team
-       // available
-       private AllXapps populateCatalog() {
-               AllXapps cList = new AllXapps();
-               cList.add(buildXapp("Pendulum Control", "v1", StatusEnum.DEPLOYED));
-               cList.add(buildXapp("Dual Connectivity", "v2", StatusEnum.DELETED));
-               cList.add(buildXapp("Admission Control", "v1", StatusEnum.FAILED));
-               cList.add(buildXapp("ANR Control", "v0", StatusEnum.SUPERSEDED));
-               return cList;
-       }
-
-       private Xapp buildXapp(String name, String version, StatusEnum status) {
-               Xapp xapp = new Xapp();
-               xapp.setName(name);
-               xapp.setVersion(version);
-               xapp.setStatus(status);
-               return xapp;
-       }
-
-}
index c70958c..094d518 100644 (file)
@@ -21,20 +21,33 @@ package org.oranosc.ric.portal.dash.controller;
 
 import java.lang.invoke.MethodHandles;
 
+import javax.servlet.http.HttpServletResponse;
+
 import org.oranosc.ric.portal.dash.DashboardConstants;
+import org.oranosc.ric.portal.dash.model.ErrorTransport;
 import org.oranosc.ric.xappmgr.client.api.DefaultApi;
 import org.oranosc.ric.xappmgr.client.model.AllXapps;
+import org.oranosc.ric.xappmgr.client.model.XAppInfo;
+import org.oranosc.ric.xappmgr.client.model.Xapp;
 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.util.Assert;
+import org.springframework.web.bind.annotation.PathVariable;
+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;
 
+/**
+ * Mimics the xApp Manager API. These controller methods just proxy calls from
+ * the front-end thru to the real back-end.
+ *
+ */
 @Configuration
 @RestController
 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xappmgr", produces = MediaType.APPLICATION_JSON_VALUE)
@@ -42,15 +55,60 @@ public class XappManagerController {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+       // Populated by the autowired constructor
+       private final DefaultApi xappMgrClient;
+
        @Autowired
-       private DefaultApi xappManagerClient;
+       public XappManagerController(final DefaultApi xappMgrClient) {
+               Assert.notNull(xappMgrClient, "client must not be null");
+               this.xappMgrClient = xappMgrClient;
+       }
+
+       @ApiOperation(value = "Calls the xApp Manager health check.")
+       @RequestMapping(value = "/health", method = RequestMethod.GET)
+       public void getHealth(HttpServletResponse response) {
+               logger.debug("getHealth");
+               xappMgrClient.getHealth();
+               response.setStatus(xappMgrClient.getApiClient().getStatusCode().value());
+       }
 
-       @ApiOperation(value = "Gets the list of xApps from the xApp manager.", response = AllXapps.class)
+       @ApiOperation(value = "Calls the xApp Manager to get the list of xApps.", response = AllXapps.class)
        @RequestMapping(value = "/xapps", method = RequestMethod.GET)
        public AllXapps getAllXapps() {
-               logger.debug("getAllXapps via " + xappManagerClient.getApiClient().getBasePath());
-               AllXapps all = xappManagerClient.getAllXapps();
-               return all;
+               logger.debug("getAllXapps via " + xappMgrClient.getApiClient().getBasePath());
+               return xappMgrClient.getAllXapps();
+       }
+
+       @ApiOperation(value = "Calls the xApp Manager to get the named xApp.", response = Xapp.class)
+       @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.GET)
+       public Xapp getXapp(@PathVariable("xAppName") String xAppName) {
+               logger.debug("getXapp {}", xAppName);
+               return xappMgrClient.getXappByName(xAppName);
+       }
+
+       @ApiOperation(value = "Calls the xApp Manager to deploy the specified Xapp.", response = Xapp.class)
+       @RequestMapping(value = "/xapps", method = RequestMethod.POST)
+       public Object deployXapp(@RequestBody XAppInfo xAppInfo, HttpServletResponse response) {
+               logger.debug("deployXapp {}", xAppInfo);
+               try {
+                       return xappMgrClient.deployXapp(xAppInfo);
+               } catch (Exception ex) {
+                       logger.error("deployXapp failed", ex);
+                       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+                       return new ErrorTransport(500, "deployXapp failed", ex);
+               }
+       }
+
+       @ApiOperation(value = "Calls the xApp Manager to undeploy the named Xapp.")
+       @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.DELETE)
+       public void undeployXapp(@PathVariable("xAppName") String xAppName, HttpServletResponse response) {
+               logger.debug("undeployXapp {}", xAppName);
+               try {
+                       xappMgrClient.undeployXapp(xAppName);
+               } catch (Exception ex) {
+                       logger.error("deployXapp failed", ex);
+                       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+               }
        }
 
 }
index 5e8ba9d..0350ad6 100644 (file)
 # limitations under the License.
 # ========================LICENSE_END===================================
 ###
-# Default properties for the RIC Dashboard backend REST server
+
+# Default properties for the RIC Dashboard backend REST services
 
 # 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
+# A1 Mediator
+a1med.basepath = http://localhost:12345
+a1med.delaypath   = /a1ric/delay
+a1med.loadpath    = /a1ric/load
+a1med.metricspath = /a1ric/metrics
 
-# E2
-e2.manager.base.url = http://localhost:30098
+# E2 Manager
+e2mgr.basepath = http://localhost:30098
 
-# Xapp Manager (not A1 mediator)
-xapp.manager.base.url = http://localhost:30099
+# Xapp Manager
+xappmgr.basepath = http://localhost:30099
@@ -17,7 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oranosc.ric.portal.dash.test;
+package org.oranosc.ric.portal.dash;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -26,7 +26,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class DashboardApplicationTests {
+public class DashboardApplicationTest {
 
        @Test
        public void contextLoads() {
index 2e15b6f..8536fdb 100644 (file)
@@ -4,7 +4,7 @@ This project was generated with [Angular CLI](https://github.com/angular/angular
 
 ## Development server
 
-Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
+Run `./ng serve --proxy-config proxy.conf.json` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
 
 ## Code scaffolding
 
index 588faf9..3cf535d 100644 (file)
@@ -3,7 +3,7 @@
   "version": "0.0.0",
   "scripts": {
     "ng": "ng",
-    "start": "ng serve",
+    "start": "ng serve --proxy-config proxy.conf.json",
     "build": "ng build",
     "test": "ng test",
     "lint": "ng lint",
index 3fcdc31..d6eda84 100644 (file)
@@ -3,6 +3,16 @@
 This projects generates a REST client library from the Swagger 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.
index 2659dbf..ad034ad 100644 (file)
@@ -27,7 +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>
+       <groupId>org.oranosc.ric.xappmgr.client</groupId>
        <artifactId>xapp-mgr-client</artifactId>
        <name>RIC xApp Manager client</name>
        <version>0.0.10-SNAPSHOT</version>
@@ -93,7 +93,7 @@ limitations under the License.
                        <plugin>
                                <groupId>io.swagger</groupId>
                                <artifactId>swagger-codegen-maven-plugin</artifactId>
-                               <version>2.2.3</version>
+                               <version>2.4.5</version>
                                <executions>
                                        <execution>
                                                <goals>
@@ -167,6 +167,45 @@ limitations under the License.
                                        </execution>
                                </executions>
                        </plugin>
+                       <!-- Skip the deploy-jar-to-nexus step -->
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-deploy-plugin</artifactId>
+                               <!-- Spring sets the <version>2.8</version> -->
+                               <configuration>
+                                       <skip>true</skip>
+                               </configuration>
+                       </plugin>
                </plugins>
+               <pluginManagement>
+                       <plugins>
+                               <!--This plugin's configuration is used to store Eclipse m2e settings 
+                                       only. It has no influence on the Maven build itself. -->
+                               <plugin>
+                                       <groupId>org.eclipse.m2e</groupId>
+                                       <artifactId>lifecycle-mapping</artifactId>
+                                       <version>1.0.0</version>
+                                       <configuration>
+                                               <lifecycleMappingMetadata>
+                                                       <pluginExecutions>
+                                                               <pluginExecution>
+                                                                       <pluginExecutionFilter>
+                                                                               <groupId>io.swagger</groupId>
+                                                                               <artifactId>swagger-codegen-maven-plugin</artifactId>
+                                                                               <versionRange>[1.0,)</versionRange>
+                                                                               <goals>
+                                                                                       <goal>generate</goal>
+                                                                               </goals>
+                                                                       </pluginExecutionFilter>
+                                                                       <action>
+                                                                               <ignore/>
+                                                                       </action>
+                                                               </pluginExecution>
+                                                       </pluginExecutions>
+                                               </lifecycleMappingMetadata>
+                                       </configuration>
+                               </plugin>
+                       </plugins>
+               </pluginManagement>
        </build>
 </project>