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).
888 * @param modelInvariantUuid model invariant ID
889 * @param modelVersion model version
890 * @return VnfResource object or null if none found
892 public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) {
894 long startTime = System.currentTimeMillis();
895 LOGGER.debug("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
897 String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion";
898 Query query = getSession().createQuery(hql);
899 query.setParameter("modelInvariantUuid", modelInvariantUuid);
900 query.setParameter("serviceVersion", modelVersion);
902 VnfResource resource = null;
904 resource = (VnfResource) query.uniqueResult();
905 } catch (org.hibernate.NonUniqueResultException nure) {
906 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'");
907 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid);
910 } catch (org.hibernate.HibernateException he) {
911 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', asdc_service_model_version='" + modelVersion + "' " + he.getMessage());
912 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid);
915 } catch (Exception e) {
916 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "' " + e.getMessage());
917 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid);
921 if (resource == null) {
922 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
924 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
930 * Return the newest version of a specific VNF resource (queried by ID).
932 * @param id The vnf id
933 * @return VnfResource object or null if none found
936 public VnfResource getVnfResourceById (int id) {
938 long startTime = System.currentTimeMillis ();
939 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
941 String hql = "FROM VnfResource WHERE id = :id";
942 Query query = getSession ().createQuery (hql);
943 query.setParameter ("id", id);
945 @SuppressWarnings("unchecked")
946 List <VnfResource> resultList = query.list ();
948 // See if something came back. Name is unique, so
949 if (resultList.isEmpty ()) {
950 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
953 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
954 return resultList.get (0);
958 * Return the newest version of a vfModule - 1607
961 public VfModule getVfModuleModelName(String modelName) {
963 long startTime = System.currentTimeMillis();
964 LOGGER.debug("Catalog database - get vfModuleModelName with name " + modelName);
966 String hql = "FROM VfModule WHERE modelName = :model_name";
967 Query query = getSession().createQuery(hql);
968 query.setParameter("model_name", modelName);
970 @SuppressWarnings("unchecked")
971 List<VfModule> resultList = query.list();
973 // See if something came back. Name is unique, so
974 if (resultList.isEmpty()) {
975 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
978 Collections.sort(resultList, new MavenLikeVersioningComparator());
979 Collections.reverse(resultList);
981 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
982 return resultList.get(0);
985 public VfModule getVfModuleModelName(String modelName, String model_version) {
987 long startTime = System.currentTimeMillis();
988 LOGGER.debug("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
990 String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
991 Query query = getSession().createQuery(hql);
992 query.setParameter("modelName", modelName);
993 query.setParameter("model_version", model_version);
995 VfModule module = null;
997 module = (VfModule) query.uniqueResult();
998 } catch (org.hibernate.NonUniqueResultException nure) {
999 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 + "'");
1000 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
1003 } catch (org.hibernate.HibernateException he) {
1004 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + he.getMessage());
1005 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
1008 } catch (Exception e) {
1009 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + e.getMessage());
1010 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
1014 if (module == null) {
1015 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
1017 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
1023 * Need this for 1707 DHV. This may be a temporary solution. May
1024 * change it to get resources using service's model name.
1029 public VfModuleCustomization getVfModuleCustomizationByModelName(String modelName) {
1031 long startTime = System.currentTimeMillis();
1032 LOGGER.debug("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
1034 String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.modelName = :model_name";
1035 Query query = getSession().createQuery(hql);
1036 query.setParameter("model_name", modelName);
1038 @SuppressWarnings("unchecked")
1039 List<VfModuleCustomization> resultList = query.list();
1041 // See if something came back. Name is unique, so
1042 if (resultList.isEmpty()) {
1043 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1047 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query ", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1048 return resultList.get(0);
1053 * Return the newest version of a specific Network resource (queried by Type).
1055 * @param networkType
1056 * @return NetworkResource object or null if none found
1058 public NetworkResource getNetworkResource(String networkType) {
1060 long startTime = System.currentTimeMillis();
1061 LOGGER.debug("Catalog database - get network resource with type " + networkType);
1063 String hql = "FROM NetworkResource WHERE model_name = :network_type";
1064 Query query = getSession().createQuery(hql);
1065 query.setParameter("network_type", networkType);
1067 @SuppressWarnings("unchecked")
1068 List <NetworkResource> resultList = query.list();
1070 // See if something came back. Name is unique, so
1071 if (resultList.isEmpty()) {
1072 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
1076 Collections.sort(resultList, new MavenLikeVersioningComparator());
1077 Collections.reverse(resultList);
1078 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
1079 return resultList.get(0);
1083 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
1087 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
1088 * @return VnfRecipe object or null if none found
1090 public VnfRecipe getVnfRecipe(String vnfType, String action, String serviceType) {
1091 boolean withServiceType = false;
1093 StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1096 if (serviceType == null || serviceType.isEmpty()) {
1097 hql.append("AND serviceType is NULL ");
1099 hql.append("AND serviceType = :serviceType ");
1100 withServiceType = true;
1103 long startTime = System.currentTimeMillis();
1104 LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
1107 + " and service type "
1110 Query query = getSession().createQuery(hql.toString());
1111 query.setParameter(VNF_TYPE, vnfType);
1112 query.setParameter(ACTION, action);
1113 if (withServiceType) {
1114 query.setParameter(SERVICE_TYPE, serviceType);
1117 @SuppressWarnings("unchecked")
1118 List <VnfRecipe> resultList = query.list();
1120 if (resultList.isEmpty()) {
1121 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1125 Collections.sort(resultList, new MavenLikeVersioningComparator());
1126 Collections.reverse(resultList);
1128 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1129 return resultList.get(0);
1133 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
1137 * @return VnfRecipe object or null if none found
1139 public VnfRecipe getVnfRecipe(String vnfType, String action) {
1140 StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1142 long startTime = System.currentTimeMillis();
1143 LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
1147 Query query = getSession().createQuery(hql.toString());
1148 query.setParameter(VNF_TYPE, vnfType);
1149 query.setParameter(ACTION, action);
1151 @SuppressWarnings("unchecked")
1152 List <VnfRecipe> resultList = query.list();
1154 if (resultList.isEmpty()) {
1155 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1159 Collections.sort(resultList, new MavenLikeVersioningComparator());
1160 Collections.reverse(resultList);
1162 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1163 return resultList.get(0);
1167 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
1171 * @return VnfRecipe object or null if none found
1173 public VnfRecipe getVnfRecipeByVfModuleId(String vnfType, String vfModuleId, String action) {
1175 StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
1177 long startTime = System.currentTimeMillis();
1178 LOGGER.debug("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
1180 Query query = getSession().createQuery(hql.toString ());
1181 query.setParameter(VF_MODULE_MODEL_UUID, vfModuleId);
1182 query.setParameter(ACTION, action);
1184 @SuppressWarnings("unchecked")
1185 List <VnfRecipe> resultList = query.list();
1187 if (resultList.isEmpty()) {
1188 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1192 Collections.sort(resultList, new MavenLikeVersioningComparator());
1193 Collections.reverse(resultList);
1195 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1196 return resultList.get(0);
1199 public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
1200 long startTime = System.currentTimeMillis();
1201 LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
1203 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
1204 Query query = getSession().createQuery(hql);
1205 query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
1207 VfModule module = null;
1209 module = (VfModule) query.uniqueResult();
1210 } catch (org.hibernate.NonUniqueResultException nure) {
1211 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1212 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1215 } catch (org.hibernate.HibernateException he) {
1216 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1217 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1220 } catch (Exception e) {
1221 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1222 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1226 if (module == null) {
1227 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
1229 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
1235 public VfModule getVfModuleType(String type) {
1236 long startTime = System.currentTimeMillis();
1237 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
1239 String hql = "FROM VfModule WHERE type = :type";
1240 Query query = getSession().createQuery(hql);
1241 query.setParameter("type", type);
1243 @SuppressWarnings("unchecked")
1244 List<VfModule> resultList = query.list();
1245 if (resultList.isEmpty()) {
1246 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
1249 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1250 Collections.reverse (resultList);
1252 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1253 return resultList.get (0);
1257 public VfModule getVfModuleType(String type, String version) {
1259 long startTime = System.currentTimeMillis();
1260 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
1262 String hql = "FROM VfModule WHERE type = :type and version = :version";
1263 Query query = getSession().createQuery(hql);
1264 query.setParameter ("type", type);
1265 query.setParameter ("version", version);
1266 VfModule module = null;
1268 module = (VfModule) query.uniqueResult ();
1269 } catch (org.hibernate.NonUniqueResultException nure) {
1270 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 + "'");
1271 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
1274 } catch (org.hibernate.HibernateException he) {
1275 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + he.getMessage());
1276 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
1279 } catch (Exception e) {
1280 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + e.getMessage());
1281 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
1285 if (module == null) {
1286 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1288 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1293 public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
1294 long startTime = System.currentTimeMillis();
1295 LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
1297 String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
1298 Query query = getSession().createQuery(hql);
1299 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1300 VnfResource vnfResource = null;
1302 vnfResource = (VnfResource) query.uniqueResult();
1303 } catch (org.hibernate.NonUniqueResultException nure) {
1304 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1305 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
1308 } catch (org.hibernate.HibernateException he) {
1309 LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + he.getMessage());
1310 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1313 } catch (Exception e) {
1314 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + e.getMessage());
1315 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1319 if (vnfResource == null) {
1320 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1322 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1327 public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
1328 long startTime = System.currentTimeMillis();
1329 LOGGER.debug("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
1331 String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
1332 Query query = getSession().createQuery(hql);
1333 query.setParameter("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
1334 VnfResource vnfResource = null;
1336 vnfResource = (VnfResource) query.uniqueResult();
1337 } catch (org.hibernate.NonUniqueResultException nure) {
1338 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
1339 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
1342 } catch (org.hibernate.HibernateException he) {
1343 LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + he.getMessage());
1344 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1347 } catch (Exception e) {
1348 LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + e.getMessage());
1349 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1353 if (vnfResource == null) {
1354 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1356 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1361 public VnfResource getVnfResourceByType(String vnfType) {
1362 return this.getVnfResource(vnfType);
1365 public VfModule getVfModuleByModelInvariantUuid(String modelInvariantUUID) {
1366 long startTime = System.currentTimeMillis();
1367 LOGGER.debug ("Catalog database - get vfModuleTypeByModelInvariantUuid with uuid " + modelInvariantUUID);
1369 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUUID ";
1370 HashMap<String, String> parameters = new HashMap<>();
1371 parameters.put("modelInvariantUUID", modelInvariantUUID);
1372 List<VfModule> modules = this.executeQueryMultipleRows(hql, parameters, true);
1373 VfModule module = null;
1375 if (modules != null && ! modules.isEmpty()) {
1376 Collections.sort (modules, new MavenLikeVersioningComparator ());
1377 Collections.reverse (modules);
1378 module = modules.get(0);
1381 if (module == null) {
1382 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1384 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1389 public VfModuleCustomization getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
1390 long startTime = System.currentTimeMillis();
1391 LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
1393 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid ";
1394 Query query = getSession().createQuery(hql);
1395 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1396 VfModuleCustomization module = null;
1398 module = (VfModuleCustomization) query.uniqueResult ();
1399 } catch (org.hibernate.NonUniqueResultException nure) {
1400 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1401 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1404 } catch (org.hibernate.HibernateException he) {
1405 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1406 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1409 } catch (Exception e) {
1410 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1411 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1415 if (module == null) {
1416 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1418 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1424 public VfModule getVfModuleByModelInvariantUuidAndModelVersion(String modelInvariantUuid, String modelVersion) {
1425 long startTime = System.currentTimeMillis();
1426 LOGGER.debug ("Catalog database - get getVfModuleByModelInvariantUuidAndModelVersion with modelInvariantUuid: " + modelInvariantUuid + ", modelVersion: " + modelVersion);
1428 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUuid and version = :modelVersion";
1429 Query query = getSession().createQuery(hql);
1430 query.setParameter ("modelInvariantUuid", modelInvariantUuid);
1431 query.setParameter("modelVersion", modelVersion);
1432 VfModule module = null;
1434 module = (VfModule) query.uniqueResult ();
1435 } catch (org.hibernate.NonUniqueResultException nure) {
1436 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "'");
1437 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);
1439 } catch (org.hibernate.HibernateException he) {
1440 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + he.getMessage());
1441 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1443 } catch (Exception e) {
1444 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + e.getMessage());
1445 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1448 if (module == null) {
1449 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1451 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1457 * Return the VfModuleCustomization object identified by the given modelCustomizationUuid 1707
1459 * @param modelCustomizationUuid
1460 * @return VfModuleCustomization or null if not found
1462 public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {
1463 long startTime = System.currentTimeMillis();
1464 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByModelCustomizationId with modelCustomizationUuid: " + modelCustomizationUuid);
1466 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1467 Query query = getSession().createQuery(hql);
1468 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1469 VfModuleCustomization VfModuleCustomization = null;
1471 VfModuleCustomization = (VfModuleCustomization) query.uniqueResult ();
1472 } catch (org.hibernate.NonUniqueResultException nure) {
1473 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1474 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1476 } catch (org.hibernate.HibernateException he) {
1477 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1478 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1480 } catch (Exception e) {
1481 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1482 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1485 if (VfModuleCustomization != null) {
1486 LOGGER.debug("Found VMC of " + VfModuleCustomization.getModelCustomizationUuid() + ", now looking for vfModule=" + VfModuleCustomization.getVfModuleModelUuid());
1487 VfModuleCustomization.setVfModule(this.getVfModuleByModelUuid(VfModuleCustomization.getVfModuleModelUuid()));
1490 if (VfModuleCustomization == null) {
1491 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1493 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1495 return VfModuleCustomization;
1499 * Return the VfModule object identified by the given modelUuid 1707
1500 * per Mike Z. - this may return more than one row - and even if it does,
1501 * the heat template will be the same - so just return any of the rows.
1504 * @return VfModule or null if not found
1506 public VfModule getVfModuleByModelUuid(String modelUuid) {
1507 long startTime = System.currentTimeMillis();
1508 LOGGER.debug ("Catalog database - get getVfModuleByModelUuid with modelUuid: " + modelUuid);
1510 String hql = "FROM VfModule WHERE modelUUID = :modelUuidValue";
1511 Query query = getSession().createQuery(hql);
1512 query.setParameter ("modelUuidValue", modelUuid);
1513 List<VfModule> vfModules = null;
1515 vfModules = query.list ();
1516 } catch (org.hibernate.HibernateException he) {
1517 LOGGER.debug("Hibernate Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + he.getMessage());
1518 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VfModule for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUuid=" + modelUuid);
1520 } catch (Exception e) {
1521 LOGGER.debug("Generic Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + e.getMessage());
1522 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUuid=" + modelUuid);
1526 if (vfModules == null || vfModules.isEmpty()) {
1527 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelUuid", null);
1530 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUuid", null);
1532 return vfModules.get(0);
1535 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1536 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1538 * @param modelCustomizationUuid
1539 * @return VnfResourceCustomization or null if not found
1541 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUuid(String modelCustomizationUuid) {
1542 long startTime = System.currentTimeMillis();
1543 LOGGER.debug ("Catalog database - get getVnfResourceByModelCustomizatonUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1545 String hql = "FROM VnfResourceCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1546 Query query = getSession().createQuery(hql);
1547 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1548 VnfResourceCustomization vnfResourceCustomization = null;
1550 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1551 } catch (org.hibernate.NonUniqueResultException nure) {
1552 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1553 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1555 } catch (org.hibernate.HibernateException he) {
1556 LOGGER.debug("Hibernate Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1557 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1559 } catch (Exception e) {
1560 LOGGER.debug("Generic Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1561 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1564 if (vnfResourceCustomization != null) {
1565 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1566 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1567 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1568 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1571 if (vnfResourceCustomization == null) {
1572 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1574 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1576 return vnfResourceCustomization;
1580 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1581 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1583 * @param getVnfResourceCustomizationByModelVersionId
1584 * @return VnfResourceCustomization or null if not found
1586 public VnfResourceCustomization getVnfResourceCustomizationByModelVersionId(String modelVersionId) {
1587 long startTime = System.currentTimeMillis();
1588 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelVersionId with modelVersionId: " + modelVersionId);
1590 String hql = "FROM VnfResourceCustomization WHERE vnfResourceModelUuid = :modelVersionId";
1591 Query query = getSession().createQuery(hql);
1592 query.setParameter ("modelVersionId", modelVersionId);
1593 VnfResourceCustomization vnfResourceCustomization = null;
1595 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1596 } catch (org.hibernate.NonUniqueResultException nure) {
1597 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"'");
1598 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId==" + modelVersionId);
1600 } catch (org.hibernate.HibernateException he) {
1601 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + he.getMessage());
1602 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId);
1604 } catch (Exception e) {
1605 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + e.getMessage());
1606 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId);
1609 if (vnfResourceCustomization != null) {
1610 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1611 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1612 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1613 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1616 if (vnfResourceCustomization == null) {
1617 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1619 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1621 return vnfResourceCustomization;
1625 * Return the VfModule object identified by the given modelCustomizationId, modelVersionId 1707
1627 * @param modelVersionId, modelCustomizationId
1628 * @return VfModule or null if not found
1630 public VfModule getVfModuleByModelCustomizationIdAndVersion(String modelCustomizationId, String modelVersionId) {
1631 long startTime = System.currentTimeMillis();
1632 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdAndVersion with modelVersionId: " + modelVersionId + " modelCustomizationId: " + modelCustomizationId);
1634 // select * from vf_module vfm where vfm.MODEL_UUID IN (
1635 // select vfmc.VF_MODULE_MODEL_UUID from vf_module_customization vfmc where vfmc.MODEL_CUSTOMIZATION_UUID='222bd8f2-341d-4419-aa0e-98398fa34050')
1636 // and vfm.MODEL_UUID = 'fa1c8558-006c-4fb6-82f2-4fc0646d6b06';
1638 String hql = "Select vfm FROM VfModule as vfm WHERE vfm.modelUUID IN ("
1639 + "SELECT vfmc.vfModuleModelUuid FROM VfModuleCustomization as vfmc "
1640 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId) "
1641 + "AND vfm.modelUUID = :modelVersionId";
1642 Query query = getSession().createQuery(hql);
1643 query.setParameter ("modelVersionId", modelVersionId);
1644 query.setParameter ("modelCustomizationId", modelCustomizationId);
1645 VfModule vfModule = null;
1647 vfModule = (VfModule) query.uniqueResult ();
1648 } catch (org.hibernate.NonUniqueResultException nure) {
1649 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"' modelCustomizationId='" + modelCustomizationId + "'");
1650 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1652 } catch (org.hibernate.HibernateException he) {
1653 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1654 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1656 } catch (Exception e) {
1657 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1658 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1662 if (vfModule == null) {
1663 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1665 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1671 * Return the VfModule object identified by the given modelCustomizationId, modelVersion, modelInvariantId 1707
1673 * @param modelCustomizationId, modelVersion, modelInvariantId
1674 * @return VfModule or null if not found
1676 public VfModule getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId(String modelCustomizationId, String modelVersion, String modelInvariantId) {
1677 long startTime = System.currentTimeMillis();
1678 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId with modelVersionId: " + modelVersion);
1680 //select * from vf_module vfm left outer join vf_module_customization vfmc on vfmc.VF_MODULE_MODEL_UUID = vfm.MODEL_UUID
1681 // where vfmc.MODEL_CUSTOMIZATION_UUID='52643a8e-7953-4e48-8eab-97165b2b3a4b' and vfm.MODEL_UUID = ''
1683 String hql = "Select vfm FROM VfModule as vfm LEFT OUTER JOIN VfModuleCustomization as vfmc on vfmc.vfModuleModelUuid = vfm.modelUUID"
1684 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId AND vfm.modelInvariantUUID = :modelInvariantId AND vfm.modelVersion = :modelVersion";
1685 Query query = getSession().createQuery(hql);
1686 query.setParameter ("modelInvariantId", modelInvariantId);
1687 query.setParameter ("modelCustomizationId", modelCustomizationId);
1688 query.setParameter ("modelVersion", modelVersion);
1689 VfModule vfModule = null;
1691 vfModule = (VfModule) query.uniqueResult ();
1692 } catch (org.hibernate.NonUniqueResultException nure) {
1693 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 +"'");
1694 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);
1696 } catch (org.hibernate.HibernateException he) {
1697 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1698 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);
1700 } catch (Exception e) {
1701 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1702 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);
1706 if (vfModule == null) {
1707 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1709 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1715 * Return the VnfResourceCustomization object identified by the given modelCustomizationName, modelInvariantId and modelVersion 1707
1717 * @param modelInvariantId, modelVersion, modelCustomizationName
1718 * @return VnfResourceCustomization or null if not found
1720 public VnfResourceCustomization getVnfResourceCustomizationByModelInvariantId(String modelInvariantId, String modelVersion, String modelCustomizationName) {
1721 long startTime = System.currentTimeMillis();
1722 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelInvariantId with modelInvariantId: " + modelInvariantId + ", modelVersion: "
1723 + modelVersion + ", modelCustomizationName: " + modelCustomizationName);
1725 String hql = "SELECT VnfResourceCustomization FROM VnfResourceCustomization as vrc "
1726 + "LEFT OUTER JOIN VnfResource as vr "
1727 + "on vr.modelUuid =vrc.vnfResourceModelUuid "
1728 + "WHERE vr.modelInvariantUuid = :modelInvariantId AND vr.modelVersion = :modelVersion AND vrc.modelInstanceName = :modelCustomizationName";
1730 Query query = getSession().createQuery(hql);
1731 query.setParameter ("modelInvariantId", modelInvariantId);
1732 query.setParameter("modelVersion", modelVersion);
1733 query.setParameter("modelCustomizationName", modelCustomizationName);
1734 VnfResourceCustomization vnfResourceCustomization = null;
1736 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1737 } catch (org.hibernate.NonUniqueResultException nure) {
1738 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 + "'");
1739 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 + "'");
1741 } catch (org.hibernate.HibernateException he) {
1742 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "' " + he.getMessage());
1743 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 + "'");
1745 } catch (Exception e) {
1746 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' " + e.getMessage());
1747 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 + "'");
1750 if (vnfResourceCustomization != null) {
1751 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1752 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUUID()));
1753 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1754 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1757 if (vnfResourceCustomization == null) {
1758 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1760 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1762 return vnfResourceCustomization;
1766 * Return list of VnfResourceCustomization objects identified by the given modelCustomizationUuid 1707
1768 * @param modelCustomizationUuid
1769 * @return List<VfModuleCustomization> or null if not found
1771 public List<VfModuleCustomization> getVfModuleCustomizationByVnfModuleCustomizationUuid(String modelCustomizationUuid) {
1772 long startTime = System.currentTimeMillis();
1773 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByVnfModuleCustomizationUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1775 // select * from vf_module_customization as vfmc where vfmc.MODEL_CUSTOMIZATION_UUID IN(
1776 // select vrcmc.VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID from vnf_res_custom_to_vf_module_custom as vrcmc
1777 // where vrcmc.VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID = 'd279139c-4b85-48ff-8ac4-9b83a6fc6da7')
1779 String hql = "SELECT vfmc FROM VfModuleCustomization as vfmc where vfmc.modelCustomizationUuid "
1780 + "IN(select vrcmc.vfModuleCustModelCustomizationUuid from VnfResCustomToVfModuleCustom as vrcmc "
1781 + "WHERE vrcmc.vnfResourceCustModelCustomizationUuid = :modelCustomizationUuid)";
1783 Query query = getSession().createQuery(hql);
1784 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1785 List<VfModuleCustomization> resultList = null;
1787 resultList = query.list();
1788 } catch (org.hibernate.HibernateException he) {
1789 LOGGER.debug("Hibernate Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + he.getMessage());
1790 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1792 } catch (Exception e) {
1793 LOGGER.debug("Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + e.getMessage());
1794 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1798 if (resultList == null) {
1799 resultList = new ArrayList<>();
1801 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByVnfModuleCustomizationUuid", null);
1806 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
1808 * @return {@link VnfResourceCustomization} object or null if none found
1810 public VnfResourceCustomization getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId (String modelCustomizationName, String modelVersionId) {
1812 long startTime = System.currentTimeMillis ();
1813 LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " modelUUID " + modelVersionId);
1815 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.vnfResourceModelUuid IN "
1816 + "(SELECT vr.modelUuid FROM VnfResource vr "
1817 + "WHERE vr.modelUuid = :modelVersionId)"
1818 + "AND vrc.modelInstanceName = :modelCustomizationName";
1820 Query query = getSession ().createQuery (hql);
1821 query.setParameter ("modelCustomizationName", modelCustomizationName);
1822 query.setParameter ("modelVersionId", modelVersionId);
1824 @SuppressWarnings("unchecked")
1825 List <VnfResourceCustomization> resultList = query.list ();
1827 if (resultList.isEmpty ()) {
1828 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1832 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1833 Collections.reverse (resultList);
1835 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1836 return resultList.get (0);
1839 public ArrayList<VfModuleCustomization> getAllVfModuleCustomizations(String vnfResourceCustomizationMCU) {
1840 LOGGER.debug ("Catalog database - getAllVfModuleCustomizations with vnfResourceCustomizationMCU " + vnfResourceCustomizationMCU);
1842 List<VnfResCustomToVfModuleCustom> matches = this.getVRCtoVFMC(vnfResourceCustomizationMCU, null);
1843 if (matches == null || matches.isEmpty()) {
1844 LOGGER.debug("Found no vf modules for " + vnfResourceCustomizationMCU);
1845 return new ArrayList<>();
1847 ArrayList<VfModuleCustomization> list = new ArrayList<>();
1848 for (VnfResCustomToVfModuleCustom v : matches) {
1849 String m = v.getVfModuleCustModelCustomizationUuid();
1850 LOGGER.debug("VfModule to match: " + m);
1851 VfModuleCustomization c = this.getVfModuleCustomizationByModelCustomizationId(m);
1855 LOGGER.debug("**UNABLE to find vfModule " + m);
1862 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1863 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1865 * @param modelCustomizationUuid
1866 * @return VnfResourceCustomization or null if not found
1868 public VnfResource getVnfResourceByModelUuid(String modelUuid) {
1869 long startTime = System.currentTimeMillis();
1870 LOGGER.debug ("Catalog database - get VnfResource with modelUuid " + modelUuid);
1872 String hql = "FROM VnfResource WHERE modelUuid = :modelUuid";
1873 Query query = getSession().createQuery(hql);
1874 query.setParameter ("modelUuid", modelUuid);
1875 VnfResource vnfResource = null;
1877 vnfResource = (VnfResource) query.uniqueResult ();
1878 } catch (org.hibernate.NonUniqueResultException nure) {
1879 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique Vnf_Resource row - data integrity error: modelUuid='" + modelUuid);
1880 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for Vnf Resource modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResource modelUuid==" + modelUuid);
1882 } catch (org.hibernate.HibernateException he) {
1883 LOGGER.debug("Hibernate Exception - while searching for: VnfResource modelUuid='" + modelUuid + "' " + he.getMessage());
1884 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResource modelUuid=" + modelUuid);
1886 } catch (Exception e) {
1887 LOGGER.debug("Generic Exception - while searching for: vnfResource ModelUuid='" + modelUuid + "'");
1888 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResource modelUuid=" + modelUuid);
1891 if (vnfResource == null) {
1892 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelUuid", null);
1894 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelUuid", null);
1899 public VnfResCustomToVfModuleCustom getVnfResCustomToVfModule(String vnfId, String vfId) {
1900 long startTime = System.currentTimeMillis();
1901 LOGGER.debug("Catalog database - getVnfResCustomToVfModule - vnfResourceCustModelCustUuid: " + vnfId + ", vfModuleCustModelCustomUuid=" + vfId);
1902 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue");
1903 HashMap<String, String> parameters = new HashMap<>();
1904 parameters.put("vnfIdValue", vnfId);
1905 parameters.put("vfIdValue", vfId);
1906 VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow(hql.toString(), parameters, true);
1907 if (vrctvmc == null) {
1908 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResCustomToVfModule", null);
1910 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResCustomToVfModule", null);
1915 public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
1916 if (vnfResource == null)
1917 return Collections.EMPTY_LIST;
1918 String vnfResourceModelUuid = vnfResource.getModelUuid();
1920 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
1922 return this.getVfModulesForVnfResource(vnfResourceModelUuid);
1926 public List<VfModule> getVfModulesForVnfResource(String vnfResourceModelUuid) {
1927 long startTime = System.currentTimeMillis();
1928 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceModelUuid: " + vnfResourceModelUuid);
1929 StringBuilder hql = new StringBuilder("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId");
1930 Query query = getSession().createQuery(hql.toString());
1931 query.setParameter("vnfResourceModelUUId", vnfResourceModelUuid);
1932 List<VfModule> resultList = null;
1934 resultList = query.list();
1935 if (resultList != null)
1936 LOGGER.debug("\tQuery found " + resultList.size() + " records.");
1938 LOGGER.debug("\tQuery found no records.");
1939 } catch (org.hibernate.HibernateException he) {
1940 LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + he.getMessage());
1941 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1943 } catch (Exception e) {
1944 LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + e.getMessage());
1945 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1948 if (resultList == null) {
1949 resultList = new ArrayList<>();
1951 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
1955 public Service getServiceByUuid (String serviceModelInvariantUuid) {
1957 long startTime = System.currentTimeMillis ();
1958 LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
1960 String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
1961 Query query = getSession ().createQuery (hql);
1962 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1964 Service service = null;
1966 service = (Service) query.uniqueResult ();
1967 } catch (org.hibernate.NonUniqueResultException nure) {
1968 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
1969 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1971 } catch (org.hibernate.HibernateException he) {
1972 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "' " + he.getMessage());
1973 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1975 } catch (Exception e) {
1976 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + " " + e.getMessage());
1977 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1980 if (service == null) {
1981 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
1983 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
1989 public NetworkResource getNetworkResourceById(Integer id) {
1990 long startTime = System.currentTimeMillis ();
1991 LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
1993 String hql = "FROM NetworkResource WHERE id = :id";
1994 Query query = getSession ().createQuery (hql);
1995 query.setParameter ("id", id);
1997 NetworkResource networkResource = null;
1999 networkResource = (NetworkResource) query.uniqueResult ();
2000 } catch (org.hibernate.NonUniqueResultException nure) {
2001 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
2002 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
2004 } catch (org.hibernate.HibernateException he) {
2005 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2006 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
2008 } catch (Exception e) {
2009 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2010 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
2014 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2015 return networkResource;
2019 public NetworkResource getNetworkResourceById(String id) {
2020 long startTime = System.currentTimeMillis ();
2021 LOGGER.debug ("Catalog database - getNetworkResource with model_uuid " + id);
2023 String hql = "FROM NetworkResource WHERE modelUUID = :model_uuid";
2024 Query query = getSession ().createQuery (hql);
2025 query.setParameter ("model_uuid", id);
2027 List<NetworkResource> networkResources = null;
2029 networkResources = query.list ();
2030 } catch (org.hibernate.HibernateException he) {
2031 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2032 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);
2034 } catch (Exception e) {
2035 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2036 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);
2040 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2041 if (networkResources == null || networkResources.isEmpty())
2044 return networkResources.get(0);
2049 public static boolean isEmptyOrNull(String str) {
2052 if ("null".equals(str))
2059 public List<ServiceToResourceCustomization> getSTR(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
2060 LOGGER.debug("Catalog database: getSTR - smu=" + serviceModelUuid + ", rmcu=" + resourceModelCustomizationUuid + ", modelType = " + modelType);
2062 if (isEmptyOrNull(serviceModelUuid) && isEmptyOrNull(resourceModelCustomizationUuid) && isEmptyOrNull(modelType))
2065 StringBuilder hql = new StringBuilder("FROM ServiceToResourceCustomization WHERE ");
2066 boolean first = true;
2067 if (serviceModelUuid != null && !serviceModelUuid.equals("")) {
2068 hql.append("serviceModelUUID = :smu");
2071 if (resourceModelCustomizationUuid != null && !resourceModelCustomizationUuid.equals("")) {
2073 hql.append(" AND ");
2075 hql.append("resourceModelCustomizationUUID = :rmcu");
2078 if (modelType != null && !modelType.equals("")) {
2080 hql.append(" AND ");
2083 hql.append("modelType = :modelType");
2086 Query query = getSession().createQuery(hql.toString());
2087 if (hql.toString().contains(":smu"))
2088 query.setParameter("smu", serviceModelUuid);
2089 if (hql.toString().contains(":rmcu"))
2090 query.setParameter("rmcu", resourceModelCustomizationUuid);
2091 if (hql.toString().contains(":modelType"))
2092 query.setParameter("modelType", modelType);
2093 LOGGER.debug("query - " + hql.toString());
2095 @SuppressWarnings("unchecked")
2096 List<ServiceToResourceCustomization> resultList = query.list();
2097 if (resultList == null || resultList.isEmpty()) {
2098 LOGGER.debug("Found no matches to the query - " + hql.toString());
2099 return new ArrayList<>();
2104 public List<VnfResCustomToVfModuleCustom> getVRCtoVFMC (String vrc_mcu, String vfmc_mcu) {
2105 LOGGER.debug("Catalog database: getVRCtoVFMC - vrc_mcu=" + vrc_mcu + ", vfmc_mcu=" + vfmc_mcu);
2107 if (isEmptyOrNull(vrc_mcu) && isEmptyOrNull(vfmc_mcu))
2110 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom WHERE ");
2111 boolean first = true;
2112 if (vrc_mcu != null && !vrc_mcu.equals("")) {
2113 hql.append("vnfResourceCustModelCustomizationUuid = :vrc_mcu");
2116 if (vfmc_mcu != null && !vfmc_mcu.equals("")) {
2118 hql.append(" AND ");
2120 hql.append("vfModuleCustModelCustomizationUuid = :vfmc_mcu");
2123 Query query = getSession().createQuery(hql.toString());
2124 if (hql.toString().contains(":vrc_mcu"))
2125 query.setParameter("vrc_mcu", vrc_mcu);
2126 if (hql.toString().contains(":vfmc_mcu"))
2127 query.setParameter("vfmc_mcu", vfmc_mcu);
2128 @SuppressWarnings("unchecked")
2129 List<VnfResCustomToVfModuleCustom> resultList = query.list();
2130 if (resultList == null || resultList.isEmpty()) {
2131 LOGGER.debug("Found no matches to the query - " + hql.toString());
2132 return new ArrayList<>();
2137 @SuppressWarnings("unchecked")
2138 public List <TempNetworkHeatTemplateLookup> getTempNetworkHeatTemplateLookup (String networkResourceModelName) {
2140 long startTime = System.currentTimeMillis ();
2141 LOGGER.debug ("Catalog database - GetTempNetworkHeatTemplateLookup for Network Name " + networkResourceModelName);
2143 String hql = "FROM TempNetworkHeatTemplateLookup where networkResourceModelName = :networkResourceModelName";
2144 Query query = getSession ().createQuery (hql);
2145 query.setParameter ("networkResourceModelName", networkResourceModelName);
2147 List <TempNetworkHeatTemplateLookup> result = query.list ();
2148 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getTempNetworkHeatTemplateLookup", null);
2152 // 1702 API Spec - Query for all networks in a Service:
2153 public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
2154 long startTime = System.currentTimeMillis();
2155 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
2157 List<ServiceToResourceCustomization> strMappings = this.getSTR(serviceModelUuid, null, "network");
2158 if (strMappings == null || strMappings.isEmpty()) {
2159 LOGGER.debug("Found NO matches for NRC with ServiceModelUuid=" + serviceModelUuid);
2160 return new ArrayList<>();
2162 LOGGER.debug("Found " + strMappings.size() + " entries in ServiceToResourceCustomizations.network with smu=" + serviceModelUuid);
2164 ArrayList<NetworkResourceCustomization> masterList = new ArrayList<>();
2165 for (ServiceToResourceCustomization stn : strMappings) {
2166 String networkModelCustomizationUuid = stn.getResourceModelCustomizationUUID();
2167 LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
2168 List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
2169 masterList.addAll(resultSet);
2171 LOGGER.debug("Returning " + masterList.size() + " NRC records");
2172 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
2175 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2176 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2178 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2179 Query query = getSession().createQuery(hql.toString());
2180 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2181 @SuppressWarnings("unchecked")
2182 List<Service> serviceList = query.list();
2184 if (serviceList.isEmpty()) {
2185 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2186 return new ArrayList<>();
2189 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2190 Collections.reverse (serviceList);
2191 Service service = serviceList.get(0);
2193 String serviceNameVersionId = service.getModelUUID();
2194 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
2196 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2197 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2199 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2200 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2202 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2203 Query query = getSession().createQuery(hql.toString());
2204 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2205 query.setParameter("serviceModelVersion", serviceModelVersion);
2208 //can fix this later - no time - could do a unique query here - but this should work
2209 @SuppressWarnings("unchecked")
2210 List<Service> serviceList = query.list();
2212 if (serviceList.isEmpty()) {
2213 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2214 return new ArrayList<>();
2217 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2218 Collections.reverse (serviceList);
2219 Service service = serviceList.get(0);
2221 String serviceNameVersionId = service.getModelUUID();
2223 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2224 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2227 public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
2228 long startTime = System.currentTimeMillis();
2229 LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
2231 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid");
2232 //Query query = getSession().createQuery(hql.toString());
2233 //query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
2234 //LOGGER.debug("QUERY: " + hql.toString() + ", networkModelCustomizationUuid=" + networkModelCustomizationUuid);
2236 //@SuppressWarnings("unchecked")
2237 //List<NetworkResourceCustomization> resultList = query.list();
2239 HashMap<String, String> params = new HashMap<>();
2240 params.put("networkModelCustomizationUuid", networkModelCustomizationUuid);
2242 List<NetworkResourceCustomization> resultList = this.executeQueryMultipleRows(hql.toString(), params, true);
2244 if (resultList.isEmpty()) {
2245 LOGGER.debug("Unable to find an NMC with nmcu=" + networkModelCustomizationUuid);
2246 return new ArrayList<>();
2248 for (NetworkResourceCustomization nrc : resultList) {
2249 nrc.setNetworkResource(this.getNetworkResourceById(nrc.getNetworkResourceModelUuid()));
2253 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
2257 public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
2258 long startTime = System.currentTimeMillis();
2259 LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
2261 NetworkResource nr = this.getNetworkResource(networkType);
2263 return new ArrayList<>();
2265 String networkResourceId = nr.getModelUUID();
2267 LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
2268 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId");
2270 Query query = getSession().createQuery(hql.toString());
2271 query.setParameter("networkResourceId", networkResourceId);
2273 @SuppressWarnings("unchecked")
2274 List<NetworkResourceCustomization> resultList = query.list();
2276 if (resultList != null && ! resultList.isEmpty()) {
2277 LOGGER.debug("Found " + resultList.size() + " results");
2278 for (NetworkResourceCustomization nrc : resultList) {
2279 nrc.setNetworkType(networkType);
2280 nrc.setNetworkResource(nr);
2283 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
2287 public ArrayList<VfModuleCustomization> getAllVfmcForVrc(VnfResourceCustomization vrc) {
2288 LOGGER.debug("Catalog database: getAllVfmcForVrc - " + vrc.getModelCustomizationUuid());
2290 List<VnfResCustomToVfModuleCustom> vfmcs = this.getVRCtoVFMC(vrc.getModelCustomizationUuid(), null);
2291 if (vfmcs == null || vfmcs.isEmpty()) {
2292 return new ArrayList<>();
2294 ArrayList<VfModuleCustomization> vfModuleCusts = new ArrayList<>();
2295 for (VnfResCustomToVfModuleCustom vfmc : vfmcs) {
2296 VfModuleCustomization vfmcust = this.getVfModuleCustomizationByModelCustomizationId(vfmc.getVfModuleCustModelCustomizationUuid());
2297 if (vfmcust != null) {
2298 vfModuleCusts.add(vfmcust);
2301 return vfModuleCusts;
2304 //1702 API Spec cont'd - Query for all VnfResources in a Service:
2305 //1707 modified for db refactoring
2306 public List<VnfResourceCustomization> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
2307 LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
2309 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2310 Query query = getSession().createQuery(hql.toString());
2311 query.setParameter("serviceModelUuid", serviceModelUuid);
2312 @SuppressWarnings("unchecked")
2313 List<Service> serviceList = query.list();
2315 if (serviceList.isEmpty()) {
2316 LOGGER.debug("Unable to find a service with modelUuid=" + serviceModelUuid);
2317 return new ArrayList<>();
2320 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2321 Collections.reverse (serviceList);
2323 // Step 2 - Now query to get the related VnfResourceCustomizations
2325 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "vnf");
2327 if (strcs.isEmpty()) {
2328 LOGGER.debug("Unable to find any related vnfs to a service with modelUuid=" + serviceModelUuid);
2329 return new ArrayList<>();
2332 ArrayList<VnfResourceCustomization> allVrcs = new ArrayList<>();
2333 for (ServiceToResourceCustomization strc : strcs) {
2334 LOGGER.debug("Try to find VRC for mcu=" + strc.getResourceModelCustomizationUUID());
2335 VnfResourceCustomization vrc = this.getVnfResourceCustomizationByModelCustomizationUuid(strc.getResourceModelCustomizationUUID());
2342 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2343 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2345 StringBuilder hqlService = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2346 Query query = getSession().createQuery(hqlService.toString());
2347 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2348 @SuppressWarnings("unchecked")
2349 List<Service> resultList = query.list();
2351 if (resultList.isEmpty()) {
2352 return new ArrayList<>();
2354 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2355 Collections.reverse (resultList);
2356 Service service = resultList.get(0);
2357 //now just call the method that takes the version - the service object will have the highest version
2358 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2360 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2361 long startTime = System.currentTimeMillis();
2362 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2364 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2365 Query query = getSession().createQuery(hql.toString());
2366 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2367 query.setParameter("serviceModelVersion", serviceModelVersion);
2369 @SuppressWarnings("unchecked")
2370 List<Service> resultList = query.list();
2372 if (resultList.isEmpty()) {
2373 return new ArrayList<>();
2375 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2376 Collections.reverse (resultList);
2377 Service service = resultList.get(0);
2378 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
2379 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2382 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
2383 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
2384 if (serviceVersion == null || serviceVersion.equals("")) {
2385 return this.getAllVnfsByServiceName(serviceName);
2388 StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName and version = :serviceVersion");
2389 Query query = getSession().createQuery(hql.toString());
2390 query.setParameter("serviceName", serviceName);
2391 query.setParameter("serviceVersion", serviceVersion);
2393 @SuppressWarnings("unchecked")
2394 List<Service> resultList = query.list();
2396 if (resultList.isEmpty()) {
2397 return Collections.EMPTY_LIST;
2399 Service service = resultList.get(0);
2400 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2402 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName) {
2403 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
2405 StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName");
2406 Query query = getSession().createQuery(hql.toString());
2407 query.setParameter("serviceName", serviceName);
2409 @SuppressWarnings("unchecked")
2410 List<Service> resultList = query.list();
2412 if (resultList.isEmpty()) {
2413 return Collections.EMPTY_LIST;
2415 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2416 Collections.reverse (resultList);
2417 Service service = resultList.get(0);
2419 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2422 public List<VnfResourceCustomization> getAllVnfsByVnfModelCustomizationUuid(String vnfModelCustomizationUuid) {
2423 long startTime = System.currentTimeMillis();
2424 LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid);
2426 StringBuilder hql1 = new StringBuilder("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu");
2427 Query query1 = getSession().createQuery(hql1.toString());
2428 query1.setParameter("vrcmcu", vnfModelCustomizationUuid);
2429 @SuppressWarnings("unchecked")
2430 List<VnfResourceCustomization> resultList1 = query1.list();
2432 if (resultList1.isEmpty()) {
2433 LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
2434 return Collections.EMPTY_LIST;
2437 for (VnfResourceCustomization vrc : resultList1) {
2438 VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid());
2439 vrc.setVnfResource(vr);
2440 vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc));
2443 LOGGER.debug("Returning " + resultList1.size() + " vnf modules");
2444 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
2448 //1702 API Spec cont'd - Query for all allotted resources in a Service
2450 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
2451 long startTime = System.currentTimeMillis();
2452 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
2454 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "allottedResource");
2455 if (strcs == null || strcs.isEmpty()) {
2456 LOGGER.debug("No AR entries found for " + serviceModelUuid);
2457 return new ArrayList<>();
2459 LOGGER.debug("Found " + strcs.size() + " entries in ServiceToResourceCustomizations with smu=" + serviceModelUuid + ", allottedResource");
2461 ArrayList<AllottedResourceCustomization> masterList = new ArrayList<>();
2462 for (ServiceToResourceCustomization star : strcs) {
2463 String arModelCustomizationUuid = star.getResourceModelCustomizationUUID();
2464 LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
2465 List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
2466 masterList.addAll(resultSet);
2468 LOGGER.debug("Returning " + masterList.size() + " ARC records");
2469 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
2473 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2474 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2476 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2477 Query query = getSession().createQuery(hql.toString());
2478 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2479 @SuppressWarnings("unchecked")
2480 List<Service> serviceList = query.list();
2482 if (serviceList.isEmpty()) {
2483 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2484 return new ArrayList<>();
2487 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2488 Collections.reverse (serviceList);
2489 Service service = serviceList.get(0);
2491 String serviceModelUuid = service.getModelUUID();
2492 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceModelUuid);
2494 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2497 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2498 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2500 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2501 Query query = getSession().createQuery(hql.toString());
2502 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2503 query.setParameter("serviceModelVersion", serviceModelVersion);
2505 @SuppressWarnings("unchecked")
2506 List<Service> serviceList = query.list();
2508 if (serviceList.isEmpty()) {
2509 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2510 return new ArrayList<>();
2513 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2514 Collections.reverse (serviceList);
2515 Service service = serviceList.get(0);
2517 String serviceModelUuid = service.getModelUUID();
2519 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2522 public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
2523 long startTime = System.currentTimeMillis();
2524 LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
2526 StringBuilder hql = new StringBuilder("FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
2527 Query query = getSession().createQuery(hql.toString());
2528 query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
2530 @SuppressWarnings("unchecked")
2531 List<AllottedResourceCustomization> resultList = query.list();
2533 if (resultList.isEmpty()) {
2534 LOGGER.debug("No ARC found with arc_mcu=" + arModelCustomizationUuid);
2535 return new ArrayList<>();
2537 // There should only be one - but we'll handle if multiple
2538 for (AllottedResourceCustomization arc : resultList) {
2539 AllottedResource ar = this.getAllottedResourceByModelUuid(arc.getArModelUuid());
2540 arc.setAllottedResource(ar);
2543 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
2547 public AllottedResource getAllottedResourceByModelUuid(String arModelUuid) {
2548 long startTime = System.currentTimeMillis ();
2549 LOGGER.debug ("Catalog database - get Allotted Resource with modelUuid= " + arModelUuid);
2551 String hql = "FROM AllottedResource WHERE modelUuid = :arModelUuid";
2552 Query query = getSession ().createQuery (hql);
2553 query.setParameter ("arModelUuid", arModelUuid);
2555 @SuppressWarnings("unchecked")
2556 List <AllottedResource> resultList = query.list ();
2558 // See if something came back. Name is unique, so
2559 if (resultList.isEmpty ()) {
2560 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. AllottedResource not found", "CatalogDB", "getAllottedResourceByModelUuid", null);
2563 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllottedResourceByModelUuid", null);
2564 return resultList.get (0);
2568 //1702 API Spec cont'd - Query for all resources in a Service:
2569 public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
2570 long startTime = System.currentTimeMillis();
2571 LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
2573 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2574 Query query = getSession().createQuery(hql.toString());
2575 query.setParameter("serviceModelUuid", serviceModelUuid);
2576 LOGGER.debug("Query: " + hql.toString() + ", smu=" + serviceModelUuid);
2577 @SuppressWarnings("unchecked")
2578 List<Service> serviceList = query.list();
2580 if (serviceList.isEmpty()) {
2581 LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
2582 return new ServiceMacroHolder();
2585 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2586 Collections.reverse (serviceList);
2587 Service service = serviceList.get(0);
2589 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2590 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
2591 smh.setNetworkResourceCustomization(nrcList);
2592 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2593 smh.setAllottedResourceCustomization(arcList);
2594 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(serviceModelUuid);
2595 smh.setVnfResourceCustomizations(vnfList);
2597 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
2600 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2601 long startTime = System.currentTimeMillis();
2602 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2604 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2605 Query query = getSession().createQuery(hql.toString());
2606 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2607 @SuppressWarnings("unchecked")
2608 List<Service> serviceList = query.list();
2610 if (serviceList.isEmpty()) {
2611 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2612 return new ServiceMacroHolder();
2615 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2616 Collections.reverse (serviceList);
2617 Service service = serviceList.get(0);
2619 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2620 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2621 smh.setNetworkResourceCustomization(nrcList);
2622 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2623 smh.setAllottedResourceCustomization(arcList);
2624 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2625 smh.setVnfResourceCustomizations(vnfList);
2627 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
2631 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2632 long startTime = System.currentTimeMillis();
2633 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2635 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2636 Query query = getSession().createQuery(hql.toString());
2637 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2638 query.setParameter("serviceModelVersion", serviceModelVersion);
2639 //TODO make this a unique query
2640 @SuppressWarnings("unchecked")
2641 List<Service> serviceList = query.list();
2643 if (serviceList.isEmpty()) {
2644 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
2645 return new ServiceMacroHolder();
2648 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2649 Collections.reverse (serviceList);
2650 Service service = serviceList.get(0);
2652 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2653 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2654 smh.setNetworkResourceCustomization(nrcList);
2655 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2656 smh.setAllottedResourceCustomization(arcList);
2657 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2658 smh.setVnfResourceCustomizations(vnfList);
2660 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
2664 // 1707 New API queries
2665 public NetworkResourceCustomization getSingleNetworkByModelCustomizationUuid(String modelCustomizationUuid) {
2666 LOGGER.debug("Catalog database; getSingleNetworkByModelCustomizationUuid - " + modelCustomizationUuid);
2667 List<NetworkResourceCustomization> resultList = this.getAllNetworksByNetworkModelCustomizationUuid(modelCustomizationUuid);
2668 if (resultList == null || resultList.isEmpty()) {
2671 return resultList.get(0);
2673 public AllottedResourceCustomization getSingleAllottedResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2674 LOGGER.debug("Catalog database; getSingleAllottedResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2675 List<AllottedResourceCustomization> resultList = this.getAllAllottedResourcesByArModelCustomizationUuid(modelCustomizationUuid);
2676 if (resultList == null || resultList.isEmpty()) {
2679 return resultList.get(0);
2682 public VnfResource getSingleVnfResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2684 long startTime = System.currentTimeMillis();
2685 LOGGER.debug("Catalog database; getSingleVnfResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2686 List<VnfResource> resultList = this.getAllVnfsByVnfModelCustomizationUuid(modelCustomizationUuid);
2687 if (resultList == null || resultList.size() < 1) {
2690 return resultList.get(0);
2695 private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
2696 HashMap<String, NetworkResource> networkResources = new HashMap<String, NetworkResource>();
2698 for (NetworkResourceCustomization nrc : resultList) {
2699 String network_id = nrc.getNetworkResourceModelUuid();
2700 if (network_id == null) {
2701 nrc.setNetworkResource(null);
2702 nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
2705 if (networkResources.containsKey(network_id)) {
2706 nrc.setNetworkResource(networkResources.get(network_id));
2707 nrc.setNetworkType(networkResources.get(network_id).getModelName());
2709 NetworkResource nr = this.getNetworkResourceById(network_id);
2711 nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
2713 nrc.setNetworkType(nr.getModelName());
2714 nrc.setNetworkResource(nr);
2715 networkResources.put(network_id, nr);
2722 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
2723 * first query VF_MODULE table by type, and then use the ID to query
2724 * VNF_RECIPE by VF_MODULE_ID and ACTION
2727 * @parm vfModuleModelName
2729 * @return VnfRecipe object or null if none found
2731 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
2732 String vfModuleType = vnfType + "::" + vfModuleModelName;
2734 StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type ");
2736 long startTime = System.currentTimeMillis ();
2737 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
2739 Query query = getSession ().createQuery (hql.toString ());
2740 query.setParameter (TYPE, vfModuleType);
2742 @SuppressWarnings("unchecked")
2743 List <VfModule> resultList = query.list ();
2745 if (resultList.isEmpty ()) {
2746 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
2750 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2751 Collections.reverse (resultList);
2753 VfModule vfMod = resultList.get(0);
2755 String vfModuleId = vfMod.getModelUUID();
2757 StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2759 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
2763 Query query1 = getSession ().createQuery (hql1.toString ());
2764 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2765 query1.setParameter (ACTION, action);
2767 @SuppressWarnings("unchecked")
2768 List <VnfRecipe> resultList1 = query1.list ();
2770 if (resultList1.isEmpty ()) {
2771 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
2775 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2776 Collections.reverse (resultList1);
2778 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
2779 return resultList1.get (0);
2783 * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2784 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2786 * @param vnfModuleType
2787 * @parm modelCustomizationUuid
2788 * @param asdcServiceModelVersion
2789 * @param modelVersion
2791 * @return VfModule list
2793 public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2796 if(modelCustomizationUuid != null){
2797 hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
2799 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2801 query = getSession ().createQuery (hql.toString ());
2802 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
2803 query.setParameter ("version", asdcServiceModelVersion);
2805 hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
2807 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2809 query = getSession ().createQuery (hql.toString ());
2810 query.setParameter (TYPE, vfModuleType);
2811 query.setParameter ("version", asdcServiceModelVersion);
2812 query.setParameter ("modelVersion", modelVersion);
2815 @SuppressWarnings("unchecked")
2816 List <VfModule> resultList = query.list ();
2822 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2823 * MODEL_CUSTOMIZATION_UUID, ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2824 * first query VF_MODULE table by type, and then use the ID to query
2825 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2828 * @parm vfModuleModelName
2830 * @return VnfRecipe object or null if none found
2832 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2833 String vfModuleType = vnfType + "::" + vfModuleModelName;
2834 long startTime = System.currentTimeMillis ();
2835 List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
2837 if (resultList.isEmpty ()) {
2838 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2842 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2843 Collections.reverse (resultList);
2845 VfModule vfMod = resultList.get(0);
2847 String vfModuleId = vfMod.getModelUUID();
2849 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2851 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2855 Query query1 = getSession ().createQuery (hql1.toString ());
2856 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2857 query1.setParameter (ACTION, action);
2859 @SuppressWarnings("unchecked")
2860 List <VnfComponentsRecipe> resultList1 = query1.list ();
2862 if (resultList1.isEmpty ()) {
2863 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2867 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2868 Collections.reverse (resultList1);
2870 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2871 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2872 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);
2875 return resultList1.get (0);
2879 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2880 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2881 * first query VF_MODULE table by type, and then use the ID to query
2882 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2885 * @parm vfModuleModelName
2887 * @return VnfRecipe object or null if none found
2889 public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
2890 long startTime = System.currentTimeMillis ();
2892 if (resultList.isEmpty ()) {
2893 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2897 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2898 Collections.reverse (resultList);
2900 VfModule vfMod = resultList.get(0);
2902 String vfModuleId = vfMod.getModelName();
2904 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2906 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2910 Query query1 = getSession ().createQuery (hql1.toString ());
2911 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2912 query1.setParameter (ACTION, action);
2914 @SuppressWarnings("unchecked")
2915 List <VnfComponentsRecipe> resultList1 = query1.list ();
2917 if (resultList1.isEmpty ()) {
2918 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2922 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2923 Collections.reverse (resultList1);
2925 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2926 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2927 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);
2930 return resultList1.get (0);
2935 * Return all VNF Resources in the Catalog DB
2937 * @return A list of VnfResource objects
2939 @SuppressWarnings("unchecked")
2940 public List <VnfResource> getAllVnfResources () {
2942 long startTime = System.currentTimeMillis ();
2943 LOGGER.debug ("Catalog database - get all VNF resources");
2945 String hql = "FROM VnfResource";
2946 Query query = getSession ().createQuery (hql);
2948 List <VnfResource> result = query.list ();
2949 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
2954 * Return VNF Resources in the Catalog DB that match a given VNF role
2956 * @return A list of VnfResource objects
2958 @SuppressWarnings("unchecked")
2959 @Deprecated // vnfRole is no longer in VnfResource
2960 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
2962 long startTime = System.currentTimeMillis ();
2963 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
2965 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
2966 Query query = getSession ().createQuery (hql);
2967 query.setParameter ("vnfRole", vnfRole);
2969 List <VnfResource> resources = query.list ();
2970 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
2975 * Return VNF Resources in the Catalog DB that match a given VNF role
2977 * @return A list of VnfResource objects
2979 @SuppressWarnings("unchecked")
2980 public List<VnfResourceCustomization> getVnfResourceCustomizationsByRole(String vnfRole) {
2981 long startTime = System.currentTimeMillis ();
2982 LOGGER.debug ("Catalog database - get all VNF resource customizations for role " + vnfRole);
2984 String hql = "FROM VnfResourceCustomization WHERE nfRole = :vnfRole";
2985 Query query = getSession ().createQuery (hql);
2986 query.setParameter ("vnfRole", vnfRole);
2988 List <VnfResourceCustomization> resources = query.list ();
2989 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationsByRole", null);
2994 * Return all Network Resources in the Catalog DB
2996 * @return A list of NetworkResource objects
2998 @SuppressWarnings("unchecked")
2999 public List <NetworkResource> getAllNetworkResources () {
3001 long startTime = System.currentTimeMillis ();
3002 LOGGER.debug ("Catalog database - get all network resources");
3004 String hql = "FROM NetworkResource";
3005 Query query = getSession ().createQuery (hql);
3007 List <NetworkResource> result = query.list ();
3008 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
3012 @SuppressWarnings("unchecked")
3013 public List<NetworkResourceCustomization> getAllNetworkResourceCustomizations() {
3014 long startTime = System.currentTimeMillis ();
3015 LOGGER.debug ("Catalog database - get all network resource customizations");
3017 String hql = "FROM NetworkResourceCustomization";
3018 Query query = getSession ().createQuery (hql);
3020 List <NetworkResourceCustomization> result = query.list ();
3021 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResourceCustomizations", null);
3026 * Return all VF Modules in the Catalog DB
3028 * @return A list of VfModule objects
3030 @SuppressWarnings("unchecked")
3031 public List <VfModule> getAllVfModules () {
3033 long startTime = System.currentTimeMillis ();
3034 LOGGER.debug ("Catalog database - get all vf modules");
3036 String hql = "FROM VfModule";
3037 Query query = getSession ().createQuery (hql);
3039 List <VfModule> result = query.list ();
3040 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
3044 @SuppressWarnings("unchecked")
3045 public List <VfModuleCustomization> getAllVfModuleCustomizations () {
3047 long startTime = System.currentTimeMillis ();
3048 LOGGER.debug ("Catalog database - get all vf module customizations");
3050 String hql = "FROM VfModuleCustomization";
3051 Query query = getSession ().createQuery (hql);
3053 List <VfModuleCustomization> result = query.list ();
3054 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModuleCustomizations", null);
3060 * Return all HeatEnvironment in the Catalog DB
3062 * @return A list of HeatEnvironment objects
3064 @SuppressWarnings("unchecked")
3065 public List <HeatEnvironment> getAllHeatEnvironment () {
3067 long startTime = System.currentTimeMillis ();
3068 LOGGER.debug ("Catalog database - get all Heat environments");
3070 String hql = "FROM HeatEnvironment";
3071 Query query = getSession ().createQuery (hql);
3073 List <HeatEnvironment> result = query.list ();
3074 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
3079 * Fetch the Environment by Environment ID - 1510
3081 @Deprecated // no longer in heat envt table
3082 public HeatEnvironment getHeatEnvironment (int id) {
3084 long startTime = System.currentTimeMillis ();
3085 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
3087 String hql = "FROM HeatEnvironment WHERE id = :idValue";
3089 LOGGER.debug ("getHeatEnvironment called with id=" + id);
3091 Query query = getSession ().createQuery (hql);
3092 query.setParameter ("idValue", id);
3094 @SuppressWarnings("unchecked")
3095 List <HeatEnvironment> resultList = query.list ();
3097 // See if something came back.
3098 if (resultList.isEmpty ()) {
3099 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
3102 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
3103 return resultList.get (0);
3107 * Fetch the nested templates - 1510
3111 public Map <String, Object> getNestedTemplates (int templateId) {
3112 Map <String, Object> nestedTemplates;
3113 long startTime = System.currentTimeMillis ();
3114 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
3116 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
3118 Query query = getSession ().createQuery (hql);
3119 query.setParameter ("parentIdValue", templateId);
3121 @SuppressWarnings("unchecked")
3122 List <HeatNestedTemplate> resultList = query.list ();
3123 // If nothing comes back, there are no nested templates
3124 if (resultList.isEmpty ()) {
3125 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3126 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
3129 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3130 nestedTemplates = new HashMap <> ();
3131 for (HeatNestedTemplate hnt : resultList) {
3132 LOGGER.debug ("Querying for " + hnt);
3133 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
3135 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3138 String providerResourceFile = hnt.getProviderResourceFile ();
3139 String heatTemplateBody = ht.getTemplateBody ();
3140 if (providerResourceFile != null && heatTemplateBody != null) {
3141 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3143 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3146 // Make sure we're not returning an empty map - if so, just return null
3147 if (nestedTemplates.isEmpty ()) {
3148 LOGGER.debug ("nestedTemplates is empty - just return null");
3149 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3152 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3153 return nestedTemplates;
3156 * Return a Map<String, Object> for returning the child templates and their contents
3158 * @param parentHeatTemplateId
3159 * @return Map<String,Object> or null if none found
3161 public Map <String, Object> getNestedTemplates (String parentHeatTemplateId) {
3162 Map <String, Object> nestedTemplates;
3163 long startTime = System.currentTimeMillis ();
3164 LOGGER.debug ("Catalog database - getNestedTemplates called with parentTemplateId " + parentHeatTemplateId);
3166 String hql = "FROM HeatNestedTemplate where parentTemplateId = :parentHeatTemplateId";
3168 Query query = getSession ().createQuery (hql);
3169 query.setParameter ("parentHeatTemplateId", parentHeatTemplateId);
3171 @SuppressWarnings("unchecked")
3172 List <HeatNestedTemplate> resultList = query.list ();
3173 // If nothing comes back, there are no nested templates
3174 if (resultList.isEmpty ()) {
3175 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3176 LOGGER.debug ("No nestedTemplates found for templateId=" + parentHeatTemplateId + ", " + hql);
3179 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3180 nestedTemplates = new HashMap <> ();
3181 for (HeatNestedTemplate hnt : resultList) {
3182 LOGGER.debug ("Querying for " + hnt);
3183 HeatTemplate ht = this.getHeatTemplateByArtifactUuid (hnt.getChildTemplateId ());
3185 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3188 String providerResourceFile = hnt.getProviderResourceFile ();
3189 String heatTemplateBody = ht.getTemplateBody ();
3190 if (providerResourceFile != null && heatTemplateBody != null) {
3191 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3193 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3196 // Make sure we're not returning an empty map - if so, just return null
3197 if (nestedTemplates.isEmpty ()) {
3198 LOGGER.debug ("nestedTemplates is empty - just return null");
3199 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3202 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3203 return nestedTemplates;
3207 * Fetch any files in the HEAT_FILES table 1510
3210 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
3211 Map <String, HeatFiles> heatFiles;
3213 long startTime = System.currentTimeMillis ();
3214 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
3215 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
3217 Query query = getSession ().createQuery (hql);
3218 query.setParameter ("vnfResourceIdValue", vnfResourceId);
3220 @SuppressWarnings("unchecked")
3221 List <HeatFiles> resultList = query.list ();
3222 // If nothing comes back, there are no heat files
3223 if (resultList.isEmpty ()) {
3224 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
3225 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
3228 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
3229 heatFiles = new HashMap <> ();
3230 for (HeatFiles hf : resultList) {
3231 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
3232 heatFiles.put (hf.getFileName (), hf);
3234 // Make sure we're not returning an empty map - if so, just return null
3235 if (heatFiles.isEmpty ()) {
3236 LOGGER.debug ("heatFiles is empty - just return null");
3237 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
3240 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
3244 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
3246 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
3248 Map <String, HeatFiles> heatFiles = null;
3250 long startTime = System.currentTimeMillis ();
3251 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
3252 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
3254 Query query = getSession ().createQuery (hql);
3255 query.setParameter ("vfModuleIdValue", vfModuleId);
3257 List<VfModuleToHeatFiles> mapList = query.list();
3258 if (mapList.isEmpty()) {
3259 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
3260 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3263 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3264 heatFiles = new HashMap<String, HeatFiles>();
3265 for (VfModuleToHeatFiles vmthf : mapList) {
3266 int heatFilesId = vmthf.getHeatFilesId();
3267 hql = "FROM HeatFiles where id = :id_value";
3268 query = getSession().createQuery(hql);
3269 query.setParameter("id_value", heatFilesId);
3270 List<HeatFiles> fileList = query.list();
3271 if (fileList.isEmpty()) {
3272 // Should this throw an exception??
3273 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
3274 String errorString = "_ERROR|" + heatFilesId;
3275 // The receiving code needs to know to throw an exception for this - or ignore it.
3276 heatFiles.put(errorString, null);
3278 // Should only ever have 1 result - add it to our Map
3279 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
3280 for (HeatFiles hf : fileList) {
3281 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3282 heatFiles.put(hf.getFileName(), hf);
3286 if (heatFiles.isEmpty()) {
3287 LOGGER.debug ("heatFiles is empty - just return null");
3288 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3291 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3298 * Return a VfModuleToHeatFiles object
3300 * @param vfModuleModelUuid, heatFilesArtifactUuid
3301 * @return VfModuleToHeatFiles or null if none found
3303 public VfModuleToHeatFiles getVfModuleToHeatFilesEntry(String vfModuleModelUuid, String heatFilesArtifactUuid) {
3305 LOGGER.debug ("Catalog database - getVfModuleToHeatFilesEntry with vfModuleModelUuid " + vfModuleModelUuid + ", heatFilesArtifactUuid=" + heatFilesArtifactUuid);
3306 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue and heatFilesArtifactUuid = :heatFilesArtifactUuidValue";
3308 HashMap<String, String> parameters = new HashMap<>();
3309 parameters.put("vfModuleModelUuidValue", vfModuleModelUuid);
3310 parameters.put("heatFilesArtifactUuidValue", heatFilesArtifactUuid);
3312 VfModuleToHeatFiles vmthf = null;
3315 vmthf = this.executeQuerySingleRow(hql, parameters, true);
3316 } catch (Exception e) {
3324 * Return a ServiceToResourceCustomization object
3326 * @param vfModuleModelUuid, heatFilesArtifactUuid
3327 * @return VfModuleToHeatFiles or null if none found
3329 public ServiceToResourceCustomization getServiceToResourceCustomization(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
3331 LOGGER.debug ("Catalog database - getServiceToResourceCustomization with serviceModelUuid=" + serviceModelUuid + ", resourceModelCustomizationUuid=" + resourceModelCustomizationUuid + ", modelType=" + modelType);
3332 String hql = "FROM ServiceToResourceCustomization where serviceModelUUID = :serviceModelUuidValue and resourceModelCustomizationUUID = :resourceModelCustomizationUuidValue and modelType = :modelTypeValue ";
3334 HashMap<String, String> parameters = new HashMap<>();
3335 parameters.put("serviceModelUuidValue", serviceModelUuid);
3336 parameters.put("resourceModelCustomizationUuidValue", resourceModelCustomizationUuid);
3337 parameters.put("modelTypeValue", modelType);
3339 ServiceToResourceCustomization strc = null;
3342 strc = this.executeQuerySingleRow(hql, parameters, true);
3343 } catch (Exception e) {
3350 * Return a Map<String, HeatFiles> for returning the heat files associated with a vfModule 1707
3352 * @param parentHeatTemplateId
3353 * @return Map<String,Object> or null if none found
3355 public Map <String, HeatFiles> getHeatFilesForVfModule(String vfModuleModelUuid) {
3356 Map <String, HeatFiles> heatFiles;
3358 long startTime = System.currentTimeMillis ();
3359 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleModelUuid " + vfModuleModelUuid);
3360 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue";
3362 Query query = getSession ().createQuery (hql);
3363 query.setParameter ("vfModuleModelUuidValue", vfModuleModelUuid);
3365 @SuppressWarnings("unchecked")
3366 List<VfModuleToHeatFiles> mapList = query.list();
3367 if (mapList.isEmpty()) {
3368 LOGGER.debug ("No heatFiles found for vfModuleModelUuid=" + vfModuleModelUuid);
3369 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3372 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3373 heatFiles = new HashMap<>();
3374 for (VfModuleToHeatFiles vmthf : mapList) {
3375 String heatFilesUuid = vmthf.getHeatFilesArtifactUuid();
3376 hql = "FROM HeatFiles where artifactUuid = :heatFilesUuidValue";
3377 query = getSession().createQuery(hql);
3378 query.setParameter("heatFilesUuidValue", heatFilesUuid);
3379 @SuppressWarnings("unchecked")
3380 List<HeatFiles> fileList = query.list();
3381 if (fileList.isEmpty()) {
3382 // Should this throw an exception??
3383 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesUuid);
3384 String errorString = "_ERROR|" + heatFilesUuid;
3385 // The receiving code needs to know to throw an exception for this - or ignore it.
3386 heatFiles.put(errorString, null);
3388 // Should only ever have 1 result - add it to our Map
3389 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesUuid);
3390 for (HeatFiles hf : fileList) {
3391 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3392 heatFiles.put(hf.getFileName(), hf);
3396 if (heatFiles.isEmpty()) {
3397 LOGGER.debug ("heatFiles is empty - just return null");
3398 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3401 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3406 * Get the heat template object based on asdc attributes
3408 * @param templateName The template name, generally the yaml filename. "example.yaml"
3409 * @param version The version as specified by ASDC. "1.1"
3410 * @param asdcResourceName The ASDC resource name provided in the ASDC artifact
3412 * @return The HeatTemplate
3414 @Deprecated // asdcResourceName is no longer in heatTeamplate
3415 public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
3417 long startTime = System.currentTimeMillis ();
3418 LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
3421 + " and ASDC resource name "
3422 + asdcResourceName);
3424 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
3425 Query query = getSession ().createQuery (hql);
3426 query.setParameter ("template_name", templateName);
3427 query.setParameter ("version", version);
3428 query.setParameter ("asdcResourceName", asdcResourceName);
3430 @SuppressWarnings("unchecked")
3431 List <HeatTemplate> resultList = query.list ();
3433 // See if something came back.
3434 if (resultList.isEmpty ()) {
3435 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
3438 // Name + Version is unique, so should only be one element
3439 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3440 return resultList.get (0);
3445 * Save the Heat Template
3447 * @param heat The heat template
3448 * @param paramSet The list of heat template parameters
3450 public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
3452 long startTime = System.currentTimeMillis ();
3453 LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName() + ", artifactUUID=" + heat.getArtifactUuid());
3455 heat.setParameters(null);
3458 HeatTemplate heatTemp = this.getHeatTemplateByArtifactUuidRegularQuery(heat.getArtifactUuid());
3460 if (heatTemp == null) {
3461 this.getSession ().save (heat);
3463 if (paramSet != null) {
3464 StringBuilder sb = new StringBuilder("Parameters: ");
3465 for (HeatTemplateParam param : paramSet) {
3466 param.setHeatTemplateArtifactUuid(heat.getArtifactUuid());
3467 sb.append(param.getParamName()).append(", ");
3469 LOGGER.debug(sb.toString());
3470 heat.setParameters (paramSet);
3472 Session session = this.getSession();
3473 if (!(session.isConnected() && session.isOpen())) {
3474 LOGGER.debug("Initial session is not connected or open - get another");
3475 session = this.getSession();
3478 } catch (HibernateException he1) {
3479 LOGGER.debug("Hibernate Exception encountered on first attempt at save(heat) - try again..." + he1.getMessage(), he1);
3481 Session session = this.getSession();
3483 } catch (HibernateException he2) {
3484 LOGGER.debug("Hibernate Exception encountered on second attempt at save(heat)" + he2.getMessage());
3485 LOGGER.debug(Arrays.toString(he2.getStackTrace()));
3487 } catch (Exception e2) {
3488 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(),e2);
3489 LOGGER.debug(Arrays.toString(e2.getStackTrace()));
3493 } catch (Exception e1) {
3494 LOGGER.debug("General Exception encountered on first attempt at save(heat) - try again..." + e1.getMessage(), e1);
3495 LOGGER.debug(Arrays.toString(e1.getStackTrace()));
3497 Session session = this.getSession();
3499 } catch (HibernateException he2) {
3500 LOGGER.debug("General Exception encountered on second attempt at save(heat)" + he2.getMessage(), he2);
3501 LOGGER.debug(Arrays.toString(he2.getStackTrace()));
3503 } catch (Exception e2) {
3504 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(), e2);
3505 LOGGER.debug(Arrays.toString(e2.getStackTrace()));
3512 heat.setArtifactUuid(heatTemp.getArtifactUuid());
3515 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3520 * Retrieves a Heat environment from DB based on its unique key.
3522 * @param name the environment artifact name
3523 * @param version the environment resource version
3524 * @param asdcResourceName the environment resource name
3525 * @return the heat environment from DB or null if not found
3528 public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
3529 long startTime = System.currentTimeMillis ();
3530 LOGGER.debug ("Catalog database - get Heat environment with name " + name
3533 + " and ASDC resource name "
3534 + asdcResourceName);
3536 String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
3537 Query query = getSession ().createQuery (hql);
3538 query.setParameter ("name", name);
3539 query.setParameter ("version", version);
3540 query.setParameter ("asdcResourceName", asdcResourceName);
3541 HeatEnvironment env = null;
3543 env = (HeatEnvironment) query.uniqueResult ();
3544 } catch (org.hibernate.NonUniqueResultException nure) {
3545 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);
3546 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);
3548 } catch (org.hibernate.HibernateException he) {
3549 LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, he);
3550 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);
3552 } catch (Exception e) {
3553 LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, e);
3554 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);
3558 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3560 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3566 * Retrieves a Heat environment from DB based on its unique key. 1707
3568 * @param name the environment artifact name
3569 * @param version the environment resource version
3570 * @return the heat environment from DB or null if not found
3572 public HeatEnvironment getHeatEnvironment (String artifactUuid, String version) {
3573 long startTime = System.currentTimeMillis ();
3574 LOGGER.debug ("Catalog database - get Heat environment with uuid " + artifactUuid
3578 String hql = "FROM HeatEnvironment WHERE artifactUuid=:artifactUuid AND version=:version";
3579 Query query = getSession ().createQuery (hql);
3580 query.setParameter ("artifactUuid", artifactUuid);
3581 query.setParameter ("version", version);
3582 HeatEnvironment env = null;
3584 env = (HeatEnvironment) query.uniqueResult ();
3585 } catch (org.hibernate.NonUniqueResultException nure) {
3586 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + artifactUuid + "', version='" + version);
3587 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "non unique result for ArtifactUUID=" + artifactUuid);
3589 } catch (org.hibernate.HibernateException he) {
3590 LOGGER.debug("Hibernate Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + he.getMessage() );
3591 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUUID=" + artifactUuid + " and version=" + version , "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUUID=" + artifactUuid);
3593 } catch (Exception e) {
3594 LOGGER.debug("Generic Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + e.getMessage());
3595 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUUID=" + artifactUuid);
3599 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3601 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3607 * Save the HeatEnvironment
3609 * @param env The Environment
3611 public void saveHeatEnvironment (HeatEnvironment env) {
3612 long startTime = System.currentTimeMillis ();
3613 LOGGER.debug ("Catalog database - save Heat environment with name "
3614 + env.getEnvironment() + " and ArtifactUUID " + env.getArtifactUuid());
3616 HeatEnvironment dbEnv = getHeatEnvironment (env.getArtifactUuid(), env.getVersion ());
3617 if (dbEnv == null) {
3619 this.getSession ().save (env);
3622 env.setArtifactUuid(dbEnv.getArtifactUuid());
3626 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3631 * Save the heatTemplate
3633 * @param heat The heat template
3635 public void saveHeatTemplate (HeatTemplate heat) {
3636 long startTime = System.currentTimeMillis ();
3637 LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
3639 this.getSession ().update (heat);
3641 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3645 public void saveHeatFile (HeatFiles heatFile) {
3646 long startTime = System.currentTimeMillis ();
3647 LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
3649 this.getSession ().save (heatFile);
3651 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
3655 public void saveVnfRecipe (VnfRecipe vnfRecipe) {
3656 long startTime = System.currentTimeMillis ();
3657 LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
3659 this.getSession ().save (vnfRecipe);
3661 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
3665 public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
3666 long startTime = System.currentTimeMillis ();
3667 LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
3669 this.getSession ().save (vnfComponentsRecipe);
3671 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
3676 public void saveOrUpdateVnfResource (VnfResource vnfResource) {
3677 long startTime = System.currentTimeMillis ();
3678 LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getModelName());
3681 VnfResource existing = this.getVnfResourceByModelUuid(vnfResource.getModelUuid());
3682 if (existing == null) {
3683 LOGGER.debug("No existing entry found - attempting to save...");
3684 this.getSession ().save (vnfResource);
3686 LOGGER.debug("Existing vnf resource found!");
3690 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
3694 public boolean saveVnfResourceCustomization (VnfResourceCustomization vnfResourceCustomization) {
3695 long startTime = System.currentTimeMillis ();
3696 LOGGER.debug ("Catalog database - save VNF Resource Customization with Name " + vnfResourceCustomization.getModelInstanceName());
3698 LOGGER.debug(vnfResourceCustomization.toString());
3699 } catch (Exception e) {
3700 LOGGER.debug("Unable to print VRC " + e.getMessage(), e);
3703 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3704 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3705 // Do any matching customization records exist?
3706 // if(networkResourceList.size() == 0){
3708 // networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUuid());
3709 // this.getSession().flush();
3710 // this.getSession().clear();
3712 VnfResourceCustomization existing = this.getVnfResourceCustomizationByModelCustomizationUuid(vnfResourceCustomization.getModelCustomizationUuid());
3714 if (existing == null) {
3715 LOGGER.debug("No existing entry found...attempting to save...");
3716 this.getSession ().save (vnfResourceCustomization);
3720 LOGGER.debug("Existing VRC entry found\n" + existing.toString());
3721 } catch (Exception e) {
3722 LOGGER.debug("Unable to print VRC2 " + e.getMessage(), e);
3728 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceCustomization", null);
3732 public void saveAllottedResourceCustomization (AllottedResourceCustomization resourceCustomization) {
3733 long startTime = System.currentTimeMillis ();
3734 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + resourceCustomization.getModelInstanceName());
3736 List<AllottedResourceCustomization> allottedResourcesList = getAllAllottedResourcesByArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
3738 if(allottedResourcesList.isEmpty()){
3739 this.getSession ().save(resourceCustomization);
3743 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3747 public void saveAllottedResource (AllottedResource allottedResource) {
3748 long startTime = System.currentTimeMillis ();
3749 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + allottedResource.getModelName());
3751 AllottedResource existing = this.getAllottedResourceByModelUuid(allottedResource.getModelUuid());
3752 if (existing == null) {
3753 this.getSession ().save (allottedResource);
3755 LOGGER.debug("Found existing allottedResource with this modelUuid - no need to save");
3759 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3763 public void saveNetworkResource (NetworkResource networkResource) throws RecordNotFoundException {
3764 long startTime = System.currentTimeMillis ();
3765 LOGGER.debug ("Catalog database - save Network Resource with Network Name " + networkResource.getModelName());
3767 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3768 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3769 // Do any matching customization records exist?
3770 if(getNetworkResourceByModelUuid(networkResource.getModelUUID()) == null){
3771 this.getSession ().save(networkResource);
3776 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3780 public void saveToscaCsar (ToscaCsar toscaCsar) throws RecordNotFoundException {
3783 long startTime = System.currentTimeMillis ();
3784 LOGGER.debug ("Catalog database - save Tosca Csar with Name " + toscaCsar.getName());
3787 if(getToscaCsar(toscaCsar.getArtifactChecksum()) == null){
3788 this.getSession ().save (toscaCsar);
3790 LOGGER.debug("Temporarily disabling saveToscaCsar pending further investigation 2017-06-02");
3793 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveToscaCsar", null);
3799 * Return the newest version of a specific Tosca CSAR Record resource (queried by Name).
3802 * @return ToscaCsar object or null if none found
3804 public ToscaCsar getToscaCsar (String artifactChecksum) {
3806 long startTime = System.currentTimeMillis ();
3807 LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactChecksum " + artifactChecksum);
3809 String hql = "FROM ToscaCsar WHERE artifactChecksum = :artifactChecksum";
3810 Query query = getSession ().createQuery (hql);
3811 query.setParameter ("artifactChecksum", artifactChecksum);
3813 @SuppressWarnings("unchecked")
3814 List <ToscaCsar> resultList = query.list ();
3816 // See if something came back. Name is unique, so
3817 if (resultList.isEmpty ()) {
3818 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsar", null);
3822 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsar", null);
3823 return resultList.get (0);
3827 * Return a specific Tosca CSAR Record resource (queried by atrifact uuid).
3829 * @param toscaCsarArtifactUUID the artifact uuid of the tosca csar
3830 * @return ToscaCsar object or null if none found
3832 public ToscaCsar getToscaCsarByUUID(String toscaCsarArtifactUUID){
3833 long startTime = System.currentTimeMillis ();
3834 LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactUUID " + toscaCsarArtifactUUID);
3836 String hql = "FROM ToscaCsar WHERE artifactUUID = :toscaCsarArtifactUUID";
3837 Query query = getSession ().createQuery (hql);
3838 query.setParameter ("toscaCsarArtifactUUID", toscaCsarArtifactUUID);
3840 @SuppressWarnings("unchecked")
3841 List <ToscaCsar> resultList = query.list ();
3843 // See if something came back. Name is unique, so
3844 if (resultList.isEmpty ()) {
3845 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsarByUUID", null);
3849 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsarByUUID", null);
3850 return resultList.get (0);
3854 * Return a specific Tosca CSAR Record resource (queried by service model uuid).
3857 * @param serviceModelUUID the service model uuid
3858 * @return ToscaCsar object or null if none found
3859 * @since ONAP Beijing Release
3861 public ToscaCsar getToscaCsarByServiceModelUUID(String serviceModelUUID){
3862 long startTime = System.currentTimeMillis ();
3863 LOGGER.debug ("Catalog database - get Tosca CSAR record with serviceModelUUID " + serviceModelUUID);
3864 Service service = getServiceByModelUUID(serviceModelUUID);
3865 if(null == service){
3866 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Service not found", "CatalogDB", "getToscaCsarByServiceModelUUID", null);
3869 ToscaCsar csar = getToscaCsarByUUID(service.getToscaCsarArtifactUUID());
3871 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Tosca csar of the service not found", "CatalogDB", "getToscaCsarByServiceModelUUID", null);
3874 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsarByServiceModelUUID", null);
3878 public void saveTempNetworkHeatTemplateLookup (TempNetworkHeatTemplateLookup tempNetworkHeatTemplateLookup) {
3879 long startTime = System.currentTimeMillis ();
3880 LOGGER.debug ("Catalog database - save TempNetworkHeatTemplateLookup with Network Model Name " + tempNetworkHeatTemplateLookup.getNetworkResourceModelName() +
3881 " and Heat Template Artifact UUID " + tempNetworkHeatTemplateLookup.getHeatTemplateArtifactUuid());
3883 this.getSession ().save (tempNetworkHeatTemplateLookup);
3886 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveTempNetworkHeatTemplateLookup", null);
3890 public void saveVfModuleToHeatFiles (VfModuleToHeatFiles vfModuleToHeatFiles) {
3891 long startTime = System.currentTimeMillis ();
3892 LOGGER.debug ("Catalog database - save VfModuleToHeatFiles with VF Module UUID " + vfModuleToHeatFiles.getVfModuleModelUuid() +
3893 " and Heat Files Artifact UUID " + vfModuleToHeatFiles.getHeatFilesArtifactUuid());
3896 this.getSession ().save (vfModuleToHeatFiles);
3899 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVFModuleToHeatFiles", null);
3903 public void saveVnfResourceToVfModuleCustomization(VnfResourceCustomization vnfResourceCustomizationUUID, VfModuleCustomization vfModuleCustomizationUUID) throws RecordNotFoundException {
3904 long startTime = System.currentTimeMillis ();
3905 VnfResCustomToVfModuleCustom vnfResCustomToVfModuleCustom = new VnfResCustomToVfModuleCustom();
3907 if(vnfResourceCustomizationUUID != null && vfModuleCustomizationUUID != null){
3908 vnfResCustomToVfModuleCustom.setVnfResourceCustModelCustomizationUuid(vnfResourceCustomizationUUID.getModelCustomizationUuid());
3909 vnfResCustomToVfModuleCustom.setVfModuleCustModelCustomizationUuid(vfModuleCustomizationUUID.getModelCustomizationUuid());
3910 String vnfId = vnfResourceCustomizationUUID.getModelCustomizationUuid();
3911 String vfId = vfModuleCustomizationUUID.getModelCustomizationUuid();
3912 LOGGER.debug ("Catalog database - save VnfResCustomToVfModuleCustom with vnf=" + vnfId + ", vf=" + vfId);
3914 VnfResCustomToVfModuleCustom existing = this.getVnfResCustomToVfModule(vnfId, vfId);
3915 if (existing == null) {
3916 LOGGER.debug("No existing entry found - will now try to save");
3917 this.getSession ().save (vnfResCustomToVfModuleCustom);
3919 LOGGER.debug("Existing entry already found - no save needed");
3922 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceToVfModuleCustomization", null);
3927 public void saveNetworkResourceCustomization (NetworkResourceCustomization networkResourceCustomization) throws RecordNotFoundException {
3928 long startTime = System.currentTimeMillis ();
3929 LOGGER.debug ("Catalog database - save Network Resource Customization with Network Name " + networkResourceCustomization.getModelInstanceName());
3931 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3932 List<NetworkResourceCustomization> networkResourceCustomizationList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3933 // Do any matching customization records exist?
3934 if(networkResourceCustomizationList.isEmpty()){
3936 // Retreive the record from the Network_Resource table associated to the Customization record based on ModelName
3937 // ?? is it modelInstanceName with 1707?
3938 NetworkResource networkResource = getNetworkResource(networkResourceCustomization.getModelInstanceName());
3940 if(networkResource == null){
3941 throw new RecordNotFoundException("No record found in NETWORK_RESOURCE table for model name " + networkResourceCustomization.getModelInstanceName());
3944 networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUUID());
3946 this.getSession ().save(networkResourceCustomization);
3951 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3955 @Deprecated // table is gone - mapped to ServiceToResource
3956 public void saveServiceToNetworks (ServiceToNetworks serviceToNetworks) {
3957 long startTime = System.currentTimeMillis ();
3958 LOGGER.debug ("Catalog database - save to ServiceToNetworks table with NetworkModelCustomizationUUID of " + serviceToNetworks.getNetworkModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToNetworks.getServiceModelUuid());
3960 this.getSession ().save(serviceToNetworks);
3963 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3967 public void saveServiceToResourceCustomization(ServiceToResourceCustomization serviceToResource) {
3968 long startTime = System.currentTimeMillis ();
3969 LOGGER.debug ("Catalog database - save to ServiceToResourceCustomization table with ServiceModelUuid of " + serviceToResource.getServiceModelUUID() + ", ResourceModelUUID of " + serviceToResource.getResourceModelCustomizationUUID() + " and model_type=" + serviceToResource.getModelType());
3970 ServiceToResourceCustomization strc = this.getServiceToResourceCustomization(serviceToResource.getServiceModelUUID(), serviceToResource.getResourceModelCustomizationUUID(), serviceToResource.getModelType());
3973 LOGGER.debug("**This ServiceToResourceCustomization record already exists - no need to save");
3975 this.getSession ().save(serviceToResource);
3978 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToResourceCustomization", null);
3982 @Deprecated // table is gone - mapped to ServiceToResourceCustomization
3983 public void saveServiceToAllottedResources (ServiceToAllottedResources serviceToAllottedResources) {
3984 long startTime = System.currentTimeMillis ();
3985 LOGGER.debug ("Catalog database - save to serviceToAllottedResources table with ARModelCustomizationUUID of " + serviceToAllottedResources.getArModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToAllottedResources.getServiceModelUuid());
3987 this.getSession ().save(serviceToAllottedResources);
3990 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToAllottedResources", null);
3994 public void saveService (Service service) {
3995 long startTime = System.currentTimeMillis ();
3996 LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getModelName()+"/"+service.getVersion()+"/"+service.getModelUUID());
3998 Service serviceInvariantDB = null;
3999 // Retrieve existing service record by nameVersionId
4000 Service serviceDB = this.getServiceByModelUUID(service.getModelUUID());
4001 if (serviceDB == null) {
4002 // 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.
4003 serviceInvariantDB = this.getServiceByInvariantUUID(service.getModelInvariantUUID());
4004 // Save the new Service record
4005 this.getSession ().save (service);
4008 if(serviceInvariantDB != null){ // existing modelInvariantId was found.
4009 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
4010 List<ServiceRecipe> serviceRecipes = getServiceRecipes(serviceInvariantDB.getModelUUID());
4012 if(serviceRecipes != null && ! serviceRecipes.isEmpty()){
4013 for(ServiceRecipe serviceRecipe : serviceRecipes){
4014 if(serviceRecipe != null){
4015 // 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.
4016 Service newService = this.getServiceByModelUUID(service.getModelUUID());
4017 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
4018 ServiceRecipe newServiceRecipe = new ServiceRecipe();
4019 newServiceRecipe.setAction(serviceRecipe.getAction());
4020 newServiceRecipe.setDescription(serviceRecipe.getDescription());
4021 newServiceRecipe.setOrchestrationUri(serviceRecipe.getOrchestrationUri());
4022 newServiceRecipe.setRecipeTimeout(serviceRecipe.getRecipeTimeout());
4023 newServiceRecipe.setServiceParamXSD(serviceRecipe.getServiceParamXSD());
4024 newServiceRecipe.setServiceModelUUID(newService.getModelUUID());
4025 newServiceRecipe.setVersion(serviceRecipe.getVersion());
4026 // Check recipe does not exist before inserting
4027 ServiceRecipe recipe = getServiceRecipeByModelUUID(newServiceRecipe.getServiceModelUUID(), newServiceRecipe.getAction());
4028 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
4030 this.getSession ().save (newServiceRecipe);
4039 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
4043 public void saveOrUpdateVfModule (VfModule vfModule) {
4044 long startTime = System.currentTimeMillis ();
4045 LOGGER.debug ("Catalog database - save or update VF Module with VF Model Name " + vfModule.getModelName());
4046 VfModule vfModuleInvariantDB = null;
4048 LOGGER.debug("heat template id = " + vfModule.getHeatTemplateArtifactUUId() + ", vol template id = "+ vfModule.getVolHeatTemplateArtifactUUId());
4049 LOGGER.debug(vfModule.toString());
4050 } catch (Exception e) {
4051 LOGGER.debug("unable to print vfmodule " + e.getMessage(), e);
4054 VfModule existing = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4055 if (existing == null) {
4056 // 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.
4057 vfModuleInvariantDB = this.getVfModuleByModelInvariantUuid(vfModule.getModelInvariantUUID());
4058 LOGGER.debug("No existing entry found, attempting to save...");
4059 this.getSession ().save (vfModule);
4062 LOGGER.debug("Found an existing vf module!\n" + existing.toString());
4063 } catch (Exception e) {
4064 LOGGER.debug("unable to print vfmodule2 " + e.getMessage(), e);
4068 if(vfModuleInvariantDB != null){ // existing modelInvariantId was found.
4069 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
4070 List<VnfComponentsRecipe> vfRecipes = getVnfComponentRecipes(vfModuleInvariantDB.getModelUUID());
4073 if(vfRecipes != null && ! vfRecipes.isEmpty()){
4074 for(VnfComponentsRecipe vfRecipe : vfRecipes){
4075 if(vfRecipe != null){
4076 // 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.
4077 VfModule newRecipe = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4078 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
4079 VnfComponentsRecipe newVnfRecipe = new VnfComponentsRecipe();
4080 newVnfRecipe.setAction(vfRecipe.getAction());
4081 newVnfRecipe.setDescription(vfRecipe.getDescription());
4082 newVnfRecipe.setOrchestrationUri(vfRecipe.getOrchestrationUri());
4083 newVnfRecipe.setRecipeTimeout(vfRecipe.getRecipeTimeout());
4084 newVnfRecipe.setVnfComponentParamXSD(vfRecipe.getVnfComponentParamXSD());
4085 newVnfRecipe.setVfModuleModelUUId(newRecipe.getModelUUID());
4086 newVnfRecipe.setVersion(vfRecipe.getVersion());
4087 newVnfRecipe.setVnfComponentType(vfRecipe.getVnfComponentType());
4088 newVnfRecipe.setVnfType(vfRecipe.getVnfType());
4089 // Check recipe does not exist before inserting
4090 // VnfComponentsRecipe recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4091 List<VnfComponentsRecipe> recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4092 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
4093 // if(recipe == null){
4094 this.getSession ().save (newVnfRecipe);
4103 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
4107 public void saveOrUpdateVfModuleCustomization (VfModuleCustomization vfModuleCustomization) {
4108 long startTime = System.currentTimeMillis ();
4109 LOGGER.debug ("Catalog database - save VF Module Customization with VF Customization Model Name UUID " + vfModuleCustomization.getVfModuleModelUuid());
4111 LOGGER.debug("env id = " + vfModuleCustomization.getHeatEnvironmentArtifactUuid() + ", vol Env=" + vfModuleCustomization.getVolEnvironmentArtifactUuid());
4112 LOGGER.debug(vfModuleCustomization.toString());
4113 } catch (Exception e) {
4114 LOGGER.debug("unable to print vfmodulecust " + e.getMessage(), e);
4117 VfModuleCustomization existing = this.getVfModuleCustomizationByModelCustomizationId(vfModuleCustomization.getModelCustomizationUuid());
4118 if (existing == null) {
4119 LOGGER.debug("No existing entry found, attempting to save...");
4120 this.getSession ().save (vfModuleCustomization);
4123 LOGGER.debug("Found an existing vf module customization entry\n" + existing.toString());
4124 } catch (Exception e) {
4125 LOGGER.debug("unable to print vfmodulecust2 " + e.getMessage(), e);
4130 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModuleCustomization", null);
4135 public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
4136 long startTime = System.currentTimeMillis ();
4137 LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
4138 + parentTemplateId +"-"+childTemplateId);
4140 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4141 // nestedTemplate.setParentTemplateId (parentTemplateId);
4142 // nestedTemplate.setChildTemplateId (childTemplateId);
4144 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
4146 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
4151 public HeatNestedTemplate getNestedHeatTemplate(String parentTemplateId, String childTemplateId) {
4152 long startTime = System.currentTimeMillis ();
4153 LOGGER.debug ("Catalog database - get nested Heat template with PerentId="
4154 + parentTemplateId +", ChildId="+childTemplateId);
4156 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4157 nestedTemplate.setParentTemplateId (parentTemplateId);
4158 nestedTemplate.setChildTemplateId (childTemplateId);
4160 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
4162 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
4167 public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4169 long startTime = System.currentTimeMillis ();
4170 LOGGER.debug ("Catalog database - save nested Heat template with name "
4171 + childTemplate.getTemplateName ());
4174 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4175 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
4176 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4177 nestedTemplate.setParentTemplateId (parentTemplateId);
4178 nestedTemplate.setChildTemplateId (childTemplate.getId ());
4179 nestedTemplate.setProviderResourceFile (yamlFile);
4180 session.save (nestedTemplate);
4183 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4189 public void saveNestedHeatTemplate (String parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4190 long startTime = System.currentTimeMillis ();
4191 LOGGER.debug ("Catalog database - save nested Heat template with name "
4192 + childTemplate.getTemplateName () + ",parentId=" + parentTemplateId + ",childId=" + childTemplate.getArtifactUuid() + ", providerResourceFile=" + yamlFile);
4195 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4196 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getArtifactUuid()) == null) {
4197 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4198 nestedTemplate.setParentTemplateId (parentTemplateId);
4199 nestedTemplate.setChildTemplateId (childTemplate.getArtifactUuid ());
4200 nestedTemplate.setProviderResourceFile (yamlFile);
4202 session.save (nestedTemplate);
4205 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4210 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
4211 long startTime = System.currentTimeMillis ();
4212 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
4213 + " and vnfResourceID "
4215 // + " and ASDC resource name "
4220 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
4221 Query query = getSession ().createQuery (hql);
4222 query.setParameter ("fileName", fileName);
4223 query.setParameter ("vnfResourceId", vnfResourceId);
4224 query.setParameter ("asdcResourceName", asdcResourceName);
4225 query.setParameter ("version", version);
4227 @SuppressWarnings("unchecked")
4229 HeatFiles heatFilesResult = null;
4231 heatFilesResult = (HeatFiles) query.uniqueResult ();
4232 } catch (org.hibernate.NonUniqueResultException nure) {
4233 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);
4234 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);
4236 } catch (org.hibernate.HibernateException he) {
4237 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + he.getMessage());
4238 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);
4240 } catch (Exception e) {
4241 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + e.getMessage());
4242 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);
4246 // See if something came back.
4247 if (heatFilesResult == null) {
4248 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4251 // Name + Version is unique, so should only be one element
4252 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4253 return heatFilesResult;
4256 public HeatFiles getHeatFiles(String artifactUuid) {
4257 long startTime = System.currentTimeMillis ();
4258 LOGGER.debug ("Catalog database - getHeatFiles with artifactUuid " + artifactUuid);
4260 String hql = "FROM HeatFiles WHERE artifactUuid = :artifactUuid";
4261 Query query = getSession ().createQuery (hql);
4262 query.setParameter ("artifactUuid", artifactUuid);
4264 @SuppressWarnings("unchecked")
4266 HeatFiles heatFilesResult = null;
4268 heatFilesResult = (HeatFiles) query.uniqueResult ();
4269 } catch (org.hibernate.NonUniqueResultException nure) {
4270 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: artifactUuid='" + artifactUuid );
4271 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid=" + artifactUuid);
4273 } catch (org.hibernate.HibernateException he) {
4274 LOGGER.debug("Hibernate Exception - while searching for: artifactUuid='" + artifactUuid + " " + he.getMessage());
4275 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + artifactUuid);
4277 } catch (Exception e) {
4278 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + " " + e.getMessage());
4279 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUuid=" + artifactUuid , "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + artifactUuid);
4283 // See if something came back.
4284 if (heatFilesResult == null) {
4285 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4288 // Name + Version is unique, so should only be one element
4289 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4290 return heatFilesResult;
4293 public void saveHeatFiles (HeatFiles childFile) {
4294 long startTime = System.currentTimeMillis ();
4295 LOGGER.debug ("Catalog database - save Heat File with name "
4296 + childFile.getFileName());
4298 // HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
4299 HeatFiles heatFiles = getHeatFiles (childFile.getArtifactUuid());
4300 if (heatFiles == null) {
4302 // asdc_heat_files_save
4303 this.getSession ().save (childFile);
4306 /* replaced 'heatFiles' by 'childFile'
4307 Based on following comment:
4308 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
4310 childFile.setArtifactUuid(heatFiles.getArtifactUuid());
4314 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
4319 public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
4321 long startTime = System.currentTimeMillis ();
4322 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4323 + childFile.getFileName());
4325 saveHeatFiles (childFile);
4326 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4327 vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
4328 vfModuleToHeatFile.setHeatFilesId(childFile.getId());
4330 session.save (vfModuleToHeatFile);
4333 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4338 public void saveVfModuleToHeatFiles (String parentVfModuleId, HeatFiles childFile) {
4339 long startTime = System.currentTimeMillis ();
4340 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4341 + childFile.getFileName());
4343 saveHeatFiles (childFile);
4344 VfModuleToHeatFiles checkExistingEntry = this.getVfModuleToHeatFilesEntry(parentVfModuleId, childFile.getArtifactUuid());
4345 if (checkExistingEntry == null) {
4346 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4347 vfModuleToHeatFile.setVfModuleModelUuid(parentVfModuleId);
4348 vfModuleToHeatFile.setHeatFilesArtifactUuid(childFile.getArtifactUuid());
4350 session.save (vfModuleToHeatFile);
4352 LOGGER.debug("**Found existing VfModuleToHeatFiles entry for " + checkExistingEntry.toString());
4353 LOGGER.debug("No need to save...");
4357 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4362 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4364 * @param networkType
4366 * @param serviceType
4367 * @return NetworkRecipe object or null if none found
4369 public NetworkResource getNetworkResourceByModelUuid(String modelUUID) {
4371 long startTime = System.currentTimeMillis ();
4372 LOGGER.debug ("Catalog database - get network resource with modelUUID " + modelUUID);
4375 String hql = "FROM NetworkResource WHERE modelUUID=:modelUUID";
4376 Query query = getSession ().createQuery (hql);
4377 query.setParameter (MODEL_UUID, modelUUID);
4379 @SuppressWarnings("unchecked")
4380 List <NetworkResource> resultList = query.list ();
4382 if (resultList.isEmpty ()) {
4386 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4387 Collections.reverse (resultList);
4389 return resultList.get (0);
4390 } catch (Exception e) {
4391 LOGGER.debug("Error trying to find Network Resource with " + modelUUID +", " + e.getMessage(),e);
4393 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelUuid", null);
4400 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
4402 * @param networkType
4404 * @param serviceType
4405 * @return NetworkRecipe object or null if none found
4407 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
4409 long startTime = System.currentTimeMillis ();
4410 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
4413 + " and service type "
4418 if (serviceType == null) {
4419 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
4421 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
4423 Query query = getSession ().createQuery (hql);
4424 query.setParameter (NETWORK_TYPE, networkType);
4425 query.setParameter (ACTION, action);
4426 if (serviceType != null) {
4427 query.setParameter ("serviceType", serviceType);
4430 @SuppressWarnings("unchecked")
4431 List <NetworkRecipe> resultList = query.list ();
4433 if (resultList.isEmpty ()) {
4437 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4438 Collections.reverse (resultList);
4440 return resultList.get (0);
4442 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4448 * Return a Network recipe that matches a given MODEL_NAME and ACTION
4452 * @return NetworkRecipe object or null if none found
4454 public NetworkRecipe getNetworkRecipe (String modelName, String action) {
4456 long startTime = System.currentTimeMillis ();
4457 LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
4463 String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND action = :action";
4465 Query query = getSession ().createQuery (hql);
4466 query.setParameter (MODEL_NAME, modelName);
4467 query.setParameter (ACTION, action);
4469 @SuppressWarnings("unchecked")
4470 List <NetworkRecipe> resultList = query.list ();
4472 if (resultList.isEmpty ()) {
4476 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4477 Collections.reverse (resultList);
4479 return resultList.get (0);
4481 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4486 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4488 * @param networkType
4490 * @param serviceType
4491 * @return NetworkRecipe object or null if none found
4493 public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
4495 long startTime = System.currentTimeMillis ();
4496 LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
4499 String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.modelUUID=c.networkResourceModelUuid and c.modelCustomizationUuid = :modelCustomizationUuid";
4500 Query query = getSession ().createQuery (hql);
4501 query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
4503 @SuppressWarnings("unchecked")
4504 List <NetworkResource> resultList = query.list ();
4506 if (resultList.isEmpty ()) {
4510 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4511 Collections.reverse (resultList);
4513 return resultList.get (0);
4514 } catch (Exception e) {
4515 LOGGER.debug("Error trying to find Network Resource with " + modelCustomizationUuid +", " + e.getMessage(),e);
4517 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelCustUuid", null);
4523 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
4527 * @param vnfComponentType
4529 * @param serviceType
4530 * @return VnfComponentsRecipe object or null if none found
4532 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
4533 String vnfComponentType,
4535 String serviceType) {
4537 long startTime = System.currentTimeMillis ();
4538 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
4539 + " and component type "
4543 + " and service type "
4548 if (serviceType == null) {
4549 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
4551 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
4553 Query query = getSession ().createQuery (hql);
4554 query.setParameter (VNF_TYPE, vnfType);
4555 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4556 query.setParameter (ACTION, action);
4557 if (serviceType != null) {
4558 query.setParameter ("serviceType", serviceType);
4561 @SuppressWarnings("unchecked")
4562 List <VnfComponentsRecipe> resultList = query.list ();
4564 if (resultList.isEmpty ()) {
4567 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4568 Collections.reverse (resultList);
4570 return resultList.get (0);
4572 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
4577 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
4580 * @param vnfComponentType
4582 * @return VnfComponentsRecipe object or null if none found
4584 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleModelUUId (String vfModuleModelUUId,
4585 String vnfComponentType,
4588 long startTime = System.currentTimeMillis ();
4589 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleModelUUId " + vfModuleModelUUId
4590 + " and component type "
4597 hql = "FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId AND vnfComponentType = :vnfComponentType AND action = :action ";
4599 Query query = getSession ().createQuery (hql);
4600 query.setParameter (VF_MODULE_MODEL_UUID, vfModuleModelUUId);
4601 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4602 query.setParameter (ACTION, action);
4604 @SuppressWarnings("unchecked")
4605 List <VnfComponentsRecipe> resultList = query.list ();
4607 if (resultList.isEmpty ()) {
4610 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4611 Collections.reverse (resultList);
4613 return resultList.get (0);
4615 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleModelUUId", null);
4619 public List<VnfComponentsRecipe> getVnfComponentRecipes (String vfModuleModelUUId) {
4621 StringBuilder hql = null;
4623 hql = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId");
4625 long startTime = System.currentTimeMillis ();
4626 LOGGER.debug ("Catalog database - get Service recipe with vfModuleModelUUId " + vfModuleModelUUId);
4628 Query query = getSession ().createQuery (hql.toString ());
4629 query.setParameter ("vfModuleModelUUId", vfModuleModelUUId);
4631 @SuppressWarnings("unchecked")
4632 List <VnfComponentsRecipe> resultList = query.list ();
4634 if (resultList.isEmpty ()) {
4635 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getVfModuleRecipes", null);
4636 return Collections.EMPTY_LIST;
4639 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4640 Collections.reverse (resultList);
4642 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleRecipes", null);
4648 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
4649 long startTime = System.currentTimeMillis ();
4651 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
4653 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
4657 this.getSession ().save (vnfComponent);
4660 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
4665 * Return a VfModule record that matches a given MODEL_NAME
4668 * @return VfModule object or null if none found
4670 public VfModule getVfModule (String modelName) {
4672 long startTime = System.currentTimeMillis ();
4673 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
4678 hql = "FROM VfModule WHERE modelName = :modelName";
4680 Query query = getSession ().createQuery (hql);
4681 query.setParameter (MODEL_NAME, modelName);
4683 @SuppressWarnings("unchecked")
4684 List <VfModule> resultList = query.list ();
4686 if (resultList.isEmpty ()) {
4689 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4690 Collections.reverse (resultList);
4692 return resultList.get (0);
4694 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
4699 * Return a VfModule record that matches a given MODEL_NAME
4702 * @return VfModule object or null if none found
4704 public VfModule getVfModuleByModelUUID (String modelUUID) {
4706 long startTime = System.currentTimeMillis ();
4707 LOGGER.debug ("Catalog database - get vf module with modelUUID " + modelUUID);
4712 hql = "FROM VfModule WHERE modelUUID = :modelUUID";
4714 Query query = getSession ().createQuery (hql);
4715 query.setParameter (MODEL_UUID, modelUUID);
4717 @SuppressWarnings("unchecked")
4718 List <VfModule> resultList = query.list ();
4720 if (resultList.isEmpty ()) {
4723 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4724 Collections.reverse (resultList);
4726 return resultList.get (0);
4728 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUUID", null);
4733 * Return a Service recipe that matches a given service ModelUUID and action
4734 * (modelUUID) and ACTION
4738 * @return ServiceRecipe object or null if none found
4740 public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
4742 long startTime = System.currentTimeMillis();
4743 LOGGER.debug("Catalog database - get Service recipe with modelUUID=" + modelUUID + " and action=" + action);
4747 // based on the new SERVICE_RECIPE schema where SERVICE_MODEL_UUID == MODEL_UUID, a JOIN with the SERVICE table is no longer needed
4748 // hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4749 // "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4750 // "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4751 // "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4752 // "WHERE SR.serviceModelUUID = :modelUUID AND SR.action = :action";
4753 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :modelUUID AND action = :action";
4754 Query query = getSession().createQuery(hql);
4755 query.setParameter(MODEL_UUID, modelUUID);
4756 query.setParameter(ACTION, action);
4758 @SuppressWarnings("unchecked")
4759 List<ServiceRecipe> recipeResultList = query.list();
4760 if (recipeResultList.isEmpty()) {
4761 LOGGER.debug("Catalog database - recipeResultList is null");
4764 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4765 Collections.reverse(recipeResultList);
4766 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4768 return recipeResultList.get(0);
4770 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipeByModelUUID", null);
4775 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
4776 * (MODEL_VERSION_ID) and ACTION
4778 * @param modelVersionId
4780 * @return ServiceRecipe object or null if none found
4783 public ServiceRecipe getServiceRecipe(String modelVersionId,
4786 long startTime = System.currentTimeMillis();
4787 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
4788 + " and action=" + action);
4792 // Note: Even with the implementation of the HQL JOIN below, the code for the two separate
4793 // SELECTs will be retained/commented for now in the event some subsequent JOIN issue arises
4794 // 1st query to get the Service record for the given SERVICE_NAME_VERSION_ID (MODEL_VERSION_ID)
4795 /* hql = "FROM Service WHERE serviceNameVersionId = :serviceNameVersionId";
4796 Query query = getSession().createQuery(hql);
4797 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
4799 @SuppressWarnings("unchecked")
4800 List<Service> serviceResultList = query.list();
4801 if (serviceResultList.isEmpty()) {
4802 LOGGER.debug("Catalog database - serviceResultList is null");
4805 Collections.sort(serviceResultList, new MavenLikeVersioningComparator());
4806 Collections.reverse(serviceResultList);
4807 LOGGER.debug("Catalog database - serviceResultList contains " + serviceResultList.get(0).toString());
4809 // 2nd query to get the ServiceRecipe record corresponding to the Service from the 1st query
4810 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action";
4811 query = getSession().createQuery(hql);
4812 // The SERVICE table 'id' field maps to the SERVICE_RECIPE table 'SERVICE_ID' field
4813 query.setParameter(SERVICE_ID, serviceResultList.get(0).getId());
4814 query.setParameter(ACTION, action);
4816 // The following SELECT performs a JOIN across the SERVICE and SERVICE_RECIPE tables. It required a new
4817 // CTR in the ServiceRecipe Class to populate that object (the other option was to parse the Object[]
4818 // returned by createQuery() and manually populate the ServiceRecipe object). Two of the 'int' fields in the
4819 // SERVICE_RECIPE DB schema (the timeouts) permit NULL values which required some additional code in the
4820 // SELECT to generate a default of 0 (needed by the CTR) in the cases where the value is NULL.
4821 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4822 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4823 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4824 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4825 "WHERE SR.serviceModelUUID = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
4826 Query query = getSession().createQuery(hql);
4827 query.setParameter(MODEL_UUID, modelVersionId);
4828 query.setParameter(ACTION, action);
4830 @SuppressWarnings("unchecked")
4831 List<ServiceRecipe> recipeResultList = query.list();
4832 if (recipeResultList.isEmpty()) {
4833 LOGGER.debug("Catalog database - recipeResultList is null");
4836 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4837 Collections.reverse(recipeResultList);
4838 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4840 return recipeResultList.get(0);
4842 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
4847 * Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
4848 * Note: This method is not currently used but was retained in the event the
4849 * architecture moves back to a MODEL/MODEL_RECIPE structure.
4852 * @param modelVersionId
4854 * @return ModelRecipe object or null if none found
4856 public ModelRecipe getModelRecipe(String modelType,
4857 String modelVersionId,
4860 long startTime = System.currentTimeMillis();
4861 LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
4862 + " and modeVersionId=" + modelVersionId
4863 + " and action=" + action);
4867 // TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
4868 // the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
4869 // There seems to be 2 issues: formatting a hql query that executes successfully
4870 // and then being able to generate a result that will fit into the ModelRecipe class.
4872 // 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
4873 hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
4874 Query query = getSession().createQuery(hql);
4875 query.setParameter(MODEL_TYPE, modelType);
4876 query.setParameter(MODEL_VERSION_ID, modelVersionId);
4878 @SuppressWarnings("unchecked")
4879 List<Model> modelResultList = query.list();
4880 if (modelResultList.isEmpty()) {
4881 LOGGER.debug("Catalog database - modelResultList is null");
4884 Collections.sort(modelResultList, new MavenLikeVersioningComparator());
4885 Collections.reverse(modelResultList);
4886 LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
4888 // 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
4889 hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
4890 query = getSession().createQuery(hql);
4891 // The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
4892 query.setParameter(MODEL_ID, modelResultList.get(0).getId());
4893 query.setParameter(ACTION, action);
4895 @SuppressWarnings("unchecked")
4896 List<ModelRecipe> recipeResultList = query.list();
4897 if (recipeResultList.isEmpty()) {
4898 LOGGER.debug("Catalog database - recipeResultList is null");
4901 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4902 Collections.reverse(recipeResultList);
4903 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4905 return recipeResultList.get(0);
4907 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
4913 * Verify the health of the DB.
4915 * @return boolean value indicate whether DB is healthy
4917 public boolean healthCheck () {
4918 long startTime = System.currentTimeMillis ();
4919 Session session = this.getSession ();
4921 // Query query = session.createQuery (" from ActiveRequests ");
4922 Query query = session.createSQLQuery (" show tables ");
4924 List<?> list = query.list();
4925 LOGGER.debug("healthCheck CatalogDB - Successful");
4929 public < E > E executeQuerySingleRow(String hql, HashMap<String, String> variables, boolean retry) {
4930 long startTime = System.currentTimeMillis();
4931 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
4932 Query query = getSession().createQuery(hql);
4934 StringBuilder sb = new StringBuilder();
4935 if (variables != null) {
4936 for(Map.Entry<String, String> entry : variables.entrySet()){
4937 sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
4938 query.setParameter(entry.getKey(), entry.getValue());
4941 LOGGER.debug("Variables:\n" + sb.toString());
4945 theObject = (E) query.uniqueResult();
4946 } catch (org.hibernate.NonUniqueResultException nure) {
4947 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row");
4948 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for " + hql, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for " + hql );
4950 } catch (org.hibernate.HibernateException he) {
4951 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
4952 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
4954 LOGGER.debug("***WILL RETRY***");
4955 return this.executeQuerySingleRow(hql, variables, false);
4959 } catch (Exception e) {
4960 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
4961 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
4963 LOGGER.debug("***WILL RETRY***");
4964 return this.executeQuerySingleRow(hql, variables, false);
4970 if (theObject == null) {
4971 LOGGER.debug("Returning null");
4972 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
4974 LOGGER.debug("Returning an Object");
4975 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
4980 public < E > List<E> executeQueryMultipleRows(String hql, HashMap<String, String> variables, boolean retry) {
4981 long startTime = System.currentTimeMillis ();
4982 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
4983 Query query = getSession().createQuery(hql);
4985 StringBuilder sb = new StringBuilder();
4986 if (variables != null) {
4987 for(Map.Entry<String, String> entry : variables.entrySet()){
4988 sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
4989 query.setParameter(entry.getKey(), entry.getValue());
4992 LOGGER.debug("Variables:\n" + sb.toString());
4994 List<E> theObjects = null;
4996 theObjects = (List<E>) query.list ();
4997 } catch (org.hibernate.HibernateException he) {
4998 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
4999 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
5001 LOGGER.debug("***WILL RETRY***");
5002 return this.executeQuerySingleRow(hql, variables, false);
5006 } catch (Exception e) {
5007 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
5008 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
5010 LOGGER.debug("***WILL RETRY***");
5011 return this.executeQuerySingleRow(hql, variables, false);
5017 if (theObjects == null) {
5018 LOGGER.debug("Returning null");
5019 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
5022 LOGGER.debug("Returning theObjects:" + theObjects.size());
5023 } catch (Exception e) {
5024 LOGGER.debug("Returning theObjects",e);
5026 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);