Update db process part
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / vnfmdriver / controller / VnfmDriverController.java
index 39b6b3f..8dd6832 100644 (file)
@@ -20,9 +20,8 @@ import java.io.IOException;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.http.HttpStatus;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
@@ -35,6 +34,8 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfmDriverMgmrInf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
@@ -49,13 +50,20 @@ import com.google.gson.Gson;
 @Controller
 @RequestMapping(value = "/api/nokiavnfmdriver/v1")
 public class VnfmDriverController {
-       private static final Logger logger = LogManager.getLogger("VnfmDriverController");
+       private static final Logger logger = LoggerFactory.getLogger(VnfmDriverController.class);
        
        @Autowired
        private VnfmDriverMgmrInf vnfmDriverMgmr;
        
        private Gson gson = new Gson();
        
+       @RequestMapping(value = "/swagger.json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+       @ResponseBody
+       public String apidoc() throws IOException {
+        ClassLoader classLoader = getClass().getClassLoader();
+        return IOUtils.toString(classLoader.getResourceAsStream("swagger.json"));
+    }
+       
        @RequestMapping(value = "/{vnfmId}/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
     @ResponseBody
     public InstantiateVnfResponse instantiateVnf(@RequestBody InstantiateVnfRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse)
@@ -65,6 +73,8 @@ public class VnfmDriverController {
                
                InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(request, vnfmId);
                
+               logger.info("InstantiateVnfResponse is " + gson.toJson(response));
+               
                httpResponse.setStatus(HttpStatus.SC_CREATED);
                
                return response;
@@ -84,12 +94,7 @@ public class VnfmDriverController {
                }
                catch(VnfmDriverException e)
                {
-                       try {
-                               httpResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
-                               httpResponse.sendError(e.getHttpStatus(), e.getMessage());
-                       } catch (IOException e1) {
-                               
-                       }
+                       processControllerException(httpResponse, e);
                }
                
                return null;
@@ -109,12 +114,7 @@ public class VnfmDriverController {
                }
                catch(VnfmDriverException e)
                {
-                       try {
-                               httpResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
-                               httpResponse.sendError(e.getHttpStatus(), e.getMessage());
-                       } catch (IOException e1) {
-                               
-                       }
+                       processControllerException(httpResponse, e);
                }
                
                return null;
@@ -132,11 +132,7 @@ public class VnfmDriverController {
                }
                catch(VnfmDriverException e)
                {
-                       try {
-                               httpResponse.sendError(e.getHttpStatus(), e.getMessage());
-                       } catch (IOException e1) {
-                               
-                       }
+                       processControllerException(httpResponse, e);
                }
                
                return null;
@@ -157,11 +153,7 @@ public class VnfmDriverController {
                }
                catch(VnfmDriverException e)
                {
-                       try {
-                               httpResponse.sendError(e.getHttpStatus(), e.getMessage());
-                       } catch (IOException e1) {
-                               
-                       }
+                       processControllerException(httpResponse, e);
                }
                
                return null;
@@ -182,15 +174,21 @@ public class VnfmDriverController {
                }
                catch(VnfmDriverException e)
                {
-                       try {
-                               httpResponse.sendError(e.getHttpStatus(), e.getMessage());
-                       } catch (IOException e1) {
-                               
-                       }
+                       processControllerException(httpResponse, e);
                }
                
                return null;
     }
 
+       private void processControllerException(HttpServletResponse httpResponse, VnfmDriverException e) {
+               try {
+                       logger.error(" VnfmDriverController --> processControllerException", e);
+                       httpResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
+                       httpResponse.sendError(e.getHttpStatus(), e.getMessage());
+               } catch (IOException e1) {
+                       logger.error("VnfmDriverController --> processControllerException error to sendError ", e1);
+               }
+       }
+
 
 }