aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorc00149107 <chenchuanyu@huawei.com>2018-03-07 10:24:57 +0800
committerc00149107 <chenchuanyu@huawei.com>2018-03-07 10:24:57 +0800
commit17d254a18dbd790ba3ef3a9ff383abe8a5d39c8f (patch)
tree87299aa1d21e30263d24e7128c2b8a0b90e48f18
parentb5ee9a189cc001d4d1a23a2626fbe1458251b125 (diff)
Support query ar recipe by ar model uuid
Support query ar recipe by ar model uuid Change-Id: I846bc1f55f2c15be02ba44496e1fc1b33fdaf8e2 Issue-ID: SO-456 Signed-off-by: c00149107 <chenchuanyu@huawei.com>
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java64
1 files changed, 64 insertions, 0 deletions
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 a01527ed8d..26b641d883 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
@@ -36,6 +36,7 @@ import org.hibernate.Session;
import org.openecomp.mso.db.AbstractSessionFactoryManager;
import org.openecomp.mso.db.catalog.beans.AllottedResource;
import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.ArRecipe;
import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
import org.openecomp.mso.db.catalog.beans.HeatFiles;
import org.openecomp.mso.db.catalog.beans.HeatNestedTemplate;
@@ -5147,4 +5148,67 @@ public class CatalogDatabase implements Closeable {
}
return theObjects;
}
+
+
+ /**
+ * get allotted resource recipe by module name and version and action.
+ * <br>
+ *
+ * @param modelName
+ * @param modelVersion
+ * @param action
+ * @return
+ * @since ONAP Beijing Release
+ */
+ public ArRecipe getArRecipeByNameVersion(String modelName, String modelVersion, String action) {
+
+ long startTime = System.currentTimeMillis ();
+ LOGGER.debug ("Catalog database - get ar recipe with ar model name " + modelName
+ +"model version " + modelVersion + " and action " + action);
+
+ try {
+ String hql = "FROM ArRecipe WHERE modelName = :modelName AND version=:version AND action = :action";
+
+ Query query = getSession ().createQuery (hql);
+ query.setParameter (MODEL_NAME, modelName);
+ query.setParameter (MODEL_VERSION, modelVersion);
+ query.setParameter (ACTION, action);
+
+ @SuppressWarnings("unchecked")
+ List <ArRecipe> resultList = query.list ();
+
+ if (resultList.isEmpty ()) {
+ return null;
+ }
+
+ Collections.sort (resultList, new MavenLikeVersioningComparator ());
+ Collections.reverse (resultList);
+
+ return resultList.get (0);
+ } finally {
+ LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
+ }
+ }
+
+ /**
+ * Return a allotted resource recipe that matches a given MODEL_UUID and ACTION
+ *
+ * @param modelName
+ * @param action
+ * @return ArRecipe object or null if none found
+ */
+ public ArRecipe getArRecipeByModuleUuid (String ArModelUuid, String action) {
+ LOGGER.debug ("Catalog database - get ar recipe with ar model uuid " + ArModelUuid
+ + " and action "
+ + action
+ );
+ AllottedResource arResource = this.getAllottedResourceByModelUuid(ArModelUuid);
+ if(null == arResource){
+ return null;
+ }
+
+ ArRecipe recipe = getArRecipeByNameVersion(arResource.getModelName(), arResource.getModelVersion(), action);
+ return recipe;
+ }
+
}