aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace/src/main
diff options
context:
space:
mode:
authorMurali-P <murali.p@huawei.com>2017-07-31 11:06:26 +0530
committerMurali-P <murali.p@huawei.com>2017-07-31 11:06:26 +0530
commitd0e21365a8bf7da9dd87915c52acb0a907dfe59b (patch)
tree06b4f5314b92ca2695bd3dbd9d545df6df242dd3 /vnfmarket-be/vnf-sdk-marketplace/src/main
parent6bf0d8e793ef1f55808bb54112f4839a18ee582a (diff)
Market place initial code
Resolved:VNFSDK-53 VNF SDK market place Change-Id: Ic9ac5491b4a43d03bce105abb295e10c476e1560 Signed-off-by: Murali-P <murali.p@huawei.com>
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/main')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonConstant.java121
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonErrorResponse.java41
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/FileUtil.java300
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerAddrConfig.java31
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerPathConfig.java38
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/JsonUtil.java118
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/MsbAddrConfig.java30
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/RestUtil.java34
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/ToolUtil.java369
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/MarketplaceResourceType.java25
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/Parameters.java22
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/connection/ConnectionUtil.java76
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/BaseData.java20
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/PackageData.java196
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/ErrorCodeException.java144
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/MarketplaceResourceException.java77
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java150
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/inf/IMarketplaceDao.java56
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/mapper/IMarketplaceMapper.java56
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/resource/PackageManager.java151
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/util/MarketplaceDbUtil.java48
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/BaseHandler.java163
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/PackageHandler.java123
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarPackage.java101
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarQueryCondition.java38
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOnboardState.java30
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationStatus.java43
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationalState.java20
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumProcessState.java20
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumResult.java62
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumType.java20
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumUsageState.java20
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/VnfPackage.java100
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/request/PackageBasicInfo.java70
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/CsarFileUriResponse.java47
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageMeta.java190
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageResponse.java57
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/UploadPackageResponse.java48
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManager.java35
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerFactory.java53
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerType.java23
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/HttpFileManagerImpl.java64
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/ToolUtil.java198
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumPackageFormat.java26
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumTemplateType.java20
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/AppServletContextListener.java37
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetails.java57
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetailsHolder.java49
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegister.java80
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegistration.java217
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbServer.java35
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingOperResult.java33
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingResult.java60
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingStep.java44
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingSteps.java32
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoradingRequest.java49
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationDetails.java34
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationResult.java60
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/ResultKey.java41
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java220
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java217
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifeCycleTestReq.java43
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java156
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestHook.java193
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/ValidateLifecycleTestResponse.java48
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VmsInfo.java42
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VnfInfo.java31
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/onboardmanager/OnBoardingHandler.java63
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/resource/PackageResource.java227
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestConstant.java83
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestResponse.java49
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulClient.java168
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulUtil.java104
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapper.java596
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java356
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/resources/generalconfig/OnBoardingSteps.json54
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/resources/log4j.properties8
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/resources/marketplace.properties15
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/configuration/configuration.xml35
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/sql/MarketplaceMapper.xml57
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/webapp/WEB-INF/web.xml43
81 files changed, 7310 insertions, 0 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonConstant.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonConstant.java
new file mode 100644
index 00000000..7345fac5
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonConstant.java
@@ -0,0 +1,121 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+public class CommonConstant {
+ // Package Status
+ public static final String PACKAGE_STATUS_DELETING = "deleting";
+
+ public static final String PACKAGE_STATUS_DELETE_FAIL = "deleteFailed";
+
+ public static final String PACKAGE_XML_FORMAT = "xml";
+
+
+ public static final String PACKAGE_YAML_FORMAT = "yaml";
+
+ // host image progress
+
+ public static final String TOSCA_METADATA = "TOSCA-Metadata";
+
+ public static final String CSAR_VERSION_META = "version";
+
+ public static final String CSAR_TYPE_META = "type";
+
+ public static final String CSAR_PROVIDER_META = "provider";
+
+ public static final String DEFINITIONS = "Definitions";
+
+ public static final String CSAR_META = "csar.meta";
+
+ public static final String CSAR_SUFFIX = ".csar";
+
+ public static final String HTTP_HEADER_CONTENT_RANGE = "Content-Range";
+
+ public static final String CATALOG_CSAR_DIR_NAME = "/csar";
+
+ public static final String REPORT_CSAR_DIR_NAME = "/reports";
+
+ public static final String COMETD_CHANNEL_PACKAGE_DELETE = "/package/delete";
+
+ public static final String SUCCESS_STR = "SUCCESS";
+
+ public static final int ONBOARDING_THREAD_COUNT = 1;
+ public static final int SUCESS = 0;
+ public static final int FAILED = -1;
+
+ public static final String CATALOUGE_UPLOAD_URL = "/openoapi/catalog/v1/csars";
+
+ public static class functionTest
+ {
+ public static final String FUNCTEST_URL = "/openoapi/vnfsdk/v1/functest/";
+ public static final String FUNCTEST_RESULT_URL = "/openoapi/vnfsdk/v1/functest/download/";
+ public static final String FUNCTEST_OPERTYPE_ID = "functiontest";
+ public static final String FUNCTEST_PACKAGE_EXISTS = "packageExists";
+ public static final String FUNCTEST_EXEC = "functestexec";
+
+ private functionTest() {
+ }
+ }
+
+ public static class LifeCycleTest
+ {
+ public static final String LIFECYCLE_TEST_URL = "/openoapi/nslcm/v1/vnfpackage";
+ public static final String LIFECYCLE_TEST_OPERTYPE_ID = "lifecycletest";
+ public static final String LIFECYCLE_TEST_EXEC = "lifecycleTestexec";
+ private LifeCycleTest() {
+ }
+ }
+
+ public static class HttpContext {
+
+ public static final String CONTENT_TYPE = "Content-Type";
+
+ public static final String MEDIA_TYPE_JSON = "application/json;charset=UTF-8";
+
+ public static final String URL = "url";
+
+ public static final String METHOD_TYPE = "methodType";
+
+ private HttpContext() {
+ }
+ }
+
+ public static class MethodType {
+
+ public static final String POST = "post";
+
+ public static final String DELETE = "delete";
+
+ public static final String PUT = "put";
+
+ public static final String GET = "get";
+
+ private MethodType() {
+ }
+ }
+
+ public static class MsbRegisterCode {
+
+ public static final int MSDB_REGISTER_RETRIES = 12;
+ public static final int MSDB_REGISTER_RETRY_SLEEP = 10000;
+
+ public static final int MSDB_REGISTER_FILE_NOT_EXISTS = 2;
+ public static final int MSDB_REGISTER_SUCESS = 0;
+ public static final int MSDB_REGISTER_FAILED = -1;
+ private MsbRegisterCode() {
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonErrorResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonErrorResponse.java
new file mode 100644
index 00000000..853aceaa
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/CommonErrorResponse.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CommonErrorResponse {
+
+ private String code;
+
+ private String message;
+
+
+ public static Object failure(String message) {
+ return message;
+ }
+
+ public CommonErrorResponse(String message) {
+ super();
+ this.message = message;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/FileUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/FileUtil.java
new file mode 100644
index 00000000..2897af6e
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/FileUtil.java
@@ -0,0 +1,300 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.io.Resources;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+
+public final class FileUtil {
+
+ public static final Logger logger = LoggerFactory.getLogger(FileUtil.class);
+
+ private static final int BUFFER_SIZE = 2 * 1024 * 1024;
+
+ private static final int TRY_COUNT = 3;
+
+ private FileUtil() {
+
+ }
+
+
+ /**
+ * create dir.
+ * @param dir dir to create
+ * @return boolean
+ */
+ public static boolean createDirectory(String dir) {
+ File folder = new File(dir);
+ int tryCount = 0;
+ while (tryCount < TRY_COUNT) {
+ tryCount++;
+ if (!folder.exists() && !folder.mkdirs()) {
+ continue;
+ } else {
+ return true;
+ }
+ }
+
+ return folder.exists();
+ }
+
+ /**
+ * delete file.
+ * @param file the file to delete
+ * @return boolean
+ */
+ public static boolean deleteFile(File file) {
+ String hintInfo = file.isDirectory() ? "dir " : "file ";
+ boolean isFileDeleted = file.delete();
+ boolean isFileExist = file.exists();
+ if (!isFileExist) {
+ if (isFileDeleted) {
+ logger.info("delete " + hintInfo + file.getAbsolutePath());
+ } else {
+ isFileDeleted = true;
+ logger.info("file not exist. no need delete " + hintInfo + file.getAbsolutePath());
+ }
+ } else {
+ logger.info("fail to delete " + hintInfo + file.getAbsolutePath());
+ }
+ return isFileDeleted;
+ }
+
+
+ /**
+ * unzip zip file.
+ * @param zipFileName file name to zip
+ * @param extPlace extPlace
+ * @return unzip file name
+ * @throws IOException e1
+ */
+ public static ArrayList<String> unzip(String zipFileName, String extPlace) throws IOException {
+ ZipFile zipFile = null;
+ ArrayList<String> unzipFileNams = new ArrayList<String>();
+
+ try {
+ zipFile = new ZipFile(zipFileName);
+ Enumeration<?> fileEn = zipFile.entries();
+ byte[] buffer = new byte[BUFFER_SIZE];
+
+ while (fileEn.hasMoreElements()) {
+ InputStream input = null;
+ BufferedOutputStream bos = null;
+ try {
+ ZipEntry entry = (ZipEntry) fileEn.nextElement();
+ if (entry.isDirectory()) {
+ continue;
+ }
+
+ input = zipFile.getInputStream(entry);
+ File file = new File(extPlace, entry.getName());
+ if (!file.getParentFile().exists()) {
+ createDirectory(file.getParentFile().getAbsolutePath());
+ }
+
+ bos = new BufferedOutputStream(new FileOutputStream(file));
+ while (true) {
+ int length = input.read(buffer);
+ if (length == -1) {
+ break;
+ }
+ bos.write(buffer, 0, length);
+ }
+ unzipFileNams.add(file.getAbsolutePath());
+ } finally {
+ closeOutputStream(bos);
+ closeInputStream(input);
+ }
+ }
+ } finally {
+ closeZipFile(zipFile);
+ }
+ return unzipFileNams;
+ }
+
+ /**
+ * close InputStream.
+ *
+ * @param inputStream the inputstream to close
+ */
+ public static void closeInputStream(InputStream inputStream) {
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ } catch (Exception e1) {
+ logger.info("close InputStream error!");
+ }
+ }
+
+ /**
+ * close OutputStream.
+ *
+ * @param outputStream the output stream to close
+ */
+ public static void closeOutputStream(OutputStream outputStream) {
+ try {
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ } catch (Exception e1) {
+ logger.info("close OutputStream error!");
+ }
+ }
+
+ public static void closeFileStream(FileInputStream ifs) {
+ try {
+ if (ifs != null) {
+ ifs.close();
+ }
+ } catch (Exception e1) {
+ logger.info("close OutputStream error!");
+ }
+ }
+
+ /**
+ * close zipFile.
+ *
+ * @param zipFile the zipFile to close
+ */
+ public static void closeZipFile(ZipFile zipFile) {
+ try {
+ if (zipFile != null) {
+ zipFile.close();
+ zipFile = null;
+ }
+ } catch (IOException e1) {
+ logger.info("close ZipFile error!");
+ }
+ }
+
+ public static boolean checkFileExists(String filePath)
+ {
+ File file = new File(filePath);
+ return file.exists();
+ }
+
+ public static boolean deleteFile(String filePath)
+ {
+ File file = new File(filePath);
+ return deleteFile(file);
+ }
+
+ public static boolean writeJsonDatatoFile(String fileAbsPath, Object obj)
+ {
+ logger.info("Write JsonData to file :"+fileAbsPath);
+
+ boolean bResult = false;
+ if(checkFileExists(fileAbsPath))
+ {
+ deleteFile(fileAbsPath);
+ }
+
+ ObjectMapper mapper = new ObjectMapper();
+ try
+ {
+ mapper.writeValue(new File(fileAbsPath), obj);
+ bResult = true;
+ }
+ catch (JsonGenerationException e)
+ {
+ logger.info("JsonGenerationException Exception: writeJsonDatatoFile-->"+fileAbsPath);
+ }
+ catch (JsonMappingException e)
+ {
+ logger.info("JsonMappingException Exception: writeJsonDatatoFile-->"+fileAbsPath);
+ }
+ catch (IOException e)
+ {
+ logger.info("IOException Exception: writeJsonDatatoFile-->"+fileAbsPath);
+ }
+ return bResult;
+ }
+
+ public static <T> Object readJsonDatafFromFile(String fileAbsPath, Class<T> clazz)
+ {
+ if(!checkFileExists(fileAbsPath))
+ {
+ logger.info("read JsonData from file , file not found :"+fileAbsPath);
+ return null;
+ }
+
+ logger.info("read JsonData from file :"+fileAbsPath);
+
+ T obj = null;
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ try
+ {
+ obj = mapper.readValue(new File(fileAbsPath), clazz);
+ }
+ catch (JsonParseException e1)
+ {
+ logger.info("JsonParseException Exception: writeJsonDatatoFile-->"+fileAbsPath);
+ }
+ catch (JsonMappingException e1)
+ {
+ logger.info("JsonMappingException Exception: writeJsonDatatoFile-->"+fileAbsPath);
+ }
+ catch (IOException e1)
+ {
+ logger.info("IOException Exception: writeJsonDatatoFile-->"+fileAbsPath);
+ }
+ return obj;
+ }
+
+ public static boolean deleteDirectory(String path)
+ {
+ File file = new File(path);
+ return deleteDirectory(file);
+ }
+
+ public static boolean deleteDirectory(File file)
+ {
+ if (!file.exists())
+ {
+ return true;
+ }
+ if (file.isDirectory())
+ {
+ for (File f : file.listFiles())
+ {
+ deleteDirectory(f);
+ }
+ }
+ return file.delete();
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerAddrConfig.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerAddrConfig.java
new file mode 100644
index 00000000..bb7c804e
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerAddrConfig.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+
+public class HttpServerAddrConfig {
+
+ protected static String httpServerAddress;
+
+ public static String getHttpServerAddress() {
+ return httpServerAddress;
+ }
+
+ public static void setHttpServerAddress(String httpServerAddress) {
+ HttpServerAddrConfig.httpServerAddress = httpServerAddress;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerPathConfig.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerPathConfig.java
new file mode 100644
index 00000000..fab2315c
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/HttpServerPathConfig.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+public class HttpServerPathConfig {
+ protected static String httpServerPath;
+
+ static
+ {
+// CatalogAppConfiguration configuration = new CatalogAppConfiguration();
+// Config.setConfigration(configuration);
+// Config.getConfigration().setMsbServerAddr("http://127.0.0.1:80");
+ MsbAddrConfig.setMsbAddress("http://127.0.0.1:8080");
+ HttpServerAddrConfig.setHttpServerAddress("http://127.0.0.1:8080");
+ HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");
+ }
+
+ public static String getHttpServerPath() {
+ return httpServerPath;
+ }
+
+ public static void setHttpServerPath(String httpServerPath) {
+ HttpServerPathConfig.httpServerPath = httpServerPath;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/JsonUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/JsonUtil.java
new file mode 100644
index 00000000..ba456998
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/JsonUtil.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.common;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Json tools class, packaging a number of commonly used Json methods.<br>
+ *
+ * @author
+ * @version GSO 0.5 2016-08-26
+ */
+public final class JsonUtil {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(JsonUtil.class);
+
+ private JsonUtil() {
+ }
+
+ /**
+ * Convert object to JSON.<br>
+ *
+ * @param obj The object to be converted
+ * @return The JSON string
+ * @since GSO 0.5
+ */
+ public static String toJson(Object obj) {
+ try {
+ return new ObjectMapper().writeValueAsString(obj);
+ } catch(IOException ex) {
+ LOGGER.error("Parser to json error.", ex);
+ throw new IllegalArgumentException("Parser obj to json error, obj = " + obj, ex);
+ }
+ }
+
+ /**
+ * Convert JSON to object.<br>
+ *
+ * @param jsonStr The JSON to be converted
+ * @param objClass The object class
+ * @return The objClass object
+ * @since GSO 0.5
+ */
+ public static <T> T fromJson(String jsonStr, Class<T> objClass) {
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ return mapper.readValue(jsonStr, objClass);
+ } catch(IOException ex) {
+ LOGGER.error("Parser to object error.", ex);
+ throw new IllegalArgumentException(
+ "Parser json to object error, json = " + jsonStr + ", expect class = " + objClass, ex);
+ }
+ }
+
+ /**
+ * Convert JSON to object.<br>
+ *
+ * @param jsonStr The JSON to be converted
+ * @param typeRef The object type
+ * @return The typeRef object
+ * @since GSO 0.5
+ */
+ public static <T> T fromJson(String jsonStr, TypeReference<T> typeRef) {
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ return mapper.readValue(jsonStr, typeRef);
+ } catch(IOException ex) {
+ LOGGER.error("Parser to object by type reference error.", ex);
+ throw new IllegalArgumentException(
+ "Parser json to object error, json = " + jsonStr + ", expect type = " + typeRef.getType(), ex);
+ }
+ }
+
+ /**
+ * Turn a json file in to a java object. <br>
+ *
+ * @param file the json file need to change.
+ * @param objClass the java class json string represent.
+ * @return the java object parsed from json string.
+ * @since GSO 0.5
+ */
+ public static <T> T fromJson(File file, Class<T> objClass) {
+ try {
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ return mapper.readValue(file, objClass);
+ } catch(IOException ex) {
+ LOGGER.error("Parser to object error.", ex);
+ throw new IllegalArgumentException(
+ "Parser json to object error, file = " + file.getName() + ", expect class = " + objClass, ex);
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/MsbAddrConfig.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/MsbAddrConfig.java
new file mode 100644
index 00000000..9d0e5ec9
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/MsbAddrConfig.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+public class MsbAddrConfig {
+
+ protected static String msbAddress;
+
+ public static String getMsbAddress() {
+ return msbAddress;
+ }
+
+ public static void setMsbAddress(String msbAddress) {
+ MsbAddrConfig.msbAddress = msbAddress;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/RestUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/RestUtil.java
new file mode 100644
index 00000000..fe3c4874
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/RestUtil.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+import javax.ws.rs.core.Response;
+
+
+public class RestUtil {
+
+ /**
+ * get rest exception.
+ * @param errorMsg error message
+ * @return Response
+ */
+ public static Response getRestException(String errorMsg) {
+ String code = "001";
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+ .entity(new CommonErrorResponse(errorMsg)).build();
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/ToolUtil.java
new file mode 100644
index 00000000..d64e064e
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/common/ToolUtil.java
@@ -0,0 +1,369 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.common;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.UUID;
+
+
+
+/**
+ * common utility class.
+ *
+ */
+public class ToolUtil {
+ private static final Logger LOG = LoggerFactory.getLogger(ToolUtil.class);
+
+ public static final String CATALOGUE_CSAR_DIR_NAME = "csar";
+
+ public static final String CATALOGUE_IMAGE_DIR_NAME = "image";
+
+ public static final int FILE_PERCENT = 1024 * 1024; // 1M
+
+ public static boolean isEmptyString(String val) {
+ return val == null || "".equals(val);
+ }
+
+ public static boolean isTrimedEmptyString(String val) {
+ return val == null || "".equals(val.trim());
+ }
+
+ public static boolean isTrimedEmptyArray(String[] val) {
+ return val == null || val.length == 0;
+ }
+
+ /**
+ * trimed string.
+ *
+ * @param val string array to trim
+ * @return String[]
+ */
+ public static String[] trimedStringArray(String[] val) {
+ if (isTrimedEmptyArray(val)) {
+ return val;
+ }
+
+ String[] rets = new String[val.length];
+ for (int i = 0; i < val.length; i++) {
+ rets[i] = val[i].trim();
+ }
+ return rets;
+ }
+
+ public static boolean isEmptyCollection(Collection<?> coll) {
+ return null == coll || coll.isEmpty();
+ }
+
+ /**
+ * store chunk file to local temp directory.
+ *
+ * @param dirName directory name
+ * @param fileName file name
+ * @param uploadedInputStream upload input stream
+ * @return String
+ * @throws IOException e
+ */
+ public static String storeChunkFileInLocal(String dirName, String fileName,
+ InputStream uploadedInputStream) throws IOException {
+ File tmpDir = new File(dirName);
+ LOG.info("tmpdir = " + File.separator + dirName);
+ if (!tmpDir.exists()) {
+ tmpDir.mkdirs();
+ }
+ File file = new File(tmpDir + File.separator + fileName);
+ OutputStream os = null;
+ try {
+ int read = 0;
+ byte[] bytes = new byte[1024];
+ os = new FileOutputStream(file, true);
+ while ((read = uploadedInputStream.read(bytes)) != -1) {
+ os.write(bytes, 0, read);
+ }
+ os.flush();
+ return file.getAbsolutePath();
+ } finally {
+ if (os != null) {
+ os.close();
+ }
+ }
+ }
+
+ /**
+ * get temp dirctory when upload package.
+ *
+ * @param dirName temp directory name
+ * @param fileName package name
+ * @return String
+ */
+ public static String getTempDir(String dirName, String fileName) {
+ // File tmpDir = new File(File.separator + dirName);
+ return Thread.currentThread().getContextClassLoader().getResource("/").getPath() + dirName + File.separator
+ + fileName.replace(".csar", "");
+ }
+
+ public static String getUnzipDir(String dirName) {
+ File tmpDir = new File(File.separator + dirName);
+ return tmpDir.getAbsolutePath().replace(".csar", "");
+ }
+
+ /**
+ * delete file.
+ *
+ * @param dirName the directory of file
+ * @param fileName file name
+ * @return boolean
+ */
+ public static boolean deleteFile(String dirName, String fileName) {
+ File tmpDir = new File(getCataloguePath() + File.separator + dirName);
+ if (!tmpDir.exists()) {
+ return true;
+ }
+ File file = new File(tmpDir.getAbsolutePath() + File.separator + fileName);
+ if (file.exists()) {
+ return file.delete();
+ }
+ return true;
+ }
+
+ public static String getCataloguePath() {
+// return Config.getConfigration().getCataloguePath();
+ return "";
+ }
+
+ public static String getCatalogueCsarPath() {
+ return getCataloguePath() + File.separator + CATALOGUE_CSAR_DIR_NAME;
+ }
+
+ public static String getCatalogueImagePath() {
+ return getCataloguePath() + File.separator + CATALOGUE_IMAGE_DIR_NAME;
+ }
+
+ /**
+ * get file size.
+ *
+ * @param file file which to get the size
+ * @param fileUnit file unit
+ * @return String file size
+ */
+ public static String getFileSize(File file, int fileUnit) {
+ String fileSize = "";
+ DecimalFormat format = new DecimalFormat("#0.00");
+ if (file.exists()) {
+ fileSize = format.format((double) file.length() / fileUnit) + "M";
+ }
+ return fileSize;
+ }
+
+ public static String formatFileSize(double fileLength, int fileUnit) {
+ DecimalFormat format = new DecimalFormat("#0.00");
+ return format.format(fileLength / fileUnit) + "M";
+ }
+
+ /**
+ * get file size by content.
+ *
+ * @param contentRange content range
+ * @return String
+ */
+ public static String getFileSizeByContent(String contentRange) {
+ String size =
+ contentRange.substring(contentRange.indexOf("/") + 1, contentRange.length()).trim();
+ return formatFileSize(Double.parseDouble(size), FILE_PERCENT);
+ }
+
+ /**
+ * fix package format.
+ *
+ * @param csarId package ID
+ * @return String
+ */
+ public static String formatCsar(String csarId) {
+ String result = csarId;
+ if (csarId.indexOf(".csar") < 0) {
+ result += ".csar";
+ }
+ return result;
+ }
+
+
+ /**
+ * delete the file and file directory.
+ *
+ * @param dir file
+ * @return boolean
+ */
+ public static boolean deleteDir(File dir) {
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i = 0; i < children.length; i++) {
+ boolean success = deleteDir(new File(dir, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+ return dir.delete();
+ }
+
+ // public static boolean unZipCsar(String fileLocation) throws IOException {
+ // String tempfolder=System.getProperty("java.io.tmpdir");
+ // ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder);
+ // if(unzipFiles.isEmpty()){
+ // return true;
+ // }
+ // }
+
+ /**
+ * judge the file's format is yaml or not.
+ *
+ * @param file file to judge
+ * @return boolean
+ */
+ public static boolean isYamlFile(File file) {
+ if (!file.isDirectory() && file.getName().indexOf(".yaml") != -1) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * remove the csar suffix.
+ *
+ * @param csarName package name
+ * @return String
+ */
+ public static String removeCsarSuffix(String csarName) {
+ return csarName.replaceAll(".csar", "");
+ }
+
+ /**
+ * add the csar fuffix.
+ *
+ * @param csarName package name
+ * @return String
+ */
+ public static String addCsarSuffix(String csarName) {
+ if (csarName.indexOf(".csar") == -1) {
+ return csarName + ".csar";
+ }
+ return csarName;
+ }
+
+ /**
+ * process file name.
+ *
+ * @param fileName file's name
+ * @return String
+ */
+ public static String processFileName(String fileName) {
+ int index = fileName.indexOf(".zip");
+ if (index == -1) {
+ return fileName;
+ }
+
+ return addCsarSuffix(fileName.replaceAll(".zip", ""));
+ }
+
+ /**
+ * exchange object to string.
+ *
+ * @param obj object
+ * @return String
+ */
+ public static String objectToString(Object obj) {
+ if (obj == null) {
+ return "";
+ }
+ Gson gson = new Gson();
+ String str = gson.toJson(obj);
+ return str;
+ }
+
+ public static String generateId() {
+ return UUID.randomUUID().toString();
+ }
+
+ /**
+ * get the size format according file size.
+ *
+ * @param fileSize file size
+ * @return size format
+ */
+ public static String getFormatFileSize(long fileSize) {
+ long kb = 1024;
+ long mb = kb * 1024;
+ long gb = mb * 1024;
+
+ if (fileSize >= gb) {
+ return String.format("%.1f GB", (float) fileSize / gb);
+ } else if (fileSize >= mb) {
+ float fi = (float) fileSize / mb;
+ return String.format(fi > 100 ? "%.0f MB" : "%.1f MB", fi);
+ } else if (fileSize >= kb) {
+ float fi = (float) fileSize / kb;
+ return String.format(fi > 100 ? "%.0f KB" : "%.1f KB", fi);
+ } else {
+ return String.format("%d B", fileSize);
+ }
+ }
+
+ /**
+ * get gson from json.
+ * @param jsonString json string
+ * @param templateClass template class
+ * @return Template
+ */
+ public static <T> T fromJson(String jsonString, Class<T> templateClass) {
+ Gson gson = new Gson();
+ return gson.fromJson(jsonString, templateClass);
+ }
+
+ /**
+ * gson to json.
+ * @param template class name
+ * @return String
+ */
+ public static <T> String toJson(T template) {
+ Gson gson = new Gson();
+ return gson.toJson(template);
+ }
+
+ /**
+ * @param value
+ * @return
+ */
+ public static String getAsString(JsonElement value) {
+ if (value.isJsonPrimitive()) {
+ return value.getAsString();
+ }
+
+ return value.toString();
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/MarketplaceResourceType.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/MarketplaceResourceType.java
new file mode 100644
index 00000000..e5140910
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/MarketplaceResourceType.java
@@ -0,0 +1,25 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.common;
+
+
+public enum MarketplaceResourceType {
+ SERVICETEMPLATE, PACKAGE, NODETEMPLATE, TEMPLATE, SERVICETEMPLATEMAPPING;
+
+ public static MarketplaceResourceType getType(String type) {
+ return valueOf(type);
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/Parameters.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/Parameters.java
new file mode 100644
index 00000000..89416bfb
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/common/Parameters.java
@@ -0,0 +1,22 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.common;
+
+public enum Parameters {
+ oid, name, provider, version, deletionPending,
+ type, status, csarId, vendor, serviceTemplateId,
+ nodeTemplateId, mappingId, nodeType;
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/connection/ConnectionUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/connection/ConnectionUtil.java
new file mode 100644
index 00000000..d8c0d3ad
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/connection/ConnectionUtil.java
@@ -0,0 +1,76 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.db.connection;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is the session factory for the database to be used in the Driver Manager.
+ * <br/>
+ *
+ * @author
+ * @version
+ */
+public class ConnectionUtil {
+
+ private static SqlSessionFactory sqlSessionFactory;
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionUtil.class);
+
+ /**
+ * Get the DB session for the myBaties.
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since
+ */
+ private ConnectionUtil() {
+
+ }
+
+ static {
+ InputStream inputStream;
+ try {
+ inputStream = Resources.getResourceAsStream("mybatis/configuration/configuration.xml");
+ if(null == sqlSessionFactory) {
+ LOGGER.error("begin generate");
+ sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
+ LOGGER.error("end generate = " + sqlSessionFactory);
+ }
+ } catch(FileNotFoundException ex) {
+ LOGGER.error("File Not Found Exception caught", ex);
+
+ } catch(IOException ex) {
+ LOGGER.error("IO Exception caught", ex);
+ } catch(Exception ex) {
+ LOGGER.error("some exception", ex);
+ }
+ }
+
+ public static SqlSessionFactory getSession() {
+ return sqlSessionFactory;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/BaseData.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/BaseData.java
new file mode 100644
index 00000000..77acf90c
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/BaseData.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.entity;
+
+public class BaseData {
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/PackageData.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/PackageData.java
new file mode 100644
index 00000000..ed137a3f
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/entity/PackageData.java
@@ -0,0 +1,196 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.entity;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "catalog_package_table")
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class PackageData extends BaseData {
+
+ @Id
+ @Column(name = "CSARID")
+ private String csarId;
+ @Column(name = "DOWNLOADURi")
+ private String downloadUri;
+
+ @Column(name = "NAME")
+ private String name;
+
+ @Column(name = "SIZE")
+ private String size;
+ @Column(name = "VERSION")
+ private String version;
+
+ @Column(name = "PROVIDER")
+ private String provider;
+ @Column(name = "TYPE")
+ private String type;
+ @Column(name = "FORMAT")
+ private String format;
+
+ @Column(name = "DELETIONPENDING")
+ private String deletionPending;
+
+ @Column(name = "MODIFYTIME")
+ private String modifyTime;
+ @Column(name = "SHORTDESC")
+ private String shortDesc;
+ @Column(name = "CREATETIME")
+ private String createTime;
+ @Column(name = "DETAILS")
+ private String details;
+ @Column(name = "REMARKS")
+ private String remarks;
+ @Column(name = "REPORT")
+ private String report;
+ @Column(name = "DOWNLOADCOUNT")
+ private int downloadCount;
+
+ public String getReport() {
+ return report;
+ }
+
+ public void setReport(String report) {
+ this.report = report;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDownloadUri() {
+ return downloadUri;
+ }
+
+ public void setDownloadUri(String downloadUri) {
+ this.downloadUri = downloadUri;
+ }
+
+ public String getSize() {
+ return size;
+ }
+
+ public void setSize(String size) {
+ this.size = size;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ public String getDeletionPending() {
+ return deletionPending;
+ }
+
+ public void setDeletionPending(String deletionPending) {
+ this.deletionPending = deletionPending;
+ }
+
+ public String getModifyTime() {
+ return modifyTime;
+ }
+
+ public String getShortDesc() {
+ return shortDesc;
+ }
+
+ public void setShortDesc(String shortDesc) {
+ this.shortDesc = shortDesc;
+ }
+
+ public String getDetails() {
+ return details;
+ }
+
+ public void setDetails(String details) {
+ this.details = details;
+ }
+
+ public String getRemarks() {
+ return remarks;
+ }
+
+ public void setRemarks(String remarks) {
+ this.remarks = remarks;
+ }
+
+ public void setModifyTime(String modifyTime) {
+ this.modifyTime = modifyTime;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getCsarId() {
+ return csarId;
+ }
+
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+
+ public int getDownloadCount() {
+ return downloadCount;
+ }
+
+ public void setDownloadCount(int downloadCount) {
+ this.downloadCount = downloadCount;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/ErrorCodeException.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/ErrorCodeException.java
new file mode 100644
index 00000000..93472b05
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/ErrorCodeException.java
@@ -0,0 +1,144 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.exception;
+
+
+public class ErrorCodeException extends Exception {
+
+ private static final long serialVersionUID = 3220072444842529499L;
+ private int categoryCode = 0;
+ private int errorCode = 1;
+ private String[] arguments = null;
+
+ private static String defaultText = null;
+
+
+ public static void setDefaultText(String text) {
+ defaultText = text;
+ }
+
+
+ public static String getDefaultText() {
+ return defaultText;
+ }
+
+
+ public ErrorCodeException(int code, String debugMessage) {
+ this(code, debugMessage, null);
+ }
+
+ /**
+ * error code exception.
+ * @param code error code
+ * @param debugMessage debug message
+ * @param arguments arguments
+ */
+ public ErrorCodeException(int code, String debugMessage, String[] arguments) {
+ super(debugMessage);
+ this.errorCode = code;
+ this.arguments = arguments;
+ }
+
+
+ public ErrorCodeException(Throwable source, int code) {
+ this(source, code, (String[]) null);
+ }
+
+ /**
+ * error code exception.
+ * @param source Throwable
+ * @param code error code
+ * @param arguments arguments
+ */
+ public ErrorCodeException(Throwable source, int code, String[] arguments) {
+ super(source);
+ this.errorCode = code;
+ this.arguments = arguments;
+ }
+
+
+ public ErrorCodeException(Throwable source, int code, String debugMessage) {
+ this(source, code, debugMessage, null);
+ }
+
+ /**
+ * error code exception.
+ * @param source Throwable
+ * @param code error code
+ * @param debugMessage debug message
+ * @param arguments arguments
+ */
+ public ErrorCodeException(Throwable source, int code, String debugMessage, String[] arguments) {
+ super(debugMessage, source);
+ this.errorCode = code;
+ this.arguments = arguments;
+ }
+
+
+ public ErrorCodeException(int category, int code, String debugMessage) {
+ this(category, code, debugMessage, null);
+ }
+
+
+ public ErrorCodeException(int category, int code, String debugMessage, String[] arguments) {
+ super(debugMessage);
+ this.categoryCode = category;
+ this.errorCode = code;
+ this.arguments = arguments;
+ }
+
+
+ public ErrorCodeException(Throwable source, int category, int code) {
+ this(source, category, code, (String[]) null);
+ }
+
+
+ public ErrorCodeException(Throwable source, int category, int code, String[] arguments) {
+ super(source);
+ this.categoryCode = category;
+ this.errorCode = code;
+ this.arguments = arguments;
+ }
+
+
+ public ErrorCodeException(Throwable source, int category, int code, String debugMessage) {
+ this(source, category, code, debugMessage, null);
+ }
+
+
+ public ErrorCodeException(Throwable source, int category, int code, String debugMessage,
+ String[] arguments) {
+ super(debugMessage, source);
+ this.categoryCode = category;
+ this.errorCode = code;
+ this.arguments = arguments;
+ }
+
+
+ public int getCategory() {
+ return categoryCode;
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+
+ public String[] getArguments() {
+ return arguments;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/MarketplaceResourceException.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/MarketplaceResourceException.java
new file mode 100644
index 00000000..ed9a6ea5
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/exception/MarketplaceResourceException.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.exception;
+
+public class MarketplaceResourceException extends ErrorCodeException {
+ private static final long serialVersionUID = 5699508780537383310L;
+
+
+ public MarketplaceResourceException(int errcode) {
+ super(errcode, "");
+ }
+
+
+ public MarketplaceResourceException(int errcode, Throwable cause) {
+ super(cause, errcode);
+ }
+
+
+ public MarketplaceResourceException(int errcode, String message, Throwable cause) {
+ super(cause, errcode, message);
+ }
+
+
+ public MarketplaceResourceException() {
+ super(9999999, null);
+ }
+
+
+ public MarketplaceResourceException(String message) {
+ super(9999999, message);
+ }
+
+
+ public MarketplaceResourceException(Throwable cause) {
+ super(cause, 9999999);
+ }
+
+
+ public MarketplaceResourceException(String message, Throwable cause) {
+ super(cause, 9999999, message);
+ }
+
+
+ /**
+ * catalog resource exception.
+ * @param source throwable source
+ * @param errId error Id
+ * @param debugMessage debug message
+ * @param arguments arguments
+ */
+ public MarketplaceResourceException(Throwable source, int errId, String debugMessage,
+ String[] arguments) {
+ super(source, errId, debugMessage, arguments);
+ }
+
+ public MarketplaceResourceException(Throwable source, int category, int code, String debugMessage,
+ String[] arguments) {
+ super(source, category, code, debugMessage, arguments);
+ }
+
+ public int getErrcode() {
+ return super.getErrorCode();
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java
new file mode 100644
index 00000000..6f1f330a
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java
@@ -0,0 +1,150 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.db.impl;
+
+import java.util.List;
+
+import javax.persistence.PersistenceException;
+
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.openo.vnfsdk.marketplace.db.connection.ConnectionUtil;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.db.inf.IMarketplaceDao;
+import org.openo.vnfsdk.marketplace.db.mapper.IMarketplaceMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is the implementation for the DAO Layer for Driver Manager.
+ * <br/>
+ *
+ * @author
+ * @version
+ */
+public class MarketplaceDaoImpl implements IMarketplaceDao {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MarketplaceDaoImpl.class);
+
+ private SqlSessionFactory sqlSessionFactory = null;
+
+ /**
+ *
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since
+ */
+ public MarketplaceDaoImpl() {
+ sqlSessionFactory = ConnectionUtil.getSession();
+ }
+
+ /**
+ * get all package data.
+ * <br/>
+ *
+ * @return
+ * @since
+ */
+ public List<PackageData> getAllPackageData() {
+ SqlSession session = sqlSessionFactory.openSession();
+ List<PackageData> csars = null;
+ try {
+ IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
+ csars = mapper.getAllPackageData();
+ session.commit();
+ } catch(PersistenceException e) {
+ LOGGER.error("Exception caught {}", e);
+// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+// ErrorCode.INVALID_DB);
+ } finally {
+ session.close();
+ }
+ return csars;
+ }
+
+ /**
+ * saving the package data object to the DB using the mybatis.
+ * <br/>
+ *
+ * @param dirverInstance
+ * @since
+ */
+ public void savePackageData(PackageData lPackageData) {
+ SqlSession session = sqlSessionFactory.openSession();
+ try {
+ IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
+ mapper.savePackageData(lPackageData);
+ session.commit();
+ } catch(PersistenceException e) {
+ LOGGER.error("Exception caught {}", e);
+// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+// ErrorCode.INVALID_DB);
+ } finally {
+ session.close();
+ }
+
+ }
+
+ public List<PackageData> getPackageData(String csarId) {
+ SqlSession session = sqlSessionFactory.openSession();
+ List<PackageData> csars = null;
+ try {
+ IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
+ csars = mapper.getPackageData(csarId);
+ session.commit();
+ } catch(PersistenceException e) {
+ LOGGER.error("Exception caught {}", e);
+// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+// ErrorCode.INVALID_DB);
+ } finally {
+ session.close();
+ }
+ return csars;
+ }
+
+ public void deletePackageData(String csarId) {
+ SqlSession session = sqlSessionFactory.openSession();
+ try {
+ IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
+ mapper.deletePackageData(csarId);
+ session.commit();
+ } catch(PersistenceException e) {
+ LOGGER.error("Exception caught {}", e);
+// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+// ErrorCode.INVALID_DB);
+ } finally {
+ session.close();
+ }
+
+ }
+
+ public void updatePackageData(PackageData oPackageData) {
+ SqlSession session = sqlSessionFactory.openSession();
+ try {
+ IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class);
+ mapper.updatePackageData(oPackageData);
+ session.commit();
+ } catch(PersistenceException e) {
+ LOGGER.error("Exception caught {}", e);
+ } finally {
+ session.close();
+ }
+
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/inf/IMarketplaceDao.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/inf/IMarketplaceDao.java
new file mode 100644
index 00000000..65046e63
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/inf/IMarketplaceDao.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.db.inf;
+
+import java.util.List;
+
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+
+/**
+ * DAO Layer for the Driver Manager Service.
+ * <br/>
+ *
+ * @author
+ * @version
+ */
+public interface IMarketplaceDao {
+
+ /**
+ * get all package instance.
+ * <br/>
+ *
+ * @return
+ * @since
+ */
+ List<PackageData> getAllPackageData();
+
+ /**
+ * saving the package instance object to the DB using the mybaties.
+ * <br/>
+ *
+ * @param packageInstance
+ * @since
+ */
+ void savePackageData(PackageData lPackageData);
+
+ List<PackageData> getPackageData(String csarID);
+
+ void deletePackageData(String csarId);
+
+ void updatePackageData(PackageData oPackageData);
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/mapper/IMarketplaceMapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/mapper/IMarketplaceMapper.java
new file mode 100644
index 00000000..c0c1b6f6
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/mapper/IMarketplaceMapper.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.db.mapper;
+
+import java.util.List;
+
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+
+/**
+ * Mapper Interface exposed to perform database operations for Driver Manager.
+ * <br/>
+ *
+ * @author
+ * @version
+ */
+public interface IMarketplaceMapper {
+
+ /**
+ * mybaties mapper for getAllDriverInstance
+ * <br/>
+ *
+ * @return
+ * @since
+ */
+ List<PackageData> getAllPackageData();
+
+ /**
+ * saving the driver instance object to the DB using the mybaties.
+ * <br/>
+ *
+ * @param dirverInstance
+ * @since
+ */
+ void savePackageData(PackageData lPackageData);
+
+ List<PackageData> getPackageData(String csarId);
+
+ void deletePackageData(String csarId);
+
+ void updatePackageData(PackageData oPackageData);
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/resource/PackageManager.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/resource/PackageManager.java
new file mode 100644
index 00000000..7123b4e7
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/resource/PackageManager.java
@@ -0,0 +1,151 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.resource;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openo.vnfsdk.marketplace.db.common.Parameters;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
+import org.openo.vnfsdk.marketplace.db.util.MarketplaceDbUtil;
+import org.openo.vnfsdk.marketplace.db.wrapper.PackageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PackageManager {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PackageManager.class);
+ private static PackageManager manager;
+ PackageHandler handler = new PackageHandler();
+
+ /**
+ * get PackageManager instance.
+ * @return PackageManager instance
+ */
+ public static synchronized PackageManager getInstance() {
+ if (manager == null) {
+ manager = new PackageManager();
+ }
+ return manager;
+ }
+
+ private PackageManager() {}
+
+ /**
+ * add package.
+ * @param packageData package data
+ * @return PackageData
+ * @throws MarketplaceResourceException e
+ */
+ public PackageData addPackage(PackageData packageData) throws MarketplaceResourceException {
+ LOGGER.info("start add package info to db.info:" + MarketplaceDbUtil.objectToString(packageData));
+ PackageData data = handler.create(packageData);
+ LOGGER.info(" package info to db end.info:" + MarketplaceDbUtil.objectToString(data));
+ return data;
+ }
+
+ /**
+ * query package by package id.
+ * @param csarId package id
+ * @return package data list
+ * @throws MarketplaceResourceException e
+ */
+ public ArrayList<PackageData> queryPackageByCsarId(String csarId)
+ throws MarketplaceResourceException {
+ LOGGER.info("start query package info by csarid." + csarId);
+ ArrayList<PackageData> data = handler.queryByID(csarId);
+ LOGGER.info("query package info end.size:" + data.size() + "detail:"
+ + MarketplaceDbUtil.objectToString(data));
+ return data;
+ }
+
+ /**
+ * query package by condition.
+ * @param name package name
+ * @param provider package provider
+ * @param version package version
+ * @param deletionPending deletionPending
+ * @param type package type
+ * @return package data list
+ * @throws MarketplaceResourceException e
+ */
+ public ArrayList<PackageData> queryPackage(String name, String provider, String version,
+ String deletionPending, String type) throws MarketplaceResourceException {
+ LOGGER.info("start query package info.name:" + name + " provider:" + provider + " version:"
+ + version + " type:" + type);
+ Map<String, String> queryParam = new HashMap<String, String>();
+ if (MarketplaceDbUtil.isNotEmpty(name)) {
+ queryParam.put(Parameters.name.name(), name);
+ }
+ if (MarketplaceDbUtil.isNotEmpty(version)) {
+ queryParam.put(Parameters.version.name(), version);
+ }
+ if (MarketplaceDbUtil.isNotEmpty(deletionPending)) {
+ queryParam.put(Parameters.deletionPending.name(), deletionPending);
+ }
+ if (MarketplaceDbUtil.isNotEmpty(type)) {
+ queryParam.put(Parameters.type.name(), type);
+ }
+ if (MarketplaceDbUtil.isNotEmpty(provider)) {
+ queryParam.put(Parameters.provider.name(), provider);
+ }
+ ArrayList<PackageData> data = handler.query(queryParam);
+ LOGGER.info("query package info end.size:" + data.size() + "detail:"
+ + MarketplaceDbUtil.objectToString(data));
+ return data;
+ }
+
+ /**
+ * delete package according package id.
+ * @param packageId package id
+ * @throws MarketplaceResourceException e
+ */
+ public void deletePackage(String packageId) throws MarketplaceResourceException {
+ LOGGER.info("start delete package info by id." + packageId);
+ handler.delete(packageId);
+ LOGGER.info(" delete package info end id." + packageId);
+ }
+
+ /**
+ * update download count of package according package id.
+ * @param packageId package id
+ * @throws MarketplaceResourceException e
+ */
+ public void updateDwonloadCount(String packageId) throws MarketplaceResourceException
+ {
+ LOGGER.info("Request received for Updating down load count for ID:" + packageId);
+
+ //STEP 1: Get the Existing download count from DB
+ //-------------------------------------------------
+ ArrayList<PackageData> data = handler.queryByID(packageId);
+ if(data.isEmpty())
+ {
+ LOGGER.info("Package Info not foun for ID:" + packageId);
+ return;
+ }
+
+ //STEP 2: Increment download Count in DB
+ //--------------------------------------
+ PackageData oPackageData = data.get(0);
+ int idownloadcount = oPackageData.getDownloadCount();
+ oPackageData.setDownloadCount(++idownloadcount);
+
+ handler.update(oPackageData);
+
+ LOGGER.info("Download count updated to :" + idownloadcount);
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/util/MarketplaceDbUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/util/MarketplaceDbUtil.java
new file mode 100644
index 00000000..f9ec997d
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/util/MarketplaceDbUtil.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.util;
+
+
+import com.google.gson.Gson;
+
+import java.util.UUID;
+
+
+public class MarketplaceDbUtil {
+
+ public static String generateId() {
+ return UUID.randomUUID().toString();
+ }
+
+ public static boolean isNotEmpty(String str) {
+ return str != null && !"".equals(str) && str.length() > 0;
+ }
+
+ /**
+ * exchange object to string.
+ * @param obj Object
+ * @return string
+ */
+ public static String objectToString(Object obj) {
+ Gson gson = new Gson();
+ if (obj != null) {
+ return gson.toJson(obj);
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/BaseHandler.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/BaseHandler.java
new file mode 100644
index 00000000..0b5b285a
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/BaseHandler.java
@@ -0,0 +1,163 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.wrapper;
+
+import java.util.List;
+import java.util.Map;
+
+import org.openo.vnfsdk.marketplace.db.entity.BaseData;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
+import org.openo.vnfsdk.marketplace.db.impl.MarketplaceDaoImpl;
+import org.openo.vnfsdk.marketplace.db.inf.IMarketplaceDao;
+import org.openo.vnfsdk.marketplace.db.util.MarketplaceDbUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+
+
+
+/**
+ * an abstract class for NFV wrapper class.
+ * provide the common methods to process the CRUD rest request.
+ *
+ */
+public abstract class BaseHandler<T extends BaseData> {
+ private static final Logger logger = LoggerFactory.getLogger(BaseHandler.class);
+
+ public Gson gson = new Gson();
+
+ /**
+ * create date.
+ * @param data data to create
+ * @param resouceType resouce type
+ * @return T
+ * @throws MarketplaceResourceException e1
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public PackageData create(PackageData data, String resouceType) throws MarketplaceResourceException {
+ PackageData rtnData = null;
+ logger.info("BaseHandler:start create data.info:" + MarketplaceDbUtil.objectToString(data));
+ try {
+// check(data);
+ IMarketplaceDao dao = new MarketplaceDaoImpl();
+ dao.savePackageData(data);
+ rtnData = data;
+ } catch (Exception e1) {
+ logger.error("BaseHandler:error while creating " + resouceType, e1);
+ // throw e1;
+ }
+ logger.info("BaseHandler:create data end.info:" + MarketplaceDbUtil.objectToString(data));
+ return rtnData;
+ }
+
+ /**
+ * delete data.
+ * @param data data to delete
+ * @param resouceType resource type
+ * @throws MarketplaceResourceException e1
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void delete(T data, String resouceType) throws MarketplaceResourceException {
+ logger.info("BaseHandler:start delete data.info:" + MarketplaceDbUtil.objectToString(data));
+ IMarketplaceDao dao = new MarketplaceDaoImpl();
+ dao.deletePackageData(((PackageData)data).getCsarId());
+ logger.info("BaseHandler:delete data end");
+ }
+
+ /**
+ * query data.
+ * @param queryParam query parameter
+ * @param resouceType resource type
+ * @return T list
+ * @throws MarketplaceResourceException e1
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public List<PackageData> query(Map<String, String> queryParam, String resouceType)
+ throws MarketplaceResourceException {
+ logger.info("BaseHandler:start query data .info:" + MarketplaceDbUtil.objectToString(queryParam));
+ List<PackageData> datas = null;
+ IMarketplaceDao dao = new MarketplaceDaoImpl();
+ datas = dao.getAllPackageData();
+ logger.info("BaseHandler: query data end .info:" + MarketplaceDbUtil.objectToString(datas));
+ return datas;
+ }
+
+ /**
+ * union query.
+ * @param filter filter
+ * @param resouceType resource type
+ * @return T list
+ * @throws MarketplaceResourceException e1
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public List<T> unionQuery(String filter, String resouceType) throws MarketplaceResourceException {
+ logger.info("BaseHandler:start union query data.fliter:" + filter);
+ List<T> datas = null;
+ /* try {
+ BaseDao dao = DaoManager.getInstance().getDao(resouceType);
+ datas = dao.unionQuery(filter);
+
+ } catch (MarketplaceResourceException e1) {
+ logger.error("BaseHandler:error while union querying " + resouceType, e1);
+ throw e1;
+ }*/
+ logger.info("BaseHandler:union query data end .info:" + MarketplaceDbUtil.objectToString(datas));
+ return datas;
+ }
+
+ /**
+ * union delete.
+ * @param filter filter
+ * @param resouceType resource type
+ * @return int
+ * @throws MarketplaceResourceException e1
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public int unionDelete(String filter, String resouceType) throws MarketplaceResourceException {
+ logger.info("BaseHandler:start delete query data.fliter:" + filter);
+// int num;
+ int num=0;
+ /*try {
+ BaseDao dao = DaoManager.getInstance().getDao(resouceType);
+ num = dao.unionDelete(filter);
+
+ } catch (MarketplaceResourceException e1) {
+ logger.error("BaseHandler:error while union delete " + resouceType, e1);
+ throw e1;
+ }*/
+ logger.info("BaseHandler:union delete data end .num:" + num);
+ return num;
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void update(T data, String resouceType) throws MarketplaceResourceException {
+ logger.info("BaseHandler:start update data.info:" + MarketplaceDbUtil.objectToString(data));
+ IMarketplaceDao dao = new MarketplaceDaoImpl();
+ dao.updatePackageData((PackageData)data);
+ logger.info("update data end");
+ }
+
+ /**
+ * check if the related object id exists in the system.
+ *
+ * @param data data to check
+ * @throws MarketplaceResourceException e
+ */
+ public abstract void check(T data) throws MarketplaceResourceException;
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/PackageHandler.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/PackageHandler.java
new file mode 100644
index 00000000..a33e80a3
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/db/wrapper/PackageHandler.java
@@ -0,0 +1,123 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.db.wrapper;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.openo.vnfsdk.marketplace.db.common.MarketplaceResourceType;
+import org.openo.vnfsdk.marketplace.db.common.Parameters;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
+import org.openo.vnfsdk.marketplace.db.impl.MarketplaceDaoImpl;
+import org.openo.vnfsdk.marketplace.db.inf.IMarketplaceDao;
+import org.openo.vnfsdk.marketplace.db.util.MarketplaceDbUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PackageHandler extends BaseHandler<PackageData> {
+ private static final Logger logger = LoggerFactory.getLogger(PackageHandler.class);
+
+ /**
+ * create package data.
+ * @param packageData package data to create
+ * @return PackageData
+ * @throws MarketplaceResourceException e1
+ */
+ public PackageData create(PackageData packageData) throws MarketplaceResourceException {
+ logger.info("packageHandler:start create package info.");
+ PackageData data = null;
+ if (!MarketplaceDbUtil.isNotEmpty(packageData.getCsarId())) {
+
+ logger.info("packageHandler:package info does not have csarid,generate UUID.");
+ String id = MarketplaceDbUtil.generateId();
+ packageData.setCsarId(id);
+ }
+ Object result = create(packageData, MarketplaceResourceType.PACKAGE.name());
+ if (result != null) {
+ data = (PackageData) result;
+ } else {
+ logger.info("packageHandler: query package info is null.");
+ }
+ logger.info("packageHandler: create package info end.");
+ return data;
+ }
+
+ /**
+ * delete data.
+ * @param id package id
+ * @throws MarketplaceResourceException e
+ */
+ public void delete(String id) throws MarketplaceResourceException {
+ logger.info("packageHandler:start delete package info.");
+ PackageData packageData = new PackageData();
+ packageData.setCsarId(id);
+ delete(packageData, MarketplaceResourceType.PACKAGE.name());
+ logger.info("packageHandler: delete package info end.");
+ }
+
+ /**
+ * query package data by map.
+ * @param queryParam map data
+ * @return PackageData list
+ * @throws MarketplaceResourceException e
+ */
+ public ArrayList<PackageData> query(Map<String, String> queryParam)
+ throws MarketplaceResourceException {
+ logger.info("packageHandler:start query package info.");
+ ArrayList<PackageData> data = new ArrayList<PackageData>();
+ Object result = query(queryParam, MarketplaceResourceType.PACKAGE.name());
+ if (result != null) {
+ data = (ArrayList<PackageData>) result;
+ } else {
+ logger.info("packageHandler: query package info is null.");
+ }
+ logger.info("packageHandler: query package info end.");
+ return data;
+ }
+
+ /**
+ * query package data by map.
+ * @param queryParam map data
+ * @return PackageData list
+ * @throws MarketplaceResourceException e
+ */
+ public ArrayList<PackageData> queryByID(String csarID)
+ throws MarketplaceResourceException {
+ logger.info("packageHandler:start query package info.");
+ ArrayList<PackageData> data = new ArrayList<PackageData>();
+ logger.info("packageHandler:start query data .info:" + csarID);
+ IMarketplaceDao dao = new MarketplaceDaoImpl();
+ Object result = dao.getPackageData(csarID);
+ if (result != null) {
+ data = (ArrayList<PackageData>) result;
+ } else {
+ logger.info("packageHandler: query package info is null.");
+ }
+ logger.info("packageHandler: query data end .info:" + MarketplaceDbUtil.objectToString(data));
+ return data;
+ }
+
+ public void update(PackageData oPackageData) throws MarketplaceResourceException{
+ update(oPackageData, MarketplaceResourceType.PACKAGE.name());
+ logger.info("packageHandler: update package info end.");
+ }
+
+ @Override
+ public void check(PackageData packageData) throws MarketplaceResourceException {
+
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarPackage.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarPackage.java
new file mode 100644
index 00000000..8e8d8030
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarPackage.java
@@ -0,0 +1,101 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+public class CsarPackage {
+ private String id;
+ private String name;
+ private String createTime;
+ private String size;
+ private String status;
+ private String deletionPending;
+ private String format;
+ private String url;
+ private String type;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDeletionPending() {
+ return deletionPending;
+ }
+
+ public void setDeletionPending(String deletionPending) {
+ this.deletionPending = deletionPending;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getSize() {
+ return size;
+ }
+
+ public void setSize(String size) {
+ this.size = size;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarQueryCondition.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarQueryCondition.java
new file mode 100644
index 00000000..b1834f59
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/CsarQueryCondition.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CsarQueryCondition {
+
+ private String csarId;
+
+ private String name;
+
+ private String provider;
+
+ private String version;
+
+ private Boolean deletionPending;
+
+ private EnumType type;
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOnboardState.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOnboardState.java
new file mode 100644
index 00000000..fb527c85
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOnboardState.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+public enum EnumOnboardState {
+ onBoarded("onBoarded"), nonOnBoarded("non-onBoarded");
+
+ String value;
+
+ EnumOnboardState(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationStatus.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationStatus.java
new file mode 100644
index 00000000..8a972546
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationStatus.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.entity;
+
+public enum EnumOperationStatus {
+
+ SUCCESS("SUCCESS", 0), NOTSTARTED("NOTSTARTED", 1),FAILED("FAILED", -1), INPROGRESS("INPROGRESS", 2);
+
+ private String name;
+
+ private int index;
+
+
+ EnumOperationStatus(final String name, final int index) {
+ this.name = name;
+ this.index = index;
+ }
+
+
+ public int getIndex() {
+ return index;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationalState.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationalState.java
new file mode 100644
index 00000000..cd42e722
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumOperationalState.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+public enum EnumOperationalState {
+ Enabled, Disabled
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumProcessState.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumProcessState.java
new file mode 100644
index 00000000..a4c08ab3
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumProcessState.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+public enum EnumProcessState {
+ normal, onBoarding, onBoardFailed, deleting, deleteFailed
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumResult.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumResult.java
new file mode 100644
index 00000000..462e62b7
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumResult.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.entity;
+
+/**
+ * enum of the result type
+ *
+ * @since crossdomain 0.5
+ */
+public enum EnumResult {
+
+ SUCCESS("SUCCESS", 0), FAIL("FAIL", -1);
+
+ private String name;
+
+ private int index;
+
+ /**
+ * constructor
+ *
+ * @param name name
+ * @param index index
+ * @since crossdomain 0.5
+ */
+ EnumResult(final String name, final int index) {
+ this.name = name;
+ this.index = index;
+ }
+
+ /**
+ * Gets index.
+ *
+ * @return Value of index.
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Gets name.
+ *
+ * @return Value of name.
+ */
+ public String getName() {
+ return name;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumType.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumType.java
new file mode 100644
index 00000000..5d823183
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumType.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+public enum EnumType {
+ GSAR, SSAR, NSAR, NFAR
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumUsageState.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumUsageState.java
new file mode 100644
index 00000000..91ae00c6
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/EnumUsageState.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+public enum EnumUsageState {
+ InUse, NotInUse
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/VnfPackage.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/VnfPackage.java
new file mode 100644
index 00000000..013946bf
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/VnfPackage.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity;
+
+public class VnfPackage {
+ private String vnfPackageId;
+ private String name;
+ private String version;
+ private String provider;
+ private String vnfd;
+ private EnumOperationalState operationalState = EnumOperationalState.Disabled;
+ private EnumUsageState usageState = EnumUsageState.InUse;
+ private String deletionPending;
+ private String vnfPackageUrl;
+
+ public String getVnfPackageId() {
+ return vnfPackageId;
+ }
+
+ public void setVnfPackageId(String vnfPackageId) {
+ this.vnfPackageId = vnfPackageId;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getVnfd() {
+ return vnfd;
+ }
+
+ public void setVnfd(String vnfd) {
+ this.vnfd = vnfd;
+ }
+
+ public EnumOperationalState getOperationalState() {
+ return operationalState;
+ }
+
+ public void setOperationalState(EnumOperationalState operationalState) {
+ this.operationalState = operationalState;
+ }
+
+ public EnumUsageState getUsageState() {
+ return usageState;
+ }
+
+ public void setUsageState(EnumUsageState usageState) {
+ this.usageState = usageState;
+ }
+
+ public String getVnfPackageUrl() {
+ return vnfPackageUrl;
+ }
+
+ public void setVnfPackageUrl(String vnfPackageUrl) {
+ this.vnfPackageUrl = vnfPackageUrl;
+ }
+
+ public String getDeletionPending() {
+ return deletionPending;
+ }
+
+ public void setDeletionPending(String deletionPending) {
+ this.deletionPending = deletionPending;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/request/PackageBasicInfo.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/request/PackageBasicInfo.java
new file mode 100644
index 00000000..8fce7b8a
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/request/PackageBasicInfo.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity.request;
+
+import org.openo.vnfsdk.marketplace.entity.EnumType;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class PackageBasicInfo {
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public EnumType getType() {
+ return type;
+ }
+
+ public void setType(EnumType type) {
+ this.type = type;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ private String provider;
+
+ private EnumType type;
+
+ private String version;
+
+ private String format;
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/CsarFileUriResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/CsarFileUriResponse.java
new file mode 100644
index 00000000..7b4bfb4e
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/CsarFileUriResponse.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity.response;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CsarFileUriResponse {
+
+ public String getDownloadUri() {
+ return downloadUri;
+ }
+
+ public void setDownloadUri(String downloadUri) {
+ this.downloadUri = downloadUri;
+ }
+
+ public String getLocalPath() {
+ return localPath;
+ }
+
+ public void setLocalPath(String localPath) {
+ this.localPath = localPath;
+ }
+
+ private String downloadUri;
+
+ private String localPath;
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageMeta.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageMeta.java
new file mode 100644
index 00000000..66460f15
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageMeta.java
@@ -0,0 +1,190 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity.response;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class PackageMeta {
+
+ private String csarId;
+
+ private String name;
+
+ private String downloadUri;
+
+ private String report;
+
+ private String size;
+
+ private String version;
+
+ private String provider;
+
+ private String type;
+
+ private String format;
+
+ private boolean deletionPending;
+
+ private String createTime;
+
+ private String modifyTime;
+
+ private String shortDesc;
+
+ private int downloadCount;
+
+ private String details;
+
+ private String remarks;
+
+ public String getCsarId() {
+ return csarId;
+ }
+
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDownloadUri() {
+ return downloadUri;
+ }
+
+ public void setDownloadUri(String downloadUri) {
+ this.downloadUri = downloadUri;
+ }
+
+ public String getSize() {
+ return size;
+ }
+
+ public void setSize(String size) {
+ this.size = size;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ public boolean isDeletionPending() {
+ return deletionPending;
+ }
+
+ public void setDeletionPending(boolean deletionPending) {
+ this.deletionPending = deletionPending;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getModifyTime() {
+ return modifyTime;
+ }
+
+ public void setModifyTime(String modifyTime) {
+ this.modifyTime = modifyTime;
+ }
+
+
+
+ public String getShortDesc() {
+ return shortDesc;
+ }
+
+ public void setShortDesc(String shortDesc) {
+ this.shortDesc = shortDesc;
+ }
+
+ public String getDetails() {
+ return details;
+ }
+
+ public void setDetails(String details) {
+ this.details = details;
+ }
+
+ public String getRemarks() {
+ return remarks;
+ }
+
+ public void setRemarks(String remarks) {
+ this.remarks = remarks;
+ }
+
+ public String getReport() {
+ return report;
+ }
+
+ public void setReport(String report) {
+ this.report = report;
+ }
+
+
+ public int getDownloadCount() {
+ return downloadCount;
+ }
+
+ public void setDownloadCount(int downloadCount) {
+ this.downloadCount = downloadCount;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageResponse.java
new file mode 100644
index 00000000..c2ce36d5
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/PackageResponse.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity.response;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class PackageResponse {
+ private static final int STATUS_SUCCESS = 1;
+
+ private int status;
+ private String message;
+ private String packageName;
+ private String processId;
+ private String exception;
+ private String reportPath;
+
+ public String getReportPath() {
+ return reportPath;
+}
+
+public void setReportPath(String reportPath) {
+ this.reportPath = reportPath;
+}
+
+public boolean isSuccess() {
+ return this.status == STATUS_SUCCESS;
+ }
+
+ @Override
+ public String toString() {
+ return "DeployPackageResponse [status=" + status + ", message=" + message + ", packageName="
+ + packageName + ", processId=" + processId + ", exception=" + exception + "]";
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/UploadPackageResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/UploadPackageResponse.java
new file mode 100644
index 00000000..b6811127
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/entity/response/UploadPackageResponse.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.entity.response;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class UploadPackageResponse {
+
+ private String csarId;
+
+ private String functestReport;
+
+ public String getCsarId() {
+ return csarId;
+ }
+
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+
+ public String getFunctestReport() {
+ return functestReport;
+ }
+
+ public void setFunctestReport(String functestReport) {
+ this.functestReport = functestReport;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManager.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManager.java
new file mode 100644
index 00000000..8ecd7587
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManager.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.filemanage;
+
+
+public interface FileManager {
+
+ /**
+ * package upload api.
+ * @param srcPath source path
+ * @param dstPath/packageType/provider/packageName/version
+ * @return boolean
+ */
+ boolean upload(String srcPath, String dstPath);
+
+ boolean download(String srcPath, String dstPath);
+
+ boolean delete(String srcPath);
+
+ //ArrayList<FileLink> queryWorkFlow(String path);
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerFactory.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerFactory.java
new file mode 100644
index 00000000..036440d0
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerFactory.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.filemanage;
+
+import org.openo.vnfsdk.marketplace.filemanage.http.HttpFileManagerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FileManagerFactory {
+ private static final Logger logger = LoggerFactory.getLogger(FileManagerFactory.class);
+
+ private static FileManager getHttpFileManager() {
+ return new HttpFileManagerImpl();
+ }
+
+ /**
+ * create file manager.
+ * @return FileManager
+ */
+ public static FileManager createFileManager() {
+ switch (getType()) {
+ case http:
+ return getHttpFileManager();
+ case ftp:
+ return null;
+ default:
+ return getHttpFileManager();
+ }
+ }
+
+ private static FileManagerType getType() {
+ String type = System.getenv("useFtp");
+ logger.info("read environment varibale uesFtp:" + type);
+ if (type != null && "true".equals(type)) {
+ return FileManagerType.ftp;
+ } else {
+ return FileManagerType.http;
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerType.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerType.java
new file mode 100644
index 00000000..046b6b24
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/FileManagerType.java
@@ -0,0 +1,23 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.filemanage;
+
+public enum FileManagerType {
+ ftp, http;
+ public static FileManagerType getType(String type) {
+ return valueOf(type);
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/HttpFileManagerImpl.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/HttpFileManagerImpl.java
new file mode 100644
index 00000000..b28b5ff7
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/HttpFileManagerImpl.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.filemanage.http;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.openo.vnfsdk.marketplace.filemanage.FileManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class HttpFileManagerImpl implements FileManager {
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpFileManagerImpl.class);
+
+ public boolean upload(String srcPath, String dstPath) {
+ boolean flag = true;
+ LOGGER.info("start upload file.srcPath:" + srcPath + " dstPath" + dstPath);
+ File srcFile = new File(srcPath);
+ if (!srcFile.exists()) {
+ LOGGER.error("src file not exist!");
+ return false;
+ }
+ // File dstFile = new File(ToolUtil.getHttpServerPath() + dstPath);
+ // LOGGER.info("dstFile AbsolutePath:" + dstFile.getAbsolutePath());
+ String targetDir = ToolUtil.getHttpServerAbsolutePath() + dstPath;
+ try {
+ ToolUtil.copyDirectory(srcPath, targetDir, true);
+ } catch (IOException e1) {
+ flag = false;
+ LOGGER.error("copy file failed.errorMsg:" + e1.getMessage());
+ }
+ LOGGER.info("upload file success!");
+ return flag;
+ }
+
+ public boolean download(String srcPath, String dstPath) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean delete(String srcPath) {
+ boolean flag = true;
+ LOGGER.info("start delete file from http server.srcPath:" + srcPath);
+ flag = ToolUtil.deleteDir(new File(ToolUtil.getHttpServerAbsolutePath() + srcPath));
+ LOGGER.info("delete file from http server end.flag:" + flag);
+ return flag;
+ }
+
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/ToolUtil.java
new file mode 100644
index 00000000..b4f63883
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/filemanage/http/ToolUtil.java
@@ -0,0 +1,198 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.filemanage.http;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.openo.vnfsdk.marketplace.common.HttpServerPathConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ToolUtil {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ToolUtil.class);
+
+ /**
+ * copy from directory.
+ * @param srcDirName source directory name
+ * @param destDirName destination directory name
+ * @param overlay overwrite or not
+ * @return boolean
+ * @throws IOException e
+ */
+ public static boolean copyDirectory(String srcDirName, String destDirName, boolean overlay)
+ throws IOException {
+ File srcDir = new File(srcDirName);
+ if (!srcDir.exists()) {
+ return false;
+ } else if (!srcDir.isDirectory()) {
+ return false;
+ }
+
+ if (!destDirName.endsWith(File.separator)) {
+ destDirName = destDirName + File.separator;
+ }
+ File destDir = new File(destDirName);
+ if (destDir.exists()) {
+ if (overlay) {
+ new File(destDirName).delete();
+ } else {
+ return false;
+ }
+ } else {
+ if (!destDir.mkdirs()) {
+ return false;
+ }
+ }
+ boolean flag = true;
+ File[] files = srcDir.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isFile()) {
+ flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true);
+ if (!flag) {
+ break;
+ }
+ } else if (files[i].isDirectory()) {
+ flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay);
+ if (!flag) {
+ break;
+ }
+ }
+ }
+ if (!flag) {
+ String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!";
+ LOGGER.error(message);
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * copy file.
+ * @param srcFileName source file name
+ * @param destFileName target file name
+ * @param overlay overwrite or not
+ * @return boolean
+ */
+ public static boolean copyFile(String srcFileName, String destFileName, boolean overlay) {
+ File srcFile = new File(srcFileName);
+
+ if (!srcFile.exists()) {
+ String message = "Source file : " + srcFileName + " not exist !";
+ LOGGER.error(message);
+ return false;
+ } else if (!srcFile.isFile()) {
+ return false;
+ }
+
+ File destFile = new File(destFileName);
+ if (destFile.exists()) {
+ if (overlay) {
+ new File(destFileName).delete();
+ }
+ } else {
+ if (!destFile.getParentFile().exists()) {
+ if (!destFile.getParentFile().mkdirs()) {
+ return false;
+ }
+ }
+ }
+
+ int byteread = 0;
+ InputStream in = null;
+ OutputStream out = null;
+
+ try {
+ in = new FileInputStream(srcFile);
+ out = new FileOutputStream(destFile);
+ byte[] buffer = new byte[1024];
+
+ while ((byteread = in.read(buffer)) != -1) {
+ out.write(buffer, 0, byteread);
+ }
+ return true;
+ } catch (FileNotFoundException e1) {
+ return false;
+ } catch (IOException e1) {
+ return false;
+ } finally {
+ try {
+ if (out != null) {
+ out.close();
+ }
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * create directory.
+ * @param destDirName target directory name
+ * @return boolean
+ */
+ public static boolean createDir(String destDirName) {
+ File dir = new File(destDirName);
+ if (dir.exists()) {
+ dir.delete();
+ }
+ if (!destDirName.endsWith(File.separator)) {
+ destDirName = destDirName + File.separator;
+ }
+ if (dir.mkdirs()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static String getHttpServerAbsolutePath() {
+ return Thread.currentThread().getContextClassLoader().getResource("/").getPath() + HttpServerPathConfig.getHttpServerPath();
+ }
+
+ /**
+ * delete directory.
+ * @param dir file to delete
+ * @return boolean
+ */
+ public static boolean deleteDir(File dir) {
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i = 0; i < children.length; i++) {
+ boolean success = deleteDir(new File(dir, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+ return dir.delete();
+ }
+
+ public static String getAppDeployPath()
+ {
+ return Thread.currentThread().getContextClassLoader().getResource("/").getPath();
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumPackageFormat.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumPackageFormat.java
new file mode 100644
index 00000000..485e15da
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumPackageFormat.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.model.parser;
+
+/**
+ * enum data.
+ *
+ * @author 10189609
+ *
+ */
+public enum EnumPackageFormat {
+ TOSCA_XML, TOSCA_YAML
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumTemplateType.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumTemplateType.java
new file mode 100644
index 00000000..e634aea7
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/model/parser/EnumTemplateType.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.model.parser;
+
+public enum EnumTemplateType {
+ NS, VNF
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/AppServletContextListener.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/AppServletContextListener.java
new file mode 100644
index 00000000..9ea074cb
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/AppServletContextListener.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.msb;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class AppServletContextListener implements ServletContextListener
+{
+
+ public void contextInitialized(ServletContextEvent eventData)
+ {
+ MsbRegister.handleMsbRegistration();
+ }
+
+ public void contextDestroyed(ServletContextEvent eventData)
+ {
+ MsbRegister.handleMsbUnRegistration();
+ }
+}
+
+
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetails.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetails.java
new file mode 100644
index 00000000..ab4190ee
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetails.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.msb;
+
+public class MsbDetails
+{
+ private MsbServer defaultServer;
+ private String ConnectTimeout;
+ private String thread;
+ private String idletimeout;
+ private String timeout;
+
+ public MsbServer getDefaultServer() {
+ return defaultServer;
+ }
+ public void setDefaultServer(MsbServer defaultServer) {
+ this.defaultServer = defaultServer;
+ }
+ public String getConnectTimeout() {
+ return ConnectTimeout;
+ }
+ public void setConnectTimeout(String connectTimeout) {
+ ConnectTimeout = connectTimeout;
+ }
+ public String getThread() {
+ return thread;
+ }
+ public void setThread(String thread) {
+ this.thread = thread;
+ }
+ public String getIdletimeout() {
+ return idletimeout;
+ }
+ public void setIdletimeout(String idletimeout) {
+ this.idletimeout = idletimeout;
+ }
+ public String getTimeout() {
+ return timeout;
+ }
+ public void setTimeout(String timeout) {
+ this.timeout = timeout;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetailsHolder.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetailsHolder.java
new file mode 100644
index 00000000..8c1d86ab
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbDetailsHolder.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.msb;
+
+import org.openo.vnfsdk.marketplace.common.FileUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MsbDetailsHolder
+{
+ private static final Logger logger = LoggerFactory.getLogger(MsbDetailsHolder.class);
+ private static final String MSB_DETAILS_PATH = "etc/conf/restclient.json";
+ private static MsbDetails msbDetails = null;
+
+ private MsbDetailsHolder(){
+ }
+
+ public static synchronized MsbDetails getMsbDetails()
+ {
+ MsbDetailsHolder.loadMsbDetails();
+ return msbDetails;
+ }
+
+ private static synchronized void loadMsbDetails ()
+ {
+ if(null != msbDetails) {
+ return;
+ }
+
+ msbDetails = (MsbDetails)FileUtil.readJsonDatafFromFile(MSB_DETAILS_PATH, MsbDetails.class);
+ if (null == msbDetails)
+ {
+ logger.error("Failed to Load MSB Details !!!");
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegister.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegister.java
new file mode 100644
index 00000000..6ade1414
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegister.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.msb;
+
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MsbRegister
+{
+ private static final Logger logger = LoggerFactory.getLogger(MsbRegister.class);
+
+ /**
+ * Interface top handle MSB Registration
+ */
+ public static void handleMsbRegistration()
+ {
+ logger.info("VNF-SDK Market Place microservice register start.");
+ int retry = 0;
+ while(CommonConstant.MsbRegisterCode.MSDB_REGISTER_RETRIES >= retry)
+ {
+ int retCode = MsbRegistration.getInstance().register();
+ if(CommonConstant.MsbRegisterCode.MSDB_REGISTER_FILE_NOT_EXISTS == retCode)
+ {
+ logger.info("microservice register failed, MSB Register File Not Exists !");
+ break;
+ }
+
+ if(CommonConstant.MsbRegisterCode.MSDB_REGISTER_SUCESS != retCode)
+ {
+ logger.warn("microservice register failed, try again after(ms):" + CommonConstant.MsbRegisterCode.MSDB_REGISTER_RETRY_SLEEP);
+ threadSleep(CommonConstant.MsbRegisterCode.MSDB_REGISTER_RETRY_SLEEP);
+ }
+ else
+ {
+ logger.info("microservice register success !");
+ break;
+ }
+
+ retry++;
+ logger.info("VNF-SDK Market Place microservice register [retry count]:" + retry);
+ }
+ logger.info("VNF-SDK Market Place microservice register end.");
+ }
+
+ public static void handleMsbUnRegistration()
+ {
+ logger.info("VNF-SDK Market Place microservice handleMsbUnRegistration Start.");
+ MsbRegistration.getInstance().unRegister();
+ logger.info("VNF-SDK Market Place microservice handleMsbUnRegistration end.");
+ }
+
+ private static void threadSleep(int second)
+ {
+ try
+ {
+ Thread.sleep(second);
+ }
+ catch(InterruptedException error)
+ {
+ logger.error("thread sleep error.errorMsg:", error);
+ Thread.currentThread().interrupt();
+ }
+ }
+}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegistration.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegistration.java
new file mode 100644
index 00000000..e1f39084
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbRegistration.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.msb;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.openo.vnfsdk.marketplace.common.JsonUtil;
+import org.openo.vnfsdk.marketplace.rest.RestResponse;
+import org.openo.vnfsdk.marketplace.rest.RestfulClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class MsbRegistration {
+ private static final Logger LOGGER = LoggerFactory.getLogger(MsbRegistration.class);
+
+ private static MsbRegistration oMsbRegistration = new MsbRegistration();
+
+ private static final String MSB_REGISTION_FILE = "etc/microservice/marketplace_rest.json";
+ private static final String MSB_REGISTION_URL = "/openoapi/microservices/v1/services?createOrUpdate=false";
+ private static final String MSB_UN_REGISTION_URL = "/openoapi/microservices/v1/services/{0}/version/{1}/nodes/{2}/{3}";
+ private static final String NODES = "nodes";
+ private static final String IP = "ip";
+ private static final String PORT = "port";
+ private static final String SERVICE_NAME = "serviceName";
+ private static final String VERSION = "version";
+
+ private boolean bRegistrationStatus = false;
+
+ private MsbRegistration () {
+ }
+
+ public static MsbRegistration getInstance()
+ {
+ return oMsbRegistration;
+ }
+ /**
+ * Interface to handle MSB Registration
+ * @return
+ */
+ public int register()
+ {
+ File file = new File(MSB_REGISTION_FILE);
+ if(!file.exists())
+ {
+ LOGGER.info("Stop registering as can't find msb registion file:" + file.getAbsolutePath());
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_FILE_NOT_EXISTS;
+ }
+
+ Map<?, ?> msbRegistionBodyMap = getMsbRegistrationData();
+ if(null == msbRegistionBodyMap)
+ {
+ LOGGER.info("Reading data from msb registion file failed:" + file.getAbsolutePath());
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_FILE_NOT_EXISTS;
+ }
+
+ LOGGER.info("Registering body: " + JsonUtil.toJson(msbRegistionBodyMap));
+
+ bRegistrationStatus = sendRequest(msbRegistionBodyMap);
+
+ return bRegistrationStatus
+ ? CommonConstant.MsbRegisterCode.MSDB_REGISTER_SUCESS
+ : CommonConstant.MsbRegisterCode.MSDB_REGISTER_FAILED;
+ }
+
+ private Map<?, ?> getMsbRegistrationData()
+ {
+ Map<?, ?> msbRegistionBodyMap = null;
+ try
+ {
+ ObjectMapper mapper = new ObjectMapper();
+ byte[] bytes = Files.readAllBytes(Paths.get(MSB_REGISTION_FILE));
+ msbRegistionBodyMap = mapper.readValue(bytes, Map.class);
+
+ replaceLocalIp(msbRegistionBodyMap);
+ }
+ catch(IOException e)
+ {
+ LOGGER.error("Failed to get microservice bus registration body, " + e);
+ }
+ return msbRegistionBodyMap;
+ }
+
+ /**
+ * Send MSB Registration request
+ * @param msbRegistionBodyMap
+ * @return
+ */
+ private boolean sendRequest(Map<?, ?> msbRegistionBodyMap)
+ {
+ LOGGER.info("Start registering to microservice bus");
+ String rawData = JsonUtil.toJson(msbRegistionBodyMap);
+ MsbDetails oMsbDetails = MsbDetailsHolder.getMsbDetails();
+ if(null == oMsbDetails) {
+ LOGGER.info("MSB Details is NULL , Registration Failed !!!");
+ return false;
+ }
+ RestResponse oResponse = RestfulClient.sendPostRequest(oMsbDetails.getDefaultServer().getHost(),
+ oMsbDetails.getDefaultServer().getPort(),
+ MSB_REGISTION_URL, rawData);
+
+ if(null == oResponse){
+ LOGGER.info("Null Unregister Response for " + MSB_REGISTION_URL);
+ return false;
+ }
+ LOGGER.info("Response Code Received for MBS Registration:" + oResponse.getStatusCode());
+ return isSuccess(oResponse.getStatusCode()) ? true : false;
+ }
+
+ public int unRegister()
+ {
+ if(!bRegistrationStatus){
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_SUCESS;
+ }
+
+ MsbDetails oMsbDetails = MsbDetailsHolder.getMsbDetails();
+ if(null == oMsbDetails){
+ LOGGER.info("MSB Details is NULL , Registration Failed !!!");
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_FAILED;
+ }
+
+ File file = new File(MSB_REGISTION_FILE);
+ if(!file.exists()){
+ LOGGER.info("Stop registering as can't find msb registion file:" + file.getAbsolutePath());
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_FILE_NOT_EXISTS;
+ }
+
+ Map<?, ?> msbRegistionBodyMap = getMsbRegistrationData();
+ if(null == msbRegistionBodyMap){
+ LOGGER.info("Reading data from msb registion file failed:" + file.getAbsolutePath());
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_FILE_NOT_EXISTS;
+ }
+
+ String serviceName = (String)msbRegistionBodyMap.get(SERVICE_NAME);
+ String version = (String)msbRegistionBodyMap.get(VERSION);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, String>> nodes = (List<Map<String, String>>)msbRegistionBodyMap.get(NODES);
+ if((null == serviceName ) || (null == version ) || (null == nodes ))
+ {
+ LOGGER.info("Readed data is Invalid from msb registion file:" + file.getAbsolutePath());
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_FILE_NOT_EXISTS;
+ }
+
+ Map<String, String> node = nodes.get(0);
+ String ip = node.get(IP);
+ String port = node.get(PORT);
+
+ String url = MessageFormat.format(MSB_UN_REGISTION_URL, serviceName, version, ip, port);
+ LOGGER.info("Start Unregister to microservice bus, url: " + url);
+
+ RestResponse oResponse = RestfulClient.delete(oMsbDetails.getDefaultServer().getHost(),
+ Integer.parseInt(oMsbDetails.getDefaultServer().getPort()),url);
+
+ if(null == oResponse) {
+ LOGGER.info("Null Unregister Response for " + url);
+ return CommonConstant.MsbRegisterCode.MSDB_REGISTER_FAILED;
+ }
+ LOGGER.info("Unregister Response " + oResponse.getStatusCode());
+ return isSuccess(oResponse.getStatusCode()) ?
+ CommonConstant.MsbRegisterCode.MSDB_REGISTER_SUCESS :
+ CommonConstant.MsbRegisterCode.MSDB_REGISTER_FAILED;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void replaceLocalIp(Map<?, ?> msbRegistionBodyMap)
+ {
+ List<Map<String, String>> nodes = (List<Map<String, String>>)msbRegistionBodyMap.get(NODES);
+ Map<String, String> node = nodes.get(0);
+ if(StringUtils.isNotEmpty(node.get(IP))) {
+ return;
+ }
+
+ try
+ {
+ InetAddress addr = InetAddress.getLocalHost();
+ String ipAddress = addr.getHostAddress();
+ node.put(IP, ipAddress);
+
+ LOGGER.info("Local ip: " + ipAddress);
+ }
+ catch(UnknownHostException e)
+ {
+ LOGGER.error("Unable to get IP address, " + e);
+ }
+ }
+
+ private boolean isSuccess(int httpCode)
+ {
+ return (httpCode == 200 || httpCode == 201) ? true : false;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbServer.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbServer.java
new file mode 100644
index 00000000..fa3bcb02
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/msb/MsbServer.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.msb;
+
+public class MsbServer
+{
+ private String host;
+ private String port;
+
+ public String getHost() {
+ return host;
+ }
+ public void setHost(String host) {
+ this.host = host;
+ }
+ public String getPort() {
+ return port;
+ }
+ public void setPort(String port) {
+ this.port = port;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingOperResult.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingOperResult.java
new file mode 100644
index 00000000..68d85987
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingOperResult.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+public class OnBoardingOperResult
+{
+ private String operId;
+ private int status;
+ public String getOperId() {
+ return operId;
+ }
+ public void setOperId(String operId) {
+ this.operId = operId;
+ }
+ public int getStatus() {
+ return status;
+ }
+ public void setStatus(int status) {
+ this.status = status;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingResult.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingResult.java
new file mode 100644
index 00000000..52bfe100
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingResult.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+
+import java.util.List;
+
+public class OnBoardingResult
+{
+ private String csarId;
+ private String operTypeId;
+ private boolean operFinished;
+ private int operStatus;
+
+ private List<OnBoardingOperResult> operResult;
+
+ public String getOperTypeId() {
+ return operTypeId;
+ }
+ public void setOperTypeId(String operTypeId) {
+ this.operTypeId = operTypeId;
+ }
+ public boolean isOperFinished() {
+ return operFinished;
+ }
+ public void setOperFinished(boolean operFinished) {
+ this.operFinished = operFinished;
+ }
+
+ public List<OnBoardingOperResult> getOperResult() {
+ return operResult;
+ }
+ public void setOperResult(List<OnBoardingOperResult> operResult) {
+ this.operResult = operResult;
+ }
+ public int getOperStatus() {
+ return operStatus;
+ }
+ public void setOperStatus(int operStatus) {
+ this.operStatus = operStatus;
+ }
+ public String getCsarId() {
+ return csarId;
+ }
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingStep.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingStep.java
new file mode 100644
index 00000000..b8a18085
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingStep.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+
+import java.util.List;
+
+public class OnBoardingStep
+{
+ private String operTypeName;
+ private String operTypeId;
+ private List<OperationDetails> oper;
+
+ public String getOperTypeName() {
+ return operTypeName;
+ }
+ public void setOperTypeName(String operTypeName) {
+ this.operTypeName = operTypeName;
+ }
+ public String getOperTypeId() {
+ return operTypeId;
+ }
+ public void setOperTypeId(String operTypeId) {
+ this.operTypeId = operTypeId;
+ }
+ public List<OperationDetails> getOper() {
+ return oper;
+ }
+ public void setOper(List<OperationDetails> oper) {
+ this.oper = oper;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingSteps.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingSteps.java
new file mode 100644
index 00000000..24410e86
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoardingSteps.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+
+import java.util.List;
+
+public class OnBoardingSteps
+{
+ private List<OnBoardingStep> operTypeList;
+
+ public List<OnBoardingStep> getOperTypeList() {
+ return operTypeList;
+ }
+
+ public void setOperTypeList(List<OnBoardingStep> operTypeList) {
+ this.operTypeList = operTypeList;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoradingRequest.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoradingRequest.java
new file mode 100644
index 00000000..622c1731
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OnBoradingRequest.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+
+public class OnBoradingRequest {
+ private String csarId;
+ private String packageName;
+ private String packagePath;
+ private String csarIdCatalouge;
+
+ public String getPackagePath() {
+ return packagePath;
+ }
+ public void setPackagePath(String packagePath) {
+ this.packagePath = packagePath;
+ }
+ public String getCsarId() {
+ return csarId;
+ }
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+ public String getPackageName() {
+ return packageName;
+ }
+ public void setPackageName(String packageName) {
+ this.packageName = packageName;
+ }
+ public String getCsarIdCatalouge() {
+ return csarIdCatalouge;
+ }
+ public void setCsarIdCatalouge(String csarIdCatalouge) {
+ this.csarIdCatalouge = csarIdCatalouge;
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationDetails.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationDetails.java
new file mode 100644
index 00000000..e8017320
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationDetails.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+
+public class OperationDetails
+{
+ private String operId;
+ private String operName;
+ public String getOperId() {
+ return operId;
+ }
+ public void setOperId(String operId) {
+ this.operId = operId;
+ }
+ public String getOperName() {
+ return operName;
+ }
+ public void setOperName(String operName) {
+ this.operName = operName;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationResult.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationResult.java
new file mode 100644
index 00000000..af7a33ae
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/OperationResult.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+
+import java.util.List;
+
+public class OperationResult
+{
+ private String csarId;
+ private String operTypeId;
+ private boolean operFinished;
+ private int operStatus;
+
+ private List<OnBoardingOperResult> operResult;
+
+ public String getOperTypeId() {
+ return operTypeId;
+ }
+ public void setOperTypeId(String operTypeId) {
+ this.operTypeId = operTypeId;
+ }
+ public boolean isOperFinished() {
+ return operFinished;
+ }
+ public void setOperFinished(boolean operFinished) {
+ this.operFinished = operFinished;
+ }
+
+ public List<OnBoardingOperResult> getOperResult() {
+ return operResult;
+ }
+ public void setOperResult(List<OnBoardingOperResult> operResult) {
+ this.operResult = operResult;
+ }
+ public int getOperStatus() {
+ return operStatus;
+ }
+ public void setOperStatus(int operStatus) {
+ this.operStatus = operStatus;
+ }
+ public String getCsarId() {
+ return csarId;
+ }
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/ResultKey.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/ResultKey.java
new file mode 100644
index 00000000..117325b9
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/entity/ResultKey.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.entity;
+
+public class ResultKey
+{
+ private String csarId;
+ private String operTypeId;
+ private String key;
+ public String getCsarId() {
+ return csarId;
+ }
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+ public String getOperTypeId() {
+ return operTypeId;
+ }
+ public void setOperTypeId(String operTypeId) {
+ this.operTypeId = operTypeId;
+ }
+ public String getKey() {
+ return key;
+ }
+ public void setKey(String key) {
+ this.key = key;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java
new file mode 100644
index 00000000..336a40f0
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java
@@ -0,0 +1,220 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.functiontest;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.openo.vnfsdk.marketplace.common.FileUtil;
+import org.openo.vnfsdk.marketplace.msb.MsbDetails;
+import org.openo.vnfsdk.marketplace.msb.MsbDetailsHolder;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
+import org.openo.vnfsdk.marketplace.rest.RestConstant;
+import org.openo.vnfsdk.marketplace.rest.RestResponse;
+import org.openo.vnfsdk.marketplace.rest.RestfulClient;
+import org.openo.vnfsdk.marketplace.rest.RestfulUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FunctionTestExceutor
+{
+ private static final Logger logger = LoggerFactory.getLogger(FunctionTestExceutor.class);
+
+ private FunctionTestExceutor()
+ {}
+
+ /**
+ * Interface to Send Request to Start Function test
+ * @param onBoradFuncTestReq
+ * @return
+ */
+ public static String execFunctionTest(OnBoradingRequest onBoradFuncTestReq)
+ {
+ String packagePath = onBoradFuncTestReq.getPackagePath() + File.separator + onBoradFuncTestReq.getPackageName();
+ logger.info("Package file path Function test:" + packagePath);
+
+ String funcTestId = null;
+ MsbDetails oMsbDetails = MsbDetailsHolder.getMsbDetails();
+ if(null == oMsbDetails)
+ {
+ logger.error("Failed to get MSB details during execFunctionTest !!!");
+ return funcTestId;
+ }
+
+ FileInputStream ifs = null;
+ InputStream inStream = null;
+
+ try
+ {
+ ifs = new FileInputStream(packagePath);
+ inStream = new BufferedInputStream(ifs);
+
+ //IP and Port needs to be configured !!!
+ RestResponse rsp = RestfulClient.post(oMsbDetails.getDefaultServer().getHost(),
+ Integer.parseInt(oMsbDetails.getDefaultServer().getPort()),
+ CommonConstant.functionTest.FUNCTEST_URL,buildRequest(inStream));
+ if(!checkValidResponse(rsp))
+ {
+ return funcTestId;
+ }
+
+ logger.error("Response for Function Test :" , rsp.getResult());
+ funcTestId = rsp.getResult();
+ return funcTestId.replaceAll("\"", "");
+ }
+ catch (FileNotFoundException exp)
+ {
+ logger.error("Fine not fond Exception for file:" , onBoradFuncTestReq.getPackagePath());
+ logger.error("Fine not fond Exception for :" , exp);
+ }
+ finally
+ {
+ FileUtil.closeInputStream(inStream);
+ FileUtil.closeFileStream(ifs);
+ }
+ return funcTestId;
+ }
+
+ /**
+ * Interface to get Function Test Results
+ * @param key
+ * @return
+ */
+ public static String getTestResultsByFuncTestKey(String key)
+ {
+ MsbDetails oMsbDetails = MsbDetailsHolder.getMsbDetails();
+ if(null == oMsbDetails)
+ {
+ logger.error("Failed to get MSB details during getTestResultsByFuncTestKey !!!");
+ return null;
+ }
+
+ logger.info("getTestResultsByFuncTestKey for Function Test Results for :" + key);
+ RestResponse rspGet = RestfulClient.get(oMsbDetails.getDefaultServer().getHost(),
+ Integer.parseInt(oMsbDetails.getDefaultServer().getPort()),
+ CommonConstant.functionTest.FUNCTEST_RESULT_URL + key);
+ if(!checkValidResponse(rspGet))
+ {
+ logger.error("Failed to convert String Json Response to TestResults list:" + rspGet.getResult());
+ return null;
+ }
+ logger.info("Function Test Results for Key:" + key + "Response:" + rspGet.getResult());
+ return rspGet.getResult();
+ }
+
+ /**
+ * Interface to get Function Test Results
+ * @param key
+ * @return
+ */
+ public static String executeFunctionTest(String strJsonRequest)
+ {
+ logger.info("executeFunctionTest Test request Received:" + strJsonRequest);
+ MsbDetails oMsbDetails = MsbDetailsHolder.getMsbDetails();
+ if(null == oMsbDetails)
+ {
+ logger.error("Failed to get MSB details during getTestResultsByFuncTestKey !!!");
+ return null;
+ }
+
+ logger.info("getTestResultsByFuncTestKey for Function Test Results for :" + strJsonRequest);
+ RestResponse rspGet = RestfulClient.sendPostRequest(oMsbDetails.getDefaultServer().getHost(),
+ oMsbDetails.getDefaultServer().getPort(),
+ CommonConstant.functionTest.FUNCTEST_RESULT_URL,
+ strJsonRequest);
+ if(!checkValidResponse(rspGet))
+ {
+ logger.error("Failed to convert String Json Response to TestResults list:" + rspGet.getResult());
+ return null;
+ }
+ logger.info("executeFunctionTest Function Test Result: " + rspGet.getResult());
+ return rspGet.getResult();
+ }
+
+ /**
+ * Interface to get Function Test Results
+ * @param key
+ * @return
+ */
+ public static String getTestResultsByFuncTestKeyMsb(String key)
+ {
+ logger.info("getTestResultsByFuncTestKey for Function Test Results for :" + key);
+
+ Map<String, String> paramsMap = new HashMap<String, String>();
+ paramsMap.put(CommonConstant.HttpContext.URL, CommonConstant.functionTest.FUNCTEST_RESULT_URL + key);
+ paramsMap.put(CommonConstant.HttpContext.METHOD_TYPE, CommonConstant.MethodType.GET);
+
+ RestfulResponse response = RestfulUtil.sendRestRequest(paramsMap, null, null);
+ if(!checkValidRestResponse(response))
+ {
+ logger.error("Respone for getTestResultsByFuncTestKeyMsb is not valid !!!");
+ return null;
+ }
+
+ if(null != response.getResponseContent())
+ {
+ logger.info("Function Test Results via MSB for Key:" + key + "Response:" + response.getResponseContent());
+ }
+ else
+ {
+ logger.info("NULL Function Test Results via MSB for Key:" + key);
+ }
+ return response.getResponseContent();
+ }
+
+ /**
+ * Check Response is Valid
+ * @param rsp
+ * @return
+ */
+ private static boolean checkValidResponse(RestResponse rsp)
+ {
+ if (rsp.getStatusCode() == null || rsp.getResult() == null
+ || (RestConstant.RESPONSE_CODE_200 != rsp.getStatusCode() && RestConstant.RESPONSE_CODE_201 != rsp.getStatusCode()))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean checkValidRestResponse(RestfulResponse rsp)
+ {
+ if ((rsp == null) || (RestConstant.RESPONSE_CODE_200 != rsp.getStatus() && RestConstant.RESPONSE_CODE_201 != rsp.getStatus()))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ @SuppressWarnings("deprecation")
+ private static HttpEntity buildRequest(InputStream inputStream)
+ throws FileNotFoundException {
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+ builder.seContentType(ContentType.MULTIPART_FORM_DATA);
+ builder.addBinaryBody("file", inputStream);
+ return builder.build();
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java
new file mode 100644
index 00000000..f15d379e
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java
@@ -0,0 +1,217 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.functiontest;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.openo.vnfsdk.marketplace.common.FileUtil;
+import org.openo.vnfsdk.marketplace.common.ToolUtil;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.entity.EnumOperationStatus;
+import org.openo.vnfsdk.marketplace.entity.EnumResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingOperResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
+import org.openo.vnfsdk.marketplace.onboarding.entity.ResultKey;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FunctionTestHook
+{
+ private static final Logger logger = LoggerFactory.getLogger(FunctionTestHook.class);
+
+ /**
+ * Start Executing Function test
+ * @param onBoradingReq
+ * @return
+ */
+ public int exec(OnBoradingRequest onBoradingReq)
+ {
+ logger.info("OnboradingRequest received for Package:" + onBoradingReq.getCsarId() + " Path:"+ onBoradingReq.getPackagePath());
+
+ buildResultPath(onBoradingReq);
+
+ OnBoardingResult oFuncTestResult = new OnBoardingResult();
+ buildFunctResponse(onBoradingReq,oFuncTestResult);
+ updateResult(oFuncTestResult);
+
+ //STEP 1:Check Package Exists
+ //---------------------------
+ if(!FileUtil.checkFileExists(onBoradingReq.getPackagePath()))
+ {
+ logger.info("Package Not Found at Path:" + onBoradingReq.getPackagePath() + ", Package Id:" + onBoradingReq.getCsarId());
+ oFuncTestResult.setOperFinished(true);
+ oFuncTestResult.setOperStatus(EnumResult.FAIL.getIndex());
+ buildFuncTestResponse(oFuncTestResult,CommonConstant.functionTest.FUNCTEST_PACKAGE_EXISTS,EnumOperationStatus.FAILED.getIndex());
+ updateResult(oFuncTestResult);
+ return EnumResult.FAIL.getIndex();
+ }
+
+ buildFuncTestResponse(oFuncTestResult,CommonConstant.functionTest.FUNCTEST_PACKAGE_EXISTS,EnumOperationStatus.SUCCESS.getIndex());
+ updateResult(oFuncTestResult);
+
+ //STEP 2:Handle function test for Package
+ //---------------------------------------
+ String functestResultKey = FunctionTestExceutor.execFunctionTest(onBoradingReq);
+ if(null == functestResultKey)
+ {
+ oFuncTestResult.setOperFinished(true);
+ oFuncTestResult.setOperStatus(EnumResult.FAIL.getIndex());
+ buildFuncTestResponse(oFuncTestResult,CommonConstant.functionTest.FUNCTEST_EXEC,EnumOperationStatus.FAILED.getIndex());
+ updateResult(oFuncTestResult);
+ return EnumResult.FAIL.getIndex();
+ }
+
+ oFuncTestResult.setOperFinished(true);
+ oFuncTestResult.setOperStatus(EnumResult.SUCCESS.getIndex());
+ buildFuncTestResponse(oFuncTestResult,CommonConstant.functionTest.FUNCTEST_EXEC,EnumOperationStatus.SUCCESS.getIndex());
+ updateResult(oFuncTestResult);
+
+ //STEP 3:Store FuncTest key to get FuncTest Results
+ //-------------------------------------------------
+ storeFuncTestResultKey(onBoradingReq,functestResultKey);
+
+ return (oFuncTestResult.getOperStatus() == EnumResult.SUCCESS.getIndex())
+ ? EnumResult.SUCCESS.getIndex() : EnumResult.FAIL.getIndex();
+ }
+
+ /**
+ *
+ * @param onBoradingReq
+ */
+ private void buildResultPath(OnBoradingRequest onBoradingReq)
+ {
+ String filePath = getResultStorePath() + File.separator + onBoradingReq.getCsarId();
+ if(!FileUtil.checkFileExists(filePath))
+ {
+ FileUtil.createDirectory(filePath);
+ }
+ }
+
+ /**
+ *
+ * @param packageData
+ * @return
+ */
+ public static String getFuncTestResults(PackageData packageData)
+ {
+ logger.info("Function Test results request for Package:" + packageData.getCsarId());
+ ResultKey keydata = getFuncTestResultKey(packageData);
+ if(null == keydata || keydata.getKey().isEmpty())
+ {
+ logger.info("Function Test key Not Found for Package Id:",packageData.getCsarId());
+ return null;
+ }
+ return FunctionTestExceutor.getTestResultsByFuncTestKey(keydata.getKey());
+ }
+
+ /**
+ * Store Function Test Result key
+ * @param onBoradingReq
+ * @param resultKey
+ */
+ private void storeFuncTestResultKey(OnBoradingRequest onBoradingReq,String resultKey)
+ {
+ //Currently we will make JSON and Store JSON to Package Path)
+ //-------------------------------------------------------------------------------
+ String filePath = getResultStorePath() + File.separator + onBoradingReq.getCsarId() + File.separator + "functestResultKey.json";
+
+ logger.info("Function test Results Key for Package Id:" + onBoradingReq.getCsarId() + ", Key:" + resultKey + " Path" + filePath);
+
+ ResultKey oResultKey = new ResultKey();
+ oResultKey.setCsarId(onBoradingReq.getCsarId());
+ oResultKey.setOperTypeId(CommonConstant.functionTest.FUNCTEST_OPERTYPE_ID);
+ oResultKey.setKey(resultKey);
+
+ FileUtil.writeJsonDatatoFile(filePath,oResultKey);
+ }
+
+ /**
+ * Store Function test Execution Results
+ * @param oFuncTestResult
+ */
+ private void updateResult(OnBoardingResult oFuncTestResult)
+ {
+ //STore Results to DB(Currently we will make JSON and Store JSON to Package Path)
+ //-------------------------------------------------------------------------------
+ logger.info("Function test Status for Package Id:" + oFuncTestResult.getCsarId() + ", Result:" + ToolUtil.objectToString(oFuncTestResult));
+ String filePath = getResultStorePath() + File.separator + oFuncTestResult.getCsarId() + File.separator + "functionTest.json";
+ FileUtil.writeJsonDatatoFile(filePath,oFuncTestResult);
+ }
+
+ /**
+ * Build Function Test Response
+ * @param onBoradingReq
+ * @param oFuncTestResult
+ */
+ private void buildFunctResponse(OnBoradingRequest onBoradingReq, OnBoardingResult oFuncTestResult)
+ {
+ oFuncTestResult.setOperFinished(false);
+ oFuncTestResult.setCsarId(onBoradingReq.getCsarId());
+ oFuncTestResult.setOperTypeId(CommonConstant.functionTest.FUNCTEST_OPERTYPE_ID);
+
+ OnBoardingOperResult oPackageExists = new OnBoardingOperResult();
+ oPackageExists.setOperId(CommonConstant.functionTest.FUNCTEST_PACKAGE_EXISTS);
+ oPackageExists.setStatus(EnumOperationStatus.NOTSTARTED.getIndex());
+
+ OnBoardingOperResult functTesExec = new OnBoardingOperResult();
+ functTesExec.setOperId(CommonConstant.functionTest.FUNCTEST_EXEC);
+ functTesExec.setStatus(EnumOperationStatus.NOTSTARTED.getIndex());
+
+ List<OnBoardingOperResult> operResult = new ArrayList<OnBoardingOperResult>();
+ operResult.add(oPackageExists);
+ operResult.add(functTesExec);
+
+ oFuncTestResult.setOperResult(operResult);
+ }
+
+ public static OnBoardingResult getOnBoardingResult(PackageData packageData)
+ {
+ String filePath = getResultStorePath() + File.separator + packageData.getCsarId() +File.separator + "functionTest.json";
+ logger.info("On Boarding Status for Package Id:" + packageData.getCsarId() + ", Result Path:" + filePath);
+
+ return (OnBoardingResult)FileUtil.readJsonDatafFromFile(filePath,OnBoardingResult.class);
+ }
+
+ private static ResultKey getFuncTestResultKey(PackageData packageData)
+ {
+ String fileName = getResultStorePath() + File.separator + packageData.getCsarId() + File.separator + "functestResultKey.json";
+
+ logger.info("Func Test Result key for Package Id:" + packageData.getCsarId() + ", Result Path:" + fileName);
+ return (ResultKey) FileUtil.readJsonDatafFromFile(fileName,ResultKey.class);
+ }
+
+ private static String getResultStorePath()
+ {
+ return org.openo.vnfsdk.marketplace.filemanage.http.ToolUtil.getHttpServerAbsolutePath();
+ }
+
+ private void buildFuncTestResponse(OnBoardingResult oFuncTestResult, String opreKey, int operStatusVal)
+ {
+ List<OnBoardingOperResult> operStatusList = oFuncTestResult.getOperResult();
+ for(OnBoardingOperResult operObj: operStatusList)
+ {
+ if(operObj.getOperId().equalsIgnoreCase(opreKey))
+ {
+ operObj.setStatus(operStatusVal);
+ break;
+ }
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifeCycleTestReq.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifeCycleTestReq.java
new file mode 100644
index 00000000..5a5db23c
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifeCycleTestReq.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle;
+
+import java.util.List;
+
+public class LifeCycleTestReq
+{
+ private String csarId;
+ private String labVimId;
+ private List<String> vimIds;
+ public String getCsarId() {
+ return csarId;
+ }
+ public void setCsarId(String csarId) {
+ this.csarId = csarId;
+ }
+ public String getLabVimId() {
+ return labVimId;
+ }
+ public void setLabVimId(String labVimId) {
+ this.labVimId = labVimId;
+ }
+ public List<String> getVimIds() {
+ return vimIds;
+ }
+ public void setVimIds(List<String> vimIds) {
+ this.vimIds = vimIds;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java
new file mode 100644
index 00000000..982b2140
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java
@@ -0,0 +1,156 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.openo.vnfsdk.marketplace.common.JsonUtil;
+import org.openo.vnfsdk.marketplace.msb.MsbDetails;
+import org.openo.vnfsdk.marketplace.msb.MsbDetailsHolder;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
+import org.openo.vnfsdk.marketplace.rest.RestConstant;
+import org.openo.vnfsdk.marketplace.rest.RestResponse;
+import org.openo.vnfsdk.marketplace.rest.RestfulClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class LifecycleTestExceutor
+{
+ private static final Logger logger = LoggerFactory.getLogger(LifecycleTestExceutor.class);
+ public static final String CATALOUGE_UPLOAD_URL_IN = "{0}:{1}/openoapi/catalog/v1/csars";
+
+ private LifecycleTestExceutor()
+ {}
+
+ /**
+ * Interface to Send Request to Start Function test
+ * @param onBoradFuncTestReq
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static String uploadPackageToCatalouge(OnBoradingRequest onBoradFuncTestReq)
+ {
+ String packagePath = onBoradFuncTestReq.getPackagePath() + File.separator + onBoradFuncTestReq.getPackageName();
+ logger.info("Package file path uploadPackageToCatalouge:" + packagePath);
+
+ String catalougeCsarId = null;
+ MsbDetails oMsbDetails = MsbDetailsHolder.getMsbDetails();
+ if(null == oMsbDetails)
+ {
+ logger.error("Failed to get MSB details during uploadPackageToCatalouge !!!");
+ return catalougeCsarId;
+ }
+
+ File fileData = new File (packagePath);
+
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+ builder.addBinaryBody("file", fileData, ContentType.MULTIPART_FORM_DATA, onBoradFuncTestReq.getPackageName());
+
+ //IP and Port needs to be configured !!!
+ RestResponse rsp = RestfulClient.post(oMsbDetails.getDefaultServer().getHost(),Integer.parseInt(oMsbDetails.getDefaultServer().getPort()),CommonConstant.CATALOUGE_UPLOAD_URL,builder.build());
+ if(!checkValidResponse(rsp))
+ {
+ logger.error("Failed to upload package to catalouge:" + rsp.getStatusCode());
+ return catalougeCsarId;
+ }
+
+ logger.info("Response for uploadPackageToCatalouge :" + rsp.getResult());
+ catalougeCsarId = getCsarIdValue(rsp.getResult());
+
+ logger.info("CSARID for uploadPackageToCatalouge :" + catalougeCsarId);
+ return catalougeCsarId;
+ }
+
+
+
+
+ public static String execlifecycleTest(OnBoradingRequest onBoradFuncTestReq, LifeCycleTestReq oLifeCycleTestReq)
+ {
+ String packagePath = onBoradFuncTestReq.getPackagePath() + File.separator + onBoradFuncTestReq.getPackageName();
+ logger.info("Package file path Function test:" + packagePath);
+
+ MsbDetails oMsbDetails = MsbDetailsHolder.getMsbDetails();
+ if(null == oMsbDetails) {
+ logger.error("Failed to get MSB details during execlifecycleTest !!!");
+ return null;
+ }
+
+ String rawDataJson = JsonUtil.toJson(oLifeCycleTestReq);
+ if(null == rawDataJson) {
+ logger.error("Failed to convert LifeCycleTestReq object to Json String !!!");
+ return null;
+ }
+
+ RestResponse oResponse = RestfulClient.sendPostRequest(oMsbDetails.getDefaultServer().getHost(),
+ oMsbDetails.getDefaultServer().getPort(),
+ CommonConstant.LifeCycleTest.LIFECYCLE_TEST_URL, rawDataJson);
+
+ if(!checkValidResponse(oResponse)) {
+ logger.error("execlifecycleTest response is faliure :"+ oResponse.getStatusCode());
+ return null;
+ }
+ logger.info("Response execlifecycleTest :"+ oResponse.getResult());
+ return oResponse.getResult();
+ }
+
+ /**
+ * Check Response is Valid
+ * @param rsp
+ * @return
+ */
+ private static boolean checkValidResponse(RestResponse rsp)
+ {
+ if (rsp.getStatusCode() == null || rsp.getResult() == null
+ || (RestConstant.RESPONSE_CODE_200 != rsp.getStatusCode() && RestConstant.RESPONSE_CODE_201 != rsp.getStatusCode()))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @param strJsonData
+ * @return
+ */
+ private static String getCsarIdValue(String strJsonData)
+ {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ Map<String, String> dataMap = null;
+ try
+ {
+ dataMap = (Map<String, String>)mapper.readValue(strJsonData, Map.class);
+ } catch(JsonParseException e) {
+ logger.error("JsonParseException:Failed to upload package to catalouge:");
+ } catch(JsonMappingException e) {
+ logger.error("JsonMappingException:Failed to upload package to catalouge:");
+ } catch(IOException e) {
+ logger.error("IOException:Failed to upload package to catalouge:");
+ }
+ return dataMap.get("csarId");
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestHook.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestHook.java
new file mode 100644
index 00000000..29710df3
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestHook.java
@@ -0,0 +1,193 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.openo.vnfsdk.marketplace.common.FileUtil;
+import org.openo.vnfsdk.marketplace.common.ToolUtil;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.entity.EnumOperationStatus;
+import org.openo.vnfsdk.marketplace.entity.EnumResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingOperResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
+import org.openo.vnfsdk.marketplace.onboarding.entity.ResultKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LifecycleTestHook
+{
+ private static final Logger logger = LoggerFactory.getLogger(LifecycleTestHook.class);
+
+ /**
+ * Start Executing Function test
+ * @param onBoradingReq
+ * @return
+ */
+ public int exec(OnBoradingRequest onBoradingReq)
+ {
+ logger.info("OnboradingRequest Lifecycle Request received for Package:" + onBoradingReq.getCsarId() + " Path:"+ onBoradingReq.getPackagePath());
+
+ buildResultPath(onBoradingReq);
+
+ OnBoardingResult olifecycleTestResult = new OnBoardingResult();
+ buildlifecycleTestResponse(onBoradingReq,olifecycleTestResult);
+ updateResult(olifecycleTestResult);
+
+ if(null == onBoradingReq.getCsarIdCatalouge() || onBoradingReq.getCsarIdCatalouge().isEmpty())
+ {
+ olifecycleTestResult.setOperFinished(true);
+ olifecycleTestResult.setOperStatus(EnumResult.FAIL.getIndex());
+ buildFuncTestResponse(olifecycleTestResult,CommonConstant.LifeCycleTest.LIFECYCLE_TEST_EXEC,EnumOperationStatus.FAILED.getIndex());
+ updateResult(olifecycleTestResult);
+ return EnumResult.FAIL.getIndex();
+ }
+
+ LifeCycleTestReq oLifeCycleTestReq = new LifeCycleTestReq();
+ populateLifeCycleReq(onBoradingReq,oLifeCycleTestReq);
+
+
+ //STEP 2: Execute Life Cycle Test and Get Result Back !!!!
+ //---------------------------------------------------------
+ String lifecycleTestResultKey = LifecycleTestExceutor.execlifecycleTest(onBoradingReq,oLifeCycleTestReq);
+ if(null == lifecycleTestResultKey)
+ {
+ olifecycleTestResult.setOperFinished(true);
+ olifecycleTestResult.setOperStatus(EnumResult.FAIL.getIndex());
+ buildFuncTestResponse(olifecycleTestResult,CommonConstant.LifeCycleTest.LIFECYCLE_TEST_EXEC,EnumOperationStatus.FAILED.getIndex());
+ updateResult(olifecycleTestResult);
+ return EnumResult.FAIL.getIndex();
+ }
+
+ olifecycleTestResult.setOperFinished(true);
+ olifecycleTestResult.setOperStatus(EnumResult.SUCCESS.getIndex());
+ buildFuncTestResponse(olifecycleTestResult,CommonConstant.LifeCycleTest.LIFECYCLE_TEST_EXEC,EnumOperationStatus.SUCCESS.getIndex());
+ updateResult(olifecycleTestResult);
+
+ //STEP 3: Store FuncTest key to get FuncTest Results
+ //-------------------------------------------------
+ storelifecycleResultKey(onBoradingReq,lifecycleTestResultKey);
+
+ return (olifecycleTestResult.getOperStatus() == EnumResult.SUCCESS.getIndex())
+ ? EnumResult.SUCCESS.getIndex() : EnumResult.FAIL.getIndex();
+ }
+
+ private void populateLifeCycleReq(OnBoradingRequest onBoradingReq, LifeCycleTestReq oLifeCycleTestReq)
+ {
+ oLifeCycleTestReq.setCsarId(onBoradingReq.getCsarId());
+ oLifeCycleTestReq.setLabVimId(oLifeCycleTestReq.getLabVimId());
+
+ List<String> vimIds = new ArrayList<String>();
+ oLifeCycleTestReq.setVimIds(vimIds);
+ }
+
+ /**
+ *
+ * @param onBoradingReq
+ */
+ private void buildResultPath(OnBoradingRequest onBoradingReq)
+ {
+ String filePath = getResultStorePath() + File.separator + onBoradingReq.getCsarId();
+ if(!FileUtil.checkFileExists(filePath))
+ {
+ FileUtil.createDirectory(filePath);
+ }
+ }
+
+ /**
+ * Store Function test Execution Results
+ * @param oFuncTestResult
+ */
+ private void updateResult(OnBoardingResult oFuncTestResult)
+ {
+ //STore Results to DB(Currently we will make JSON and Store JSON to Package Path)
+ //-------------------------------------------------------------------------------
+ logger.info("Lifecycle test Status for Package Id:" + oFuncTestResult.getCsarId() + ", Result:" + ToolUtil.objectToString(oFuncTestResult));
+ String filePath = getResultStorePath() + File.separator + oFuncTestResult.getCsarId() + File.separator + "lifecycleTest.json";
+ FileUtil.writeJsonDatatoFile(filePath,oFuncTestResult);
+ }
+
+ /**
+ * Build Function Test Response
+ * @param onBoradingReq
+ * @param oFuncTestResult
+ */
+ private void buildlifecycleTestResponse(OnBoradingRequest onBoradingReq, OnBoardingResult oTestResult)
+ {
+ oTestResult.setOperFinished(false);
+ oTestResult.setCsarId(onBoradingReq.getCsarId());
+ oTestResult.setOperTypeId(CommonConstant.LifeCycleTest.LIFECYCLE_TEST_OPERTYPE_ID);
+
+ OnBoardingOperResult lifecycleTestExec = new OnBoardingOperResult();
+ lifecycleTestExec.setOperId(CommonConstant.LifeCycleTest.LIFECYCLE_TEST_EXEC);
+ lifecycleTestExec.setStatus(EnumOperationStatus.NOTSTARTED.getIndex());
+
+ List<OnBoardingOperResult> operResult = new ArrayList<OnBoardingOperResult>();
+ operResult.add(lifecycleTestExec);
+ oTestResult.setOperResult(operResult);
+ }
+
+ public static OnBoardingResult getOnBoardingResult(PackageData packageData)
+ {
+ String filePath = getResultStorePath() + File.separator + packageData.getCsarId() +File.separator + "lifecycleTest.json";
+ logger.info("On Boarding Status for Package Id:" + packageData.getCsarId() + ", Result Path:" + filePath);
+
+ return (OnBoardingResult)FileUtil.readJsonDatafFromFile(filePath,OnBoardingResult.class);
+ }
+
+ /**
+ * Store Function Test Result key
+ * @param onBoradingReq
+ * @param resultKey
+ */
+ private void storelifecycleResultKey(OnBoradingRequest onBoradingReq,String resultKey)
+ {
+ //Currently we will make JSON and Store JSON to Package Path)
+ //-------------------------------------------------------------------------------
+ String filePath = getResultStorePath() + File.separator + onBoradingReq.getCsarId() + File.separator + "lifecycleTestResultKey.json";
+
+ logger.info("Function test Results Key for Package Id:" + onBoradingReq.getCsarId() + ", Key:" + resultKey + " Path" + filePath);
+
+ ResultKey oResultKey = new ResultKey();
+ oResultKey.setCsarId(onBoradingReq.getCsarId());
+ oResultKey.setOperTypeId(CommonConstant.LifeCycleTest.LIFECYCLE_TEST_OPERTYPE_ID);
+ oResultKey.setKey(resultKey);
+
+ FileUtil.writeJsonDatatoFile(filePath,oResultKey);
+ }
+
+ private static String getResultStorePath()
+ {
+ return org.openo.vnfsdk.marketplace.filemanage.http.ToolUtil.getHttpServerAbsolutePath();
+ }
+
+ private void buildFuncTestResponse(OnBoardingResult oFuncTestResult, String opreKey, int operStatusVal)
+ {
+ List<OnBoardingOperResult> operStatusList = oFuncTestResult.getOperResult();
+ for(OnBoardingOperResult operObj: operStatusList)
+ {
+ if(operObj.getOperId().equalsIgnoreCase(opreKey))
+ {
+ operObj.setStatus(operStatusVal);
+ break;
+ }
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/ValidateLifecycleTestResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/ValidateLifecycleTestResponse.java
new file mode 100644
index 00000000..4bec21bc
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/ValidateLifecycleTestResponse.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle;
+
+public class ValidateLifecycleTestResponse
+{
+ private String jobId;
+ private String validate_status;
+ private String lifecycle_status;
+ private VnfInfo vnf_info;
+ public String getJobId() {
+ return jobId;
+ }
+ public void setJobId(String jobId) {
+ this.jobId = jobId;
+ }
+ public String getValidate_status() {
+ return validate_status;
+ }
+ public void setValidate_status(String validate_status) {
+ this.validate_status = validate_status;
+ }
+ public String getLifecycle_status() {
+ return lifecycle_status;
+ }
+ public void setLifecycle_status(String lifecycle_status) {
+ this.lifecycle_status = lifecycle_status;
+ }
+ public VnfInfo getVnf_info() {
+ return vnf_info;
+ }
+ public void setVnf_info(VnfInfo vnf_info) {
+ this.vnf_info = vnf_info;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VmsInfo.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VmsInfo.java
new file mode 100644
index 00000000..f45a2ee4
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VmsInfo.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle;
+
+
+public class VmsInfo
+{
+ private String ip;
+ private String username;
+ private String password;
+ public String getIp() {
+ return ip;
+ }
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+ public String getUsername() {
+ return username;
+ }
+ public void setUsername(String username) {
+ this.username = username;
+ }
+ public String getPassword() {
+ return password;
+ }
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VnfInfo.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VnfInfo.java
new file mode 100644
index 00000000..1afd6256
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/VnfInfo.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle;
+
+import java.util.List;
+
+public class VnfInfo
+{
+ private List<VmsInfo> vms;
+
+ public List<VmsInfo> getVms() {
+ return vms;
+ }
+
+ public void setVms(List<VmsInfo> vms) {
+ this.vms = vms;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/onboardmanager/OnBoardingHandler.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/onboardmanager/OnBoardingHandler.java
new file mode 100644
index 00000000..7656932d
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/onboarding/onboardmanager/OnBoardingHandler.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.onboarding.onboardmanager;
+
+import org.openo.vnfsdk.marketplace.common.FileUtil;
+import org.openo.vnfsdk.marketplace.db.resource.PackageManager;
+import org.openo.vnfsdk.marketplace.entity.EnumResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
+import org.openo.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook;
+import org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.LifecycleTestHook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class OnBoardingHandler
+{
+ private static final Logger logger = LoggerFactory.getLogger(OnBoardingHandler.class);
+
+ public void handleOnBoardingReq(OnBoradingRequest onBoradingReq)
+ {
+ //Handle Package Life cycle/Validation
+ //------------------------------------
+ LifecycleTestHook oLifecycleTestHook = new LifecycleTestHook();
+ int iLifeCycleResponse = oLifecycleTestHook.exec(onBoradingReq);
+ if(EnumResult.SUCCESS.getIndex() != iLifeCycleResponse)
+ {
+ logger.error("Onboarding falied for Package Id during Lifecycle Test:" + onBoradingReq.getCsarId());
+ }
+
+ //Handle Package FunctionTest
+ //-------------------------
+ FunctionTestHook oFunctionTestHook = new FunctionTestHook();
+ int iFuncTestResponse = oFunctionTestHook.exec(onBoradingReq);
+ if(EnumResult.SUCCESS.getIndex() != iFuncTestResponse)
+ {
+ logger.error("Onboarding falied for Package Id during Function Test:" + onBoradingReq.getCsarId());
+ return;
+ }
+
+ FileUtil.deleteDirectory(onBoradingReq.getPackagePath());
+ try
+ {
+ PackageManager.getInstance().updateDwonloadCount(onBoradingReq.getCsarId());
+ }
+ catch (Exception e)
+ {
+ logger.error("Download count udate failed for Package:" + onBoradingReq.getPackagePath() ,e);
+ }
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/resource/PackageResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/resource/PackageResource.java
new file mode 100644
index 00000000..e043ea56
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/resource/PackageResource.java
@@ -0,0 +1,227 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.resource;
+
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+import org.openo.vnfsdk.marketplace.entity.response.CsarFileUriResponse;
+import org.openo.vnfsdk.marketplace.entity.response.PackageMeta;
+import org.openo.vnfsdk.marketplace.entity.response.UploadPackageResponse;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
+import org.openo.vnfsdk.marketplace.wrapper.PackageWrapper;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * csar package service.
+ *
+ * @author 10189609
+ *
+ */
+@Path("/PackageResource")
+@Api(tags = {"Package Resource"})
+public class PackageResource {
+
+ @Path("/updatestatus")
+ @POST
+ @ApiOperation(value = "update validate and lifecycle test status", response = UploadPackageResponse.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "update error",
+ response = String.class)})
+ public Response updateValidateStatus(
+ @ApiParam(value = "http request body") @Context HttpServletRequest request,
+ @ApiParam(value = "http header") @Context HttpHeaders head
+ ) throws Exception {
+ InputStream input = request.getInputStream();
+ return PackageWrapper.getInstance().updateValidateStatus(input, head);
+
+ }
+
+
+ @Path("/csars")
+ @GET
+ @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class,
+ responseContainer = "List")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
+ response = String.class)})
+ public Response queryPackageListByCond(
+ @ApiParam(value = "csar name") @QueryParam("name") String name, @ApiParam(
+ value = "csar provider") @QueryParam("provider") String provider, @ApiParam(
+ value = "csar version") @QueryParam("version") String version, @ApiParam(
+ value = "delay to delete") @QueryParam("deletionPending") String deletionPending,
+ @ApiParam(value = "csar type") @QueryParam("type") String type) {
+ return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version,
+ deletionPending, type);
+ }
+
+ @Path("/csars/{csarId}")
+ @GET
+ @ApiOperation(value = "get csar package list", response = PackageMeta.class,
+ responseContainer = "List")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
+ response = String.class)})
+ public Response queryPackageById(
+ @ApiParam(value = "csar id") @PathParam("csarId") String csarId) {
+ return PackageWrapper.getInstance().queryPackageById(csarId);
+ }
+ @Path("/csars")
+ @POST
+ @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class)
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
+ response = String.class)})
+ public Response uploadPackage(
+ @ApiParam(value = "file inputstream",
+ required = true) @FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("params") String details,
+ @ApiParam(value = "file detail",
+ required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
+ @ApiParam(value = "http header") @Context HttpHeaders head) throws Exception {
+ return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, details, head);
+ }
+
+ @Path("/csars/{csarId}")
+ @DELETE
+ @ApiOperation(value = "delete a package")
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
+ response = String.class)})
+ public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
+ return PackageWrapper.getInstance().delPackage(csarId);
+ }
+
+ @Path("/csars/{csarId}/files")
+ @GET
+ @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
+ response = String.class)})
+ public Response getCsarFileUri(
+ @ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId) {
+ return PackageWrapper.getInstance().getCsarFileUri(csarId);
+ }
+
+ @Path("/csars/{csarId}/downloaded")
+ @GET
+ @ApiOperation(value = "update download count for a package",response = Response.class)
+ public Response updateDwonloadCount(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
+ return PackageWrapper.getInstance().updateDwonloadCount(csarId);
+ }
+
+ @Path("/csars/{csarId}/reupload")
+ @POST
+ @ApiOperation(value = "re-upload csar package", response = UploadPackageResponse.class)
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
+ response = String.class)})
+ public Response reUploadPackage(
+ @ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
+ @ApiParam(value = "file inputstream",
+ required = true) @FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("params") String details,
+ @ApiParam(value = "file detail",
+ required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
+ @ApiParam(value = "http header") @Context HttpHeaders head) throws Exception {
+ return PackageWrapper.getInstance().reUploadPackage(csarId,uploadedInputStream, fileDetail, details, head);
+ }
+
+ @Path("/csars/{csarId}/onboardstatus")
+ @GET
+ @ApiOperation(value="Get VNF OnBoarding Result", response=OnBoardingResult.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getOnBoardingResult(@ApiParam("csar Id") @PathParam("csarId") String csarId,
+ @ApiParam("operation type") @QueryParam("operTypeId") String operTypeId,
+ @ApiParam("operation id") @QueryParam("operId") String operId)
+ {
+ return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
+ }
+
+ @Path("/csars/{csarId}/operresult")
+ @GET
+ @ApiOperation(value = "Get VNF OnBoarded Opeartion Result", response = Response.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getOperStatus(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
+ @ApiParam(value = "operation type") @QueryParam("operTypeId") String operTypeId) {
+ return PackageWrapper.getInstance().getOperResultByOperTypeId(csarId,operTypeId);
+ }
+
+ @Path("/csars/onboardsteps")
+ @GET
+ @ApiOperation(value="Get VNF OnBoarded Steps", response=Response.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getOnBoardingSteps()
+ {
+ return PackageWrapper.getInstance().getOnBoardingSteps();
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestConstant.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestConstant.java
new file mode 100644
index 00000000..4617a27d
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestConstant.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.rest;
+
+
+public class RestConstant {
+
+ public static final String UNAME_KEY = "UNAME_KEY";
+
+ public static final String PWD_KEY = "PWD_KEY";
+
+ public static final String NETCONF = "NETCONF";
+
+ public static final String ASYNC = "ASYNC";
+
+ public static final String SYNC = "SYNC";
+
+ public static final String HEADERMAP_TYPE = "HEADERMAP_TYPE";
+
+ public static final String HEADERMAP_VALUE = "HEADERMAP_VALUE";
+
+ public static final String AUTH_TOKEN = "AUTH_TOKEN";
+
+ public static final String DEFAULT_HOST_ADDRESS = "localhost";
+
+ public static final int DEFAULT_PORT = 8080;
+
+ public static final int DEFAULT_MAX_CONNECTION_PER_CONTROLLER = 10;
+
+ public static final int DEFAULT_STRING_LENGTH_64 = 64;
+
+ public static final int DEFAULT_STRING_LENGTH_128 = 128;
+
+ public static final int RESPONSE_CODE_200 = 200;
+
+ public static final int RESPONSE_CODE_201 = 201;
+
+ public static class HttpContext {
+
+ public static final String CONTENT_TYPE = "Content-Type";
+
+ public static final String MEDIA_TYPE_JSON = "application/json;charset=UTF-8";
+
+ public static final String URL = "url";
+
+ public static final String METHOD_TYPE = "methodType";
+
+ private HttpContext() {
+ }
+ }
+
+
+ public static class MethodType {
+
+ public static final String POST = "post";
+
+ public static final String DELETE = "delete";
+
+ public static final String PUT = "put";
+
+ public static final String GET = "get";
+
+ private MethodType() {
+ }
+ }
+
+ private RestConstant() {
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestResponse.java
new file mode 100644
index 00000000..8ed1553f
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestResponse.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.rest;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RestResponse {
+
+ public Integer getStatusCode() {
+ return statusCode;
+ }
+
+ public void setStatusCode(Integer statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ public String getResult() {
+ return result;
+ }
+
+ public void setResult(String result) {
+ this.result = result;
+ }
+
+ private Integer statusCode;
+
+ private String result;
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulClient.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulClient.java
new file mode 100644
index 00000000..78be4652
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulClient.java
@@ -0,0 +1,168 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.rest;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RestfulClient {
+ private static final String HTTP = "http";
+ private static final Logger logger = LoggerFactory.getLogger(RestfulClient.class);
+
+ enum HttpMethod {
+ GET, POST, PUT, DELETE
+ }
+
+ /**
+ * execute http.
+ * @param method http method
+ * @param ip ip
+ * @param port port
+ * @param url url
+ * @param body http body
+ * @return RestResponse
+ */
+ public static RestResponse executeHttp(HttpMethod method, String ip, int port, String url,
+ HttpEntity body) {
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpResponse httpResponse = null;
+ RestResponse result = new RestResponse();
+ try {
+ // specify the host, protocol, and port
+ HttpHost target = new HttpHost(ip, port, HTTP);
+ // specify the get request
+ HttpRequest request = getRequest(method, url, body);
+ httpResponse = httpclient.execute(target, request);
+ HttpEntity entity = httpResponse.getEntity();
+ if (entity != null) {
+ result.setStatusCode(httpResponse.getStatusLine().getStatusCode());
+ result.setResult(EntityUtils.toString(entity));
+ }
+ } catch (Exception e1) {
+ logger.error("send get rest request error:", e1.getMessage());
+ } finally {
+ if (httpclient != null) {
+ try {
+ httpclient.close();
+ } catch (IOException e2) {
+ logger.error("close httpclient error:", e2.getMessage());
+ }
+ }
+ }
+ return result;
+ }
+
+ private static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) {
+ HttpRequest request = null;
+ switch (method) {
+ case GET:
+ request = new HttpGet(url);
+ break;
+ case POST:
+ request = new HttpPost(url);
+ ((HttpPost) request).setEntity(body);
+ break;
+ case PUT:
+ request = new HttpPut(url);
+ ((HttpPut) request).setEntity(body);
+ break;
+ case DELETE:
+ request = new HttpDelete(url);
+ break;
+ default:
+ break;
+ }
+ return request;
+ }
+
+ public static RestResponse get(String ip, int port, String url) {
+ return executeHttp(HttpMethod.GET, ip, port, url, null);
+ }
+
+ public static RestResponse delete(String ip, int port, String url) {
+ return executeHttp(HttpMethod.DELETE, ip, port, url, null);
+ }
+
+ public static RestResponse post(String ip, int port, String url, HttpEntity requestBody) {
+ return executeHttp(HttpMethod.POST, ip, port, url, requestBody);
+ }
+
+ public static RestResponse sendPostRequest(String ip, String port, String url, String strJson)
+ {
+ RestResponse result = new RestResponse();
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+ HttpResponse httpResponse = null;
+ try
+ {
+ String urlPost = "http://" + ip + ":" + port + url;
+ logger.info("URL formed for Post, URL :" + urlPost);
+ logger.info("URL formed for Post, JSON :" + strJson);
+
+ HttpPost request = new HttpPost(urlPost);
+
+ StringEntity params = new StringEntity(strJson);
+ request.addHeader("content-type", "application/json");
+ request.setEntity(params);
+
+ httpResponse = httpClient.execute(request);
+ HttpEntity entity = httpResponse.getEntity();
+ if (entity != null)
+ {
+ result.setStatusCode(httpResponse.getStatusLine().getStatusCode());
+ result.setResult(EntityUtils.toString(entity));
+ }
+ }
+ catch (Exception ex)
+ {
+ logger.error("Send Post request error:", ex.getMessage());
+ }
+ finally
+ {
+ try {
+ if(null != httpClient) {
+ httpClient.close();
+ }
+ }
+ catch(IOException e){
+ logger.error("IOException :Send Post request error:", e.getMessage());
+ }
+ }
+ return result;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulUtil.java
new file mode 100644
index 00000000..03912646
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/rest/RestfulUtil.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.vnfsdk.marketplace.rest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.roa.util.restclient.Restful;
+import org.openo.baseservice.roa.util.restclient.RestfulFactory;
+import org.openo.baseservice.roa.util.restclient.RestfulParametes;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RestfulUtil {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RestfulUtil.class);
+
+ private RestfulUtil() {
+ }
+
+ /**
+ * Interface for Sending Request via REST
+ * @param paramsMap
+ * @param params
+ * @param queryParam
+ * @return
+ */
+ public static RestfulResponse sendRestRequest(Map<String, String> paramsMap, String params,Map<String, String> queryParam)
+ {
+ if(null == paramsMap)
+ {
+ LOGGER.error("sendRestResponse : Input validation failed !");
+ return null;
+ }
+
+ String url = paramsMap.get(RestConstant.HttpContext.URL);
+ String methodType = paramsMap.get(RestConstant.HttpContext.METHOD_TYPE);
+
+ RestfulResponse rsp = null;
+ Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP);
+
+ try
+ {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ Map<String, String> headerMap = new HashMap<String, String>(3);
+ headerMap.put(RestConstant.HttpContext.CONTENT_TYPE, RestConstant.HttpContext.MEDIA_TYPE_JSON);
+ restfulParametes.setHeaderMap(headerMap);
+
+ if(null != params)
+ {
+ restfulParametes.setRawData(params);
+ }
+
+ if(null != queryParam)
+ {
+ for(Map.Entry<String, String> curEntity : queryParam.entrySet())
+ {
+ restfulParametes.putHttpContextHeader(curEntity.getKey(), curEntity.getValue());
+ }
+ }
+ if(rest != null)
+ {
+ if(RestConstant.MethodType.GET.equalsIgnoreCase(methodType))
+ {
+ rsp = rest.get(url, restfulParametes, null);
+ }
+ else if(RestConstant.MethodType.POST.equalsIgnoreCase(methodType))
+ {
+ rsp = rest.post(url, restfulParametes, null);
+ }
+ else if(RestConstant.MethodType.PUT.equalsIgnoreCase(methodType))
+ {
+ rsp = rest.put(url, restfulParametes, null);
+ }
+ else if(RestConstant.MethodType.DELETE.equalsIgnoreCase(methodType))
+ {
+ rsp = rest.delete(url, restfulParametes, null);
+ }
+ }
+ }
+ catch(ServiceException e)
+ {
+ LOGGER.error("sendRestResponse, get restful response catch exception {}", e);
+ }
+ return rsp;
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapper.java
new file mode 100644
index 00000000..f42ac636
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapper.java
@@ -0,0 +1,596 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.wrapper;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import net.sf.json.JSONObject;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.openo.vnfsdk.marketplace.common.FileUtil;
+import org.openo.vnfsdk.marketplace.common.JsonUtil;
+import org.openo.vnfsdk.marketplace.common.RestUtil;
+import org.openo.vnfsdk.marketplace.common.ToolUtil;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
+import org.openo.vnfsdk.marketplace.db.resource.PackageManager;
+import org.openo.vnfsdk.marketplace.db.util.MarketplaceDbUtil;
+import org.openo.vnfsdk.marketplace.entity.request.PackageBasicInfo;
+import org.openo.vnfsdk.marketplace.entity.response.PackageMeta;
+import org.openo.vnfsdk.marketplace.entity.response.UploadPackageResponse;
+import org.openo.vnfsdk.marketplace.filemanage.FileManagerFactory;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingOperResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoardingSteps;
+import org.openo.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
+import org.openo.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestExceutor;
+import org.openo.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook;
+import org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.LifecycleTestExceutor;
+import org.openo.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.ValidateLifecycleTestResponse;
+import org.openo.vnfsdk.marketplace.onboarding.onboardmanager.OnBoardingHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PackageWrapper {
+ private static PackageWrapper packageWrapper;
+ private static final Logger LOG = LoggerFactory.getLogger(PackageWrapper.class);
+
+ /**
+ * get PackageWrapper instance.
+ * @return package wrapper instance
+ */
+ public static PackageWrapper getInstance() {
+ if (packageWrapper == null) {
+ packageWrapper = new PackageWrapper();
+ }
+ return packageWrapper;
+ }
+
+ public Response updateValidateStatus(InputStream inputStream, HttpHeaders head) throws Exception
+ {
+ String reqParam = IOUtils.toString(inputStream);
+ LOG.info("updateValidateStatus request param:"+reqParam);
+ if(StringUtils.isBlank(reqParam)) {
+ LOG.error("The updateValidateStatus request params can't be null");
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
+
+ ValidateLifecycleTestResponse lyfValidateResp = JsonUtil.fromJson(reqParam, ValidateLifecycleTestResponse.class);
+ if(!checkOperationSucess(lyfValidateResp))
+ {
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
+
+ String funcTestResponse = FunctionTestExceutor.executeFunctionTest(reqParam);
+ if(null == funcTestResponse)
+ {
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
+
+ JSONObject funcTestRspObject = JSONObject.fromObject(funcTestResponse);
+ if(!funcTestRspObject.get("status").equals(CommonConstant.SUCCESS_STR))
+ {
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
+
+ JSONObject result = new JSONObject();
+ result.put("msg","SUCCESS");
+ return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();
+ }
+
+ private boolean checkOperationSucess(ValidateLifecycleTestResponse lyfValidateResp)
+ {
+ boolean bOperStatus = false;
+ if(null == lyfValidateResp)
+ {
+ LOG.error("ValidateLifecycleTestResponse is NUll !!!");
+ return bOperStatus;
+ }
+ if(lyfValidateResp.getLifecycle_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR)
+ && lyfValidateResp.getValidate_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR))
+ {
+ LOG.error("Lifecycle/Validation Response failed :" + lyfValidateResp.getLifecycle_status() + File.separator + lyfValidateResp.getValidate_status());
+ bOperStatus = true;
+ }
+ return bOperStatus;
+ }
+
+ /**
+ * query package list by condition.
+ * @param name package name
+ * @param provider package provider
+ * @param version package version
+ * @param deletionPending package deletionPending
+ * @param type package type
+ * @return Response
+ */
+ public Response queryPackageListByCond(String name, String provider, String version,
+ String deletionPending, String type) {
+ ArrayList<PackageData> dbresult = new ArrayList<PackageData>();
+ ArrayList<PackageMeta> result = new ArrayList<PackageMeta>();
+ LOG.info("query package info.name:" + name + " provider:" + provider + " version" + version
+ + " deletionPending" + deletionPending + " type:" + type);
+ try {
+ dbresult =
+ PackageManager.getInstance().queryPackage(name, provider, version, deletionPending, type);
+ result = PackageWrapperUtil.packageDataList2PackageMetaList(dbresult);
+ return Response.ok(ToolUtil.objectToString(result)).build();
+ } catch (MarketplaceResourceException e1) {
+ LOG.error("query package by csarId from db error ! " + e1.getMessage());
+ return RestUtil.getRestException(e1.getMessage());
+ }
+ }
+
+ /**
+ * query package by id.
+ * @param csarId package id
+ * @return Response
+ */
+ public Response queryPackageById(String csarId) {
+ PackageData dbResult = new PackageData();
+ PackageMeta result = new PackageMeta();
+ dbResult = PackageWrapperUtil.getPackageInfoById(csarId);
+ result = PackageWrapperUtil.packageData2PackageMeta(dbResult);
+ return Response.ok(ToolUtil.objectToString(result)).build();
+ }
+
+ /**
+ * upload package.
+ * @param uploadedInputStream inputStream
+ * @param fileDetail package detail
+ * @param head http header
+ * @return Response
+ * @throws Exception e
+ */
+ public Response uploadPackage(InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail, String details, HttpHeaders head) throws Exception
+ {
+ LOG.info("Upload/Reupload request Received !!!!");
+
+ String packageId = MarketplaceDbUtil.generateId();
+ return handlePackageUpload(packageId,uploadedInputStream, fileDetail, details, head);
+ }
+
+ /**
+ * Interface for Uploading package
+ * @param packageId
+ * @param uploadedInputStream
+ * @param fileDetail
+ * @param details
+ * @param head
+ * @return
+ * @throws IOException
+ * @throws MarketplaceResourceException
+ */
+ private Response handlePackageUpload(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail,
+ String details, HttpHeaders head) throws IOException, MarketplaceResourceException
+ {
+ boolean bResult = handleDataValidate(packageId,uploadedInputStream,fileDetail);
+ if(!bResult)
+ {
+ LOG.error("Validation of Input received for Package Upload failed !!!");
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
+
+ LOG.info("the fileDetail = " + ToolUtil.objectToString(fileDetail));
+
+ String fileName = ToolUtil.processFileName(fileDetail.getFileName());
+ String localDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);
+
+ String contentRange = null;
+ if (head != null)
+ {
+ contentRange = head.getHeaderString(CommonConstant.HTTP_HEADER_CONTENT_RANGE);
+ }
+ LOG.info("store package chunk file, fileName:" + fileName + ",contentRange:" + contentRange);
+ if (ToolUtil.isEmptyString(contentRange))
+ {
+ int fileSize = uploadedInputStream.available();
+ contentRange = "0-" + fileSize + "/" + fileSize;
+ }
+
+ String fileLocation = ToolUtil.storeChunkFileInLocal(localDirName, fileName, uploadedInputStream);
+ LOG.info("the fileLocation when upload package is :" + fileLocation);
+
+ uploadedInputStream.close();
+
+ PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
+ if (null == basicInfo.getType() || null == basicInfo.getProvider() || null == basicInfo.getVersion())
+ {
+ LOG.error("Package basicInfo is incorrect ! basicIonfo = " + ToolUtil.objectToString(basicInfo));
+ return Response.serverError().build();
+ }
+
+ UploadPackageResponse result = new UploadPackageResponse();
+ Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange, fileName);
+ if (isEnd)
+ {
+ PackageMeta packageMeta = PackageWrapperUtil.getPackageMeta(packageId,fileName, fileLocation, basicInfo, details);
+
+ String path = basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator + packageMeta.getCsarId() + File.separator + fileName.replace(".csar", "") + File.separator + basicInfo.getVersion();
+ String dowloadUri = File.separator + path + File.separator;
+ packageMeta.setDownloadUri(dowloadUri);
+
+ LOG.info("dest path is : " + path);
+ LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
+
+ PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
+
+ String destPath = File.separator + path + File.separator + File.separator;
+ boolean uploadResult = FileManagerFactory.createFileManager().upload(localDirName, destPath);
+ if (uploadResult)
+ {
+ //Create OnBoarding Request
+ //--------------------------
+ OnBoradingRequest oOnboradingRequest = new OnBoradingRequest();
+ oOnboradingRequest.setCsarId(packageId);
+ oOnboradingRequest.setPackageName(fileName);
+ oOnboradingRequest.setPackagePath(localDirName);
+
+ //Upload the Package to CATALOUGE and get CSARID
+ //---------------------------------------------
+ String catalougeCsarId = LifecycleTestExceutor.uploadPackageToCatalouge(oOnboradingRequest);
+ if((null == catalougeCsarId) || catalougeCsarId.isEmpty())
+ {
+ LOG.error("Failed to Upload Package to catalougeCsarId " + ToolUtil.objectToString(basicInfo));
+ return Response.status(Status.INTERNAL_SERVER_ERROR).build();
+ }
+ oOnboradingRequest.setCsarIdCatalouge(catalougeCsarId);
+ LOG.info("catalougeCsarId :" + catalougeCsarId);
+
+
+ //Update Default download count to -1
+ packageData.setCsarId(packageId);
+ packageData.setDownloadCount(-1);
+ PackageData packateDbData = PackageManager.getInstance().addPackage(packageData);
+
+ LOG.info("Store package data to database succed ! packateDbData = " + ToolUtil.objectToString(packateDbData));
+ LOG.info("upload package file end, fileName:" + fileName);
+
+ result.setCsarId(packateDbData.getCsarId());
+
+ //Assign OnBoarding Request to OnBoarding Handler
+ //------------------------------------------------
+ addOnBoardingRequest(oOnboradingRequest);
+
+ LOG.info("OnboradingRequest Data : " + ToolUtil.objectToString(oOnboradingRequest));
+ }
+ }
+ return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();
+ }
+
+ /**
+ * Execute OnBarding request
+ * @param oOnboradingRequest
+ */
+ private void addOnBoardingRequest(final OnBoradingRequest oOnboradingRequest)
+ {
+ ExecutorService es = Executors.newFixedThreadPool(CommonConstant.ONBOARDING_THREAD_COUNT);
+ es.submit(new Callable<Integer>()
+ {
+ public Integer call() throws Exception
+ {
+ new OnBoardingHandler().handleOnBoardingReq(oOnboradingRequest);
+ return CommonConstant.SUCESS;
+ }
+ });
+ }
+
+ /**
+ * delete package by package id.
+ * @param csarId package id
+ * @return Response
+ */
+ public Response delPackage(String csarId) {
+ LOG.info("delete package info.csarId:" + csarId);
+ if (ToolUtil.isEmptyString(csarId)) {
+ LOG.error("delete package fail, csarid is null");
+ return Response.serverError().build();
+ }
+ deletePackageDataById(csarId);
+ return Response.ok().build();
+ }
+
+ /**
+ * Delete Package by CSAR ID
+ * @param csarId
+ */
+ private void deletePackageDataById(String csarId) {
+ String packagePath = PackageWrapperUtil.getPackagePath(csarId);
+ if (packagePath == null) {
+ LOG.error("package path is null! ");
+ }
+
+ //Delete Package
+ FileManagerFactory.createFileManager().delete(packagePath);
+ //Delete Results Data
+ FileManagerFactory.createFileManager().delete(File.separator + csarId);
+
+
+ //delete package data from database
+ try {
+ PackageManager.getInstance().deletePackage(csarId);
+ } catch (MarketplaceResourceException e1) {
+ LOG.error("delete package by csarId from db error ! " + e1.getMessage(), e1);
+ }
+ }
+
+ /**
+ * download package by package id.
+ * @param csarId package id
+ * @return Response
+ */
+ public Response downloadCsarPackagesById(String csarId) {
+ PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
+
+ String packageName = packageData.getName();
+ String path = org.openo.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 + ".csar";
+
+ LOG.info("downloadCsarPackagesById path is : " + path);
+
+ File csarFile = new File(path);
+ if (!csarFile.exists()) {
+ return Response.status(Status.INTERNAL_SERVER_ERROR).build();
+ }
+
+ LOG.info("downloadCsarPackagesById ABS path is : " + csarFile.getAbsolutePath());
+
+ try
+ {
+ InputStream fis = new BufferedInputStream(new FileInputStream(csarFile.getAbsolutePath()));
+ return Response.ok(fis)
+ .header("Content-Disposition", "attachment; filename=\"" + csarFile.getName() + "\"")
+ .build();
+ }
+ catch (Exception e1)
+ {
+ LOG.error("download vnf package fail.", e1);
+ return RestUtil.getRestException(e1.getMessage());
+ }
+ }
+
+ /**
+ * get package file uri.
+ * @param csarId package id
+ * @param relativePath file relative path
+ * @return Response
+ */
+ public Response getCsarFileUri(String csarId) {
+ return downloadCsarPackagesById(csarId);
+ }
+
+ /**
+ * Interface to Update Download count for CSAR ID
+ * @param csarId
+ * @return
+ */
+ public Response updateDwonloadCount(String csarId) {
+ return handleDownladCountUpdate(csarId) ?
+ Response.ok().build() :
+ Response.status(Status.EXPECTATION_FAILED).build();
+ }
+
+ /**
+ * Handle downlowa count update
+ * @param csarId
+ * @return
+ */
+ private boolean handleDownladCountUpdate(String csarId) {
+ boolean bupdateSucess = false;
+ try
+ {
+ PackageManager.getInstance().updateDwonloadCount(csarId);
+ bupdateSucess = true;
+ }
+ catch (Exception exp)
+ {
+ LOG.error("Updating Donwload count failed for Package with ID !!! : " + exp.getMessage(), exp);
+ }
+ return bupdateSucess;
+ }
+
+ /**
+ * Interface to Re upload Package
+ * @param csarId
+ * @param uploadedInputStream
+ * @param fileDetail
+ * @param details
+ * @param head
+ * @return
+ * @throws Exception
+ */
+ public Response reUploadPackage(String csarId,
+ InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail,
+ String details,
+ HttpHeaders head) throws Exception
+ {
+ LOG.info("Reupload request Received !!!!");
+
+ //STEP 1: Validate Input Data
+ //----------------------------
+ boolean bResult = handleDataValidate(csarId,uploadedInputStream,fileDetail);
+ if(!bResult)
+ {
+ LOG.error("Validation of Input received for Package Upload failed during Reload!!!");
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
+
+ //STEP 2: Delete All Package Data based on package id
+ //----------------------------------------------------
+ deletePackageDataById(csarId);
+
+ //STEP 3: upload package with same package id
+ //-------------------------------------------
+ return handlePackageUpload(csarId,uploadedInputStream, fileDetail, details, head);
+ }
+
+ /**
+ * Interface to get OnBoarding Result by Operation Type
+ * @param csarId
+ * @param operTypeId
+ * @param operId
+ * @return
+ */
+ public Response getOnBoardingResult(String csarId, String operTypeId, String operId)
+ {
+ LOG.info("getOnBoardingResult request : csarId:" + csarId + " operTypeId:" + operTypeId + " operId:" + operId);
+ if ((null == csarId) || (null == operTypeId) || (null == operId)) {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ if ((csarId.isEmpty()) || (operTypeId.isEmpty()) || (operId.isEmpty())) {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
+ if (null == packageData) {
+ return Response.status(Response.Status.PRECONDITION_FAILED).build();
+ }
+
+ handleDelayExec(operId);
+
+ OnBoardingResult oOnBoardingResult = FunctionTestHook.getOnBoardingResult(packageData);
+ if (null == oOnBoardingResult) {
+ return Response.status(Response.Status.PRECONDITION_FAILED).build();
+ }
+ filterOnBoardingResultByOperId(oOnBoardingResult, operId);
+
+ String strResult = ToolUtil.objectToString(oOnBoardingResult);
+ LOG.info("getOnBoardingResult response : " + strResult);
+ return Response.ok(strResult, "application/json").build();
+ }
+
+
+ private void filterOnBoardingResultByOperId(OnBoardingResult oOnBoardingResult, String operId)
+ {
+ if (0 == operId.compareToIgnoreCase("all")) {
+ return;
+ }
+ if (0 == operId.compareToIgnoreCase("download"))
+ {
+ List<OnBoardingOperResult> operResultListTemp = new ArrayList<OnBoardingOperResult>();
+ OnBoardingOperResult operResultListTmp = new OnBoardingOperResult();
+ operResultListTmp.setOperId("download");
+ operResultListTmp.setStatus(0);
+ operResultListTemp.add(operResultListTmp);
+ oOnBoardingResult.setOperResult(operResultListTemp);
+ return;
+ }
+ List<OnBoardingOperResult> operResultListOut = new ArrayList<OnBoardingOperResult>();
+ List<OnBoardingOperResult> operResultList = oOnBoardingResult.getOperResult();
+ for (OnBoardingOperResult operResult : operResultList) {
+ if (0 == operResult.getOperId().compareToIgnoreCase(operId)) {
+ operResultListOut.add(operResult);
+ }
+ }
+ oOnBoardingResult.setOperResult(operResultListOut);
+ }
+
+ /**
+ * Interface to get OnBoarding Status by Operation ID
+ * @param csarId
+ * @param operTypeId
+ * @return
+ */
+ public Response getOperResultByOperTypeId(String csarId, String operTypeId)
+ {
+ LOG.error("getOnBoardingResult request : csarId:"+ csarId + " operTypeId:"+operTypeId);
+ if(null == csarId || null == operTypeId || csarId.isEmpty() || operTypeId.isEmpty())
+ {
+ return Response.status(Status.BAD_REQUEST).build();
+ }
+
+ PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
+ if(null == packageData)
+ {
+ LOG.error("Failed to find package for PackageID:"+ csarId);
+ return Response.status(Status.PRECONDITION_FAILED).build();
+ }
+
+ //Get result key to fetch Function Test Results
+ //---------------------------------------------
+ String strResult = FunctionTestHook.getFuncTestResults(packageData);
+ if(null == strResult)
+ {
+ LOG.error("NULL reponse for getOperResultByOperTypeId response :"+ strResult);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).build();
+ }
+ LOG.info("getOperResultByOperTypeId response :"+ strResult);
+ return Response.ok(strResult, MediaType.APPLICATION_JSON).build();
+ }
+
+ private boolean handleDataValidate(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail)
+ {
+ boolean bvalidateOk = false;
+ if ((null != uploadedInputStream) && (fileDetail != null) && !ToolUtil.isEmptyString(packageId))
+ {
+ bvalidateOk = true;
+ }
+ return bvalidateOk;
+ }
+
+ /**
+ * Interface to get OnBoarding Steps
+ * @return
+ */
+ public Response getOnBoardingSteps()
+ {
+ LOG.info("Get OnBoarding Steps request Received !!!");
+
+ String filePath = org.openo.vnfsdk.marketplace.filemanage.http.ToolUtil.getAppDeployPath() + File.separator +"generalconfig/OnBoardingSteps.json";
+ LOG.info("Onboarding Steps Json file Path :" + filePath);
+
+ OnBoardingSteps oOnBoardingSteps = (OnBoardingSteps)FileUtil.readJsonDatafFromFile(filePath, OnBoardingSteps.class);
+ if (null == oOnBoardingSteps) {
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
+ String strResult = ToolUtil.objectToString(oOnBoardingSteps);
+ LOG.info("getOnBoardingSteps response :" + strResult);
+ return Response.ok(strResult, MediaType.APPLICATION_JSON).build();
+ }
+
+ private void handleDelayExec(String operId)
+ {
+ if (0 == operId.compareToIgnoreCase(CommonConstant.functionTest.FUNCTEST_EXEC))
+ {
+ try
+ {
+ Thread.sleep(8000);
+ }
+ catch (InterruptedException e)
+ {
+ LOG.info("handleDelayExex response : " + e.getMessage());
+ }
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java
new file mode 100644
index 00000000..02cf567d
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/openo/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java
@@ -0,0 +1,356 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.vnfsdk.marketplace.wrapper;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+
+import org.openo.vnfsdk.marketplace.common.CommonConstant;
+import org.openo.vnfsdk.marketplace.common.FileUtil;
+import org.openo.vnfsdk.marketplace.common.MsbAddrConfig;
+import org.openo.vnfsdk.marketplace.common.ToolUtil;
+import org.openo.vnfsdk.marketplace.db.entity.PackageData;
+import org.openo.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
+import org.openo.vnfsdk.marketplace.db.resource.PackageManager;
+import org.openo.vnfsdk.marketplace.entity.EnumType;
+import org.openo.vnfsdk.marketplace.entity.request.PackageBasicInfo;
+import org.openo.vnfsdk.marketplace.entity.response.PackageMeta;
+import org.openo.vnfsdk.marketplace.model.parser.EnumPackageFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.internal.LinkedTreeMap;
+
+
+public class PackageWrapperUtil {
+ private static final Logger LOG = LoggerFactory.getLogger(PackageWrapperUtil.class);
+
+ public static long getPacakgeSize(String fileLocation) {
+ File file = new File(fileLocation);
+ return file.length();
+ }
+
+ /**
+ * change package metadata to fix database.
+ * @param meta package metadata
+ * @param details
+ * @return package data in database
+ */
+ public static PackageData getPackageData(PackageMeta meta) {
+ PackageData packageData = new PackageData();
+ packageData.setCreateTime(meta.getCreateTime());
+ packageData.setDeletionPending(String.valueOf(meta.isDeletionPending()));
+ packageData.setDownloadUri(meta.getDownloadUri());
+ packageData.setFormat(meta.getFormat());
+ packageData.setModifyTime(meta.getModifyTime());
+ packageData.setName(meta.getName());
+ packageData.setCsarId(meta.getCsarId());
+ packageData.setProvider(meta.getProvider());
+ String fileSize = meta.getSize();
+ packageData.setSize(fileSize);
+ packageData.setType(meta.getType());
+ packageData.setVersion(meta.getVersion());
+ packageData.setDetails(meta.getDetails());
+ packageData.setShortDesc(meta.getShortDesc());
+ packageData.setRemarks(meta.getRemarks());
+ return packageData;
+ }
+
+ /**
+ * judge wether is the end of upload package.
+ * @param contentRange package sise range
+ * @param csarName package name
+ * @return boolean
+ */
+ public static boolean isUploadEnd(String contentRange, String csarName) {
+ String range = contentRange;
+ range = range.replace("bytes", "").trim();
+ range = range.substring(0, range.indexOf("/"));
+ String size =
+ contentRange.substring(contentRange.indexOf("/") + 1, contentRange.length()).trim();
+ int fileSize = Integer.parseInt(size);
+ String[] ranges = range.split("-");
+ int startPosition = Integer.parseInt(ranges[0]);
+ if (startPosition == 0) {
+ // delPackageBySync(csarName);
+ }
+ // index start from 0
+ int endPosition = Integer.parseInt(ranges[1]) + 1;
+ if (endPosition >= fileSize) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * get package detail by package id.
+ * @param csarId package id
+ * @return package detail
+ */
+ public static PackageData getPackageInfoById(String csarId) {
+ PackageData result = new PackageData();
+ ArrayList<PackageData> packageDataList = new ArrayList<PackageData>();
+ try {
+ packageDataList = PackageManager.getInstance().queryPackageByCsarId(csarId);
+ if (packageDataList != null && packageDataList.size() > 0) {
+ result = PackageManager.getInstance().queryPackageByCsarId(csarId).get(0);
+ }
+ } catch (MarketplaceResourceException e1) {
+ LOG.error("query package by csarId from db error ! " + e1.getMessage());
+ }
+ return result;
+ }
+
+ /**
+ * get package metadata from basic info.
+ * @param fileName package name
+ * @param fileLocation the location of package
+ * @param basic basic infomation of package. include version, type and provider
+ * @return package metadata
+ */
+ public static PackageMeta getPackageMeta(String packageId,String fileName, String fileLocation,
+ PackageBasicInfo basic, String details) {
+ PackageMeta packageMeta = new PackageMeta();
+ long size = getPacakgeSize(fileLocation);
+ packageMeta.setFormat(basic.getFormat());
+
+ if(null == packageId)
+ {
+ packageId = ToolUtil.generateId();
+ }
+ packageMeta.setCsarId(packageId);
+
+ packageMeta.setName(fileName.replace(CommonConstant.CSAR_SUFFIX, ""));
+ packageMeta.setType(basic.getType().toString());
+ packageMeta.setVersion(basic.getVersion());
+ packageMeta.setProvider(basic.getProvider());
+ packageMeta.setDeletionPending(false);
+ String sizeStr = ToolUtil.getFormatFileSize(size);
+ packageMeta.setSize(sizeStr);
+ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String currentTime = sdf1.format(new Date());
+ packageMeta.setCreateTime(currentTime);
+ packageMeta.setModifyTime(currentTime);
+ if(null != details)
+ {
+ LinkedTreeMap<String,String> csarDetails = ToolUtil.fromJson(details, LinkedTreeMap.class);
+ packageMeta.setDetails(csarDetails.get("details"));
+ packageMeta.setShortDesc(csarDetails.get("shortDesc"));
+ packageMeta.setRemarks(csarDetails.get("remarks"));
+ }
+ return packageMeta;
+ }
+
+ /**
+ * get downloadUri from package metadata.
+ * @param csarId package id
+ * @return download uri
+ */
+ public static String getPackagePath(String csarId) {
+ ArrayList<PackageData> packageList = new ArrayList<PackageData>();
+ String downloadUri = null;
+ try {
+ packageList = PackageManager.getInstance().queryPackageByCsarId(csarId);
+ downloadUri = packageList.get(0).getDownloadUri();
+ } catch (MarketplaceResourceException e1) {
+ LOG.error("Query CSAR package by ID failed ! csarId = " + csarId);
+ }
+ return downloadUri;
+ }
+
+
+ /**
+ * get package name from ftpUrl.
+ * @param ftpUrl ftp url
+ * @return package name
+ */
+ public static String getPackageName(String ftpUrl) {
+ int index = ftpUrl.lastIndexOf("/");
+ String packageName = ftpUrl.substring(index);
+ return packageName;
+ }
+
+ /**
+ * translate package data from database to package metadata.
+ * @param dbResult data from database
+ * @return package metadata list
+ */
+ public static ArrayList<PackageMeta> packageDataList2PackageMetaList(
+ ArrayList<PackageData> dbResult) {
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ PackageMeta meta = new PackageMeta();
+ if (dbResult.size() > 0) {
+ for (int i = 0; i < dbResult.size(); i++) {
+ PackageData data = dbResult.get(i);
+ meta = packageData2PackageMeta(data);
+ metas.add(meta);
+ }
+ }
+ return metas;
+ }
+
+ public static PackageMeta packageData2PackageMeta(PackageData packageData) {
+ PackageMeta meta = new PackageMeta();
+ meta.setCsarId(packageData.getCsarId());
+ meta.setCreateTime(packageData.getCreateTime());
+ meta.setDeletionPending(Boolean.getBoolean(packageData.getDeletionPending()));
+ String packageUri =
+ packageData.getDownloadUri() + packageData.getName() + CommonConstant.CSAR_SUFFIX;
+ String packageUrl = getUrl(packageUri);
+ meta.setDownloadUri(packageUrl);
+ meta.setReport(packageData.getReport());
+ meta.setFormat(packageData.getFormat());
+ meta.setModifyTime(packageData.getModifyTime());
+ meta.setName(packageData.getName());
+ meta.setDetails(packageData.getDetails());
+ meta.setProvider(packageData.getProvider());
+ meta.setSize(packageData.getSize());
+ meta.setType(packageData.getType());
+ meta.setShortDesc(packageData.getShortDesc());
+ meta.setVersion(packageData.getVersion());
+ meta.setRemarks(packageData.getRemarks());
+ meta.setDownloadCount(packageData.getDownloadCount());
+ return meta;
+ }
+
+ /**
+ * add msb address as prefix to uri.
+ * @param uri uri
+ * @return url
+ */
+ public static String getUrl(String uri) {
+ String url = null;
+// if ((MsbAddrConfig.getMsbAddress().endsWith("/")) && uri.startsWith("/")) {
+// url = MsbAddrConfig.getMsbAddress() + uri.substring(1);
+// }
+// url = MsbAddrConfig.getMsbAddress() + uri;
+ if ((getDownloadUriHead().endsWith("/")) && uri.startsWith("/")) {
+ url = getDownloadUriHead() + uri.substring(1);
+ }
+ url = getDownloadUriHead() + uri;
+ String urlresult = url.replace("\\", "/");
+ return urlresult;
+ }
+
+ public static String getDownloadUriHead() {
+ return MsbAddrConfig.getMsbAddress() + "/files/catalog-http";
+ }
+
+ /**
+ * get local path.
+ * @param uri uri
+ * @return local path
+ */
+ public static String getLocalPath(String uri) {
+ File srcDir = new File(uri);
+ String localPath = srcDir.getAbsolutePath();
+ return localPath.replace("\\", "/");
+ }
+
+ /**
+ * get package basic information.
+ * @param fileLocation package location
+ * @return package basic information
+ */
+ public static PackageBasicInfo getPacageBasicInfo(String fileLocation) {
+ PackageBasicInfo basicInfo = new PackageBasicInfo();
+ String unzipDir = ToolUtil.getUnzipDir(fileLocation);
+ boolean isXmlCsar = false;
+ try {
+ String tempfolder = unzipDir;
+ ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder);
+ if (unzipFiles.isEmpty()) {
+ isXmlCsar = true;
+ }
+ for (String unzipFile : unzipFiles) {
+ if (unzipFile.endsWith(CommonConstant.CSAR_META)) {
+ basicInfo = readCsarMeta(unzipFile);
+ }
+ if (ToolUtil.isYamlFile(new File(unzipFile))) {
+ isXmlCsar = false;
+ }
+ }
+ } catch (IOException e1) {
+ LOG.error("judge package type error ! " + e1.getMessage());
+ }
+ if (isXmlCsar) {
+ basicInfo.setFormat(CommonConstant.PACKAGE_XML_FORMAT);
+ } else {
+ basicInfo.setFormat(CommonConstant.PACKAGE_YAML_FORMAT);
+ }
+ return basicInfo;
+ }
+
+ private static PackageBasicInfo readCsarMeta(String unzipFile) {
+ PackageBasicInfo basicInfo = new PackageBasicInfo();
+ File file = new File(unzipFile);
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String tempString = null;
+ while ((tempString = reader.readLine()) != null) {
+ if (!tempString.equals("")) {
+ int count1 = tempString.indexOf(":");
+ String meta = tempString.substring(0, count1).trim();
+ if (meta.equalsIgnoreCase(CommonConstant.CSAR_TYPE_META)) {
+ int count = tempString.indexOf(":") + 1;
+ basicInfo.setType(EnumType.valueOf(tempString.substring(count).trim()));
+ }
+ if (meta.equalsIgnoreCase(CommonConstant.CSAR_PROVIDER_META)) {
+ int count = tempString.indexOf(":") + 1;
+ basicInfo.setProvider(tempString.substring(count).trim());
+ }
+ if (meta.equalsIgnoreCase(CommonConstant.CSAR_VERSION_META)) {
+ int count = tempString.indexOf(":") + 1;
+ basicInfo.setVersion(tempString.substring(count).trim());
+ }
+ }
+ }
+ reader.close();
+ } catch (IOException e2) {
+ e2.printStackTrace();
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e1) {
+ LOG.error("close reader failed ! " + e1.getMessage());
+ }
+ }
+ }
+ return basicInfo;
+ }
+
+ /**
+ * get package format enum.
+ * @param format package format
+ * @return package format enum
+ */
+ public static EnumPackageFormat getPackageFormat(String format) {
+ if (format.equals("xml")) {
+ return EnumPackageFormat.TOSCA_XML;
+ } else if (format.equals("yml") || format.equals("yaml")) {
+ return EnumPackageFormat.TOSCA_YAML;
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/generalconfig/OnBoardingSteps.json b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/generalconfig/OnBoardingSteps.json
new file mode 100644
index 00000000..ca69f285
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/generalconfig/OnBoardingSteps.json
@@ -0,0 +1,54 @@
+{
+ "operTypeList":[
+ {
+ "operTypeName":"Validation",
+ "operTypeId":"validation",
+ "oper":[
+ {
+ "operId":"upload_id_1",
+ "operName":"Validation Step 1 Execute"
+ },
+ {
+ "operId":"upload_id_2",
+ "operName":"Validation Step 2 Execute"
+ },
+ {
+ "operId":"upload_id_3",
+ "operName":"Validation Step 3 Execute"
+ },
+ {
+ "operId":"upload_id_4",
+ "operName":"Validation Step 4 Execute"
+ }
+ ]
+ },
+ {
+ "operTypeName":"LifeCycle",
+ "operTypeId":"lifecycletest",
+ "oper":[
+ {
+ "operId":"lifecycleTestexec",
+ "operName":"LifeCycle Test Execute"
+ }
+ ]
+ },
+ {
+ "operTypeName":"Function Test",
+ "operTypeId":"functiontest",
+ "oper":[
+ {
+ "operId":"packageExists",
+ "operName":"Check Package exists"
+ },
+ {
+ "operId":"download",
+ "operName":"Download Package from Repository"
+ },
+ {
+ "operId":"functestexec",
+ "operName":"Execute Function Testing"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/log4j.properties b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/log4j.properties
new file mode 100644
index 00000000..f1a00ee8
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/log4j.properties
@@ -0,0 +1,8 @@
+log4j.rootLogger=INFO,root
+log4j.appender.root.Append=true
+log4j.appender.root.File=${catalina.base}/logs/vnfsdkmarketplace.log
+log4j.appender.root.layout.ConversionPattern=%d %-5p [%t][%X{moduleID}][%C %L] %m%n
+log4j.appender.root.layout=org.apache.log4j.PatternLayout
+log4j.appender.root.MaxBackupIndex=50
+log4j.appender.root.MaxFileSize=20MB
+log4j.appender.root=org.apache.log4j.RollingFileAppender \ No newline at end of file
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/marketplace.properties b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/marketplace.properties
new file mode 100644
index 00000000..6bf73453
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/marketplace.properties
@@ -0,0 +1,15 @@
+# Copyright 2017 Huawei Technologies Co., Ltd.
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+IP=msb.openo.org
+PORT=80 \ No newline at end of file
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/configuration/configuration.xml b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/configuration/configuration.xml
new file mode 100644
index 00000000..76da57c8
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/configuration/configuration.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2017 Huawei Technologies Co., Ltd.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE configuration
+PUBLIC "//mybatis.org//DTD Config 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-config.dtd">
+<configuration>
+ <environments default="development">
+ <environment id="development">
+ <transactionManager type="JDBC" />
+ <dataSource type="POOLED">
+ <property name="driver" value="com.mysql.jdbc.Driver" />
+ <property name="url" value="jdbc:mysql://127.0.0.1:3306/marketplaceDB" />
+ <property name="username" value="root" />
+ <property name="password" value="Changeme_123" />
+ </dataSource>
+ </environment>
+ </environments>
+ <mappers>
+ <mapper resource="mybatis/sql/MarketplaceMapper.xml" />
+ </mappers>
+</configuration> \ No newline at end of file
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/sql/MarketplaceMapper.xml b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/sql/MarketplaceMapper.xml
new file mode 100644
index 00000000..27801ae5
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/resources/mybatis/sql/MarketplaceMapper.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2017 Huawei Technologies Co., Ltd.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.openo.vnfsdk.marketplace.db.mapper.IMarketplaceMapper">
+
+ <select id="getAllPackageData" resultType="org.openo.vnfsdk.marketplace.db.entity.PackageData">
+ SELECT
+ *
+ FROM
+ CSAR_PACKAGE_TABLE
+ </select>
+
+ <select id="getPackageData" resultType="org.openo.vnfsdk.marketplace.db.entity.PackageData">
+ SELECT
+ *
+ FROM
+ CSAR_PACKAGE_TABLE
+ WHERE
+ CSARID=#{csarId}
+ </select>
+
+ <insert id="savePackageData" parameterType="org.openo.vnfsdk.marketplace.db.entity.PackageData">
+ INSERT INTO
+ CSAR_PACKAGE_TABLE
+ (CSARID, DOWNLOADURI, REPORT, SIZE, FORMAT, CREATETIME, DELETIONPENDING, MODIFYTIME, SHORTDESC, NAME, VERSION, PROVIDER, TYPE, DETAILS, REMARKS,DOWNLOADCOUNT)
+ VALUES
+ (#{csarId}, #{downloadUri}, #{report}, #{size}, #{format},#{createTime}, #{deletionPending}, #{modifyTime}, #{shortDesc}, #{name}, #{version}, #{provider},#{type}, #{details}, #{remarks}, #{downloadCount})
+ </insert>
+
+ <delete id="deletePackageData" parameterType="String">
+ DELETE FROM
+ CSAR_PACKAGE_TABLE
+ WHERE
+ CSARID=#{csarId}
+ </delete>
+
+ <delete id="updatePackageData" parameterType="org.openo.vnfsdk.marketplace.db.entity.PackageData">
+ UPDATE CSAR_PACKAGE_TABLE SET DOWNLOADCOUNT=#{downloadCount}
+ WHERE
+ CSARID=#{csarId}
+ </delete>
+
+</mapper> \ No newline at end of file
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/webapp/WEB-INF/web.xml b/vnfmarket-be/vnf-sdk-marketplace/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..c7480d0b
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,43 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+ xmlns = "http://java.sun.com/xml/ns/javaee"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ id = "WebApp_ID" version = "3.0">
+ <listener>
+ <listener-class>org.openo.vnfsdk.marketplace.msb.AppServletContextListener</listener-class>
+ </listener>
+ <servlet>
+ <servlet-name>Jersey RESTful Application</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.openo.vnfsdk.marketplace.resource</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
+ </init-param>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Jersey RESTful Application</servlet-name>
+ <url-pattern>/openoapi/vnfsdk-marketplace/v1/*</url-pattern>
+ </servlet-mapping>
+
+ <filter>
+ <filter-name>CorsFilter</filter-name>
+ <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
+ <init-param>
+ <param-name>cors.allowed.origins</param-name>
+ <param-value>*</param-value>
+ </init-param>
+ <init-param>
+ <param-name>cors.allowed.methods</param-name>
+ <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>CorsFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app> \ No newline at end of file