Moving api classes to controller package
Change-Id: Iccdf2333a1187210638f01d6a360d1d4eaf46b07
diff --git a/rapp-manager/src/main/java/org/oransc/rappmanager/controller/AppController.java b/rapp-manager/src/main/java/org/oransc/rappmanager/controller/AppController.java
index 3bdc4a4..ca1994b 100644
--- a/rapp-manager/src/main/java/org/oransc/rappmanager/controller/AppController.java
+++ b/rapp-manager/src/main/java/org/oransc/rappmanager/controller/AppController.java
@@ -27,10 +27,11 @@
import io.swagger.annotations.ApiResponses;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import org.oransc.rappmanager.exception.ServiceException;
import org.oransc.rappmanager.service.App;
-import org.oransc.rappmanager.service.AppList;
import org.oransc.rappmanager.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -62,7 +63,19 @@
@ApiOperation(value = "Return all Apps")
@ApiResponses(value = {@ApiResponse(code = 200, message = "rApp List")})
public ResponseEntity<AppList> getAllApps() throws ServiceException {
- return new ResponseEntity<>(appService.getAllApps(), HttpStatus.OK);
+ Collection<AppInfo> apps = new ArrayList<>();
+ appService.getAllApps().forEach(app -> apps.add(toAppInfo(app)));
+ AppList list = AppList.builder().apps(apps).build();
+
+ return new ResponseEntity<>(list, HttpStatus.OK);
+ }
+
+ private AppInfo toAppInfo(App app) {
+ return AppInfo.builder() //
+ .name(app.getName()) //
+ .namespace(app.getNamespace()) //
+ .version(app.getVersion()) //
+ .build();
}
@PostMapping(
diff --git a/rapp-manager/src/main/java/org/oransc/rappmanager/service/AppList.java b/rapp-manager/src/main/java/org/oransc/rappmanager/controller/AppList.java
similarity index 89%
rename from rapp-manager/src/main/java/org/oransc/rappmanager/service/AppList.java
rename to rapp-manager/src/main/java/org/oransc/rappmanager/controller/AppList.java
index 2767314..d4911a0 100644
--- a/rapp-manager/src/main/java/org/oransc/rappmanager/service/AppList.java
+++ b/rapp-manager/src/main/java/org/oransc/rappmanager/controller/AppList.java
@@ -16,9 +16,9 @@
* ========================LICENSE_END===================================
*/
-package org.oransc.rappmanager.service;
+package org.oransc.rappmanager.controller;
-import java.util.List;
+import java.util.Collection;
import lombok.Builder;
import lombok.Getter;
@@ -29,5 +29,5 @@
@Builder
public class AppList {
- private List<App> apps;
+ private Collection<AppInfo> apps;
}
diff --git a/rapp-manager/src/main/java/org/oransc/rappmanager/service/AppService.java b/rapp-manager/src/main/java/org/oransc/rappmanager/service/AppService.java
index 2f16455..db2a7df 100644
--- a/rapp-manager/src/main/java/org/oransc/rappmanager/service/AppService.java
+++ b/rapp-manager/src/main/java/org/oransc/rappmanager/service/AppService.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.util.Collection;
import org.oransc.rappmanager.configuration.ApplicationConfig;
import org.oransc.rappmanager.controller.AppInfo;
@@ -44,10 +45,10 @@
@Autowired
ApplicationConfig appConfig;
- public AppList getAllApps() throws ServiceException {
+ public Collection<App> getAllApps() {
// Call Kubernetes api to get the apps- pod, deplyment, statefulset, job?
// Get the apps list this ms managing.
- return AppList.builder().apps(appStore.getAllApp()).build();
+ return appStore.getAllApp();
}
public App getApp(String name, String version) throws ServiceException {
@@ -67,6 +68,7 @@
// call the kubernetes api to create objects (helm call)
// Call the kubernetes api to create namespace
// Validate the override file
+ logger.info("Install app {} {}", app.getName(), app.getVersion());
helmClient.installApp(app);
}
diff --git a/rapp-manager/src/test/java/org/oransc/rappmanager/controller/AppControllerTest.java b/rapp-manager/src/test/java/org/oransc/rappmanager/controller/AppControllerTest.java
index 6fc62e0..778fd0f 100644
--- a/rapp-manager/src/test/java/org/oransc/rappmanager/controller/AppControllerTest.java
+++ b/rapp-manager/src/test/java/org/oransc/rappmanager/controller/AppControllerTest.java
@@ -9,13 +9,13 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Arrays;
+import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.oransc.rappmanager.Application;
import org.oransc.rappmanager.configuration.ApplicationConfig;
import org.oransc.rappmanager.service.App;
-import org.oransc.rappmanager.service.AppList;
import org.oransc.rappmanager.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -51,7 +51,7 @@
@MockBean
private AppService appService;
- private AppList apps;
+ private Collection<App> apps;
@Test
public void testGetAllApps() throws Exception {
@@ -62,7 +62,7 @@
.andExpect(jsonPath("$.apps.[0].name", is("helloworldApp")));
}
- private AppList getAllApps() {
- return AppList.builder().apps(Arrays.asList(App.builder().name("helloworldApp").build())).build();
+ private Collection<App> getAllApps() {
+ return Arrays.asList(App.builder().name("helloworldApp").build());
}
}