aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2018-09-05 12:40:17 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2018-09-08 18:49:51 +0530
commitd17103ecbdb0c93b3f0e3980455417027c52fee1 (patch)
tree0433f52819c9bc3380fca4461fe9ea4e7b7cdb96
parentf1b0f474d7d3cd6faaec7c2e4d8f4e9c183607e8 (diff)
VTP: Migrate csar validation to VTP
Issue-ID: VNFSDK-305 Change-Id: I671195eec1e015de0e7457617b17dc0328a27a9a Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/pom.xml12
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java52
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java30
3 files changed, 57 insertions, 37 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/pom.xml b/vnfmarket-be/vnf-sdk-marketplace/pom.xml
index a7d754a2..0b5b44d7 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/pom.xml
+++ b/vnfmarket-be/vnf-sdk-marketplace/pom.xml
@@ -31,6 +31,12 @@
<dependencies>
+ <!-- oclip -->
+ <dependency>
+ <groupId>org.onap.cli</groupId>
+ <artifactId>oclip-grpc-client</artifactId>
+ <version>1.0.0</version>
+ </dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
@@ -174,12 +180,6 @@
<version>25.0-jre</version>
</dependency>
- <!-- UT end -->
- <dependency>
- <groupId>org.onap.vnfsdk.validation</groupId>
- <artifactId>validation-csar</artifactId>
- <version>1.1.2</version>
- </dependency>
</dependencies>
<profiles>
<profile>
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 8feab3f8..e2cc0c0d 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
@@ -36,7 +36,6 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.http.HttpStatus;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
-import org.onap.validation.csar.CsarValidator;
import org.onap.vnfsdk.marketplace.common.CommonConstant;
import org.onap.vnfsdk.marketplace.common.CommonErrorResponse;
import org.onap.vnfsdk.marketplace.common.FileUtil;
@@ -59,6 +58,8 @@ import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestExc
import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook;
import org.onap.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.ValidateLifecycleTestResponse;
import org.onap.vnfsdk.marketplace.onboarding.onboardmanager.OnBoardingHandler;
+import org.open.infc.grpc.Result;
+import org.open.infc.grpc.client.OpenRemoteCli;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,7 +71,7 @@ public class PackageWrapper {
/**
* get PackageWrapper instance.
- *
+ *
* @return package wrapper instance
*/
public static PackageWrapper getInstance() {
@@ -124,7 +125,7 @@ public class PackageWrapper {
/**
* query package list by condition.
- *
+ *
* @param name package name
* @param provider package provider
* @param version package version
@@ -150,7 +151,7 @@ public class PackageWrapper {
/**
* query package by id.
- *
+ *
* @param csarId package id
* @return Response
*/
@@ -162,7 +163,7 @@ public class PackageWrapper {
/**
* upload package.
- *
+ *
* @param uploadedInputStream inputStream
* @param fileDetail package detail
* @param head http header
@@ -242,7 +243,7 @@ public class PackageWrapper {
/**
* Interface for Uploading package
- *
+ *
* @param packageId
* @param uploadedInputStream
* @param fileDetail
@@ -287,15 +288,18 @@ public class PackageWrapper {
uploadedInputStream.close();
try {
- CsarValidator cv = new CsarValidator(packageId, fileLocation);
+ Result result = OpenRemoteCli.run(new String[] { "-P", "onap-vtp", "csar-validate", "--csar", fileLocation, "--format", "json" });
+ LOG.info("CSAR validation is successful" + result.getOutput());
- String validationResp = cv.validateCsar();
- if("SUCCESS" != validationResp) {
- LOG.error("Could not validate failed");
- return Response.status(Status.EXPECTATION_FAILED).entity(new CommonErrorResponse(validationResp))
- .build();
+ int exitCode = result.getExitCode();
+ String output = result.getOutput();
+
+ if((exitCode != 0) || !output.contains("\"error\":\"SUCCESS\"")) {
+ LOG.error("Could not validate failed");
+ return Response.status(Status.EXPECTATION_FAILED).entity(new CommonErrorResponse(output))
+ .build();
}
- } catch(Exception e) {
+ } catch (Exception e) {
LOG.error("CSAR validation panicked", e);
return Response.status(Status.EXPECTATION_FAILED).entity(
new CommonErrorResponse("Exception occurred while validating csar package:" + e.getMessage()))
@@ -318,7 +322,7 @@ public class PackageWrapper {
/**
* Execute OnBarding request
- *
+ *
* @param oOnboradingRequest
*/
private void addOnBoardingRequest(final OnBoradingRequest oOnboradingRequest) {
@@ -332,7 +336,7 @@ public class PackageWrapper {
/**
* delete package by package id.
- *
+ *
* @param csarId package id
* @return Response
*/
@@ -348,7 +352,7 @@ public class PackageWrapper {
/**
* Delete Package by CSAR ID
- *
+ *
* @param csarId
*/
private void deletePackageDataById(String csarId) {
@@ -372,7 +376,7 @@ public class PackageWrapper {
/**
* download package by package id.
- *
+ *
* @param csarId package id
* @return Response
*/
@@ -406,7 +410,7 @@ public class PackageWrapper {
/**
* get package file uri.
- *
+ *
* @param csarId package id
* @param relativePath file relative path
* @return Response
@@ -417,7 +421,7 @@ public class PackageWrapper {
/**
* Interface to Update Download count for CSAR ID
- *
+ *
* @param csarId
* @return
*/
@@ -428,7 +432,7 @@ public class PackageWrapper {
/**
* Handle downlowa count update
- *
+ *
* @param csarId
* @return
*/
@@ -445,7 +449,7 @@ public class PackageWrapper {
/**
* Interface to Re upload Package
- *
+ *
* @param csarId
* @param uploadedInputStream
* @param fileDetail
@@ -483,7 +487,7 @@ public class PackageWrapper {
/**
* Interface to get OnBoarding Result by Operation Type
- *
+ *
* @param csarId
* @param operTypeId
* @param operId
@@ -539,7 +543,7 @@ public class PackageWrapper {
/**
* Interface to get OnBoarding Status by Operation ID
- *
+ *
* @param csarId
* @param operTypeId
* @return
@@ -578,7 +582,7 @@ public class PackageWrapper {
/**
* Interface to get OnBoarding Steps
- *
+ *
* @return
*/
public Response getOnBoardingSteps() {
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 c9c03cc9..6ec0406a 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
@@ -67,6 +67,8 @@ import org.onap.vnfsdk.marketplace.rest.RestResponse;
import org.onap.vnfsdk.marketplace.rest.RestfulClient;
import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper;
import org.onap.vnfsdk.marketplace.wrapper.PackageWrapperUtil;
+import org.open.infc.grpc.Result;
+import org.open.infc.grpc.client.OpenRemoteCli;
import mockit.Mock;
import mockit.MockUp;
@@ -640,11 +642,11 @@ public class PackageResourceTest {
packageDataList.add(packageData);
return packageDataList;
}
-
+
@Mock
public List<PackageData> getPackageDataSubset(Map<String, String> paramsMap) {
List<PackageData> packageDataList = new ArrayList<PackageData>();
-
+
return packageDataList;
}
};
@@ -731,6 +733,20 @@ public class PackageResourceTest {
}
};
+
+ new MockUp<OpenRemoteCli>() {
+
+ @Mock
+ public Result run(String[] args) {
+ Result result = Result.newBuilder().
+ setExitCode(0).
+ setOutput("{\"error\":\"SUCCESS\"}").
+ build();
+
+ return result;
+ }
+ };
+
FormDataContentDisposition fileDetail =
FormDataContentDisposition.name("fileName").fileName("clearwater_ns.csar").build();
@@ -1068,12 +1084,12 @@ public class PackageResourceTest {
public void testPkgFormat() {
assertNotNull(PackageWrapperUtil.getPackageFormat("xml"));
assertNotNull(PackageWrapperUtil.getPackageFormat("yml"));
- assertNull(PackageWrapperUtil.getPackageFormat("pdf"));
+ assertNull(PackageWrapperUtil.getPackageFormat("pdf"));
MsbDetailsHolder.getMsbDetails();
try {
IMarketplaceDao dao = new MarketplaceDaoImpl();
-
+
packageDataList = new ArrayList<PackageData>();
packageData = new PackageData();
packageData.setCsarId("21");
@@ -1083,13 +1099,13 @@ public class PackageResourceTest {
packageData.setVersion("v1.0");
packageData.setProvider("Huawei");
packageDataList.add(packageData);
-
+
dao.savePackageData(packageData);
dao.getAllPackageData();
dao.getPackageData("21");
dao.updatePackageData(packageData);
- dao.deletePackageData("21");
-
+ dao.deletePackageData("21");
+
} catch(Exception e) {
}