aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuanHu <yuan.hu1@zte.com.cn>2016-11-25 10:02:44 +0800
committerYuanHu <yuan.hu1@zte.com.cn>2016-12-01 16:17:17 +0800
commitfe2b8d5a4c201b32d016ecb5930e197d3fb84e0a (patch)
tree398727c19039c8bf12f030b5d50a9e30c97a9eaa
parentf48e46c31a7ea43739d8608aca17fd53b486fff6 (diff)
Deploy/UnDeploy workflow package Code optimization for overwrite upload csar package.
Change-Id: Ieb8f2e9ce3a3867fa45ef6cbc52d9d40813dfe35 Issue-id: TOSCA-191 Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java68
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java5
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java3
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java60
4 files changed, 93 insertions, 43 deletions
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java
index a2684025..bdbafb87 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java
@@ -27,50 +27,100 @@ import org.slf4j.LoggerFactory;
public class ModelService {
private static final Logger logger = LoggerFactory.getLogger(ModelService.class);
-
- private static final ModelService instance = new ModelService();
+
+ private static ModelService instance;
public static ModelService getInstance() {
+ if (instance == null) {
+ instance = new ModelService();
+ }
return instance;
}
+
/**
* delete service template according package id.
+ *
* @param packageId package id
* @throws CatalogBadRequestException e1
* @throws CatalogResourceException e2
*/
- public void delete(String packageId) throws CatalogBadRequestException, CatalogResourceException {
+ public void delete(String packageId) throws CatalogResourceException {
logger.info("delete package model data begin.");
-
+
ServiceTemplate st = getServiceTemplateByCsarIdIgnoreError(packageId);
if (st == null) {
return;
}
+ undeployOperationPackage(st.getOperations());
+
TemplateManager.getInstance().deleteServiceTemplateById(st.getServiceTemplateId());
TemplateManager.getInstance().deleteServiceTemplateMapping(null, st.getServiceTemplateId());
- ServiceTemplateOperation[] operations = st.getOperations();
+ logger.info("delete package model data end.");
+ }
+
+ private void undeployOperationPackage(ServiceTemplateOperation[] operations)
+ throws CatalogResourceException {
if (operations != null && operations.length > 0) {
for (ServiceTemplateOperation op : operations) {
Wso2ServiceConsumer.deletePackage(op.getPackageName());
}
}
-
- logger.info("delete package model data end.");
}
private ServiceTemplate getServiceTemplateByCsarIdIgnoreError(String packageId) {
- try{
+ try {
return ServiceTemplateWrapper.getInstance().getServiceTemplateByCsarId(packageId);
} catch (CatalogBadRequestException ignore) {
logger.info("delete package model data ignore.", ignore);
} catch (CatalogResourceException ignore) {
logger.info("delete package model data ignore.", ignore);
}
-
+
return null;
}
+ /**
+ * delete service template data only, not undeploy operation package.
+ *
+ * @param packageId package id
+ * @throws CatalogBadRequestException e1
+ * @throws CatalogResourceException e2
+ */
+ public void deleteServiceTemplateData(String packageId) throws CatalogResourceException {
+ logger.info("delete service template data begin.");
+
+ ServiceTemplate st = getServiceTemplateByCsarIdIgnoreError(packageId);
+ if (st == null) {
+ return;
+ }
+
+ TemplateManager.getInstance().deleteServiceTemplateById(st.getServiceTemplateId());
+ TemplateManager.getInstance().deleteServiceTemplateMapping(null, st.getServiceTemplateId());
+
+ logger.info("delete service template data end.");
+ }
+
+ /**
+ * undeploy operation package of the service template.
+ *
+ * @param packageId package id
+ * @throws CatalogBadRequestException e1
+ * @throws CatalogResourceException e2
+ */
+ public void undeployOperationPackage(String packageId) throws CatalogResourceException {
+ logger.info("undeploy operation package begin.");
+
+ ServiceTemplate st = getServiceTemplateByCsarIdIgnoreError(packageId);
+ if (st == null) {
+ return;
+ }
+
+ undeployOperationPackage(st.getOperations());
+
+ logger.info("undeploy operation package end.");
+ }
+
}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java
index e9cec9d2..56db0aee 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java
@@ -97,6 +97,11 @@ public class ServiceTemplateWrapper {
return TemplateDataHelper.convert2ServiceTemplates(stdList);
}
+
+ public ServiceTemplate[] getServiceTemplates() throws CatalogResourceException {
+ return TemplateDataHelper.convert2ServiceTemplates(
+ TemplateManager.getInstance().queryServiceTemplate(null, null, null));
+ }
/**
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java
index aabeae63..0aff3854 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java
@@ -446,9 +446,6 @@ public class TemplateResource {
} catch (CatalogResourceException e1) {
logger.error("test failed.", e1);
throw RestUtils.newInternalServerErrorException(e1);
- } catch (CatalogBadRequestException e2) {
- logger.error("test failed.", e2);
- throw RestUtils.newBadRequestException(e2);
}
}
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 cf879d95..5614ff92 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
@@ -15,10 +15,24 @@
*/
package org.openo.commontosca.catalog.wrapper;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.openo.commontosca.catalog.cometd.CometdException;
import org.openo.commontosca.catalog.cometd.CometdService;
-import org.openo.commontosca.catalog.cometd.CometdUtil;
import org.openo.commontosca.catalog.common.CommonConstant;
import org.openo.commontosca.catalog.common.HttpServerPathConfig;
import org.openo.commontosca.catalog.common.RestUtil;
@@ -26,7 +40,6 @@ import org.openo.commontosca.catalog.common.ToolUtil;
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.request.PackageBasicInfo;
import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;
import org.openo.commontosca.catalog.entity.response.PackageMeta;
@@ -34,24 +47,9 @@ import org.openo.commontosca.catalog.entity.response.UploadPackageResponse;
import org.openo.commontosca.catalog.filemanage.FileManagerFactory;
import org.openo.commontosca.catalog.model.parser.ModelParserFactory;
import org.openo.commontosca.catalog.model.service.ModelService;
-import org.openo.commontosca.catalog.resources.CatalogBadRequestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
public class PackageWrapper {
private static PackageWrapper packageWrapper;
private static final Logger LOG = LoggerFactory.getLogger(PackageWrapper.class);
@@ -145,10 +143,22 @@ public class PackageWrapper {
String destPath = File.separator + path;
boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath);
if (uploadResult == true) {
+ List<PackageData> existPackageDatas =
+ PackageManager.getInstance().queryPackage(packageData.getName(),
+ packageData.getProvider(), packageData.getVersion(), null, packageData.getType());
+
packateDbData = PackageManager.getInstance().addPackage(packageData);
LOG.info("Store package data to database succed ! packateDbData = "
+ ToolUtil.objectToString(packateDbData));
try {
+ //undeploy operation package of the old csar.
+ if (null != existPackageDatas && existPackageDatas.size() > 0) {
+ LOG.info("undeploy operation package of the old csar package.");
+ for (int i = 0; i < existPackageDatas.size(); i++) {
+ ModelService.getInstance().undeployOperationPackage(existPackageDatas.get(i).getCsarId());
+ }
+ }
+
String tempCsarPath = tempDirName + File.separator + fileName;
serviceTemplateId = ModelParserFactory.getInstance().parse(packateDbData.getCsarId(),
tempCsarPath, PackageWrapperUtil.getPackageFormat(packateDbData.getFormat()));
@@ -169,15 +179,10 @@ public class PackageWrapper {
PackageManager.getInstance().deletePackage(packateDbData.getCsarId());
}
//delete the redundant package data and template data while reupload the same package success.
- ArrayList<PackageData> existPackageDatas =
- PackageManager.getInstance().queryPackage(packageData.getName(),
- packageData.getProvider(), packageData.getVersion(), null, packageData.getType());
if (null != existPackageDatas && existPackageDatas.size() > 0) {
LOG.warn("The package already exist ! Begin to delete the orgin data and reupload !");
for (int i = 0; i < existPackageDatas.size(); i++) {
- if (!existPackageDatas.get(i).getCsarId().equals(packateDbData.getCsarId())) {
- this.delPackageTemplateData(existPackageDatas.get(i).getCsarId());
- }
+ this.delPackageTemplateData(existPackageDatas.get(i).getCsarId());
}
}
LOG.info("upload package file end, fileName:" + fileName);
@@ -199,10 +204,7 @@ public class PackageWrapper {
}
// delete template data from db
try {
- ModelService.getInstance().delete(csarId);
- } catch (CatalogBadRequestException e1) {
- LOG.error("delete template data from db error! csarId = " + csarId, e1);
- return;
+ ModelService.getInstance().deleteServiceTemplateData(csarId);
} catch (CatalogResourceException e2) {
LOG.error("delete template data from db error! csarId = " + csarId, e2);
return;
@@ -293,10 +295,6 @@ public class PackageWrapper {
// delete template data from db
try {
ModelService.getInstance().delete(csarId);
- } catch (CatalogBadRequestException e1) {
- LOG.error("delete template data from db error! csarId = " + csarId, e1);
- publishDelFinishCometdMessage(csarId, "Delete template data failed! " + e1.getMessage());
- return;
} catch (CatalogResourceException e2) {
LOG.error("delete template data from db error! csarId = " + csarId, e2);
publishDelFinishCometdMessage(csarId, "Delete template data failed! " + e2.getMessage());