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.NonUniqueResultException;
33 import org.hibernate.Query;
34 import org.hibernate.Session;
35 import org.hibernate.SessionFactory;
36 import org.hibernate.cfg.Configuration;
37 import org.hibernate.service.ServiceRegistry;
38 import org.hibernate.service.ServiceRegistryBuilder;
40 import org.openecomp.mso.db.HibernateUtils;
41 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
42 import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
43 import org.openecomp.mso.logger.MessageEnum;
44 import org.openecomp.mso.logger.MsoLogger;
47 * This class encapsulates all of the objects that can be queried from a Catalog database.
48 * Clients must use these methods to retrieve catalog objects. The session is not
49 * available for clients to do their own direct queries to the database.
53 public class CatalogDatabase implements Closeable {
55 protected static HibernateUtils hibernateUtils = new HibernateUtilsCatalogDb ();
57 private static final String NETWORK_TYPE = "networkType";
58 private static final String ACTION = "action";
59 private static final String VNF_TYPE = "vnfType";
60 private static final String SERVICE_TYPE = "serviceType";
61 private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
62 private static final String MODEL_ID = "modelId";
63 private static final String MODEL_NAME = "modelName";
64 private static final String TYPE = "type";
65 private static final String MODEL_TYPE = "modelType";
66 private static final String MODEL_VERSION_ID = "modelVersionId";
67 private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
68 private static final String VF_MODULE_ID = "vfModuleId";
69 private static final String SERVICE_NAME_VERSION_ID= "serviceNameVersionId";
71 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
73 protected Session session = null;
75 public CatalogDatabase () {
79 private Session getSession () {
81 if (session == null) {
83 session = hibernateUtils.getSessionFactory ().openSession ();
84 session.beginTransaction ();
85 } catch (HibernateException he) {
86 LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Error creating Hibernate Session: " + he, "", "", MsoLogger.ErrorCode.DataError, "Error creating Hibernate Session: " + he);
95 * Close an open Catalog Database session.
96 * This method should always be called when a client is finished using a
97 * CatalogDatabase instance.
100 public void close () {
101 if (session != null) {
108 * Commits the current transaction on this session and starts a fresh one.
110 public void commit () {
111 getSession ().getTransaction ().commit ();
112 getSession ().beginTransaction ();
116 * Rolls back current transaction and starts a fresh one.
118 public void rollback () {
119 getSession ().getTransaction ().rollback ();
120 getSession ().beginTransaction ();
124 * Return all Heat Templates in the Catalog DB
126 * @return A list of HeatTemplate objects
128 @SuppressWarnings("unchecked")
129 public List <HeatTemplate> getAllHeatTemplates () {
130 long startTime = System.currentTimeMillis ();
131 LOGGER.debug ("Catalog database - get all Heat templates");
132 String hql = "FROM HeatTemplate";
133 Query query = getSession ().createQuery (hql);
135 List <HeatTemplate> result = query.list ();
136 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatTemplates", null);
141 * Fetch a specific Heat Template by ID.
144 * @return HeatTemplate object or null if none found
146 public HeatTemplate getHeatTemplate (int templateId) {
147 long startTime = System.currentTimeMillis ();
148 LOGGER.debug ("Catalog database - get Heat template with id " + templateId);
150 HeatTemplate template = (HeatTemplate) getSession ().get (HeatTemplate.class, templateId);
151 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
156 * Return the newest version of a specific Heat Template (queried by Name).
158 * @param templateName
159 * @return HeatTemplate object or null if none found
161 public HeatTemplate getHeatTemplate (String templateName) {
163 long startTime = System.currentTimeMillis ();
164 LOGGER.debug ("Catalog database - get Heat template with name " + templateName);
166 String hql = "FROM HeatTemplate WHERE templateName = :template_name";
167 Query query = getSession ().createQuery (hql);
168 query.setParameter ("template_name", templateName);
170 @SuppressWarnings("unchecked")
171 List <HeatTemplate> resultList = query.list ();
173 // See if something came back. Name is unique, so
174 if (resultList.isEmpty ()) {
175 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null);
178 Collections.sort (resultList, new MavenLikeVersioningComparator ());
179 Collections.reverse (resultList);
181 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
182 return resultList.get (0);
186 * Return a specific version of a specific Heat Template (queried by Name).
188 * @param templateName
190 * @return HeatTemplate object or null if none found
192 public HeatTemplate getHeatTemplate (String templateName, String version) {
194 long startTime = System.currentTimeMillis ();
195 LOGGER.debug ("Catalog database - get Heat template with name " + templateName
199 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version";
200 Query query = getSession ().createQuery (hql);
201 query.setParameter ("template_name", templateName);
202 query.setParameter ("version", version);
204 @SuppressWarnings("unchecked")
205 List <HeatTemplate> resultList = query.list ();
207 // See if something came back.
208 if (resultList.isEmpty ()) {
209 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found.", "CatalogDB", "getHeatTemplate", null);
212 // Name + Version is unique, so should only be one element
213 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
214 return resultList.get (0);
218 * Fetch a Service definition by InvariantUUID
220 public Service getServiceByInvariantUUID (String modelInvariantUUID) {
222 long startTime = System.currentTimeMillis ();
223 LOGGER.debug ("Catalog database - get service with Invariant UUID " + modelInvariantUUID);
225 String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid";
226 Query query = getSession ().createQuery (hql);
227 query.setParameter ("model_invariant_uuid", modelInvariantUUID);
229 @SuppressWarnings("unchecked")
230 List <Service> resultList = query.list ();
232 // See if something came back.
233 if (resultList.isEmpty ()) {
234 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
237 Collections.sort (resultList, new MavenLikeVersioningComparator ());
238 Collections.reverse (resultList);
240 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
241 return resultList.get (0);
245 * Fetch a Service definition
247 public Service getService (String serviceName) {
249 long startTime = System.currentTimeMillis ();
250 LOGGER.debug ("Catalog database - get service with name " + serviceName);
252 String hql = "FROM Service WHERE serviceName = :service_name";
253 Query query = getSession ().createQuery (hql);
254 query.setParameter ("service_name", serviceName);
256 Service service = null;
258 service = (Service) query.uniqueResult ();
259 } catch (org.hibernate.NonUniqueResultException nure) {
260 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceName='" + serviceName + "'");
261 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceName=" + serviceName);
263 } catch (org.hibernate.HibernateException he) {
264 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceName + "'");
265 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceName=" + serviceName);
267 } catch (Exception e) {
268 LOGGER.debug("Generic Exception - while searching for: serviceName='" + serviceName);
269 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceName=" + serviceName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceName=" + serviceName);
272 if (service == null) {
273 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
275 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
282 * Fetch a Service definition
284 public Service getServiceByUUID (String serviceNameVersionId) {
286 long startTime = System.currentTimeMillis ();
287 LOGGER.debug ("Catalog database - get service with UUID " + serviceNameVersionId);
289 String hql = "FROM Service WHERE serviceNameVersionId = :service_id";
290 Query query = getSession ().createQuery (hql);
291 query.setParameter ("service_id", serviceNameVersionId);
293 Service service = null;
295 service = (Service) query.uniqueResult ();
296 } catch (org.hibernate.NonUniqueResultException nure) {
297 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceNameVersionId='" + serviceNameVersionId + "'");
298 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceNameVersionId=" + serviceNameVersionId);
300 } catch (org.hibernate.HibernateException he) {
301 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceNameVersionId + "'");
302 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceNameVersionId=" + serviceNameVersionId);
304 } catch (Exception e) {
305 LOGGER.debug("Generic Exception - while searching for: serviceName='" + serviceNameVersionId);
306 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceNameVersionId=" + serviceNameVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceNameVersionId=" + serviceNameVersionId);
309 if (service == null) {
310 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
312 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
319 * Fetch the Common Service API definition using Http Method + serviceNameVersionId
321 public Service getService(HashMap<String, String> map, String httpMethod) {
323 String serviceNameVersionId = map.get("serviceNameVersionId");
325 String serviceId = "not_set";
326 String serviceVersion = "not_set";
328 if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
329 LOGGER.debug ("Catalog database - get serviceNameVersionId with id " + serviceNameVersionId);
331 String hql = "FROM Service WHERE service_name_version_id = :service_name_version_id and http_method = :http_method";
332 query = getSession ().createQuery (hql);
333 query.setParameter ("service_name_version_id", serviceNameVersionId);
335 serviceId = map.get("serviceId");
336 serviceVersion = map.get("serviceVersion");
337 LOGGER.debug ("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
339 String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
340 query = getSession ().createQuery (hql);
341 query.setParameter ("service_id", serviceId);
342 query.setParameter ("service_version", serviceVersion);
345 query.setParameter ("http_method", httpMethod);
347 long startTime = System.currentTimeMillis ();
348 Service service = null;
350 service = (Service) query.uniqueResult ();
351 } catch (org.hibernate.NonUniqueResultException nure) {
352 LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
353 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);
355 } catch (org.hibernate.HibernateException he) {
356 LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
357 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);
359 } catch (Exception e) {
360 LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
361 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);
364 if (service == null) {
365 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
367 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
373 * Return the newest version of a Service (queried by Name).
376 * @return Service object or null if none found
378 public Service getServiceByName (String serviceName) {
380 long startTime = System.currentTimeMillis ();
381 LOGGER.debug ("Catalog database - get service with name " + serviceName);
383 String hql = "FROM Service WHERE serviceName = :service_name";
384 Query query = getSession ().createQuery (hql);
385 query.setParameter ("service_name", serviceName);
387 @SuppressWarnings("unchecked")
388 List <Service> resultList = query.list ();
390 // See if something came back.
391 if (resultList.isEmpty ()) {
392 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
395 Collections.sort (resultList, new MavenLikeVersioningComparator ());
396 Collections.reverse (resultList);
398 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
399 return resultList.get (0);
402 public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
403 long startTime = System.currentTimeMillis ();
404 LOGGER.debug ("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion);
406 String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR";
407 Query query = getSession ().createQuery (hql);
408 query.setParameter ("MODEL_INVARIANT_UUID", modelInvariantId);
409 query.setParameter("VERSION_STR", modelVersion);
411 Service result = null;
413 result = (Service) query.uniqueResult();
414 } catch (org.hibernate.NonUniqueResultException nure) {
415 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
416 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantId=" + modelInvariantId + " and modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId);
417 throw new Exception("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
419 // See if something came back.
421 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null);
425 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null);
430 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
431 * (MODEL_VERSION_ID) and ACTION
433 * @param modelVersionId
435 * @return ServiceRecipe object or null if none found
437 public ServiceRecipe getServiceRecipe(String modelVersionId,
440 long startTime = System.currentTimeMillis();
441 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
442 + " and action=" + action);
447 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceId, SR.action, SR.description, " +
448 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
449 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
450 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
451 "WHERE SR.serviceId = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
452 Query query = getSession().createQuery(hql);
453 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
454 query.setParameter(ACTION, action);
456 @SuppressWarnings("unchecked")
457 List<ServiceRecipe> recipeResultList = query.list();
458 if (recipeResultList.isEmpty()) {
459 LOGGER.debug("Catalog database - recipeResultList is null");
462 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
463 Collections.reverse(recipeResultList);
464 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
466 return recipeResultList.get(0);
468 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
473 * Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
477 * @return ServiceRecipe object or null if none found
479 public ServiceRecipe getServiceRecipe (int serviceId, String action) {
481 StringBuilder hql = null;
484 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceId = :serviceId");
486 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceId = :serviceId AND action = :action ");
489 long startTime = System.currentTimeMillis ();
490 LOGGER.debug ("Catalog database - get Service recipe with serviceId " + Integer.toString(serviceId)
495 Query query = getSession ().createQuery (hql.toString ());
496 query.setParameter ("serviceId", serviceId);
497 query.setParameter (ACTION, action);
499 query.setParameter (ACTION, action);
502 @SuppressWarnings("unchecked")
503 List <ServiceRecipe> resultList = query.list ();
505 if (resultList.isEmpty ()) {
506 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
510 Collections.sort (resultList, new MavenLikeVersioningComparator ());
511 Collections.reverse (resultList);
513 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
514 return resultList.get (0);
520 * @return ServiceRecipe object or null if none found. returns a newest version of Service recipe that matches a given serviceName, action and for the newest service version
522 public ServiceRecipe getServiceRecipeByServiceNameAndAction(String serviceName, String action) {
523 Service service = getServiceByName(serviceName);
524 if (service != null ){
525 return getServiceRecipe(service.getId(),action);
530 public List<ServiceRecipe> getServiceRecipes (int serviceId) {
532 StringBuilder hql = null;
534 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceId = :serviceId");
536 long startTime = System.currentTimeMillis ();
537 LOGGER.debug ("Catalog database - get Service recipe with serviceId " + Integer.toString(serviceId));
539 Query query = getSession ().createQuery (hql.toString ());
540 query.setParameter ("serviceId", serviceId);
542 @SuppressWarnings("unchecked")
543 List <ServiceRecipe> resultList = query.list ();
545 if (resultList.isEmpty ()) {
546 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null);
550 Collections.sort (resultList, new MavenLikeVersioningComparator ());
551 Collections.reverse (resultList);
553 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null);
558 * Return the VNF component data - queried by the VNFs ID and the component type.
562 * @return VnfComponent object or null if none found
564 public VnfComponent getVnfComponent (int vnfId, String type) {
566 long startTime = System.currentTimeMillis();
567 LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
569 String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
570 Query query = getSession ().createQuery (hql);
571 query.setParameter ("vnf_id", vnfId);
572 query.setParameter ("type", type);
574 VnfComponent result = null;
576 result = (VnfComponent) query.uniqueResult();
577 } catch (org.hibernate.NonUniqueResultException nure) {
578 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
579 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);
581 } catch (org.hibernate.HibernateException he) {
582 LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "'");
583 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);
585 } catch (Exception e) {
586 LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "'");
587 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);
591 //LOGGER.debug("Found VNF Component: " + result.toString());
592 if (result != null) {
593 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
595 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
601 * Return the newest version of a specific VNF resource (queried by Name).
604 * @return VnfResource object or null if none found
606 public VnfResource getVnfResource (String vnfType) {
608 long startTime = System.currentTimeMillis ();
609 LOGGER.debug ("Catalog database - get vnf resource with name " + vnfType);
611 String hql = "FROM VnfResource WHERE vnfType = :vnf_name";
612 Query query = getSession ().createQuery (hql);
613 query.setParameter ("vnf_name", vnfType);
615 @SuppressWarnings("unchecked")
616 List <VnfResource> resultList = query.list ();
618 // See if something came back. Name is unique, so
619 if (resultList.isEmpty ()) {
620 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
623 Collections.sort (resultList, new MavenLikeVersioningComparator ());
624 Collections.reverse (resultList);
626 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
627 return resultList.get (0);
631 * Return the newest version of a specific VNF resource (queried by Name).
635 * @return VnfResource object or null if none found
637 public VnfResource getVnfResource (String vnfType, String serviceVersion) {
639 long startTime = System.currentTimeMillis ();
640 LOGGER.debug ("Catalog database - get VNF resource with name " + vnfType);
642 String hql = "FROM VnfResource WHERE vnfType = :vnfName and version = :serviceVersion";
643 Query query = getSession ().createQuery (hql);
644 query.setParameter ("vnfName", vnfType);
645 query.setParameter ("serviceVersion", serviceVersion);
647 VnfResource resource = null;
649 resource = (VnfResource) query.uniqueResult ();
650 } catch (org.hibernate.NonUniqueResultException nure) {
651 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
652 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
654 } catch (org.hibernate.HibernateException he) {
655 LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "'");
656 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
658 } catch (Exception e) {
659 LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
660 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
663 if (resource == null) {
664 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
666 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
672 * Return the newest version of a specific VNF resource (queried by modelCustomizationId).
676 * @return VnfResource object or null if none found
678 public VnfResource getVnfResourceByModelCustomizationId (String modelCustomizationId, String serviceVersion) {
680 long startTime = System.currentTimeMillis ();
681 LOGGER.debug ("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
683 String hql = "FROM VnfResource WHERE modelCustomizationUuid = :modelCustomizationId and version = :serviceVersion";
684 Query query = getSession ().createQuery (hql);
685 query.setParameter ("modelCustomizationId", modelCustomizationId);
686 query.setParameter ("serviceVersion", serviceVersion);
688 VnfResource resource = null;
690 resource = (VnfResource) query.uniqueResult ();
691 } catch (org.hibernate.NonUniqueResultException nure) {
692 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "', serviceVersion='" + serviceVersion + "'");
693 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
695 } catch (org.hibernate.HibernateException he) {
696 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "', asdc_service_model_version='" + serviceVersion + "'");
697 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationId=" + modelCustomizationId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationId=" + modelCustomizationId);
699 } catch (Exception e) {
700 LOGGER.debug("Generic Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "', serviceVersion='" + serviceVersion + "'");
701 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationId=" + modelCustomizationId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationId=" + modelCustomizationId);
704 if (resource == null) {
705 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
707 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
713 * Return the newest version of a specific VNF resource (queried by ID).
715 * @param id The vnf id
716 * @return VnfResource object or null if none found
718 public VnfResource getVnfResourceById (int id) {
720 long startTime = System.currentTimeMillis ();
721 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
723 String hql = "FROM VnfResource WHERE id = :id";
724 Query query = getSession ().createQuery (hql);
725 query.setParameter ("id", id);
727 @SuppressWarnings("unchecked")
728 List <VnfResource> resultList = query.list ();
730 // See if something came back. Name is unique, so
731 if (resultList.isEmpty ()) {
732 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
735 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
736 return resultList.get (0);
740 * Return the newest version of a vfModule - 1607
743 public VfModule getVfModuleModelName (String modelName) {
745 long startTime = System.currentTimeMillis ();
746 LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName);
748 String hql = "FROM VfModule WHERE model_name = :model_name";
749 Query query = getSession ().createQuery (hql);
750 query.setParameter ("model_name", modelName);
752 @SuppressWarnings("unchecked")
753 List <VfModule> resultList = query.list ();
755 // See if something came back. Name is unique, so
756 if (resultList.isEmpty ()) {
757 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
760 Collections.sort (resultList, new MavenLikeVersioningComparator ());
761 Collections.reverse (resultList);
763 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
764 return resultList.get (0);
767 public VfModule getVfModuleModelName (String modelName, String model_version) {
769 long startTime = System.currentTimeMillis ();
770 LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
772 String hql = "FROM VfModule WHERE model_name = :model_name and version = :model_version";
773 Query query = getSession ().createQuery (hql);
774 query.setParameter ("model_name", modelName);
775 query.setParameter ("model_version", model_version);
777 VfModule module = null;
779 module = (VfModule) query.uniqueResult ();
780 } catch (org.hibernate.NonUniqueResultException nure) {
781 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 + "'");
782 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
784 } catch (org.hibernate.HibernateException he) {
785 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
786 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
788 } catch (Exception e) {
789 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
790 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
793 if (module == null) {
794 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
796 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
803 * Return the newest version of a specific Network resource (queried by Type).
806 * @return NetworkResource object or null if none found
808 public NetworkResource getNetworkResource (String networkType) {
810 long startTime = System.currentTimeMillis ();
811 LOGGER.debug ("Catalog database - get network resource with type " + networkType);
813 String hql = "FROM NetworkResource WHERE networkType = :network_type";
814 Query query = getSession ().createQuery (hql);
815 query.setParameter ("network_type", networkType);
817 @SuppressWarnings("unchecked")
818 List <NetworkResource> resultList = query.list ();
820 // See if something came back. Name is unique, so
821 if (resultList.isEmpty ()) {
822 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
826 Collections.sort (resultList, new MavenLikeVersioningComparator ());
827 Collections.reverse (resultList);
828 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
829 return resultList.get (0);
833 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
837 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
838 * @return VnfRecipe object or null if none found
840 public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) {
841 boolean withServiceType = false;
843 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
846 if (serviceType == null || serviceType.isEmpty ()) {
847 hql.append ("AND serviceType is NULL ");
849 hql.append ("AND serviceType = :serviceType ");
850 withServiceType = true;
853 long startTime = System.currentTimeMillis ();
854 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
857 + " and service type "
860 Query query = getSession ().createQuery (hql.toString ());
861 query.setParameter (VNF_TYPE, vnfType);
862 query.setParameter (ACTION, action);
863 if (withServiceType) {
864 query.setParameter (SERVICE_TYPE, serviceType);
867 @SuppressWarnings("unchecked")
868 List <VnfRecipe> resultList = query.list ();
870 if (resultList.isEmpty ()) {
871 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
875 Collections.sort (resultList, new MavenLikeVersioningComparator ());
876 Collections.reverse (resultList);
878 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
879 return resultList.get (0);
883 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
887 * @return VnfRecipe object or null if none found
889 public VnfRecipe getVnfRecipe (String vnfType, String action) {
890 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
892 long startTime = System.currentTimeMillis ();
893 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
897 Query query = getSession ().createQuery (hql.toString ());
898 query.setParameter (VNF_TYPE, vnfType);
899 query.setParameter (ACTION, action);
901 @SuppressWarnings("unchecked")
902 List <VnfRecipe> resultList = query.list ();
904 if (resultList.isEmpty ()) {
905 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
909 Collections.sort (resultList, new MavenLikeVersioningComparator ());
910 Collections.reverse (resultList);
912 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
913 return resultList.get (0);
917 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
921 * @return VnfRecipe object or null if none found
923 public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) {
925 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
927 long startTime = System.currentTimeMillis ();
928 LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
930 Query query = getSession ().createQuery (hql.toString ());
931 query.setParameter (VF_MODULE_ID, vfModuleId);
932 query.setParameter (ACTION, action);
934 @SuppressWarnings("unchecked")
935 List <VnfRecipe> resultList = query.list ();
937 if (resultList.isEmpty ()) {
938 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
942 Collections.sort (resultList, new MavenLikeVersioningComparator ());
943 Collections.reverse (resultList);
945 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
946 return resultList.get (0);
949 public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
950 long startTime = System.currentTimeMillis();
951 LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
953 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
954 Query query = getSession().createQuery(hql);
955 query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
957 VfModule module = null;
959 module = (VfModule) query.uniqueResult();
960 } catch (org.hibernate.NonUniqueResultException nure) {
961 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
962 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
964 } catch (org.hibernate.HibernateException he) {
965 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
966 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
968 } catch (Exception e) {
969 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
970 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
973 if (module == null) {
974 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
976 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
981 public VfModule getVfModuleType(String type) {
982 long startTime = System.currentTimeMillis();
983 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
985 String hql = "FROM VfModule WHERE type = :type";
986 Query query = getSession().createQuery(hql);
987 query.setParameter("type", type);
989 @SuppressWarnings("unchecked")
990 List<VfModule> resultList = query.list();
991 if (resultList.isEmpty()) {
992 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
995 Collections.sort (resultList, new MavenLikeVersioningComparator ());
996 Collections.reverse (resultList);
998 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
999 return resultList.get (0);
1002 public VfModule getVfModuleType(String type, String version) {
1004 long startTime = System.currentTimeMillis();
1005 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
1007 String hql = "FROM VfModule WHERE type = :type and version = :version";
1008 Query query = getSession().createQuery(hql);
1009 query.setParameter ("type", type);
1010 query.setParameter ("version", version);
1011 VfModule module = null;
1013 module = (VfModule) query.uniqueResult ();
1014 } catch (org.hibernate.NonUniqueResultException nure) {
1015 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 + "'");
1016 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
1018 } catch (org.hibernate.HibernateException he) {
1019 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "'");
1020 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
1022 } catch (Exception e) {
1023 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "'");
1024 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
1027 if (module == null) {
1028 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1030 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1035 public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
1036 long startTime = System.currentTimeMillis();
1037 LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
1039 String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
1040 Query query = getSession().createQuery(hql);
1041 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1042 VnfResource vnfResource = null;
1044 vnfResource = (VnfResource) query.uniqueResult ();
1045 } catch (org.hibernate.NonUniqueResultException nure) {
1046 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1047 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
1049 } catch (org.hibernate.HibernateException he) {
1050 LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1051 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1053 } catch (Exception e) {
1054 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1055 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1058 if (vnfResource == null) {
1059 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1061 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1066 public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
1067 long startTime = System.currentTimeMillis();
1068 LOGGER.debug ("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
1070 String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
1071 Query query = getSession().createQuery(hql);
1072 query.setParameter ("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
1073 VnfResource vnfResource = null;
1075 vnfResource = (VnfResource) query.uniqueResult ();
1076 } catch (org.hibernate.NonUniqueResultException nure) {
1077 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
1078 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
1080 } catch (org.hibernate.HibernateException he) {
1081 LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "'");
1082 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1084 } catch (Exception e) {
1085 LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "'");
1086 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1089 if (vnfResource == null) {
1090 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1092 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1097 public VnfResource getVnfResourceByType(String vnfType) {
1098 return this.getVnfResource(vnfType);
1101 public VfModule getVfModuleByModelInvariantUuid(String vfModuleModelInvariantUuid) {
1102 long startTime = System.currentTimeMillis();
1103 LOGGER.debug ("Catalog database - get vfModuleTypeByUuid with uuid " + vfModuleModelInvariantUuid);
1105 String hql = "FROM VfModule WHERE vfModuleModelInvariantUuid = :vfModuleModelInvariantUuid ";
1106 Query query = getSession().createQuery(hql);
1107 query.setParameter ("vfModuleModelInvariantUuid", vfModuleModelInvariantUuid);
1108 VfModule module = null;
1110 module = (VfModule) query.uniqueResult ();
1111 } catch (org.hibernate.NonUniqueResultException nure) {
1112 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vfModuleModelInvariantUuid='" + vfModuleModelInvariantUuid + "'");
1113 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vfModuleModelInvariantUuid==" + vfModuleModelInvariantUuid);
1115 } catch (org.hibernate.HibernateException he) {
1116 LOGGER.debug("Hibernate Exception - while searching for: vfModuleModelInvariantUuid='" + vfModuleModelInvariantUuid + "'");
1117 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid);
1119 } catch (Exception e) {
1120 LOGGER.debug("Generic Exception - while searching for: vfModuleModelInvariantUuid='" + vfModuleModelInvariantUuid + "'");
1121 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vfModuleModelInvariantUuid=" + vfModuleModelInvariantUuid);
1124 if (module == null) {
1125 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1127 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1132 public VfModule getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
1133 long startTime = System.currentTimeMillis();
1134 LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
1136 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid ";
1137 Query query = getSession().createQuery(hql);
1138 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1139 VfModule module = null;
1141 module = (VfModule) query.uniqueResult ();
1142 } catch (org.hibernate.NonUniqueResultException nure) {
1143 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1144 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1146 } catch (org.hibernate.HibernateException he) {
1147 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1148 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1150 } catch (Exception e) {
1151 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1152 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1155 if (module == null) {
1156 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1158 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1163 public VfModule getVfModuleByType(String vfModuleType) {
1164 return this.getVfModuleType(vfModuleType);
1167 public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
1168 if (vnfResource == null)
1170 int vnfResourceId = vnfResource.getId();
1172 long startTime = System.currentTimeMillis();
1173 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
1175 return this.getVfModulesForVnfResource(vnfResourceId);
1179 public List<VfModule> getVfModulesForVnfResource(int vnfResourceId) {
1180 long startTime = System.currentTimeMillis();
1181 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceId: " + vnfResourceId);
1182 StringBuilder hql = new StringBuilder("FROM VfModule where vnfResourceId = :vnfResourceId");
1183 Query query = getSession().createQuery(hql.toString());
1184 query.setParameter("vnfResourceId", vnfResourceId);
1185 List<VfModule> resultList = null;
1187 resultList = query.list();
1188 if (resultList != null)
1189 LOGGER.debug("\tQuery found " + resultList.size() + " records.");
1191 LOGGER.debug("\tQuery found no records.");
1192 } catch (org.hibernate.HibernateException he) {
1193 LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceId='" + vnfResourceId + " " + he.getMessage());
1194 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceId=" + vnfResourceId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceId=" + vnfResourceId);
1195 } catch (Exception e) {
1196 LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceId='" + vnfResourceId + " " + e.getMessage());
1197 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceId=" + vnfResourceId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceId=" + vnfResourceId);
1199 if (resultList == null) {
1200 resultList = new ArrayList<VfModule>();
1202 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
1206 public Service getServiceByUuid (String serviceModelInvariantUuid) {
1208 long startTime = System.currentTimeMillis ();
1209 LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
1211 String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
1212 Query query = getSession ().createQuery (hql);
1213 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1215 Service service = null;
1217 service = (Service) query.uniqueResult ();
1218 } catch (org.hibernate.NonUniqueResultException nure) {
1219 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1220 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1222 } catch (org.hibernate.HibernateException he) {
1223 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "'");
1224 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1226 } catch (Exception e) {
1227 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1228 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1231 if (service == null) {
1232 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
1234 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
1240 public NetworkResource getNetworkResourceById(Integer id) {
1241 long startTime = System.currentTimeMillis ();
1242 LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
1244 String hql = "FROM NetworkResource WHERE id = :id";
1245 Query query = getSession ().createQuery (hql);
1246 query.setParameter ("id", id);
1248 NetworkResource networkResource = null;
1250 networkResource = (NetworkResource) query.uniqueResult ();
1251 } catch (org.hibernate.NonUniqueResultException nure) {
1252 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
1253 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
1255 } catch (org.hibernate.HibernateException he) {
1256 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "'");
1257 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
1259 } catch (Exception e) {
1260 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id);
1261 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
1265 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
1266 return networkResource;
1270 // 1702 API Spec - Query for all networks in a Service:
1271 public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
1272 long startTime = System.currentTimeMillis();
1273 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
1275 // This is a 2-step process (3 really) - 1) query ServiceToNetworks, 2) query NetworkResourceCustomization, 3) populate the networkType
1277 StringBuilder hql1 = new StringBuilder("FROM ServiceToNetworks WHERE serviceModelUuid = :serviceModelUuid");
1278 Query query = getSession().createQuery(hql1.toString());
1279 query.setParameter("serviceModelUuid", serviceModelUuid);
1280 @SuppressWarnings("unchecked")
1281 List<ServiceToNetworks> resultList1 = query.list();
1282 if (resultList1 == null || resultList1.size() < 1) {
1283 LOGGER.debug("Found no matches to the query - FROM ServiceToNetworks WHERE serviceModelUuid = " + serviceModelUuid);
1284 return new ArrayList<NetworkResourceCustomization>();
1286 LOGGER.debug("Found " + resultList1.size() + " entries in ServiceToNetworks with smu=" + serviceModelUuid);
1288 ArrayList<NetworkResourceCustomization> masterList = new ArrayList<NetworkResourceCustomization>();
1289 for (ServiceToNetworks stn : resultList1) {
1290 String networkModelCustomizationUuid = stn.getNetworkModelCustomizationUuid();
1291 LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
1292 List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
1293 for (NetworkResourceCustomization nrc : resultSet) {
1294 masterList.add(nrc);
1297 LOGGER.debug("Returning " + masterList.size() + " NRC records");
1298 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
1302 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1303 long startTime = System.currentTimeMillis();
1304 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1306 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1307 Query query = getSession().createQuery(hql.toString());
1308 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1309 @SuppressWarnings("unchecked")
1310 List<Service> serviceList = query.list();
1312 if (serviceList.isEmpty()) {
1313 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
1314 return new ArrayList<NetworkResourceCustomization>();
1317 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1318 Collections.reverse (serviceList);
1319 Service service = serviceList.get(0);
1321 String serviceNameVersionId = service.getServiceNameVersionId();
1322 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
1324 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
1325 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
1327 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1328 long startTime = System.currentTimeMillis();
1329 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1331 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1332 Query query = getSession().createQuery(hql.toString());
1333 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1334 query.setParameter("serviceModelVersion", serviceModelVersion);
1337 //can fix this later - no time - could do a unique query here - but this should work
1338 @SuppressWarnings("unchecked")
1339 List<Service> serviceList = query.list();
1341 if (serviceList.isEmpty()) {
1342 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
1343 return new ArrayList<NetworkResourceCustomization>();
1346 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1347 Collections.reverse (serviceList);
1348 Service service = serviceList.get(0);
1350 String serviceNameVersionId = service.getServiceNameVersionId();
1352 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
1353 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
1356 public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
1357 long startTime = System.currentTimeMillis();
1358 LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
1360 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid");
1361 Query query = getSession().createQuery(hql.toString());
1362 query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
1364 @SuppressWarnings("unchecked")
1365 List<NetworkResourceCustomization> resultList = query.list();
1367 this.populateNetworkResourceType(resultList);
1369 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
1372 public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
1373 long startTime = System.currentTimeMillis();
1374 LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
1376 NetworkResource nr = this.getNetworkResource(networkType);
1378 return new ArrayList<NetworkResourceCustomization>();
1380 Integer networkResourceId = nr.getId();
1382 LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
1383 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE networkResourceId = :networkResourceId");
1385 Query query = getSession().createQuery(hql.toString());
1386 query.setParameter("networkResourceId", networkResourceId);
1388 @SuppressWarnings("unchecked")
1389 List<NetworkResourceCustomization> resultList = query.list();
1391 if (resultList != null && resultList.size() > 0) {
1392 LOGGER.debug("Found " + resultList.size() + " results");
1393 for (NetworkResourceCustomization nrc : resultList) {
1394 nrc.setNetworkType(networkType);
1395 nrc.setNetworkResource(nr);
1398 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
1403 //1702 API Spec cont'd - Query for all VnfResources in a Service:
1404 public List<VnfResource> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
1405 long startTime = System.currentTimeMillis();
1406 LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
1408 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceNameVersionId = :serviceModelUuid");
1409 Query query = getSession().createQuery(hql.toString());
1410 query.setParameter("serviceModelUuid", serviceModelUuid);
1411 @SuppressWarnings("unchecked")
1412 List<Service> serviceList = query.list();
1414 if (serviceList.isEmpty()) {
1415 return new ArrayList<VnfResource>();
1418 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1419 Collections.reverse (serviceList);
1420 Service service = serviceList.get(0);
1422 String serviceModelInvariantUuid = service.getModelInvariantUUID();
1423 String serviceModelVersion = service.getVersion();
1425 return this.getAllVnfsByServiceModelInvariantUuid(serviceModelInvariantUuid, serviceModelVersion);
1428 public List<VnfResource> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1429 long startTime = System.currentTimeMillis();
1430 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1432 StringBuilder hqlService = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1433 Query query = getSession().createQuery(hqlService.toString());
1434 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1435 @SuppressWarnings("unchecked")
1436 List<Service> resultList = query.list();
1438 if (resultList.isEmpty()) {
1439 return new ArrayList<VnfResource>();
1441 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1442 Collections.reverse (resultList);
1443 Service service = resultList.get(0);
1444 //now just call the method that takes the version - the service object will have the highest version
1445 return this.getAllVnfsByServiceModelInvariantUuid(serviceModelInvariantUuid, service.getVersion());
1447 public List<VnfResource> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1448 long startTime = System.currentTimeMillis();
1449 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1451 StringBuilder hql = new StringBuilder("FROM VnfResource WHERE serviceModelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1452 Query query = getSession().createQuery(hql.toString());
1453 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1454 query.setParameter("serviceModelVersion", serviceModelVersion);
1456 @SuppressWarnings("unchecked")
1457 List<VnfResource> resultList = query.list();
1459 if (resultList.isEmpty()) {
1460 return new ArrayList<VnfResource>();
1462 // so we have a list of VnfResource objects - but we need to add each one's VfModule objects
1463 for (VnfResource vnfResource : resultList) {
1464 List<VfModule> vfModules = this.getVfModulesForVnfResource(vnfResource);
1465 if (vfModules != null && !vfModules.isEmpty()) {
1466 for (VfModule vfm : vfModules) {
1467 vnfResource.addVfModule(vfm);
1471 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
1475 public List<VnfResource> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
1476 long startTime = System.currentTimeMillis();
1477 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
1478 if (serviceVersion == null || serviceVersion.equals("")) {
1479 return this.getAllVnfsByServiceName(serviceName);
1482 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceName = :serviceName and version = :serviceVersion");
1483 Query query = getSession().createQuery(hql.toString());
1484 query.setParameter("serviceName", serviceName);
1485 query.setParameter("serviceVersion", serviceVersion);
1487 @SuppressWarnings("unchecked")
1488 List<Service> resultList = query.list();
1490 if (resultList.isEmpty()) {
1494 Service service = resultList.get(0);
1496 return this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1498 public List<VnfResource> getAllVnfsByServiceName(String serviceName) {
1499 long startTime = System.currentTimeMillis();
1500 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
1502 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceName = :serviceName");
1503 Query query = getSession().createQuery(hql.toString());
1504 query.setParameter("serviceName", serviceName);
1506 @SuppressWarnings("unchecked")
1507 List<Service> resultList = query.list();
1509 if (resultList.isEmpty()) {
1512 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1513 Collections.reverse (resultList);
1514 Service service = resultList.get(0);
1516 return this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1518 public List<VnfResource> getAllVnfsByVnfModelCustomizationUuid(String vnfModelCustomizationUuid) {
1519 long startTime = System.currentTimeMillis();
1520 LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid);
1522 StringBuilder hql = new StringBuilder("FROM VnfResource WHERE modelCustomizationUuid = :vnfModelCustomizationUuid");
1523 Query query = getSession().createQuery(hql.toString());
1524 query.setParameter("vnfModelCustomizationUuid", vnfModelCustomizationUuid);
1526 @SuppressWarnings("unchecked")
1527 List<VnfResource> resultList = query.list();
1529 if (resultList.isEmpty()) {
1530 LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
1533 // so we have a list of VnfResource objects - but we need to add each one's VfModule objects
1534 for (VnfResource vnfResource : resultList) {
1535 LOGGER.debug("Finding vfModules for vnfResource.id=" + vnfResource.getId());
1536 List<VfModule> vfModules = this.getVfModulesForVnfResource(vnfResource);
1537 if (vfModules != null && !vfModules.isEmpty()) {
1538 LOGGER.debug("\tFound " + vfModules.size() + " vf modules");
1539 for (VfModule vfm : vfModules) {
1540 vnfResource.addVfModule(vfm);
1544 LOGGER.debug("Returning " + resultList + " vnf modules");
1545 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
1549 //1702 API Spec cont'd - Query for all allotted resources in a Service
1551 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
1552 long startTime = System.currentTimeMillis();
1553 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
1555 // This is a 2-step process (3 really) - 1) query ServiceToAllottedResources, 2) query AllottedResourceCustomization
1557 StringBuilder hql1 = new StringBuilder("FROM ServiceToAllottedResources WHERE serviceModelUuid = :serviceModelUuid");
1558 Query query = getSession().createQuery(hql1.toString());
1559 query.setParameter("serviceModelUuid", serviceModelUuid);
1560 @SuppressWarnings("unchecked")
1561 List<ServiceToAllottedResources> resultList1 = query.list();
1562 if (resultList1 == null || resultList1.size() < 1) {
1563 LOGGER.debug("Found no matches to the query " + hql1.toString());
1564 return new ArrayList<AllottedResourceCustomization>();
1566 LOGGER.debug("Found " + resultList1.size() + " entries in ServiceToAllottedResources with smu=" + serviceModelUuid);
1568 ArrayList<AllottedResourceCustomization> masterList = new ArrayList<AllottedResourceCustomization>();
1569 for (ServiceToAllottedResources star : resultList1) {
1570 String arModelCustomizationUuid = star.getArModelCustomizationUuid();
1571 LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
1572 List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
1573 for (AllottedResourceCustomization arc : resultSet) {
1574 masterList.add(arc);
1577 LOGGER.debug("Returning " + masterList.size() + " ARC records");
1578 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
1582 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1583 long startTime = System.currentTimeMillis();
1584 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1586 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1587 Query query = getSession().createQuery(hql.toString());
1588 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1589 @SuppressWarnings("unchecked")
1590 List<Service> serviceList = query.list();
1592 if (serviceList.isEmpty()) {
1593 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
1594 return new ArrayList<AllottedResourceCustomization>();
1597 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1598 Collections.reverse (serviceList);
1599 Service service = serviceList.get(0);
1601 String serviceNameVersionId = service.getServiceNameVersionId();
1602 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
1604 // Service.serviceNameVersionId == ServiceToAllottedResources.serviceModelUuid
1605 return this.getAllAllottedResourcesByServiceModelUuid(serviceNameVersionId);
1608 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1609 long startTime = System.currentTimeMillis();
1610 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1612 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1613 Query query = getSession().createQuery(hql.toString());
1614 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1615 query.setParameter("serviceModelVersion", serviceModelVersion);
1618 //can fix this later - no time - could do a unique query here - but this should work
1619 @SuppressWarnings("unchecked")
1620 List<Service> serviceList = query.list();
1622 if (serviceList.isEmpty()) {
1623 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
1624 return new ArrayList<AllottedResourceCustomization>();
1627 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1628 Collections.reverse (serviceList);
1629 Service service = serviceList.get(0);
1631 String serviceNameVersionId = service.getServiceNameVersionId();
1633 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
1634 return this.getAllAllottedResourcesByServiceModelUuid(serviceNameVersionId);
1637 public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
1638 long startTime = System.currentTimeMillis();
1639 LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
1641 StringBuilder hql = new StringBuilder("FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
1642 Query query = getSession().createQuery(hql.toString());
1643 query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
1645 @SuppressWarnings("unchecked")
1646 List<AllottedResourceCustomization> resultList = query.list();
1648 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
1652 //1702 API Spec cont'd - Query for all resources in a Service:
1653 public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
1654 long startTime = System.currentTimeMillis();
1655 LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
1657 StringBuilder hql = new StringBuilder("FROM Service WHERE serviceNameVersionId = :serviceModelUuid");
1658 Query query = getSession().createQuery(hql.toString());
1659 query.setParameter("serviceModelUuid", serviceModelUuid);
1660 @SuppressWarnings("unchecked")
1661 List<Service> serviceList = query.list();
1663 if (serviceList.isEmpty()) {
1664 LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
1665 return new ServiceMacroHolder();
1668 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1669 Collections.reverse (serviceList);
1670 Service service = serviceList.get(0);
1672 ServiceMacroHolder smh = new ServiceMacroHolder(service);
1673 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
1674 smh.setNetworkResourceCustomization(nrcList);
1675 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
1676 smh.setAllottedResourceCustomization(arcList);
1677 ArrayList<VnfResource> vnfList = (ArrayList<VnfResource>) this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1678 smh.setVnfResources(vnfList);
1680 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
1683 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
1684 long startTime = System.currentTimeMillis();
1685 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
1687 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
1688 Query query = getSession().createQuery(hql.toString());
1689 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1690 @SuppressWarnings("unchecked")
1691 List<Service> serviceList = query.list();
1693 if (serviceList.isEmpty()) {
1694 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1695 return new ServiceMacroHolder();
1698 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1699 Collections.reverse (serviceList);
1700 Service service = serviceList.get(0);
1702 ServiceMacroHolder smh = new ServiceMacroHolder(service);
1703 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getServiceNameVersionId());
1704 smh.setNetworkResourceCustomization(nrcList);
1705 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getServiceNameVersionId());
1706 smh.setAllottedResourceCustomization(arcList);
1707 ArrayList<VnfResource> vnfList = (ArrayList<VnfResource>) this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1708 smh.setVnfResources(vnfList);
1710 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
1714 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
1715 long startTime = System.currentTimeMillis();
1716 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
1718 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
1719 Query query = getSession().createQuery(hql.toString());
1720 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
1721 query.setParameter("serviceModelVersion", serviceModelVersion);
1722 //TODO make this a unique query
1723 @SuppressWarnings("unchecked")
1724 List<Service> serviceList = query.list();
1726 if (serviceList.isEmpty()) {
1727 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
1728 return new ServiceMacroHolder();
1731 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
1732 Collections.reverse (serviceList);
1733 Service service = serviceList.get(0);
1735 ServiceMacroHolder smh = new ServiceMacroHolder(service);
1736 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getServiceNameVersionId());
1737 smh.setNetworkResourceCustomization(nrcList);
1738 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getServiceNameVersionId());
1739 smh.setAllottedResourceCustomization(arcList);
1740 ArrayList<VnfResource> vnfList = (ArrayList<VnfResource>) this.getAllVnfsByServiceModelInvariantUuid(service.getModelInvariantUUID(), service.getVersion());
1741 smh.setVnfResources(vnfList);
1743 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
1747 // 1707 New API queries
1748 public NetworkResourceCustomization getSingleNetworkByModelCustomizationUuid(String modelCustomizationUuid) {
1749 long startTime = System.currentTimeMillis();
1750 LOGGER.debug("Catalog database; getSingleNetworkByModelCustomizationUuid - " + modelCustomizationUuid);
1751 List<NetworkResourceCustomization> resultList = this.getAllNetworksByNetworkModelCustomizationUuid(modelCustomizationUuid);
1752 if (resultList == null || resultList.size() < 1) {
1755 return resultList.get(0);
1757 public AllottedResourceCustomization getSingleAllottedResourceByModelCustomizationUuid(String modelCustomizationUuid) {
1758 long startTime = System.currentTimeMillis();
1759 LOGGER.debug("Catalog database; getSingleAllottedResourceByModelCustomizationUuid - " + modelCustomizationUuid);
1760 List<AllottedResourceCustomization> resultList = this.getAllAllottedResourcesByArModelCustomizationUuid(modelCustomizationUuid);
1761 if (resultList == null || resultList.size() < 1) {
1764 return resultList.get(0);
1766 public VnfResource getSingleVnfResourceByModelCustomizationUuid(String modelCustomizationUuid) {
1767 long startTime = System.currentTimeMillis();
1768 LOGGER.debug("Catalog database; getSingleVnfResourceByModelCustomizationUuid - " + modelCustomizationUuid);
1769 List<VnfResource> resultList = this.getAllVnfsByVnfModelCustomizationUuid(modelCustomizationUuid);
1770 if (resultList == null || resultList.size() < 1) {
1773 return resultList.get(0);
1776 private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
1777 HashMap<Integer, NetworkResource> networkResources = new HashMap<Integer, NetworkResource>();
1779 for (NetworkResourceCustomization nrc : resultList) {
1780 Integer network_id = nrc.getNetworkResourceId();
1781 if (network_id == null) {
1782 nrc.setNetworkResource(null);
1783 nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
1786 if (networkResources.containsKey(network_id)) {
1787 nrc.setNetworkResource(networkResources.get(network_id));
1788 nrc.setNetworkType(networkResources.get(network_id).getNetworkType());
1790 NetworkResource nr = this.getNetworkResourceById(network_id);
1792 nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
1794 nrc.setNetworkType(nr.getNetworkType());
1795 nrc.setNetworkResource(nr);
1796 networkResources.put(network_id, nr);
1803 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
1804 * first query VF_MODULE table by type, and then use the ID to query
1805 * VNF_RECIPE by VF_MODULE_ID and ACTION
1808 * @parm vfModuleModelName
1810 * @return VnfRecipe object or null if none found
1812 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
1813 String vfModuleType = vnfType + "::" + vfModuleModelName;
1815 StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type ");
1817 long startTime = System.currentTimeMillis ();
1818 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
1820 Query query = getSession ().createQuery (hql.toString ());
1821 query.setParameter (TYPE, vfModuleType);
1823 @SuppressWarnings("unchecked")
1824 List <VfModule> resultList = query.list ();
1826 if (resultList.isEmpty ()) {
1827 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
1831 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1832 Collections.reverse (resultList);
1834 VfModule vfMod = resultList.get(0);
1836 int id = vfMod.getId();
1837 String vfModuleId = Integer.toString(id);
1839 StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
1841 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
1845 Query query1 = getSession ().createQuery (hql1.toString ());
1846 query1.setParameter (VF_MODULE_ID, vfModuleId);
1847 query1.setParameter (ACTION, action);
1849 @SuppressWarnings("unchecked")
1850 List <VnfRecipe> resultList1 = query1.list ();
1852 if (resultList1.isEmpty ()) {
1853 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
1857 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
1858 Collections.reverse (resultList1);
1860 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
1861 return resultList1.get (0);
1865 * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
1866 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
1868 * @param vnfModuleType
1869 * @parm modelCustomizationUuid
1870 * @param asdcServiceModelVersion
1871 * @param modelVersion
1873 * @return VfModule list
1875 public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
1878 if(modelCustomizationUuid != null){
1879 hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
1881 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
1883 query = getSession ().createQuery (hql.toString ());
1884 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1885 query.setParameter ("version", asdcServiceModelVersion);
1887 hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
1889 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
1891 query = getSession ().createQuery (hql.toString ());
1892 query.setParameter (TYPE, vfModuleType);
1893 query.setParameter ("version", asdcServiceModelVersion);
1894 query.setParameter ("modelVersion", modelVersion);
1897 @SuppressWarnings("unchecked")
1898 List <VfModule> resultList = query.list ();
1903 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
1904 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
1905 * first query VF_MODULE table by type, and then use the ID to query
1906 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
1909 * @parm vfModuleModelName
1911 * @return VnfRecipe object or null if none found
1913 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
1914 String vfModuleType = vnfType + "::" + vfModuleModelName;
1915 long startTime = System.currentTimeMillis ();
1916 List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
1918 if (resultList.isEmpty ()) {
1919 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
1923 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1924 Collections.reverse (resultList);
1926 VfModule vfMod = resultList.get(0);
1928 int id = vfMod.getId();
1929 String vfModuleId = Integer.toString(id);
1931 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
1933 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
1937 Query query1 = getSession ().createQuery (hql1.toString ());
1938 query1.setParameter (VF_MODULE_ID, vfModuleId);
1939 query1.setParameter (ACTION, action);
1941 @SuppressWarnings("unchecked")
1942 List <VnfComponentsRecipe> resultList1 = query1.list ();
1944 if (resultList1.isEmpty ()) {
1945 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
1949 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
1950 Collections.reverse (resultList1);
1952 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
1953 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
1954 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);
1957 return resultList1.get (0);
1961 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
1962 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
1963 * first query VF_MODULE table by type, and then use the ID to query
1964 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
1967 * @parm vfModuleModelName
1969 * @return VnfRecipe object or null if none found
1971 public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
1972 long startTime = System.currentTimeMillis ();
1974 if (resultList.isEmpty ()) {
1975 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
1979 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1980 Collections.reverse (resultList);
1982 VfModule vfMod = resultList.get(0);
1984 int id = vfMod.getId();
1985 String vfModuleId = Integer.toString(id);
1987 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
1989 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
1993 Query query1 = getSession ().createQuery (hql1.toString ());
1994 query1.setParameter (VF_MODULE_ID, vfModuleId);
1995 query1.setParameter (ACTION, action);
1997 @SuppressWarnings("unchecked")
1998 List <VnfComponentsRecipe> resultList1 = query1.list ();
2000 if (resultList1.isEmpty ()) {
2001 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2005 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2006 Collections.reverse (resultList1);
2008 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2009 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2010 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);
2013 return resultList1.get (0);
2018 * Return all VNF Resources in the Catalog DB
2020 * @return A list of VnfResource objects
2022 @SuppressWarnings("unchecked")
2023 public List <VnfResource> getAllVnfResources () {
2025 long startTime = System.currentTimeMillis ();
2026 LOGGER.debug ("Catalog database - get all VNF resources");
2028 String hql = "FROM VnfResource";
2029 Query query = getSession ().createQuery (hql);
2031 List <VnfResource> result = query.list ();
2032 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
2037 * Return VNF Resources in the Catalog DB that match a given VNF role
2039 * @return A list of VnfResource objects
2041 @SuppressWarnings("unchecked")
2042 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
2044 long startTime = System.currentTimeMillis ();
2045 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
2047 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
2048 Query query = getSession ().createQuery (hql);
2049 query.setParameter ("vnfRole", vnfRole);
2051 List <VnfResource> resources = query.list ();
2052 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
2057 * Return all Network Resources in the Catalog DB
2059 * @return A list of NetworkResource objects
2061 @SuppressWarnings("unchecked")
2062 public List <NetworkResource> getAllNetworkResources () {
2064 long startTime = System.currentTimeMillis ();
2065 LOGGER.debug ("Catalog database - get all network resources");
2067 String hql = "FROM NetworkResource";
2068 Query query = getSession ().createQuery (hql);
2070 List <NetworkResource> result = query.list ();
2071 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
2076 * Return all VF Modules in the Catalog DB
2078 * @return A list of VfModule objects
2080 @SuppressWarnings("unchecked")
2081 public List <VfModule> getAllVfModules () {
2083 long startTime = System.currentTimeMillis ();
2084 LOGGER.debug ("Catalog database - get all vf modules");
2086 String hql = "FROM VfModule";
2087 Query query = getSession ().createQuery (hql);
2089 List <VfModule> result = query.list ();
2090 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
2095 * Return all HeatEnvironment in the Catalog DB
2097 * @return A list of HeatEnvironment objects
2099 @SuppressWarnings("unchecked")
2100 public List <HeatEnvironment> getAllHeatEnvironment () {
2102 long startTime = System.currentTimeMillis ();
2103 LOGGER.debug ("Catalog database - get all Heat environments");
2105 String hql = "FROM HeatEnvironment";
2106 Query query = getSession ().createQuery (hql);
2108 List <HeatEnvironment> result = query.list ();
2109 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
2114 * Fetch the Environment by Environment ID - 1510
2116 public HeatEnvironment getHeatEnvironment (int id) {
2118 long startTime = System.currentTimeMillis ();
2119 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
2121 String hql = "FROM HeatEnvironment WHERE id = :idValue";
2123 LOGGER.debug ("getHeatEnvironment called with id=" + id);
2125 Query query = getSession ().createQuery (hql);
2126 query.setParameter ("idValue", id);
2128 @SuppressWarnings("unchecked")
2129 List <HeatEnvironment> resultList = query.list ();
2131 // See if something came back.
2132 if (resultList.isEmpty ()) {
2133 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
2136 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
2137 return resultList.get (0);
2141 * Fetch the nested templates - 1510
2144 public Map <String, Object> getNestedTemplates (int templateId) {
2145 Map <String, Object> nestedTemplates = null;
2146 long startTime = System.currentTimeMillis ();
2147 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
2149 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
2151 Query query = getSession ().createQuery (hql);
2152 query.setParameter ("parentIdValue", templateId);
2154 @SuppressWarnings("unchecked")
2155 List <HeatNestedTemplate> resultList = query.list ();
2156 // If nothing comes back, there are no nested templates
2157 if (resultList.isEmpty ()) {
2158 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
2159 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
2162 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
2163 nestedTemplates = new HashMap <String, Object> ();
2164 for (HeatNestedTemplate hnt : resultList) {
2165 LOGGER.debug ("Querying for " + hnt);
2166 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
2168 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
2171 String providerResourceFile = hnt.getProviderResourceFile ();
2172 String heatTemplateBody = ht.getTemplateBody ();
2173 if (providerResourceFile != null && heatTemplateBody != null) {
2174 nestedTemplates.put (providerResourceFile, heatTemplateBody);
2176 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
2179 // Make sure we're not returning an empty map - if so, just return null
2180 if (nestedTemplates.isEmpty ()) {
2181 LOGGER.debug ("nestedTemplates is empty - just return null");
2182 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
2185 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
2186 return nestedTemplates;
2190 * Fetch any files in the HEAT_FILES table 1510
2192 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
2193 Map <String, HeatFiles> heatFiles = null;
2195 long startTime = System.currentTimeMillis ();
2196 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
2197 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
2199 Query query = getSession ().createQuery (hql);
2200 query.setParameter ("vnfResourceIdValue", vnfResourceId);
2202 @SuppressWarnings("unchecked")
2203 List <HeatFiles> resultList = query.list ();
2204 // If nothing comes back, there are no heat files
2205 if (resultList.isEmpty ()) {
2206 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
2207 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
2210 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
2211 heatFiles = new HashMap <String, HeatFiles> ();
2212 for (HeatFiles hf : resultList) {
2213 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
2214 heatFiles.put (hf.getFileName (), hf);
2216 // Make sure we're not returning an empty map - if so, just return null
2217 if (heatFiles.isEmpty ()) {
2218 LOGGER.debug ("heatFiles is empty - just return null");
2219 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
2222 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
2226 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
2228 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
2229 Map <String, HeatFiles> heatFiles = null;
2231 long startTime = System.currentTimeMillis ();
2232 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
2233 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
2235 Query query = getSession ().createQuery (hql);
2236 query.setParameter ("vfModuleIdValue", vfModuleId);
2238 List<VfModuleToHeatFiles> mapList = query.list();
2239 if (mapList.isEmpty()) {
2240 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
2241 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
2244 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
2245 //TODO - convert this all with one join - brute force for now due to time
2246 heatFiles = new HashMap<String, HeatFiles>();
2247 for (VfModuleToHeatFiles vmthf : mapList) {
2248 int heatFilesId = vmthf.getHeatFilesId();
2249 hql = "FROM HeatFiles where id = :id_value";
2250 query = getSession().createQuery(hql);
2251 query.setParameter("id_value", heatFilesId);
2252 List<HeatFiles> fileList = query.list();
2253 if (fileList.isEmpty()) {
2254 // Should this throw an exception??
2255 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
2256 String errorString = "_ERROR|" + heatFilesId;
2257 // The receiving code needs to know to throw an exception for this - or ignore it.
2258 heatFiles.put(errorString, null);
2260 // Should only ever have 1 result - add it to our Map
2261 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
2262 for (HeatFiles hf : fileList) {
2263 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
2264 heatFiles.put(hf.getFileName(), hf);
2268 if (heatFiles.isEmpty()) {
2269 LOGGER.debug ("heatFiles is empty - just return null");
2270 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
2273 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
2280 * Get the heat template object based on asdc attributes
2282 * @param templateName The template name, generally the yaml filename. "example.yaml"
2283 * @param version The version as specified by ASDC. "1.1"
2284 * @param asdcResourceName The ASDC resource name provided in the ASDC artifact
2286 * @return The HeatTemplate
2288 public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
2290 long startTime = System.currentTimeMillis ();
2291 LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
2294 + " and ASDC resource name "
2295 + asdcResourceName);
2297 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
2298 Query query = getSession ().createQuery (hql);
2299 query.setParameter ("template_name", templateName);
2300 query.setParameter ("version", version);
2301 query.setParameter ("asdcResourceName", asdcResourceName);
2303 @SuppressWarnings("unchecked")
2304 List <HeatTemplate> resultList = query.list ();
2306 // See if something came back.
2307 if (resultList.isEmpty ()) {
2308 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
2311 // Name + Version is unique, so should only be one element
2312 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
2313 return resultList.get (0);
2317 * Save the Heat Template
2319 * @param heat The heat template
2320 * @param paramSet The list of heat template parameters
2322 public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
2324 long startTime = System.currentTimeMillis ();
2325 LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName());
2327 heat.setParameters(null);
2329 HeatTemplate heatTemp = this.getHeatTemplate (heat.getTemplateName (),
2331 heat.getAsdcResourceName ());
2332 if (heatTemp == null) {
2333 this.getSession ().save (heat);
2335 if (paramSet != null) {
2336 for (HeatTemplateParam param : paramSet) {
2337 param.setHeatTemplateId (heat.getId ());
2339 heat.setParameters (paramSet);
2340 this.getSession ().merge (heat);
2344 heat.setId(heatTemp.getId());
2347 heat.setParameters(paramSet);
2348 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
2353 * Retrieves a Heat environment from DB based on its unique key.
2355 * @param name the environment artifact name
2356 * @param version the environment resource version
2357 * @param asdcResourceName the environment resource name
2358 * @return the heat environment from DB or null if not found
2360 public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
2361 long startTime = System.currentTimeMillis ();
2362 LOGGER.debug ("Catalog database - get Heat environment with name " + name
2365 + " and ASDC resource name "
2366 + asdcResourceName);
2368 String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
2369 Query query = getSession ().createQuery (hql);
2370 query.setParameter ("name", name);
2371 query.setParameter ("version", version);
2372 query.setParameter ("asdcResourceName", asdcResourceName);
2373 HeatEnvironment env = null;
2375 env = (HeatEnvironment) query.uniqueResult ();
2376 } catch (org.hibernate.NonUniqueResultException nure) {
2377 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);
2378 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);
2380 } catch (org.hibernate.HibernateException he) {
2381 LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
2382 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);
2384 } catch (Exception e) {
2385 LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
2386 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);
2390 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
2392 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
2398 * Save the HeatEnvironment
2400 * @param env The Environment
2402 public void saveHeatEnvironment (HeatEnvironment env) {
2403 long startTime = System.currentTimeMillis ();
2404 LOGGER.debug ("Catalog database - save Heat environment with name "
2405 + env.getEnvironment());
2407 HeatEnvironment dbEnv = getHeatEnvironment (env.getName (), env.getVersion (), env.getAsdcResourceName ());
2408 if (dbEnv == null) {
2410 this.getSession ().save (env);
2413 env.setId(dbEnv.getId());
2417 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
2422 * Save the heatTemplate
2424 * @param heat The heat template
2426 public void saveHeatTemplate (HeatTemplate heat) {
2427 long startTime = System.currentTimeMillis ();
2428 LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
2430 this.getSession ().update (heat);
2432 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
2436 public void saveHeatFile (HeatFiles heatFile) {
2437 long startTime = System.currentTimeMillis ();
2438 LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
2440 this.getSession ().save (heatFile);
2442 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
2446 public void saveVnfRecipe (VnfRecipe vnfRecipe) {
2447 long startTime = System.currentTimeMillis ();
2448 LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
2450 this.getSession ().save (vnfRecipe);
2452 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
2456 public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
2457 long startTime = System.currentTimeMillis ();
2458 LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
2460 this.getSession ().save (vnfComponentsRecipe);
2462 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
2467 public void saveOrUpdateVnfResource (VnfResource vnfResource) {
2468 long startTime = System.currentTimeMillis ();
2469 LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getVnfType ());
2472 if (vnfResource.getId() != 0) {
2473 this.getSession ().merge (vnfResource);
2475 this.getSession ().save (vnfResource);
2479 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
2483 public void saveAllottedResourceCustomization (AllottedResourceCustomization resourceCustomization) {
2484 long startTime = System.currentTimeMillis ();
2485 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + resourceCustomization.getModelName());
2487 List<AllottedResourceCustomization> allottedResourcesList = getAllAllottedResourcesByArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
2489 if(allottedResourcesList.size() == 0){
2490 this.getSession ().save(resourceCustomization);
2494 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
2498 public void saveNetworkResourceCustomization (NetworkResourceCustomization networkResourceCustomization) throws RecordNotFoundException {
2499 long startTime = System.currentTimeMillis ();
2500 LOGGER.debug ("Catalog database - save Network Resource Customization with Network Name " + networkResourceCustomization.getModelName());
2502 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
2503 List<NetworkResourceCustomization> networkResourceCustomizationList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
2504 // Do any matching customization records exist?
2505 if(networkResourceCustomizationList.size() == 0){
2507 // Retreive the record from the Network_Resource table associated to the Customization record based on ModelName
2508 NetworkResource networkResource = getNetworkResource(networkResourceCustomization.getModelName());
2510 if(networkResource == null){
2511 throw new RecordNotFoundException("No record found in NETWORK_RESOURCE table for model name " + networkResourceCustomization.getModelName());
2514 networkResourceCustomization.setNetworkResourceId(networkResource.getId());
2516 this.getSession ().save(networkResourceCustomization);
2521 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
2525 public void saveServiceToNetworks (ServiceToNetworks serviceToNetworks) {
2526 long startTime = System.currentTimeMillis ();
2527 LOGGER.debug ("Catalog database - save to ServiceToNetworks table with NetworkModelCustomizationUUID of " + serviceToNetworks.getNetworkModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToNetworks.getServiceModelUuid());
2529 this.getSession ().save(serviceToNetworks);
2532 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
2536 public void saveServiceToAllottedResources (ServiceToAllottedResources serviceToAllottedResources) {
2537 long startTime = System.currentTimeMillis ();
2538 LOGGER.debug ("Catalog database - save to serviceToAllottedResources table with ARModelCustomizationUUID of " + serviceToAllottedResources.getArModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToAllottedResources.getServiceModelUuid());
2540 this.getSession ().save(serviceToAllottedResources);
2543 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToAllottedResources", null);
2547 public void saveService (Service service) {
2548 long startTime = System.currentTimeMillis ();
2549 LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getServiceName()+"/"+service.getVersion()+"/"+service.getServiceNameVersionId());
2551 Service serviceInvariantDB = null;
2552 // Retrieve existing service record by nameVersionId
2553 Service serviceDB = this.getServiceByUUID(service.getServiceNameVersionId());
2554 if (serviceDB == null) {
2555 // 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.
2556 serviceInvariantDB = this.getServiceByInvariantUUID(service.getModelInvariantUUID());
2557 // Save the new Service record
2558 this.getSession ().save (service);
2561 if(serviceInvariantDB != null){ // existing modelInvariantId was found.
2562 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
2563 List<ServiceRecipe> serviceRecipes = getServiceRecipes(serviceInvariantDB.getId());
2565 if(serviceRecipes != null && serviceRecipes.size() > 0){
2566 for(ServiceRecipe serviceRecipe : serviceRecipes){
2567 if(serviceRecipe != null){
2568 // 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.
2569 Service newService = this.getServiceByUUID(service.getServiceNameVersionId());
2570 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
2571 ServiceRecipe newServiceRecipe = new ServiceRecipe();
2572 newServiceRecipe.setAction(serviceRecipe.getAction());
2573 newServiceRecipe.setDescription(serviceRecipe.getDescription());
2574 newServiceRecipe.setOrchestrationUri(serviceRecipe.getOrchestrationUri());
2575 newServiceRecipe.setRecipeTimeout(serviceRecipe.getRecipeTimeout());
2576 newServiceRecipe.setServiceParamXSD(serviceRecipe.getServiceParamXSD());
2577 newServiceRecipe.setServiceId(newService.getId());
2578 newServiceRecipe.setVersion(serviceRecipe.getVersion());
2579 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
2580 this.getSession ().save (newServiceRecipe);
2588 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
2592 public void saveOrUpdateVfModule (VfModule vfModule) {
2593 long startTime = System.currentTimeMillis ();
2594 LOGGER.debug ("Catalog database - save VNF Module with VF Model Name " + vfModule.getModelName());
2597 if (vfModule.getId() != 0) {
2598 this.getSession ().merge (vfModule);
2600 this.getSession ().save (vfModule);
2604 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
2608 public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
2609 long startTime = System.currentTimeMillis ();
2610 LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
2611 + parentTemplateId +"-"+childTemplateId);
2613 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
2614 nestedTemplate.setParentTemplateId (parentTemplateId);
2615 nestedTemplate.setChildTemplateId (childTemplateId);
2617 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
2619 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
2623 public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
2624 long startTime = System.currentTimeMillis ();
2625 LOGGER.debug ("Catalog database - save nested Heat template with name "
2626 + childTemplate.getTemplateName ());
2629 saveHeatTemplate(childTemplate, childTemplate.getParameters());
2630 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
2631 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
2632 nestedTemplate.setParentTemplateId (parentTemplateId);
2633 nestedTemplate.setChildTemplateId (childTemplate.getId ());
2634 nestedTemplate.setProviderResourceFile (yamlFile);
2635 session.save (nestedTemplate);
2638 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
2642 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
2643 long startTime = System.currentTimeMillis ();
2644 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
2645 + " and vnfResourceID "
2647 // + " and ASDC resource name "
2652 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
2653 Query query = getSession ().createQuery (hql);
2654 query.setParameter ("fileName", fileName);
2655 query.setParameter ("vnfResourceId", vnfResourceId);
2656 query.setParameter ("asdcResourceName", asdcResourceName);
2657 query.setParameter ("version", version);
2659 @SuppressWarnings("unchecked")
2661 HeatFiles heatFilesResult = null;
2663 heatFilesResult = (HeatFiles) query.uniqueResult ();
2664 } catch (org.hibernate.NonUniqueResultException nure) {
2665 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);
2666 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);
2667 heatFilesResult = null;
2668 } catch (org.hibernate.HibernateException he) {
2669 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
2670 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);
2671 heatFilesResult = null;
2672 } catch (Exception e) {
2673 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
2674 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);
2675 heatFilesResult = null;
2678 // See if something came back.
2679 if (heatFilesResult == null) {
2680 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
2683 // Name + Version is unique, so should only be one element
2684 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
2685 return heatFilesResult;
2688 public void saveHeatFiles (HeatFiles childFile) {
2689 long startTime = System.currentTimeMillis ();
2690 LOGGER.debug ("Catalog database - save Heat File with name "
2691 + childFile.getFileName());
2693 HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
2694 if (heatFiles == null) {
2696 // asdc_heat_files_save
2697 this.getSession ().save (childFile);
2700 /* replaced 'heatFiles' by 'childFile'
2701 Based on following comment:
2702 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
2704 childFile.setId(heatFiles.getId());
2708 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
2712 public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
2713 long startTime = System.currentTimeMillis ();
2714 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
2715 + childFile.getFileName());
2717 saveHeatFiles (childFile);
2718 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
2719 vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
2720 vfModuleToHeatFile.setHeatFilesId(childFile.getId());
2722 session.save (vfModuleToHeatFile);
2725 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
2731 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
2733 * @param networkType
2735 * @param serviceType
2736 * @return NetworkRecipe object or null if none found
2738 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
2740 long startTime = System.currentTimeMillis ();
2741 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
2744 + " and service type "
2749 if (serviceType == null) {
2750 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
2752 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
2754 Query query = getSession ().createQuery (hql);
2755 query.setParameter (NETWORK_TYPE, networkType);
2756 query.setParameter (ACTION, action);
2757 if (serviceType != null) {
2758 query.setParameter ("serviceType", serviceType);
2761 @SuppressWarnings("unchecked")
2762 List <NetworkRecipe> resultList = query.list ();
2764 if (resultList.isEmpty ()) {
2768 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2769 Collections.reverse (resultList);
2771 return resultList.get (0);
2773 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
2778 * Return a Network recipe that matches a given NETWORK_TYPE and ACTION
2780 * @param networkType
2782 * @return NetworkRecipe object or null if none found
2784 public NetworkRecipe getNetworkRecipe (String networkType, String action) {
2786 long startTime = System.currentTimeMillis ();
2787 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
2793 String hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action";
2795 Query query = getSession ().createQuery (hql);
2796 query.setParameter (NETWORK_TYPE, networkType);
2797 query.setParameter (ACTION, action);
2799 @SuppressWarnings("unchecked")
2800 List <NetworkRecipe> resultList = query.list ();
2802 if (resultList.isEmpty ()) {
2806 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2807 Collections.reverse (resultList);
2809 return resultList.get (0);
2811 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
2816 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
2818 * @param networkType
2820 * @param serviceType
2821 * @return NetworkRecipe object or null if none found
2823 public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
2825 long startTime = System.currentTimeMillis ();
2826 LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
2829 String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.id=c.networkResourceId and c.modelCustomizationUuid = :modelCustomizationUuid";
2830 Query query = getSession ().createQuery (hql);
2831 query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
2833 @SuppressWarnings("unchecked")
2834 List <NetworkResource> resultList = query.list ();
2836 if (resultList.isEmpty ()) {
2840 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2841 Collections.reverse (resultList);
2843 return resultList.get (0);
2845 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceBySvcNtwkRsrc", null);
2850 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
2854 * @param vnfComponentType
2856 * @param serviceType
2857 * @return VnfComponentsRecipe object or null if none found
2859 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
2860 String vnfComponentType,
2862 String serviceType) {
2864 long startTime = System.currentTimeMillis ();
2865 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
2866 + " and component type "
2870 + " and service type "
2875 if (serviceType == null) {
2876 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
2878 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
2880 Query query = getSession ().createQuery (hql);
2881 query.setParameter (VNF_TYPE, vnfType);
2882 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
2883 query.setParameter (ACTION, action);
2884 if (serviceType != null) {
2885 query.setParameter ("serviceType", serviceType);
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", "getVnfComponentsRecipe", null);
2904 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
2907 * @param vnfComponentType
2909 * @return VnfComponentsRecipe object or null if none found
2911 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleId (String vfModuleId,
2912 String vnfComponentType,
2915 long startTime = System.currentTimeMillis ();
2916 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleId " + vfModuleId
2917 + " and component type "
2924 hql = "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND vnfComponentType = :vnfComponentType AND action = :action ";
2926 Query query = getSession ().createQuery (hql);
2927 query.setParameter (VF_MODULE_ID, vfModuleId);
2928 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
2929 query.setParameter (ACTION, action);
2931 @SuppressWarnings("unchecked")
2932 List <VnfComponentsRecipe> resultList = query.list ();
2934 if (resultList.isEmpty ()) {
2937 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2938 Collections.reverse (resultList);
2940 return resultList.get (0);
2942 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleId", null);
2948 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
2949 long startTime = System.currentTimeMillis ();
2951 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
2953 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
2957 if (vnfComponentDb != null) {
2958 this.getSession ().merge (vnfComponent);
2960 this.getSession ().save (vnfComponent);
2964 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
2969 * Return a VfModule record that matches a given MODEL_NAME
2972 * @return VfModule object or null if none found
2974 public VfModule getVfModule (String modelName) {
2976 long startTime = System.currentTimeMillis ();
2977 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
2982 hql = "FROM VfModule WHERE modelName = :modelName";
2984 Query query = getSession ().createQuery (hql);
2985 query.setParameter (MODEL_NAME, modelName);
2987 @SuppressWarnings("unchecked")
2988 List <VfModule> resultList = query.list ();
2990 if (resultList.isEmpty ()) {
2993 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2994 Collections.reverse (resultList);
2996 return resultList.get (0);
2998 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
3003 * Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
3004 * Note: This method is not currently used but was retained in the event the
3005 * architecture moves back to a MODEL/MODEL_RECIPE structure.
3008 * @param modelVersionId
3010 * @return ModelRecipe object or null if none found
3012 public ModelRecipe getModelRecipe(String modelType,
3013 String modelVersionId,
3016 long startTime = System.currentTimeMillis();
3017 LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
3018 + " and modeVersionId=" + modelVersionId
3019 + " and action=" + action);
3023 // TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
3024 // the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
3025 // There seems to be 2 issues: formatting a hql query that executes successfully
3026 // and then being able to generate a result that will fit into the ModelRecipe class.
3028 // 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
3029 hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
3030 Query query = getSession().createQuery(hql);
3031 query.setParameter(MODEL_TYPE, modelType);
3032 query.setParameter(MODEL_VERSION_ID, modelVersionId);
3034 @SuppressWarnings("unchecked")
3035 List<Model> modelResultList = query.list();
3036 if (modelResultList.isEmpty()) {
3037 LOGGER.debug("Catalog database - modelResultList is null");
3040 Collections.sort(modelResultList, new MavenLikeVersioningComparator());
3041 Collections.reverse(modelResultList);
3042 LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
3044 // 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
3045 hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
3046 query = getSession().createQuery(hql);
3047 // The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
3048 query.setParameter(MODEL_ID, modelResultList.get(0).getId());
3049 query.setParameter(ACTION, action);
3051 @SuppressWarnings("unchecked")
3052 List<ModelRecipe> recipeResultList = query.list();
3053 if (recipeResultList.isEmpty()) {
3054 LOGGER.debug("Catalog database - recipeResultList is null");
3057 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
3058 Collections.reverse(recipeResultList);
3059 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
3061 return recipeResultList.get(0);
3063 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
3069 * Verify the health of the DB.
3071 * @return boolean value indicate whether DB is healthy
3073 public boolean healthCheck () {
3074 long startTime = System.currentTimeMillis ();
3075 Session session = this.getSession ();
3077 Query query = session.createSQLQuery (" show tables ");
3079 List<?> list = query.list();
3080 LOGGER.debug("healthCheck CatalogDB - Successful");