From b5ee9a189cc001d4d1a23a2626fbe1458251b125 Mon Sep 17 00:00:00 2001 From: c00149107 Date: Wed, 7 Mar 2018 09:39:58 +0800 Subject: Support query vnf recipe by vnf model uuid Support query vnf recipe by vnf model uuid Change-Id: Ie85fff28586e31bc4c5f3cc90a6360e7af3ba575 Issue-ID: SO-456 Signed-off-by: c00149107 --- .../openecomp/mso/db/catalog/CatalogDatabase.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'mso-catalog-db/src/main/java') diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java index bbdb065027..a01527ed8d 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java @@ -1130,6 +1130,8 @@ public class CatalogDatabase implements Closeable { return resultList.get(0); } + + /** * Return a VNF recipe that matches a given VNF_TYPE and ACTION * @@ -1163,6 +1165,63 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null); return resultList.get(0); } + + /** + * Return a VNF recipe that matches a given ModelName and Modelversion and ACTION + * + * @param modelName + * @param modelVersion + * @param action + * @return VnfRecipe object or null if none found + */ + public VnfRecipe getVnfRecipeByNameVersion(String modelName, String modelVersion, String action) { + StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND version= :version AND action = :action "); + + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF recipe with name " + modelName + + " and action " + + action); + + Query query = getSession().createQuery(hql.toString()); + query.setParameter(VNF_TYPE, modelName); + query.setParameter(MODEL_VERSION, modelVersion); + query.setParameter(ACTION, action); + + @SuppressWarnings("unchecked") + List resultList = query.list(); + + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null); + return null; + } + + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); + + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null); + return resultList.get(0); + } + + /** + * Return a Network recipe that matches a given MODEL_UUID and ACTION + * + * @param modelName + * @param action + * @return NetworkRecipe object or null if none found + */ + public VnfRecipe getVnfRecipeByModuleUuid (String vnfModelUuid, String action) { + LOGGER.debug ("Catalog database - get vnf recipe with vnf resource model uuid " + vnfModelUuid + + " and action " + + action + ); + VnfResource vnfResource = getVnfResourceByModelUuid(vnfModelUuid); + if(null == vnfResource){ + return null; + } + + VnfRecipe recipe = this.getVnfRecipeByNameVersion(vnfResource.getModelName(), vnfResource.getModelVersion(), action); + return recipe; + } /** * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION -- cgit 1.2.3-korg