summaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace
diff options
context:
space:
mode:
authorHailong Zhang <zhanghailong22@huawei.com>2019-09-05 20:07:35 +0800
committerWeitao Gao <victor.gao@huawei.com>2019-10-14 06:49:14 +0000
commit7f232e125dbe030f0bf3c360865cba832b694404 (patch)
treeaeb33a7ebecdf15ea71208ebdc3f67db47765b56 /vnfmarket-be/vnf-sdk-marketplace
parent9a5a56c6aff10320b4460dbda22a36751a2c2300 (diff)
modify Sonar Issue
Issue-ID: VNFSDK-462 Signed-off-by: Hailong Zhang <zhanghailong22@huawei.com> Change-Id: I4aa45fbad04b961a1287ed1a4b7bee6cdefd9101
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java9
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java1
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java4
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java32
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java2
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java2
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java1
7 files changed, 31 insertions, 20 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java
index f05a22f9..ad5034e3 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java
@@ -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);
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java
index 60cdf65c..218d0ad8 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java
@@ -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 "{}";
}
}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java
index b50e30f1..f6139066 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java
@@ -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()));
}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
index 5d025c51..83db8e8b 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
@@ -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";
}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java
index 01bd7c31..4d1933ee 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java
@@ -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
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java
index df386060..d8c215d9 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java
@@ -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()
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java
index 64df9fa9..11cce8fb 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java
@@ -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;