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.Collections;
25 import java.util.HashMap;
26 import java.util.List;
29 import org.openecomp.mso.db.catalog.beans.*;
30 import org.hibernate.HibernateException;
31 import org.hibernate.Query;
32 import org.hibernate.Session;
33 import org.hibernate.SessionFactory;
34 import org.hibernate.cfg.Configuration;
35 import org.hibernate.service.ServiceRegistry;
36 import org.hibernate.service.ServiceRegistryBuilder;
38 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
39 import org.openecomp.mso.logger.MessageEnum;
40 import org.openecomp.mso.logger.MsoLogger;
43 * This class encapsulates all of the objects that can be queried from a Catalog database.
44 * Clients must use these methods to retrieve catalog objects. The session is not
45 * available for clients to do their own direct queries to the database.
49 public class CatalogDatabase implements Closeable {
51 protected static final String NETWORK_TYPE = "networkType";
52 protected static final String ACTION = "action";
53 protected static final String VNF_TYPE = "vnfType";
54 protected static final String SERVICE_TYPE = "serviceType";
55 protected static final String VNF_COMPONENT_TYPE = "vnfComponentType";
56 protected static final String MODEL_NAME = "modelName";
57 protected static final String TYPE = "type";
58 protected static final String VF_MODULE_ID = "vfModuleId";
59 protected static boolean initialized = false;
60 protected static SessionFactory sessionFactory;
61 protected static ServiceRegistry serviceRegistry;
62 protected static final String SERVICE_NAME_VERSION_ID= "serviceNameVersionId";
64 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
66 protected Session session = null;
68 public CatalogDatabase () {
72 private Session getSession () {
74 LOGGER.debug ("Initializing Catalog Database in Hibernate");
75 Configuration configuration = null;
77 if ("MYSQL".equals (System.getProperty ("mso.db"))
78 || "MARIADB".equals (System.getProperty ("mso.db"))) {
79 configuration = new Configuration ().configure ("hibernate-catalog-mysql.cfg.xml");
81 serviceRegistry = new ServiceRegistryBuilder ().applySettings (configuration.getProperties ()).buildServiceRegistry ();
83 sessionFactory = configuration.buildSessionFactory (serviceRegistry);
85 LOGGER.error (MessageEnum.APIH_DB_ACCESS_EXC_REASON, "DB Connection not specified to the JVM,choose either:-Dmso.db=MARIADB, -Dmso.db=MYSQL or -Dmso.container=AJSC", "", "", MsoLogger.ErrorCode.DataError, "DB Connection not specified to the JVM,choose either:-Dmso.db=MARIADB, -Dmso.db=MYSQL or -Dmso.container=AJSC");
87 } catch (Exception e) {
88 LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG,
89 "Catalog DB initialization issue: " + e.getMessage (), "", "", MsoLogger.ErrorCode.DataError, "Catalog DB initialization issue: " + e.getMessage (), e);
94 LOGGER.debug ("Catalog Database initialization complete");
97 if (session == null) {
99 session = sessionFactory.openSession ();
100 session.beginTransaction ();
101 } catch (HibernateException he) {
102 LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Error creating Hibernate Session: " + he, "", "", MsoLogger.ErrorCode.DataError, "Error creating Hibernate Session: " + he);
111 * Close an open Catalog Database session.
112 * This method should always be called when a client is finished using a
113 * CatalogDatabase instance.
116 public void close () {
117 if (session != null) {
124 * Commits the current transaction on this session and starts a fresh one.
126 public void commit () {
127 getSession ().getTransaction ().commit ();
128 getSession ().beginTransaction ();
132 * Rolls back current transaction and starts a fresh one.
134 public void rollback () {
135 getSession ().getTransaction ().rollback ();
136 getSession ().beginTransaction ();
140 * Return all Heat Templates in the Catalog DB
142 * @return A list of HeatTemplate objects
144 @SuppressWarnings("unchecked")
145 public List <HeatTemplate> getAllHeatTemplates () {
146 long startTime = System.currentTimeMillis ();
147 LOGGER.debug ("Catalog database - get all Heat templates");
148 String hql = "FROM HeatTemplate";
149 Query query = getSession ().createQuery (hql);
151 List <HeatTemplate> result = query.list ();
152 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatTemplates", null);
157 * Fetch a specific Heat Template by ID.
160 * @return HeatTemplate object or null if none found
162 public HeatTemplate getHeatTemplate (int templateId) {
163 long startTime = System.currentTimeMillis ();
164 LOGGER.debug ("Catalog database - get Heat template with id " + templateId);
166 HeatTemplate template = (HeatTemplate) getSession ().get (HeatTemplate.class, templateId);
167 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
172 * Return the newest version of a specific Heat Template (queried by Name).
174 * @param templateName
175 * @return HeatTemplate object or null if none found
177 public HeatTemplate getHeatTemplate (String templateName) {
179 long startTime = System.currentTimeMillis ();
180 LOGGER.debug ("Catalog database - get Heat template with name " + templateName);
182 String hql = "FROM HeatTemplate WHERE templateName = :template_name";
183 Query query = getSession ().createQuery (hql);
184 query.setParameter ("template_name", templateName);
186 @SuppressWarnings("unchecked")
187 List <HeatTemplate> resultList = query.list ();
189 // See if something came back. Name is unique, so
190 if (resultList.isEmpty ()) {
191 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null);
194 Collections.sort (resultList, new MavenLikeVersioningComparator ());
195 Collections.reverse (resultList);
197 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
198 return resultList.get (0);
202 * Return a specific version of a specific Heat Template (queried by Name).
204 * @param templateName
206 * @return HeatTemplate object or null if none found
208 public HeatTemplate getHeatTemplate (String templateName, String version) {
210 long startTime = System.currentTimeMillis ();
211 LOGGER.debug ("Catalog database - get Heat template with name " + templateName
215 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version";
216 Query query = getSession ().createQuery (hql);
217 query.setParameter ("template_name", templateName);
218 query.setParameter ("version", version);
220 @SuppressWarnings("unchecked")
221 List <HeatTemplate> resultList = query.list ();
223 // See if something came back.
224 if (resultList.isEmpty ()) {
225 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found.", "CatalogDB", "getHeatTemplate", null);
228 // Name + Version is unique, so should only be one element
229 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
230 return resultList.get (0);
234 * Fetch a Service definition
236 public Service getService (String serviceName) {
238 long startTime = System.currentTimeMillis ();
239 LOGGER.debug ("Catalog database - get service with name " + serviceName);
241 String hql = "FROM Service WHERE serviceName = :service_name";
242 Query query = getSession ().createQuery (hql);
243 query.setParameter ("service_name", serviceName);
245 Service service = null;
247 service = (Service) query.uniqueResult ();
248 } catch (org.hibernate.NonUniqueResultException nure) {
249 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceName='" + serviceName + "'");
250 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceName=" + serviceName);
252 } catch (org.hibernate.HibernateException he) {
253 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceName + "'");
254 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceName=" + serviceName);
256 } catch (Exception e) {
257 LOGGER.debug("Generic Exception - while searching for: serviceName='" + serviceName);
258 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceName=" + serviceName);
261 if (service == null) {
262 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
264 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
271 * Fetch a Service definition
273 public Service getServiceByUUID (String serviceNameVersionId) {
275 long startTime = System.currentTimeMillis ();
276 LOGGER.debug ("Catalog database - get service with UUID " + serviceNameVersionId);
278 String hql = "FROM Service WHERE serviceNameVersionId = :service_id";
279 Query query = getSession ().createQuery (hql);
280 query.setParameter ("service_id", serviceNameVersionId);
282 Service service = null;
284 service = (Service) query.uniqueResult ();
285 } catch (org.hibernate.NonUniqueResultException nure) {
286 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceNameVersionId='" + serviceNameVersionId + "'");
287 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceNameVersionId=" + serviceNameVersionId);
289 } catch (org.hibernate.HibernateException he) {
290 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceNameVersionId + "'");
291 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceNameVersionId=" + serviceNameVersionId);
293 } catch (Exception e) {
294 LOGGER.debug("Generic Exception - while searching for: serviceName='" + serviceNameVersionId);
295 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceNameVersionId=" + serviceNameVersionId);
298 if (service == null) {
299 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
301 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
308 * Fetch the Common Service API definition using Http Method + serviceNameVersionId
310 public Service getService(HashMap<String, String> map, String httpMethod) {
312 String serviceNameVersionId = map.get("serviceNameVersionId");
314 String serviceId = "not_set";
315 String serviceVersion = "not_set";
317 if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
318 LOGGER.debug ("Catalog database - get serviceNameVersionId with id " + serviceNameVersionId);
320 String hql = "FROM Service WHERE service_name_version_id = :service_name_version_id and http_method = :http_method";
321 query = getSession ().createQuery (hql);
322 query.setParameter ("service_name_version_id", serviceNameVersionId);
324 serviceId = map.get("serviceId");
325 serviceVersion = map.get("serviceVersion");
326 LOGGER.debug ("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
328 String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
329 query = getSession ().createQuery (hql);
330 query.setParameter ("service_id", serviceId);
331 query.setParameter ("service_version", serviceVersion);
334 query.setParameter ("http_method", httpMethod);
336 long startTime = System.currentTimeMillis ();
337 Service service = null;
339 service = (Service) query.uniqueResult ();
340 } catch (org.hibernate.NonUniqueResultException nure) {
341 LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
342 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);
344 } catch (org.hibernate.HibernateException he) {
345 LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
346 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);
348 } catch (Exception e) {
349 LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
350 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);
353 if (service == null) {
354 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
356 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
362 * Return the newest version of a Service (queried by Name).
365 * @return Service object or null if none found
367 public Service getServiceByName (String serviceName) {
369 long startTime = System.currentTimeMillis ();
370 LOGGER.debug ("Catalog database - get service with name " + serviceName);
372 String hql = "FROM Service WHERE serviceName = :service_name";
373 Query query = getSession ().createQuery (hql);
374 query.setParameter ("service_name", serviceName);
376 @SuppressWarnings("unchecked")
377 List <Service> resultList = query.list ();
379 // See if something came back.
380 if (resultList.isEmpty ()) {
381 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
384 Collections.sort (resultList, new MavenLikeVersioningComparator ());
385 Collections.reverse (resultList);
387 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
388 return resultList.get (0);
392 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
393 * (MODEL_VERSION_ID) and ACTION
395 * @param modelVersionId
397 * @return ServiceRecipe object or null if none found
399 public ServiceRecipe getServiceRecipe(String modelVersionId,
402 long startTime = System.currentTimeMillis();
403 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
404 + " and action=" + action);
409 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceId, SR.action, SR.description, " +
410 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
411 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
412 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
413 "WHERE SR.serviceId = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
414 Query query = getSession().createQuery(hql);
415 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
416 query.setParameter(ACTION, action);
418 @SuppressWarnings("unchecked")
419 List<ServiceRecipe> recipeResultList = query.list();
420 if (recipeResultList.isEmpty()) {
421 LOGGER.debug("Catalog database - recipeResultList is null");
424 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
425 Collections.reverse(recipeResultList);
426 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
428 return recipeResultList.get(0);
430 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
435 * Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
439 * @return ServiceRecipe object or null if none found
441 public ServiceRecipe getServiceRecipe (int serviceId, String action) {
443 StringBuilder hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceId = :serviceId AND action = :action ");
446 long startTime = System.currentTimeMillis ();
447 LOGGER.debug ("Catalog database - get Service recipe with serviceId " + Integer.toString(serviceId)
452 Query query = getSession ().createQuery (hql.toString ());
453 query.setParameter ("serviceId", serviceId);
454 query.setParameter (ACTION, action);
456 @SuppressWarnings("unchecked")
457 List <ServiceRecipe> resultList = query.list ();
459 if (resultList.isEmpty ()) {
460 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
464 Collections.sort (resultList, new MavenLikeVersioningComparator ());
465 Collections.reverse (resultList);
467 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
468 return resultList.get (0);
473 * Return the VNF component data - queried by the VNFs ID and the component type.
477 * @return VnfComponent object or null if none found
479 public VnfComponent getVnfComponent (int vnfId, String type) {
481 long startTime = System.currentTimeMillis();
482 LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
484 String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
485 Query query = getSession ().createQuery (hql);
486 query.setParameter ("vnf_id", vnfId);
487 query.setParameter ("type", type);
489 VnfComponent result = null;
491 result = (VnfComponent) query.uniqueResult();
492 } catch (org.hibernate.NonUniqueResultException nure) {
493 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
494 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);
496 } catch (org.hibernate.HibernateException he) {
497 LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "'");
498 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);
500 } catch (Exception e) {
501 LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "'");
502 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);
506 //LOGGER.debug("Found VNF Component: " + result.toString());
507 if (result != null) {
508 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
510 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
516 * Return the newest version of a specific VNF resource (queried by Name).
519 * @return VnfResource object or null if none found
521 public VnfResource getVnfResource (String vnfType) {
523 long startTime = System.currentTimeMillis ();
524 LOGGER.debug ("Catalog database - get vnf resource with name " + vnfType);
526 String hql = "FROM VnfResource WHERE vnfType = :vnf_name";
527 Query query = getSession ().createQuery (hql);
528 query.setParameter ("vnf_name", vnfType);
530 @SuppressWarnings("unchecked")
531 List <VnfResource> resultList = query.list ();
533 // See if something came back. Name is unique, so
534 if (resultList.isEmpty ()) {
535 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
538 Collections.sort (resultList, new MavenLikeVersioningComparator ());
539 Collections.reverse (resultList);
541 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
542 return resultList.get (0);
546 * Return the newest version of a specific VNF resource (queried by Name).
550 * @return VnfResource object or null if none found
552 public VnfResource getVnfResource (String vnfType, String serviceVersion) {
554 long startTime = System.currentTimeMillis ();
555 LOGGER.debug ("Catalog database - get VNF resource with name " + vnfType);
557 String hql = "FROM VnfResource WHERE vnfType = :vnfName and version = :serviceVersion";
558 Query query = getSession ().createQuery (hql);
559 query.setParameter ("vnfName", vnfType);
560 query.setParameter ("serviceVersion", serviceVersion);
562 VnfResource resource = null;
564 resource = (VnfResource) query.uniqueResult ();
565 } catch (org.hibernate.NonUniqueResultException nure) {
566 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
567 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
569 } catch (org.hibernate.HibernateException he) {
570 LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "'");
571 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
573 } catch (Exception e) {
574 LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
575 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
578 if (resource == null) {
579 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
581 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
587 * Return the newest version of a specific VNF resource (queried by ID).
589 * @param id The vnf id
590 * @return VnfResource object or null if none found
592 public VnfResource getVnfResourceById (int id) {
594 long startTime = System.currentTimeMillis ();
595 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
597 String hql = "FROM VnfResource WHERE id = :id";
598 Query query = getSession ().createQuery (hql);
599 query.setParameter ("id", id);
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. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
609 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
610 return resultList.get (0);
614 * Return the newest version of a vfModule - 1607
617 public VfModule getVfModuleModelName (String modelName) {
619 long startTime = System.currentTimeMillis ();
620 LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName);
622 String hql = "FROM VfModule WHERE model_name = :model_name";
623 Query query = getSession ().createQuery (hql);
624 query.setParameter ("model_name", modelName);
626 @SuppressWarnings("unchecked")
627 List <VfModule> resultList = query.list ();
629 // See if something came back. Name is unique, so
630 if (resultList.isEmpty ()) {
631 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
634 Collections.sort (resultList, new MavenLikeVersioningComparator ());
635 Collections.reverse (resultList);
637 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
638 return resultList.get (0);
641 public VfModule getVfModuleModelName (String modelName, String model_version) {
643 long startTime = System.currentTimeMillis ();
644 LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
646 String hql = "FROM VfModule WHERE model_name = :model_name and version = :model_version";
647 Query query = getSession ().createQuery (hql);
648 query.setParameter ("model_name", modelName);
649 query.setParameter ("model_version", model_version);
651 VfModule module = null;
653 module = (VfModule) query.uniqueResult ();
654 } catch (org.hibernate.NonUniqueResultException nure) {
655 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 + "'");
656 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
658 } catch (org.hibernate.HibernateException he) {
659 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
660 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
662 } catch (Exception e) {
663 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
664 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
667 if (module == null) {
668 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
670 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
677 * Return the newest version of a specific Network resource (queried by Type).
680 * @return NetworkResource object or null if none found
682 public NetworkResource getNetworkResource (String networkType) {
684 long startTime = System.currentTimeMillis ();
685 LOGGER.debug ("Catalog database - get network resource with type " + networkType);
687 String hql = "FROM NetworkResource WHERE networkType = :network_type";
688 Query query = getSession ().createQuery (hql);
689 query.setParameter ("network_type", networkType);
691 @SuppressWarnings("unchecked")
692 List <NetworkResource> resultList = query.list ();
694 // See if something came back. Name is unique, so
695 if (resultList.isEmpty ()) {
696 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
700 Collections.sort (resultList, new MavenLikeVersioningComparator ());
701 Collections.reverse (resultList);
702 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
703 return resultList.get (0);
707 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
711 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
712 * @return VnfRecipe object or null if none found
714 public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) {
715 boolean withServiceType = false;
717 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
720 if (serviceType == null || serviceType.isEmpty ()) {
721 hql.append ("AND serviceType is NULL ");
723 hql.append ("AND serviceType = :serviceType ");
724 withServiceType = true;
727 long startTime = System.currentTimeMillis ();
728 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
731 + " and service type "
734 Query query = getSession ().createQuery (hql.toString ());
735 query.setParameter (VNF_TYPE, vnfType);
736 query.setParameter (ACTION, action);
737 if (withServiceType) {
738 query.setParameter (SERVICE_TYPE, serviceType);
741 @SuppressWarnings("unchecked")
742 List <VnfRecipe> resultList = query.list ();
744 if (resultList.isEmpty ()) {
745 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
749 Collections.sort (resultList, new MavenLikeVersioningComparator ());
750 Collections.reverse (resultList);
752 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
753 return resultList.get (0);
757 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
761 * @return VnfRecipe object or null if none found
763 public VnfRecipe getVnfRecipe (String vnfType, String action) {
764 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
766 long startTime = System.currentTimeMillis ();
767 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
771 Query query = getSession ().createQuery (hql.toString ());
772 query.setParameter (VNF_TYPE, vnfType);
773 query.setParameter (ACTION, action);
775 @SuppressWarnings("unchecked")
776 List <VnfRecipe> resultList = query.list ();
778 if (resultList.isEmpty ()) {
779 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
783 Collections.sort (resultList, new MavenLikeVersioningComparator ());
784 Collections.reverse (resultList);
786 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
787 return resultList.get (0);
791 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
795 * @return VnfRecipe object or null if none found
797 public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) {
799 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
801 long startTime = System.currentTimeMillis ();
802 LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
804 Query query = getSession ().createQuery (hql.toString ());
805 query.setParameter (VF_MODULE_ID, vfModuleId);
806 query.setParameter (ACTION, action);
808 @SuppressWarnings("unchecked")
809 List <VnfRecipe> resultList = query.list ();
811 if (resultList.isEmpty ()) {
812 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
816 Collections.sort (resultList, new MavenLikeVersioningComparator ());
817 Collections.reverse (resultList);
819 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
820 return resultList.get (0);
823 public VfModule getVfModuleType(String type) {
824 long startTime = System.currentTimeMillis();
825 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
827 String hql = "FROM VfModule WHERE type = :type";
828 Query query = getSession().createQuery(hql);
829 query.setParameter("type", type);
831 @SuppressWarnings("unchecked")
832 List<VfModule> resultList = query.list();
833 if (resultList.isEmpty()) {
834 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
837 Collections.sort (resultList, new MavenLikeVersioningComparator ());
838 Collections.reverse (resultList);
840 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
841 return resultList.get (0);
844 public VfModule getVfModuleType(String type, String version) {
846 long startTime = System.currentTimeMillis();
847 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
849 String hql = "FROM VfModule WHERE type = :type and version = :version";
850 Query query = getSession().createQuery(hql);
851 query.setParameter ("type", type);
852 query.setParameter ("version", version);
853 VfModule module = null;
855 module = (VfModule) query.uniqueResult ();
856 } catch (org.hibernate.NonUniqueResultException nure) {
857 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 + "'");
858 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
860 } catch (org.hibernate.HibernateException he) {
861 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "'");
862 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
864 } catch (Exception e) {
865 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "'");
866 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
869 if (module == null) {
870 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
872 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
879 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
880 * first query VF_MODULE table by type, and then use the ID to query
881 * VNF_RECIPE by VF_MODULE_ID and ACTION
884 * @parm vfModuleModelName
886 * @return VnfRecipe object or null if none found
888 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
889 String vfModuleType = vnfType + "::" + vfModuleModelName;
891 StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type ");
893 long startTime = System.currentTimeMillis ();
894 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
896 Query query = getSession ().createQuery (hql.toString ());
897 query.setParameter (TYPE, vfModuleType);
899 @SuppressWarnings("unchecked")
900 List <VfModule> resultList = query.list ();
902 if (resultList.isEmpty ()) {
903 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
907 Collections.sort (resultList, new MavenLikeVersioningComparator ());
908 Collections.reverse (resultList);
910 VfModule vfMod = resultList.get(0);
912 int id = vfMod.getId();
913 String vfModuleId = Integer.toString(id);
915 StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
917 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
921 Query query1 = getSession ().createQuery (hql1.toString ());
922 query1.setParameter (VF_MODULE_ID, vfModuleId);
923 query1.setParameter (ACTION, action);
925 @SuppressWarnings("unchecked")
926 List <VnfRecipe> resultList1 = query1.list ();
928 if (resultList1.isEmpty ()) {
929 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
933 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
934 Collections.reverse (resultList1);
936 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
937 return resultList1.get (0);
941 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
942 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
943 * first query VF_MODULE table by type, and then use the ID to query
944 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
947 * @parm vfModuleModelName
949 * @return VnfRecipe object or null if none found
951 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String asdcServiceModelVersion, String modelVersion, String action) {
952 String vfModuleType = vnfType + "::" + vfModuleModelName;
954 StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
956 long startTime = System.currentTimeMillis ();
957 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
959 Query query = getSession ().createQuery (hql.toString ());
960 query.setParameter (TYPE, vfModuleType);
961 query.setParameter ("version", asdcServiceModelVersion);
962 query.setParameter ("modelVersion", modelVersion);
964 @SuppressWarnings("unchecked")
965 List <VfModule> resultList = query.list ();
967 if (resultList.isEmpty ()) {
968 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
972 Collections.sort (resultList, new MavenLikeVersioningComparator ());
973 Collections.reverse (resultList);
975 VfModule vfMod = resultList.get(0);
977 int id = vfMod.getId();
978 String vfModuleId = Integer.toString(id);
980 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
982 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
986 Query query1 = getSession ().createQuery (hql1.toString ());
987 query1.setParameter (VF_MODULE_ID, vfModuleId);
988 query1.setParameter (ACTION, action);
990 @SuppressWarnings("unchecked")
991 List <VnfComponentsRecipe> resultList1 = query1.list ();
993 if (resultList1.isEmpty ()) {
994 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
998 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
999 Collections.reverse (resultList1);
1001 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
1002 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
1003 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);
1006 return resultList1.get (0);
1011 * Return all VNF Resources in the Catalog DB
1013 * @return A list of VnfResource objects
1015 @SuppressWarnings("unchecked")
1016 public List <VnfResource> getAllVnfResources () {
1018 long startTime = System.currentTimeMillis ();
1019 LOGGER.debug ("Catalog database - get all VNF resources");
1021 String hql = "FROM VnfResource";
1022 Query query = getSession ().createQuery (hql);
1024 List <VnfResource> result = query.list ();
1025 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
1030 * Return VNF Resources in the Catalog DB that match a given VNF role
1032 * @return A list of VnfResource objects
1034 @SuppressWarnings("unchecked")
1035 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
1037 long startTime = System.currentTimeMillis ();
1038 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
1040 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
1041 Query query = getSession ().createQuery (hql);
1042 query.setParameter ("vnfRole", vnfRole);
1044 List <VnfResource> resources = query.list ();
1045 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
1050 * Return all Network Resources in the Catalog DB
1052 * @return A list of NetworkResource objects
1054 @SuppressWarnings("unchecked")
1055 public List <NetworkResource> getAllNetworkResources () {
1057 long startTime = System.currentTimeMillis ();
1058 LOGGER.debug ("Catalog database - get all network resources");
1060 String hql = "FROM NetworkResource";
1061 Query query = getSession ().createQuery (hql);
1063 List <NetworkResource> result = query.list ();
1064 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
1069 * Return all VF Modules in the Catalog DB
1071 * @return A list of VfModule objects
1073 @SuppressWarnings("unchecked")
1074 public List <VfModule> getAllVfModules () {
1076 long startTime = System.currentTimeMillis ();
1077 LOGGER.debug ("Catalog database - get all vf modules");
1079 String hql = "FROM VfModule";
1080 Query query = getSession ().createQuery (hql);
1082 List <VfModule> result = query.list ();
1083 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
1088 * Return all HeatEnvironment in the Catalog DB
1090 * @return A list of HeatEnvironment objects
1092 @SuppressWarnings("unchecked")
1093 public List <HeatEnvironment> getAllHeatEnvironment () {
1095 long startTime = System.currentTimeMillis ();
1096 LOGGER.debug ("Catalog database - get all Heat environments");
1098 String hql = "FROM HeatEnvironment";
1099 Query query = getSession ().createQuery (hql);
1101 List <HeatEnvironment> result = query.list ();
1102 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
1107 * Fetch the Environment by Environment ID - 1510
1109 public HeatEnvironment getHeatEnvironment (int id) {
1111 long startTime = System.currentTimeMillis ();
1112 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
1114 String hql = "FROM HeatEnvironment WHERE id = :idValue";
1116 LOGGER.debug ("getHeatEnvironment called with id=" + id);
1118 Query query = getSession ().createQuery (hql);
1119 query.setParameter ("idValue", id);
1121 @SuppressWarnings("unchecked")
1122 List <HeatEnvironment> resultList = query.list ();
1124 // See if something came back.
1125 if (resultList.isEmpty ()) {
1126 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
1129 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
1130 return resultList.get (0);
1134 * Fetch the nested templates - 1510
1137 public Map <String, Object> getNestedTemplates (int templateId) {
1138 Map <String, Object> nestedTemplates = null;
1139 long startTime = System.currentTimeMillis ();
1140 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
1142 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
1144 Query query = getSession ().createQuery (hql);
1145 query.setParameter ("parentIdValue", templateId);
1147 @SuppressWarnings("unchecked")
1148 List <HeatNestedTemplate> resultList = query.list ();
1149 // If nothing comes back, there are no nested templates
1150 if (resultList.isEmpty ()) {
1151 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
1152 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
1155 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
1156 nestedTemplates = new HashMap <String, Object> ();
1157 for (HeatNestedTemplate hnt : resultList) {
1158 LOGGER.debug ("Querying for " + hnt);
1159 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
1161 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
1164 String providerResourceFile = hnt.getProviderResourceFile ();
1165 String heatTemplateBody = ht.getTemplateBody ();
1166 if (providerResourceFile != null && heatTemplateBody != null) {
1167 nestedTemplates.put (providerResourceFile, heatTemplateBody);
1169 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
1172 // Make sure we're not returning an empty map - if so, just return null
1173 if (nestedTemplates.isEmpty ()) {
1174 LOGGER.debug ("nestedTemplates is empty - just return null");
1175 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
1178 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
1179 return nestedTemplates;
1183 * Fetch any files in the HEAT_FILES table 1510
1185 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
1186 Map <String, HeatFiles> heatFiles = null;
1188 long startTime = System.currentTimeMillis ();
1189 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
1190 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
1192 Query query = getSession ().createQuery (hql);
1193 query.setParameter ("vnfResourceIdValue", vnfResourceId);
1195 @SuppressWarnings("unchecked")
1196 List <HeatFiles> resultList = query.list ();
1197 // If nothing comes back, there are no heat files
1198 if (resultList.isEmpty ()) {
1199 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
1200 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
1203 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
1204 heatFiles = new HashMap <String, HeatFiles> ();
1205 for (HeatFiles hf : resultList) {
1206 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
1207 heatFiles.put (hf.getFileName (), hf);
1209 // Make sure we're not returning an empty map - if so, just return null
1210 if (heatFiles.isEmpty ()) {
1211 LOGGER.debug ("heatFiles is empty - just return null");
1212 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
1215 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
1219 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
1221 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
1222 Map <String, HeatFiles> heatFiles = null;
1224 long startTime = System.currentTimeMillis ();
1225 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
1226 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
1228 Query query = getSession ().createQuery (hql);
1229 query.setParameter ("vfModuleIdValue", vfModuleId);
1231 List<VfModuleToHeatFiles> mapList = query.list();
1232 if (mapList.isEmpty()) {
1233 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
1234 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
1237 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
1238 //TODO - convert this all with one join - brute force for now due to time
1239 heatFiles = new HashMap<String, HeatFiles>();
1240 for (VfModuleToHeatFiles vmthf : mapList) {
1241 int heatFilesId = vmthf.getHeatFilesId();
1242 hql = "FROM HeatFiles where id = :id_value";
1243 query = getSession().createQuery(hql);
1244 query.setParameter("id_value", heatFilesId);
1245 List<HeatFiles> fileList = query.list();
1246 if (fileList.isEmpty()) {
1247 // Should this throw an exception??
1248 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
1249 String errorString = "_ERROR|" + heatFilesId;
1250 // The receiving code needs to know to throw an exception for this - or ignore it.
1251 heatFiles.put(errorString, null);
1253 // Should only ever have 1 result - add it to our Map
1254 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
1255 for (HeatFiles hf : fileList) {
1256 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
1257 heatFiles.put(hf.getFileName(), hf);
1261 if (heatFiles.isEmpty()) {
1262 LOGGER.debug ("heatFiles is empty - just return null");
1263 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
1266 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
1273 * Get the heat template object based on asdc attributes
1275 * @param templateName The template name, generally the yaml filename. "example.yaml"
1276 * @param version The version as specified by ASDC. "1.1"
1277 * @param asdcResourceName The ASDC resource name provided in the ASDC artifact
1279 * @return The HeatTemplate
1281 public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
1283 long startTime = System.currentTimeMillis ();
1284 LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
1287 + " and ASDC resource name "
1288 + asdcResourceName);
1290 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
1291 Query query = getSession ().createQuery (hql);
1292 query.setParameter ("template_name", templateName);
1293 query.setParameter ("version", version);
1294 query.setParameter ("asdcResourceName", asdcResourceName);
1296 @SuppressWarnings("unchecked")
1297 List <HeatTemplate> resultList = query.list ();
1299 // See if something came back.
1300 if (resultList.isEmpty ()) {
1301 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
1304 // Name + Version is unique, so should only be one element
1305 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
1306 return resultList.get (0);
1310 * Save the Heat Template
1312 * @param heat The heat template
1313 * @param paramSet The list of heat template parameters
1315 public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
1317 long startTime = System.currentTimeMillis ();
1318 LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName());
1320 heat.setParameters(null);
1322 HeatTemplate heatTemp = this.getHeatTemplate (heat.getTemplateName (),
1324 heat.getAsdcResourceName ());
1325 if (heatTemp == null) {
1326 this.getSession ().save (heat);
1328 if (paramSet != null) {
1329 for (HeatTemplateParam param : paramSet) {
1330 param.setHeatTemplateId (heat.getId ());
1332 heat.setParameters (paramSet);
1333 this.getSession ().merge (heat);
1337 heat.setId(heatTemp.getId());
1340 heat.setParameters(paramSet);
1341 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
1346 * Retrieves a Heat environment from DB based on its unique key.
1348 * @param name the environment artifact name
1349 * @param version the environment resource version
1350 * @param asdcResourceName the environment resource name
1351 * @return the heat environment from DB or null if not found
1353 public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
1354 long startTime = System.currentTimeMillis ();
1355 LOGGER.debug ("Catalog database - get Heat environment with name " + name
1358 + " and ASDC resource name "
1359 + asdcResourceName);
1361 String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
1362 Query query = getSession ().createQuery (hql);
1363 query.setParameter ("name", name);
1364 query.setParameter ("version", version);
1365 query.setParameter ("asdcResourceName", asdcResourceName);
1366 HeatEnvironment env = null;
1368 env = (HeatEnvironment) query.uniqueResult ();
1369 } catch (org.hibernate.NonUniqueResultException nure) {
1370 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);
1371 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);
1373 } catch (org.hibernate.HibernateException he) {
1374 LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
1375 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);
1377 } catch (Exception e) {
1378 LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
1379 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);
1383 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
1385 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
1391 * Save the HeatEnvironment
1393 * @param env The Environment
1395 public void saveHeatEnvironment (HeatEnvironment env) {
1396 long startTime = System.currentTimeMillis ();
1397 LOGGER.debug ("Catalog database - save Heat environment with name "
1398 + env.getEnvironment());
1400 HeatEnvironment dbEnv = getHeatEnvironment (env.getName (), env.getVersion (), env.getAsdcResourceName ());
1401 if (dbEnv == null) {
1403 this.getSession ().save (env);
1406 env.setId(dbEnv.getId());
1410 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
1415 * Save the heatTemplate
1417 * @param heat The heat template
1419 public void saveHeatTemplate (HeatTemplate heat) {
1420 long startTime = System.currentTimeMillis ();
1421 LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
1423 this.getSession ().update (heat);
1425 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
1429 public void saveHeatFile (HeatFiles heatFile) {
1430 long startTime = System.currentTimeMillis ();
1431 LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
1433 this.getSession ().save (heatFile);
1435 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
1439 public void saveVnfRecipe (VnfRecipe vnfRecipe) {
1440 long startTime = System.currentTimeMillis ();
1441 LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
1443 this.getSession ().save (vnfRecipe);
1445 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
1449 public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
1450 long startTime = System.currentTimeMillis ();
1451 LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
1453 this.getSession ().save (vnfComponentsRecipe);
1455 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
1460 public void saveOrUpdateVnfResource (VnfResource vnfResource) {
1461 long startTime = System.currentTimeMillis ();
1462 LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getVnfType ());
1465 if (vnfResource.getId() != 0) {
1466 this.getSession ().merge (vnfResource);
1468 this.getSession ().save (vnfResource);
1472 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
1476 public void saveService (Service service) {
1477 long startTime = System.currentTimeMillis ();
1478 LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getServiceName()+"/"+service.getServiceVersion()+"/"+service.getServiceNameVersionId());
1480 Service serviceDB = this.getServiceByUUID(service.getServiceNameVersionId());
1481 if (serviceDB == null) {
1482 this.getSession ().save (service);
1486 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
1490 public void saveOrUpdateVfModule (VfModule vfModule) {
1491 long startTime = System.currentTimeMillis ();
1492 LOGGER.debug ("Catalog database - save VNF Module with VF Model Name " + vfModule.getModelName());
1495 if (vfModule.getId() != 0) {
1496 this.getSession ().merge (vfModule);
1498 this.getSession ().save (vfModule);
1502 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
1506 public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
1507 long startTime = System.currentTimeMillis ();
1508 LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
1509 + parentTemplateId +"-"+childTemplateId);
1511 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
1512 nestedTemplate.setParentTemplateId (parentTemplateId);
1513 nestedTemplate.setChildTemplateId (childTemplateId);
1515 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
1517 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
1521 public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
1522 long startTime = System.currentTimeMillis ();
1523 LOGGER.debug ("Catalog database - save nested Heat template with name "
1524 + childTemplate.getTemplateName ());
1527 saveHeatTemplate(childTemplate, childTemplate.getParameters());
1528 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
1529 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
1530 nestedTemplate.setParentTemplateId (parentTemplateId);
1531 nestedTemplate.setChildTemplateId (childTemplate.getId ());
1532 nestedTemplate.setProviderResourceFile (yamlFile);
1533 session.save (nestedTemplate);
1536 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
1540 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
1541 long startTime = System.currentTimeMillis ();
1542 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
1543 + " and vnfResourceID "
1545 // + " and ASDC resource name "
1550 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
1551 Query query = getSession ().createQuery (hql);
1552 query.setParameter ("fileName", fileName);
1553 query.setParameter ("vnfResourceId", vnfResourceId);
1554 query.setParameter ("asdcResourceName", asdcResourceName);
1555 query.setParameter ("version", version);
1557 @SuppressWarnings("unchecked")
1559 HeatFiles heatFilesResult = null;
1561 heatFilesResult = (HeatFiles) query.uniqueResult ();
1562 } catch (org.hibernate.NonUniqueResultException nure) {
1563 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);
1564 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);
1565 heatFilesResult = null;
1566 } catch (org.hibernate.HibernateException he) {
1567 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
1568 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);
1569 heatFilesResult = null;
1570 } catch (Exception e) {
1571 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
1572 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);
1573 heatFilesResult = null;
1576 // See if something came back.
1577 if (heatFilesResult == null) {
1578 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
1581 // Name + Version is unique, so should only be one element
1582 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
1583 return heatFilesResult;
1586 public void saveHeatFiles (HeatFiles childFile) {
1587 long startTime = System.currentTimeMillis ();
1588 LOGGER.debug ("Catalog database - save Heat File with name "
1589 + childFile.getFileName());
1591 HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
1592 if (heatFiles == null) {
1594 // asdc_heat_files_save
1595 this.getSession ().save (childFile);
1598 /* replaced 'heatFiles' by 'childFile'
1599 Based on following comment:
1600 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
1602 childFile.setId(heatFiles.getId());
1606 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
1610 public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
1611 long startTime = System.currentTimeMillis ();
1612 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
1613 + childFile.getFileName());
1615 saveHeatFiles (childFile);
1616 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
1617 vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
1618 vfModuleToHeatFile.setHeatFilesId(childFile.getId());
1620 session.save (vfModuleToHeatFile);
1623 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
1629 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
1631 * @param networkType
1633 * @param serviceType
1634 * @return NetworkRecipe object or null if none found
1636 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
1638 long startTime = System.currentTimeMillis ();
1639 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
1642 + " and service type "
1647 if (serviceType == null) {
1648 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
1650 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
1652 Query query = getSession ().createQuery (hql);
1653 query.setParameter (NETWORK_TYPE, networkType);
1654 query.setParameter (ACTION, action);
1655 if (serviceType != null) {
1656 query.setParameter ("serviceType", serviceType);
1659 @SuppressWarnings("unchecked")
1660 List <NetworkRecipe> resultList = query.list ();
1662 if (resultList.isEmpty ()) {
1666 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1667 Collections.reverse (resultList);
1669 return resultList.get (0);
1671 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
1676 * Return a Network recipe that matches a given NETWORK_TYPE and ACTION
1678 * @param networkType
1680 * @return NetworkRecipe object or null if none found
1682 public NetworkRecipe getNetworkRecipe (String networkType, String action) {
1684 long startTime = System.currentTimeMillis ();
1685 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
1691 String hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action";
1693 Query query = getSession ().createQuery (hql);
1694 query.setParameter (NETWORK_TYPE, networkType);
1695 query.setParameter (ACTION, action);
1697 @SuppressWarnings("unchecked")
1698 List <NetworkRecipe> resultList = query.list ();
1700 if (resultList.isEmpty ()) {
1704 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1705 Collections.reverse (resultList);
1707 return resultList.get (0);
1709 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
1714 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
1718 * @param vnfComponentType
1720 * @param serviceType
1721 * @return VnfComponentsRecipe object or null if none found
1723 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
1724 String vnfComponentType,
1726 String serviceType) {
1728 long startTime = System.currentTimeMillis ();
1729 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
1730 + " and component type "
1734 + " and service type "
1739 if (serviceType == null) {
1740 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
1742 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
1744 Query query = getSession ().createQuery (hql);
1745 query.setParameter (VNF_TYPE, vnfType);
1746 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
1747 query.setParameter (ACTION, action);
1748 if (serviceType != null) {
1749 query.setParameter ("serviceType", serviceType);
1752 @SuppressWarnings("unchecked")
1753 List <VnfComponentsRecipe> resultList = query.list ();
1755 if (resultList.isEmpty ()) {
1758 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1759 Collections.reverse (resultList);
1761 return resultList.get (0);
1763 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
1768 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
1771 * @param vnfComponentType
1773 * @return VnfComponentsRecipe object or null if none found
1775 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleId (String vfModuleId,
1776 String vnfComponentType,
1779 long startTime = System.currentTimeMillis ();
1780 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleId " + vfModuleId
1781 + " and component type "
1788 hql = "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND vnfComponentType = :vnfComponentType AND action = :action ";
1790 Query query = getSession ().createQuery (hql);
1791 query.setParameter (VF_MODULE_ID, vfModuleId);
1792 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
1793 query.setParameter (ACTION, action);
1795 @SuppressWarnings("unchecked")
1796 List <VnfComponentsRecipe> resultList = query.list ();
1798 if (resultList.isEmpty ()) {
1801 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1802 Collections.reverse (resultList);
1804 return resultList.get (0);
1806 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleId", null);
1812 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
1813 long startTime = System.currentTimeMillis ();
1815 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
1817 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
1821 if (vnfComponentDb != null) {
1822 this.getSession ().merge (vnfComponent);
1824 this.getSession ().save (vnfComponent);
1828 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
1833 * Return a VfModule record that matches a given MODEL_NAME
1836 * @return VfModule object or null if none found
1838 public VfModule getVfModule (String modelName) {
1840 long startTime = System.currentTimeMillis ();
1841 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
1846 hql = "FROM VfModule WHERE modelName = :modelName";
1848 Query query = getSession ().createQuery (hql);
1849 query.setParameter (MODEL_NAME, modelName);
1851 @SuppressWarnings("unchecked")
1852 List <VfModule> resultList = query.list ();
1854 if (resultList.isEmpty ()) {
1857 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1858 Collections.reverse (resultList);
1860 return resultList.get (0);
1862 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
1868 * Verify the health of the DB.
1870 * @return boolean value indicate whether DB is healthy
1872 public boolean healthCheck () {
1873 long startTime = System.currentTimeMillis ();
1874 Session session = this.getSession ();
1876 Query query = session.createSQLQuery (" show tables ");
1878 List<?> list = query.list();
1879 LOGGER.debug("healthCheck CatalogDB - Successful");