modify Sonar Issue 24/95024/2
authorHailong Zhang <zhanghailong22@huawei.com>
Thu, 5 Sep 2019 12:07:35 +0000 (20:07 +0800)
committerWeitao Gao <victor.gao@huawei.com>
Mon, 14 Oct 2019 06:49:14 +0000 (06:49 +0000)
Issue-ID: VNFSDK-462

Signed-off-by: Hailong Zhang <zhanghailong22@huawei.com>
Change-Id: I4aa45fbad04b961a1287ed1a4b7bee6cdefd9101

vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java
vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java
vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java

index f05a22f..ad5034e 100644 (file)
@@ -72,7 +72,7 @@ public class PackageWrapper {
 
     private static final boolean DISABLE_VALIDATION = true;
 
-    private static final String fileFormat = ".csar";
+    private static final String FILE_FORMAT = ".csar";
 
     /**
      * get PackageWrapper instance.
@@ -198,7 +198,7 @@ public class PackageWrapper {
                     PackageWrapperUtil.getPackageMeta(packageId, fileName, fileLocation, basicInfo, details);
             try {
                 String path = basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator
-                        + packageMeta.getCsarId() + File.separator + fileName.replace(fileFormat, "") + File.separator
+                        + packageMeta.getCsarId() + File.separator + fileName.replace(FILE_FORMAT, "") + File.separator
                         + basicInfo.getVersion();
 
                 String dowloadUri = File.separator + path + File.separator;
@@ -268,7 +268,7 @@ public class PackageWrapper {
                     .build();
         }
 
-        String fileName = "temp_" + packageId + fileFormat;
+        String fileName = "temp_" + packageId + FILE_FORMAT;
         if(null != fileDetail) {
             LOG.info("the fileDetail = " + ToolUtil.objectToString(fileDetail));
 
@@ -317,6 +317,7 @@ public class PackageWrapper {
         try {
             result = manageUpload(packageId, fileName, fileLocation, details, contentRange);
         } catch(ErrorCodeException e) {
+            LOG.error("ErrorCodeException occurs ",e);
             return Response.status(Status.EXPECTATION_FAILED)
                     .entity(new CommonErrorResponse("Package Name already exists")).build();
         }
@@ -394,7 +395,7 @@ public class PackageWrapper {
         String path = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getHttpServerAbsolutePath()
                 + File.separatorChar + packageData.getType() + File.separatorChar + packageData.getProvider()
                 + File.separatorChar + packageData.getCsarId() + File.separator + packageName + File.separatorChar
-                + packageData.getVersion() + File.separator + packageName + fileFormat;
+                + packageData.getVersion() + File.separator + packageName + FILE_FORMAT;
 
         LOG.info("downloadCsarPackagesById path is :  " + path);
 
index 60cdf65..218d0ad 100644 (file)
@@ -36,6 +36,7 @@ public class VTPModelBase {
             objectMapper.setSerializationInclusion(Include.NON_EMPTY);
             return objectMapper.writeValueAsString(obj);
         } catch (JsonProcessingException e) {
+            logger.error("JsonProcessingException occurs ",e);
             return "{}";
         }
     }
index b50e30f..f613906 100644 (file)
@@ -80,9 +80,11 @@ public class VTPResource {
                     timeout,
                     requestId).run(args);
         } catch(OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption e) {
+            LOG.info("Timed out.", e);
             throw new VTPException(
                   new VTPError().setHttpStatus(HttpStatus.SC_GATEWAY_TIMEOUT).setMessage("Timed out. Please use request-id to track the progress.").setCode(VTPError.TIMEOUT));
         } catch (Exception e) {
+            LOG.info("Exception occurs.", e);
             throw new VTPException(new VTPError().setMessage(e.getMessage()));
         }
 
@@ -123,9 +125,11 @@ public class VTPResource {
                     timeout,
                     requestId).invoke(scenario, profile, testCase, args);
          } catch(OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption e) {
+            LOG.info("Timed out.", e);
              throw new VTPException(
                   new VTPError().setHttpStatus(HttpStatus.SC_GATEWAY_TIMEOUT).setMessage("Timed out. Please use request-id to track the progress.").setCode(VTPError.TIMEOUT));
         } catch (Exception e) {
+            LOG.info("Exception occurs", e);
             throw new VTPException(
                     new VTPError().setMessage(e.getMessage()));
         }
index 5d025c5..83db8e8 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.onap.vtp.execution;
 
+import java.io.EOFException;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.StandardCopyOption;
@@ -27,6 +28,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.logging.Logger;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DefaultValue;
@@ -81,9 +83,11 @@ public class VTPExecutionResource  extends VTPResource{
     private static final String STATUS = "status";
     private static final String OUTPUT = "output";
     private static final String INPUT = "input";
+    private static final String ERROR = "error";
+    private static final String FILE = "file://";
 
 
-    public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException, IOException {
+    public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws Exception {
         if (requestId == null) {
             requestId = UUID.randomUUID().toString();
         }
@@ -116,8 +120,8 @@ public class VTPExecutionResource  extends VTPResource{
             // tests can fail but still produce results.
             ObjectMapper mapper = new ObjectMapper();
             Map<String,String> m = output.getAttrsMap();
-            if ((m.containsKey("error")) && (!StringUtils.equals(m.get("error"), "{}"))) {
-              execution.setResults(mapper.readTree(m.get("error")));
+            if ((m.containsKey(ERROR)) && (!StringUtils.equals(m.get(ERROR), "{}"))) {
+              execution.setResults(mapper.readTree(m.get(ERROR)));
             }
             else if (m.containsKey("results")) {
               execution.setResults(mapper.readTree(m.get("results")));
@@ -170,18 +174,18 @@ public class VTPExecutionResource  extends VTPResource{
     public Response executeTestcases(
              @ApiParam(value = "Request Id") @QueryParam("requestId") String requestId,
              @ApiParam(value = "Testcase File arguments", required = false) @FormDataParam("file") List<FormDataBodyPart> bodyParts,
-             @FormDataParam("executions") String executionsJson) throws VTPException, IOException {
+             @FormDataParam("executions") String executionsJson) throws Exception {
 
         VTPTestExecutionList executions = new VTPTestExecution.VTPTestExecutionList();
         Map<String, String> map = this.storeTestCaseInputFiles(bodyParts);
 
         for (Map.Entry<String, String> entry: map.entrySet()) {
-            if (executionsJson.contains("file://" + entry.getKey())) {
-                executionsJson = executionsJson.replaceAll("file://" + entry.getKey(), entry.getValue());
+            if (executionsJson.contains(FILE + entry.getKey())) {
+                executionsJson = executionsJson.replaceAll(FILE + entry.getKey(), entry.getValue());
             }
         }
 
-        if (executionsJson.contains("file://")) {
+        if (executionsJson.contains(FILE)) {
             VTPError err = new VTPError()
                     .setMessage("Some file form-data is missing as executions has input parameter tagged with file://")
                     .setHttpStatus(HttpStatus.BAD_REQUEST_400);
@@ -208,7 +212,7 @@ public class VTPExecutionResource  extends VTPResource{
             String testCaseName,
             String profile,
             String startTime,
-            String endTime) throws VTPException, IOException{
+            String endTime) throws Exception{
         List<String> args = new ArrayList<>();
         args.addAll(Arrays.asList(new String[] {
                 "--product", "open-cli", "execution-list", "--format", "json"
@@ -308,14 +312,14 @@ public class VTPExecutionResource  extends VTPResource{
              @ApiParam("Test profile name") @QueryParam("profileName") String profileName,
              @ApiParam("Test execution start time") @QueryParam("startTime") String startTime,
              @ApiParam("Test execution end time") @QueryParam("endTime") String endTime
-             ) throws VTPException, IOException {
+             ) throws Exception {
 
         return Response.ok(this.listTestExecutionsHandler(
                 requestId, scenario, testsuiteName, testcaseName, profileName, startTime, endTime).getExecutions().toString(), MediaType.APPLICATION_JSON).build();
     }
 
     public VTPTestExecution getTestExecutionHandler(
-            String executionId) throws VTPException, IOException{
+            String executionId) throws Exception{
         List<String> args = new ArrayList<>();
         args.addAll(Arrays.asList(new String[] {
                 "--product", "open-cli", "execution-show", "--execution-id", executionId, "--format", "json"
@@ -362,9 +366,11 @@ public class VTPExecutionResource  extends VTPResource{
                         resultJson = mapper.readTree(result.get(OUTPUT).toString());
                     }
                 } catch (Exception e) {
+                    LOG.error("Exception occirs", e);
                     ObjectNode node = JsonNodeFactory.instance.objectNode();
-                    node.put("error", result.get(OUTPUT).asText());
+                    node.put(ERROR, result.get(OUTPUT).asText());
                     resultJson = node;
+
                 }
 
                 exec.setResults(resultJson);
@@ -384,7 +390,7 @@ public class VTPExecutionResource  extends VTPResource{
                     response = VTPError.class) })
     public Response getTestExecution(
              @ApiParam("Test execution Id") @PathParam("executionId") String executionId
-             ) throws VTPException, IOException {
+             ) throws Exception {
 
         return Response.ok(this.getTestExecutionHandler(executionId).toString(), MediaType.APPLICATION_JSON).build();
     }
@@ -413,7 +419,7 @@ public class VTPExecutionResource  extends VTPResource{
     public Response getTestExecutionLogs(
              @ApiParam("Test execution Id") @PathParam("executionId") String executionId,
              @ApiParam("Test console reports, Options: out, err, debug") @DefaultValue("out")  @QueryParam("option") String option
-             ) throws VTPException, IOException {
+             ) throws VTPException {
         if (!("out".equalsIgnoreCase(option) || "err".equalsIgnoreCase(option) || "debug".equalsIgnoreCase(option))) {
                 option = "out";
         }
index 01bd7c3..4d1933e 100644 (file)
@@ -25,7 +25,7 @@ public class ErrorCodeExceptionTest {
 
     @Before
     public void setUp() {
-        e1 = new ErrorCodeException(null, 0, 0, null, null);
+        e1 = new ErrorCodeException(null, 0, null);
     }
 
     @Test
index df38606..d8c215d 100644 (file)
@@ -24,7 +24,7 @@ public class MarketplaceResourceExceptionTest {
     MarketplaceResourceException marketplaceResourceException;
     @Before
     public void setUp() throws Exception {
-        marketplaceResourceException= new MarketplaceResourceException(null,0,0,null,null);
+        marketplaceResourceException= new MarketplaceResourceException(null,0,null);
     }
     @Test
     public void testGetter()
index 64df9fa..11cce8f 100644 (file)
@@ -70,7 +70,6 @@ import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
 import org.onap.vnfsdk.marketplace.onboarding.entity.ResultKey;
 import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestExceutor;
 import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook;
-import org.onap.vnfsdk.marketplace.resource.PackageResource;
 import org.onap.vnfsdk.marketplace.rest.RestResponse;
 import org.onap.vnfsdk.marketplace.rest.RestfulClient;
 import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper;