diff options
12 files changed, 33 insertions, 254 deletions
@@ -1,7 +1,7 @@ -.idea
-*.iml
-.classpath
-.project
-.settings
-target
+.idea +*.iml +.classpath +.project +.settings +target dependency-reduced-pom.xml
\ No newline at end of file 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<CatalogAppConfiguration> { 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/entity/response/UpdatePackageResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/YmalParseBaseAddrConfig.java index 30ca11b4..57d45b1c 100644 --- 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/common/YmalParseBaseAddrConfig.java @@ -14,17 +14,17 @@ * limitations under the License. */ -package org.openo.commontosca.catalog.entity.response; +package org.openo.commontosca.catalog.common; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +public class YmalParseBaseAddrConfig { -@Data -@NoArgsConstructor -@AllArgsConstructor -public class UpdatePackageResponse { + protected static String yamlParseAddr; - private String usageState; + 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/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<FileLink> queryWorkFlow(String path); + //ArrayList<FileLink> 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<FileLink> queryWorkFlow(String path) { - LOGGER.info("start query workFlow from http server.path:" + path); - File workFlowRoot = new File(ToolUtil.getHttpServerPath() + path); - ArrayList<FileLink> fileLinks = new ArrayList<FileLink>(); - 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<FileLink> fileLinks = new ArrayList<FileLink>(); - LOG.info("start query plans of package.csarId:" + csarId); - ArrayList<PackageData> packageList = new ArrayList<PackageData>(); - 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(); - } + } diff --git a/catalog-core/catalog-mgr/src/main/resources/api-doc/META-INF/MANIFEST.MF b/catalog-core/catalog-mgr/src/main/resources/api-doc/META-INF/MANIFEST.MF index c90621f4..eaf90a94 100644 --- a/catalog-core/catalog-mgr/src/main/resources/api-doc/META-INF/MANIFEST.MF +++ b/catalog-core/catalog-mgr/src/main/resources/api-doc/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ -Manifest-Version: 1.0
-Created-By: 1.7.0_72 (Oracle Corporation)
-
+Manifest-Version: 1.0 +Created-By: 1.7.0_72 (Oracle Corporation) + diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java index b8e3367e..4622542b 100644 --- a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java @@ -25,7 +25,6 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.openo.commontosca.catalog.CatalogAppConfiguration; import org.openo.commontosca.catalog.common.Config; @@ -44,7 +43,6 @@ import org.openo.commontosca.catalog.entity.EnumProcessState; import org.openo.commontosca.catalog.entity.EnumUsageState; import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; import org.openo.commontosca.catalog.entity.response.PackageMeta; -import org.openo.commontosca.catalog.filemanage.entity.FileLink; import java.io.File; import java.io.FileInputStream; @@ -100,9 +98,6 @@ public class PackageWrapperTest { } } - // PowerMockito.mockStatic(PackageManager.class); - // PowerMockito.when(manager.addPackage(packageData)).thenReturn(packageData); - // PowerMock.replayAll(); PackageData packageData = new PackageData(); packageData = getPackageData(); manager.addPackage(packageData); @@ -162,19 +157,10 @@ public class PackageWrapperTest { public void testQueryPackageById() throws Exception { ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>(); metas = getPackageMetaList(); - // PackageManager packageManager = mock(PackageManager.class); - // when(packageManager.queryPackageByCsarId(anyString())).thenThrow(new Exception()); - // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(packageManager); - // PowerMockito.mockStatic(PackageManager.class); - // PowerMockito.when(PackageManager.getInstance()).thenReturn(manager); - // PowerMock.replayAll(); - // when(manager.queryPackageByCsarId(anyString())).thenThrow(new Exception()); - // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(manager); - Response result = PackageWrapper.getInstance().queryPackageById("1"); + Response result = PackageWrapper.getInstance().queryPackageById("123456"); assertEquals(200, result.getStatus()); assertEquals(metas, result.getEntity()); - } @Test @@ -193,7 +179,7 @@ public class PackageWrapperTest { public void testUpdatePackageStatus() { System.out.println("Test update package status"); Response result = - PackageWrapper.getInstance().updatePackageStatus("1", "Enabled", "NotInUse", "true", + PackageWrapper.getInstance().updatePackageStatus("123456", "Enabled", "NotInUse", "true", "onBoarding", "true"); assertEquals(200, result.getStatus()); } @@ -212,27 +198,7 @@ public class PackageWrapperTest { expectResult.setDownloadUri(csarFileUri); expectResult.setLocalPath(localPath); - Response result = PackageWrapper.getInstance().getCsarFileUri("1", "/images/segw.img"); - assertEquals(200, result.getStatus()); - assertEquals(expectResult, result.getEntity()); - } - - @Ignore - @Test - public void testGetPlansUri() { - System.out.println("Test get csar plans uri "); - ArrayList<FileLink> expectResult = new ArrayList<FileLink>(); - FileLink fileLink1 = new FileLink(); - fileLink1.setFileName("init.zip"); - fileLink1.setDownloadUri(MsbAddrConfig.getMsbAddress() - + "/NSAR/ZTE/NanocellGW/v1.0/Plans/init.zip"); - expectResult.add(fileLink1); - FileLink fileLink2 = new FileLink(); - fileLink2.setFileName("delete.zip"); - fileLink2.setDownloadUri(MsbAddrConfig.getMsbAddress() - + "/NSAR/ZTE/NanocellGW/v1.0/Plans/delete.zip"); - expectResult.add(fileLink2); - Response result = PackageWrapper.getInstance().getCsarPlansUri("1"); + Response result = PackageWrapper.getInstance().getCsarFileUri("123456", "/images/segw.img"); assertEquals(200, result.getStatus()); assertEquals(expectResult, result.getEntity()); } @@ -240,7 +206,7 @@ public class PackageWrapperTest { @Test public void testDelPackage() { System.out.println("Test delete package "); - Response result = PackageWrapper.getInstance().delPackage("1"); + Response result = PackageWrapper.getInstance().delPackage("123456"); assertEquals(204, result.getStatus()); try { Thread.sleep(5000); @@ -254,9 +220,9 @@ public class PackageWrapperTest { */ @After public void tearDown() throws Exception { - ArrayList<PackageData> packageList = manager.queryPackageByCsarId("1"); + ArrayList<PackageData> packageList = manager.queryPackageByCsarId("123456"); if (packageList != null && packageList.size() != 0) { - manager.deletePackage("1"); + manager.deletePackage("123456"); } else { return; } @@ -280,7 +246,7 @@ public class PackageWrapperTest { private PackageData getPackageData() { PackageData packageData = new PackageData(); - packageData.setCsarId("1"); + packageData.setCsarId("123456"); packageData.setCreateTime("2016-06-29 03:33:15"); packageData.setDeletionPending("false"); packageData.setDownloadUri("/NSAR/ZTE/NanocellGW/v1.0/"); @@ -298,18 +264,10 @@ public class PackageWrapperTest { return packageData; } - private ArrayList<PackageData> getPackageDataList() { - ArrayList<PackageData> packageDataList = new ArrayList<PackageData>(); - PackageData packageData = new PackageData(); - packageData = getPackageData(); - packageDataList.add(packageData); - return packageDataList; - } - private ArrayList<PackageMeta> getPackageMetaList() { PackageMeta meta = new PackageMeta(); meta.setCreateTime("2016-06-29 03:33:15"); - meta.setCsarId("1"); + meta.setCsarId("123456"); meta.setDeletionPending(false); meta.setDownloadUri(MsbAddrConfig.getMsbAddress() + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW.csar"); |