From e830c81a3ca9bbf17dfc42c540dcdc18f74ee16a Mon Sep 17 00:00:00 2001 From: nancylizi Date: Tue, 20 Sep 2016 12:18:59 +0800 Subject: Remove unused code of package manager, change a way to read yamlParseAddr from config file. Issue-id: TOSCA-58 Change-Id: Ie6183f9eefe4e8204a1d9b7ff614b0276d76d9c7 Signed-off-by: nancylizi --- .../org/openo/commontosca/catalog/CatalogApp.java | 2 + .../commontosca/catalog/common/CommonConstant.java | 2 +- .../openo/commontosca/catalog/common/MsbUtil.java | 3 +- .../catalog/common/YmalParseBaseAddrConfig.java | 30 +++++++ .../request/UploadPackageFromFtpRequest.java | 38 --------- .../entity/response/UpdatePackageResponse.java | 30 ------- .../catalog/filemanage/FileManager.java | 6 +- .../catalog/filemanage/entity/FileLink.java | 30 ------- .../filemanage/http/HttpFileManagerImpl.java | 20 ----- .../catalog/wrapper/PackageWrapper.java | 92 +--------------------- 10 files changed, 37 insertions(+), 216 deletions(-) create mode 100644 catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/YmalParseBaseAddrConfig.java delete mode 100644 catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/request/UploadPackageFromFtpRequest.java delete mode 100644 catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/UpdatePackageResponse.java delete mode 100644 catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/entity/FileLink.java (limited to 'catalog-core/catalog-mgr/src/main/java') diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java index 8a00fbe6..4764c7b4 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java @@ -35,6 +35,7 @@ import org.openo.commontosca.catalog.common.HttpServerAddrConfig; import org.openo.commontosca.catalog.common.HttpServerPathConfig; import org.openo.commontosca.catalog.common.MsbAddrConfig; import org.openo.commontosca.catalog.common.ServiceRegistrer; +import org.openo.commontosca.catalog.common.YmalParseBaseAddrConfig; import org.openo.commontosca.catalog.db.dao.DaoManager; import org.openo.commontosca.catalog.db.entity.NodeTemplateData; import org.openo.commontosca.catalog.db.entity.PackageData; @@ -96,6 +97,7 @@ public class CatalogApp extends Application { MsbAddrConfig.setMsbAddress(configuration.getMsbServerAddr()); HttpServerAddrConfig.setHttpServerAddress(configuration.getHttpServerAddr()); HttpServerPathConfig.setHttpServerPath(configuration.getHttpServerPath()); + YmalParseBaseAddrConfig.setYmalParseBaseAddr(configuration.getYamlParseAddr()); initDao(); final ConsoleHealthCheck healthCheck = new ConsoleHealthCheck(configuration.getTemplate()); environment.healthChecks().register("template", healthCheck); diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java index e6992264..1175ade7 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java @@ -20,7 +20,7 @@ public class CommonConstant { // Package Status public static final String PACKAGE_STATUS_DELETING = "deleting"; - public static final String PACKAGE_STATUS_DELETE_FAIL = "deletefail"; + public static final String PACKAGE_STATUS_DELETE_FAIL = "deleteFailed"; public static final String PACKAGE_XML_FORMAT = "xml"; diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbUtil.java index 1a5eac6c..121646b0 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbUtil.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbUtil.java @@ -51,6 +51,7 @@ public class MsbUtil { } public static String getYamlParseBaseUrl() { - return Config.getConfigration().getYamlParseAddr() + "/api/yamlparser/v1"; + return YmalParseBaseAddrConfig.getYmalParseBaseAddr() + "/api/yamlparser/v1"; +// return Config.getConfigration().getYamlParseAddr() + "/api/yamlparser/v1"; } } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/YmalParseBaseAddrConfig.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/YmalParseBaseAddrConfig.java new file mode 100644 index 00000000..57d45b1c --- /dev/null +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/YmalParseBaseAddrConfig.java @@ -0,0 +1,30 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.commontosca.catalog.common; + +public class YmalParseBaseAddrConfig { + + protected static String yamlParseAddr; + + public static String getYmalParseBaseAddr() { + return yamlParseAddr; + } + + public static void setYmalParseBaseAddr(String yamlParseAddr) { + YmalParseBaseAddrConfig.yamlParseAddr = yamlParseAddr; + } +} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/request/UploadPackageFromFtpRequest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/request/UploadPackageFromFtpRequest.java deleted file mode 100644 index 074b418f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/request/UploadPackageFromFtpRequest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2016 [ZTE] and others. - * - * 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.commontosca.catalog.entity.request; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import org.openo.commontosca.catalog.entity.EnumType; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class UploadPackageFromFtpRequest { - - private String provider; - - private EnumType type; - - private String version; - - private String ftpUrl; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/UpdatePackageResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/UpdatePackageResponse.java deleted file mode 100644 index 30ca11b4..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/UpdatePackageResponse.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2016 [ZTE] and others. - * - * 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.commontosca.catalog.entity.response; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class UpdatePackageResponse { - - private String usageState; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManager.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManager.java index a66e458e..d5a3dd31 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManager.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManager.java @@ -16,10 +16,6 @@ package org.openo.commontosca.catalog.filemanage; -import org.openo.commontosca.catalog.filemanage.entity.FileLink; - -import java.util.ArrayList; - public interface FileManager { @@ -35,6 +31,6 @@ public interface FileManager { boolean delete(String srcPath); - ArrayList queryWorkFlow(String path); + //ArrayList queryWorkFlow(String path); } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/entity/FileLink.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/entity/FileLink.java deleted file mode 100644 index f979c8fe..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/entity/FileLink.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2016 [ZTE] and others. - * - * 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.commontosca.catalog.filemanage.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class FileLink { - private String fileName; - private String downloadUri; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java index acdc767a..dea67c83 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java @@ -17,13 +17,11 @@ package org.openo.commontosca.catalog.filemanage.http; import org.openo.commontosca.catalog.filemanage.FileManager; -import org.openo.commontosca.catalog.filemanage.entity.FileLink; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.util.ArrayList; public class HttpFileManagerImpl implements FileManager { @@ -67,23 +65,5 @@ public class HttpFileManagerImpl implements FileManager { return flag; } - @Override - public ArrayList queryWorkFlow(String path) { - LOGGER.info("start query workFlow from http server.path:" + path); - File workFlowRoot = new File(ToolUtil.getHttpServerPath() + path); - ArrayList fileLinks = new ArrayList(); - File[] files = workFlowRoot.listFiles(); - if (files != null && files.length != 0) { - for (File file : files) { - if (file.isFile() && file.getName().endsWith(".zip")) { - FileLink fileLink = new FileLink(); - fileLink.setFileName(file.getName()); - fileLink.setDownloadUri(path + "/" + file.getName()); - } - } - } - LOGGER.info("start query workFlow from http server.size:" + fileLinks.size()); - return fileLinks; - } } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java index a7d9fcca..0f54f03f 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java @@ -21,20 +21,15 @@ import org.openo.commontosca.catalog.common.CommonConstant; import org.openo.commontosca.catalog.common.HttpServerPathConfig; import org.openo.commontosca.catalog.common.RestUtil; import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.common.ZipCompressor; import org.openo.commontosca.catalog.db.entity.PackageData; import org.openo.commontosca.catalog.db.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.resource.PackageManager; import org.openo.commontosca.catalog.db.resource.TemplateManager; -import org.openo.commontosca.catalog.entity.EnumType; import org.openo.commontosca.catalog.entity.request.PackageBasicInfo; -import org.openo.commontosca.catalog.entity.request.UploadPackageFromFtpRequest; import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; import org.openo.commontosca.catalog.entity.response.PackageMeta; import org.openo.commontosca.catalog.entity.response.UploadPackageResponse; import org.openo.commontosca.catalog.filemanage.FileManagerFactory; -import org.openo.commontosca.catalog.filemanage.entity.FileLink; -import org.openo.commontosca.catalog.model.parser.EnumPackageFormat; import org.openo.commontosca.catalog.model.parser.ModelParserFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -428,90 +423,5 @@ public class PackageWrapper { return result; } - /** - * upload package from ftp. - * @param request package basic information - * @return Response - */ - public Response uploadPackageFromFtp(UploadPackageFromFtpRequest request) { - PackageBasicInfo basicInfo = new PackageBasicInfo(); - String tempDirName = null; - String fileName = ""; - UploadPackageResponse result = new UploadPackageResponse(); - basicInfo.setProvider("zte"); - basicInfo.setType(EnumType.NSAR); - basicInfo.setVersion("v1.0"); - PackageMeta packageMeta = new PackageMeta(); - - try { - String ftpUrl = request.getFtpUrl(); - String packageName = PackageWrapperUtil.getPackageName(ftpUrl); - fileName = ToolUtil.processFileName(packageName); - tempDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName); - PackageWrapperUtil.downPackageFromFtp(ftpUrl, tempDirName); - String path = - basicInfo.getType().toString() + File.separator + basicInfo.getProvider() - + File.separator + fileName.replace(".csar", "") + File.separator - + basicInfo.getVersion(); - LOG.info("dest path is : " + path); - packageMeta = PackageWrapperUtil.getPackageMeta(fileName, tempDirName, basicInfo); - String dowloadUri = File.separator + path + File.separator + fileName; - packageMeta.setDownloadUri(dowloadUri); - LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta)); - String destPath = File.separator + path; - boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath); - if (uploadResult == true) { - String newZipPath = tempDirName + fileName.replace(".csar", ".zip"); - ZipCompressor zc = new ZipCompressor(newZipPath); - String metadataPath = tempDirName + File.separator + CommonConstant.TOSCA_METADATA; - String definitions = tempDirName + File.separator + CommonConstant.DEFINITIONS; - zc.compress(metadataPath, definitions); - String parseResult = ModelParserFactory.getInstance().parse(packageMeta.getCsarId(), - newZipPath, EnumPackageFormat.valueOf(packageMeta.getFormat())); - PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta); - PackageManager.getInstance().addPackage(packageData); - } - LOG.info("upload package file end, fileName:" + fileName); - result.setCsarId(packageMeta.getCsarId()); - return Response.ok(result).build(); - } catch (Exception e1) { - LOG.error("upload package fail.", e1); - String csarId = packageMeta.getCsarId(); - if (csarId != null) { - try { - PackageManager.getInstance().deletePackage(csarId); - } catch (CatalogResourceException e2) { - LOG.error("delete package failed !"); - } - } - return RestUtil.getRestException(e1.getMessage()); - } finally { - if (tempDirName != null) { - ToolUtil.deleteDir(new File(tempDirName)); - } - } - } - - /** - * get csar plan uri. - * @param csarId package id - * @return Response - */ - public Response getCsarPlansUri(String csarId) { - ArrayList fileLinks = new ArrayList(); - LOG.info("start query plans of package.csarId:" + csarId); - ArrayList packageList = new ArrayList(); - try { - packageList = PackageManager.getInstance().queryPackageByCsarId(csarId); - if (packageList != null && packageList.size() != 0) { - String downloadUri = packageList.get(0).getDownloadUri(); - fileLinks = FileManagerFactory.createFileManager().queryWorkFlow(downloadUri); - } - return Response.ok(fileLinks).build(); - } catch (CatalogResourceException e1) { - LOG.error("Query plans of package by ID failed ! csarId = " + csarId); - return RestUtil.getRestException(e1.getMessage()); - } - // return Response.serverError().build(); - } + } -- cgit 1.2.3-korg