Support query vnf recipe by vnf model uuid 89/34389/1
authorc00149107 <chenchuanyu@huawei.com>
Wed, 7 Mar 2018 01:39:58 +0000 (09:39 +0800)
committerc00149107 <chenchuanyu@huawei.com>
Wed, 7 Mar 2018 01:39:58 +0000 (09:39 +0800)
Support query vnf recipe by vnf model uuid

Change-Id: Ie85fff28586e31bc4c5f3cc90a6360e7af3ba575
Issue-ID: SO-456
Signed-off-by: c00149107 <chenchuanyu@huawei.com>
mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java

index bbdb065..a01527e 100644 (file)
@@ -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 <VnfRecipe> 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