X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=mso-catalog-db%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fmso%2Fdb%2Fcatalog%2FCatalogDatabase.java;h=4fb5ebc1f8c3ebeb5a649ab4d24c4c0f82139b8b;hb=58dd35b739d5a141467866580b95e30aff03b4f2;hp=534b5a38c926709f84200effb57593b34f1a38d5;hpb=51f4f8eb9cfaa582ab2a6780cee762b0a98912b2;p=so.git 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 534b5a38c9..4fb5ebc1f8 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; @@ -87,11 +88,13 @@ public class CatalogDatabase implements Closeable { private static final String VNF_COMPONENT_TYPE = "vnfComponentType"; private static final String MODEL_ID = "modelId"; private static final String MODEL_NAME = "modelName"; + private static final String MODEL_VERSION = "version"; private static final String TYPE = "type"; private static final String MODEL_TYPE = "modelType"; private static final String MODEL_VERSION_ID = "modelVersionId"; private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid"; - private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId"; + private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId"; + private static final String NETWORK_SERVICE = "network service"; protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); @@ -205,7 +208,7 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null); return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null); @@ -366,7 +369,7 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null); @@ -528,7 +531,7 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null); return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null); @@ -600,7 +603,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null); @@ -644,7 +647,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null); @@ -671,7 +674,7 @@ public class CatalogDatabase implements Closeable { return Collections.EMPTY_LIST; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null); @@ -748,7 +751,7 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null); return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null); @@ -874,7 +877,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null); @@ -975,7 +978,7 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null); return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null); @@ -1073,7 +1076,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null); return resultList.get(0); @@ -1122,13 +1125,15 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); 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 VNF_TYPE and ACTION * @@ -1137,14 +1142,13 @@ public class CatalogDatabase implements Closeable { * @return VnfRecipe object or null if none found */ public VnfRecipe getVnfRecipe(String vnfType, String action) { - StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action "); long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType + " and action " + action); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action "); query.setParameter(VNF_TYPE, vnfType); query.setParameter(ACTION, action); @@ -1156,12 +1160,90 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); 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) { + + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF recipe with name " + modelName + " and action " + action); + + Query query = getSession().createQuery("FROM VnfRecipe WHERE vnfType = :vnfType AND version= :version AND action = :action "); + 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; + } + + resultList.sort(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 vnfModelUuid + * @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.getVersion(), action); + + if (recipe == null && vnfResource.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) { + recipe = getDefaultVnfRecipe(action); + } + return recipe; + } + + private VnfRecipe getDefaultVnfRecipe(String action) { + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get default VNF recipe with action: " + action); + + Query query = getSession().createQuery("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action "); + query.setParameter(VNF_TYPE, "NS_DEFAULT"); + 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; + } + + 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 VF_MODULE_ID and ACTION @@ -1172,12 +1254,10 @@ public class CatalogDatabase implements Closeable { */ public VnfRecipe getVnfRecipeByVfModuleId(String vnfType, String vfModuleId, String action) { - StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action "); - long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId); - Query query = getSession().createQuery(hql.toString ()); + Query query = getSession().createQuery("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action "); query.setParameter(VF_MODULE_MODEL_UUID, vfModuleId); query.setParameter(ACTION, action); @@ -1189,7 +1269,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort(resultList, new MavenLikeVersioningComparator()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(resultList); LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null); @@ -1246,7 +1326,7 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null); @@ -1373,7 +1453,7 @@ public class CatalogDatabase implements Closeable { VfModule module = null; if (modules != null && ! modules.isEmpty()) { - Collections.sort (modules, new MavenLikeVersioningComparator ()); + modules.sort(new MavenLikeVersioningComparator()); Collections.reverse (modules); module = modules.get(0); } @@ -1580,7 +1660,7 @@ public class CatalogDatabase implements Closeable { * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean * - * @param getVnfResourceCustomizationByModelVersionId + * @param modelVersionId * @return VnfResourceCustomization or null if not found */ public VnfResourceCustomization getVnfResourceCustomizationByModelVersionId(String modelVersionId) { @@ -1829,7 +1909,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null); @@ -1862,7 +1942,7 @@ public class CatalogDatabase implements Closeable { * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean * - * @param modelCustomizationUuid + * @param modelUuid * @return VnfResourceCustomization or null if not found */ public VnfResource getVnfResourceByModelUuid(String modelUuid) { @@ -1893,17 +1973,17 @@ public class CatalogDatabase implements Closeable { } else { LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelUuid", null); } - return vnfResource; + return vnfResource; } - + public VnfResCustomToVfModuleCustom getVnfResCustomToVfModule(String vnfId, String vfId) { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database - getVnfResCustomToVfModule - vnfResourceCustModelCustUuid: " + vnfId + ", vfModuleCustModelCustomUuid=" + vfId); - StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue"); - HashMap parameters = new HashMap<>(); + HashMap parameters = new HashMap<>(); parameters.put("vnfIdValue", vnfId); parameters.put("vfIdValue", vfId); - VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow(hql.toString(), parameters, true); + VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow( + "FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue", parameters, true); if (vrctvmc == null) { LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResCustomToVfModule", null); } else { @@ -1926,8 +2006,7 @@ public class CatalogDatabase implements Closeable { public List getVfModulesForVnfResource(String vnfResourceModelUuid) { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceModelUuid: " + vnfResourceModelUuid); - StringBuilder hql = new StringBuilder("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId"); query.setParameter("vnfResourceModelUUId", vnfResourceModelUuid); List resultList = null; try { @@ -2175,8 +2254,7 @@ public class CatalogDatabase implements Closeable { public List getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) { LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); @SuppressWarnings("unchecked") List serviceList = query.list(); @@ -2186,7 +2264,7 @@ public class CatalogDatabase implements Closeable { return new ArrayList<>(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); Service service = serviceList.get(0); @@ -2199,8 +2277,8 @@ public class CatalogDatabase implements Closeable { public List getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) { LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery( + "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); query.setParameter("serviceModelVersion", serviceModelVersion); @@ -2214,7 +2292,7 @@ public class CatalogDatabase implements Closeable { return new ArrayList<>(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); Service service = serviceList.get(0); @@ -2228,18 +2306,18 @@ public class CatalogDatabase implements Closeable { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid); - StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid"); - //Query query = getSession().createQuery(hql.toString()); + //Query query = getSession().createQuery(hql.toString()); //query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid); //LOGGER.debug("QUERY: " + hql.toString() + ", networkModelCustomizationUuid=" + networkModelCustomizationUuid); - + //@SuppressWarnings("unchecked") //List resultList = query.list(); - + HashMap params = new HashMap<>(); params.put("networkModelCustomizationUuid", networkModelCustomizationUuid); - List resultList = this.executeQueryMultipleRows(hql.toString(), params, true); + List resultList = this.executeQueryMultipleRows( + "FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid", params, true); if (resultList.isEmpty()) { LOGGER.debug("Unable to find an NMC with nmcu=" + networkModelCustomizationUuid); @@ -2248,7 +2326,6 @@ public class CatalogDatabase implements Closeable { for (NetworkResourceCustomization nrc : resultList) { nrc.setNetworkResource(this.getNetworkResourceById(nrc.getNetworkResourceModelUuid())); } - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null); return resultList; @@ -2265,9 +2342,9 @@ public class CatalogDatabase implements Closeable { String networkResourceId = nr.getModelUUID(); LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId); - StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery( + "FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId"); query.setParameter("networkResourceId", networkResourceId); @SuppressWarnings("unchecked") @@ -2286,7 +2363,7 @@ public class CatalogDatabase implements Closeable { } public ArrayList getAllVfmcForVrc(VnfResourceCustomization vrc) { LOGGER.debug("Catalog database: getAllVfmcForVrc - " + vrc.getModelCustomizationUuid()); - + List vfmcs = this.getVRCtoVFMC(vrc.getModelCustomizationUuid(), null); if (vfmcs == null || vfmcs.isEmpty()) { return new ArrayList<>(); @@ -2306,8 +2383,7 @@ public class CatalogDatabase implements Closeable { public List getAllVnfsByServiceModelUuid(String serviceModelUuid) { LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery("FROM Service WHERE modelUUID = :serviceModelUuid"); query.setParameter("serviceModelUuid", serviceModelUuid); @SuppressWarnings("unchecked") List serviceList = query.list(); @@ -2317,7 +2393,7 @@ public class CatalogDatabase implements Closeable { return new ArrayList<>(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); // Step 2 - Now query to get the related VnfResourceCustomizations @@ -2328,7 +2404,7 @@ public class CatalogDatabase implements Closeable { LOGGER.debug("Unable to find any related vnfs to a service with modelUuid=" + serviceModelUuid); return new ArrayList<>(); } - + ArrayList allVrcs = new ArrayList<>(); for (ServiceToResourceCustomization strc : strcs) { LOGGER.debug("Try to find VRC for mcu=" + strc.getResourceModelCustomizationUUID()); @@ -2337,13 +2413,12 @@ public class CatalogDatabase implements Closeable { allVrcs.add(vrc); } return allVrcs; - + } public List getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) { LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid); - StringBuilder hqlService = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); - Query query = getSession().createQuery(hqlService.toString()); + Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); @SuppressWarnings("unchecked") List resultList = query.list(); @@ -2351,7 +2426,7 @@ public class CatalogDatabase implements Closeable { if (resultList.isEmpty()) { return new ArrayList<>(); } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); Service service = resultList.get(0); //now just call the method that takes the version - the service object will have the highest version @@ -2361,8 +2436,8 @@ public class CatalogDatabase implements Closeable { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery( + "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); query.setParameter("serviceModelVersion", serviceModelVersion); @@ -2372,7 +2447,7 @@ public class CatalogDatabase implements Closeable { if (resultList.isEmpty()) { return new ArrayList<>(); } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); Service service = resultList.get(0); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null); @@ -2385,8 +2460,8 @@ public class CatalogDatabase implements Closeable { return this.getAllVnfsByServiceName(serviceName); } - StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName and version = :serviceVersion"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery( + "FROM Service WHERE modelName = :serviceName and version = :serviceVersion"); query.setParameter("serviceName", serviceName); query.setParameter("serviceVersion", serviceVersion); @@ -2402,8 +2477,7 @@ public class CatalogDatabase implements Closeable { public List getAllVnfsByServiceName(String serviceName) { LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery("FROM Service WHERE modelName = :serviceName"); query.setParameter("serviceName", serviceName); @SuppressWarnings("unchecked") @@ -2412,7 +2486,7 @@ public class CatalogDatabase implements Closeable { if (resultList.isEmpty()) { return Collections.EMPTY_LIST; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); Service service = resultList.get(0); @@ -2423,8 +2497,7 @@ public class CatalogDatabase implements Closeable { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid); - StringBuilder hql1 = new StringBuilder("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu"); - Query query1 = getSession().createQuery(hql1.toString()); + Query query1 = getSession().createQuery("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu"); query1.setParameter("vrcmcu", vnfModelCustomizationUuid); @SuppressWarnings("unchecked") List resultList1 = query1.list(); @@ -2433,12 +2506,12 @@ public class CatalogDatabase implements Closeable { LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid); return Collections.EMPTY_LIST; } - - for (VnfResourceCustomization vrc : resultList1) { - VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid()); - vrc.setVnfResource(vr); - vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc)); - } + + for (VnfResourceCustomization vrc : resultList1) { + VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid()); + vrc.setVnfResource(vr); + vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc)); + } LOGGER.debug("Returning " + resultList1.size() + " vnf modules"); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null); @@ -2473,8 +2546,7 @@ public class CatalogDatabase implements Closeable { public List getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) { LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); @SuppressWarnings("unchecked") List serviceList = query.list(); @@ -2484,7 +2556,7 @@ public class CatalogDatabase implements Closeable { return new ArrayList<>(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); Service service = serviceList.get(0); @@ -2497,8 +2569,8 @@ public class CatalogDatabase implements Closeable { public List getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) { LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery( + "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); query.setParameter("serviceModelVersion", serviceModelVersion); @@ -2510,7 +2582,7 @@ public class CatalogDatabase implements Closeable { return new ArrayList<>(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); Service service = serviceList.get(0); @@ -2523,8 +2595,8 @@ public class CatalogDatabase implements Closeable { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid); - StringBuilder hql = new StringBuilder("FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery( + "FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid"); query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid); @SuppressWarnings("unchecked") @@ -2582,7 +2654,7 @@ public class CatalogDatabase implements Closeable { return new ServiceMacroHolder(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); Service service = serviceList.get(0); @@ -2601,8 +2673,7 @@ public class CatalogDatabase implements Closeable { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); @SuppressWarnings("unchecked") List serviceList = query.list(); @@ -2612,7 +2683,7 @@ public class CatalogDatabase implements Closeable { return new ServiceMacroHolder(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); Service service = serviceList.get(0); @@ -2632,8 +2703,8 @@ public class CatalogDatabase implements Closeable { long startTime = System.currentTimeMillis(); LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion); - StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); - Query query = getSession().createQuery(hql.toString()); + Query query = getSession().createQuery( + "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion"); query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid); query.setParameter("serviceModelVersion", serviceModelVersion); //TODO make this a unique query @@ -2645,7 +2716,7 @@ public class CatalogDatabase implements Closeable { return new ServiceMacroHolder(); } - Collections.sort (serviceList, new MavenLikeVersioningComparator ()); + serviceList.sort(new MavenLikeVersioningComparator()); Collections.reverse (serviceList); Service service = serviceList.get(0); @@ -2693,7 +2764,7 @@ public class CatalogDatabase implements Closeable { } private void populateNetworkResourceType(List resultList) { - HashMap networkResources = new HashMap(); + HashMap networkResources = new HashMap<>(); for (NetworkResourceCustomization nrc : resultList) { String network_id = nrc.getNetworkResourceModelUuid(); @@ -2731,12 +2802,10 @@ public class CatalogDatabase implements Closeable { public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) { String vfModuleType = vnfType + "::" + vfModuleModelName; - StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type "); - long startTime = System.currentTimeMillis (); LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType); - Query query = getSession ().createQuery (hql.toString ()); + Query query = getSession ().createQuery ("FROM VfModule WHERE type = :type "); query.setParameter (TYPE, vfModuleType); @SuppressWarnings("unchecked") @@ -2747,20 +2816,18 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); VfModule vfMod = resultList.get(0); String vfModuleId = vfMod.getModelUUID(); - StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action "); - LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId + " and action " + action); - Query query1 = getSession ().createQuery (hql1.toString ()); + Query query1 = getSession ().createQuery ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action "); query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId); query1.setParameter (ACTION, action); @@ -2772,7 +2839,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList1, new MavenLikeVersioningComparator ()); + resultList1.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList1); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null); @@ -2783,7 +2850,7 @@ public class CatalogDatabase implements Closeable { * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION * - * @param vnfModuleType + * @param vfModuleType * @parm modelCustomizationUuid * @param asdcServiceModelVersion * @param modelVersion @@ -2839,20 +2906,19 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); VfModule vfMod = resultList.get(0); String vfModuleId = vfMod.getModelUUID(); - StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action "); - LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId + " and action " + action); - Query query1 = getSession ().createQuery (hql1.toString ()); + Query query1 = getSession ().createQuery ( + "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action "); query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId); query1.setParameter (ACTION, action); @@ -2864,7 +2930,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList1, new MavenLikeVersioningComparator ()); + resultList1.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList1); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null); @@ -2894,20 +2960,19 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); VfModule vfMod = resultList.get(0); - String vfModuleId = vfMod.getModelName(); - - StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action "); + String vfModuleId = vfMod.getModelName(); LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId + " and action " + action); - Query query1 = getSession ().createQuery (hql1.toString ()); + Query query1 = getSession ().createQuery ( + "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action "); query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId); query1.setParameter (ACTION, action); @@ -2919,7 +2984,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList1, new MavenLikeVersioningComparator ()); + resultList1.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList1); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null); @@ -3323,7 +3388,9 @@ public class CatalogDatabase implements Closeable { /** * Return a ServiceToResourceCustomization object * - * @param vfModuleModelUuid, heatFilesArtifactUuid + * @param serviceModelUuid + * @param resourceModelCustomizationUuid + * @param modelType * @return VfModuleToHeatFiles or null if none found */ public ServiceToResourceCustomization getServiceToResourceCustomization(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) { @@ -3349,7 +3416,7 @@ public class CatalogDatabase implements Closeable { /** * Return a Map for returning the heat files associated with a vfModule 1707 * - * @param parentHeatTemplateId + * @param vfModuleModelUuid * @return Map or null if none found */ public Map getHeatFilesForVfModule(String vfModuleModelUuid) { @@ -3565,7 +3632,7 @@ public class CatalogDatabase implements Closeable { /** * Retrieves a Heat environment from DB based on its unique key. 1707 * - * @param name the environment artifact name + * @param artifactUuid the environment artifact name * @param version the environment resource version * @return the heat environment from DB or null if not found */ @@ -3798,7 +3865,7 @@ public class CatalogDatabase implements Closeable { /** * Return the newest version of a specific Tosca CSAR Record resource (queried by Name). * - * @param ToscaCsar + * @param artifactChecksum * @return ToscaCsar object or null if none found */ public ToscaCsar getToscaCsar (String artifactChecksum) { @@ -4081,7 +4148,7 @@ public class CatalogDatabase implements Closeable { newVnfRecipe.setDescription(vfRecipe.getDescription()); newVnfRecipe.setOrchestrationUri(vfRecipe.getOrchestrationUri()); newVnfRecipe.setRecipeTimeout(vfRecipe.getRecipeTimeout()); - newVnfRecipe.setVnfComponentParamXSD(vfRecipe.getVnfComponentParamXSD()); + newVnfRecipe.setParamXSD(vfRecipe.getParamXSD()); newVnfRecipe.setVfModuleModelUUId(newRecipe.getModelUUID()); newVnfRecipe.setVersion(vfRecipe.getVersion()); newVnfRecipe.setVnfComponentType(vfRecipe.getVnfComponentType()); @@ -4163,28 +4230,6 @@ public class CatalogDatabase implements Closeable { } } - @Deprecated - public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) { - /* - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - save nested Heat template with name " - + childTemplate.getTemplateName ()); - try { - - saveHeatTemplate(childTemplate, childTemplate.getParameters()); - if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) { - HeatNestedTemplate nestedTemplate = new HeatNestedTemplate (); - nestedTemplate.setParentTemplateId (parentTemplateId); - nestedTemplate.setChildTemplateId (childTemplate.getId ()); - nestedTemplate.setProviderResourceFile (yamlFile); - session.save (nestedTemplate); - } - } finally { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null); - } - */ - } - // 1707 public void saveNestedHeatTemplate (String parentTemplateId, HeatTemplate childTemplate, String yamlFile) { long startTime = System.currentTimeMillis (); @@ -4315,26 +4360,6 @@ public class CatalogDatabase implements Closeable { } } - @Deprecated - public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) { - /* - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - save Heat File to VFmodule link " - + childFile.getFileName()); - try { - saveHeatFiles (childFile); - VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles (); - vfModuleToHeatFile.setVfModuleId(parentVfModuleId); - vfModuleToHeatFile.setHeatFilesId(childFile.getId()); - - session.save (vfModuleToHeatFile); - - } finally { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null); - } - */ - } - public void saveVfModuleToHeatFiles (String parentVfModuleId, HeatFiles childFile) { long startTime = System.currentTimeMillis (); LOGGER.debug ("Catalog database - save Heat File to VFmodule link " @@ -4361,9 +4386,7 @@ public class CatalogDatabase implements Closeable { /** * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID * - * @param networkType - * @param action - * @param serviceType + * @param modelUUID * @return NetworkRecipe object or null if none found */ public NetworkResource getNetworkResourceByModelUuid(String modelUUID) { @@ -4383,7 +4406,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4434,7 +4457,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4443,6 +4466,36 @@ public class CatalogDatabase implements Closeable { } } + /** + * Return a Network recipe that matches a given MODEL_UUID and ACTION + * + * @param networkModelUuid + * @param action + * @return NetworkRecipe object or null if none found + */ + public NetworkRecipe getNetworkRecipeByModuleUuid (String networkModelUuid, String action) { + LOGGER.debug ("Catalog database - get network recipe with network model uuid " + networkModelUuid + + " and action " + + action + ); + NetworkResource networkResource = getNetworkResourceByModelUuid(networkModelUuid); + if(null == networkResource){ + return null; + } + + NetworkRecipe recipe = getNetworkRecipeByNameVersion(networkResource.getModelName(), networkResource.getModelVersion(), action); + + if (recipe == null) { + recipe = getDefaultNetworkReceipe(action); + } + + return recipe; + } + + private NetworkRecipe getDefaultNetworkReceipe(String action) { + String modelName = "SDNC_DEFAULT"; + return getNetworkRecipe(modelName, action); + } /** * Return a Network recipe that matches a given MODEL_NAME and ACTION @@ -4473,7 +4526,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4482,12 +4535,50 @@ public class CatalogDatabase implements Closeable { } } + /** + * get network recipe by module name and version and action. + *
+ * + * @param modelName + * @param modelVersion + * @param action + * @return + * @since ONAP Beijing Release + */ + public NetworkRecipe getNetworkRecipeByNameVersion(String modelName, String modelVersion, String action) { + + long startTime = System.currentTimeMillis (); + LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName + +"model version " + modelVersion + " and action " + action); + + try { + String hql = "FROM NetworkRecipe 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 resultList = query.list (); + + if (resultList.isEmpty ()) { + return null; + } + + resultList.sort(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 Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID * - * @param networkType - * @param action - * @param serviceType + * @param modelCustomizationUuid * @return NetworkRecipe object or null if none found */ public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) { @@ -4507,7 +4598,7 @@ public class CatalogDatabase implements Closeable { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4564,7 +4655,7 @@ public class CatalogDatabase implements Closeable { if (resultList.isEmpty ()) { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4576,7 +4667,7 @@ public class CatalogDatabase implements Closeable { /** * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION * - * @param vfModuleId + * @param vfModuleModelUUId * @param vnfComponentType * @param action * @return VnfComponentsRecipe object or null if none found @@ -4607,7 +4698,7 @@ public class CatalogDatabase implements Closeable { if (resultList.isEmpty ()) { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4636,7 +4727,7 @@ public class CatalogDatabase implements Closeable { return Collections.EMPTY_LIST; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleRecipes", null); @@ -4686,7 +4777,7 @@ public class CatalogDatabase implements Closeable { if (resultList.isEmpty ()) { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4698,7 +4789,7 @@ public class CatalogDatabase implements Closeable { /** * Return a VfModule record that matches a given MODEL_NAME * - * @param modelName + * @param modelUUID * @return VfModule object or null if none found */ public VfModule getVfModuleByModelUUID (String modelUUID) { @@ -4720,7 +4811,7 @@ public class CatalogDatabase implements Closeable { if (resultList.isEmpty ()) { return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); + resultList.sort(new MavenLikeVersioningComparator()); Collections.reverse (resultList); return resultList.get (0); @@ -4761,7 +4852,7 @@ public class CatalogDatabase implements Closeable { LOGGER.debug("Catalog database - recipeResultList is null"); return null; } - Collections.sort(recipeResultList, new MavenLikeVersioningComparator()); + recipeResultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(recipeResultList); LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString()); @@ -4833,7 +4924,7 @@ public class CatalogDatabase implements Closeable { LOGGER.debug("Catalog database - recipeResultList is null"); return null; } - Collections.sort(recipeResultList, new MavenLikeVersioningComparator()); + recipeResultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(recipeResultList); LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString()); @@ -4881,7 +4972,7 @@ public class CatalogDatabase implements Closeable { LOGGER.debug("Catalog database - modelResultList is null"); return null; } - Collections.sort(modelResultList, new MavenLikeVersioningComparator()); + modelResultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(modelResultList); LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString()); @@ -4898,7 +4989,7 @@ public class CatalogDatabase implements Closeable { LOGGER.debug("Catalog database - recipeResultList is null"); return null; } - Collections.sort(recipeResultList, new MavenLikeVersioningComparator()); + recipeResultList.sort(new MavenLikeVersioningComparator()); Collections.reverse(recipeResultList); LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString()); @@ -5027,4 +5118,67 @@ public class CatalogDatabase implements Closeable { } return theObjects; } + + + /** + * get allotted resource recipe by module name and version and action. + *
+ * + * @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 resultList = query.list (); + + if (resultList.isEmpty ()) { + return null; + } + + resultList.sort(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; + } + }