2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.db.catalog;
23 import java.io.Closeable;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.List;
30 import org.openecomp.mso.db.catalog.beans.*;
31 import org.hibernate.HibernateException;
32 import org.hibernate.Query;
33 import org.hibernate.Session;
34 import org.hibernate.SessionFactory;
35 import org.hibernate.cfg.Configuration;
36 import org.hibernate.service.ServiceRegistry;
37 import org.hibernate.service.ServiceRegistryBuilder;
39 import org.openecomp.mso.db.HibernateUtils;
40 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
41 import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
42 import org.openecomp.mso.logger.MessageEnum;
43 import org.openecomp.mso.logger.MsoLogger;
46 * This class encapsulates all of the objects that can be queried from a Catalog database.
47 * Clients must use these methods to retrieve catalog objects. The session is not
48 * available for clients to do their own direct queries to the database.
52 public class CatalogDatabase implements Closeable {
54 protected static HibernateUtils hibernateUtils = new HibernateUtilsCatalogDb ();
56 private static final String NETWORK_TYPE = "networkType";
57 private static final String ACTION = "action";
58 private static final String VNF_TYPE = "vnfType";
59 private static final String SERVICE_TYPE = "serviceType";
60 private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
61 private static final String MODEL_ID = "modelId";
62 private static final String MODEL_NAME = "modelName";
63 private static final String TYPE = "type";
64 private static final String MODEL_TYPE = "modelType";
65 private static final String MODEL_VERSION_ID = "modelVersionId";
66 private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
67 private static final String VF_MODULE_ID = "vfModuleId";
68 private static final String SERVICE_NAME_VERSION_ID= "serviceNameVersionId";
70 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
72 protected Session session = null;
74 public CatalogDatabase () {
78 private Session getSession () {
80 if (session == null) {
82 session = hibernateUtils.getSessionFactory ().openSession ();
83 session.beginTransaction ();
84 } catch (HibernateException he) {
85 LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Error creating Hibernate Session: " + he, "", "", MsoLogger.ErrorCode.DataError, "Error creating Hibernate Session: " + he);
94 * Close an open Catalog Database session.
95 * This method should always be called when a client is finished using a
96 * CatalogDatabase instance.
99 public void close () {
100 if (session != null) {
107 * Commits the current transaction on this session and starts a fresh one.
109 public void commit () {
110 getSession ().getTransaction ().commit ();
111 getSession ().beginTransaction ();
115 * Rolls back current transaction and starts a fresh one.
117 public void rollback () {
118 getSession ().getTransaction ().rollback ();
119 getSession ().beginTransaction ();
123 * Return all Heat Templates in the Catalog DB
125 * @return A list of HeatTemplate objects
127 @SuppressWarnings("unchecked")
128 public List <HeatTemplate> getAllHeatTemplates () {
129 long startTime = System.currentTimeMillis ();
130 LOGGER.debug ("Catalog database - get all Heat templates");
131 String hql = "FROM HeatTemplate";
132 Query query = getSession ().createQuery (hql);
134 List <HeatTemplate> result = query.list ();
135 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatTemplates", null);
140 * Fetch a specific Heat Template by ID.
143 * @return HeatTemplate object or null if none found
145 public HeatTemplate getHeatTemplate (int templateId) {
146 long startTime = System.currentTimeMillis ();
147 LOGGER.debug ("Catalog database - get Heat template with id " + templateId);
149 HeatTemplate template = (HeatTemplate) getSession ().get (HeatTemplate.class, templateId);
150 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
155 * Return the newest version of a specific Heat Template (queried by Name).
157 * @param templateName
158 * @return HeatTemplate object or null if none found
160 public HeatTemplate getHeatTemplate (String templateName) {
162 long startTime = System.currentTimeMillis ();
163 LOGGER.debug ("Catalog database - get Heat template with name " + templateName);
165 String hql = "FROM HeatTemplate WHERE templateName = :template_name";
166 Query query = getSession ().createQuery (hql);
167 query.setParameter ("template_name", templateName);
169 @SuppressWarnings("unchecked")
170 List <HeatTemplate> resultList = query.list ();
172 // See if something came back. Name is unique, so
173 if (resultList.isEmpty ()) {
174 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null);
177 Collections.sort (resultList, new MavenLikeVersioningComparator ());
178 Collections.reverse (resultList);
180 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
181 return resultList.get (0);
185 * Return a specific version of a specific Heat Template (queried by Name).
187 * @param templateName
189 * @return HeatTemplate object or null if none found
191 public HeatTemplate getHeatTemplate (String templateName, String version) {
193 long startTime = System.currentTimeMillis ();
194 LOGGER.debug ("Catalog database - get Heat template with name " + templateName
198 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version";
199 Query query = getSession ().createQuery (hql);
200 query.setParameter ("template_name", templateName);
201 query.setParameter ("version", version);
203 @SuppressWarnings("unchecked")
204 List <HeatTemplate> resultList = query.list ();
206 // See if something came back.
207 if (resultList.isEmpty ()) {
208 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found.", "CatalogDB", "getHeatTemplate", null);
211 // Name + Version is unique, so should only be one element
212 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
213 return resultList.get (0);
217 * Fetch a Service definition by InvariantUUID
219 public Service getServiceByInvariantUUID (String modelInvariantUUID) {
221 long startTime = System.currentTimeMillis ();
222 LOGGER.debug ("Catalog database - get service with Invariant UUID " + modelInvariantUUID);
224 String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid";
225 Query query = getSession ().createQuery (hql);
226 query.setParameter ("model_invariant_uuid", modelInvariantUUID);
228 @SuppressWarnings("unchecked")
229 List <Service> resultList = query.list ();
231 // See if something came back.
232 if (resultList.isEmpty ()) {
233 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
236 Collections.sort (resultList, new MavenLikeVersioningComparator ());
237 Collections.reverse (resultList);
239 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
240 return resultList.get (0);
244 * Fetch a Service definition
246 public Service getService (String serviceName) {
248 long startTime = System.currentTimeMillis ();
249 LOGGER.debug ("Catalog database - get service with name " + serviceName);
251 String hql = "FROM Service WHERE serviceName = :service_name";
252 Query query = getSession ().createQuery (hql);
253 query.setParameter ("service_name", serviceName);
255 Service service = null;
257 service = (Service) query.uniqueResult ();
258 } catch (org.hibernate.NonUniqueResultException nure) {
259 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceName='" + serviceName + "'");
260 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceName=" + serviceName);
262 } catch (org.hibernate.HibernateException he) {
263 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceName + "'");
264 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceName=" + serviceName);
266 } catch (Exception e) {
267 LOGGER.debug("Generic Exception - while searching for: serviceName='" + serviceName);
268 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceName=" + serviceName);
271 if (service == null) {
272 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
274 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
281 * Fetch a Service definition
283 public Service getServiceByUUID (String serviceNameVersionId) {
285 long startTime = System.currentTimeMillis ();
286 LOGGER.debug ("Catalog database - get service with UUID " + serviceNameVersionId);
288 String hql = "FROM Service WHERE serviceNameVersionId = :service_id";
289 Query query = getSession ().createQuery (hql);
290 query.setParameter ("service_id", serviceNameVersionId);
292 Service service = null;
294 service = (Service) query.uniqueResult ();
295 } catch (org.hibernate.NonUniqueResultException nure) {
296 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceNameVersionId='" + serviceNameVersionId + "'");
297 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceNameVersionId=" + serviceNameVersionId);
299 } catch (org.hibernate.HibernateException he) {
300 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceNameVersionId + "'");
301 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceNameVersionId=" + serviceNameVersionId);
303 } catch (Exception e) {
304 LOGGER.debug("Generic Exception - while searching for: serviceName='" + serviceNameVersionId);
305 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceNameVersionId=" + serviceNameVersionId);
308 if (service == null) {
309 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
311 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
318 * Fetch the Common Service API definition using Http Method + serviceNameVersionId
320 public Service getService(HashMap<String, String> map, String httpMethod) {
322 String serviceNameVersionId = map.get("serviceNameVersionId");
324 String serviceId = "not_set";
325 String serviceVersion = "not_set";
327 if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
328 LOGGER.debug ("Catalog database - get serviceNameVersionId with id " + serviceNameVersionId);
330 String hql = "FROM Service WHERE service_name_version_id = :service_name_version_id and http_method = :http_method";
331 query = getSession ().createQuery (hql);
332 query.setParameter ("service_name_version_id", serviceNameVersionId);
334 serviceId = map.get("serviceId");
335 serviceVersion = map.get("serviceVersion");
336 LOGGER.debug ("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
338 String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
339 query = getSession ().createQuery (hql);
340 query.setParameter ("service_id", serviceId);
341 query.setParameter ("service_version", serviceVersion);
344 query.setParameter ("http_method", httpMethod);
346 long startTime = System.currentTimeMillis ();
347 Service service = null;
349 service = (Service) query.uniqueResult ();
350 } catch (org.hibernate.NonUniqueResultException nure) {
351 LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
352 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for service_id=" + serviceId);
354 } catch (org.hibernate.HibernateException he) {
355 LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
356 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for service_id=" + serviceId);
358 } catch (Exception e) {
359 LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
360 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for service_id=" + serviceId);
363 if (service == null) {
364 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
366 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
372 * Return the newest version of a Service (queried by Name).
375 * @return Service object or null if none found
377 public Service getServiceByName (String serviceName) {
379 long startTime = System.currentTimeMillis ();
380 LOGGER.debug ("Catalog database - get service with name " + serviceName);
382 String hql = "FROM Service WHERE serviceName = :service_name";
383 Query query = getSession ().createQuery (hql);
384 query.setParameter ("service_name", serviceName);
386 @SuppressWarnings("unchecked")
387 List <Service> resultList = query.list ();
389 // See if something came back.
390 if (resultList.isEmpty ()) {
391 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
394 Collections.sort (resultList, new MavenLikeVersioningComparator ());
395 Collections.reverse (resultList);
397 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
398 return resultList.get (0);
401 public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
402 long startTime = System.currentTimeMillis ();
403 LOGGER.debug ("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion);
405 String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR";
406 Query query = getSession ().createQuery (hql);
407 query.setParameter ("MODEL_INVARIANT_UUID", modelInvariantId);
408 query.setParameter("VERSION_STR", modelVersion);
410 Service result = null;
412 result = (Service) query.uniqueResult();
413 } catch (org.hibernate.NonUniqueResultException nure) {
414 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
415 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantId=" + modelInvariantId + " and modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId);
416 throw new Exception("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
418 // See if something came back.
420 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null);
424 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null);
429 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
430 * (MODEL_VERSION_ID) and ACTION
432 * @param modelVersionId
434 * @return ServiceRecipe object or null if none found
436 public ServiceRecipe getServiceRecipe(String modelVersionId,
439 long startTime = System.currentTimeMillis();
440 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
441 + " and action=" + action);
446 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceId, SR.action, SR.description, " +
447 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
448 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
449 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
450 "WHERE SR.serviceId = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
451 Query query = getSession().createQuery(hql);
452 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
453 query.setParameter(ACTION, action);
455 @SuppressWarnings("unchecked")
456 List<ServiceRecipe> recipeResultList = query.list();
457 if (recipeResultList.isEmpty()) {
458 LOGGER.debug("Catalog database - recipeResultList is null");
461 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
462 Collections.reverse(recipeResultList);
463 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
465 return recipeResultList.get(0);
467 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
472 * Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
476 * @return ServiceRecipe object or null if none found
478 public ServiceRecipe getServiceRecipe (int serviceId, String action) {
480 StringBuilder hql = null;
483 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceId = :serviceId");
485 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceId = :serviceId AND action = :action ");
488 long startTime = System.currentTimeMillis ();
489 LOGGER.debug ("Catalog database - get Service recipe with serviceId " + Integer.toString(serviceId)
494 Query query = getSession ().createQuery (hql.toString ());
495 query.setParameter ("serviceId", serviceId);
496 query.setParameter (ACTION, action);
498 query.setParameter (ACTION, action);
501 @SuppressWarnings("unchecked")
502 List <ServiceRecipe> resultList = query.list ();
504 if (resultList.isEmpty ()) {
505 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
509 Collections.sort (resultList, new MavenLikeVersioningComparator ());
510 Collections.reverse (resultList);
512 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
513 return resultList.get (0);
516 public List<ServiceRecipe> getServiceRecipes (int serviceId) {
518 StringBuilder hql = null;
520 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceId = :serviceId");
522 long startTime = System.currentTimeMillis ();
523 LOGGER.debug ("Catalog database - get Service recipe with serviceId " + Integer.toString(serviceId));
525 Query query = getSession ().createQuery (hql.toString ());
526 query.setParameter ("serviceId", serviceId);
528 @SuppressWarnings("unchecked")
529 List <ServiceRecipe> resultList = query.list ();
531 if (resultList.isEmpty ()) {
532 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null);
536 Collections.sort (resultList, new MavenLikeVersioningComparator ());
537 Collections.reverse (resultList);
539 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null);
544 * Return the VNF component data - queried by the VNFs ID and the component type.
548 * @return VnfComponent object or null if none found
550 public VnfComponent getVnfComponent (int vnfId, String type) {
552 long startTime = System.currentTimeMillis();
553 LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
555 String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
556 Query query = getSession ().createQuery (hql);
557 query.setParameter ("vnf_id", vnfId);
558 query.setParameter ("type", type);
560 VnfComponent result = null;
562 result = (VnfComponent) query.uniqueResult();
563 } catch (org.hibernate.NonUniqueResultException nure) {
564 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
565 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnf_id=" + vnfId + " and componentType=" + type, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnf_id=" + vnfId);
567 } catch (org.hibernate.HibernateException he) {
568 LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "'");
569 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnf_id=" + vnfId + " and componentType=" + type, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnf_id=" + vnfId);
571 } catch (Exception e) {
572 LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "'");
573 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnf_id=" + vnfId + " and componentType=" + type, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnf_id=" + vnfId);
577 //LOGGER.debug("Found VNF Component: " + result.toString());
578 if (result != null) {
579 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
581 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
587 * Return the newest version of a specific VNF resource (queried by Name).
590 * @return VnfResource object or null if none found
592 public VnfResource getVnfResource (String vnfType) {
594 long startTime = System.currentTimeMillis ();
595 LOGGER.debug ("Catalog database - get vnf resource with name " + vnfType);
597 String hql = "FROM VnfResource WHERE vnfType = :vnf_name";
598 Query query = getSession ().createQuery (hql);
599 query.setParameter ("vnf_name", vnfType);
601 @SuppressWarnings("unchecked")
602 List <VnfResource> resultList = query.list ();
604 // See if something came back. Name is unique, so
605 if (resultList.isEmpty ()) {
606 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
609 Collections.sort (resultList, new MavenLikeVersioningComparator ());
610 Collections.reverse (resultList);
612 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
613 return resultList.get (0);
617 * Return the newest version of a specific VNF resource (queried by Name).
621 * @return VnfResource object or null if none found
623 public VnfResource getVnfResource (String vnfType, String serviceVersion) {
625 long startTime = System.currentTimeMillis ();
626 LOGGER.debug ("Catalog database - get VNF resource with name " + vnfType);
628 String hql = "FROM VnfResource WHERE vnfType = :vnfName and version = :serviceVersion";
629 Query query = getSession ().createQuery (hql);
630 query.setParameter ("vnfName", vnfType);
631 query.setParameter ("serviceVersion", serviceVersion);
633 VnfResource resource = null;
635 resource = (VnfResource) query.uniqueResult ();
636 } catch (org.hibernate.NonUniqueResultException nure) {
637 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
638 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
640 } catch (org.hibernate.HibernateException he) {
641 LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "'");
642 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
644 } catch (Exception e) {
645 LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
646 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
649 if (resource == null) {
650 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
652 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
658 * Return the newest version of a specific VNF resource (queried by modelCustomizationId).
662 * @return VnfResource object or null if none found
664 public VnfResource getVnfResourceByModelCustomizationId (String modelCustomizationId, String serviceVersion) {
666 long startTime = System.currentTimeMillis ();
667 LOGGER.debug ("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
669 String hql = "FROM VnfResource WHERE modelCustomizationUuid = :modelCustomizationId and version = :serviceVersion";
670 Query query = getSession ().createQuery (hql);
671 query.setParameter ("modelCustomizationId", modelCustomizationId);
672 query.setParameter ("serviceVersion", serviceVersion);
674 VnfResource resource = null;
676 resource = (VnfResource) query.uniqueResult ();
677 } catch (org.hibernate.NonUniqueResultException nure) {
678 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "', serviceVersion='" + serviceVersion + "'");
679 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
681 } catch (org.hibernate.HibernateException he) {
682 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "', asdc_service_model_version='" + serviceVersion + "'");
683 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationId=" + modelCustomizationId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationId=" + modelCustomizationId);
685 } catch (Exception e) {
686 LOGGER.debug("Generic Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "', serviceVersion='" + serviceVersion + "'");
687 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationId=" + modelCustomizationId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationId=" + modelCustomizationId);
690 if (resource == null) {
691 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
693 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
699 * Return the newest version of a specific VNF resource (queried by ID).
701 * @param id The vnf id
702 * @return VnfResource object or null if none found
704 public VnfResource getVnfResourceById (int id) {
706 long startTime = System.currentTimeMillis ();
707 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
709 String hql = "FROM VnfResource WHERE id = :id";
710 Query query = getSession ().createQuery (hql);
711 query.setParameter ("id", id);
713 @SuppressWarnings("unchecked")
714 List <VnfResource> resultList = query.list ();
716 // See if something came back. Name is unique, so
717 if (resultList.isEmpty ()) {
718 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
721 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
722 return resultList.get (0);
726 * Return the newest version of a vfModule - 1607
729 public VfModule getVfModuleModelName (String modelName) {
731 long startTime = System.currentTimeMillis ();
732 LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName);
734 String hql = "FROM VfModule WHERE model_name = :model_name";
735 Query query = getSession ().createQuery (hql);
736 query.setParameter ("model_name", modelName);
738 @SuppressWarnings("unchecked")
739 List <VfModule> resultList = query.list ();
741 // See if something came back. Name is unique, so
742 if (resultList.isEmpty ()) {
743 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
746 Collections.sort (resultList, new MavenLikeVersioningComparator ());
747 Collections.reverse (resultList);
749 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
750 return resultList.get (0);
753 public VfModule getVfModuleModelName (String modelName, String model_version) {
755 long startTime = System.currentTimeMillis ();
756 LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
758 String hql = "FROM VfModule WHERE model_name = :model_name and version = :model_version";
759 Query query = getSession ().createQuery (hql);
760 query.setParameter ("model_name", modelName);
761 query.setParameter ("model_version", model_version);
763 VfModule module = null;
765 module = (VfModule) query.uniqueResult ();
766 } catch (org.hibernate.NonUniqueResultException nure) {
767 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
768 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
770 } catch (org.hibernate.HibernateException he) {
771 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
772 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
774 } catch (Exception e) {
775 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
776 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
779 if (module == null) {
780 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
782 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
789 * Return the newest version of a specific Network resource (queried by Type).
792 * @return NetworkResource object or null if none found
794 public NetworkResource getNetworkResource (String networkType) {
796 long startTime = System.currentTimeMillis ();
797 LOGGER.debug ("Catalog database - get network resource with type " + networkType);
799 String hql = "FROM NetworkResource WHERE networkType = :network_type";
800 Query query = getSession ().createQuery (hql);
801 query.setParameter ("network_type", networkType);
803 @SuppressWarnings("unchecked")
804 List <NetworkResource> resultList = query.list ();
806 // See if something came back. Name is unique, so
807 if (resultList.isEmpty ()) {
808 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
812 Collections.sort (resultList, new MavenLikeVersioningComparator ());
813 Collections.reverse (resultList);
814 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
815 return resultList.get (0);
819 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
823 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
824 * @return VnfRecipe object or null if none found
826 public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) {
827 boolean withServiceType = false;
829 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
832 if (serviceType == null || serviceType.isEmpty ()) {
833 hql.append ("AND serviceType is NULL ");
835 hql.append ("AND serviceType = :serviceType ");
836 withServiceType = true;
839 long startTime = System.currentTimeMillis ();
840 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
843 + " and service type "
846 Query query = getSession ().createQuery (hql.toString ());
847 query.setParameter (VNF_TYPE, vnfType);
848 query.setParameter (ACTION, action);
849 if (withServiceType) {
850 query.setParameter (SERVICE_TYPE, serviceType);
853 @SuppressWarnings("unchecked")
854 List <VnfRecipe> resultList = query.list ();
856 if (resultList.isEmpty ()) {
857 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
861 Collections.sort (resultList, new MavenLikeVersioningComparator ());
862 Collections.reverse (resultList);
864 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
865 return resultList.get (0);
869 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
873 * @return VnfRecipe object or null if none found
875 public VnfRecipe getVnfRecipe (String vnfType, String action) {
876 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
878 long startTime = System.currentTimeMillis ();
879 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
883 Query query = getSession ().createQuery (hql.toString ());
884 query.setParameter (VNF_TYPE, vnfType);
885 query.setParameter (ACTION, action);
887 @SuppressWarnings("unchecked")
888 List <VnfRecipe> resultList = query.list ();
890 if (resultList.isEmpty ()) {
891 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
895 Collections.sort (resultList, new MavenLikeVersioningComparator ());
896 Collections.reverse (resultList);
898 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
899 return resultList.get (0);
903 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
907 * @return VnfRecipe object or null if none found
909 public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) {
911 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
913 long startTime = System.currentTimeMillis ();
914 LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
916 Query query = getSession ().createQuery (hql.toString ());
917 query.setParameter (VF_MODULE_ID, vfModuleId);
918 query.setParameter (ACTION, action);
920 @SuppressWarnings("unchecked")
921 List <VnfRecipe> resultList = query.list ();
923 if (resultList.isEmpty ()) {
924 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
928 Collections.sort (resultList, new MavenLikeVersioningComparator ());
929 Collections.reverse (resultList);
931 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
932 return resultList.get (0);
935 public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
936 long startTime = System.currentTimeMillis();
937 LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
939 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
940 Query query = getSession().createQuery(hql);
941 query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
943 VfModule module = null;
945 module = (VfModule) query.uniqueResult();
946 } catch (org.hibernate.NonUniqueResultException nure) {
947 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
948 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
950 } catch (org.hibernate.HibernateException he) {
951 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
952 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
954 } catch (Exception e) {
955 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
956 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
959 if (module == null) {
960 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
962 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
967 public VfModule getVfModuleType(String type) {
968 long startTime = System.currentTimeMillis();
969 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
971 String hql = "FROM VfModule WHERE type = :type";
972 Query query = getSession().createQuery(hql);
973 query.setParameter("type", type);
975 @SuppressWarnings("unchecked")
976 List<VfModule> resultList = query.list();
977 if (resultList.isEmpty()) {
978 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
981 Collections.sort (resultList, new MavenLikeVersioningComparator ());
982 Collections.reverse (resultList);
984 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
985 return resultList.get (0);
988 public VfModule getVfModuleType(String type, String version) {
990 long startTime = System.currentTimeMillis();
991 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
993 String hql = "FROM VfModule WHERE type = :type and version = :version";
994 Query query = getSession().createQuery(hql);
995 query.setParameter ("type", type);
996 query.setParameter ("version", version);
997 VfModule module = null;
999 module = (VfModule) query.uniqueResult ();
1000 } catch (org.hibernate.NonUniqueResultException nure) {
1001 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: type='" + type + "', asdc_service_model_version='" + version + "'");
1002 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
1004 } catch (org.hibernate.HibernateException he) {
1005 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "'");
1006 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
1008 } catch (Exception e) {
1009 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "'");
1010 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
1013 if (module == null) {
1014 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1016 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1021 public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
1022 long startTime = System.currentTimeMillis();
1023 LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
1025 String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
1026 Query query = getSession().createQuery(hql);
1027 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1028 VnfResource vnfResource = null;
1030 vnfResource = (VnfResource) query.uniqueResult ();
1031 } catch (org.hibernate.NonUniqueResultException nure) {
1032 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1033 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
1035 } catch (org.hibernate.HibernateException he) {
1036 LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1037 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1039 } catch (Exception e) {
1040 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1041 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1044 if (vnfResource == null) {
1045 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1047 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1052 public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
1053 long startTime = System.currentTimeMillis();
1054 LOGGER.debug ("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
1056 String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
1057 Query query = getSession().createQuery(hql);
1058 query.setParameter ("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
1059 VnfResource vnfResource = null;
1061 vnfResource = (VnfResource) query.uniqueResult ();
1062 } catch (org.hibernate.NonUniqueResultException nure) {
1063 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
1064 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
1066 } catch (org.hibernate.HibernateException he) {
1067 LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "'");
1068 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1070 } catch (Exception e) {
1071 LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "'");
1072 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1075 if (vnfResource == null) {
1076 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1078 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1083 public VnfResource getVnfResourceByType(String vnfType) {
1084 return this.getVnfResource(vnfType);
1087 public VfModule getVfModuleByModelInvariantUuid(String vfModuleModelInvariantUuid) {
1088 long startTime = System.currentTimeMillis();
1089 LOGGER.debug ("Catalog database - get vfModuleTypeByUuid with uuid " + vfModuleModelInvariantUuid);
1091 String hql = "FROM VfModule WHERE vfModuleModelInvariantUuid = :vfModuleModelInvariantUuid ";
1092 Query query = getSession().createQuery(hql);
1093 query.setParameter ("vfModuleModelInvariantUuid", vfModuleModelInvariantUuid);
1094 VfModule module = null;
1096 module = (VfModule) query.uniqueResult ();
1097 } catch (org.hibernate.NonUniqueResultException nure) {
1098 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vfModuleModelInvariantUuid='" + vfModuleModelInvariantUuid + "'");
1099 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vfModuleModelInvariantUuid==" + vfModuleModelInvariantUuid);
1101 } catch (org.hibernate.HibernateException he) {
1102 LOGGER.debug("Hibernate Exception - while searching for: vfModuleModelInvariantUuid='" + vfModuleModelInvariantUuid + "'");
1103 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid);
1105 } catch (Exception e) {
1106 LOGGER.debug("Generic Exception - while searching for: vfModuleModelInvariantUuid='" + vfModuleModelInvariantUuid + "'");
1107 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid);
1110 if (module == null) {
1111 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1113 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1118 public VfModule getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
1119 long startTime = System.currentTimeMillis();
1120 LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
1122 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid ";
1123 Query query = getSession().createQuery(hql);
1124 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1125 VfModule module = null;
1127 module = (VfModule) query.uniqueResult ();
1128 } catch (org.hibernate.NonUniqueResultException nure) {
1129 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1130 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1132 } catch (org.hibernate.HibernateException he) {
1133 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1134 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1136 } catch (Exception e) {
1137 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1138 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1141 if (module == null) {
1142 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1144 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1149 public VfModule getVfModuleByType(String vfModuleType) {
1150 return this.getVfModuleType(vfModuleType);
1153 public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
1154 if (vnfResource == null)
1156 int vnfResourceId = vnfResource.getId();
1158 long startTime = System.currentTimeMillis();
1159 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
1161 return this.getVfModulesForVnfResource(vnfResourceId);
1165 public List<VfModule> getVfModulesForVnfResource(int vnfResourceId) {
1166 long startTime = System.currentTimeMillis();
1167 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceId: " + vnfResourceId);
1168 StringBuilder hql = new StringBuilder("FROM VfModule where vnfResourceId = :vnfResourceId");
1169 Query query = getSession().createQuery(hql.toString());
1170 query.setParameter("vnfResourceId", vnfResourceId);
1171 List<VfModule> resultList = null;
1173 resultList = query.list();
1174 if (resultList != null)
1175 LOGGER.debug("\tQuery found " + resultList.size() + " records.");
1177 LOGGER.debug("\tQuery found no records.");
1178 } catch (org.hibernate.HibernateException he) {
1179 LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceId='" + vnfResourceId + " " + he.getMessage());
1180 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceId=" + vnfResourceId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceId=" + vnfResourceId);
1181 } catch (Exception e) {
1182 LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceId='" + vnfResourceId + " " + e.getMessage());
1183 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceId=" + vnfResourceId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceId=" + vnfResourceId);
1185 if (resultList == null) {
1186 resultList = new ArrayList<VfModule>();
1188 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
1192 public Service getServiceByUuid (String serviceModelInvariantUuid) {
1194 long startTime = System.currentTimeMillis ();
1195 LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
1197 String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
1198 Query query = getSession ().createQuery (hql);
1199 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1201 Service service = null;
1203 service = (Service) query.uniqueResult ();
1204 } catch (org.hibernate.NonUniqueResultException nure) {
1205 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1206 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1208 } catch (org.hibernate.HibernateException he) {
1209 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "'");
1210 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1212 } catch (Exception e) {
1213 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1214 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1217 if (service == null) {
1218 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
1220 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
1226 public NetworkResource getNetworkResourceById(Integer id) {
1227 long startTime = System.currentTimeMillis ();
1228 LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
1230 String hql = "FROM NetworkResource WHERE id = :id";
1231 Query query = getSession ().createQuery (hql);
1232 query.setParameter ("id", id);
1234 NetworkResource networkResource = null;
1236 networkResource = (NetworkResource) query.uniqueResult ();
1237 } catch (org.hibernate.NonUniqueResultException nure) {
1238 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
1239 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
1241 } catch (org.hibernate.HibernateException he) {
1242 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "'");
1243 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
1245 } catch (Exception e) {
1246 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id);
1247 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
1251 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
1252 return networkResource;
1256 // 1702 API Spec - Query for all networks in a Service:
1257 public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
1258 long startTime = System.currentTimeMillis();
1259 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
1261 // This is a 2-step process (3 really) - 1) query ServiceToNetworks, 2) query NetworkResourceCustomization, 3) populate the networkType
1263 StringBuilder hql1 = new StringBuilder("FROM ServiceToNetworks WHERE serviceModelUuid = :serviceModelUuid");
1264 Query query = getSession().createQuery(hql1.toString());
1265 query.setParameter("serviceModelUuid", serviceModelUuid);
1266 @SuppressWarnings("unchecked")
1267 List<ServiceToNetworks> resultList1 = query.list();
1268 if (resultList1 == null || resultList1.size() < 1) {
1269 LOGGER.debug("Found no matches to the query - FROM ServiceToNetworks WHERE serviceModelUuid = " + serviceModelUuid);
1272 LOGGER.debug("Found " + resultList1.size() + " entries in ServiceToNetworks with smu=" + serviceModelUuid);
1274 ArrayList<NetworkResourceCustomization> masterList = new ArrayList<NetworkResourceCustomization>();
1275 for (ServiceToNetworks stn : resultList1) {
1276 String networkModelCustomizationUuid = stn.getNetworkModelCustomizationUuid();
1277 LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
1278 List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
1279 for (NetworkResourceCustomization nrc : resultSet) {
1280 masterList.add(nrc);
1283 LOGGER.debug("Returning " + masterList.size() + " NRC records");
1284 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
1288 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1289 long startTime = System.currentTimeMillis();
1290 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1292 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1293 Query query = getSession().createQuery(hql.toString());
1294 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1295 @SuppressWarnings("unchecked")
1296 List<Service> serviceList = query.list();
1298 if (serviceList.isEmpty()) {
1299 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
1303 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1304 Collections.reverse (serviceList);
1305 Service service = serviceList.get(0);
1307 String serviceNameVersionId = service.getServiceNameVersionId();
1308 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
1310 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
1311 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
1313 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1314 long startTime = System.currentTimeMillis();
1315 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1317 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1318 Query query = getSession().createQuery(hql.toString());
1319 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1320 query.setParameter("serviceModelVersion", serviceModelVersion);
1323 //can fix this later - no time - could do a unique query here - but this should work
1324 @SuppressWarnings("unchecked")
1325 List<Service> serviceList = query.list();
1327 if (serviceList.isEmpty()) {
1328 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
1332 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1333 Collections.reverse (serviceList);
1334 Service service = serviceList.get(0);
1336 String serviceNameVersionId = service.getServiceNameVersionId();
1338 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
1339 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
1342 public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
1343 long startTime = System.currentTimeMillis();
1344 LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
1346 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid");
1347 Query query = getSession().createQuery(hql.toString());
1348 query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
1350 @SuppressWarnings("unchecked")
1351 List<NetworkResourceCustomization> resultList = query.list();
1353 this.populateNetworkResourceType(resultList);
1355 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
1358 public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
1359 long startTime = System.currentTimeMillis();
1360 LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
1362 NetworkResource nr = this.getNetworkResource(networkType);
1364 return new ArrayList<NetworkResourceCustomization>();
1366 Integer networkResourceId = nr.getId();
1368 LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
1369 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE networkResourceId = :networkResourceId");
1371 Query query = getSession().createQuery(hql.toString());
1372 query.setParameter("networkResourceId", networkResourceId);
1374 @SuppressWarnings("unchecked")
1375 List<NetworkResourceCustomization> resultList = query.list();
1377 if (resultList != null && resultList.size() > 0) {
1378 LOGGER.debug("Found " + resultList.size() + " results");
1379 for (NetworkResourceCustomization nrc : resultList) {
1380 nrc.setNetworkType(networkType);
1381 nrc.setNetworkResource(nr);
1384 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
1389 //1702 API Spec cont'd - Query for all VnfResources in a Service:
1390 public List<VnfResource> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
1391 long startTime = System.currentTimeMillis();
1392 LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
1394 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceNameVersionId = :serviceModelUuid");
1395 Query query = getSession().createQuery(hql.toString());
1396 query.setParameter("serviceModelUuid", serviceModelUuid);
1397 @SuppressWarnings("unchecked")
1398 List<Service> serviceList = query.list();
1400 if (serviceList.isEmpty()) {
1404 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1405 Collections.reverse (serviceList);
1406 Service service = serviceList.get(0);
1408 String serviceModelInvariantUuid = service.getModelInvariantUUID();
1409 String serviceModelVersion = service.getVersion();
1411 return this.getAllVnfsByServiceModelInvariantUuid(serviceModelInvariantUuid, serviceModelVersion);
1414 public List<VnfResource> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1415 long startTime = System.currentTimeMillis();
1416 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1418 StringBuilder hqlService = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1419 Query query = getSession().createQuery(hqlService.toString());
1420 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1421 @SuppressWarnings("unchecked")
1422 List<Service> resultList = query.list();
1424 if (resultList.isEmpty()) {
1427 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1428 Collections.reverse (resultList);
1429 Service service = resultList.get(0);
1430 //now just call the method that takes the version - the service object will have the highest version
1431 return this.getAllVnfsByServiceModelInvariantUuid(serviceModelInvariantUuid, service.getVersion());
1433 public List<VnfResource> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1434 long startTime = System.currentTimeMillis();
1435 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1437 StringBuilder hql = new StringBuilder("FROM VnfResource WHERE serviceModelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1438 Query query = getSession().createQuery(hql.toString());
1439 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1440 query.setParameter("serviceModelVersion", serviceModelVersion);
1442 @SuppressWarnings("unchecked")
1443 List<VnfResource> resultList = query.list();
1445 if (resultList.isEmpty()) {
1448 // so we have a list of VnfResource objects - but we need to add each one's VfModule objects
1449 for (VnfResource vnfResource : resultList) {
1450 List<VfModule> vfModules = this.getVfModulesForVnfResource(vnfResource);
1451 if (vfModules != null && !vfModules.isEmpty()) {
1452 for (VfModule vfm : vfModules) {
1453 vnfResource.addVfModule(vfm);
1457 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
1461 public List<VnfResource> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
1462 long startTime = System.currentTimeMillis();
1463 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
1464 if (serviceVersion == null || serviceVersion.equals("")) {
1465 return this.getAllVnfsByServiceName(serviceName);
1468 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceName = :serviceName and version = :serviceVersion");
1469 Query query = getSession().createQuery(hql.toString());
1470 query.setParameter("serviceName", serviceName);
1471 query.setParameter("serviceVersion", serviceVersion);
1473 @SuppressWarnings("unchecked")
1474 List<Service> resultList = query.list();
1476 if (resultList.isEmpty()) {
1480 Service service = resultList.get(0);
1482 return this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1484 public List<VnfResource> getAllVnfsByServiceName(String serviceName) {
1485 long startTime = System.currentTimeMillis();
1486 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
1488 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceName = :serviceName");
1489 Query query = getSession().createQuery(hql.toString());
1490 query.setParameter("serviceName", serviceName);
1492 @SuppressWarnings("unchecked")
1493 List<Service> resultList = query.list();
1495 if (resultList.isEmpty()) {
1498 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1499 Collections.reverse (resultList);
1500 Service service = resultList.get(0);
1502 return this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1504 public List<VnfResource> getAllVnfsByVnfModelCustomizationUuid(String vnfModelCustomizationUuid) {
1505 long startTime = System.currentTimeMillis();
1506 LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid);
1508 StringBuilder hql = new StringBuilder("FROM VnfResource WHERE modelCustomizationUuid = :vnfModelCustomizationUuid");
1509 Query query = getSession().createQuery(hql.toString());
1510 query.setParameter("vnfModelCustomizationUuid", vnfModelCustomizationUuid);
1512 @SuppressWarnings("unchecked")
1513 List<VnfResource> resultList = query.list();
1515 if (resultList.isEmpty()) {
1516 LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
1519 // so we have a list of VnfResource objects - but we need to add each one's VfModule objects
1520 for (VnfResource vnfResource : resultList) {
1521 LOGGER.debug("Finding vfModules for vnfResource.id=" + vnfResource.getId());
1522 List<VfModule> vfModules = this.getVfModulesForVnfResource(vnfResource);
1523 if (vfModules != null && !vfModules.isEmpty()) {
1524 LOGGER.debug("\tFound " + vfModules.size() + " vf modules");
1525 for (VfModule vfm : vfModules) {
1526 vnfResource.addVfModule(vfm);
1530 LOGGER.debug("Returning " + resultList + " vnf modules");
1531 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
1535 //1702 API Spec cont'd - Query for all allotted resources in a Service
1537 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
1538 long startTime = System.currentTimeMillis();
1539 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
1541 // This is a 2-step process (3 really) - 1) query ServiceToAllottedResources, 2) query AllottedResourceCustomization
1543 StringBuilder hql1 = new StringBuilder("FROM ServiceToAllottedResources WHERE serviceModelUuid = :serviceModelUuid");
1544 Query query = getSession().createQuery(hql1.toString());
1545 query.setParameter("serviceModelUuid", serviceModelUuid);
1546 @SuppressWarnings("unchecked")
1547 List<ServiceToAllottedResources> resultList1 = query.list();
1548 if (resultList1 == null || resultList1.size() < 1) {
1549 LOGGER.debug("Found no matches to the query " + hql1.toString());
1552 LOGGER.debug("Found " + resultList1.size() + " entries in ServiceToAllottedResources with smu=" + serviceModelUuid);
1554 ArrayList<AllottedResourceCustomization> masterList = new ArrayList<AllottedResourceCustomization>();
1555 for (ServiceToAllottedResources star : resultList1) {
1556 String arModelCustomizationUuid = star.getArModelCustomizationUuid();
1557 LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
1558 List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
1559 for (AllottedResourceCustomization arc : resultSet) {
1560 masterList.add(arc);
1563 LOGGER.debug("Returning " + masterList.size() + " ARC records");
1564 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
1568 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1569 long startTime = System.currentTimeMillis();
1570 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1572 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1573 Query query = getSession().createQuery(hql.toString());
1574 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1575 @SuppressWarnings("unchecked")
1576 List<Service> serviceList = query.list();
1578 if (serviceList.isEmpty()) {
1579 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
1583 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1584 Collections.reverse (serviceList);
1585 Service service = serviceList.get(0);
1587 String serviceNameVersionId = service.getServiceNameVersionId();
1588 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
1590 // Service.serviceNameVersionId == ServiceToAllottedResources.serviceModelUuid
1591 return this.getAllAllottedResourcesByServiceModelUuid(serviceNameVersionId);
1594 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1595 long startTime = System.currentTimeMillis();
1596 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1598 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1599 Query query = getSession().createQuery(hql.toString());
1600 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1601 query.setParameter("serviceModelVersion", serviceModelVersion);
1604 //can fix this later - no time - could do a unique query here - but this should work
1605 @SuppressWarnings("unchecked")
1606 List<Service> serviceList = query.list();
1608 if (serviceList.isEmpty()) {
1609 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
1613 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1614 Collections.reverse (serviceList);
1615 Service service = serviceList.get(0);
1617 String serviceNameVersionId = service.getServiceNameVersionId();
1619 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
1620 return this.getAllAllottedResourcesByServiceModelUuid(serviceNameVersionId);
1623 public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
1624 long startTime = System.currentTimeMillis();
1625 LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
1627 StringBuilder hql = new StringBuilder("FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
1628 Query query = getSession().createQuery(hql.toString());
1629 query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
1631 @SuppressWarnings("unchecked")
1632 List<AllottedResourceCustomization> resultList = query.list();
1634 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
1638 //1702 API Spec cont'd - Query for all resources in a Service:
1639 public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
1640 long startTime = System.currentTimeMillis();
1641 LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
1643 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceNameVersionId = :serviceModelUuid");
1644 Query query = getSession().createQuery(hql.toString());
1645 query.setParameter("serviceModelUuid", serviceModelUuid);
1646 @SuppressWarnings("unchecked")
1647 List<Service> serviceList = query.list();
1649 if (serviceList.isEmpty()) {
1650 LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
1654 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1655 Collections.reverse (serviceList);
1656 Service service = serviceList.get(0);
1658 ServiceMacroHolder smh = new ServiceMacroHolder(service);
1659 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
1660 smh.setNetworkResourceCustomization(nrcList);
1661 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
1662 smh.setAllottedResourceCustomization(arcList);
1663 ArrayList<VnfResource> vnfList = (ArrayList<VnfResource>) this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1664 smh.setVnfResources(vnfList);
1666 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
1669 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1670 long startTime = System.currentTimeMillis();
1671 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1673 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1674 Query query = getSession().createQuery(hql.toString());
1675 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1676 @SuppressWarnings("unchecked")
1677 List<Service> serviceList = query.list();
1679 if (serviceList.isEmpty()) {
1680 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1684 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1685 Collections.reverse (serviceList);
1686 Service service = serviceList.get(0);
1688 ServiceMacroHolder smh = new ServiceMacroHolder(service);
1689 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getServiceNameVersionId());
1690 smh.setNetworkResourceCustomization(nrcList);
1691 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getServiceNameVersionId());
1692 smh.setAllottedResourceCustomization(arcList);
1693 ArrayList<VnfResource> vnfList = (ArrayList<VnfResource>) this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1694 smh.setVnfResources(vnfList);
1696 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
1700 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1701 long startTime = System.currentTimeMillis();
1702 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1704 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1705 Query query = getSession().createQuery(hql.toString());
1706 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1707 query.setParameter("serviceModelVersion", serviceModelVersion);
1708 //TODO make this a unique query
1709 @SuppressWarnings("unchecked")
1710 List<Service> serviceList = query.list();
1712 if (serviceList.isEmpty()) {
1713 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
1717 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1718 Collections.reverse (serviceList);
1719 Service service = serviceList.get(0);
1721 ServiceMacroHolder smh = new ServiceMacroHolder(service);
1722 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getServiceNameVersionId());
1723 smh.setNetworkResourceCustomization(nrcList);
1724 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getServiceNameVersionId());
1725 smh.setAllottedResourceCustomization(arcList);
1726 ArrayList<VnfResource> vnfList = (ArrayList<VnfResource>) this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1727 smh.setVnfResources(vnfList);
1729 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
1733 private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
1734 HashMap<Integer, NetworkResource> networkResources = new HashMap<Integer, NetworkResource>();
1736 for (NetworkResourceCustomization nrc : resultList) {
1737 Integer network_id = nrc.getNetworkResourceId();
1738 if (network_id == null) {
1739 nrc.setNetworkResource(null);
1740 nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
1743 if (networkResources.containsKey(network_id)) {
1744 nrc.setNetworkResource(networkResources.get(network_id));
1745 nrc.setNetworkType(networkResources.get(network_id).getNetworkType());
1747 NetworkResource nr = this.getNetworkResourceById(network_id);
1749 nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
1751 nrc.setNetworkType(nr.getNetworkType());
1752 nrc.setNetworkResource(nr);
1753 networkResources.put(network_id, nr);
1760 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
1761 * first query VF_MODULE table by type, and then use the ID to query
1762 * VNF_RECIPE by VF_MODULE_ID and ACTION
1765 * @parm vfModuleModelName
1767 * @return VnfRecipe object or null if none found
1769 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
1770 String vfModuleType = vnfType + "::" + vfModuleModelName;
1772 StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type ");
1774 long startTime = System.currentTimeMillis ();
1775 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
1777 Query query = getSession ().createQuery (hql.toString ());
1778 query.setParameter (TYPE, vfModuleType);
1780 @SuppressWarnings("unchecked")
1781 List <VfModule> resultList = query.list ();
1783 if (resultList.isEmpty ()) {
1784 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
1788 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1789 Collections.reverse (resultList);
1791 VfModule vfMod = resultList.get(0);
1793 int id = vfMod.getId();
1794 String vfModuleId = Integer.toString(id);
1796 StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
1798 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
1802 Query query1 = getSession ().createQuery (hql1.toString ());
1803 query1.setParameter (VF_MODULE_ID, vfModuleId);
1804 query1.setParameter (ACTION, action);
1806 @SuppressWarnings("unchecked")
1807 List <VnfRecipe> resultList1 = query1.list ();
1809 if (resultList1.isEmpty ()) {
1810 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
1814 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
1815 Collections.reverse (resultList1);
1817 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
1818 return resultList1.get (0);
1822 * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
1823 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
1825 * @param vnfModuleType
1826 * @parm modelCustomizationUuid
1827 * @param asdcServiceModelVersion
1828 * @param modelVersion
1830 * @return VfModule list
1832 public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
1835 if(modelCustomizationUuid != null){
1836 hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
1838 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
1840 query = getSession ().createQuery (hql.toString ());
1841 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1842 query.setParameter ("version", asdcServiceModelVersion);
1844 hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
1846 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
1848 query = getSession ().createQuery (hql.toString ());
1849 query.setParameter (TYPE, vfModuleType);
1850 query.setParameter ("version", asdcServiceModelVersion);
1851 query.setParameter ("modelVersion", modelVersion);
1854 @SuppressWarnings("unchecked")
1855 List <VfModule> resultList = query.list ();
1860 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
1861 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
1862 * first query VF_MODULE table by type, and then use the ID to query
1863 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
1866 * @parm vfModuleModelName
1868 * @return VnfRecipe object or null if none found
1870 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
1871 String vfModuleType = vnfType + "::" + vfModuleModelName;
1872 long startTime = System.currentTimeMillis ();
1873 List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
1875 if (resultList.isEmpty ()) {
1876 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
1880 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1881 Collections.reverse (resultList);
1883 VfModule vfMod = resultList.get(0);
1885 int id = vfMod.getId();
1886 String vfModuleId = Integer.toString(id);
1888 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
1890 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
1894 Query query1 = getSession ().createQuery (hql1.toString ());
1895 query1.setParameter (VF_MODULE_ID, vfModuleId);
1896 query1.setParameter (ACTION, action);
1898 @SuppressWarnings("unchecked")
1899 List <VnfComponentsRecipe> resultList1 = query1.list ();
1901 if (resultList1.isEmpty ()) {
1902 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
1906 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
1907 Collections.reverse (resultList1);
1909 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
1910 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
1911 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Different ORCHESTRATION URIs found for same VERSION and ID. No result returned.", "CatalogDB", "getVnfComponentsRecipe", null);
1914 return resultList1.get (0);
1918 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
1919 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
1920 * first query VF_MODULE table by type, and then use the ID to query
1921 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
1924 * @parm vfModuleModelName
1926 * @return VnfRecipe object or null if none found
1928 public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
1929 long startTime = System.currentTimeMillis ();
1931 if (resultList.isEmpty ()) {
1932 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
1936 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1937 Collections.reverse (resultList);
1939 VfModule vfMod = resultList.get(0);
1941 int id = vfMod.getId();
1942 String vfModuleId = Integer.toString(id);
1944 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
1946 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
1950 Query query1 = getSession ().createQuery (hql1.toString ());
1951 query1.setParameter (VF_MODULE_ID, vfModuleId);
1952 query1.setParameter (ACTION, action);
1954 @SuppressWarnings("unchecked")
1955 List <VnfComponentsRecipe> resultList1 = query1.list ();
1957 if (resultList1.isEmpty ()) {
1958 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
1962 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
1963 Collections.reverse (resultList1);
1965 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
1966 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
1967 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Different ORCHESTRATION URIs found for same VERSION and ID. No result returned.", "CatalogDB", "getVnfComponentsRecipe", null);
1970 return resultList1.get (0);
1975 * Return all VNF Resources in the Catalog DB
1977 * @return A list of VnfResource objects
1979 @SuppressWarnings("unchecked")
1980 public List <VnfResource> getAllVnfResources () {
1982 long startTime = System.currentTimeMillis ();
1983 LOGGER.debug ("Catalog database - get all VNF resources");
1985 String hql = "FROM VnfResource";
1986 Query query = getSession ().createQuery (hql);
1988 List <VnfResource> result = query.list ();
1989 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
1994 * Return VNF Resources in the Catalog DB that match a given VNF role
1996 * @return A list of VnfResource objects
1998 @SuppressWarnings("unchecked")
1999 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
2001 long startTime = System.currentTimeMillis ();
2002 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
2004 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
2005 Query query = getSession ().createQuery (hql);
2006 query.setParameter ("vnfRole", vnfRole);
2008 List <VnfResource> resources = query.list ();
2009 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
2014 * Return all Network Resources in the Catalog DB
2016 * @return A list of NetworkResource objects
2018 @SuppressWarnings("unchecked")
2019 public List <NetworkResource> getAllNetworkResources () {
2021 long startTime = System.currentTimeMillis ();
2022 LOGGER.debug ("Catalog database - get all network resources");
2024 String hql = "FROM NetworkResource";
2025 Query query = getSession ().createQuery (hql);
2027 List <NetworkResource> result = query.list ();
2028 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
2033 * Return all VF Modules in the Catalog DB
2035 * @return A list of VfModule objects
2037 @SuppressWarnings("unchecked")
2038 public List <VfModule> getAllVfModules () {
2040 long startTime = System.currentTimeMillis ();
2041 LOGGER.debug ("Catalog database - get all vf modules");
2043 String hql = "FROM VfModule";
2044 Query query = getSession ().createQuery (hql);
2046 List <VfModule> result = query.list ();
2047 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
2052 * Return all HeatEnvironment in the Catalog DB
2054 * @return A list of HeatEnvironment objects
2056 @SuppressWarnings("unchecked")
2057 public List <HeatEnvironment> getAllHeatEnvironment () {
2059 long startTime = System.currentTimeMillis ();
2060 LOGGER.debug ("Catalog database - get all Heat environments");
2062 String hql = "FROM HeatEnvironment";
2063 Query query = getSession ().createQuery (hql);
2065 List <HeatEnvironment> result = query.list ();
2066 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
2071 * Fetch the Environment by Environment ID - 1510
2073 public HeatEnvironment getHeatEnvironment (int id) {
2075 long startTime = System.currentTimeMillis ();
2076 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
2078 String hql = "FROM HeatEnvironment WHERE id = :idValue";
2080 LOGGER.debug ("getHeatEnvironment called with id=" + id);
2082 Query query = getSession ().createQuery (hql);
2083 query.setParameter ("idValue", id);
2085 @SuppressWarnings("unchecked")
2086 List <HeatEnvironment> resultList = query.list ();
2088 // See if something came back.
2089 if (resultList.isEmpty ()) {
2090 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
2093 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
2094 return resultList.get (0);
2098 * Fetch the nested templates - 1510
2101 public Map <String, Object> getNestedTemplates (int templateId) {
2102 Map <String, Object> nestedTemplates = null;
2103 long startTime = System.currentTimeMillis ();
2104 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
2106 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
2108 Query query = getSession ().createQuery (hql);
2109 query.setParameter ("parentIdValue", templateId);
2111 @SuppressWarnings("unchecked")
2112 List <HeatNestedTemplate> resultList = query.list ();
2113 // If nothing comes back, there are no nested templates
2114 if (resultList.isEmpty ()) {
2115 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
2116 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
2119 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
2120 nestedTemplates = new HashMap <String, Object> ();
2121 for (HeatNestedTemplate hnt : resultList) {
2122 LOGGER.debug ("Querying for " + hnt);
2123 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
2125 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
2128 String providerResourceFile = hnt.getProviderResourceFile ();
2129 String heatTemplateBody = ht.getTemplateBody ();
2130 if (providerResourceFile != null && heatTemplateBody != null) {
2131 nestedTemplates.put (providerResourceFile, heatTemplateBody);
2133 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
2136 // Make sure we're not returning an empty map - if so, just return null
2137 if (nestedTemplates.isEmpty ()) {
2138 LOGGER.debug ("nestedTemplates is empty - just return null");
2139 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
2142 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
2143 return nestedTemplates;
2147 * Fetch any files in the HEAT_FILES table 1510
2149 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
2150 Map <String, HeatFiles> heatFiles = null;
2152 long startTime = System.currentTimeMillis ();
2153 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
2154 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
2156 Query query = getSession ().createQuery (hql);
2157 query.setParameter ("vnfResourceIdValue", vnfResourceId);
2159 @SuppressWarnings("unchecked")
2160 List <HeatFiles> resultList = query.list ();
2161 // If nothing comes back, there are no heat files
2162 if (resultList.isEmpty ()) {
2163 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
2164 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
2167 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
2168 heatFiles = new HashMap <String, HeatFiles> ();
2169 for (HeatFiles hf : resultList) {
2170 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
2171 heatFiles.put (hf.getFileName (), hf);
2173 // Make sure we're not returning an empty map - if so, just return null
2174 if (heatFiles.isEmpty ()) {
2175 LOGGER.debug ("heatFiles is empty - just return null");
2176 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
2179 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
2183 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
2185 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
2186 Map <String, HeatFiles> heatFiles = null;
2188 long startTime = System.currentTimeMillis ();
2189 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
2190 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
2192 Query query = getSession ().createQuery (hql);
2193 query.setParameter ("vfModuleIdValue", vfModuleId);
2195 List<VfModuleToHeatFiles> mapList = query.list();
2196 if (mapList.isEmpty()) {
2197 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
2198 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
2201 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
2202 //TODO - convert this all with one join - brute force for now due to time
2203 heatFiles = new HashMap<String, HeatFiles>();
2204 for (VfModuleToHeatFiles vmthf : mapList) {
2205 int heatFilesId = vmthf.getHeatFilesId();
2206 hql = "FROM HeatFiles where id = :id_value";
2207 query = getSession().createQuery(hql);
2208 query.setParameter("id_value", heatFilesId);
2209 List<HeatFiles> fileList = query.list();
2210 if (fileList.isEmpty()) {
2211 // Should this throw an exception??
2212 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
2213 String errorString = "_ERROR|" + heatFilesId;
2214 // The receiving code needs to know to throw an exception for this - or ignore it.
2215 heatFiles.put(errorString, null);
2217 // Should only ever have 1 result - add it to our Map
2218 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
2219 for (HeatFiles hf : fileList) {
2220 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
2221 heatFiles.put(hf.getFileName(), hf);
2225 if (heatFiles.isEmpty()) {
2226 LOGGER.debug ("heatFiles is empty - just return null");
2227 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
2230 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
2237 * Get the heat template object based on asdc attributes
2239 * @param templateName The template name, generally the yaml filename. "example.yaml"
2240 * @param version The version as specified by ASDC. "1.1"
2241 * @param asdcResourceName The ASDC resource name provided in the ASDC artifact
2243 * @return The HeatTemplate
2245 public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
2247 long startTime = System.currentTimeMillis ();
2248 LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
2251 + " and ASDC resource name "
2252 + asdcResourceName);
2254 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
2255 Query query = getSession ().createQuery (hql);
2256 query.setParameter ("template_name", templateName);
2257 query.setParameter ("version", version);
2258 query.setParameter ("asdcResourceName", asdcResourceName);
2260 @SuppressWarnings("unchecked")
2261 List <HeatTemplate> resultList = query.list ();
2263 // See if something came back.
2264 if (resultList.isEmpty ()) {
2265 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
2268 // Name + Version is unique, so should only be one element
2269 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
2270 return resultList.get (0);
2274 * Save the Heat Template
2276 * @param heat The heat template
2277 * @param paramSet The list of heat template parameters
2279 public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
2281 long startTime = System.currentTimeMillis ();
2282 LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName());
2284 heat.setParameters(null);
2286 HeatTemplate heatTemp = this.getHeatTemplate (heat.getTemplateName (),
2288 heat.getAsdcResourceName ());
2289 if (heatTemp == null) {
2290 this.getSession ().save (heat);
2292 if (paramSet != null) {
2293 for (HeatTemplateParam param : paramSet) {
2294 param.setHeatTemplateId (heat.getId ());
2296 heat.setParameters (paramSet);
2297 this.getSession ().merge (heat);
2301 heat.setId(heatTemp.getId());
2304 heat.setParameters(paramSet);
2305 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
2310 * Retrieves a Heat environment from DB based on its unique key.
2312 * @param name the environment artifact name
2313 * @param version the environment resource version
2314 * @param asdcResourceName the environment resource name
2315 * @return the heat environment from DB or null if not found
2317 public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
2318 long startTime = System.currentTimeMillis ();
2319 LOGGER.debug ("Catalog database - get Heat environment with name " + name
2322 + " and ASDC resource name "
2323 + asdcResourceName);
2325 String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
2326 Query query = getSession ().createQuery (hql);
2327 query.setParameter ("name", name);
2328 query.setParameter ("version", version);
2329 query.setParameter ("asdcResourceName", asdcResourceName);
2330 HeatEnvironment env = null;
2332 env = (HeatEnvironment) query.uniqueResult ();
2333 } catch (org.hibernate.NonUniqueResultException nure) {
2334 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + name + "', version='" + version + "' and asdcResourceName=" + asdcResourceName);
2335 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for envName=" + name + " and version=" + version + " and asdcResourceName=" + asdcResourceName, "", "", MsoLogger.ErrorCode.DataError, "non unique result for envName=" + name);
2337 } catch (org.hibernate.HibernateException he) {
2338 LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
2339 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for envName=" + name + " and version=" + version + " and asdcResourceName=" + asdcResourceName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for envName=" + name);
2341 } catch (Exception e) {
2342 LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
2343 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for envName=" + name + " and version=" + version + " and asdcResourceName=" + asdcResourceName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for envName=" + name);
2347 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
2349 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
2355 * Save the HeatEnvironment
2357 * @param env The Environment
2359 public void saveHeatEnvironment (HeatEnvironment env) {
2360 long startTime = System.currentTimeMillis ();
2361 LOGGER.debug ("Catalog database - save Heat environment with name "
2362 + env.getEnvironment());
2364 HeatEnvironment dbEnv = getHeatEnvironment (env.getName (), env.getVersion (), env.getAsdcResourceName ());
2365 if (dbEnv == null) {
2367 this.getSession ().save (env);
2370 env.setId(dbEnv.getId());
2374 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
2379 * Save the heatTemplate
2381 * @param heat The heat template
2383 public void saveHeatTemplate (HeatTemplate heat) {
2384 long startTime = System.currentTimeMillis ();
2385 LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
2387 this.getSession ().update (heat);
2389 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
2393 public void saveHeatFile (HeatFiles heatFile) {
2394 long startTime = System.currentTimeMillis ();
2395 LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
2397 this.getSession ().save (heatFile);
2399 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
2403 public void saveVnfRecipe (VnfRecipe vnfRecipe) {
2404 long startTime = System.currentTimeMillis ();
2405 LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
2407 this.getSession ().save (vnfRecipe);
2409 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
2413 public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
2414 long startTime = System.currentTimeMillis ();
2415 LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
2417 this.getSession ().save (vnfComponentsRecipe);
2419 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
2424 public void saveOrUpdateVnfResource (VnfResource vnfResource) {
2425 long startTime = System.currentTimeMillis ();
2426 LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getVnfType ());
2429 if (vnfResource.getId() != 0) {
2430 this.getSession ().merge (vnfResource);
2432 this.getSession ().save (vnfResource);
2436 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
2440 public void saveAllottedResourceCustomization (AllottedResourceCustomization resourceCustomization) {
2441 long startTime = System.currentTimeMillis ();
2442 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + resourceCustomization.getModelName());
2444 List<AllottedResourceCustomization> allottedResourcesList = getAllAllottedResourcesByArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
2446 if(allottedResourcesList.size() == 0){
2447 this.getSession ().save(resourceCustomization);
2451 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
2455 public void saveNetworkResourceCustomization (NetworkResourceCustomization networkResourceCustomization) throws RecordNotFoundException {
2456 long startTime = System.currentTimeMillis ();
2457 LOGGER.debug ("Catalog database - save Network Resource Customization with Network Name " + networkResourceCustomization.getModelName());
2459 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
2460 List<NetworkResourceCustomization> networkResourceCustomizationList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
2461 // Do any matching customization records exist?
2462 if(networkResourceCustomizationList.size() == 0){
2464 // Retreive the record from the Network_Resource table associated to the Customization record based on ModelName
2465 NetworkResource networkResource = getNetworkResource(networkResourceCustomization.getModelName());
2467 if(networkResource == null){
2468 throw new RecordNotFoundException("No record found in NETWORK_RESOURCE table for model name " + networkResourceCustomization.getModelName());
2471 networkResourceCustomization.setNetworkResourceId(networkResource.getId());
2473 this.getSession ().save(networkResourceCustomization);
2478 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
2482 public void saveServiceToNetworks (ServiceToNetworks serviceToNetworks) {
2483 long startTime = System.currentTimeMillis ();
2484 LOGGER.debug ("Catalog database - save to ServiceToNetworks table with NetworkModelCustomizationUUID of " + serviceToNetworks.getNetworkModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToNetworks.getServiceModelUuid());
2486 this.getSession ().save(serviceToNetworks);
2489 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
2493 public void saveServiceToAllottedResources (ServiceToAllottedResources serviceToAllottedResources) {
2494 long startTime = System.currentTimeMillis ();
2495 LOGGER.debug ("Catalog database - save to serviceToAllottedResources table with ARModelCustomizationUUID of " + serviceToAllottedResources.getArModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToAllottedResources.getServiceModelUuid());
2497 this.getSession ().save(serviceToAllottedResources);
2500 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToAllottedResources", null);
2504 public void saveService (Service service) {
2505 long startTime = System.currentTimeMillis ();
2506 LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getServiceName()+"/"+service.getVersion()+"/"+service.getServiceNameVersionId());
2508 Service serviceInvariantDB = null;
2509 // Retrieve existing service record by nameVersionId
2510 Service serviceDB = this.getServiceByUUID(service.getServiceNameVersionId());
2511 if (serviceDB == null) {
2512 // Check to see if a record with the same modelInvariantId already exists. This tells us that a previous version exists and we can copy its recipe Record for the new service record.
2513 serviceInvariantDB = this.getServiceByInvariantUUID(service.getModelInvariantUUID());
2514 // Save the new Service record
2515 this.getSession ().save (service);
2518 if(serviceInvariantDB != null){ // existing modelInvariantId was found.
2519 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
2520 List<ServiceRecipe> serviceRecipes = getServiceRecipes(serviceInvariantDB.getId());
2522 if(serviceRecipes != null && serviceRecipes.size() > 0){
2523 for(ServiceRecipe serviceRecipe : serviceRecipes){
2524 if(serviceRecipe != null){
2525 // Fetch the service record that we just added. We do this so we can extract its Id column value, this will be the foreign key we use in the service recipe table.
2526 Service newService = this.getServiceByUUID(service.getServiceNameVersionId());
2527 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
2528 ServiceRecipe newServiceRecipe = new ServiceRecipe();
2529 newServiceRecipe.setAction(serviceRecipe.getAction());
2530 newServiceRecipe.setDescription(serviceRecipe.getDescription());
2531 newServiceRecipe.setOrchestrationUri(serviceRecipe.getOrchestrationUri());
2532 newServiceRecipe.setRecipeTimeout(serviceRecipe.getRecipeTimeout());
2533 newServiceRecipe.setServiceParamXSD(serviceRecipe.getServiceParamXSD());
2534 newServiceRecipe.setServiceId(newService.getId());
2535 newServiceRecipe.setVersion(serviceRecipe.getVersion());
2536 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
2537 this.getSession ().save (newServiceRecipe);
2545 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
2549 public void saveOrUpdateVfModule (VfModule vfModule) {
2550 long startTime = System.currentTimeMillis ();
2551 LOGGER.debug ("Catalog database - save VNF Module with VF Model Name " + vfModule.getModelName());
2554 if (vfModule.getId() != 0) {
2555 this.getSession ().merge (vfModule);
2557 this.getSession ().save (vfModule);
2561 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
2565 public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
2566 long startTime = System.currentTimeMillis ();
2567 LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
2568 + parentTemplateId +"-"+childTemplateId);
2570 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
2571 nestedTemplate.setParentTemplateId (parentTemplateId);
2572 nestedTemplate.setChildTemplateId (childTemplateId);
2574 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
2576 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
2580 public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
2581 long startTime = System.currentTimeMillis ();
2582 LOGGER.debug ("Catalog database - save nested Heat template with name "
2583 + childTemplate.getTemplateName ());
2586 saveHeatTemplate(childTemplate, childTemplate.getParameters());
2587 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
2588 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
2589 nestedTemplate.setParentTemplateId (parentTemplateId);
2590 nestedTemplate.setChildTemplateId (childTemplate.getId ());
2591 nestedTemplate.setProviderResourceFile (yamlFile);
2592 session.save (nestedTemplate);
2595 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
2599 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
2600 long startTime = System.currentTimeMillis ();
2601 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
2602 + " and vnfResourceID "
2604 // + " and ASDC resource name "
2609 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
2610 Query query = getSession ().createQuery (hql);
2611 query.setParameter ("fileName", fileName);
2612 query.setParameter ("vnfResourceId", vnfResourceId);
2613 query.setParameter ("asdcResourceName", asdcResourceName);
2614 query.setParameter ("version", version);
2616 @SuppressWarnings("unchecked")
2618 HeatFiles heatFilesResult = null;
2620 heatFilesResult = (HeatFiles) query.uniqueResult ();
2621 } catch (org.hibernate.NonUniqueResultException nure) {
2622 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
2623 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for fileName=" + fileName + " and vnfResourceId=" + vnfResourceId + " and asdcResourceName=" + asdcResourceName + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for fileName=" + fileName);
2624 heatFilesResult = null;
2625 } catch (org.hibernate.HibernateException he) {
2626 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
2627 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for fileName=" + fileName + " and vnfResourceId=" + vnfResourceId + " and asdcResourceName=" + asdcResourceName + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for fileName=" + fileName);
2628 heatFilesResult = null;
2629 } catch (Exception e) {
2630 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
2631 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for fileName=" + fileName + " and vnfResourceId=" + vnfResourceId + " and asdcResourceName=" + asdcResourceName + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for fileName=" + fileName);
2632 heatFilesResult = null;
2635 // See if something came back.
2636 if (heatFilesResult == null) {
2637 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
2640 // Name + Version is unique, so should only be one element
2641 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
2642 return heatFilesResult;
2645 public void saveHeatFiles (HeatFiles childFile) {
2646 long startTime = System.currentTimeMillis ();
2647 LOGGER.debug ("Catalog database - save Heat File with name "
2648 + childFile.getFileName());
2650 HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
2651 if (heatFiles == null) {
2653 // asdc_heat_files_save
2654 this.getSession ().save (childFile);
2657 /* replaced 'heatFiles' by 'childFile'
2658 Based on following comment:
2659 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
2661 childFile.setId(heatFiles.getId());
2665 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
2669 public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
2670 long startTime = System.currentTimeMillis ();
2671 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
2672 + childFile.getFileName());
2674 saveHeatFiles (childFile);
2675 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
2676 vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
2677 vfModuleToHeatFile.setHeatFilesId(childFile.getId());
2679 session.save (vfModuleToHeatFile);
2682 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
2688 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
2690 * @param networkType
2692 * @param serviceType
2693 * @return NetworkRecipe object or null if none found
2695 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
2697 long startTime = System.currentTimeMillis ();
2698 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
2701 + " and service type "
2706 if (serviceType == null) {
2707 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
2709 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
2711 Query query = getSession ().createQuery (hql);
2712 query.setParameter (NETWORK_TYPE, networkType);
2713 query.setParameter (ACTION, action);
2714 if (serviceType != null) {
2715 query.setParameter ("serviceType", serviceType);
2718 @SuppressWarnings("unchecked")
2719 List <NetworkRecipe> resultList = query.list ();
2721 if (resultList.isEmpty ()) {
2725 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2726 Collections.reverse (resultList);
2728 return resultList.get (0);
2730 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
2735 * Return a Network recipe that matches a given NETWORK_TYPE and ACTION
2737 * @param networkType
2739 * @return NetworkRecipe object or null if none found
2741 public NetworkRecipe getNetworkRecipe (String networkType, String action) {
2743 long startTime = System.currentTimeMillis ();
2744 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
2750 String hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action";
2752 Query query = getSession ().createQuery (hql);
2753 query.setParameter (NETWORK_TYPE, networkType);
2754 query.setParameter (ACTION, action);
2756 @SuppressWarnings("unchecked")
2757 List <NetworkRecipe> resultList = query.list ();
2759 if (resultList.isEmpty ()) {
2763 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2764 Collections.reverse (resultList);
2766 return resultList.get (0);
2768 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
2773 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
2775 * @param networkType
2777 * @param serviceType
2778 * @return NetworkRecipe object or null if none found
2780 public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
2782 long startTime = System.currentTimeMillis ();
2783 LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
2786 String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.id=c.networkResourceId and c.modelCustomizationUuid = :modelCustomizationUuid";
2787 Query query = getSession ().createQuery (hql);
2788 query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
2790 @SuppressWarnings("unchecked")
2791 List <NetworkResource> resultList = query.list ();
2793 if (resultList.isEmpty ()) {
2797 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2798 Collections.reverse (resultList);
2800 return resultList.get (0);
2802 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceBySvcNtwkRsrc", null);
2807 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
2811 * @param vnfComponentType
2813 * @param serviceType
2814 * @return VnfComponentsRecipe object or null if none found
2816 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
2817 String vnfComponentType,
2819 String serviceType) {
2821 long startTime = System.currentTimeMillis ();
2822 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
2823 + " and component type "
2827 + " and service type "
2832 if (serviceType == null) {
2833 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
2835 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
2837 Query query = getSession ().createQuery (hql);
2838 query.setParameter (VNF_TYPE, vnfType);
2839 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
2840 query.setParameter (ACTION, action);
2841 if (serviceType != null) {
2842 query.setParameter ("serviceType", serviceType);
2845 @SuppressWarnings("unchecked")
2846 List <VnfComponentsRecipe> resultList = query.list ();
2848 if (resultList.isEmpty ()) {
2851 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2852 Collections.reverse (resultList);
2854 return resultList.get (0);
2856 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
2861 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
2864 * @param vnfComponentType
2866 * @return VnfComponentsRecipe object or null if none found
2868 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleId (String vfModuleId,
2869 String vnfComponentType,
2872 long startTime = System.currentTimeMillis ();
2873 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleId " + vfModuleId
2874 + " and component type "
2881 hql = "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND vnfComponentType = :vnfComponentType AND action = :action ";
2883 Query query = getSession ().createQuery (hql);
2884 query.setParameter (VF_MODULE_ID, vfModuleId);
2885 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
2886 query.setParameter (ACTION, action);
2888 @SuppressWarnings("unchecked")
2889 List <VnfComponentsRecipe> resultList = query.list ();
2891 if (resultList.isEmpty ()) {
2894 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2895 Collections.reverse (resultList);
2897 return resultList.get (0);
2899 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleId", null);
2905 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
2906 long startTime = System.currentTimeMillis ();
2908 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
2910 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
2914 if (vnfComponentDb != null) {
2915 this.getSession ().merge (vnfComponent);
2917 this.getSession ().save (vnfComponent);
2921 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
2926 * Return a VfModule record that matches a given MODEL_NAME
2929 * @return VfModule object or null if none found
2931 public VfModule getVfModule (String modelName) {
2933 long startTime = System.currentTimeMillis ();
2934 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
2939 hql = "FROM VfModule WHERE modelName = :modelName";
2941 Query query = getSession ().createQuery (hql);
2942 query.setParameter (MODEL_NAME, modelName);
2944 @SuppressWarnings("unchecked")
2945 List <VfModule> resultList = query.list ();
2947 if (resultList.isEmpty ()) {
2950 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2951 Collections.reverse (resultList);
2953 return resultList.get (0);
2955 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
2960 * Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
2961 * Note: This method is not currently used but was retained in the event the
2962 * architecture moves back to a MODEL/MODEL_RECIPE structure.
2965 * @param modelVersionId
2967 * @return ModelRecipe object or null if none found
2969 public ModelRecipe getModelRecipe(String modelType,
2970 String modelVersionId,
2973 long startTime = System.currentTimeMillis();
2974 LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
2975 + " and modeVersionId=" + modelVersionId
2976 + " and action=" + action);
2980 // TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
2981 // the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
2982 // There seems to be 2 issues: formatting a hql query that executes successfully
2983 // and then being able to generate a result that will fit into the ModelRecipe class.
2985 // 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
2986 hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
2987 Query query = getSession().createQuery(hql);
2988 query.setParameter(MODEL_TYPE, modelType);
2989 query.setParameter(MODEL_VERSION_ID, modelVersionId);
2991 @SuppressWarnings("unchecked")
2992 List<Model> modelResultList = query.list();
2993 if (modelResultList.isEmpty()) {
2994 LOGGER.debug("Catalog database - modelResultList is null");
2997 Collections.sort(modelResultList, new MavenLikeVersioningComparator());
2998 Collections.reverse(modelResultList);
2999 LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
3001 // 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
3002 hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
3003 query = getSession().createQuery(hql);
3004 // The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
3005 query.setParameter(MODEL_ID, modelResultList.get(0).getId());
3006 query.setParameter(ACTION, action);
3008 @SuppressWarnings("unchecked")
3009 List<ModelRecipe> recipeResultList = query.list();
3010 if (recipeResultList.isEmpty()) {
3011 LOGGER.debug("Catalog database - recipeResultList is null");
3014 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
3015 Collections.reverse(recipeResultList);
3016 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
3018 return recipeResultList.get(0);
3020 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
3026 * Verify the health of the DB.
3028 * @return boolean value indicate whether DB is healthy
3030 public boolean healthCheck () {
3031 long startTime = System.currentTimeMillis ();
3032 Session session = this.getSession ();
3034 Query query = session.createSQLQuery (" show tables ");
3036 List<?> list = query.list();
3037 LOGGER.debug("healthCheck CatalogDB - Successful");