2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.mso.db.catalog;
24 import java.io.Closeable;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.List;
33 import org.hibernate.HibernateException;
34 import org.hibernate.Query;
35 import org.hibernate.Session;
36 import org.openecomp.mso.db.AbstractSessionFactoryManager;
37 import org.openecomp.mso.db.catalog.beans.AllottedResource;
38 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
39 import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
40 import org.openecomp.mso.db.catalog.beans.HeatFiles;
41 import org.openecomp.mso.db.catalog.beans.HeatNestedTemplate;
42 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
43 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
44 import org.openecomp.mso.db.catalog.beans.Model;
45 import org.openecomp.mso.db.catalog.beans.ModelRecipe;
46 import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
47 import org.openecomp.mso.db.catalog.beans.NetworkResource;
48 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
49 import org.openecomp.mso.db.catalog.beans.Service;
50 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
51 import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
52 import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
53 import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
54 import org.openecomp.mso.db.catalog.beans.ServiceToResourceCustomization;
55 import org.openecomp.mso.db.catalog.beans.TempNetworkHeatTemplateLookup;
56 import org.openecomp.mso.db.catalog.beans.ToscaCsar;
57 import org.openecomp.mso.db.catalog.beans.VfModule;
58 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
59 import org.openecomp.mso.db.catalog.beans.VfModuleToHeatFiles;
60 import org.openecomp.mso.db.catalog.beans.VnfComponent;
61 import org.openecomp.mso.db.catalog.beans.VnfComponentsRecipe;
62 import org.openecomp.mso.db.catalog.beans.VnfRecipe;
63 import org.openecomp.mso.db.catalog.beans.VnfResCustomToVfModuleCustom;
64 import org.openecomp.mso.db.catalog.beans.VnfResource;
65 import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
66 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
67 import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
68 import org.openecomp.mso.logger.MessageEnum;
69 import org.openecomp.mso.logger.MsoLogger;
72 * This class encapsulates all of the objects that can be queried from a Catalog database.
73 * Clients must use these methods to retrieve catalog objects. The session is not
74 * available for clients to do their own direct queries to the database.
78 public class CatalogDatabase implements Closeable {
80 protected final AbstractSessionFactoryManager sessionFactoryCatalogDB;
82 private static final String NETWORK_TYPE = "networkType";
83 private static final String ACTION = "action";
84 private static final String VNF_TYPE = "vnfType";
85 private static final String SERVICE_TYPE = "serviceType";
86 private static final String MODEL_UUID= "modelUUID";
87 private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
88 private static final String MODEL_ID = "modelId";
89 private static final String MODEL_NAME = "modelName";
90 private static final String TYPE = "type";
91 private static final String MODEL_TYPE = "modelType";
92 private static final String MODEL_VERSION_ID = "modelVersionId";
93 private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
94 private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId";
96 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
98 protected Session session = null;
100 protected CatalogDatabase (AbstractSessionFactoryManager sessionFactoryCatalog) {
101 sessionFactoryCatalogDB = sessionFactoryCatalog;
104 public static CatalogDatabase getInstance() {
105 return new CatalogDatabase(new CatalogDbSessionFactoryManager ());
108 private Session getSession () {
110 if (session == null) {
112 session = sessionFactoryCatalogDB.getSessionFactory ().openSession ();
113 session.beginTransaction ();
114 } catch (HibernateException he) {
115 LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Error creating Hibernate Session: " + he, "", "", MsoLogger.ErrorCode.DataError, "Error creating Hibernate Session: " + he);
124 * Close an open Catalog Database session.
125 * This method should always be called when a client is finished using a
126 * CatalogDatabase instance.
129 public void close () {
130 if (session != null) {
137 * Commits the current transaction on this session and starts a fresh one.
139 public void commit () {
140 getSession ().getTransaction ().commit ();
141 getSession ().beginTransaction ();
145 * Rolls back current transaction and starts a fresh one.
147 public void rollback () {
148 getSession ().getTransaction ().rollback ();
149 getSession ().beginTransaction ();
153 * Return all Heat Templates in the Catalog DB
155 * @return A list of HeatTemplate objects
157 @SuppressWarnings("unchecked")
158 public List <HeatTemplate> getAllHeatTemplates() {
159 long startTime = System.currentTimeMillis();
160 LOGGER.debug("Catalog database - get all Heat templates");
161 String hql = "FROM HeatTemplate";
162 Query query = getSession().createQuery(hql);
164 List <HeatTemplate> result = query.list();
165 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatTemplates", null);
170 * Fetch a specific Heat Template by ID.
172 * @param templateId template id
173 * @return HeatTemplate object or null if none found
176 public HeatTemplate getHeatTemplate(int templateId) {
177 long startTime = System.currentTimeMillis();
178 LOGGER.debug ("Catalog database - get Heat template with id " + templateId);
180 HeatTemplate template = (HeatTemplate) getSession().get(HeatTemplate.class, templateId);
181 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
186 * Return the newest version of a specific Heat Template (queried by Name).
188 * @param templateName template name
189 * @return HeatTemplate object or null if none found
191 public HeatTemplate getHeatTemplate(String templateName) {
193 long startTime = System.currentTimeMillis();
194 LOGGER.debug("Catalog database - get Heat template with name " + templateName);
196 String hql = "FROM HeatTemplate WHERE templateName = :template_name";
197 Query query = getSession().createQuery (hql);
198 query.setParameter("template_name", templateName);
200 @SuppressWarnings("unchecked")
201 List <HeatTemplate> resultList = query.list();
203 // See if something came back. Name is unique, so
204 if (resultList.isEmpty ()) {
205 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null);
208 Collections.sort(resultList, new MavenLikeVersioningComparator());
209 Collections.reverse(resultList);
211 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
212 return resultList.get(0);
216 * Return a specific version of a specific Heat Template (queried by Name).
218 * @param templateName
220 * @return HeatTemplate object or null if none found
222 public HeatTemplate getHeatTemplate(String templateName, String version) {
224 long startTime = System.currentTimeMillis();
225 LOGGER.debug("Catalog database - get Heat template with name " + templateName
229 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version";
230 Query query = getSession().createQuery(hql);
231 query.setParameter("template_name", templateName);
232 query.setParameter("version", version);
234 @SuppressWarnings("unchecked")
235 List <HeatTemplate> resultList = query.list();
237 // See if something came back.
238 if (resultList.isEmpty()) {
239 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found.", "CatalogDB", "getHeatTemplate", null);
242 // Name + Version is unique, so should only be one element
243 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
244 return resultList.get(0);
248 * Return a specific Heat Template by ARTIFACT_UUID).
250 * @param artifactUuid
251 * @return HeatTemplate object or null if none found
254 public HeatTemplate getHeatTemplateByArtifactUuid(String artifactUuid) {
255 long startTime = System.currentTimeMillis ();
256 LOGGER.debug ("Catalog database - get Heat template with artifactUuid " + artifactUuid);
258 // Will this work if the id is a string?
259 HeatTemplate template = (HeatTemplate) getSession ().get (HeatTemplate.class, artifactUuid);
260 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
265 * Return a specific Heat Template by ARTIFACT_UUID using standard query method. unique record expected.
267 * @param artifactUuid
268 * @return HeatTemplate object or null if none found
270 public HeatTemplate getHeatTemplateByArtifactUuidRegularQuery(String artifactUuid) {
271 long startTime = System.currentTimeMillis();
272 LOGGER.debug("Catalog database - get Heat template (regular query) with artifactUuid " + artifactUuid);
274 String hql = "FROM HeatTemplate WHERE artifactUuid = :artifactUuidValue";
275 HashMap<String, String> variables = new HashMap<>();
276 variables.put("artifactUuidValue", artifactUuid);
277 HeatTemplate template = (HeatTemplate) this.executeQuerySingleRow(hql, variables, true);
279 if (template == null) {
280 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
282 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
287 public List<HeatTemplateParam> getParametersForHeatTemplate(String heatTemplateArtifactUuid) {
288 LOGGER.debug ("Catalog database - getParametersForHeatTemplate with artifactUuid " + heatTemplateArtifactUuid);
290 String hql = "FROM HeatTemplateParams WHERE artifactUuid = :artifactUuidValue";
291 Query query = getSession().createQuery(hql);
292 query.setParameter ("artifactUuidValue", heatTemplateArtifactUuid);
293 List<HeatTemplateParam> resultList = new ArrayList<>();
295 resultList = query.list ();
296 } catch (org.hibernate.HibernateException he) {
297 LOGGER.debug("Hibernate Exception - while searching HeatTemplateParams for: heatTemplateArtifactUuid='" + heatTemplateArtifactUuid + "'" + he.getMessage());
298 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching HeatTemplateParams for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + heatTemplateArtifactUuid);
300 } catch (Exception e) {
301 LOGGER.debug("Generic Exception - while searching HeatTemplateParam for: artifactUuid='" + heatTemplateArtifactUuid + "'" + e.getMessage());
302 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching HeatTemplate for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + heatTemplateArtifactUuid);
311 * Return a specific Heat Environment by ARTIFACT_UUID using standard query method. unique record expected.
313 * @param artifactUuid
314 * @return HeatEnvironment object or null if none found
316 public HeatEnvironment getHeatEnvironmentByArtifactUuid(String artifactUuid) {
317 long startTime = System.currentTimeMillis();
318 LOGGER.debug("Catalog database - get Heat Environment with artifactUuid " + artifactUuid);
320 String hql = "FROM HeatEnvironment WHERE artifactUuid = :artifactUuidValue";
321 Query query = getSession().createQuery(hql);
322 query.setParameter("artifactUuidValue", artifactUuid);
323 HeatEnvironment environment = null;
325 environment = (HeatEnvironment) query.uniqueResult();
326 } catch (org.hibernate.NonUniqueResultException nure) {
327 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row for Envt - data integrity error: artifactUuid='" + artifactUuid +"'", nure);
328 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for heatEnvironment artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid==" + artifactUuid);
329 } catch (org.hibernate.HibernateException he) {
330 LOGGER.debug("Hibernate Exception - while searching for envt: artifactUuid='" + artifactUuid + "' " + he.getMessage());
331 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching envt for artifactUuid=" + artifactUuid);
334 } catch (Exception e) {
335 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + "' " + e.getMessage());
336 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching envt for artifactUuid=" + artifactUuid);
341 if (environment == null) {
342 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
344 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
350 * Fetch a Service definition by InvariantUUID
352 public Service getServiceByInvariantUUID (String modelInvariantUUID) {
354 long startTime = System.currentTimeMillis();
355 LOGGER.debug("Catalog database - get service with Invariant UUID " + modelInvariantUUID);
357 String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid";
358 Query query = getSession().createQuery(hql);
359 query.setParameter ("model_invariant_uuid", modelInvariantUUID);
361 @SuppressWarnings("unchecked")
362 List <Service> resultList = query.list ();
364 // See if something came back.
365 if (resultList.isEmpty ()) {
366 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
369 Collections.sort (resultList, new MavenLikeVersioningComparator ());
370 Collections.reverse (resultList);
372 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
373 return resultList.get (0);
377 * Fetch a Service definition
379 public Service getService (String modelName) {
381 long startTime = System.currentTimeMillis();
382 LOGGER.debug("Catalog database - get service with name " + modelName);
384 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
385 Query query = getSession().createQuery(hql);
386 query.setParameter("MODEL_NAME", modelName);
388 Service service = null;
390 service = (Service) query.uniqueResult();
391 } catch (org.hibernate.NonUniqueResultException nure) {
392 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelName='" + modelName + "'");
393 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelName=" + modelName);
395 } catch (org.hibernate.HibernateException he) {
396 LOGGER.debug("Hibernate Exception - while searching for: modelName='" + modelName + "' " + he.getMessage());
397 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelName=" + modelName);
399 } catch (Exception e) {
400 LOGGER.debug("Generic Exception - while searching for: modelName='" + modelName + " " + e.getMessage());
401 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelName=" + modelName);
404 if (service == null) {
405 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
407 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
413 public Service getServiceByModelUUID (String modelUUID) {
415 long startTime = System.currentTimeMillis();
416 LOGGER.debug("Catalog database - get service with Model UUID " + modelUUID);
418 String hql = "FROM Service WHERE modelUUID = :MODEL_UUID";
419 HashMap<String, String> parameters = new HashMap<>();
420 parameters.put("MODEL_UUID", modelUUID);
423 Service service = this.executeQuerySingleRow(hql, parameters, true);
427 service = (Service) query.uniqueResult ();
428 } catch (org.hibernate.NonUniqueResultException nure) {
429 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelUUID='" + modelUUID + "'");
430 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelUUID=" + modelUUID);
432 } catch (org.hibernate.HibernateException he) {
433 LOGGER.debug("Hibernate Exception - while searching for: modelUUID='" + modelUUID + "' " + he.getMessage());
434 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUUID=" + modelUUID);
436 } catch (Exception e) {
437 LOGGER.debug("Generic Exception - while searching for: modelUUID='" + modelUUID + " " + e.getMessage());
438 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUUID=" + modelUUID);
442 if (service == null) {
443 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getServiceByModelUUID", null);
445 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelUUID", null);
452 * Fetch the Common Service API definition using Http Method + serviceNameVersionId
454 public Service getService(Map<String, String> map, String httpMethod) {
456 String serviceNameVersionId = map.get("serviceNameVersionId");
458 String serviceId = "not_set";
459 String serviceVersion = "not_set";
461 if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
462 LOGGER.debug ("Catalog database - get service modelUUID with id " + serviceNameVersionId);
464 String hql = "FROM Service WHERE MODEL_UUID = :MODEL_UUID and http_method = :http_method";
465 query = getSession().createQuery(hql);
466 query.setParameter("MODEL_UUID", serviceNameVersionId);
468 serviceId = map.get("serviceId");
469 serviceVersion = map.get("serviceVersion");
470 LOGGER.debug("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
472 String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
473 query = getSession().createQuery(hql);
474 query.setParameter("service_id", serviceId);
475 query.setParameter("service_version", serviceVersion);
478 query.setParameter("http_method", httpMethod);
480 long startTime = System.currentTimeMillis();
481 Service service = null;
483 service = (Service) query.uniqueResult();
484 } catch (org.hibernate.NonUniqueResultException nure) {
485 LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
486 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);
489 } catch (org.hibernate.HibernateException he) {
490 LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + he.getMessage());
491 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);
494 } catch (Exception e) {
495 LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
496 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);
500 if (service == null) {
501 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
503 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
509 * Return the newest version of a Service (queried by Name).
512 * @return Service object or null if none found
514 public Service getServiceByModelName(String modelName){
516 long startTime = System.currentTimeMillis();
517 LOGGER.debug("Catalog database - get service with name " + modelName);
519 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
520 Query query = getSession().createQuery(hql);
521 query.setParameter("MODEL_NAME", modelName);
523 @SuppressWarnings("unchecked")
524 List <Service> resultList = query.list();
526 // See if something came back.
527 if (resultList.isEmpty()) {
528 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null);
531 Collections.sort(resultList, new MavenLikeVersioningComparator ());
532 Collections.reverse(resultList);
534 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null);
535 return resultList.get(0);
538 public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
539 long startTime = System.currentTimeMillis();
540 LOGGER.debug("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion);
542 String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR";
543 Query query = getSession().createQuery(hql);
544 query.setParameter("MODEL_INVARIANT_UUID", modelInvariantId);
545 query.setParameter("VERSION_STR", modelVersion);
547 Service result = null;
549 result = (Service) query.uniqueResult();
550 } catch (org.hibernate.NonUniqueResultException nure) {
551 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'", nure);
552 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantId=" + modelInvariantId + " and modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId);
553 throw new Exception("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
555 // See if something came back.
557 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null);
561 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null);
566 * Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
568 * @param serviceModelUUID
570 * @return ServiceRecipe object or null if none found
573 public ServiceRecipe getServiceRecipe (int serviceModelUUID, String action) {
578 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
580 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action ");
583 long startTime = System.currentTimeMillis ();
584 LOGGER.debug ("Catalog database - get Service recipe with serviceModelUUID " + Integer.toString(serviceModelUUID)
589 Query query = getSession ().createQuery (hql.toString ());
590 query.setParameter ("serviceModelUUID", serviceModelUUID);
592 query.setParameter (ACTION, action);
595 @SuppressWarnings("unchecked")
596 List <ServiceRecipe> resultList = query.list ();
598 if (resultList.isEmpty ()) {
599 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
603 Collections.sort (resultList, new MavenLikeVersioningComparator ());
604 Collections.reverse (resultList);
606 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
607 return resultList.get (0);
611 * Return a newest version of Service recipe that matches a given SERVICE_MODEL_UUID and ACTION
613 * @param serviceModelUuid
615 * @return ServiceRecipe object or null if none found
617 public ServiceRecipe getServiceRecipeByServiceModelUuid(String serviceModelUuid, String action) {
622 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid");
624 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action ");
627 long startTime = System.currentTimeMillis ();
628 LOGGER.debug("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid
633 Query query = getSession().createQuery(hql.toString());
634 query.setParameter("serviceModelUuid", serviceModelUuid);
636 query.setParameter(ACTION, action);
639 @SuppressWarnings("unchecked")
640 List <ServiceRecipe> resultList = query.list();
642 if (resultList.isEmpty()) {
643 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
647 Collections.sort(resultList, new MavenLikeVersioningComparator());
648 Collections.reverse(resultList);
650 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
651 return resultList.get(0);
654 public List<ServiceRecipe> getServiceRecipes(String serviceModelUuid) {
658 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
660 long startTime = System.currentTimeMillis();
661 LOGGER.debug("Catalog database - get Service recipe with serviceModelUUID " + serviceModelUuid);
663 Query query = getSession().createQuery(hql.toString());
664 query.setParameter("serviceModelUUID", serviceModelUuid);
666 @SuppressWarnings("unchecked")
667 List <ServiceRecipe> resultList = query.list();
669 if (resultList.isEmpty()) {
670 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null);
671 return Collections.EMPTY_LIST;
674 Collections.sort(resultList, new MavenLikeVersioningComparator());
675 Collections.reverse(resultList);
677 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null);
683 * Return the VNF component data - queried by the VNFs ID and the component type.
687 * @return VnfComponent object or null if none found
690 public VnfComponent getVnfComponent (int vnfId, String type) {
692 long startTime = System.currentTimeMillis();
693 LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
695 String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
696 Query query = getSession ().createQuery (hql);
697 query.setParameter ("vnf_id", vnfId);
698 query.setParameter ("type", type);
700 VnfComponent result = null;
702 result = (VnfComponent) query.uniqueResult();
703 } catch (org.hibernate.NonUniqueResultException nure) {
704 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
705 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);
708 } catch (org.hibernate.HibernateException he) {
709 LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + he.getMessage());
710 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);
713 } catch (Exception e) {
714 LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + e.getMessage());
715 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);
720 if (result != null) {
721 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
723 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
729 * Return the newest version of a specific VNF resource (queried by Name).
732 * @return VnfResource object or null if none found
734 public VnfResource getVnfResource (String vnfType) {
736 long startTime = System.currentTimeMillis();
737 LOGGER.debug("Catalog database - get vnf resource with model_name " + vnfType);
739 String hql = "FROM VnfResource WHERE modelName = :vnf_name";
740 Query query = getSession().createQuery(hql);
741 query.setParameter("vnf_name", vnfType);
743 @SuppressWarnings("unchecked")
744 List <VnfResource> resultList = query.list();
746 // See if something came back. Name is unique, so
747 if (resultList.isEmpty()) {
748 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
751 Collections.sort(resultList, new MavenLikeVersioningComparator());
752 Collections.reverse(resultList);
754 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
755 return resultList.get(0);
759 * Return the newest version of a specific VNF resource (queried by Name).
762 * @param serviceVersion
763 * @return VnfResource object or null if none found
765 public VnfResource getVnfResource (String vnfType, String serviceVersion) {
767 long startTime = System.currentTimeMillis();
768 LOGGER.debug("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion);
770 String hql = "FROM VnfResource WHERE modelName = :vnfName and version = :serviceVersion";
771 Query query = getSession().createQuery(hql);
772 query.setParameter("vnfName", vnfType);
773 query.setParameter("serviceVersion", serviceVersion);
775 VnfResource resource = null;
777 resource = (VnfResource) query.uniqueResult();
778 } catch (org.hibernate.NonUniqueResultException nure) {
779 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
780 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
783 } catch (org.hibernate.HibernateException he) {
784 LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "' " + he.getMessage());
785 LOGGER.debug(Arrays.toString(he.getStackTrace()));
786 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
789 } catch (Exception e) {
790 LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
791 LOGGER.debug(Arrays.toString(e.getStackTrace()));
792 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
796 if (resource == null) {
797 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
799 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
805 * Return VnfResource (queried by modelCustomizationId).
807 * @param modelCustomizationId
808 * @return VnfResource object or null if none found
810 public VnfResource getVnfResourceByModelCustomizationId(String modelCustomizationId) {
812 long startTime = System.currentTimeMillis();
813 LOGGER.debug("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
815 String hql = "SELECT vr "
816 + "FROM VnfResource as vr JOIN vr.vnfResourceCustomizations as vrc "
817 + "WHERE vrc.modelCustomizationUuid = :modelCustomizationId";
819 Query query = getSession().createQuery(hql);
820 query.setParameter("modelCustomizationId", modelCustomizationId);
822 VnfResource resource = null;
824 resource = (VnfResource) query.uniqueResult();
825 } catch(org.hibernate.NonUniqueResultException nure) {
826 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "'");
827 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
830 } catch (org.hibernate.HibernateException he) {
831 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
832 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationId=" + modelCustomizationId);
835 } catch (Exception e) {
836 LOGGER.debug("Generic Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
837 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationId=" + modelCustomizationId);
841 if (resource == null) {
842 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
844 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
851 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
853 * @return {@link VnfResourceCustomization} object or null if none found
855 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationName (String modelCustomizationName, String modelVersionId) {
857 long startTime = System.currentTimeMillis();
858 LOGGER.debug("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId);
860 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.modelCustomizationUuid IN "
861 + "(SELECT src.resourceModelCustomizationUUID FROM ServiceToResourceCustomization src "
862 + "WHERE src.serviceModelUUID = :modelVersionId)"
863 + "AND vrc.modelInstanceName = :modelCustomizationName";
865 Query query = getSession().createQuery(hql);
866 query.setParameter("modelCustomizationName", modelCustomizationName);
867 query.setParameter("modelVersionId", modelVersionId);
869 @SuppressWarnings("unchecked")
870 List<VnfResourceCustomization> resultList = query.list();
872 if (resultList.isEmpty()) {
873 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
877 Collections.sort(resultList, new MavenLikeVersioningComparator());
878 Collections.reverse(resultList);
880 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
881 return resultList.get(0);
886 * Return the newest version of a specific VNF resource (queried by modelInvariantId).
889 * @return VnfResource object or null if none found
891 public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) {
893 long startTime = System.currentTimeMillis ();
894 LOGGER.debug ("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
896 String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion";
897 Query query = getSession ().createQuery (hql);
898 query.setParameter ("modelInvariantUuid", modelInvariantUuid);
899 query.setParameter ("serviceVersion", modelVersion);
901 VnfResource resource = null;
903 resource = (VnfResource) query.uniqueResult ();
904 } catch (org.hibernate.NonUniqueResultException nure) {
905 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'");
906 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid);
909 } catch (org.hibernate.HibernateException he) {
910 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', asdc_service_model_version='" + modelVersion + "' " + he.getMessage());
911 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid);
914 } catch (Exception e) {
915 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "' " + e.getMessage());
916 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid);
920 if (resource == null) {
921 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
923 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
929 * Return the newest version of a specific VNF resource (queried by ID).
931 * @param id The vnf id
932 * @return VnfResource object or null if none found
935 public VnfResource getVnfResourceById (int id) {
937 long startTime = System.currentTimeMillis ();
938 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
940 String hql = "FROM VnfResource WHERE id = :id";
941 Query query = getSession ().createQuery (hql);
942 query.setParameter ("id", id);
944 @SuppressWarnings("unchecked")
945 List <VnfResource> resultList = query.list ();
947 // See if something came back. Name is unique, so
948 if (resultList.isEmpty ()) {
949 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
952 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
953 return resultList.get (0);
957 * Return the newest version of a vfModule - 1607
960 public VfModule getVfModuleModelName (String modelName) {
962 long startTime = System.currentTimeMillis ();
963 LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName);
965 String hql = "FROM VfModule WHERE modelName = :model_name";
966 Query query = getSession ().createQuery (hql);
967 query.setParameter ("model_name", modelName);
969 @SuppressWarnings("unchecked")
970 List <VfModule> resultList = query.list ();
972 // See if something came back. Name is unique, so
973 if (resultList.isEmpty ()) {
974 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
977 Collections.sort (resultList, new MavenLikeVersioningComparator ());
978 Collections.reverse (resultList);
980 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
981 return resultList.get (0);
984 public VfModule getVfModuleModelName (String modelName, String model_version) {
986 long startTime = System.currentTimeMillis ();
987 LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
989 String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
990 Query query = getSession ().createQuery (hql);
991 query.setParameter ("modelName", modelName);
992 query.setParameter ("model_version", model_version);
994 VfModule module = null;
996 module = (VfModule) query.uniqueResult ();
997 } catch (org.hibernate.NonUniqueResultException nure) {
998 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 + "'");
999 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
1002 } catch (org.hibernate.HibernateException he) {
1003 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + he.getMessage());
1004 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
1007 } catch (Exception e) {
1008 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + e.getMessage());
1009 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
1013 if (module == null) {
1014 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
1016 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
1022 * Need this for 1707 DHV. This may be a temporary solution. May
1023 * change it to get resources using service's model name.
1028 public VfModuleCustomization getVfModuleCustomizationByModelName (String modelName) {
1030 long startTime = System.currentTimeMillis ();
1031 LOGGER.debug ("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
1033 String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.modelName = :model_name";
1034 Query query = getSession ().createQuery (hql);
1035 query.setParameter ("model_name", modelName);
1037 @SuppressWarnings("unchecked")
1038 List<VfModuleCustomization> resultList = query.list();
1040 // See if something came back. Name is unique, so
1041 if (resultList.isEmpty ()) {
1042 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1046 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query ", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1047 return resultList.get(0);
1052 * Return the newest version of a specific Network resource (queried by Type).
1054 * @param networkType
1055 * @return NetworkResource object or null if none found
1057 public NetworkResource getNetworkResource (String networkType) {
1059 long startTime = System.currentTimeMillis ();
1060 LOGGER.debug ("Catalog database - get network resource with type " + networkType);
1062 String hql = "FROM NetworkResource WHERE model_name = :network_type";
1063 Query query = getSession ().createQuery (hql);
1064 query.setParameter ("network_type", networkType);
1066 @SuppressWarnings("unchecked")
1067 List <NetworkResource> resultList = query.list ();
1069 // See if something came back. Name is unique, so
1070 if (resultList.isEmpty ()) {
1071 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
1075 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1076 Collections.reverse (resultList);
1077 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
1078 return resultList.get (0);
1082 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
1086 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
1087 * @return VnfRecipe object or null if none found
1089 public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) {
1090 boolean withServiceType = false;
1092 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1095 if (serviceType == null || serviceType.isEmpty ()) {
1096 hql.append ("AND serviceType is NULL ");
1098 hql.append ("AND serviceType = :serviceType ");
1099 withServiceType = true;
1102 long startTime = System.currentTimeMillis ();
1103 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
1106 + " and service type "
1109 Query query = getSession ().createQuery (hql.toString ());
1110 query.setParameter (VNF_TYPE, vnfType);
1111 query.setParameter (ACTION, action);
1112 if (withServiceType) {
1113 query.setParameter (SERVICE_TYPE, serviceType);
1116 @SuppressWarnings("unchecked")
1117 List <VnfRecipe> resultList = query.list ();
1119 if (resultList.isEmpty ()) {
1120 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1124 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1125 Collections.reverse (resultList);
1127 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1128 return resultList.get (0);
1132 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
1136 * @return VnfRecipe object or null if none found
1138 public VnfRecipe getVnfRecipe (String vnfType, String action) {
1139 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1141 long startTime = System.currentTimeMillis ();
1142 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
1146 Query query = getSession ().createQuery (hql.toString ());
1147 query.setParameter (VNF_TYPE, vnfType);
1148 query.setParameter (ACTION, action);
1150 @SuppressWarnings("unchecked")
1151 List <VnfRecipe> resultList = query.list ();
1153 if (resultList.isEmpty ()) {
1154 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1158 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1159 Collections.reverse (resultList);
1161 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1162 return resultList.get (0);
1166 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
1170 * @return VnfRecipe object or null if none found
1172 public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) {
1174 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
1176 long startTime = System.currentTimeMillis ();
1177 LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
1179 Query query = getSession ().createQuery (hql.toString ());
1180 query.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
1181 query.setParameter (ACTION, action);
1183 @SuppressWarnings("unchecked")
1184 List <VnfRecipe> resultList = query.list ();
1186 if (resultList.isEmpty ()) {
1187 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1191 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1192 Collections.reverse (resultList);
1194 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1195 return resultList.get (0);
1198 public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
1199 long startTime = System.currentTimeMillis();
1200 LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
1202 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
1203 Query query = getSession().createQuery(hql);
1204 query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
1206 VfModule module = null;
1208 module = (VfModule) query.uniqueResult();
1209 } catch (org.hibernate.NonUniqueResultException nure) {
1210 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1211 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1214 } catch (org.hibernate.HibernateException he) {
1215 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1216 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1219 } catch (Exception e) {
1220 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1221 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1225 if (module == null) {
1226 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
1228 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
1234 public VfModule getVfModuleType(String type) {
1235 long startTime = System.currentTimeMillis();
1236 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
1238 String hql = "FROM VfModule WHERE type = :type";
1239 Query query = getSession().createQuery(hql);
1240 query.setParameter("type", type);
1242 @SuppressWarnings("unchecked")
1243 List<VfModule> resultList = query.list();
1244 if (resultList.isEmpty()) {
1245 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
1248 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1249 Collections.reverse (resultList);
1251 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1252 return resultList.get (0);
1256 public VfModule getVfModuleType(String type, String version) {
1258 long startTime = System.currentTimeMillis();
1259 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
1261 String hql = "FROM VfModule WHERE type = :type and version = :version";
1262 Query query = getSession().createQuery(hql);
1263 query.setParameter ("type", type);
1264 query.setParameter ("version", version);
1265 VfModule module = null;
1267 module = (VfModule) query.uniqueResult ();
1268 } catch (org.hibernate.NonUniqueResultException nure) {
1269 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 + "'");
1270 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
1273 } catch (org.hibernate.HibernateException he) {
1274 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + he.getMessage());
1275 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
1278 } catch (Exception e) {
1279 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + e.getMessage());
1280 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
1284 if (module == null) {
1285 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1287 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1292 public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
1293 long startTime = System.currentTimeMillis();
1294 LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
1296 String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
1297 Query query = getSession().createQuery(hql);
1298 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1299 VnfResource vnfResource = null;
1301 vnfResource = (VnfResource) query.uniqueResult ();
1302 } catch (org.hibernate.NonUniqueResultException nure) {
1303 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1304 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
1307 } catch (org.hibernate.HibernateException he) {
1308 LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + he.getMessage());
1309 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1312 } catch (Exception e) {
1313 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + e.getMessage());
1314 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1318 if (vnfResource == null) {
1319 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1321 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1326 public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
1327 long startTime = System.currentTimeMillis();
1328 LOGGER.debug ("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
1330 String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
1331 Query query = getSession().createQuery(hql);
1332 query.setParameter ("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
1333 VnfResource vnfResource = null;
1335 vnfResource = (VnfResource) query.uniqueResult ();
1336 } catch (org.hibernate.NonUniqueResultException nure) {
1337 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
1338 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
1341 } catch (org.hibernate.HibernateException he) {
1342 LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + he.getMessage());
1343 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1346 } catch (Exception e) {
1347 LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + e.getMessage());
1348 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1352 if (vnfResource == null) {
1353 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1355 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1360 public VnfResource getVnfResourceByType(String vnfType) {
1361 return this.getVnfResource(vnfType);
1364 public VfModule getVfModuleByModelInvariantUuid(String modelInvariantUUID) {
1365 long startTime = System.currentTimeMillis();
1366 LOGGER.debug ("Catalog database - get vfModuleTypeByModelInvariantUuid with uuid " + modelInvariantUUID);
1368 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUUID ";
1369 HashMap<String, String> parameters = new HashMap<>();
1370 parameters.put("modelInvariantUUID", modelInvariantUUID);
1371 List<VfModule> modules = this.executeQueryMultipleRows(hql, parameters, true);
1372 VfModule module = null;
1374 if (modules != null && ! modules.isEmpty()) {
1375 Collections.sort (modules, new MavenLikeVersioningComparator ());
1376 Collections.reverse (modules);
1377 module = modules.get(0);
1380 if (module == null) {
1381 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1383 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1388 public VfModuleCustomization getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
1389 long startTime = System.currentTimeMillis();
1390 LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
1392 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid ";
1393 Query query = getSession().createQuery(hql);
1394 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1395 VfModuleCustomization module = null;
1397 module = (VfModuleCustomization) query.uniqueResult ();
1398 } catch (org.hibernate.NonUniqueResultException nure) {
1399 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1400 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1403 } catch (org.hibernate.HibernateException he) {
1404 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1405 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1408 } catch (Exception e) {
1409 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1410 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1414 if (module == null) {
1415 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1417 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1423 public VfModule getVfModuleByModelInvariantUuidAndModelVersion(String modelInvariantUuid, String modelVersion) {
1424 long startTime = System.currentTimeMillis();
1425 LOGGER.debug ("Catalog database - get getVfModuleByModelInvariantUuidAndModelVersion with modelInvariantUuid: " + modelInvariantUuid + ", modelVersion: " + modelVersion);
1427 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUuid and version = :modelVersion";
1428 Query query = getSession().createQuery(hql);
1429 query.setParameter ("modelInvariantUuid", modelInvariantUuid);
1430 query.setParameter("modelVersion", modelVersion);
1431 VfModule module = null;
1433 module = (VfModule) query.uniqueResult ();
1434 } catch (org.hibernate.NonUniqueResultException nure) {
1435 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "'");
1436 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModule ModelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for ModelInvariantUuid==" + modelInvariantUuid + " modelVersion==" + modelVersion);
1438 } catch (org.hibernate.HibernateException he) {
1439 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + he.getMessage());
1440 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1442 } catch (Exception e) {
1443 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + e.getMessage());
1444 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1447 if (module == null) {
1448 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1450 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1456 * Return the VfModuleCustomization object identified by the given modelCustomizationUuid 1707
1458 * @param modelCustomizationUuid
1459 * @return VfModuleCustomization or null if not found
1461 public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {
1462 long startTime = System.currentTimeMillis();
1463 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByModelCustomizationId with modelCustomizationUuid: " + modelCustomizationUuid);
1465 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1466 Query query = getSession().createQuery(hql);
1467 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1468 VfModuleCustomization VfModuleCustomization = null;
1470 VfModuleCustomization = (VfModuleCustomization) query.uniqueResult ();
1471 } catch (org.hibernate.NonUniqueResultException nure) {
1472 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1473 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1475 } catch (org.hibernate.HibernateException he) {
1476 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1477 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1479 } catch (Exception e) {
1480 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1481 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1484 if (VfModuleCustomization != null) {
1485 LOGGER.debug("Found VMC of " + VfModuleCustomization.getModelCustomizationUuid() + ", now looking for vfModule=" + VfModuleCustomization.getVfModuleModelUuid());
1486 VfModuleCustomization.setVfModule(this.getVfModuleByModelUuid(VfModuleCustomization.getVfModuleModelUuid()));
1489 if (VfModuleCustomization == null) {
1490 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1492 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1494 return VfModuleCustomization;
1498 * Return the VfModule object identified by the given modelUuid 1707
1499 * per Mike Z. - this may return more than one row - and even if it does,
1500 * the heat template will be the same - so just return any of the rows.
1503 * @return VfModule or null if not found
1505 public VfModule getVfModuleByModelUuid(String modelUuid) {
1506 long startTime = System.currentTimeMillis();
1507 LOGGER.debug ("Catalog database - get getVfModuleByModelUuid with modelUuid: " + modelUuid);
1509 String hql = "FROM VfModule WHERE modelUUID = :modelUuidValue";
1510 Query query = getSession().createQuery(hql);
1511 query.setParameter ("modelUuidValue", modelUuid);
1512 List<VfModule> vfModules = null;
1514 vfModules = query.list ();
1515 } catch (org.hibernate.HibernateException he) {
1516 LOGGER.debug("Hibernate Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + he.getMessage());
1517 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VfModule for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUuid=" + modelUuid);
1519 } catch (Exception e) {
1520 LOGGER.debug("Generic Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + e.getMessage());
1521 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUuid=" + modelUuid);
1525 if (vfModules == null || vfModules.isEmpty()) {
1526 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelUuid", null);
1529 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUuid", null);
1531 return vfModules.get(0);
1534 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1535 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1537 * @param modelCustomizationUuid
1538 * @return VnfResourceCustomization or null if not found
1540 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUuid(String modelCustomizationUuid) {
1541 long startTime = System.currentTimeMillis();
1542 LOGGER.debug ("Catalog database - get getVnfResourceByModelCustomizatonUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1544 String hql = "FROM VnfResourceCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1545 Query query = getSession().createQuery(hql);
1546 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1547 VnfResourceCustomization vnfResourceCustomization = null;
1549 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1550 } catch (org.hibernate.NonUniqueResultException nure) {
1551 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1552 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1554 } catch (org.hibernate.HibernateException he) {
1555 LOGGER.debug("Hibernate Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1556 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1558 } catch (Exception e) {
1559 LOGGER.debug("Generic Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1560 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1563 if (vnfResourceCustomization != null) {
1564 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1565 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1566 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1567 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1570 if (vnfResourceCustomization == null) {
1571 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1573 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1575 return vnfResourceCustomization;
1579 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1580 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1582 * @param getVnfResourceCustomizationByModelVersionId
1583 * @return VnfResourceCustomization or null if not found
1585 public VnfResourceCustomization getVnfResourceCustomizationByModelVersionId(String modelVersionId) {
1586 long startTime = System.currentTimeMillis();
1587 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelVersionId with modelVersionId: " + modelVersionId);
1589 String hql = "FROM VnfResourceCustomization WHERE vnfResourceModelUuid = :modelVersionId";
1590 Query query = getSession().createQuery(hql);
1591 query.setParameter ("modelVersionId", modelVersionId);
1592 VnfResourceCustomization vnfResourceCustomization = null;
1594 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1595 } catch (org.hibernate.NonUniqueResultException nure) {
1596 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"'");
1597 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId==" + modelVersionId);
1599 } catch (org.hibernate.HibernateException he) {
1600 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + he.getMessage());
1601 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId);
1603 } catch (Exception e) {
1604 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + e.getMessage());
1605 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId);
1608 if (vnfResourceCustomization != null) {
1609 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1610 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1611 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1612 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1615 if (vnfResourceCustomization == null) {
1616 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1618 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1620 return vnfResourceCustomization;
1624 * Return the VfModule object identified by the given modelCustomizationId, modelVersionId 1707
1626 * @param modelVersionId, modelCustomizationId
1627 * @return VfModule or null if not found
1629 public VfModule getVfModuleByModelCustomizationIdAndVersion(String modelCustomizationId, String modelVersionId) {
1630 long startTime = System.currentTimeMillis();
1631 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdAndVersion with modelVersionId: " + modelVersionId + " modelCustomizationId: " + modelCustomizationId);
1633 // select * from vf_module vfm where vfm.MODEL_UUID IN (
1634 // select vfmc.VF_MODULE_MODEL_UUID from vf_module_customization vfmc where vfmc.MODEL_CUSTOMIZATION_UUID='222bd8f2-341d-4419-aa0e-98398fa34050')
1635 // and vfm.MODEL_UUID = 'fa1c8558-006c-4fb6-82f2-4fc0646d6b06';
1637 String hql = "Select vfm FROM VfModule as vfm WHERE vfm.modelUUID IN ("
1638 + "SELECT vfmc.vfModuleModelUuid FROM VfModuleCustomization as vfmc "
1639 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId) "
1640 + "AND vfm.modelUUID = :modelVersionId";
1641 Query query = getSession().createQuery(hql);
1642 query.setParameter ("modelVersionId", modelVersionId);
1643 query.setParameter ("modelCustomizationId", modelCustomizationId);
1644 VfModule vfModule = null;
1646 vfModule = (VfModule) query.uniqueResult ();
1647 } catch (org.hibernate.NonUniqueResultException nure) {
1648 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"' modelCustomizationId='" + modelCustomizationId + "'");
1649 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1651 } catch (org.hibernate.HibernateException he) {
1652 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1653 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1655 } catch (Exception e) {
1656 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1657 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1661 if (vfModule == null) {
1662 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1664 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1670 * Return the VfModule object identified by the given modelCustomizationId, modelVersion, modelInvariantId 1707
1672 * @param modelCustomizationId, modelVersion, modelInvariantId
1673 * @return VfModule or null if not found
1675 public VfModule getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId(String modelCustomizationId, String modelVersion, String modelInvariantId) {
1676 long startTime = System.currentTimeMillis();
1677 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId with modelVersionId: " + modelVersion);
1679 //select * from vf_module vfm left outer join vf_module_customization vfmc on vfmc.VF_MODULE_MODEL_UUID = vfm.MODEL_UUID
1680 // where vfmc.MODEL_CUSTOMIZATION_UUID='52643a8e-7953-4e48-8eab-97165b2b3a4b' and vfm.MODEL_UUID = ''
1682 String hql = "Select vfm FROM VfModule as vfm LEFT OUTER JOIN VfModuleCustomization as vfmc on vfmc.vfModuleModelUuid = vfm.modelUUID"
1683 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId AND vfm.modelInvariantUUID = :modelInvariantId AND vfm.modelVersion = :modelVersion";
1684 Query query = getSession().createQuery(hql);
1685 query.setParameter ("modelInvariantId", modelInvariantId);
1686 query.setParameter ("modelCustomizationId", modelCustomizationId);
1687 query.setParameter ("modelVersion", modelVersion);
1688 VfModule vfModule = null;
1690 vfModule = (VfModule) query.uniqueResult ();
1691 } catch (org.hibernate.NonUniqueResultException nure) {
1692 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelInvariantId='" + modelInvariantId +"' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId +"'");
1693 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId + " modelVersion=" + modelVersion + " modelCustomizationId=" + modelCustomizationId);
1695 } catch (org.hibernate.HibernateException he) {
1696 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1697 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantId=" + modelInvariantId + " modelVersion=" + modelVersion + " modelCustomizationId=" + modelCustomizationId);
1699 } catch (Exception e) {
1700 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1701 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantId=" + modelInvariantId + " modelVersion=" + modelVersion + " modelCustomizationId=" + modelCustomizationId);
1705 if (vfModule == null) {
1706 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1708 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1714 * Return the VnfResourceCustomization object identified by the given modelCustomizationName, modelInvariantId and modelVersion 1707
1716 * @param modelInvariantId, modelVersion, modelCustomizationName
1717 * @return VnfResourceCustomization or null if not found
1719 public VnfResourceCustomization getVnfResourceCustomizationByModelInvariantId(String modelInvariantId, String modelVersion, String modelCustomizationName) {
1720 long startTime = System.currentTimeMillis();
1721 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelInvariantId with modelInvariantId: " + modelInvariantId + ", modelVersion: "
1722 + modelVersion + ", modelCustomizationName: " + modelCustomizationName);
1724 String hql = "SELECT VnfResourceCustomization FROM VnfResourceCustomization as vrc "
1725 + "LEFT OUTER JOIN VnfResource as vr "
1726 + "on vr.modelUuid =vrc.vnfResourceModelUuid "
1727 + "WHERE vr.modelInvariantUuid = :modelInvariantId AND vr.modelVersion = :modelVersion AND vrc.modelInstanceName = :modelCustomizationName";
1729 Query query = getSession().createQuery(hql);
1730 query.setParameter ("modelInvariantId", modelInvariantId);
1731 query.setParameter("modelVersion", modelVersion);
1732 query.setParameter("modelCustomizationName", modelCustomizationName);
1733 VnfResourceCustomization vnfResourceCustomization = null;
1735 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1736 } catch (org.hibernate.NonUniqueResultException nure) {
1737 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' modelCustomizationName='" + modelCustomizationName + "'");
1738 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId==" + modelInvariantId+"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "'");
1740 } catch (org.hibernate.HibernateException he) {
1741 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "' " + he.getMessage());
1742 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantId=" + modelInvariantId+"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "'");
1744 } catch (Exception e) {
1745 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' " + e.getMessage());
1746 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantId=" + modelInvariantId+"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "'");
1749 if (vnfResourceCustomization != null) {
1750 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1751 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUUID()));
1752 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1753 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1756 if (vnfResourceCustomization == null) {
1757 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1759 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1761 return vnfResourceCustomization;
1765 * Return list of VnfResourceCustomization objects identified by the given modelCustomizationUuid 1707
1767 * @param modelCustomizationUuid
1768 * @return List<VfModuleCustomization> or null if not found
1770 public List<VfModuleCustomization> getVfModuleCustomizationByVnfModuleCustomizationUuid(String modelCustomizationUuid) {
1771 long startTime = System.currentTimeMillis();
1772 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByVnfModuleCustomizationUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1774 // select * from vf_module_customization as vfmc where vfmc.MODEL_CUSTOMIZATION_UUID IN(
1775 // select vrcmc.VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID from vnf_res_custom_to_vf_module_custom as vrcmc
1776 // where vrcmc.VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID = 'd279139c-4b85-48ff-8ac4-9b83a6fc6da7')
1778 String hql = "SELECT vfmc FROM VfModuleCustomization as vfmc where vfmc.modelCustomizationUuid "
1779 + "IN(select vrcmc.vfModuleCustModelCustomizationUuid from VnfResCustomToVfModuleCustom as vrcmc "
1780 + "WHERE vrcmc.vnfResourceCustModelCustomizationUuid = :modelCustomizationUuid)";
1782 Query query = getSession().createQuery(hql);
1783 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1784 List<VfModuleCustomization> resultList = null;
1786 resultList = query.list();
1787 } catch (org.hibernate.HibernateException he) {
1788 LOGGER.debug("Hibernate Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + he.getMessage());
1789 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1791 } catch (Exception e) {
1792 LOGGER.debug("Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + e.getMessage());
1793 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1797 if (resultList == null) {
1798 resultList = new ArrayList<>();
1800 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByVnfModuleCustomizationUuid", null);
1805 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
1807 * @return {@link VnfResourceCustomization} object or null if none found
1809 public VnfResourceCustomization getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId (String modelCustomizationName, String modelVersionId) {
1811 long startTime = System.currentTimeMillis ();
1812 LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " modelUUID " + modelVersionId);
1814 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.vnfResourceModelUuid IN "
1815 + "(SELECT vr.modelUuid FROM VnfResource vr "
1816 + "WHERE vr.modelUuid = :modelVersionId)"
1817 + "AND vrc.modelInstanceName = :modelCustomizationName";
1819 Query query = getSession ().createQuery (hql);
1820 query.setParameter ("modelCustomizationName", modelCustomizationName);
1821 query.setParameter ("modelVersionId", modelVersionId);
1823 @SuppressWarnings("unchecked")
1824 List <VnfResourceCustomization> resultList = query.list ();
1826 if (resultList.isEmpty ()) {
1827 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1831 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1832 Collections.reverse (resultList);
1834 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1835 return resultList.get (0);
1838 public ArrayList<VfModuleCustomization> getAllVfModuleCustomizations(String vnfResourceCustomizationMCU) {
1839 LOGGER.debug ("Catalog database - getAllVfModuleCustomizations with vnfResourceCustomizationMCU " + vnfResourceCustomizationMCU);
1841 List<VnfResCustomToVfModuleCustom> matches = this.getVRCtoVFMC(vnfResourceCustomizationMCU, null);
1842 if (matches == null || matches.isEmpty()) {
1843 LOGGER.debug("Found no vf modules for " + vnfResourceCustomizationMCU);
1844 return new ArrayList<>();
1846 ArrayList<VfModuleCustomization> list = new ArrayList<>();
1847 for (VnfResCustomToVfModuleCustom v : matches) {
1848 String m = v.getVfModuleCustModelCustomizationUuid();
1849 LOGGER.debug("VfModule to match: " + m);
1850 VfModuleCustomization c = this.getVfModuleCustomizationByModelCustomizationId(m);
1854 LOGGER.debug("**UNABLE to find vfModule " + m);
1861 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1862 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1864 * @param modelCustomizationUuid
1865 * @return VnfResourceCustomization or null if not found
1867 public VnfResource getVnfResourceByModelUuid(String modelUuid) {
1868 long startTime = System.currentTimeMillis();
1869 LOGGER.debug ("Catalog database - get VnfResource with modelUuid " + modelUuid);
1871 String hql = "FROM VnfResource WHERE modelUuid = :modelUuid";
1872 Query query = getSession().createQuery(hql);
1873 query.setParameter ("modelUuid", modelUuid);
1874 VnfResource vnfResource = null;
1876 vnfResource = (VnfResource) query.uniqueResult ();
1877 } catch (org.hibernate.NonUniqueResultException nure) {
1878 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique Vnf_Resource row - data integrity error: modelUuid='" + modelUuid);
1879 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for Vnf Resource modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResource modelUuid==" + modelUuid);
1881 } catch (org.hibernate.HibernateException he) {
1882 LOGGER.debug("Hibernate Exception - while searching for: VnfResource modelUuid='" + modelUuid + "' " + he.getMessage());
1883 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResource modelUuid=" + modelUuid);
1885 } catch (Exception e) {
1886 LOGGER.debug("Generic Exception - while searching for: vnfResource ModelUuid='" + modelUuid + "'");
1887 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResource modelUuid=" + modelUuid);
1890 if (vnfResource == null) {
1891 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelUuid", null);
1893 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelUuid", null);
1898 public VnfResCustomToVfModuleCustom getVnfResCustomToVfModule(String vnfId, String vfId) {
1899 long startTime = System.currentTimeMillis();
1900 LOGGER.debug("Catalog database - getVnfResCustomToVfModule - vnfResourceCustModelCustUuid: " + vnfId + ", vfModuleCustModelCustomUuid=" + vfId);
1901 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue");
1902 HashMap<String, String> parameters = new HashMap<>();
1903 parameters.put("vnfIdValue", vnfId);
1904 parameters.put("vfIdValue", vfId);
1905 VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow(hql.toString(), parameters, true);
1906 if (vrctvmc == null) {
1907 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResCustomToVfModule", null);
1909 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResCustomToVfModule", null);
1914 public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
1915 if (vnfResource == null)
1916 return Collections.EMPTY_LIST;
1917 String vnfResourceModelUuid = vnfResource.getModelUuid();
1919 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
1921 return this.getVfModulesForVnfResource(vnfResourceModelUuid);
1925 public List<VfModule> getVfModulesForVnfResource(String vnfResourceModelUuid) {
1926 long startTime = System.currentTimeMillis();
1927 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceModelUuid: " + vnfResourceModelUuid);
1928 StringBuilder hql = new StringBuilder("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId");
1929 Query query = getSession().createQuery(hql.toString());
1930 query.setParameter("vnfResourceModelUUId", vnfResourceModelUuid);
1931 List<VfModule> resultList = null;
1933 resultList = query.list();
1934 if (resultList != null)
1935 LOGGER.debug("\tQuery found " + resultList.size() + " records.");
1937 LOGGER.debug("\tQuery found no records.");
1938 } catch (org.hibernate.HibernateException he) {
1939 LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + he.getMessage());
1940 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1942 } catch (Exception e) {
1943 LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + e.getMessage());
1944 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1947 if (resultList == null) {
1948 resultList = new ArrayList<>();
1950 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
1954 public Service getServiceByUuid (String serviceModelInvariantUuid) {
1956 long startTime = System.currentTimeMillis ();
1957 LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
1959 String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
1960 Query query = getSession ().createQuery (hql);
1961 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1963 Service service = null;
1965 service = (Service) query.uniqueResult ();
1966 } catch (org.hibernate.NonUniqueResultException nure) {
1967 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1968 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1970 } catch (org.hibernate.HibernateException he) {
1971 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "' " + he.getMessage());
1972 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1974 } catch (Exception e) {
1975 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + " " + e.getMessage());
1976 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1979 if (service == null) {
1980 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
1982 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
1988 public NetworkResource getNetworkResourceById(Integer id) {
1989 long startTime = System.currentTimeMillis ();
1990 LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
1992 String hql = "FROM NetworkResource WHERE id = :id";
1993 Query query = getSession ().createQuery (hql);
1994 query.setParameter ("id", id);
1996 NetworkResource networkResource = null;
1998 networkResource = (NetworkResource) query.uniqueResult ();
1999 } catch (org.hibernate.NonUniqueResultException nure) {
2000 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
2001 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
2003 } catch (org.hibernate.HibernateException he) {
2004 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2005 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
2007 } catch (Exception e) {
2008 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2009 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
2013 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2014 return networkResource;
2018 public NetworkResource getNetworkResourceById(String id) {
2019 long startTime = System.currentTimeMillis ();
2020 LOGGER.debug ("Catalog database - getNetworkResource with model_uuid " + id);
2022 String hql = "FROM NetworkResource WHERE modelUUID = :model_uuid";
2023 Query query = getSession ().createQuery (hql);
2024 query.setParameter ("model_uuid", id);
2026 List<NetworkResource> networkResources = null;
2028 networkResources = query.list ();
2029 } catch (org.hibernate.HibernateException he) {
2030 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2031 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.model_uuid=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.model_uuid=" + id);
2033 } catch (Exception e) {
2034 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2035 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.model_uuid=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.model_uuid=" + id);
2039 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2040 if (networkResources == null || networkResources.isEmpty())
2043 return networkResources.get(0);
2048 public static boolean isEmptyOrNull(String str) {
2051 if ("null".equals(str))
2058 public List<ServiceToResourceCustomization> getSTR(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
2059 LOGGER.debug("Catalog database: getSTR - smu=" + serviceModelUuid + ", rmcu=" + resourceModelCustomizationUuid + ", modelType = " + modelType);
2061 if (isEmptyOrNull(serviceModelUuid) && isEmptyOrNull(resourceModelCustomizationUuid) && isEmptyOrNull(modelType))
2064 StringBuilder hql = new StringBuilder("FROM ServiceToResourceCustomization WHERE ");
2065 boolean first = true;
2066 if (serviceModelUuid != null && !serviceModelUuid.equals("")) {
2067 hql.append("serviceModelUUID = :smu");
2070 if (resourceModelCustomizationUuid != null && !resourceModelCustomizationUuid.equals("")) {
2072 hql.append(" AND ");
2074 hql.append("resourceModelCustomizationUUID = :rmcu");
2077 if (modelType != null && !modelType.equals("")) {
2079 hql.append(" AND ");
2082 hql.append("modelType = :modelType");
2085 Query query = getSession().createQuery(hql.toString());
2086 if (hql.toString().contains(":smu"))
2087 query.setParameter("smu", serviceModelUuid);
2088 if (hql.toString().contains(":rmcu"))
2089 query.setParameter("rmcu", resourceModelCustomizationUuid);
2090 if (hql.toString().contains(":modelType"))
2091 query.setParameter("modelType", modelType);
2092 LOGGER.debug("query - " + hql.toString());
2094 @SuppressWarnings("unchecked")
2095 List<ServiceToResourceCustomization> resultList = query.list();
2096 if (resultList == null || resultList.isEmpty()) {
2097 LOGGER.debug("Found no matches to the query - " + hql.toString());
2098 return new ArrayList<>();
2103 public List<VnfResCustomToVfModuleCustom> getVRCtoVFMC (String vrc_mcu, String vfmc_mcu) {
2104 LOGGER.debug("Catalog database: getVRCtoVFMC - vrc_mcu=" + vrc_mcu + ", vfmc_mcu=" + vfmc_mcu);
2106 if (isEmptyOrNull(vrc_mcu) && isEmptyOrNull(vfmc_mcu))
2109 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom WHERE ");
2110 boolean first = true;
2111 if (vrc_mcu != null && !vrc_mcu.equals("")) {
2112 hql.append("vnfResourceCustModelCustomizationUuid = :vrc_mcu");
2115 if (vfmc_mcu != null && !vfmc_mcu.equals("")) {
2117 hql.append(" AND ");
2119 hql.append("vfModuleCustModelCustomizationUuid = :vfmc_mcu");
2122 Query query = getSession().createQuery(hql.toString());
2123 if (hql.toString().contains(":vrc_mcu"))
2124 query.setParameter("vrc_mcu", vrc_mcu);
2125 if (hql.toString().contains(":vfmc_mcu"))
2126 query.setParameter("vfmc_mcu", vfmc_mcu);
2127 @SuppressWarnings("unchecked")
2128 List<VnfResCustomToVfModuleCustom> resultList = query.list();
2129 if (resultList == null || resultList.isEmpty()) {
2130 LOGGER.debug("Found no matches to the query - " + hql.toString());
2131 return new ArrayList<>();
2136 @SuppressWarnings("unchecked")
2137 public List <TempNetworkHeatTemplateLookup> getTempNetworkHeatTemplateLookup (String networkResourceModelName) {
2139 long startTime = System.currentTimeMillis ();
2140 LOGGER.debug ("Catalog database - GetTempNetworkHeatTemplateLookup for Network Name " + networkResourceModelName);
2142 String hql = "FROM TempNetworkHeatTemplateLookup where networkResourceModelName = :networkResourceModelName";
2143 Query query = getSession ().createQuery (hql);
2144 query.setParameter ("networkResourceModelName", networkResourceModelName);
2146 List <TempNetworkHeatTemplateLookup> result = query.list ();
2147 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getTempNetworkHeatTemplateLookup", null);
2151 // 1702 API Spec - Query for all networks in a Service:
2152 public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
2153 long startTime = System.currentTimeMillis();
2154 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
2156 List<ServiceToResourceCustomization> strMappings = this.getSTR(serviceModelUuid, null, "network");
2157 if (strMappings == null || strMappings.isEmpty()) {
2158 LOGGER.debug("Found NO matches for NRC with ServiceModelUuid=" + serviceModelUuid);
2159 return new ArrayList<>();
2161 LOGGER.debug("Found " + strMappings.size() + " entries in ServiceToResourceCustomizations.network with smu=" + serviceModelUuid);
2163 ArrayList<NetworkResourceCustomization> masterList = new ArrayList<>();
2164 for (ServiceToResourceCustomization stn : strMappings) {
2165 String networkModelCustomizationUuid = stn.getResourceModelCustomizationUUID();
2166 LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
2167 List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
2168 for (NetworkResourceCustomization nrc : resultSet) {
2169 masterList.add(nrc);
2172 LOGGER.debug("Returning " + masterList.size() + " NRC records");
2173 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
2176 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2177 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2179 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2180 Query query = getSession().createQuery(hql.toString());
2181 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2182 @SuppressWarnings("unchecked")
2183 List<Service> serviceList = query.list();
2185 if (serviceList.isEmpty()) {
2186 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2187 return new ArrayList<>();
2190 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2191 Collections.reverse (serviceList);
2192 Service service = serviceList.get(0);
2194 String serviceNameVersionId = service.getModelUUID();
2195 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
2197 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2198 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2200 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2201 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2203 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2204 Query query = getSession().createQuery(hql.toString());
2205 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2206 query.setParameter("serviceModelVersion", serviceModelVersion);
2209 //can fix this later - no time - could do a unique query here - but this should work
2210 @SuppressWarnings("unchecked")
2211 List<Service> serviceList = query.list();
2213 if (serviceList.isEmpty()) {
2214 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2215 return new ArrayList<>();
2218 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2219 Collections.reverse (serviceList);
2220 Service service = serviceList.get(0);
2222 String serviceNameVersionId = service.getModelUUID();
2224 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2225 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2228 public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
2229 long startTime = System.currentTimeMillis();
2230 LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
2232 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid");
2233 //Query query = getSession().createQuery(hql.toString());
2234 //query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
2235 //LOGGER.debug("QUERY: " + hql.toString() + ", networkModelCustomizationUuid=" + networkModelCustomizationUuid);
2237 //@SuppressWarnings("unchecked")
2238 //List<NetworkResourceCustomization> resultList = query.list();
2240 HashMap<String, String> params = new HashMap<>();
2241 params.put("networkModelCustomizationUuid", networkModelCustomizationUuid);
2243 List<NetworkResourceCustomization> resultList = this.executeQueryMultipleRows(hql.toString(), params, true);
2245 if (resultList.isEmpty()) {
2246 LOGGER.debug("Unable to find an NMC with nmcu=" + networkModelCustomizationUuid);
2247 return new ArrayList<>();
2249 for (NetworkResourceCustomization nrc : resultList) {
2250 nrc.setNetworkResource(this.getNetworkResourceById(nrc.getNetworkResourceModelUuid()));
2254 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
2258 public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
2259 long startTime = System.currentTimeMillis();
2260 LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
2262 NetworkResource nr = this.getNetworkResource(networkType);
2264 return new ArrayList<>();
2266 String networkResourceId = nr.getModelUUID();
2268 LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
2269 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId");
2271 Query query = getSession().createQuery(hql.toString());
2272 query.setParameter("networkResourceId", networkResourceId);
2274 @SuppressWarnings("unchecked")
2275 List<NetworkResourceCustomization> resultList = query.list();
2277 if (resultList != null && ! resultList.isEmpty()) {
2278 LOGGER.debug("Found " + resultList.size() + " results");
2279 for (NetworkResourceCustomization nrc : resultList) {
2280 nrc.setNetworkType(networkType);
2281 nrc.setNetworkResource(nr);
2284 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
2288 public ArrayList<VfModuleCustomization> getAllVfmcForVrc(VnfResourceCustomization vrc) {
2289 LOGGER.debug("Catalog database: getAllVfmcForVrc - " + vrc.getModelCustomizationUuid());
2291 List<VnfResCustomToVfModuleCustom> vfmcs = this.getVRCtoVFMC(vrc.getModelCustomizationUuid(), null);
2292 if (vfmcs == null || vfmcs.isEmpty()) {
2293 return new ArrayList<>();
2295 ArrayList<VfModuleCustomization> vfModuleCusts = new ArrayList<>();
2296 for (VnfResCustomToVfModuleCustom vfmc : vfmcs) {
2297 VfModuleCustomization vfmcust = this.getVfModuleCustomizationByModelCustomizationId(vfmc.getVfModuleCustModelCustomizationUuid());
2298 if (vfmcust != null) {
2299 vfModuleCusts.add(vfmcust);
2302 return vfModuleCusts;
2305 //1702 API Spec cont'd - Query for all VnfResources in a Service:
2306 //1707 modified for db refactoring
2307 public List<VnfResourceCustomization> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
2308 LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
2310 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2311 Query query = getSession().createQuery(hql.toString());
2312 query.setParameter("serviceModelUuid", serviceModelUuid);
2313 @SuppressWarnings("unchecked")
2314 List<Service> serviceList = query.list();
2316 if (serviceList.isEmpty()) {
2317 LOGGER.debug("Unable to find a service with modelUuid=" + serviceModelUuid);
2318 return new ArrayList<>();
2321 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2322 Collections.reverse (serviceList);
2324 // Step 2 - Now query to get the related VnfResourceCustomizations
2326 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "vnf");
2328 if (strcs.isEmpty()) {
2329 LOGGER.debug("Unable to find any related vnfs to a service with modelUuid=" + serviceModelUuid);
2330 return new ArrayList<>();
2333 ArrayList<VnfResourceCustomization> allVrcs = new ArrayList<>();
2334 for (ServiceToResourceCustomization strc : strcs) {
2335 LOGGER.debug("Try to find VRC for mcu=" + strc.getResourceModelCustomizationUUID());
2336 VnfResourceCustomization vrc = this.getVnfResourceCustomizationByModelCustomizationUuid(strc.getResourceModelCustomizationUUID());
2343 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2344 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2346 StringBuilder hqlService = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2347 Query query = getSession().createQuery(hqlService.toString());
2348 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2349 @SuppressWarnings("unchecked")
2350 List<Service> resultList = query.list();
2352 if (resultList.isEmpty()) {
2353 return new ArrayList<>();
2355 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2356 Collections.reverse (resultList);
2357 Service service = resultList.get(0);
2358 //now just call the method that takes the version - the service object will have the highest version
2359 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2361 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2362 long startTime = System.currentTimeMillis();
2363 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2365 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2366 Query query = getSession().createQuery(hql.toString());
2367 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2368 query.setParameter("serviceModelVersion", serviceModelVersion);
2370 @SuppressWarnings("unchecked")
2371 List<Service> resultList = query.list();
2373 if (resultList.isEmpty()) {
2374 return new ArrayList<>();
2376 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2377 Collections.reverse (resultList);
2378 Service service = resultList.get(0);
2379 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
2380 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2383 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
2384 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
2385 if (serviceVersion == null || serviceVersion.equals("")) {
2386 return this.getAllVnfsByServiceName(serviceName);
2389 StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName and version = :serviceVersion");
2390 Query query = getSession().createQuery(hql.toString());
2391 query.setParameter("serviceName", serviceName);
2392 query.setParameter("serviceVersion", serviceVersion);
2394 @SuppressWarnings("unchecked")
2395 List<Service> resultList = query.list();
2397 if (resultList.isEmpty()) {
2398 return Collections.EMPTY_LIST;
2400 Service service = resultList.get(0);
2401 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2403 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName) {
2404 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
2406 StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName");
2407 Query query = getSession().createQuery(hql.toString());
2408 query.setParameter("serviceName", serviceName);
2410 @SuppressWarnings("unchecked")
2411 List<Service> resultList = query.list();
2413 if (resultList.isEmpty()) {
2414 return Collections.EMPTY_LIST;
2416 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2417 Collections.reverse (resultList);
2418 Service service = resultList.get(0);
2420 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2423 public List<VnfResourceCustomization> getAllVnfsByVnfModelCustomizationUuid(String vnfModelCustomizationUuid) {
2424 long startTime = System.currentTimeMillis();
2425 LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid);
2427 StringBuilder hql1 = new StringBuilder("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu");
2428 Query query1 = getSession().createQuery(hql1.toString());
2429 query1.setParameter("vrcmcu", vnfModelCustomizationUuid);
2430 @SuppressWarnings("unchecked")
2431 List<VnfResourceCustomization> resultList1 = query1.list();
2433 if (resultList1.isEmpty()) {
2434 LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
2435 return Collections.EMPTY_LIST;
2438 for (VnfResourceCustomization vrc : resultList1) {
2439 VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid());
2440 vrc.setVnfResource(vr);
2441 vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc));
2444 LOGGER.debug("Returning " + resultList1.size() + " vnf modules");
2445 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
2449 //1702 API Spec cont'd - Query for all allotted resources in a Service
2451 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
2452 long startTime = System.currentTimeMillis();
2453 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
2455 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "allottedResource");
2456 if (strcs == null || strcs.isEmpty()) {
2457 LOGGER.debug("No AR entries found for " + serviceModelUuid);
2458 return new ArrayList<>();
2460 LOGGER.debug("Found " + strcs.size() + " entries in ServiceToResourceCustomizations with smu=" + serviceModelUuid + ", allottedResource");
2462 ArrayList<AllottedResourceCustomization> masterList = new ArrayList<>();
2463 for (ServiceToResourceCustomization star : strcs) {
2464 String arModelCustomizationUuid = star.getResourceModelCustomizationUUID();
2465 LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
2466 List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
2467 for (AllottedResourceCustomization arc : resultSet) {
2468 masterList.add(arc);
2471 LOGGER.debug("Returning " + masterList.size() + " ARC records");
2472 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
2476 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2477 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2479 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2480 Query query = getSession().createQuery(hql.toString());
2481 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2482 @SuppressWarnings("unchecked")
2483 List<Service> serviceList = query.list();
2485 if (serviceList.isEmpty()) {
2486 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2487 return new ArrayList<>();
2490 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2491 Collections.reverse (serviceList);
2492 Service service = serviceList.get(0);
2494 String serviceModelUuid = service.getModelUUID();
2495 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceModelUuid);
2497 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2500 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2501 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2503 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2504 Query query = getSession().createQuery(hql.toString());
2505 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2506 query.setParameter("serviceModelVersion", serviceModelVersion);
2508 @SuppressWarnings("unchecked")
2509 List<Service> serviceList = query.list();
2511 if (serviceList.isEmpty()) {
2512 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2513 return new ArrayList<>();
2516 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2517 Collections.reverse (serviceList);
2518 Service service = serviceList.get(0);
2520 String serviceModelUuid = service.getModelUUID();
2522 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2525 public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
2526 long startTime = System.currentTimeMillis();
2527 LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
2529 StringBuilder hql = new StringBuilder("FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
2530 Query query = getSession().createQuery(hql.toString());
2531 query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
2533 @SuppressWarnings("unchecked")
2534 List<AllottedResourceCustomization> resultList = query.list();
2536 if (resultList.isEmpty()) {
2537 LOGGER.debug("No ARC found with arc_mcu=" + arModelCustomizationUuid);
2538 return new ArrayList<>();
2540 // There should only be one - but we'll handle if multiple
2541 for (AllottedResourceCustomization arc : resultList) {
2542 AllottedResource ar = this.getAllottedResourceByModelUuid(arc.getArModelUuid());
2543 arc.setAllottedResource(ar);
2546 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
2550 public AllottedResource getAllottedResourceByModelUuid(String arModelUuid) {
2551 long startTime = System.currentTimeMillis ();
2552 LOGGER.debug ("Catalog database - get Allotted Resource with modelUuid= " + arModelUuid);
2554 String hql = "FROM AllottedResource WHERE modelUuid = :arModelUuid";
2555 Query query = getSession ().createQuery (hql);
2556 query.setParameter ("arModelUuid", arModelUuid);
2558 @SuppressWarnings("unchecked")
2559 List <AllottedResource> resultList = query.list ();
2561 // See if something came back. Name is unique, so
2562 if (resultList.isEmpty ()) {
2563 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. AllottedResource not found", "CatalogDB", "getAllottedResourceByModelUuid", null);
2566 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllottedResourceByModelUuid", null);
2567 return resultList.get (0);
2571 //1702 API Spec cont'd - Query for all resources in a Service:
2572 public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
2573 long startTime = System.currentTimeMillis();
2574 LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
2576 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2577 Query query = getSession().createQuery(hql.toString());
2578 query.setParameter("serviceModelUuid", serviceModelUuid);
2579 LOGGER.debug("Query: " + hql.toString() + ", smu=" + serviceModelUuid);
2580 @SuppressWarnings("unchecked")
2581 List<Service> serviceList = query.list();
2583 if (serviceList.isEmpty()) {
2584 LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
2585 return new ServiceMacroHolder();
2588 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2589 Collections.reverse (serviceList);
2590 Service service = serviceList.get(0);
2592 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2593 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
2594 smh.setNetworkResourceCustomization(nrcList);
2595 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2596 smh.setAllottedResourceCustomization(arcList);
2597 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(serviceModelUuid);
2598 smh.setVnfResourceCustomizations(vnfList);
2600 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
2603 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2604 long startTime = System.currentTimeMillis();
2605 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2607 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2608 Query query = getSession().createQuery(hql.toString());
2609 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2610 @SuppressWarnings("unchecked")
2611 List<Service> serviceList = query.list();
2613 if (serviceList.isEmpty()) {
2614 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2615 return new ServiceMacroHolder();
2618 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2619 Collections.reverse (serviceList);
2620 Service service = serviceList.get(0);
2622 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2623 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2624 smh.setNetworkResourceCustomization(nrcList);
2625 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2626 smh.setAllottedResourceCustomization(arcList);
2627 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2628 smh.setVnfResourceCustomizations(vnfList);
2630 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
2634 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2635 long startTime = System.currentTimeMillis();
2636 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2638 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2639 Query query = getSession().createQuery(hql.toString());
2640 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2641 query.setParameter("serviceModelVersion", serviceModelVersion);
2642 //TODO make this a unique query
2643 @SuppressWarnings("unchecked")
2644 List<Service> serviceList = query.list();
2646 if (serviceList.isEmpty()) {
2647 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
2648 return new ServiceMacroHolder();
2651 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2652 Collections.reverse (serviceList);
2653 Service service = serviceList.get(0);
2655 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2656 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2657 smh.setNetworkResourceCustomization(nrcList);
2658 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2659 smh.setAllottedResourceCustomization(arcList);
2660 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2661 smh.setVnfResourceCustomizations(vnfList);
2663 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
2667 // 1707 New API queries
2668 public NetworkResourceCustomization getSingleNetworkByModelCustomizationUuid(String modelCustomizationUuid) {
2669 LOGGER.debug("Catalog database; getSingleNetworkByModelCustomizationUuid - " + modelCustomizationUuid);
2670 List<NetworkResourceCustomization> resultList = this.getAllNetworksByNetworkModelCustomizationUuid(modelCustomizationUuid);
2671 if (resultList == null || resultList.isEmpty()) {
2674 return resultList.get(0);
2676 public AllottedResourceCustomization getSingleAllottedResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2677 LOGGER.debug("Catalog database; getSingleAllottedResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2678 List<AllottedResourceCustomization> resultList = this.getAllAllottedResourcesByArModelCustomizationUuid(modelCustomizationUuid);
2679 if (resultList == null || resultList.isEmpty()) {
2682 return resultList.get(0);
2685 public VnfResource getSingleVnfResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2687 long startTime = System.currentTimeMillis();
2688 LOGGER.debug("Catalog database; getSingleVnfResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2689 List<VnfResource> resultList = this.getAllVnfsByVnfModelCustomizationUuid(modelCustomizationUuid);
2690 if (resultList == null || resultList.size() < 1) {
2693 return resultList.get(0);
2698 private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
2699 HashMap<String, NetworkResource> networkResources = new HashMap<String, NetworkResource>();
2701 for (NetworkResourceCustomization nrc : resultList) {
2702 String network_id = nrc.getNetworkResourceModelUuid();
2703 if (network_id == null) {
2704 nrc.setNetworkResource(null);
2705 nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
2708 if (networkResources.containsKey(network_id)) {
2709 nrc.setNetworkResource(networkResources.get(network_id));
2710 nrc.setNetworkType(networkResources.get(network_id).getModelName());
2712 NetworkResource nr = this.getNetworkResourceById(network_id);
2714 nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
2716 nrc.setNetworkType(nr.getModelName());
2717 nrc.setNetworkResource(nr);
2718 networkResources.put(network_id, nr);
2725 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
2726 * first query VF_MODULE table by type, and then use the ID to query
2727 * VNF_RECIPE by VF_MODULE_ID and ACTION
2730 * @parm vfModuleModelName
2732 * @return VnfRecipe object or null if none found
2734 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
2735 String vfModuleType = vnfType + "::" + vfModuleModelName;
2737 StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type ");
2739 long startTime = System.currentTimeMillis ();
2740 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
2742 Query query = getSession ().createQuery (hql.toString ());
2743 query.setParameter (TYPE, vfModuleType);
2745 @SuppressWarnings("unchecked")
2746 List <VfModule> resultList = query.list ();
2748 if (resultList.isEmpty ()) {
2749 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
2753 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2754 Collections.reverse (resultList);
2756 VfModule vfMod = resultList.get(0);
2758 String vfModuleId = vfMod.getModelUUID();
2760 StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2762 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
2766 Query query1 = getSession ().createQuery (hql1.toString ());
2767 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2768 query1.setParameter (ACTION, action);
2770 @SuppressWarnings("unchecked")
2771 List <VnfRecipe> resultList1 = query1.list ();
2773 if (resultList1.isEmpty ()) {
2774 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
2778 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2779 Collections.reverse (resultList1);
2781 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
2782 return resultList1.get (0);
2786 * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2787 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2789 * @param vnfModuleType
2790 * @parm modelCustomizationUuid
2791 * @param asdcServiceModelVersion
2792 * @param modelVersion
2794 * @return VfModule list
2796 public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2799 if(modelCustomizationUuid != null){
2800 hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
2802 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2804 query = getSession ().createQuery (hql.toString ());
2805 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
2806 query.setParameter ("version", asdcServiceModelVersion);
2808 hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
2810 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2812 query = getSession ().createQuery (hql.toString ());
2813 query.setParameter (TYPE, vfModuleType);
2814 query.setParameter ("version", asdcServiceModelVersion);
2815 query.setParameter ("modelVersion", modelVersion);
2818 @SuppressWarnings("unchecked")
2819 List <VfModule> resultList = query.list ();
2825 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2826 * MODEL_CUSTOMIZATION_UUID, ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2827 * first query VF_MODULE table by type, and then use the ID to query
2828 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2831 * @parm vfModuleModelName
2833 * @return VnfRecipe object or null if none found
2835 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2836 String vfModuleType = vnfType + "::" + vfModuleModelName;
2837 long startTime = System.currentTimeMillis ();
2838 List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
2840 if (resultList.isEmpty ()) {
2841 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2845 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2846 Collections.reverse (resultList);
2848 VfModule vfMod = resultList.get(0);
2850 String vfModuleId = vfMod.getModelUUID();
2852 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2854 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2858 Query query1 = getSession ().createQuery (hql1.toString ());
2859 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2860 query1.setParameter (ACTION, action);
2862 @SuppressWarnings("unchecked")
2863 List <VnfComponentsRecipe> resultList1 = query1.list ();
2865 if (resultList1.isEmpty ()) {
2866 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2870 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2871 Collections.reverse (resultList1);
2873 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2874 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2875 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);
2878 return resultList1.get (0);
2882 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2883 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2884 * first query VF_MODULE table by type, and then use the ID to query
2885 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2888 * @parm vfModuleModelName
2890 * @return VnfRecipe object or null if none found
2892 public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
2893 long startTime = System.currentTimeMillis ();
2895 if (resultList.isEmpty ()) {
2896 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2900 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2901 Collections.reverse (resultList);
2903 VfModule vfMod = resultList.get(0);
2905 String vfModuleId = vfMod.getModelName();
2907 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2909 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2913 Query query1 = getSession ().createQuery (hql1.toString ());
2914 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2915 query1.setParameter (ACTION, action);
2917 @SuppressWarnings("unchecked")
2918 List <VnfComponentsRecipe> resultList1 = query1.list ();
2920 if (resultList1.isEmpty ()) {
2921 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2925 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2926 Collections.reverse (resultList1);
2928 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2929 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2930 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);
2933 return resultList1.get (0);
2938 * Return all VNF Resources in the Catalog DB
2940 * @return A list of VnfResource objects
2942 @SuppressWarnings("unchecked")
2943 public List <VnfResource> getAllVnfResources () {
2945 long startTime = System.currentTimeMillis ();
2946 LOGGER.debug ("Catalog database - get all VNF resources");
2948 String hql = "FROM VnfResource";
2949 Query query = getSession ().createQuery (hql);
2951 List <VnfResource> result = query.list ();
2952 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
2957 * Return VNF Resources in the Catalog DB that match a given VNF role
2959 * @return A list of VnfResource objects
2961 @SuppressWarnings("unchecked")
2962 @Deprecated // vnfRole is no longer in VnfResource
2963 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
2965 long startTime = System.currentTimeMillis ();
2966 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
2968 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
2969 Query query = getSession ().createQuery (hql);
2970 query.setParameter ("vnfRole", vnfRole);
2972 List <VnfResource> resources = query.list ();
2973 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
2978 * Return VNF Resources in the Catalog DB that match a given VNF role
2980 * @return A list of VnfResource objects
2982 @SuppressWarnings("unchecked")
2983 public List<VnfResourceCustomization> getVnfResourceCustomizationsByRole(String vnfRole) {
2984 long startTime = System.currentTimeMillis ();
2985 LOGGER.debug ("Catalog database - get all VNF resource customizations for role " + vnfRole);
2987 String hql = "FROM VnfResourceCustomization WHERE nfRole = :vnfRole";
2988 Query query = getSession ().createQuery (hql);
2989 query.setParameter ("vnfRole", vnfRole);
2991 List <VnfResourceCustomization> resources = query.list ();
2992 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationsByRole", null);
2997 * Return all Network Resources in the Catalog DB
2999 * @return A list of NetworkResource objects
3001 @SuppressWarnings("unchecked")
3002 public List <NetworkResource> getAllNetworkResources () {
3004 long startTime = System.currentTimeMillis ();
3005 LOGGER.debug ("Catalog database - get all network resources");
3007 String hql = "FROM NetworkResource";
3008 Query query = getSession ().createQuery (hql);
3010 List <NetworkResource> result = query.list ();
3011 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
3015 @SuppressWarnings("unchecked")
3016 public List<NetworkResourceCustomization> getAllNetworkResourceCustomizations() {
3017 long startTime = System.currentTimeMillis ();
3018 LOGGER.debug ("Catalog database - get all network resource customizations");
3020 String hql = "FROM NetworkResourceCustomization";
3021 Query query = getSession ().createQuery (hql);
3023 List <NetworkResourceCustomization> result = query.list ();
3024 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResourceCustomizations", null);
3029 * Return all VF Modules in the Catalog DB
3031 * @return A list of VfModule objects
3033 @SuppressWarnings("unchecked")
3034 public List <VfModule> getAllVfModules () {
3036 long startTime = System.currentTimeMillis ();
3037 LOGGER.debug ("Catalog database - get all vf modules");
3039 String hql = "FROM VfModule";
3040 Query query = getSession ().createQuery (hql);
3042 List <VfModule> result = query.list ();
3043 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
3047 @SuppressWarnings("unchecked")
3048 public List <VfModuleCustomization> getAllVfModuleCustomizations () {
3050 long startTime = System.currentTimeMillis ();
3051 LOGGER.debug ("Catalog database - get all vf module customizations");
3053 String hql = "FROM VfModuleCustomization";
3054 Query query = getSession ().createQuery (hql);
3056 List <VfModuleCustomization> result = query.list ();
3057 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModuleCustomizations", null);
3063 * Return all HeatEnvironment in the Catalog DB
3065 * @return A list of HeatEnvironment objects
3067 @SuppressWarnings("unchecked")
3068 public List <HeatEnvironment> getAllHeatEnvironment () {
3070 long startTime = System.currentTimeMillis ();
3071 LOGGER.debug ("Catalog database - get all Heat environments");
3073 String hql = "FROM HeatEnvironment";
3074 Query query = getSession ().createQuery (hql);
3076 List <HeatEnvironment> result = query.list ();
3077 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
3082 * Fetch the Environment by Environment ID - 1510
3084 @Deprecated // no longer in heat envt table
3085 public HeatEnvironment getHeatEnvironment (int id) {
3087 long startTime = System.currentTimeMillis ();
3088 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
3090 String hql = "FROM HeatEnvironment WHERE id = :idValue";
3092 LOGGER.debug ("getHeatEnvironment called with id=" + id);
3094 Query query = getSession ().createQuery (hql);
3095 query.setParameter ("idValue", id);
3097 @SuppressWarnings("unchecked")
3098 List <HeatEnvironment> resultList = query.list ();
3100 // See if something came back.
3101 if (resultList.isEmpty ()) {
3102 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
3105 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
3106 return resultList.get (0);
3110 * Fetch the nested templates - 1510
3114 public Map <String, Object> getNestedTemplates (int templateId) {
3115 Map <String, Object> nestedTemplates;
3116 long startTime = System.currentTimeMillis ();
3117 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
3119 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
3121 Query query = getSession ().createQuery (hql);
3122 query.setParameter ("parentIdValue", templateId);
3124 @SuppressWarnings("unchecked")
3125 List <HeatNestedTemplate> resultList = query.list ();
3126 // If nothing comes back, there are no nested templates
3127 if (resultList.isEmpty ()) {
3128 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3129 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
3132 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3133 nestedTemplates = new HashMap <> ();
3134 for (HeatNestedTemplate hnt : resultList) {
3135 LOGGER.debug ("Querying for " + hnt);
3136 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
3138 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3141 String providerResourceFile = hnt.getProviderResourceFile ();
3142 String heatTemplateBody = ht.getTemplateBody ();
3143 if (providerResourceFile != null && heatTemplateBody != null) {
3144 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3146 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3149 // Make sure we're not returning an empty map - if so, just return null
3150 if (nestedTemplates.isEmpty ()) {
3151 LOGGER.debug ("nestedTemplates is empty - just return null");
3152 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3155 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3156 return nestedTemplates;
3159 * Return a Map<String, Object> for returning the child templates and their contents
3161 * @param parentHeatTemplateId
3162 * @return Map<String,Object> or null if none found
3164 public Map <String, Object> getNestedTemplates (String parentHeatTemplateId) {
3165 Map <String, Object> nestedTemplates;
3166 long startTime = System.currentTimeMillis ();
3167 LOGGER.debug ("Catalog database - getNestedTemplates called with parentTemplateId " + parentHeatTemplateId);
3169 String hql = "FROM HeatNestedTemplate where parentTemplateId = :parentHeatTemplateId";
3171 Query query = getSession ().createQuery (hql);
3172 query.setParameter ("parentHeatTemplateId", parentHeatTemplateId);
3174 @SuppressWarnings("unchecked")
3175 List <HeatNestedTemplate> resultList = query.list ();
3176 // If nothing comes back, there are no nested templates
3177 if (resultList.isEmpty ()) {
3178 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3179 LOGGER.debug ("No nestedTemplates found for templateId=" + parentHeatTemplateId + ", " + hql);
3182 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3183 nestedTemplates = new HashMap <> ();
3184 for (HeatNestedTemplate hnt : resultList) {
3185 LOGGER.debug ("Querying for " + hnt);
3186 HeatTemplate ht = this.getHeatTemplateByArtifactUuid (hnt.getChildTemplateId ());
3188 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3191 String providerResourceFile = hnt.getProviderResourceFile ();
3192 String heatTemplateBody = ht.getTemplateBody ();
3193 if (providerResourceFile != null && heatTemplateBody != null) {
3194 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3196 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3199 // Make sure we're not returning an empty map - if so, just return null
3200 if (nestedTemplates.isEmpty ()) {
3201 LOGGER.debug ("nestedTemplates is empty - just return null");
3202 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3205 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3206 return nestedTemplates;
3210 * Fetch any files in the HEAT_FILES table 1510
3213 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
3214 Map <String, HeatFiles> heatFiles;
3216 long startTime = System.currentTimeMillis ();
3217 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
3218 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
3220 Query query = getSession ().createQuery (hql);
3221 query.setParameter ("vnfResourceIdValue", vnfResourceId);
3223 @SuppressWarnings("unchecked")
3224 List <HeatFiles> resultList = query.list ();
3225 // If nothing comes back, there are no heat files
3226 if (resultList.isEmpty ()) {
3227 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
3228 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
3231 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
3232 heatFiles = new HashMap <> ();
3233 for (HeatFiles hf : resultList) {
3234 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
3235 heatFiles.put (hf.getFileName (), hf);
3237 // Make sure we're not returning an empty map - if so, just return null
3238 if (heatFiles.isEmpty ()) {
3239 LOGGER.debug ("heatFiles is empty - just return null");
3240 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
3243 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
3247 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
3249 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
3251 Map <String, HeatFiles> heatFiles = null;
3253 long startTime = System.currentTimeMillis ();
3254 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
3255 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
3257 Query query = getSession ().createQuery (hql);
3258 query.setParameter ("vfModuleIdValue", vfModuleId);
3260 List<VfModuleToHeatFiles> mapList = query.list();
3261 if (mapList.isEmpty()) {
3262 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
3263 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3266 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3267 heatFiles = new HashMap<String, HeatFiles>();
3268 for (VfModuleToHeatFiles vmthf : mapList) {
3269 int heatFilesId = vmthf.getHeatFilesId();
3270 hql = "FROM HeatFiles where id = :id_value";
3271 query = getSession().createQuery(hql);
3272 query.setParameter("id_value", heatFilesId);
3273 List<HeatFiles> fileList = query.list();
3274 if (fileList.isEmpty()) {
3275 // Should this throw an exception??
3276 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
3277 String errorString = "_ERROR|" + heatFilesId;
3278 // The receiving code needs to know to throw an exception for this - or ignore it.
3279 heatFiles.put(errorString, null);
3281 // Should only ever have 1 result - add it to our Map
3282 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
3283 for (HeatFiles hf : fileList) {
3284 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3285 heatFiles.put(hf.getFileName(), hf);
3289 if (heatFiles.isEmpty()) {
3290 LOGGER.debug ("heatFiles is empty - just return null");
3291 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3294 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3301 * Return a VfModuleToHeatFiles object
3303 * @param vfModuleModelUuid, heatFilesArtifactUuid
3304 * @return VfModuleToHeatFiles or null if none found
3306 public VfModuleToHeatFiles getVfModuleToHeatFilesEntry(String vfModuleModelUuid, String heatFilesArtifactUuid) {
3308 LOGGER.debug ("Catalog database - getVfModuleToHeatFilesEntry with vfModuleModelUuid " + vfModuleModelUuid + ", heatFilesArtifactUuid=" + heatFilesArtifactUuid);
3309 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue and heatFilesArtifactUuid = :heatFilesArtifactUuidValue";
3311 HashMap<String, String> parameters = new HashMap<>();
3312 parameters.put("vfModuleModelUuidValue", vfModuleModelUuid);
3313 parameters.put("heatFilesArtifactUuidValue", heatFilesArtifactUuid);
3315 VfModuleToHeatFiles vmthf = null;
3318 vmthf = this.executeQuerySingleRow(hql, parameters, true);
3319 } catch (Exception e) {
3327 * Return a ServiceToResourceCustomization object
3329 * @param vfModuleModelUuid, heatFilesArtifactUuid
3330 * @return VfModuleToHeatFiles or null if none found
3332 public ServiceToResourceCustomization getServiceToResourceCustomization(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
3334 LOGGER.debug ("Catalog database - getServiceToResourceCustomization with serviceModelUuid=" + serviceModelUuid + ", resourceModelCustomizationUuid=" + resourceModelCustomizationUuid + ", modelType=" + modelType);
3335 String hql = "FROM ServiceToResourceCustomization where serviceModelUUID = :serviceModelUuidValue and resourceModelCustomizationUUID = :resourceModelCustomizationUuidValue and modelType = :modelTypeValue ";
3337 HashMap<String, String> parameters = new HashMap<>();
3338 parameters.put("serviceModelUuidValue", serviceModelUuid);
3339 parameters.put("resourceModelCustomizationUuidValue", resourceModelCustomizationUuid);
3340 parameters.put("modelTypeValue", modelType);
3342 ServiceToResourceCustomization strc = null;
3345 strc = this.executeQuerySingleRow(hql, parameters, true);
3346 } catch (Exception e) {
3353 * Return a Map<String, HeatFiles> for returning the heat files associated with a vfModule 1707
3355 * @param parentHeatTemplateId
3356 * @return Map<String,Object> or null if none found
3358 public Map <String, HeatFiles> getHeatFilesForVfModule(String vfModuleModelUuid) {
3359 Map <String, HeatFiles> heatFiles;
3361 long startTime = System.currentTimeMillis ();
3362 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleModelUuid " + vfModuleModelUuid);
3363 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue";
3365 Query query = getSession ().createQuery (hql);
3366 query.setParameter ("vfModuleModelUuidValue", vfModuleModelUuid);
3368 @SuppressWarnings("unchecked")
3369 List<VfModuleToHeatFiles> mapList = query.list();
3370 if (mapList.isEmpty()) {
3371 LOGGER.debug ("No heatFiles found for vfModuleModelUuid=" + vfModuleModelUuid);
3372 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3375 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3376 heatFiles = new HashMap<>();
3377 for (VfModuleToHeatFiles vmthf : mapList) {
3378 String heatFilesUuid = vmthf.getHeatFilesArtifactUuid();
3379 hql = "FROM HeatFiles where artifactUuid = :heatFilesUuidValue";
3380 query = getSession().createQuery(hql);
3381 query.setParameter("heatFilesUuidValue", heatFilesUuid);
3382 @SuppressWarnings("unchecked")
3383 List<HeatFiles> fileList = query.list();
3384 if (fileList.isEmpty()) {
3385 // Should this throw an exception??
3386 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesUuid);
3387 String errorString = "_ERROR|" + heatFilesUuid;
3388 // The receiving code needs to know to throw an exception for this - or ignore it.
3389 heatFiles.put(errorString, null);
3391 // Should only ever have 1 result - add it to our Map
3392 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesUuid);
3393 for (HeatFiles hf : fileList) {
3394 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3395 heatFiles.put(hf.getFileName(), hf);
3399 if (heatFiles.isEmpty()) {
3400 LOGGER.debug ("heatFiles is empty - just return null");
3401 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3404 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3409 * Get the heat template object based on asdc attributes
3411 * @param templateName The template name, generally the yaml filename. "example.yaml"
3412 * @param version The version as specified by ASDC. "1.1"
3413 * @param asdcResourceName The ASDC resource name provided in the ASDC artifact
3415 * @return The HeatTemplate
3417 @Deprecated // asdcResourceName is no longer in heatTeamplate
3418 public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
3420 long startTime = System.currentTimeMillis ();
3421 LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
3424 + " and ASDC resource name "
3425 + asdcResourceName);
3427 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
3428 Query query = getSession ().createQuery (hql);
3429 query.setParameter ("template_name", templateName);
3430 query.setParameter ("version", version);
3431 query.setParameter ("asdcResourceName", asdcResourceName);
3433 @SuppressWarnings("unchecked")
3434 List <HeatTemplate> resultList = query.list ();
3436 // See if something came back.
3437 if (resultList.isEmpty ()) {
3438 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
3441 // Name + Version is unique, so should only be one element
3442 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3443 return resultList.get (0);
3448 * Save the Heat Template
3450 * @param heat The heat template
3451 * @param paramSet The list of heat template parameters
3453 public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
3455 long startTime = System.currentTimeMillis ();
3456 LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName() + ", artifactUUID=" + heat.getArtifactUuid());
3458 heat.setParameters(null);
3461 HeatTemplate heatTemp = this.getHeatTemplateByArtifactUuidRegularQuery(heat.getArtifactUuid());
3463 if (heatTemp == null) {
3464 this.getSession ().save (heat);
3466 if (paramSet != null) {
3467 StringBuilder sb = new StringBuilder("Parameters: ");
3468 for (HeatTemplateParam param : paramSet) {
3469 param.setHeatTemplateArtifactUuid(heat.getArtifactUuid());
3470 sb.append(param.getParamName() + ", ");
3472 LOGGER.debug(sb.toString());
3473 heat.setParameters (paramSet);
3475 Session session = this.getSession();
3476 if (!(session.isConnected() && session.isOpen())) {
3477 LOGGER.debug("Initial session is not connected or open - get another");
3478 session = this.getSession();
3481 } catch (HibernateException he1) {
3482 LOGGER.debug("Hibernate Exception encountered on first attempt at save(heat) - try again..." + he1.getMessage(), he1);
3484 Session session = this.getSession();
3486 } catch (HibernateException he2) {
3487 LOGGER.debug("Hibernate Exception encountered on second attempt at save(heat)" + he2.getMessage());
3488 LOGGER.debug(Arrays.toString(he2.getStackTrace()));
3490 } catch (Exception e2) {
3491 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(),e2);
3492 LOGGER.debug(Arrays.toString(e2.getStackTrace()));
3496 } catch (Exception e1) {
3497 LOGGER.debug("General Exception encountered on first attempt at save(heat) - try again..." + e1.getMessage(), e1);
3498 LOGGER.debug(Arrays.toString(e1.getStackTrace()));
3500 Session session = this.getSession();
3502 } catch (HibernateException he2) {
3503 LOGGER.debug("General Exception encountered on second attempt at save(heat)" + he2.getMessage(), he2);
3504 LOGGER.debug(Arrays.toString(he2.getStackTrace()));
3506 } catch (Exception e2) {
3507 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(), e2);
3508 LOGGER.debug(Arrays.toString(e2.getStackTrace()));
3515 heat.setArtifactUuid(heatTemp.getArtifactUuid());
3518 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3523 * Retrieves a Heat environment from DB based on its unique key.
3525 * @param name the environment artifact name
3526 * @param version the environment resource version
3527 * @param asdcResourceName the environment resource name
3528 * @return the heat environment from DB or null if not found
3531 public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
3532 long startTime = System.currentTimeMillis ();
3533 LOGGER.debug ("Catalog database - get Heat environment with name " + name
3536 + " and ASDC resource name "
3537 + asdcResourceName);
3539 String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
3540 Query query = getSession ().createQuery (hql);
3541 query.setParameter ("name", name);
3542 query.setParameter ("version", version);
3543 query.setParameter ("asdcResourceName", asdcResourceName);
3544 HeatEnvironment env = null;
3546 env = (HeatEnvironment) query.uniqueResult ();
3547 } catch (org.hibernate.NonUniqueResultException nure) {
3548 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, nure);
3549 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);
3551 } catch (org.hibernate.HibernateException he) {
3552 LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, he);
3553 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);
3555 } catch (Exception e) {
3556 LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, e);
3557 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);
3561 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3563 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3569 * Retrieves a Heat environment from DB based on its unique key. 1707
3571 * @param name the environment artifact name
3572 * @param version the environment resource version
3573 * @return the heat environment from DB or null if not found
3575 public HeatEnvironment getHeatEnvironment (String artifactUuid, String version) {
3576 long startTime = System.currentTimeMillis ();
3577 LOGGER.debug ("Catalog database - get Heat environment with uuid " + artifactUuid
3581 String hql = "FROM HeatEnvironment WHERE artifactUuid=:artifactUuid AND version=:version";
3582 Query query = getSession ().createQuery (hql);
3583 query.setParameter ("artifactUuid", artifactUuid);
3584 query.setParameter ("version", version);
3585 HeatEnvironment env = null;
3587 env = (HeatEnvironment) query.uniqueResult ();
3588 } catch (org.hibernate.NonUniqueResultException nure) {
3589 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + artifactUuid + "', version='" + version);
3590 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "non unique result for ArtifactUUID=" + artifactUuid);
3592 } catch (org.hibernate.HibernateException he) {
3593 LOGGER.debug("Hibernate Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + he.getMessage() );
3594 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUUID=" + artifactUuid + " and version=" + version , "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUUID=" + artifactUuid);
3596 } catch (Exception e) {
3597 LOGGER.debug("Generic Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + e.getMessage());
3598 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUUID=" + artifactUuid);
3602 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3604 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3610 * Save the HeatEnvironment
3612 * @param env The Environment
3614 public void saveHeatEnvironment (HeatEnvironment env) {
3615 long startTime = System.currentTimeMillis ();
3616 LOGGER.debug ("Catalog database - save Heat environment with name "
3617 + env.getEnvironment() + " and ArtifactUUID " + env.getArtifactUuid());
3619 HeatEnvironment dbEnv = getHeatEnvironment (env.getArtifactUuid(), env.getVersion ());
3620 if (dbEnv == null) {
3622 this.getSession ().save (env);
3625 env.setArtifactUuid(dbEnv.getArtifactUuid());
3629 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3634 * Save the heatTemplate
3636 * @param heat The heat template
3638 public void saveHeatTemplate (HeatTemplate heat) {
3639 long startTime = System.currentTimeMillis ();
3640 LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
3642 this.getSession ().update (heat);
3644 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3648 public void saveHeatFile (HeatFiles heatFile) {
3649 long startTime = System.currentTimeMillis ();
3650 LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
3652 this.getSession ().save (heatFile);
3654 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
3658 public void saveVnfRecipe (VnfRecipe vnfRecipe) {
3659 long startTime = System.currentTimeMillis ();
3660 LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
3662 this.getSession ().save (vnfRecipe);
3664 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
3668 public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
3669 long startTime = System.currentTimeMillis ();
3670 LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
3672 this.getSession ().save (vnfComponentsRecipe);
3674 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
3679 public void saveOrUpdateVnfResource (VnfResource vnfResource) {
3680 long startTime = System.currentTimeMillis ();
3681 LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getModelName());
3684 VnfResource existing = this.getVnfResourceByModelUuid(vnfResource.getModelUuid());
3685 if (existing == null) {
3686 LOGGER.debug("No existing entry found - attempting to save...");
3687 this.getSession ().save (vnfResource);
3689 LOGGER.debug("Existing vnf resource found!");
3693 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
3697 public boolean saveVnfResourceCustomization (VnfResourceCustomization vnfResourceCustomization) {
3698 long startTime = System.currentTimeMillis ();
3699 LOGGER.debug ("Catalog database - save VNF Resource Customization with Name " + vnfResourceCustomization.getModelInstanceName());
3701 LOGGER.debug(vnfResourceCustomization.toString());
3702 } catch (Exception e) {
3703 LOGGER.debug("Unable to print VRC " + e.getMessage(), e);
3706 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3707 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3708 // Do any matching customization records exist?
3709 // if(networkResourceList.size() == 0){
3711 // networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUuid());
3712 // this.getSession().flush();
3713 // this.getSession().clear();
3715 VnfResourceCustomization existing = this.getVnfResourceCustomizationByModelCustomizationUuid(vnfResourceCustomization.getModelCustomizationUuid());
3717 if (existing == null) {
3718 LOGGER.debug("No existing entry found...attempting to save...");
3719 this.getSession ().save (vnfResourceCustomization);
3723 LOGGER.debug("Existing VRC entry found\n" + existing.toString());
3724 } catch (Exception e) {
3725 LOGGER.debug("Unable to print VRC2 " + e.getMessage(), e);
3731 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceCustomization", null);
3735 public void saveAllottedResourceCustomization (AllottedResourceCustomization resourceCustomization) {
3736 long startTime = System.currentTimeMillis ();
3737 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + resourceCustomization.getModelInstanceName());
3739 List<AllottedResourceCustomization> allottedResourcesList = getAllAllottedResourcesByArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
3741 if(allottedResourcesList.isEmpty()){
3742 this.getSession ().save(resourceCustomization);
3746 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3750 public void saveAllottedResource (AllottedResource allottedResource) {
3751 long startTime = System.currentTimeMillis ();
3752 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + allottedResource.getModelName());
3754 AllottedResource existing = this.getAllottedResourceByModelUuid(allottedResource.getModelUuid());
3755 if (existing == null) {
3756 this.getSession ().save (allottedResource);
3758 LOGGER.debug("Found existing allottedResource with this modelUuid - no need to save");
3762 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3766 public void saveNetworkResource (NetworkResource networkResource) throws RecordNotFoundException {
3767 long startTime = System.currentTimeMillis ();
3768 LOGGER.debug ("Catalog database - save Network Resource with Network Name " + networkResource.getModelName());
3770 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3771 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3772 // Do any matching customization records exist?
3773 if(getNetworkResourceByModelUuid(networkResource.getModelUUID()) == null){
3774 this.getSession ().save(networkResource);
3779 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3783 public void saveToscaCsar (ToscaCsar toscaCsar) throws RecordNotFoundException {
3786 long startTime = System.currentTimeMillis ();
3787 LOGGER.debug ("Catalog database - save Tosca Csar with Name " + toscaCsar.getName());
3790 if(getToscaCsar(toscaCsar.getArtifactChecksum()) == null){
3791 this.getSession ().save (toscaCsar);
3793 LOGGER.debug("Temporarily disabling saveToscaCsar pending further investigation 2017-06-02");
3796 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveToscaCsar", null);
3802 * Return the newest version of a specific Tosca CSAR Record resource (queried by Name).
3805 * @return ToscaCsar object or null if none found
3807 public ToscaCsar getToscaCsar (String artifactChecksum) {
3809 long startTime = System.currentTimeMillis ();
3810 LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactChecksum " + artifactChecksum);
3812 String hql = "FROM ToscaCsar WHERE artifactChecksum = :artifactChecksum";
3813 Query query = getSession ().createQuery (hql);
3814 query.setParameter ("artifactChecksum", artifactChecksum);
3816 @SuppressWarnings("unchecked")
3817 List <ToscaCsar> resultList = query.list ();
3819 // See if something came back. Name is unique, so
3820 if (resultList.isEmpty ()) {
3821 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsar", null);
3825 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsar", null);
3826 return resultList.get (0);
3830 public void saveTempNetworkHeatTemplateLookup (TempNetworkHeatTemplateLookup tempNetworkHeatTemplateLookup) {
3831 long startTime = System.currentTimeMillis ();
3832 LOGGER.debug ("Catalog database - save TempNetworkHeatTemplateLookup with Network Model Name " + tempNetworkHeatTemplateLookup.getNetworkResourceModelName() +
3833 " and Heat Template Artifact UUID " + tempNetworkHeatTemplateLookup.getHeatTemplateArtifactUuid());
3835 this.getSession ().save (tempNetworkHeatTemplateLookup);
3838 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveTempNetworkHeatTemplateLookup", null);
3842 public void saveVfModuleToHeatFiles (VfModuleToHeatFiles vfModuleToHeatFiles) {
3843 long startTime = System.currentTimeMillis ();
3844 LOGGER.debug ("Catalog database - save VfModuleToHeatFiles with VF Module UUID " + vfModuleToHeatFiles.getVfModuleModelUuid() +
3845 " and Heat Files Artifact UUID " + vfModuleToHeatFiles.getHeatFilesArtifactUuid());
3848 this.getSession ().save (vfModuleToHeatFiles);
3851 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVFModuleToHeatFiles", null);
3855 public void saveVnfResourceToVfModuleCustomization(VnfResourceCustomization vnfResourceCustomizationUUID, VfModuleCustomization vfModuleCustomizationUUID) throws RecordNotFoundException {
3856 long startTime = System.currentTimeMillis ();
3857 VnfResCustomToVfModuleCustom vnfResCustomToVfModuleCustom = new VnfResCustomToVfModuleCustom();
3859 if(vnfResourceCustomizationUUID != null && vfModuleCustomizationUUID != null){
3860 vnfResCustomToVfModuleCustom.setVnfResourceCustModelCustomizationUuid(vnfResourceCustomizationUUID.getModelCustomizationUuid());
3861 vnfResCustomToVfModuleCustom.setVfModuleCustModelCustomizationUuid(vfModuleCustomizationUUID.getModelCustomizationUuid());
3862 String vnfId = vnfResourceCustomizationUUID.getModelCustomizationUuid();
3863 String vfId = vfModuleCustomizationUUID.getModelCustomizationUuid();
3864 LOGGER.debug ("Catalog database - save VnfResCustomToVfModuleCustom with vnf=" + vnfId + ", vf=" + vfId);
3866 VnfResCustomToVfModuleCustom existing = this.getVnfResCustomToVfModule(vnfId, vfId);
3867 if (existing == null) {
3868 LOGGER.debug("No existing entry found - will now try to save");
3869 this.getSession ().save (vnfResCustomToVfModuleCustom);
3871 LOGGER.debug("Existing entry already found - no save needed");
3874 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceToVfModuleCustomization", null);
3879 public void saveNetworkResourceCustomization (NetworkResourceCustomization networkResourceCustomization) throws RecordNotFoundException {
3880 long startTime = System.currentTimeMillis ();
3881 LOGGER.debug ("Catalog database - save Network Resource Customization with Network Name " + networkResourceCustomization.getModelInstanceName());
3883 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3884 List<NetworkResourceCustomization> networkResourceCustomizationList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3885 // Do any matching customization records exist?
3886 if(networkResourceCustomizationList.isEmpty()){
3888 // Retreive the record from the Network_Resource table associated to the Customization record based on ModelName
3889 // ?? is it modelInstanceName with 1707?
3890 NetworkResource networkResource = getNetworkResource(networkResourceCustomization.getModelInstanceName());
3892 if(networkResource == null){
3893 throw new RecordNotFoundException("No record found in NETWORK_RESOURCE table for model name " + networkResourceCustomization.getModelInstanceName());
3896 networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUUID());
3898 this.getSession ().save(networkResourceCustomization);
3903 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3907 @Deprecated // table is gone - mapped to ServiceToResource
3908 public void saveServiceToNetworks (ServiceToNetworks serviceToNetworks) {
3909 long startTime = System.currentTimeMillis ();
3910 LOGGER.debug ("Catalog database - save to ServiceToNetworks table with NetworkModelCustomizationUUID of " + serviceToNetworks.getNetworkModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToNetworks.getServiceModelUuid());
3912 this.getSession ().save(serviceToNetworks);
3915 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3919 public void saveServiceToResourceCustomization(ServiceToResourceCustomization serviceToResource) {
3920 long startTime = System.currentTimeMillis ();
3921 LOGGER.debug ("Catalog database - save to ServiceToResourceCustomization table with ServiceModelUuid of " + serviceToResource.getServiceModelUUID() + ", ResourceModelUUID of " + serviceToResource.getResourceModelCustomizationUUID() + " and model_type=" + serviceToResource.getModelType());
3922 ServiceToResourceCustomization strc = this.getServiceToResourceCustomization(serviceToResource.getServiceModelUUID(), serviceToResource.getResourceModelCustomizationUUID(), serviceToResource.getModelType());
3925 LOGGER.debug("**This ServiceToResourceCustomization record already exists - no need to save");
3927 this.getSession ().save(serviceToResource);
3930 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToResourceCustomization", null);
3934 @Deprecated // table is gone - mapped to ServiceToResourceCustomization
3935 public void saveServiceToAllottedResources (ServiceToAllottedResources serviceToAllottedResources) {
3936 long startTime = System.currentTimeMillis ();
3937 LOGGER.debug ("Catalog database - save to serviceToAllottedResources table with ARModelCustomizationUUID of " + serviceToAllottedResources.getArModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToAllottedResources.getServiceModelUuid());
3939 this.getSession ().save(serviceToAllottedResources);
3942 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToAllottedResources", null);
3946 public void saveService (Service service) {
3947 long startTime = System.currentTimeMillis ();
3948 LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getModelName()+"/"+service.getVersion()+"/"+service.getModelUUID());
3950 Service serviceInvariantDB = null;
3951 // Retrieve existing service record by nameVersionId
3952 Service serviceDB = this.getServiceByModelUUID(service.getModelUUID());
3953 if (serviceDB == null) {
3954 // 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.
3955 serviceInvariantDB = this.getServiceByInvariantUUID(service.getModelInvariantUUID());
3956 // Save the new Service record
3957 this.getSession ().save (service);
3960 if(serviceInvariantDB != null){ // existing modelInvariantId was found.
3961 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
3962 List<ServiceRecipe> serviceRecipes = getServiceRecipes(serviceInvariantDB.getModelUUID());
3964 if(serviceRecipes != null && ! serviceRecipes.isEmpty()){
3965 for(ServiceRecipe serviceRecipe : serviceRecipes){
3966 if(serviceRecipe != null){
3967 // 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.
3968 Service newService = this.getServiceByModelUUID(service.getModelUUID());
3969 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
3970 ServiceRecipe newServiceRecipe = new ServiceRecipe();
3971 newServiceRecipe.setAction(serviceRecipe.getAction());
3972 newServiceRecipe.setDescription(serviceRecipe.getDescription());
3973 newServiceRecipe.setOrchestrationUri(serviceRecipe.getOrchestrationUri());
3974 newServiceRecipe.setRecipeTimeout(serviceRecipe.getRecipeTimeout());
3975 newServiceRecipe.setServiceParamXSD(serviceRecipe.getServiceParamXSD());
3976 newServiceRecipe.setServiceModelUUID(newService.getModelUUID());
3977 newServiceRecipe.setVersion(serviceRecipe.getVersion());
3978 // Check recipe does not exist before inserting
3979 ServiceRecipe recipe = getServiceRecipeByModelUUID(newServiceRecipe.getServiceModelUUID(), newServiceRecipe.getAction());
3980 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
3982 this.getSession ().save (newServiceRecipe);
3991 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
3995 public void saveOrUpdateVfModule (VfModule vfModule) {
3996 long startTime = System.currentTimeMillis ();
3997 LOGGER.debug ("Catalog database - save or update VF Module with VF Model Name " + vfModule.getModelName());
3998 VfModule vfModuleInvariantDB = null;
4000 LOGGER.debug("heat template id = " + vfModule.getHeatTemplateArtifactUUId() + ", vol template id = "+ vfModule.getVolHeatTemplateArtifactUUId());
4001 LOGGER.debug(vfModule.toString());
4002 } catch (Exception e) {
4003 LOGGER.debug("unable to print vfmodule " + e.getMessage(), e);
4006 VfModule existing = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4007 if (existing == null) {
4008 // 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.
4009 vfModuleInvariantDB = this.getVfModuleByModelInvariantUuid(vfModule.getModelInvariantUUID());
4010 LOGGER.debug("No existing entry found, attempting to save...");
4011 this.getSession ().save (vfModule);
4014 LOGGER.debug("Found an existing vf module!\n" + existing.toString());
4015 } catch (Exception e) {
4016 LOGGER.debug("unable to print vfmodule2 " + e.getMessage(), e);
4020 if(vfModuleInvariantDB != null){ // existing modelInvariantId was found.
4021 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
4022 List<VnfComponentsRecipe> vfRecipes = getVnfComponentRecipes(vfModuleInvariantDB.getModelUUID());
4025 if(vfRecipes != null && ! vfRecipes.isEmpty()){
4026 for(VnfComponentsRecipe vfRecipe : vfRecipes){
4027 if(vfRecipe != null){
4028 // 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.
4029 VfModule newRecipe = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4030 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
4031 VnfComponentsRecipe newVnfRecipe = new VnfComponentsRecipe();
4032 newVnfRecipe.setAction(vfRecipe.getAction());
4033 newVnfRecipe.setDescription(vfRecipe.getDescription());
4034 newVnfRecipe.setOrchestrationUri(vfRecipe.getOrchestrationUri());
4035 newVnfRecipe.setRecipeTimeout(vfRecipe.getRecipeTimeout());
4036 newVnfRecipe.setVnfComponentParamXSD(vfRecipe.getVnfComponentParamXSD());
4037 newVnfRecipe.setVfModuleModelUUId(newRecipe.getModelUUID());
4038 newVnfRecipe.setVersion(vfRecipe.getVersion());
4039 newVnfRecipe.setVnfComponentType(vfRecipe.getVnfComponentType());
4040 newVnfRecipe.setVnfType(vfRecipe.getVnfType());
4041 // Check recipe does not exist before inserting
4042 // VnfComponentsRecipe recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4043 List<VnfComponentsRecipe> recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4044 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
4045 // if(recipe == null){
4046 this.getSession ().save (newVnfRecipe);
4055 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
4059 public void saveOrUpdateVfModuleCustomization (VfModuleCustomization vfModuleCustomization) {
4060 long startTime = System.currentTimeMillis ();
4061 LOGGER.debug ("Catalog database - save VF Module Customization with VF Customization Model Name UUID " + vfModuleCustomization.getVfModuleModelUuid());
4063 LOGGER.debug("env id = " + vfModuleCustomization.getHeatEnvironmentArtifactUuid() + ", vol Env=" + vfModuleCustomization.getVolEnvironmentArtifactUuid());
4064 LOGGER.debug(vfModuleCustomization.toString());
4065 } catch (Exception e) {
4066 LOGGER.debug("unable to print vfmodulecust " + e.getMessage(), e);
4069 VfModuleCustomization existing = this.getVfModuleCustomizationByModelCustomizationId(vfModuleCustomization.getModelCustomizationUuid());
4070 if (existing == null) {
4071 LOGGER.debug("No existing entry found, attempting to save...");
4072 this.getSession ().save (vfModuleCustomization);
4075 LOGGER.debug("Found an existing vf module customization entry\n" + existing.toString());
4076 } catch (Exception e) {
4077 LOGGER.debug("unable to print vfmodulecust2 " + e.getMessage(), e);
4082 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModuleCustomization", null);
4087 public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
4088 long startTime = System.currentTimeMillis ();
4089 LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
4090 + parentTemplateId +"-"+childTemplateId);
4092 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4093 // nestedTemplate.setParentTemplateId (parentTemplateId);
4094 // nestedTemplate.setChildTemplateId (childTemplateId);
4096 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
4098 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
4103 public HeatNestedTemplate getNestedHeatTemplate(String parentTemplateId, String childTemplateId) {
4104 long startTime = System.currentTimeMillis ();
4105 LOGGER.debug ("Catalog database - get nested Heat template with PerentId="
4106 + parentTemplateId +", ChildId="+childTemplateId);
4108 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4109 nestedTemplate.setParentTemplateId (parentTemplateId);
4110 nestedTemplate.setChildTemplateId (childTemplateId);
4112 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
4114 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
4119 public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4121 long startTime = System.currentTimeMillis ();
4122 LOGGER.debug ("Catalog database - save nested Heat template with name "
4123 + childTemplate.getTemplateName ());
4126 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4127 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
4128 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4129 nestedTemplate.setParentTemplateId (parentTemplateId);
4130 nestedTemplate.setChildTemplateId (childTemplate.getId ());
4131 nestedTemplate.setProviderResourceFile (yamlFile);
4132 session.save (nestedTemplate);
4135 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4141 public void saveNestedHeatTemplate (String parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4142 long startTime = System.currentTimeMillis ();
4143 LOGGER.debug ("Catalog database - save nested Heat template with name "
4144 + childTemplate.getTemplateName () + ",parentId=" + parentTemplateId + ",childId=" + childTemplate.getArtifactUuid() + ", providerResourceFile=" + yamlFile);
4147 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4148 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getArtifactUuid()) == null) {
4149 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4150 nestedTemplate.setParentTemplateId (parentTemplateId);
4151 nestedTemplate.setChildTemplateId (childTemplate.getArtifactUuid ());
4152 nestedTemplate.setProviderResourceFile (yamlFile);
4154 session.save (nestedTemplate);
4157 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4162 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
4163 long startTime = System.currentTimeMillis ();
4164 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
4165 + " and vnfResourceID "
4167 // + " and ASDC resource name "
4172 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
4173 Query query = getSession ().createQuery (hql);
4174 query.setParameter ("fileName", fileName);
4175 query.setParameter ("vnfResourceId", vnfResourceId);
4176 query.setParameter ("asdcResourceName", asdcResourceName);
4177 query.setParameter ("version", version);
4179 @SuppressWarnings("unchecked")
4181 HeatFiles heatFilesResult = null;
4183 heatFilesResult = (HeatFiles) query.uniqueResult ();
4184 } catch (org.hibernate.NonUniqueResultException nure) {
4185 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);
4186 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);
4188 } catch (org.hibernate.HibernateException he) {
4189 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + he.getMessage());
4190 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);
4192 } catch (Exception e) {
4193 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + e.getMessage());
4194 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);
4198 // See if something came back.
4199 if (heatFilesResult == null) {
4200 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4203 // Name + Version is unique, so should only be one element
4204 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4205 return heatFilesResult;
4208 public HeatFiles getHeatFiles(String artifactUuid) {
4209 long startTime = System.currentTimeMillis ();
4210 LOGGER.debug ("Catalog database - getHeatFiles with artifactUuid " + artifactUuid);
4212 String hql = "FROM HeatFiles WHERE artifactUuid = :artifactUuid";
4213 Query query = getSession ().createQuery (hql);
4214 query.setParameter ("artifactUuid", artifactUuid);
4216 @SuppressWarnings("unchecked")
4218 HeatFiles heatFilesResult = null;
4220 heatFilesResult = (HeatFiles) query.uniqueResult ();
4221 } catch (org.hibernate.NonUniqueResultException nure) {
4222 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: artifactUuid='" + artifactUuid );
4223 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid=" + artifactUuid);
4225 } catch (org.hibernate.HibernateException he) {
4226 LOGGER.debug("Hibernate Exception - while searching for: artifactUuid='" + artifactUuid + " " + he.getMessage());
4227 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + artifactUuid);
4229 } catch (Exception e) {
4230 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + " " + e.getMessage());
4231 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUuid=" + artifactUuid , "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + artifactUuid);
4235 // See if something came back.
4236 if (heatFilesResult == null) {
4237 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4240 // Name + Version is unique, so should only be one element
4241 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4242 return heatFilesResult;
4245 public void saveHeatFiles (HeatFiles childFile) {
4246 long startTime = System.currentTimeMillis ();
4247 LOGGER.debug ("Catalog database - save Heat File with name "
4248 + childFile.getFileName());
4250 // HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
4251 HeatFiles heatFiles = getHeatFiles (childFile.getArtifactUuid());
4252 if (heatFiles == null) {
4254 // asdc_heat_files_save
4255 this.getSession ().save (childFile);
4258 /* replaced 'heatFiles' by 'childFile'
4259 Based on following comment:
4260 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
4262 childFile.setArtifactUuid(heatFiles.getArtifactUuid());
4266 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
4271 public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
4273 long startTime = System.currentTimeMillis ();
4274 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4275 + childFile.getFileName());
4277 saveHeatFiles (childFile);
4278 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4279 vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
4280 vfModuleToHeatFile.setHeatFilesId(childFile.getId());
4282 session.save (vfModuleToHeatFile);
4285 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4290 public void saveVfModuleToHeatFiles (String parentVfModuleId, HeatFiles childFile) {
4291 long startTime = System.currentTimeMillis ();
4292 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4293 + childFile.getFileName());
4295 saveHeatFiles (childFile);
4296 VfModuleToHeatFiles checkExistingEntry = this.getVfModuleToHeatFilesEntry(parentVfModuleId, childFile.getArtifactUuid());
4297 if (checkExistingEntry == null) {
4298 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4299 vfModuleToHeatFile.setVfModuleModelUuid(parentVfModuleId);
4300 vfModuleToHeatFile.setHeatFilesArtifactUuid(childFile.getArtifactUuid());
4302 session.save (vfModuleToHeatFile);
4304 LOGGER.debug("**Found existing VfModuleToHeatFiles entry for " + checkExistingEntry.toString());
4305 LOGGER.debug("No need to save...");
4309 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4314 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4316 * @param networkType
4318 * @param serviceType
4319 * @return NetworkRecipe object or null if none found
4321 public NetworkResource getNetworkResourceByModelUuid(String modelUUID) {
4323 long startTime = System.currentTimeMillis ();
4324 LOGGER.debug ("Catalog database - get network resource with modelUUID " + modelUUID);
4327 String hql = "FROM NetworkResource WHERE modelUUID=:modelUUID";
4328 Query query = getSession ().createQuery (hql);
4329 query.setParameter (MODEL_UUID, modelUUID);
4331 @SuppressWarnings("unchecked")
4332 List <NetworkResource> resultList = query.list ();
4334 if (resultList.isEmpty ()) {
4338 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4339 Collections.reverse (resultList);
4341 return resultList.get (0);
4342 } catch (Exception e) {
4343 LOGGER.debug("Error trying to find Network Resource with " + modelUUID +", " + e.getMessage(),e);
4345 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelUuid", null);
4352 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
4354 * @param networkType
4356 * @param serviceType
4357 * @return NetworkRecipe object or null if none found
4359 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
4361 long startTime = System.currentTimeMillis ();
4362 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
4365 + " and service type "
4370 if (serviceType == null) {
4371 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
4373 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
4375 Query query = getSession ().createQuery (hql);
4376 query.setParameter (NETWORK_TYPE, networkType);
4377 query.setParameter (ACTION, action);
4378 if (serviceType != null) {
4379 query.setParameter ("serviceType", serviceType);
4382 @SuppressWarnings("unchecked")
4383 List <NetworkRecipe> resultList = query.list ();
4385 if (resultList.isEmpty ()) {
4389 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4390 Collections.reverse (resultList);
4392 return resultList.get (0);
4394 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4400 * Return a Network recipe that matches a given MODEL_NAME and ACTION
4404 * @return NetworkRecipe object or null if none found
4406 public NetworkRecipe getNetworkRecipe (String modelName, String action) {
4408 long startTime = System.currentTimeMillis ();
4409 LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
4415 String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND action = :action";
4417 Query query = getSession ().createQuery (hql);
4418 query.setParameter (MODEL_NAME, modelName);
4419 query.setParameter (ACTION, action);
4421 @SuppressWarnings("unchecked")
4422 List <NetworkRecipe> resultList = query.list ();
4424 if (resultList.isEmpty ()) {
4428 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4429 Collections.reverse (resultList);
4431 return resultList.get (0);
4433 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4438 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4440 * @param networkType
4442 * @param serviceType
4443 * @return NetworkRecipe object or null if none found
4445 public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
4447 long startTime = System.currentTimeMillis ();
4448 LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
4451 String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.modelUUID=c.networkResourceModelUuid and c.modelCustomizationUuid = :modelCustomizationUuid";
4452 Query query = getSession ().createQuery (hql);
4453 query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
4455 @SuppressWarnings("unchecked")
4456 List <NetworkResource> resultList = query.list ();
4458 if (resultList.isEmpty ()) {
4462 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4463 Collections.reverse (resultList);
4465 return resultList.get (0);
4466 } catch (Exception e) {
4467 LOGGER.debug("Error trying to find Network Resource with " + modelCustomizationUuid +", " + e.getMessage(),e);
4469 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelCustUuid", null);
4475 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
4479 * @param vnfComponentType
4481 * @param serviceType
4482 * @return VnfComponentsRecipe object or null if none found
4484 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
4485 String vnfComponentType,
4487 String serviceType) {
4489 long startTime = System.currentTimeMillis ();
4490 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
4491 + " and component type "
4495 + " and service type "
4500 if (serviceType == null) {
4501 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
4503 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
4505 Query query = getSession ().createQuery (hql);
4506 query.setParameter (VNF_TYPE, vnfType);
4507 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4508 query.setParameter (ACTION, action);
4509 if (serviceType != null) {
4510 query.setParameter ("serviceType", serviceType);
4513 @SuppressWarnings("unchecked")
4514 List <VnfComponentsRecipe> resultList = query.list ();
4516 if (resultList.isEmpty ()) {
4519 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4520 Collections.reverse (resultList);
4522 return resultList.get (0);
4524 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
4529 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
4532 * @param vnfComponentType
4534 * @return VnfComponentsRecipe object or null if none found
4536 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleModelUUId (String vfModuleModelUUId,
4537 String vnfComponentType,
4540 long startTime = System.currentTimeMillis ();
4541 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleModelUUId " + vfModuleModelUUId
4542 + " and component type "
4549 hql = "FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId AND vnfComponentType = :vnfComponentType AND action = :action ";
4551 Query query = getSession ().createQuery (hql);
4552 query.setParameter (VF_MODULE_MODEL_UUID, vfModuleModelUUId);
4553 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4554 query.setParameter (ACTION, action);
4556 @SuppressWarnings("unchecked")
4557 List <VnfComponentsRecipe> resultList = query.list ();
4559 if (resultList.isEmpty ()) {
4562 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4563 Collections.reverse (resultList);
4565 return resultList.get (0);
4567 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleModelUUId", null);
4571 public List<VnfComponentsRecipe> getVnfComponentRecipes (String vfModuleModelUUId) {
4573 StringBuilder hql = null;
4575 hql = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId");
4577 long startTime = System.currentTimeMillis ();
4578 LOGGER.debug ("Catalog database - get Service recipe with vfModuleModelUUId " + vfModuleModelUUId);
4580 Query query = getSession ().createQuery (hql.toString ());
4581 query.setParameter ("vfModuleModelUUId", vfModuleModelUUId);
4583 @SuppressWarnings("unchecked")
4584 List <VnfComponentsRecipe> resultList = query.list ();
4586 if (resultList.isEmpty ()) {
4587 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getVfModuleRecipes", null);
4588 return Collections.EMPTY_LIST;
4591 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4592 Collections.reverse (resultList);
4594 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleRecipes", null);
4600 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
4601 long startTime = System.currentTimeMillis ();
4603 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
4605 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
4609 this.getSession ().save (vnfComponent);
4612 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
4617 * Return a VfModule record that matches a given MODEL_NAME
4620 * @return VfModule object or null if none found
4622 public VfModule getVfModule (String modelName) {
4624 long startTime = System.currentTimeMillis ();
4625 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
4630 hql = "FROM VfModule WHERE modelName = :modelName";
4632 Query query = getSession ().createQuery (hql);
4633 query.setParameter (MODEL_NAME, modelName);
4635 @SuppressWarnings("unchecked")
4636 List <VfModule> resultList = query.list ();
4638 if (resultList.isEmpty ()) {
4641 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4642 Collections.reverse (resultList);
4644 return resultList.get (0);
4646 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
4651 * Return a VfModule record that matches a given MODEL_NAME
4654 * @return VfModule object or null if none found
4656 public VfModule getVfModuleByModelUUID (String modelUUID) {
4658 long startTime = System.currentTimeMillis ();
4659 LOGGER.debug ("Catalog database - get vf module with modelUUID " + modelUUID);
4664 hql = "FROM VfModule WHERE modelUUID = :modelUUID";
4666 Query query = getSession ().createQuery (hql);
4667 query.setParameter (MODEL_UUID, modelUUID);
4669 @SuppressWarnings("unchecked")
4670 List <VfModule> resultList = query.list ();
4672 if (resultList.isEmpty ()) {
4675 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4676 Collections.reverse (resultList);
4678 return resultList.get (0);
4680 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUUID", null);
4685 * Return a Service recipe that matches a given service ModelUUID and action
4686 * (modelUUID) and ACTION
4690 * @return ServiceRecipe object or null if none found
4692 public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
4694 long startTime = System.currentTimeMillis();
4695 LOGGER.debug("Catalog database - get Service recipe with modelUUID=" + modelUUID + " and action=" + action);
4699 // based on the new SERVICE_RECIPE schema where SERVICE_MODEL_UUID == MODEL_UUID, a JOIN with the SERVICE table is no longer needed
4700 // hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4701 // "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4702 // "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4703 // "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4704 // "WHERE SR.serviceModelUUID = :modelUUID AND SR.action = :action";
4705 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :modelUUID AND action = :action";
4706 Query query = getSession().createQuery(hql);
4707 query.setParameter(MODEL_UUID, modelUUID);
4708 query.setParameter(ACTION, action);
4710 @SuppressWarnings("unchecked")
4711 List<ServiceRecipe> recipeResultList = query.list();
4712 if (recipeResultList.isEmpty()) {
4713 LOGGER.debug("Catalog database - recipeResultList is null");
4716 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4717 Collections.reverse(recipeResultList);
4718 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4720 return recipeResultList.get(0);
4722 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipeByModelUUID", null);
4727 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
4728 * (MODEL_VERSION_ID) and ACTION
4730 * @param modelVersionId
4732 * @return ServiceRecipe object or null if none found
4735 public ServiceRecipe getServiceRecipe(String modelVersionId,
4738 long startTime = System.currentTimeMillis();
4739 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
4740 + " and action=" + action);
4744 // Note: Even with the implementation of the HQL JOIN below, the code for the two separate
4745 // SELECTs will be retained/commented for now in the event some subsequent JOIN issue arises
4746 // 1st query to get the Service record for the given SERVICE_NAME_VERSION_ID (MODEL_VERSION_ID)
4747 /* hql = "FROM Service WHERE serviceNameVersionId = :serviceNameVersionId";
4748 Query query = getSession().createQuery(hql);
4749 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
4751 @SuppressWarnings("unchecked")
4752 List<Service> serviceResultList = query.list();
4753 if (serviceResultList.isEmpty()) {
4754 LOGGER.debug("Catalog database - serviceResultList is null");
4757 Collections.sort(serviceResultList, new MavenLikeVersioningComparator());
4758 Collections.reverse(serviceResultList);
4759 LOGGER.debug("Catalog database - serviceResultList contains " + serviceResultList.get(0).toString());
4761 // 2nd query to get the ServiceRecipe record corresponding to the Service from the 1st query
4762 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action";
4763 query = getSession().createQuery(hql);
4764 // The SERVICE table 'id' field maps to the SERVICE_RECIPE table 'SERVICE_ID' field
4765 query.setParameter(SERVICE_ID, serviceResultList.get(0).getId());
4766 query.setParameter(ACTION, action);
4768 // The following SELECT performs a JOIN across the SERVICE and SERVICE_RECIPE tables. It required a new
4769 // CTR in the ServiceRecipe Class to populate that object (the other option was to parse the Object[]
4770 // returned by createQuery() and manually populate the ServiceRecipe object). Two of the 'int' fields in the
4771 // SERVICE_RECIPE DB schema (the timeouts) permit NULL values which required some additional code in the
4772 // SELECT to generate a default of 0 (needed by the CTR) in the cases where the value is NULL.
4773 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4774 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4775 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4776 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4777 "WHERE SR.serviceModelUUID = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
4778 Query query = getSession().createQuery(hql);
4779 query.setParameter(MODEL_UUID, modelVersionId);
4780 query.setParameter(ACTION, action);
4782 @SuppressWarnings("unchecked")
4783 List<ServiceRecipe> recipeResultList = query.list();
4784 if (recipeResultList.isEmpty()) {
4785 LOGGER.debug("Catalog database - recipeResultList is null");
4788 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4789 Collections.reverse(recipeResultList);
4790 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4792 return recipeResultList.get(0);
4794 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
4799 * Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
4800 * Note: This method is not currently used but was retained in the event the
4801 * architecture moves back to a MODEL/MODEL_RECIPE structure.
4804 * @param modelVersionId
4806 * @return ModelRecipe object or null if none found
4808 public ModelRecipe getModelRecipe(String modelType,
4809 String modelVersionId,
4812 long startTime = System.currentTimeMillis();
4813 LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
4814 + " and modeVersionId=" + modelVersionId
4815 + " and action=" + action);
4819 // TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
4820 // the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
4821 // There seems to be 2 issues: formatting a hql query that executes successfully
4822 // and then being able to generate a result that will fit into the ModelRecipe class.
4824 // 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
4825 hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
4826 Query query = getSession().createQuery(hql);
4827 query.setParameter(MODEL_TYPE, modelType);
4828 query.setParameter(MODEL_VERSION_ID, modelVersionId);
4830 @SuppressWarnings("unchecked")
4831 List<Model> modelResultList = query.list();
4832 if (modelResultList.isEmpty()) {
4833 LOGGER.debug("Catalog database - modelResultList is null");
4836 Collections.sort(modelResultList, new MavenLikeVersioningComparator());
4837 Collections.reverse(modelResultList);
4838 LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
4840 // 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
4841 hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
4842 query = getSession().createQuery(hql);
4843 // The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
4844 query.setParameter(MODEL_ID, modelResultList.get(0).getId());
4845 query.setParameter(ACTION, action);
4847 @SuppressWarnings("unchecked")
4848 List<ModelRecipe> recipeResultList = query.list();
4849 if (recipeResultList.isEmpty()) {
4850 LOGGER.debug("Catalog database - recipeResultList is null");
4853 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4854 Collections.reverse(recipeResultList);
4855 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4857 return recipeResultList.get(0);
4859 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
4865 * Verify the health of the DB.
4867 * @return boolean value indicate whether DB is healthy
4869 public boolean healthCheck () {
4870 long startTime = System.currentTimeMillis ();
4871 Session session = this.getSession ();
4873 // Query query = session.createQuery (" from ActiveRequests ");
4874 Query query = session.createSQLQuery (" show tables ");
4876 List<?> list = query.list();
4877 LOGGER.debug("healthCheck CatalogDB - Successful");
4881 public < E > E executeQuerySingleRow(String hql, HashMap<String, String> variables, boolean retry) {
4882 long startTime = System.currentTimeMillis();
4883 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
4884 Query query = getSession().createQuery(hql);
4886 StringBuilder sb = new StringBuilder();
4887 if (variables != null) {
4888 for(Map.Entry<String, String> entry : variables.entrySet()){
4889 sb.append(entry.getKey() + "=" + entry.getValue() + "\n");
4890 query.setParameter(entry.getKey(), entry.getValue());
4893 LOGGER.debug("Variables:\n" + sb.toString());
4897 theObject = (E) query.uniqueResult();
4898 } catch (org.hibernate.NonUniqueResultException nure) {
4899 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row");
4900 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for " + hql, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for " + hql );
4902 } catch (org.hibernate.HibernateException he) {
4903 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
4904 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
4906 LOGGER.debug("***WILL RETRY***");
4907 return this.executeQuerySingleRow(hql, variables, false);
4911 } catch (Exception e) {
4912 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
4913 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
4915 LOGGER.debug("***WILL RETRY***");
4916 return this.executeQuerySingleRow(hql, variables, false);
4922 if (theObject == null) {
4923 LOGGER.debug("Returning null");
4924 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
4926 LOGGER.debug("Returning an Object");
4927 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
4932 public < E > List<E> executeQueryMultipleRows(String hql, HashMap<String, String> variables, boolean retry) {
4933 long startTime = System.currentTimeMillis ();
4934 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
4935 Query query = getSession().createQuery(hql);
4937 StringBuilder sb = new StringBuilder();
4938 if (variables != null) {
4939 for(Map.Entry<String, String> entry : variables.entrySet()){
4940 sb.append(entry.getKey() + "=" + entry.getValue()+ "\n");
4941 query.setParameter(entry.getKey(), entry.getValue());
4944 LOGGER.debug("Variables:\n" + sb.toString());
4946 List<E> theObjects = null;
4948 theObjects = (List<E>) query.list ();
4949 } catch (org.hibernate.HibernateException he) {
4950 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
4951 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
4953 LOGGER.debug("***WILL RETRY***");
4954 return this.executeQuerySingleRow(hql, variables, false);
4958 } catch (Exception e) {
4959 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
4960 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
4962 LOGGER.debug("***WILL RETRY***");
4963 return this.executeQuerySingleRow(hql, variables, false);
4969 if (theObjects == null) {
4970 LOGGER.debug("Returning null");
4971 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
4974 LOGGER.debug("Returning theObjects:" + theObjects.size());
4975 } catch (Exception e) {
4976 LOGGER.debug("Returning theObjects",e);
4978 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);