aboutsummaryrefslogtreecommitdiffstats
path: root/mso-catalog-db/src/main/java/org
diff options
context:
space:
mode:
authorChuanyu Chen <chenchuanyu@huawei.com>2018-03-07 03:57:05 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-07 03:57:05 +0000
commitc018d684b72cf0ea8e3ab2dd8b8a974738f6c5f2 (patch)
tree46dd70b9a7b81cf30ab645832ad07d2f5daeaba3 /mso-catalog-db/src/main/java/org
parentd9134ec971e925bc03069666c1511146d2df50e7 (diff)
parent17d254a18dbd790ba3ef3a9ff383abe8a5d39c8f (diff)
Merge "Support query ar recipe by ar model uuid"
Diffstat (limited to 'mso-catalog-db/src/main/java/org')
-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 6083f1bd9f..bd3b988254 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;
@@ -5129,4 +5130,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;
+ }
+
}