2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.db.catalog;
23 import java.io.Closeable;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.List;
31 import org.hibernate.HibernateException;
32 import org.hibernate.Query;
33 import org.hibernate.Session;
34 import org.openecomp.mso.db.AbstractSessionFactoryManager;
35 import org.openecomp.mso.db.catalog.beans.AllottedResource;
36 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
37 import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
38 import org.openecomp.mso.db.catalog.beans.HeatFiles;
39 import org.openecomp.mso.db.catalog.beans.HeatNestedTemplate;
40 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
41 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
42 import org.openecomp.mso.db.catalog.beans.Model;
43 import org.openecomp.mso.db.catalog.beans.ModelRecipe;
44 import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
45 import org.openecomp.mso.db.catalog.beans.NetworkResource;
46 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
47 import org.openecomp.mso.db.catalog.beans.Service;
48 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
49 import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
50 import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
51 import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
52 import org.openecomp.mso.db.catalog.beans.ServiceToResourceCustomization;
53 import org.openecomp.mso.db.catalog.beans.TempNetworkHeatTemplateLookup;
54 import org.openecomp.mso.db.catalog.beans.ToscaCsar;
55 import org.openecomp.mso.db.catalog.beans.VfModule;
56 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
57 import org.openecomp.mso.db.catalog.beans.VfModuleToHeatFiles;
58 import org.openecomp.mso.db.catalog.beans.VnfComponent;
59 import org.openecomp.mso.db.catalog.beans.VnfComponentsRecipe;
60 import org.openecomp.mso.db.catalog.beans.VnfRecipe;
61 import org.openecomp.mso.db.catalog.beans.VnfResCustomToVfModuleCustom;
62 import org.openecomp.mso.db.catalog.beans.VnfResource;
63 import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
64 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
65 import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
66 import org.openecomp.mso.logger.MessageEnum;
67 import org.openecomp.mso.logger.MsoLogger;
70 * This class encapsulates all of the objects that can be queried from a Catalog database.
71 * Clients must use these methods to retrieve catalog objects. The session is not
72 * available for clients to do their own direct queries to the database.
76 public class CatalogDatabase implements Closeable {
78 protected final AbstractSessionFactoryManager sessionFactoryCatalogDB;
80 private static final String NETWORK_TYPE = "networkType";
81 private static final String ACTION = "action";
82 private static final String VNF_TYPE = "vnfType";
83 private static final String SERVICE_TYPE = "serviceType";
84 private static final String SERVICE_ID= "serviceId";
85 private static final String MODEL_UUID= "modelUUID";
86 private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
87 private static final String MODEL_ID = "modelId";
88 private static final String MODEL_NAME = "modelName";
89 private static final String TYPE = "type";
90 private static final String MODEL_TYPE = "modelType";
91 private static final String MODEL_VERSION_ID = "modelVersionId";
92 private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
93 private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId";
94 private static final String VF_MODULE_ID = "vfModuleId";
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.
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
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<String, String>();
276 variables.put("artifactUuidValue", artifactUuid);
277 //Query query = getSession().createQuery(hql);
278 //query.setParameter ("artifactUuidValue", artifactUuid);
279 HeatTemplate template = (HeatTemplate) this.executeQuerySingleRow(hql.toString(), variables, true);
281 if (template == null) {
282 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
284 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
289 public List<HeatTemplateParam> getParametersForHeatTemplate(String heatTemplateArtifactUuid) {
290 long startTime = System.currentTimeMillis ();
291 LOGGER.debug ("Catalog database - getParametersForHeatTemplate with artifactUuid " + heatTemplateArtifactUuid);
293 String hql = "FROM HeatTemplateParams WHERE artifactUuid = :artifactUuidValue";
294 Query query = getSession().createQuery(hql);
295 query.setParameter ("artifactUuidValue", heatTemplateArtifactUuid);
296 List<HeatTemplateParam> resultList = null;
298 resultList = query.list ();
299 } catch (org.hibernate.HibernateException he) {
300 LOGGER.debug("Hibernate Exception - while searching HeatTemplateParams for: heatTemplateArtifactUuid='" + heatTemplateArtifactUuid + "'" + he.getMessage());
301 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching HeatTemplateParams for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + heatTemplateArtifactUuid);
302 resultList = new ArrayList<HeatTemplateParam>();
304 } catch (Exception e) {
305 LOGGER.debug("Generic Exception - while searching HeatTemplateParam for: artifactUuid='" + heatTemplateArtifactUuid + "'" + e.getMessage());
306 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching HeatTemplate for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + heatTemplateArtifactUuid);
307 resultList = new ArrayList<HeatTemplateParam>();
316 * Return a specific Heat Environment by ARTIFACT_UUID using standard query method. unique record expected.
318 * @param artifactUuid
319 * @return HeatEnvironment object or null if none found
321 public HeatEnvironment getHeatEnvironmentByArtifactUuid(String artifactUuid) {
322 long startTime = System.currentTimeMillis ();
323 LOGGER.debug ("Catalog database - get Heat Environment with artifactUuid " + artifactUuid);
325 String hql = "FROM HeatEnvironment WHERE artifactUuid = :artifactUuidValue";
326 Query query = getSession().createQuery(hql);
327 query.setParameter ("artifactUuidValue", artifactUuid);
328 HeatEnvironment environment = null;
330 environment = (HeatEnvironment) query.uniqueResult ();
331 } catch (org.hibernate.NonUniqueResultException nure) {
332 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row for Envt - data integrity error: artifactUuid='" + artifactUuid +"'");
333 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for heatEnvironment artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid==" + artifactUuid);
335 } catch (org.hibernate.HibernateException he) {
336 LOGGER.debug("Hibernate Exception - while searching for envt: artifactUuid='" + artifactUuid + "' " + he.getMessage());
337 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching envt for artifactUuid=" + artifactUuid);
340 } catch (Exception e) {
341 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + "' " + e.getMessage());
342 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching envt for artifactUuid=" + artifactUuid);
347 if (environment == null) {
348 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
350 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
356 * Fetch a Service definition by InvariantUUID
358 public Service getServiceByInvariantUUID (String modelInvariantUUID) {
360 long startTime = System.currentTimeMillis ();
361 LOGGER.debug ("Catalog database - get service with Invariant UUID " + modelInvariantUUID);
363 String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid";
364 Query query = getSession ().createQuery (hql);
365 query.setParameter ("model_invariant_uuid", modelInvariantUUID);
367 @SuppressWarnings("unchecked")
368 List <Service> resultList = query.list ();
370 // See if something came back.
371 if (resultList.isEmpty ()) {
372 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
375 Collections.sort (resultList, new MavenLikeVersioningComparator ());
376 Collections.reverse (resultList);
378 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
379 return resultList.get (0);
383 * Fetch a Service definition
385 public Service getService (String modelName) {
387 long startTime = System.currentTimeMillis ();
388 LOGGER.debug ("Catalog database - get service with name " + modelName);
390 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
391 Query query = getSession ().createQuery (hql);
392 query.setParameter ("MODEL_NAME", modelName);
394 Service service = null;
396 service = (Service) query.uniqueResult ();
397 } catch (org.hibernate.NonUniqueResultException nure) {
398 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelName='" + modelName + "'");
399 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelName=" + modelName);
401 } catch (org.hibernate.HibernateException he) {
402 LOGGER.debug("Hibernate Exception - while searching for: modelName='" + modelName + "' " + he.getMessage());
403 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelName=" + modelName);
405 } catch (Exception e) {
406 LOGGER.debug("Generic Exception - while searching for: modelName='" + modelName + " " + e.getMessage());
407 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelName=" + modelName);
410 if (service == null) {
411 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
413 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
419 public Service getServiceByModelUUID (String modelUUID) {
421 long startTime = System.currentTimeMillis ();
422 LOGGER.debug ("Catalog database - get service with Model UUID " + modelUUID);
424 String hql = "FROM Service WHERE modelUUID = :MODEL_UUID";
425 HashMap<String, String> parameters = new HashMap<String, String>();
426 parameters.put("MODEL_UUID", modelUUID);
429 Service service = this.executeQuerySingleRow(hql, parameters, true);
433 service = (Service) query.uniqueResult ();
434 } catch (org.hibernate.NonUniqueResultException nure) {
435 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelUUID='" + modelUUID + "'");
436 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelUUID=" + modelUUID);
438 } catch (org.hibernate.HibernateException he) {
439 LOGGER.debug("Hibernate Exception - while searching for: modelUUID='" + modelUUID + "' " + he.getMessage());
440 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUUID=" + modelUUID);
442 } catch (Exception e) {
443 LOGGER.debug("Generic Exception - while searching for: modelUUID='" + modelUUID + " " + e.getMessage());
444 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUUID=" + modelUUID);
448 if (service == null) {
449 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getServiceByModelUUID", null);
451 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelUUID", null);
458 * Fetch the Common Service API definition using Http Method + serviceNameVersionId
460 public Service getService(HashMap<String, String> map, String httpMethod) {
462 String serviceNameVersionId = map.get("serviceNameVersionId");
464 String serviceId = "not_set";
465 String serviceVersion = "not_set";
467 if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
468 LOGGER.debug ("Catalog database - get service modelUUID with id " + serviceNameVersionId);
470 String hql = "FROM Service WHERE MODEL_UUID = :MODEL_UUID and http_method = :http_method";
471 query = getSession ().createQuery (hql);
472 query.setParameter ("MODEL_UUID", serviceNameVersionId);
474 serviceId = map.get("serviceId");
475 serviceVersion = map.get("serviceVersion");
476 LOGGER.debug ("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
478 String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
479 query = getSession ().createQuery (hql);
480 query.setParameter ("service_id", serviceId);
481 query.setParameter ("service_version", serviceVersion);
484 query.setParameter ("http_method", httpMethod);
486 long startTime = System.currentTimeMillis ();
487 Service service = null;
489 service = (Service) query.uniqueResult ();
490 } catch (org.hibernate.NonUniqueResultException nure) {
491 LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
492 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);
495 } catch (org.hibernate.HibernateException he) {
496 LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + he.getMessage());
497 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);
500 } catch (Exception e) {
501 LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
502 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);
506 if (service == null) {
507 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
509 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
515 * Return the newest version of a Service (queried by Name).
518 * @return Service object or null if none found
520 public Service getServiceByModelName (String modelName){
522 long startTime = System.currentTimeMillis ();
523 LOGGER.debug ("Catalog database - get service with name " + modelName);
525 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
526 Query query = getSession ().createQuery (hql);
527 query.setParameter ("MODEL_NAME", modelName);
529 @SuppressWarnings("unchecked")
530 List <Service> resultList = query.list ();
532 // See if something came back.
533 if (resultList.isEmpty ()) {
534 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null);
537 Collections.sort (resultList, new MavenLikeVersioningComparator ());
538 Collections.reverse (resultList);
540 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null);
541 return resultList.get (0);
544 public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
545 long startTime = System.currentTimeMillis ();
546 LOGGER.debug ("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion);
548 String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR";
549 Query query = getSession ().createQuery (hql);
550 query.setParameter ("MODEL_INVARIANT_UUID", modelInvariantId);
551 query.setParameter("VERSION_STR", modelVersion);
553 Service result = null;
555 result = (Service) query.uniqueResult();
556 } catch (org.hibernate.NonUniqueResultException nure) {
557 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
558 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantId=" + modelInvariantId + " and modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId);
559 throw new Exception("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
561 // See if something came back.
563 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null);
567 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null);
572 * Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
574 * @param serviceModelUUID
576 * @return ServiceRecipe object or null if none found
579 public ServiceRecipe getServiceRecipe (int serviceModelUUID, String action) {
581 StringBuilder hql = null;
584 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
586 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action ");
589 long startTime = System.currentTimeMillis ();
590 LOGGER.debug ("Catalog database - get Service recipe with serviceModelUUID " + Integer.toString(serviceModelUUID)
595 Query query = getSession ().createQuery (hql.toString ());
596 query.setParameter ("serviceModelUUID", serviceModelUUID);
598 query.setParameter (ACTION, action);
601 @SuppressWarnings("unchecked")
602 List <ServiceRecipe> resultList = query.list ();
604 if (resultList.isEmpty ()) {
605 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
609 Collections.sort (resultList, new MavenLikeVersioningComparator ());
610 Collections.reverse (resultList);
612 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
613 return resultList.get (0);
617 * Return a newest version of Service recipe that matches a given SERVICE_MODEL_UUID and ACTION
619 * @param serviceModelUuid
621 * @return ServiceRecipe object or null if none found
623 public ServiceRecipe getServiceRecipeByServiceModelUuid (String serviceModelUuid, String action) {
625 StringBuilder hql = null;
628 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid");
630 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action ");
633 long startTime = System.currentTimeMillis ();
634 LOGGER.debug ("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid
639 Query query = getSession ().createQuery (hql.toString ());
640 query.setParameter ("serviceModelUuid", serviceModelUuid);
642 query.setParameter (ACTION, action);
645 @SuppressWarnings("unchecked")
646 List <ServiceRecipe> resultList = query.list ();
648 if (resultList.isEmpty ()) {
649 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
653 Collections.sort (resultList, new MavenLikeVersioningComparator ());
654 Collections.reverse (resultList);
656 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
657 return resultList.get (0);
660 public List<ServiceRecipe> getServiceRecipes (String serviceModelUuid) {
662 StringBuilder hql = null;
664 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
666 long startTime = System.currentTimeMillis ();
667 LOGGER.debug ("Catalog database - get Service recipe with serviceModelUUID " + serviceModelUuid);
669 Query query = getSession ().createQuery (hql.toString ());
670 query.setParameter ("serviceModelUUID", serviceModelUuid);
672 @SuppressWarnings("unchecked")
673 List <ServiceRecipe> resultList = query.list ();
675 if (resultList.isEmpty ()) {
676 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null);
680 Collections.sort (resultList, new MavenLikeVersioningComparator ());
681 Collections.reverse (resultList);
683 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null);
689 * Return the VNF component data - queried by the VNFs ID and the component type.
693 * @return VnfComponent object or null if none found
696 public VnfComponent getVnfComponent (int vnfId, String type) {
698 long startTime = System.currentTimeMillis();
699 LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
701 String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
702 Query query = getSession ().createQuery (hql);
703 query.setParameter ("vnf_id", vnfId);
704 query.setParameter ("type", type);
706 VnfComponent result = null;
708 result = (VnfComponent) query.uniqueResult();
709 } catch (org.hibernate.NonUniqueResultException nure) {
710 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
711 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);
714 } catch (org.hibernate.HibernateException he) {
715 LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + he.getMessage());
716 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);
719 } catch (Exception e) {
720 LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + e.getMessage());
721 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);
726 //LOGGER.debug("Found VNF Component: " + result.toString());
727 if (result != null) {
728 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
730 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
736 * Return the newest version of a specific VNF resource (queried by Name).
739 * @return VnfResource object or null if none found
741 public VnfResource getVnfResource (String vnfType) {
743 long startTime = System.currentTimeMillis ();
744 LOGGER.debug ("Catalog database - get vnf resource with model_name " + vnfType);
746 String hql = "FROM VnfResource WHERE modelName = :vnf_name";
747 Query query = getSession ().createQuery (hql);
748 query.setParameter ("vnf_name", vnfType);
750 @SuppressWarnings("unchecked")
751 List <VnfResource> resultList = query.list ();
753 // See if something came back. Name is unique, so
754 if (resultList.isEmpty ()) {
755 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
758 Collections.sort (resultList, new MavenLikeVersioningComparator ());
759 Collections.reverse (resultList);
761 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
762 return resultList.get (0);
766 * Return the newest version of a specific VNF resource (queried by Name).
770 * @return VnfResource object or null if none found
772 public VnfResource getVnfResource (String vnfType, String serviceVersion) {
774 long startTime = System.currentTimeMillis ();
775 LOGGER.debug ("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion);
777 String hql = "FROM VnfResource WHERE modelName = :vnfName and version = :serviceVersion";
778 Query query = getSession ().createQuery (hql);
779 query.setParameter ("vnfName", vnfType);
780 query.setParameter ("serviceVersion", serviceVersion);
782 VnfResource resource = null;
784 resource = (VnfResource) query.uniqueResult ();
785 } catch (org.hibernate.NonUniqueResultException nure) {
786 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
787 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
790 } catch (org.hibernate.HibernateException he) {
791 LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "' " + he.getMessage());
792 LOGGER.debug(he.getStackTrace().toString());
793 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
796 } catch (Exception e) {
797 LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
798 LOGGER.debug(e.getStackTrace().toString());
799 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
803 if (resource == null) {
804 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
806 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
812 * Return VnfResource (queried by modelCustomizationId).
814 * @param modelCustomizationId
815 * @return VnfResource object or null if none found
817 public VnfResource getVnfResourceByModelCustomizationId (String modelCustomizationId) {
819 long startTime = System.currentTimeMillis ();
820 LOGGER.debug ("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
822 String hql = "SELECT vr "
823 + "FROM VnfResource as vr JOIN vr.vnfResourceCustomizations as vrc "
824 + "WHERE vrc.modelCustomizationUuid = :modelCustomizationId";
826 Query query = getSession ().createQuery (hql);
827 query.setParameter ("modelCustomizationId", modelCustomizationId);
829 VnfResource resource = null;
831 resource = (VnfResource) query.uniqueResult ();
832 } catch (org.hibernate.NonUniqueResultException nure) {
833 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "'");
834 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
837 } catch (org.hibernate.HibernateException he) {
838 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
839 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationId=" + modelCustomizationId);
842 } catch (Exception e) {
843 LOGGER.debug("Generic Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
844 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationId=" + modelCustomizationId);
848 if (resource == null) {
849 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
851 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
858 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
860 * @return {@link VnfResourceCustomization} object or null if none found
862 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationName (String modelCustomizationName, String modelVersionId) {
864 long startTime = System.currentTimeMillis ();
865 LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId);
867 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.modelCustomizationUuid IN "
868 + "(SELECT src.resourceModelCustomizationUUID FROM ServiceToResourceCustomization src "
869 + "WHERE src.serviceModelUUID = :modelVersionId)"
870 + "AND vrc.modelInstanceName = :modelCustomizationName";
872 Query query = getSession ().createQuery (hql);
873 query.setParameter ("modelCustomizationName", modelCustomizationName);
874 query.setParameter ("modelVersionId", modelVersionId);
876 @SuppressWarnings("unchecked")
877 List <VnfResourceCustomization> resultList = query.list ();
879 if (resultList.isEmpty ()) {
880 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
884 Collections.sort (resultList, new MavenLikeVersioningComparator ());
885 Collections.reverse (resultList);
887 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
888 return resultList.get (0);
893 * Return the newest version of a specific VNF resource (queried by modelInvariantId).
896 * @return VnfResource object or null if none found
898 public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) {
900 long startTime = System.currentTimeMillis ();
901 LOGGER.debug ("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
903 String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion";
904 Query query = getSession ().createQuery (hql);
905 query.setParameter ("modelInvariantUuid", modelInvariantUuid);
906 query.setParameter ("serviceVersion", modelVersion);
908 VnfResource resource = null;
910 resource = (VnfResource) query.uniqueResult ();
911 } catch (org.hibernate.NonUniqueResultException nure) {
912 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'");
913 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid);
916 } catch (org.hibernate.HibernateException he) {
917 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', asdc_service_model_version='" + modelVersion + "' " + he.getMessage());
918 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid);
921 } catch (Exception e) {
922 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "' " + e.getMessage());
923 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid);
927 if (resource == null) {
928 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
930 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
936 * Return the newest version of a specific VNF resource (queried by ID).
938 * @param id The vnf id
939 * @return VnfResource object or null if none found
942 public VnfResource getVnfResourceById (int id) {
944 long startTime = System.currentTimeMillis ();
945 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
947 String hql = "FROM VnfResource WHERE id = :id";
948 Query query = getSession ().createQuery (hql);
949 query.setParameter ("id", id);
951 @SuppressWarnings("unchecked")
952 List <VnfResource> resultList = query.list ();
954 // See if something came back. Name is unique, so
955 if (resultList.isEmpty ()) {
956 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
959 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
960 return resultList.get (0);
964 * Return the newest version of a vfModule - 1607
967 public VfModule getVfModuleModelName (String modelName) {
969 long startTime = System.currentTimeMillis ();
970 LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName);
972 String hql = "FROM VfModule WHERE modelName = :model_name";
973 Query query = getSession ().createQuery (hql);
974 query.setParameter ("model_name", modelName);
976 @SuppressWarnings("unchecked")
977 List <VfModule> resultList = query.list ();
979 // See if something came back. Name is unique, so
980 if (resultList.isEmpty ()) {
981 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
984 Collections.sort (resultList, new MavenLikeVersioningComparator ());
985 Collections.reverse (resultList);
987 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
988 return resultList.get (0);
991 public VfModule getVfModuleModelName (String modelName, String model_version) {
993 long startTime = System.currentTimeMillis ();
994 LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
996 String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
997 Query query = getSession ().createQuery (hql);
998 query.setParameter ("modelName", modelName);
999 query.setParameter ("model_version", model_version);
1001 VfModule module = null;
1003 module = (VfModule) query.uniqueResult ();
1004 } catch (org.hibernate.NonUniqueResultException nure) {
1005 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 + "'");
1006 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
1009 } catch (org.hibernate.HibernateException he) {
1010 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + he.getMessage());
1011 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
1014 } catch (Exception e) {
1015 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + e.getMessage());
1016 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
1020 if (module == null) {
1021 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
1023 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
1029 * Need this for 1707 DHV. This may be a temporary solution. May
1030 * change it to get resources using service's model name.
1035 public VfModuleCustomization getVfModuleCustomizationByModelName (String modelName) {
1037 long startTime = System.currentTimeMillis ();
1038 LOGGER.debug ("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
1040 String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.modelName = :model_name";
1041 Query query = getSession ().createQuery (hql);
1042 query.setParameter ("model_name", modelName);
1044 @SuppressWarnings("unchecked")
1045 List<VfModuleCustomization> resultList = query.list();
1047 // See if something came back. Name is unique, so
1048 if (resultList.isEmpty ()) {
1049 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1053 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query ", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1054 return resultList.get(0);
1059 * Return the newest version of a specific Network resource (queried by Type).
1061 * @param networkType
1062 * @return NetworkResource object or null if none found
1064 public NetworkResource getNetworkResource (String networkType) {
1066 long startTime = System.currentTimeMillis ();
1067 LOGGER.debug ("Catalog database - get network resource with type " + networkType);
1069 String hql = "FROM NetworkResource WHERE model_name = :network_type";
1070 Query query = getSession ().createQuery (hql);
1071 query.setParameter ("network_type", networkType);
1073 @SuppressWarnings("unchecked")
1074 List <NetworkResource> resultList = query.list ();
1076 // See if something came back. Name is unique, so
1077 if (resultList.isEmpty ()) {
1078 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
1082 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1083 Collections.reverse (resultList);
1084 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
1085 return resultList.get (0);
1089 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
1093 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
1094 * @return VnfRecipe object or null if none found
1096 public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) {
1097 boolean withServiceType = false;
1099 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1102 if (serviceType == null || serviceType.isEmpty ()) {
1103 hql.append ("AND serviceType is NULL ");
1105 hql.append ("AND serviceType = :serviceType ");
1106 withServiceType = true;
1109 long startTime = System.currentTimeMillis ();
1110 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
1113 + " and service type "
1116 Query query = getSession ().createQuery (hql.toString ());
1117 query.setParameter (VNF_TYPE, vnfType);
1118 query.setParameter (ACTION, action);
1119 if (withServiceType) {
1120 query.setParameter (SERVICE_TYPE, serviceType);
1123 @SuppressWarnings("unchecked")
1124 List <VnfRecipe> resultList = query.list ();
1126 if (resultList.isEmpty ()) {
1127 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1131 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1132 Collections.reverse (resultList);
1134 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1135 return resultList.get (0);
1139 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
1143 * @return VnfRecipe object or null if none found
1145 public VnfRecipe getVnfRecipe (String vnfType, String action) {
1146 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1148 long startTime = System.currentTimeMillis ();
1149 LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
1153 Query query = getSession ().createQuery (hql.toString ());
1154 query.setParameter (VNF_TYPE, vnfType);
1155 query.setParameter (ACTION, action);
1157 @SuppressWarnings("unchecked")
1158 List <VnfRecipe> resultList = query.list ();
1160 if (resultList.isEmpty ()) {
1161 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1165 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1166 Collections.reverse (resultList);
1168 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1169 return resultList.get (0);
1173 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
1177 * @return VnfRecipe object or null if none found
1179 public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) {
1181 StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
1183 long startTime = System.currentTimeMillis ();
1184 LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
1186 Query query = getSession ().createQuery (hql.toString ());
1187 query.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
1188 query.setParameter (ACTION, action);
1190 @SuppressWarnings("unchecked")
1191 List <VnfRecipe> resultList = query.list ();
1193 if (resultList.isEmpty ()) {
1194 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1198 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1199 Collections.reverse (resultList);
1201 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1202 return resultList.get (0);
1205 public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
1206 long startTime = System.currentTimeMillis();
1207 LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
1209 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
1210 Query query = getSession().createQuery(hql);
1211 query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
1213 VfModule module = null;
1215 module = (VfModule) query.uniqueResult();
1216 } catch (org.hibernate.NonUniqueResultException nure) {
1217 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1218 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1221 } catch (org.hibernate.HibernateException he) {
1222 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1223 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1226 } catch (Exception e) {
1227 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1228 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1232 if (module == null) {
1233 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
1235 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
1241 public VfModule getVfModuleType(String type) {
1242 long startTime = System.currentTimeMillis();
1243 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
1245 String hql = "FROM VfModule WHERE type = :type";
1246 Query query = getSession().createQuery(hql);
1247 query.setParameter("type", type);
1249 @SuppressWarnings("unchecked")
1250 List<VfModule> resultList = query.list();
1251 if (resultList.isEmpty()) {
1252 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
1255 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1256 Collections.reverse (resultList);
1258 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1259 return resultList.get (0);
1263 public VfModule getVfModuleType(String type, String version) {
1265 long startTime = System.currentTimeMillis();
1266 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
1268 String hql = "FROM VfModule WHERE type = :type and version = :version";
1269 Query query = getSession().createQuery(hql);
1270 query.setParameter ("type", type);
1271 query.setParameter ("version", version);
1272 VfModule module = null;
1274 module = (VfModule) query.uniqueResult ();
1275 } catch (org.hibernate.NonUniqueResultException nure) {
1276 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 + "'");
1277 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
1280 } catch (org.hibernate.HibernateException he) {
1281 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + he.getMessage());
1282 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
1285 } catch (Exception e) {
1286 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + e.getMessage());
1287 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
1291 if (module == null) {
1292 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1294 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1299 public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
1300 long startTime = System.currentTimeMillis();
1301 LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
1303 String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
1304 Query query = getSession().createQuery(hql);
1305 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1306 VnfResource vnfResource = null;
1308 vnfResource = (VnfResource) query.uniqueResult ();
1309 } catch (org.hibernate.NonUniqueResultException nure) {
1310 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1311 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
1314 } catch (org.hibernate.HibernateException he) {
1315 LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + he.getMessage());
1316 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1319 } catch (Exception e) {
1320 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + e.getMessage());
1321 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1325 if (vnfResource == null) {
1326 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1328 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1333 public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
1334 long startTime = System.currentTimeMillis();
1335 LOGGER.debug ("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
1337 String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
1338 Query query = getSession().createQuery(hql);
1339 query.setParameter ("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
1340 VnfResource vnfResource = null;
1342 vnfResource = (VnfResource) query.uniqueResult ();
1343 } catch (org.hibernate.NonUniqueResultException nure) {
1344 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
1345 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
1348 } catch (org.hibernate.HibernateException he) {
1349 LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + he.getMessage());
1350 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1353 } catch (Exception e) {
1354 LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + e.getMessage());
1355 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1359 if (vnfResource == null) {
1360 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1362 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1367 public VnfResource getVnfResourceByType(String vnfType) {
1368 return this.getVnfResource(vnfType);
1371 public VfModule getVfModuleByModelInvariantUuid(String modelInvariantUUID) {
1372 long startTime = System.currentTimeMillis();
1373 LOGGER.debug ("Catalog database - get vfModuleTypeByModelInvariantUuid with uuid " + modelInvariantUUID);
1375 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUUID ";
1376 HashMap<String, String> parameters = new HashMap<String, String>();
1377 parameters.put("modelInvariantUUID", modelInvariantUUID);
1378 List<VfModule> modules = this.executeQueryMultipleRows(hql.toString(), parameters, true);
1379 VfModule module = null;
1381 if (modules != null && modules.size() > 0) {
1382 Collections.sort (modules, new MavenLikeVersioningComparator ());
1383 Collections.reverse (modules);
1384 module = modules.get(0);
1387 if (module == null) {
1388 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1390 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1395 public VfModuleCustomization getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
1396 long startTime = System.currentTimeMillis();
1397 LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
1399 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid ";
1400 Query query = getSession().createQuery(hql);
1401 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1402 VfModuleCustomization module = null;
1404 module = (VfModuleCustomization) query.uniqueResult ();
1405 } catch (org.hibernate.NonUniqueResultException nure) {
1406 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1407 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1410 } catch (org.hibernate.HibernateException he) {
1411 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1412 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1415 } catch (Exception e) {
1416 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1417 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1421 if (module == null) {
1422 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1424 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1430 public VfModule getVfModuleByModelInvariantUuidAndModelVersion(String modelInvariantUuid, String modelVersion) {
1431 long startTime = System.currentTimeMillis();
1432 LOGGER.debug ("Catalog database - get getVfModuleByModelInvariantUuidAndModelVersion with modelInvariantUuid: " + modelInvariantUuid + ", modelVersion: " + modelVersion);
1434 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUuid and version = :modelVersion";
1435 Query query = getSession().createQuery(hql);
1436 query.setParameter ("modelInvariantUuid", modelInvariantUuid);
1437 query.setParameter("modelVersion", modelVersion);
1438 VfModule module = null;
1440 module = (VfModule) query.uniqueResult ();
1441 } catch (org.hibernate.NonUniqueResultException nure) {
1442 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "'");
1443 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);
1446 } catch (org.hibernate.HibernateException he) {
1447 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + he.getMessage());
1448 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1451 } catch (Exception e) {
1452 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + e.getMessage());
1453 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1457 if (module == null) {
1458 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1460 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1466 * Return the VfModuleCustomization object identified by the given modelCustomizationUuid 1707
1468 * @param modelCustomizationUuid
1469 * @return VfModuleCustomization or null if not found
1471 public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {
1472 long startTime = System.currentTimeMillis();
1473 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByModelCustomizationId with modelCustomizationUuid: " + modelCustomizationUuid);
1475 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1476 Query query = getSession().createQuery(hql);
1477 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1478 VfModuleCustomization VfModuleCustomization = null;
1480 VfModuleCustomization = (VfModuleCustomization) query.uniqueResult ();
1481 } catch (org.hibernate.NonUniqueResultException nure) {
1482 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1483 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1484 VfModuleCustomization = null;
1486 } catch (org.hibernate.HibernateException he) {
1487 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1488 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1489 VfModuleCustomization = null;
1491 } catch (Exception e) {
1492 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1493 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1494 VfModuleCustomization = null;
1497 if (VfModuleCustomization != null) {
1498 LOGGER.debug("Found VMC of " + VfModuleCustomization.getModelCustomizationUuid() + ", now looking for vfModule=" + VfModuleCustomization.getVfModuleModelUuid());
1499 VfModuleCustomization.setVfModule(this.getVfModuleByModelUuid(VfModuleCustomization.getVfModuleModelUuid()));
1502 if (VfModuleCustomization == null) {
1503 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1505 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1507 return VfModuleCustomization;
1511 * Return the VfModule object identified by the given modelUuid 1707
1512 * per Mike Z. - this may return more than one row - and even if it does,
1513 * the heat template will be the same - so just return any of the rows.
1516 * @return VfModule or null if not found
1518 public VfModule getVfModuleByModelUuid(String modelUuid) {
1519 long startTime = System.currentTimeMillis();
1520 LOGGER.debug ("Catalog database - get getVfModuleByModelUuid with modelUuid: " + modelUuid);
1522 String hql = "FROM VfModule WHERE modelUUID = :modelUuidValue";
1523 Query query = getSession().createQuery(hql);
1524 query.setParameter ("modelUuidValue", modelUuid);
1525 //VfModule vfModule = null;
1526 List<VfModule> vfModules = null;
1528 vfModules = query.list ();
1529 } catch (org.hibernate.HibernateException he) {
1530 LOGGER.debug("Hibernate Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + he.getMessage());
1531 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VfModule for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUuid=" + modelUuid);
1534 } catch (Exception e) {
1535 LOGGER.debug("Generic Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + e.getMessage());
1536 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUuid=" + modelUuid);
1541 if (vfModules == null || vfModules.size() < 1) {
1542 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelUuid", null);
1545 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUuid", null);
1547 return vfModules.get(0);
1550 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1551 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1553 * @param modelCustomizationUuid
1554 * @return VnfResourceCustomization or null if not found
1556 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUuid(String modelCustomizationUuid) {
1557 long startTime = System.currentTimeMillis();
1558 LOGGER.debug ("Catalog database - get getVnfResourceByModelCustomizatonUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1560 String hql = "FROM VnfResourceCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1561 Query query = getSession().createQuery(hql);
1562 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1563 VnfResourceCustomization vnfResourceCustomization = null;
1565 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1566 } catch (org.hibernate.NonUniqueResultException nure) {
1567 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1568 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1569 vnfResourceCustomization = null;
1571 } catch (org.hibernate.HibernateException he) {
1572 LOGGER.debug("Hibernate Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1573 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1574 vnfResourceCustomization = null;
1576 } catch (Exception e) {
1577 LOGGER.debug("Generic Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1578 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1579 vnfResourceCustomization = null;
1582 if (vnfResourceCustomization != null) {
1583 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1584 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1585 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1586 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1589 if (vnfResourceCustomization == null) {
1590 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1592 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1594 return vnfResourceCustomization;
1598 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1599 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1601 * @param getVnfResourceCustomizationByModelVersionId
1602 * @return VnfResourceCustomization or null if not found
1604 public VnfResourceCustomization getVnfResourceCustomizationByModelVersionId(String modelVersionId) {
1605 long startTime = System.currentTimeMillis();
1606 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelVersionId with modelVersionId: " + modelVersionId);
1608 String hql = "FROM VnfResourceCustomization WHERE vnfResourceModelUuid = :modelVersionId";
1609 Query query = getSession().createQuery(hql);
1610 query.setParameter ("modelVersionId", modelVersionId);
1611 VnfResourceCustomization vnfResourceCustomization = null;
1613 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1614 } catch (org.hibernate.NonUniqueResultException nure) {
1615 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"'");
1616 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId==" + modelVersionId);
1617 vnfResourceCustomization = null;
1619 } catch (org.hibernate.HibernateException he) {
1620 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + he.getMessage());
1621 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId);
1622 vnfResourceCustomization = null;
1624 } catch (Exception e) {
1625 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + e.getMessage());
1626 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId);
1627 vnfResourceCustomization = null;
1630 if (vnfResourceCustomization != null) {
1631 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1632 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1633 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1634 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1637 if (vnfResourceCustomization == null) {
1638 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1640 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1642 return vnfResourceCustomization;
1646 * Return the VfModule object identified by the given modelCustomizationId, modelVersionId 1707
1648 * @param modelVersionId, modelCustomizationId
1649 * @return VfModule or null if not found
1651 public VfModule getVfModuleByModelCustomizationIdAndVersion(String modelCustomizationId, String modelVersionId) {
1652 long startTime = System.currentTimeMillis();
1653 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdAndVersion with modelVersionId: " + modelVersionId + " modelCustomizationId: " + modelCustomizationId);
1655 // select * from vf_module vfm where vfm.MODEL_UUID IN (
1656 // select vfmc.VF_MODULE_MODEL_UUID from vf_module_customization vfmc where vfmc.MODEL_CUSTOMIZATION_UUID='222bd8f2-341d-4419-aa0e-98398fa34050')
1657 // and vfm.MODEL_UUID = 'fa1c8558-006c-4fb6-82f2-4fc0646d6b06';
1659 String hql = "Select vfm FROM VfModule as vfm WHERE vfm.modelUUID IN ("
1660 + "SELECT vfmc.vfModuleModelUuid FROM VfModuleCustomization as vfmc "
1661 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId) "
1662 + "AND vfm.modelUUID = :modelVersionId";
1663 Query query = getSession().createQuery(hql);
1664 query.setParameter ("modelVersionId", modelVersionId);
1665 query.setParameter ("modelCustomizationId", modelCustomizationId);
1666 VfModule vfModule = null;
1668 vfModule = (VfModule) query.uniqueResult ();
1669 } catch (org.hibernate.NonUniqueResultException nure) {
1670 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"' modelCustomizationId='" + modelCustomizationId + "'");
1671 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1674 } catch (org.hibernate.HibernateException he) {
1675 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1676 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1679 } catch (Exception e) {
1680 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1681 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1686 if (vfModule == null) {
1687 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1689 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1695 * Return the VfModule object identified by the given modelCustomizationId, modelVersion, modelInvariantId 1707
1697 * @param modelCustomizationId, modelVersion, modelInvariantId
1698 * @return VfModule or null if not found
1700 public VfModule getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId(String modelCustomizationId, String modelVersion, String modelInvariantId) {
1701 long startTime = System.currentTimeMillis();
1702 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId with modelVersionId: " + modelVersion);
1704 //select * from vf_module vfm left outer join vf_module_customization vfmc on vfmc.VF_MODULE_MODEL_UUID = vfm.MODEL_UUID
1705 // where vfmc.MODEL_CUSTOMIZATION_UUID='52643a8e-7953-4e48-8eab-97165b2b3a4b' and vfm.MODEL_UUID = ''
1707 String hql = "Select vfm FROM VfModule as vfm LEFT OUTER JOIN VfModuleCustomization as vfmc on vfmc.vfModuleModelUuid = vfm.modelUUID"
1708 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId AND vfm.modelInvariantUUID = :modelInvariantId AND vfm.modelVersion = :modelVersion";
1709 Query query = getSession().createQuery(hql);
1710 query.setParameter ("modelInvariantId", modelInvariantId);
1711 query.setParameter ("modelCustomizationId", modelCustomizationId);
1712 query.setParameter ("modelVersion", modelVersion);
1713 VfModule vfModule = null;
1715 vfModule = (VfModule) query.uniqueResult ();
1716 } catch (org.hibernate.NonUniqueResultException nure) {
1717 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 +"'");
1718 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);
1721 } catch (org.hibernate.HibernateException he) {
1722 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1723 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);
1726 } catch (Exception e) {
1727 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1728 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);
1733 if (vfModule == null) {
1734 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1736 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1742 * Return the VnfResourceCustomization object identified by the given modelCustomizationName, modelInvariantId and modelVersion 1707
1744 * @param modelInvariantId, modelVersion, modelCustomizationName
1745 * @return VnfResourceCustomization or null if not found
1747 public VnfResourceCustomization getVnfResourceCustomizationByModelInvariantId(String modelInvariantId, String modelVersion, String modelCustomizationName) {
1748 long startTime = System.currentTimeMillis();
1749 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelInvariantId with modelInvariantId: " + modelInvariantId + ", modelVersion: "
1750 + modelVersion + ", modelCustomizationName: " + modelCustomizationName);
1752 String hql = "SELECT VnfResourceCustomization FROM VnfResourceCustomization as vrc "
1753 + "LEFT OUTER JOIN VnfResource as vr "
1754 + "on vr.modelUuid =vrc.vnfResourceModelUuid "
1755 + "WHERE vr.modelInvariantUuid = :modelInvariantId AND vr.modelVersion = :modelVersion AND vrc.modelInstanceName = :modelCustomizationName";
1757 Query query = getSession().createQuery(hql);
1758 query.setParameter ("modelInvariantId", modelInvariantId);
1759 query.setParameter("modelVersion", modelVersion);
1760 query.setParameter("modelCustomizationName", modelCustomizationName);
1761 VnfResourceCustomization vnfResourceCustomization = null;
1763 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1764 } catch (org.hibernate.NonUniqueResultException nure) {
1765 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 + "'");
1766 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 + "'");
1767 vnfResourceCustomization = null;
1769 } catch (org.hibernate.HibernateException he) {
1770 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "' " + he.getMessage());
1771 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 + "'");
1772 vnfResourceCustomization = null;
1774 } catch (Exception e) {
1775 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' " + e.getMessage());
1776 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 + "'");
1777 vnfResourceCustomization = null;
1780 if (vnfResourceCustomization != null) {
1781 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1782 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUUID()));
1783 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1784 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1787 if (vnfResourceCustomization == null) {
1788 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1790 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1792 return vnfResourceCustomization;
1796 * Return list of VnfResourceCustomization objects identified by the given modelCustomizationUuid 1707
1798 * @param modelCustomizationUuid
1799 * @return List<VfModuleCustomization> or null if not found
1801 public List<VfModuleCustomization> getVfModuleCustomizationByVnfModuleCustomizationUuid(String modelCustomizationUuid) {
1802 long startTime = System.currentTimeMillis();
1803 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByVnfModuleCustomizationUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1805 // select * from vf_module_customization as vfmc where vfmc.MODEL_CUSTOMIZATION_UUID IN(
1806 // select vrcmc.VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID from vnf_res_custom_to_vf_module_custom as vrcmc
1807 // where vrcmc.VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID = 'd279139c-4b85-48ff-8ac4-9b83a6fc6da7')
1809 String hql = "SELECT vfmc FROM VfModuleCustomization as vfmc where vfmc.modelCustomizationUuid "
1810 + "IN(select vrcmc.vfModuleCustModelCustomizationUuid from VnfResCustomToVfModuleCustom as vrcmc "
1811 + "WHERE vrcmc.vnfResourceCustModelCustomizationUuid = :modelCustomizationUuid)";
1813 Query query = getSession().createQuery(hql);
1814 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1815 List<VfModuleCustomization> resultList = null;
1817 resultList = query.list();
1818 } catch (org.hibernate.HibernateException he) {
1819 LOGGER.debug("Hibernate Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + he.getMessage());
1820 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1822 } catch (Exception e) {
1823 LOGGER.debug("Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + e.getMessage());
1824 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1828 if (resultList == null) {
1829 resultList = new ArrayList<VfModuleCustomization>();
1831 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByVnfModuleCustomizationUuid", null);
1836 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
1838 * @return {@link VnfResourceCustomization} object or null if none found
1840 public VnfResourceCustomization getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId (String modelCustomizationName, String modelVersionId) {
1842 long startTime = System.currentTimeMillis ();
1843 LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " modelUUID " + modelVersionId);
1845 //select vrc.* from vnf_resource_customization vrc where vrc.MODEL_CUSTOMIZATION_UUID IN (select src.RESOURCE_MODEL_CUSTOMIZATION_UUID from service_to_resource_customizations src);
1846 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.vnfResourceModelUuid IN "
1847 + "(SELECT vr.modelUuid FROM VnfResource vr "
1848 + "WHERE vr.modelUuid = :modelVersionId)"
1849 + "AND vrc.modelInstanceName = :modelCustomizationName";
1851 Query query = getSession ().createQuery (hql);
1852 query.setParameter ("modelCustomizationName", modelCustomizationName);
1853 query.setParameter ("modelVersionId", modelVersionId);
1855 @SuppressWarnings("unchecked")
1856 List <VnfResourceCustomization> resultList = query.list ();
1858 if (resultList.isEmpty ()) {
1859 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1863 Collections.sort (resultList, new MavenLikeVersioningComparator ());
1864 Collections.reverse (resultList);
1866 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1867 return resultList.get (0);
1870 public ArrayList<VfModuleCustomization> getAllVfModuleCustomizations(String vnfResourceCustomizationMCU) {
1871 long startTime = System.currentTimeMillis();
1872 LOGGER.debug ("Catalog database - getAllVfModuleCustomizations with vnfResourceCustomizationMCU " + vnfResourceCustomizationMCU);
1874 List<VnfResCustomToVfModuleCustom> matches = this.getVRCtoVFMC(vnfResourceCustomizationMCU, null);
1875 if (matches == null || matches.size() < 1) {
1876 LOGGER.debug("Found no vf modules for " + vnfResourceCustomizationMCU);
1877 return new ArrayList<VfModuleCustomization>();
1879 ArrayList<VfModuleCustomization> list = new ArrayList<VfModuleCustomization>();
1880 for (VnfResCustomToVfModuleCustom v : matches) {
1881 String m = v.getVfModuleCustModelCustomizationUuid();
1882 LOGGER.debug("VfModule to match: " + m);
1883 VfModuleCustomization c = this.getVfModuleCustomizationByModelCustomizationId(m);
1887 LOGGER.debug("**UNABLE to find vfModule " + m);
1894 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1895 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1897 * @param modelCustomizationUuid
1898 * @return VnfResourceCustomization or null if not found
1900 public VnfResource getVnfResourceByModelUuid(String modelUuid) {
1901 long startTime = System.currentTimeMillis();
1902 LOGGER.debug ("Catalog database - get VnfResource with modelUuid " + modelUuid);
1904 String hql = "FROM VnfResource WHERE modelUuid = :modelUuid";
1905 Query query = getSession().createQuery(hql);
1906 query.setParameter ("modelUuid", modelUuid);
1907 VnfResource vnfResource = null;
1909 vnfResource = (VnfResource) query.uniqueResult ();
1910 } catch (org.hibernate.NonUniqueResultException nure) {
1911 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique Vnf_Resource row - data integrity error: modelUuid='" + modelUuid);
1912 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for Vnf Resource modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResource modelUuid==" + modelUuid);
1915 } catch (org.hibernate.HibernateException he) {
1916 LOGGER.debug("Hibernate Exception - while searching for: VnfResource modelUuid='" + modelUuid + "' " + he.getMessage());
1917 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResource modelUuid=" + modelUuid);
1920 } catch (Exception e) {
1921 LOGGER.debug("Generic Exception - while searching for: vnfResource ModelUuid='" + modelUuid + "'");
1922 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResource modelUuid=" + modelUuid);
1926 if (vnfResource == null) {
1927 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelUuid", null);
1929 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelUuid", null);
1934 public VnfResCustomToVfModuleCustom getVnfResCustomToVfModule(String vnfId, String vfId) {
1935 long startTime = System.currentTimeMillis();
1936 LOGGER.debug("Catalog database - getVnfResCustomToVfModule - vnfResourceCustModelCustUuid: " + vnfId + ", vfModuleCustModelCustomUuid=" + vfId);
1937 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue");
1938 HashMap<String, String> parameters = new HashMap<String, String>();
1939 parameters.put("vnfIdValue", vnfId);
1940 parameters.put("vfIdValue", vfId);
1941 VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow(hql.toString(), parameters, true);
1942 if (vrctvmc == null) {
1943 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResCustomToVfModule", null);
1945 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResCustomToVfModule", null);
1950 public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
1951 if (vnfResource == null)
1953 String vnfResourceModelUuid = vnfResource.getModelUuid();
1955 long startTime = System.currentTimeMillis();
1956 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
1958 return this.getVfModulesForVnfResource(vnfResourceModelUuid);
1962 public List<VfModule> getVfModulesForVnfResource(String vnfResourceModelUuid) {
1963 long startTime = System.currentTimeMillis();
1964 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceModelUuid: " + vnfResourceModelUuid);
1965 StringBuilder hql = new StringBuilder("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId");
1966 Query query = getSession().createQuery(hql.toString());
1967 query.setParameter("vnfResourceModelUUId", vnfResourceModelUuid);
1968 List<VfModule> resultList = null;
1970 resultList = query.list();
1971 if (resultList != null)
1972 LOGGER.debug("\tQuery found " + resultList.size() + " records.");
1974 LOGGER.debug("\tQuery found no records.");
1975 } catch (org.hibernate.HibernateException he) {
1976 LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + he.getMessage());
1977 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1979 } catch (Exception e) {
1980 LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + e.getMessage());
1981 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1984 if (resultList == null) {
1985 resultList = new ArrayList<VfModule>();
1987 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
1991 public Service getServiceByUuid (String serviceModelInvariantUuid) {
1993 long startTime = System.currentTimeMillis ();
1994 LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
1996 String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
1997 Query query = getSession ().createQuery (hql);
1998 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
2000 Service service = null;
2002 service = (Service) query.uniqueResult ();
2003 } catch (org.hibernate.NonUniqueResultException nure) {
2004 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
2005 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2007 } catch (org.hibernate.HibernateException he) {
2008 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "' " + he.getMessage());
2009 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2011 } catch (Exception e) {
2012 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + " " + e.getMessage());
2013 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2016 if (service == null) {
2017 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
2019 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
2025 public NetworkResource getNetworkResourceById(Integer id) {
2026 long startTime = System.currentTimeMillis ();
2027 LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
2029 String hql = "FROM NetworkResource WHERE id = :id";
2030 Query query = getSession ().createQuery (hql);
2031 query.setParameter ("id", id);
2033 NetworkResource networkResource = null;
2035 networkResource = (NetworkResource) query.uniqueResult ();
2036 } catch (org.hibernate.NonUniqueResultException nure) {
2037 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
2038 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
2040 } catch (org.hibernate.HibernateException he) {
2041 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2042 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
2044 } catch (Exception e) {
2045 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2046 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
2050 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2051 return networkResource;
2055 public NetworkResource getNetworkResourceById(String id) {
2056 long startTime = System.currentTimeMillis ();
2057 LOGGER.debug ("Catalog database - getNetworkResource with model_uuid " + id);
2059 String hql = "FROM NetworkResource WHERE modelUUID = :model_uuid";
2060 Query query = getSession ().createQuery (hql);
2061 query.setParameter ("model_uuid", id);
2063 List<NetworkResource> networkResources = null;
2065 networkResources = query.list ();
2066 } catch (org.hibernate.HibernateException he) {
2067 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2068 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);
2070 } catch (Exception e) {
2071 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2072 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);
2076 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2077 if (networkResources == null || networkResources.isEmpty())
2080 return networkResources.get(0);
2085 public static boolean isEmptyOrNull(String str) {
2088 if (str.equals("null"))
2095 public List<ServiceToResourceCustomization> getSTR(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
2096 long startTime = System.currentTimeMillis();
2097 LOGGER.debug("Catalog database: getSTR - smu=" + serviceModelUuid + ", rmcu=" + resourceModelCustomizationUuid + ", modelType = " + modelType);
2099 if (isEmptyOrNull(serviceModelUuid) && isEmptyOrNull(resourceModelCustomizationUuid) && isEmptyOrNull(modelType))
2102 StringBuilder hql = new StringBuilder("FROM ServiceToResourceCustomization WHERE ");
2103 boolean first = true;
2104 if (serviceModelUuid != null && !serviceModelUuid.equals("")) {
2105 hql.append("serviceModelUUID = :smu");
2108 if (resourceModelCustomizationUuid != null && !resourceModelCustomizationUuid.equals("")) {
2110 hql.append(" AND ");
2112 hql.append("resourceModelCustomizationUUID = :rmcu");
2115 if (modelType != null && !modelType.equals("")) {
2117 hql.append(" AND ");
2120 hql.append("modelType = :modelType");
2123 Query query = getSession().createQuery(hql.toString());
2124 if (hql.toString().contains(":smu"))
2125 query.setParameter("smu", serviceModelUuid);
2126 if (hql.toString().contains(":rmcu"))
2127 query.setParameter("rmcu", resourceModelCustomizationUuid);
2128 if (hql.toString().contains(":modelType"))
2129 query.setParameter("modelType", modelType);
2130 LOGGER.debug("query - " + hql.toString());
2132 @SuppressWarnings("unchecked")
2133 List<ServiceToResourceCustomization> resultList = query.list();
2134 if (resultList == null || resultList.size() < 1) {
2135 LOGGER.debug("Found no matches to the query - " + hql.toString());
2136 return new ArrayList<ServiceToResourceCustomization>();
2141 public List<VnfResCustomToVfModuleCustom> getVRCtoVFMC (String vrc_mcu, String vfmc_mcu) {
2142 long startTime = System.currentTimeMillis();
2143 LOGGER.debug("Catalog database: getVRCtoVFMC - vrc_mcu=" + vrc_mcu + ", vfmc_mcu=" + vfmc_mcu);
2145 if (isEmptyOrNull(vrc_mcu) && isEmptyOrNull(vfmc_mcu))
2148 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom WHERE ");
2149 boolean first = true;
2150 if (vrc_mcu != null && !vrc_mcu.equals("")) {
2151 hql.append("vnfResourceCustModelCustomizationUuid = :vrc_mcu");
2154 if (vfmc_mcu != null && !vfmc_mcu.equals("")) {
2156 hql.append(" AND ");
2158 hql.append("vfModuleCustModelCustomizationUuid = :vfmc_mcu");
2161 Query query = getSession().createQuery(hql.toString());
2162 if (hql.toString().contains(":vrc_mcu"))
2163 query.setParameter("vrc_mcu", vrc_mcu);
2164 if (hql.toString().contains(":vfmc_mcu"))
2165 query.setParameter("vfmc_mcu", vfmc_mcu);
2166 @SuppressWarnings("unchecked")
2167 List<VnfResCustomToVfModuleCustom> resultList = query.list();
2168 if (resultList == null || resultList.size() < 1) {
2169 LOGGER.debug("Found no matches to the query - " + hql.toString());
2170 return new ArrayList<VnfResCustomToVfModuleCustom>();
2175 @SuppressWarnings("unchecked")
2176 public List <TempNetworkHeatTemplateLookup> getTempNetworkHeatTemplateLookup (String networkResourceModelName) {
2178 long startTime = System.currentTimeMillis ();
2179 LOGGER.debug ("Catalog database - GetTempNetworkHeatTemplateLookup for Network Name " + networkResourceModelName);
2181 String hql = "FROM TempNetworkHeatTemplateLookup where networkResourceModelName = :networkResourceModelName";
2182 Query query = getSession ().createQuery (hql);
2183 query.setParameter ("networkResourceModelName", networkResourceModelName);
2185 List <TempNetworkHeatTemplateLookup> result = query.list ();
2186 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getTempNetworkHeatTemplateLookup", null);
2190 // 1702 API Spec - Query for all networks in a Service:
2191 public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
2192 long startTime = System.currentTimeMillis();
2193 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
2195 List<ServiceToResourceCustomization> strMappings = this.getSTR(serviceModelUuid, null, "network");
2196 if (strMappings == null || strMappings.size() < 1) {
2197 LOGGER.debug("Found NO matches for NRC with ServiceModelUuid=" + serviceModelUuid);
2198 return new ArrayList<NetworkResourceCustomization>();
2200 LOGGER.debug("Found " + strMappings.size() + " entries in ServiceToResourceCustomizations.network with smu=" + serviceModelUuid);
2202 ArrayList<NetworkResourceCustomization> masterList = new ArrayList<NetworkResourceCustomization>();
2203 for (ServiceToResourceCustomization stn : strMappings) {
2204 String networkModelCustomizationUuid = stn.getResourceModelCustomizationUUID();
2205 LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
2206 List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
2207 for (NetworkResourceCustomization nrc : resultSet) {
2208 masterList.add(nrc);
2211 LOGGER.debug("Returning " + masterList.size() + " NRC records");
2212 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
2215 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2216 long startTime = System.currentTimeMillis();
2217 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2219 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2220 Query query = getSession().createQuery(hql.toString());
2221 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2222 @SuppressWarnings("unchecked")
2223 List<Service> serviceList = query.list();
2225 if (serviceList.isEmpty()) {
2226 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2227 return new ArrayList<NetworkResourceCustomization>();
2230 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2231 Collections.reverse (serviceList);
2232 Service service = serviceList.get(0);
2234 String serviceNameVersionId = service.getModelUUID();
2235 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
2237 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2238 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2240 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2241 long startTime = System.currentTimeMillis();
2242 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2244 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2245 Query query = getSession().createQuery(hql.toString());
2246 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2247 query.setParameter("serviceModelVersion", serviceModelVersion);
2250 //can fix this later - no time - could do a unique query here - but this should work
2251 @SuppressWarnings("unchecked")
2252 List<Service> serviceList = query.list();
2254 if (serviceList.isEmpty()) {
2255 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2256 return new ArrayList<NetworkResourceCustomization>();
2259 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2260 Collections.reverse (serviceList);
2261 Service service = serviceList.get(0);
2263 String serviceNameVersionId = service.getModelUUID();
2265 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2266 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2269 public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
2270 long startTime = System.currentTimeMillis();
2271 LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
2273 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid");
2274 //Query query = getSession().createQuery(hql.toString());
2275 //query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
2276 //LOGGER.debug("QUERY: " + hql.toString() + ", networkModelCustomizationUuid=" + networkModelCustomizationUuid);
2278 //@SuppressWarnings("unchecked")
2279 //List<NetworkResourceCustomization> resultList = query.list();
2281 HashMap<String, String> params = new HashMap<String, String>();
2282 params.put("networkModelCustomizationUuid", networkModelCustomizationUuid);
2284 List<NetworkResourceCustomization> resultList = this.executeQueryMultipleRows(hql.toString(), params, true);
2286 if (resultList.isEmpty()) {
2287 LOGGER.debug("Unable to find an NMC with nmcu=" + networkModelCustomizationUuid);
2288 return new ArrayList<NetworkResourceCustomization>();
2290 for (NetworkResourceCustomization nrc : resultList) {
2291 nrc.setNetworkResource(this.getNetworkResourceById(nrc.getNetworkResourceModelUuid()));
2294 //this.populateNetworkResourceType(resultList);
2296 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
2300 public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
2301 long startTime = System.currentTimeMillis();
2302 LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
2304 NetworkResource nr = this.getNetworkResource(networkType);
2306 return new ArrayList<NetworkResourceCustomization>();
2308 String networkResourceId = nr.getModelUUID();
2310 LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
2311 StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId");
2313 Query query = getSession().createQuery(hql.toString());
2314 query.setParameter("networkResourceId", networkResourceId);
2316 @SuppressWarnings("unchecked")
2317 List<NetworkResourceCustomization> resultList = query.list();
2319 if (resultList != null && resultList.size() > 0) {
2320 LOGGER.debug("Found " + resultList.size() + " results");
2321 for (NetworkResourceCustomization nrc : resultList) {
2322 nrc.setNetworkType(networkType);
2323 nrc.setNetworkResource(nr);
2326 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
2330 public ArrayList<VfModuleCustomization> getAllVfmcForVrc(VnfResourceCustomization vrc) {
2331 long startTime = System.currentTimeMillis();
2332 LOGGER.debug("Catalog database: getAllVfmcForVrc - " + vrc.getModelCustomizationUuid());
2334 List<VnfResCustomToVfModuleCustom> vfmcs = this.getVRCtoVFMC(vrc.getModelCustomizationUuid(), null);
2335 if (vfmcs == null || vfmcs.size() < 1) {
2338 ArrayList<VfModuleCustomization> vfModuleCusts = new ArrayList<VfModuleCustomization>();
2339 for (VnfResCustomToVfModuleCustom vfmc : vfmcs) {
2340 VfModuleCustomization vfmcust = this.getVfModuleCustomizationByModelCustomizationId(vfmc.getVfModuleCustModelCustomizationUuid());
2341 if (vfmcust != null) {
2342 vfModuleCusts.add(vfmcust);
2345 return vfModuleCusts;
2348 //1702 API Spec cont'd - Query for all VnfResources in a Service:
2349 //1707 modified for db refactoring
2350 public List<VnfResourceCustomization> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
2351 long startTime = System.currentTimeMillis();
2352 LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
2354 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2355 Query query = getSession().createQuery(hql.toString());
2356 query.setParameter("serviceModelUuid", serviceModelUuid);
2357 @SuppressWarnings("unchecked")
2358 List<Service> serviceList = query.list();
2360 if (serviceList.isEmpty()) {
2361 LOGGER.debug("Unable to find a service with modelUuid=" + serviceModelUuid);
2362 return new ArrayList<VnfResourceCustomization>();
2365 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2366 Collections.reverse (serviceList);
2367 Service service = serviceList.get(0);
2369 // Step 2 - Now query to get the related VnfResourceCustomizations
2371 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "vnf");
2373 if (strcs.isEmpty()) {
2374 LOGGER.debug("Unable to find any related vnfs to a service with modelUuid=" + serviceModelUuid);
2375 return new ArrayList<VnfResourceCustomization>();
2378 ArrayList<VnfResourceCustomization> allVrcs = new ArrayList<VnfResourceCustomization>();
2379 for (ServiceToResourceCustomization strc : strcs) {
2380 LOGGER.debug("Try to find VRC for mcu=" + strc.getResourceModelCustomizationUUID());
2381 VnfResourceCustomization vrc = this.getVnfResourceCustomizationByModelCustomizationUuid(strc.getResourceModelCustomizationUUID());
2388 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2389 long startTime = System.currentTimeMillis();
2390 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2392 StringBuilder hqlService = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2393 Query query = getSession().createQuery(hqlService.toString());
2394 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2395 @SuppressWarnings("unchecked")
2396 List<Service> resultList = query.list();
2398 if (resultList.isEmpty()) {
2399 return new ArrayList<VnfResourceCustomization>();
2401 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2402 Collections.reverse (resultList);
2403 Service service = resultList.get(0);
2404 //now just call the method that takes the version - the service object will have the highest version
2405 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2407 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2408 long startTime = System.currentTimeMillis();
2409 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2411 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2412 Query query = getSession().createQuery(hql.toString());
2413 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2414 query.setParameter("serviceModelVersion", serviceModelVersion);
2416 @SuppressWarnings("unchecked")
2417 List<Service> resultList = query.list();
2419 if (resultList.isEmpty()) {
2420 return new ArrayList<VnfResourceCustomization>();
2422 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2423 Collections.reverse (resultList);
2424 Service service = resultList.get(0);
2425 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
2426 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2429 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
2430 long startTime = System.currentTimeMillis();
2431 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
2432 if (serviceVersion == null || serviceVersion.equals("")) {
2433 return this.getAllVnfsByServiceName(serviceName);
2436 StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName and version = :serviceVersion");
2437 Query query = getSession().createQuery(hql.toString());
2438 query.setParameter("serviceName", serviceName);
2439 query.setParameter("serviceVersion", serviceVersion);
2441 @SuppressWarnings("unchecked")
2442 List<Service> resultList = query.list();
2444 if (resultList.isEmpty()) {
2447 Service service = resultList.get(0);
2448 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2450 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName) {
2451 long startTime = System.currentTimeMillis();
2452 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
2454 StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName");
2455 Query query = getSession().createQuery(hql.toString());
2456 query.setParameter("serviceName", serviceName);
2458 @SuppressWarnings("unchecked")
2459 List<Service> resultList = query.list();
2461 if (resultList.isEmpty()) {
2464 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2465 Collections.reverse (resultList);
2466 Service service = resultList.get(0);
2468 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2471 public List<VnfResourceCustomization> getAllVnfsByVnfModelCustomizationUuid(String vnfModelCustomizationUuid) {
2472 long startTime = System.currentTimeMillis();
2473 LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid);
2475 StringBuilder hql1 = new StringBuilder("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu");
2476 Query query1 = getSession().createQuery(hql1.toString());
2477 query1.setParameter("vrcmcu", vnfModelCustomizationUuid);
2478 @SuppressWarnings("unchecked")
2479 List<VnfResourceCustomization> resultList1 = query1.list();
2481 if (resultList1.isEmpty()) {
2482 LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
2486 for (VnfResourceCustomization vrc : resultList1) {
2487 VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid());
2488 vrc.setVnfResource(vr);
2489 vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc));
2492 LOGGER.debug("Returning " + resultList1.size() + " vnf modules");
2493 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
2497 //1702 API Spec cont'd - Query for all allotted resources in a Service
2499 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
2500 long startTime = System.currentTimeMillis();
2501 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
2503 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "allottedResource");
2504 if (strcs == null || strcs.size() < 1) {
2505 LOGGER.debug("No AR entries found for " + serviceModelUuid);
2506 return new ArrayList<AllottedResourceCustomization>();
2508 LOGGER.debug("Found " + strcs.size() + " entries in ServiceToResourceCustomizations with smu=" + serviceModelUuid + ", allottedResource");
2510 ArrayList<AllottedResourceCustomization> masterList = new ArrayList<AllottedResourceCustomization>();
2511 for (ServiceToResourceCustomization star : strcs) {
2512 String arModelCustomizationUuid = star.getResourceModelCustomizationUUID();
2513 LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
2514 List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
2515 for (AllottedResourceCustomization arc : resultSet) {
2516 masterList.add(arc);
2519 LOGGER.debug("Returning " + masterList.size() + " ARC records");
2520 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
2524 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2525 long startTime = System.currentTimeMillis();
2526 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2528 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2529 Query query = getSession().createQuery(hql.toString());
2530 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2531 @SuppressWarnings("unchecked")
2532 List<Service> serviceList = query.list();
2534 if (serviceList.isEmpty()) {
2535 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2536 return new ArrayList<AllottedResourceCustomization>();
2539 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2540 Collections.reverse (serviceList);
2541 Service service = serviceList.get(0);
2543 String serviceModelUuid = service.getModelUUID();
2544 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceModelUuid);
2546 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2549 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2550 long startTime = System.currentTimeMillis();
2551 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2553 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2554 Query query = getSession().createQuery(hql.toString());
2555 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2556 query.setParameter("serviceModelVersion", serviceModelVersion);
2558 @SuppressWarnings("unchecked")
2559 List<Service> serviceList = query.list();
2561 if (serviceList.isEmpty()) {
2562 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2563 return new ArrayList<AllottedResourceCustomization>();
2566 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2567 Collections.reverse (serviceList);
2568 Service service = serviceList.get(0);
2570 String serviceModelUuid = service.getModelUUID();
2572 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2575 public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
2576 long startTime = System.currentTimeMillis();
2577 LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
2579 StringBuilder hql = new StringBuilder("FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
2580 Query query = getSession().createQuery(hql.toString());
2581 query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
2583 @SuppressWarnings("unchecked")
2584 List<AllottedResourceCustomization> resultList = query.list();
2586 if (resultList.isEmpty()) {
2587 LOGGER.debug("No ARC found with arc_mcu=" + arModelCustomizationUuid);
2588 return new ArrayList<AllottedResourceCustomization>();
2590 // There should only be one - but we'll handle if multiple
2591 for (AllottedResourceCustomization arc : resultList) {
2592 AllottedResource ar = this.getAllottedResourceByModelUuid(arc.getArModelUuid());
2593 arc.setAllottedResource(ar);
2596 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
2600 public AllottedResource getAllottedResourceByModelUuid(String arModelUuid) {
2601 long startTime = System.currentTimeMillis ();
2602 LOGGER.debug ("Catalog database - get Allotted Resource with modelUuid= " + arModelUuid);
2604 String hql = "FROM AllottedResource WHERE modelUuid = :arModelUuid";
2605 Query query = getSession ().createQuery (hql);
2606 query.setParameter ("arModelUuid", arModelUuid);
2608 @SuppressWarnings("unchecked")
2609 List <AllottedResource> resultList = query.list ();
2611 // See if something came back. Name is unique, so
2612 if (resultList.isEmpty ()) {
2613 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. AllottedResource not found", "CatalogDB", "getAllottedResourceByModelUuid", null);
2616 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllottedResourceByModelUuid", null);
2617 return resultList.get (0);
2621 //1702 API Spec cont'd - Query for all resources in a Service:
2622 public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
2623 long startTime = System.currentTimeMillis();
2624 LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
2626 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2627 Query query = getSession().createQuery(hql.toString());
2628 query.setParameter("serviceModelUuid", serviceModelUuid);
2629 LOGGER.debug("Query: " + hql.toString() + ", smu=" + serviceModelUuid);
2630 @SuppressWarnings("unchecked")
2631 List<Service> serviceList = query.list();
2633 if (serviceList.isEmpty()) {
2634 LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
2635 return new ServiceMacroHolder();
2638 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2639 Collections.reverse (serviceList);
2640 Service service = serviceList.get(0);
2642 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2643 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
2644 smh.setNetworkResourceCustomization(nrcList);
2645 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2646 smh.setAllottedResourceCustomization(arcList);
2647 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(serviceModelUuid);
2648 smh.setVnfResourceCustomizations(vnfList);
2650 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
2653 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2654 long startTime = System.currentTimeMillis();
2655 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2657 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2658 Query query = getSession().createQuery(hql.toString());
2659 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2660 @SuppressWarnings("unchecked")
2661 List<Service> serviceList = query.list();
2663 if (serviceList.isEmpty()) {
2664 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2665 return new ServiceMacroHolder();
2668 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2669 Collections.reverse (serviceList);
2670 Service service = serviceList.get(0);
2672 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2673 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2674 smh.setNetworkResourceCustomization(nrcList);
2675 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2676 smh.setAllottedResourceCustomization(arcList);
2677 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2678 smh.setVnfResourceCustomizations(vnfList);
2680 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
2684 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2685 long startTime = System.currentTimeMillis();
2686 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2688 StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2689 Query query = getSession().createQuery(hql.toString());
2690 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2691 query.setParameter("serviceModelVersion", serviceModelVersion);
2692 //TODO make this a unique query
2693 @SuppressWarnings("unchecked")
2694 List<Service> serviceList = query.list();
2696 if (serviceList.isEmpty()) {
2697 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
2698 return new ServiceMacroHolder();
2701 Collections.sort (serviceList, new MavenLikeVersioningComparator ());
2702 Collections.reverse (serviceList);
2703 Service service = serviceList.get(0);
2705 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2706 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2707 smh.setNetworkResourceCustomization(nrcList);
2708 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2709 smh.setAllottedResourceCustomization(arcList);
2710 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2711 smh.setVnfResourceCustomizations(vnfList);
2713 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
2717 // 1707 New API queries
2718 public NetworkResourceCustomization getSingleNetworkByModelCustomizationUuid(String modelCustomizationUuid) {
2719 long startTime = System.currentTimeMillis();
2720 LOGGER.debug("Catalog database; getSingleNetworkByModelCustomizationUuid - " + modelCustomizationUuid);
2721 List<NetworkResourceCustomization> resultList = this.getAllNetworksByNetworkModelCustomizationUuid(modelCustomizationUuid);
2722 if (resultList == null || resultList.size() < 1) {
2725 return resultList.get(0);
2727 public AllottedResourceCustomization getSingleAllottedResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2728 long startTime = System.currentTimeMillis();
2729 LOGGER.debug("Catalog database; getSingleAllottedResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2730 List<AllottedResourceCustomization> resultList = this.getAllAllottedResourcesByArModelCustomizationUuid(modelCustomizationUuid);
2731 if (resultList == null || resultList.size() < 1) {
2734 return resultList.get(0);
2737 public VnfResource getSingleVnfResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2739 long startTime = System.currentTimeMillis();
2740 LOGGER.debug("Catalog database; getSingleVnfResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2741 List<VnfResource> resultList = this.getAllVnfsByVnfModelCustomizationUuid(modelCustomizationUuid);
2742 if (resultList == null || resultList.size() < 1) {
2745 return resultList.get(0);
2750 private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
2751 HashMap<String, NetworkResource> networkResources = new HashMap<String, NetworkResource>();
2753 for (NetworkResourceCustomization nrc : resultList) {
2754 //Integer network_id = nrc.getNetworkResourceId();
2755 String network_id = nrc.getNetworkResourceModelUuid();
2756 if (network_id == null) {
2757 nrc.setNetworkResource(null);
2758 nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
2761 if (networkResources.containsKey(network_id)) {
2762 nrc.setNetworkResource(networkResources.get(network_id));
2763 nrc.setNetworkType(networkResources.get(network_id).getModelName());
2765 NetworkResource nr = this.getNetworkResourceById(network_id);
2767 nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
2769 nrc.setNetworkType(nr.getModelName());
2770 nrc.setNetworkResource(nr);
2771 networkResources.put(network_id, nr);
2778 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
2779 * first query VF_MODULE table by type, and then use the ID to query
2780 * VNF_RECIPE by VF_MODULE_ID and ACTION
2783 * @parm vfModuleModelName
2785 * @return VnfRecipe object or null if none found
2787 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
2788 String vfModuleType = vnfType + "::" + vfModuleModelName;
2790 StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type ");
2792 long startTime = System.currentTimeMillis ();
2793 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
2795 Query query = getSession ().createQuery (hql.toString ());
2796 query.setParameter (TYPE, vfModuleType);
2798 @SuppressWarnings("unchecked")
2799 List <VfModule> resultList = query.list ();
2801 if (resultList.isEmpty ()) {
2802 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
2806 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2807 Collections.reverse (resultList);
2809 VfModule vfMod = resultList.get(0);
2811 String vfModuleId = vfMod.getModelUUID();
2813 StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2815 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
2819 Query query1 = getSession ().createQuery (hql1.toString ());
2820 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2821 query1.setParameter (ACTION, action);
2823 @SuppressWarnings("unchecked")
2824 List <VnfRecipe> resultList1 = query1.list ();
2826 if (resultList1.isEmpty ()) {
2827 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
2831 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2832 Collections.reverse (resultList1);
2834 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
2835 return resultList1.get (0);
2839 * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2840 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2842 * @param vnfModuleType
2843 * @parm modelCustomizationUuid
2844 * @param asdcServiceModelVersion
2845 * @param modelVersion
2847 * @return VfModule list
2849 public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2852 if(modelCustomizationUuid != null){
2853 hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
2855 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2857 query = getSession ().createQuery (hql.toString ());
2858 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
2859 query.setParameter ("version", asdcServiceModelVersion);
2861 hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
2863 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2865 query = getSession ().createQuery (hql.toString ());
2866 query.setParameter (TYPE, vfModuleType);
2867 query.setParameter ("version", asdcServiceModelVersion);
2868 query.setParameter ("modelVersion", modelVersion);
2871 @SuppressWarnings("unchecked")
2872 List <VfModule> resultList = query.list ();
2878 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2879 * MODEL_CUSTOMIZATION_UUID, ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2880 * first query VF_MODULE table by type, and then use the ID to query
2881 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2884 * @parm vfModuleModelName
2886 * @return VnfRecipe object or null if none found
2888 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2889 String vfModuleType = vnfType + "::" + vfModuleModelName;
2890 long startTime = System.currentTimeMillis ();
2891 List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
2893 if (resultList.isEmpty ()) {
2894 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2898 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2899 Collections.reverse (resultList);
2901 VfModule vfMod = resultList.get(0);
2903 String vfModuleId = vfMod.getModelUUID();
2905 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2907 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2911 Query query1 = getSession ().createQuery (hql1.toString ());
2912 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2913 query1.setParameter (ACTION, action);
2915 @SuppressWarnings("unchecked")
2916 List <VnfComponentsRecipe> resultList1 = query1.list ();
2918 if (resultList1.isEmpty ()) {
2919 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2923 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2924 Collections.reverse (resultList1);
2926 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2927 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2928 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);
2931 return resultList1.get (0);
2935 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2936 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2937 * first query VF_MODULE table by type, and then use the ID to query
2938 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2941 * @parm vfModuleModelName
2943 * @return VnfRecipe object or null if none found
2945 public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
2946 long startTime = System.currentTimeMillis ();
2948 if (resultList.isEmpty ()) {
2949 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2953 Collections.sort (resultList, new MavenLikeVersioningComparator ());
2954 Collections.reverse (resultList);
2956 VfModule vfMod = resultList.get(0);
2958 String vfModuleId = vfMod.getModelName();
2960 StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2962 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2966 Query query1 = getSession ().createQuery (hql1.toString ());
2967 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2968 query1.setParameter (ACTION, action);
2970 @SuppressWarnings("unchecked")
2971 List <VnfComponentsRecipe> resultList1 = query1.list ();
2973 if (resultList1.isEmpty ()) {
2974 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2978 Collections.sort (resultList1, new MavenLikeVersioningComparator ());
2979 Collections.reverse (resultList1);
2981 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2982 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2983 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);
2986 return resultList1.get (0);
2991 * Return all VNF Resources in the Catalog DB
2993 * @return A list of VnfResource objects
2995 @SuppressWarnings("unchecked")
2996 public List <VnfResource> getAllVnfResources () {
2998 long startTime = System.currentTimeMillis ();
2999 LOGGER.debug ("Catalog database - get all VNF resources");
3001 String hql = "FROM VnfResource";
3002 Query query = getSession ().createQuery (hql);
3004 List <VnfResource> result = query.list ();
3005 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
3010 * Return VNF Resources in the Catalog DB that match a given VNF role
3012 * @return A list of VnfResource objects
3014 @SuppressWarnings("unchecked")
3015 @Deprecated // vnfRole is no longer in VnfResource
3016 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
3018 long startTime = System.currentTimeMillis ();
3019 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
3021 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
3022 Query query = getSession ().createQuery (hql);
3023 query.setParameter ("vnfRole", vnfRole);
3025 List <VnfResource> resources = query.list ();
3026 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
3031 * Return VNF Resources in the Catalog DB that match a given VNF role
3033 * @return A list of VnfResource objects
3035 @SuppressWarnings("unchecked")
3036 public List<VnfResourceCustomization> getVnfResourceCustomizationsByRole(String vnfRole) {
3037 long startTime = System.currentTimeMillis ();
3038 LOGGER.debug ("Catalog database - get all VNF resource customizations for role " + vnfRole);
3040 String hql = "FROM VnfResourceCustomization WHERE nfRole = :vnfRole";
3041 Query query = getSession ().createQuery (hql);
3042 query.setParameter ("vnfRole", vnfRole);
3044 List <VnfResourceCustomization> resources = query.list ();
3045 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationsByRole", null);
3050 * Return all Network Resources in the Catalog DB
3052 * @return A list of NetworkResource objects
3054 @SuppressWarnings("unchecked")
3055 public List <NetworkResource> getAllNetworkResources () {
3057 long startTime = System.currentTimeMillis ();
3058 LOGGER.debug ("Catalog database - get all network resources");
3060 String hql = "FROM NetworkResource";
3061 Query query = getSession ().createQuery (hql);
3063 List <NetworkResource> result = query.list ();
3064 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
3068 @SuppressWarnings("unchecked")
3069 public List<NetworkResourceCustomization> getAllNetworkResourceCustomizations() {
3070 long startTime = System.currentTimeMillis ();
3071 LOGGER.debug ("Catalog database - get all network resource customizations");
3073 String hql = "FROM NetworkResourceCustomization";
3074 Query query = getSession ().createQuery (hql);
3076 List <NetworkResourceCustomization> result = query.list ();
3077 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResourceCustomizations", null);
3082 * Return all VF Modules in the Catalog DB
3084 * @return A list of VfModule objects
3086 @SuppressWarnings("unchecked")
3087 public List <VfModule> getAllVfModules () {
3089 long startTime = System.currentTimeMillis ();
3090 LOGGER.debug ("Catalog database - get all vf modules");
3092 String hql = "FROM VfModule";
3093 Query query = getSession ().createQuery (hql);
3095 List <VfModule> result = query.list ();
3096 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
3100 @SuppressWarnings("unchecked")
3101 public List <VfModuleCustomization> getAllVfModuleCustomizations () {
3103 long startTime = System.currentTimeMillis ();
3104 LOGGER.debug ("Catalog database - get all vf module customizations");
3106 String hql = "FROM VfModuleCustomization";
3107 Query query = getSession ().createQuery (hql);
3109 List <VfModuleCustomization> result = query.list ();
3110 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModuleCustomizations", null);
3116 * Return all HeatEnvironment in the Catalog DB
3118 * @return A list of HeatEnvironment objects
3120 @SuppressWarnings("unchecked")
3121 public List <HeatEnvironment> getAllHeatEnvironment () {
3123 long startTime = System.currentTimeMillis ();
3124 LOGGER.debug ("Catalog database - get all Heat environments");
3126 String hql = "FROM HeatEnvironment";
3127 Query query = getSession ().createQuery (hql);
3129 List <HeatEnvironment> result = query.list ();
3130 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
3135 * Fetch the Environment by Environment ID - 1510
3137 @Deprecated // no longer in heat envt table
3138 public HeatEnvironment getHeatEnvironment (int id) {
3140 long startTime = System.currentTimeMillis ();
3141 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
3143 String hql = "FROM HeatEnvironment WHERE id = :idValue";
3145 LOGGER.debug ("getHeatEnvironment called with id=" + id);
3147 Query query = getSession ().createQuery (hql);
3148 query.setParameter ("idValue", id);
3150 @SuppressWarnings("unchecked")
3151 List <HeatEnvironment> resultList = query.list ();
3153 // See if something came back.
3154 if (resultList.isEmpty ()) {
3155 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
3158 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
3159 return resultList.get (0);
3163 * Fetch the nested templates - 1510
3167 public Map <String, Object> getNestedTemplates (int templateId) {
3168 Map <String, Object> nestedTemplates = null;
3169 long startTime = System.currentTimeMillis ();
3170 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
3172 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
3174 Query query = getSession ().createQuery (hql);
3175 query.setParameter ("parentIdValue", templateId);
3177 @SuppressWarnings("unchecked")
3178 List <HeatNestedTemplate> resultList = query.list ();
3179 // If nothing comes back, there are no nested templates
3180 if (resultList.isEmpty ()) {
3181 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3182 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
3185 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3186 nestedTemplates = new HashMap <String, Object> ();
3187 for (HeatNestedTemplate hnt : resultList) {
3188 LOGGER.debug ("Querying for " + hnt);
3189 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
3191 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3194 String providerResourceFile = hnt.getProviderResourceFile ();
3195 String heatTemplateBody = ht.getTemplateBody ();
3196 if (providerResourceFile != null && heatTemplateBody != null) {
3197 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3199 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3202 // Make sure we're not returning an empty map - if so, just return null
3203 if (nestedTemplates.isEmpty ()) {
3204 LOGGER.debug ("nestedTemplates is empty - just return null");
3205 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3208 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3209 return nestedTemplates;
3212 * Return a Map<String, Object> for returning the child templates and their contents
3214 * @param parentHeatTemplateId
3215 * @return Map<String,Object> or null if none found
3217 public Map <String, Object> getNestedTemplates (String parentHeatTemplateId) {
3218 Map <String, Object> nestedTemplates = null;
3219 long startTime = System.currentTimeMillis ();
3220 LOGGER.debug ("Catalog database - getNestedTemplates called with parentTemplateId " + parentHeatTemplateId);
3222 String hql = "FROM HeatNestedTemplate where parentTemplateId = :parentHeatTemplateId";
3224 Query query = getSession ().createQuery (hql);
3225 query.setParameter ("parentHeatTemplateId", parentHeatTemplateId);
3227 @SuppressWarnings("unchecked")
3228 List <HeatNestedTemplate> resultList = query.list ();
3229 // If nothing comes back, there are no nested templates
3230 if (resultList.isEmpty ()) {
3231 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3232 LOGGER.debug ("No nestedTemplates found for templateId=" + parentHeatTemplateId + ", " + hql);
3235 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3236 nestedTemplates = new HashMap <String, Object> ();
3237 for (HeatNestedTemplate hnt : resultList) {
3238 LOGGER.debug ("Querying for " + hnt);
3239 HeatTemplate ht = this.getHeatTemplateByArtifactUuid (hnt.getChildTemplateId ());
3241 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3244 String providerResourceFile = hnt.getProviderResourceFile ();
3245 String heatTemplateBody = ht.getTemplateBody ();
3246 if (providerResourceFile != null && heatTemplateBody != null) {
3247 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3249 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3252 // Make sure we're not returning an empty map - if so, just return null
3253 if (nestedTemplates.isEmpty ()) {
3254 LOGGER.debug ("nestedTemplates is empty - just return null");
3255 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3258 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3259 return nestedTemplates;
3263 * Fetch any files in the HEAT_FILES table 1510
3266 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
3267 Map <String, HeatFiles> heatFiles = null;
3269 long startTime = System.currentTimeMillis ();
3270 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
3271 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
3273 Query query = getSession ().createQuery (hql);
3274 query.setParameter ("vnfResourceIdValue", vnfResourceId);
3276 @SuppressWarnings("unchecked")
3277 List <HeatFiles> resultList = query.list ();
3278 // If nothing comes back, there are no heat files
3279 if (resultList.isEmpty ()) {
3280 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
3281 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
3284 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
3285 heatFiles = new HashMap <String, HeatFiles> ();
3286 for (HeatFiles hf : resultList) {
3287 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
3288 heatFiles.put (hf.getFileName (), hf);
3290 // Make sure we're not returning an empty map - if so, just return null
3291 if (heatFiles.isEmpty ()) {
3292 LOGGER.debug ("heatFiles is empty - just return null");
3293 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
3296 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
3300 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
3302 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
3304 Map <String, HeatFiles> heatFiles = null;
3306 long startTime = System.currentTimeMillis ();
3307 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
3308 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
3310 Query query = getSession ().createQuery (hql);
3311 query.setParameter ("vfModuleIdValue", vfModuleId);
3313 List<VfModuleToHeatFiles> mapList = query.list();
3314 if (mapList.isEmpty()) {
3315 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
3316 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3319 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3320 heatFiles = new HashMap<String, HeatFiles>();
3321 for (VfModuleToHeatFiles vmthf : mapList) {
3322 int heatFilesId = vmthf.getHeatFilesId();
3323 hql = "FROM HeatFiles where id = :id_value";
3324 query = getSession().createQuery(hql);
3325 query.setParameter("id_value", heatFilesId);
3326 List<HeatFiles> fileList = query.list();
3327 if (fileList.isEmpty()) {
3328 // Should this throw an exception??
3329 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
3330 String errorString = "_ERROR|" + heatFilesId;
3331 // The receiving code needs to know to throw an exception for this - or ignore it.
3332 heatFiles.put(errorString, null);
3334 // Should only ever have 1 result - add it to our Map
3335 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
3336 for (HeatFiles hf : fileList) {
3337 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3338 heatFiles.put(hf.getFileName(), hf);
3342 if (heatFiles.isEmpty()) {
3343 LOGGER.debug ("heatFiles is empty - just return null");
3344 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3347 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3354 * Return a VfModuleToHeatFiles object
3356 * @param vfModuleModelUuid, heatFilesArtifactUuid
3357 * @return VfModuleToHeatFiles or null if none found
3359 public VfModuleToHeatFiles getVfModuleToHeatFilesEntry(String vfModuleModelUuid, String heatFilesArtifactUuid) {
3361 long startTime = System.currentTimeMillis ();
3362 LOGGER.debug ("Catalog database - getVfModuleToHeatFilesEntry with vfModuleModelUuid " + vfModuleModelUuid + ", heatFilesArtifactUuid=" + heatFilesArtifactUuid);
3363 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue and heatFilesArtifactUuid = :heatFilesArtifactUuidValue";
3365 HashMap<String, String> parameters = new HashMap<String, String>();
3366 parameters.put("vfModuleModelUuidValue", vfModuleModelUuid);
3367 parameters.put("heatFilesArtifactUuidValue", heatFilesArtifactUuid);
3369 VfModuleToHeatFiles vmthf = null;
3372 vmthf = this.executeQuerySingleRow(hql.toString(), parameters, true);
3373 } catch (Exception e) {
3381 * Return a ServiceToResourceCustomization object
3383 * @param vfModuleModelUuid, heatFilesArtifactUuid
3384 * @return VfModuleToHeatFiles or null if none found
3386 public ServiceToResourceCustomization getServiceToResourceCustomization(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
3388 long startTime = System.currentTimeMillis ();
3389 LOGGER.debug ("Catalog database - getServiceToResourceCustomization with serviceModelUuid=" + serviceModelUuid + ", resourceModelCustomizationUuid=" + resourceModelCustomizationUuid + ", modelType=" + modelType);
3390 String hql = "FROM ServiceToResourceCustomization where serviceModelUUID = :serviceModelUuidValue and resourceModelCustomizationUUID = :resourceModelCustomizationUuidValue and modelType = :modelTypeValue ";
3392 HashMap<String, String> parameters = new HashMap<String, String>();
3393 parameters.put("serviceModelUuidValue", serviceModelUuid);
3394 parameters.put("resourceModelCustomizationUuidValue", resourceModelCustomizationUuid);
3395 parameters.put("modelTypeValue", modelType);
3397 ServiceToResourceCustomization strc = null;
3400 strc = this.executeQuerySingleRow(hql.toString(), parameters, true);
3401 } catch (Exception e) {
3408 * Return a Map<String, HeatFiles> for returning the heat files associated with a vfModule 1707
3410 * @param parentHeatTemplateId
3411 * @return Map<String,Object> or null if none found
3413 public Map <String, HeatFiles> getHeatFilesForVfModule(String vfModuleModelUuid) {
3414 Map <String, HeatFiles> heatFiles = null;
3416 long startTime = System.currentTimeMillis ();
3417 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleModelUuid " + vfModuleModelUuid);
3418 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue";
3420 Query query = getSession ().createQuery (hql);
3421 query.setParameter ("vfModuleModelUuidValue", vfModuleModelUuid);
3423 @SuppressWarnings("unchecked")
3424 List<VfModuleToHeatFiles> mapList = query.list();
3425 if (mapList.isEmpty()) {
3426 LOGGER.debug ("No heatFiles found for vfModuleModelUuid=" + vfModuleModelUuid);
3427 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3430 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3431 heatFiles = new HashMap<String, HeatFiles>();
3432 for (VfModuleToHeatFiles vmthf : mapList) {
3433 String heatFilesUuid = vmthf.getHeatFilesArtifactUuid();
3434 hql = "FROM HeatFiles where artifactUuid = :heatFilesUuidValue";
3435 query = getSession().createQuery(hql);
3436 query.setParameter("heatFilesUuidValue", heatFilesUuid);
3437 @SuppressWarnings("unchecked")
3438 List<HeatFiles> fileList = query.list();
3439 if (fileList.isEmpty()) {
3440 // Should this throw an exception??
3441 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesUuid);
3442 String errorString = "_ERROR|" + heatFilesUuid;
3443 // The receiving code needs to know to throw an exception for this - or ignore it.
3444 heatFiles.put(errorString, null);
3446 // Should only ever have 1 result - add it to our Map
3447 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesUuid);
3448 for (HeatFiles hf : fileList) {
3449 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3450 heatFiles.put(hf.getFileName(), hf);
3454 if (heatFiles.isEmpty()) {
3455 LOGGER.debug ("heatFiles is empty - just return null");
3456 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3459 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3464 * Get the heat template object based on asdc attributes
3466 * @param templateName The template name, generally the yaml filename. "example.yaml"
3467 * @param version The version as specified by ASDC. "1.1"
3468 * @param asdcResourceName The ASDC resource name provided in the ASDC artifact
3470 * @return The HeatTemplate
3472 @Deprecated // asdcResourceName is no longer in heatTeamplate
3473 public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
3475 long startTime = System.currentTimeMillis ();
3476 LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
3479 + " and ASDC resource name "
3480 + asdcResourceName);
3482 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
3483 Query query = getSession ().createQuery (hql);
3484 query.setParameter ("template_name", templateName);
3485 query.setParameter ("version", version);
3486 query.setParameter ("asdcResourceName", asdcResourceName);
3488 @SuppressWarnings("unchecked")
3489 List <HeatTemplate> resultList = query.list ();
3491 // See if something came back.
3492 if (resultList.isEmpty ()) {
3493 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
3496 // Name + Version is unique, so should only be one element
3497 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3498 return resultList.get (0);
3503 * Save the Heat Template
3505 * @param heat The heat template
3506 * @param paramSet The list of heat template parameters
3508 public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
3510 long startTime = System.currentTimeMillis ();
3511 LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName() + ", artifactUUID=" + heat.getArtifactUuid());
3513 heat.setParameters(null);
3515 // HeatTemplate heatTemp = this.getHeatTemplate (heat.getTemplateName (),
3516 // heat.getVersion ());
3518 HeatTemplate heatTemp = this.getHeatTemplateByArtifactUuidRegularQuery(heat.getArtifactUuid());
3520 if (heatTemp == null) {
3521 this.getSession ().save (heat);
3523 if (paramSet != null) {
3524 StringBuilder sb = new StringBuilder("Parameters: ");
3525 for (HeatTemplateParam param : paramSet) {
3526 param.setHeatTemplateArtifactUuid(heat.getArtifactUuid());
3527 sb.append(param.getParamName() + ", ");
3529 LOGGER.debug(sb.toString());
3530 heat.setParameters (paramSet);
3532 Session session = this.getSession();
3533 if (!(session.isConnected() && session.isOpen())) {
3534 LOGGER.debug("Initial session is not connected or open - get another");
3535 session = this.getSession();
3537 //session.merge(heat);
3539 } catch (HibernateException he1) {
3540 LOGGER.debug("Hibernate Exception encountered on first attempt at save(heat) - try again..." + he1.getMessage());
3541 LOGGER.debug(he1.getStackTrace().toString());
3543 Session session = this.getSession();
3544 //session.merge(heat);
3546 } catch (HibernateException he2) {
3547 LOGGER.debug("Hibernate Exception encountered on second attempt at save(heat)" + he2.getMessage());
3548 LOGGER.debug(he2.getStackTrace().toString());
3550 } catch (Exception e2) {
3551 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage());
3552 LOGGER.debug(e2.getStackTrace().toString());
3556 } catch (Exception e1) {
3557 LOGGER.debug("General Exception encountered on first attempt at save(heat) - try again..." + e1.getMessage());
3558 LOGGER.debug(e1.getStackTrace().toString());
3560 Session session = this.getSession();
3561 //session.merge(heat);
3563 } catch (HibernateException he2) {
3564 LOGGER.debug("General Exception encountered on second attempt at save(heat)" + he2.getMessage());
3565 LOGGER.debug(he2.getStackTrace().toString());
3567 } catch (Exception e2) {
3568 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage());
3569 LOGGER.debug(e2.getStackTrace().toString());
3576 heat.setArtifactUuid(heatTemp.getArtifactUuid());
3579 //heat.setParameters(paramSet);
3580 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3585 * Retrieves a Heat environment from DB based on its unique key.
3587 * @param name the environment artifact name
3588 * @param version the environment resource version
3589 * @param asdcResourceName the environment resource name
3590 * @return the heat environment from DB or null if not found
3593 public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
3594 long startTime = System.currentTimeMillis ();
3595 LOGGER.debug ("Catalog database - get Heat environment with name " + name
3598 + " and ASDC resource name "
3599 + asdcResourceName);
3601 String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
3602 Query query = getSession ().createQuery (hql);
3603 query.setParameter ("name", name);
3604 query.setParameter ("version", version);
3605 query.setParameter ("asdcResourceName", asdcResourceName);
3606 HeatEnvironment env = null;
3608 env = (HeatEnvironment) query.uniqueResult ();
3609 } catch (org.hibernate.NonUniqueResultException nure) {
3610 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);
3611 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);
3613 } catch (org.hibernate.HibernateException he) {
3614 LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
3615 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);
3617 } catch (Exception e) {
3618 LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName);
3619 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);
3623 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3625 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3631 * Retrieves a Heat environment from DB based on its unique key. 1707
3633 * @param name the environment artifact name
3634 * @param version the environment resource version
3635 * @return the heat environment from DB or null if not found
3637 public HeatEnvironment getHeatEnvironment (String artifactUuid, String version) {
3638 long startTime = System.currentTimeMillis ();
3639 LOGGER.debug ("Catalog database - get Heat environment with uuid " + artifactUuid
3643 String hql = "FROM HeatEnvironment WHERE artifactUuid=:artifactUuid AND version=:version";
3644 Query query = getSession ().createQuery (hql);
3645 query.setParameter ("artifactUuid", artifactUuid);
3646 query.setParameter ("version", version);
3647 HeatEnvironment env = null;
3649 env = (HeatEnvironment) query.uniqueResult ();
3650 } catch (org.hibernate.NonUniqueResultException nure) {
3651 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + artifactUuid + "', version='" + version);
3652 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "non unique result for ArtifactUUID=" + artifactUuid);
3655 } catch (org.hibernate.HibernateException he) {
3656 LOGGER.debug("Hibernate Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + he.getMessage() );
3657 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUUID=" + artifactUuid + " and version=" + version , "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUUID=" + artifactUuid);
3660 } catch (Exception e) {
3661 LOGGER.debug("Generic Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + e.getMessage());
3662 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUUID=" + artifactUuid);
3667 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3669 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3675 * Save the HeatEnvironment
3677 * @param env The Environment
3679 public void saveHeatEnvironment (HeatEnvironment env) {
3680 long startTime = System.currentTimeMillis ();
3681 LOGGER.debug ("Catalog database - save Heat environment with name "
3682 + env.getEnvironment() + " and ArtifactUUID " + env.getArtifactUuid());
3684 HeatEnvironment dbEnv = getHeatEnvironment (env.getArtifactUuid(), env.getVersion ());
3685 if (dbEnv == null) {
3687 this.getSession ().save (env);
3690 env.setArtifactUuid(dbEnv.getArtifactUuid());
3694 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3699 * Save the heatTemplate
3701 * @param heat The heat template
3703 public void saveHeatTemplate (HeatTemplate heat) {
3704 long startTime = System.currentTimeMillis ();
3705 LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
3707 this.getSession ().update (heat);
3709 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3713 public void saveHeatFile (HeatFiles heatFile) {
3714 long startTime = System.currentTimeMillis ();
3715 LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
3717 this.getSession ().save (heatFile);
3719 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
3723 public void saveVnfRecipe (VnfRecipe vnfRecipe) {
3724 long startTime = System.currentTimeMillis ();
3725 LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
3727 this.getSession ().save (vnfRecipe);
3729 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
3733 public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
3734 long startTime = System.currentTimeMillis ();
3735 LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
3737 this.getSession ().save (vnfComponentsRecipe);
3739 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
3744 public void saveOrUpdateVnfResource (VnfResource vnfResource) {
3745 long startTime = System.currentTimeMillis ();
3746 LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getModelName());
3747 //LOGGER.debug(vnfResource.toString());
3750 VnfResource existing = this.getVnfResourceByModelUuid(vnfResource.getModelUuid());
3751 if (existing == null) {
3752 LOGGER.debug("No existing entry found - attempting to save...");
3753 this.getSession ().save (vnfResource);
3755 //LOGGER.debug("Existing vnf resource found!" + existing.toString());
3756 LOGGER.debug("Existing vnf resource found!");
3760 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
3764 public boolean saveVnfResourceCustomization (VnfResourceCustomization vnfResourceCustomization) {
3765 long startTime = System.currentTimeMillis ();
3766 LOGGER.debug ("Catalog database - save VNF Resource Customization with Name " + vnfResourceCustomization.getModelInstanceName());
3768 LOGGER.debug(vnfResourceCustomization.toString());
3769 } catch (Exception e) {
3770 LOGGER.debug("Unable to print VRC " + e.getMessage());
3773 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3774 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3775 // Do any matching customization records exist?
3776 // if(networkResourceList.size() == 0){
3778 // networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUuid());
3779 // this.getSession().flush();
3780 // this.getSession().clear();
3782 VnfResourceCustomization existing = this.getVnfResourceCustomizationByModelCustomizationUuid(vnfResourceCustomization.getModelCustomizationUuid());
3784 if (existing == null) {
3785 LOGGER.debug("No existing entry found...attempting to save...");
3786 this.getSession ().save (vnfResourceCustomization);
3790 LOGGER.debug("Existing VRC entry found\n" + existing.toString());
3791 } catch (Exception e) {
3792 LOGGER.debug("Unable to print VRC2 " + e.getMessage());
3798 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceCustomization", null);
3802 public void saveAllottedResourceCustomization (AllottedResourceCustomization resourceCustomization) {
3803 long startTime = System.currentTimeMillis ();
3804 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + resourceCustomization.getModelInstanceName());
3806 List<AllottedResourceCustomization> allottedResourcesList = getAllAllottedResourcesByArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
3808 if(allottedResourcesList.size() == 0){
3809 this.getSession ().save(resourceCustomization);
3813 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3817 public void saveAllottedResource (AllottedResource allottedResource) {
3818 long startTime = System.currentTimeMillis ();
3819 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + allottedResource.getModelName());
3821 AllottedResource existing = this.getAllottedResourceByModelUuid(allottedResource.getModelUuid());
3822 if (existing == null) {
3823 this.getSession ().save (allottedResource);
3825 LOGGER.debug("Found existing allottedResource with this modelUuid - no need to save");
3829 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3833 public void saveNetworkResource (NetworkResource networkResource) throws RecordNotFoundException {
3834 long startTime = System.currentTimeMillis ();
3835 LOGGER.debug ("Catalog database - save Network Resource with Network Name " + networkResource.getModelName());
3837 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3838 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3839 // Do any matching customization records exist?
3840 if(getNetworkResourceByModelUuid(networkResource.getModelUUID()) == null){
3841 this.getSession ().save(networkResource);
3846 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3850 public void saveToscaCsar (ToscaCsar toscaCsar) throws RecordNotFoundException {
3853 long startTime = System.currentTimeMillis ();
3854 LOGGER.debug ("Catalog database - save Tosca Csar with Name " + toscaCsar.getName());
3857 if(getToscaCsar(toscaCsar.getArtifactChecksum()) == null){
3858 this.getSession ().save (toscaCsar);
3860 //if (toscaCsar.getArtifactUUID() != null) {
3861 // this.getSession ().merge (toscaCsar);
3863 // this.getSession ().save (toscaCsar);
3864 LOGGER.debug("Temporarily disabling saveToscaCsar pending further investigation 2017-06-02");
3868 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveToscaCsar", null);
3874 * Return the newest version of a specific Tosca CSAR Record resource (queried by Name).
3877 * @return ToscaCsar object or null if none found
3879 public ToscaCsar getToscaCsar (String artifactChecksum) {
3881 long startTime = System.currentTimeMillis ();
3882 LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactChecksum " + artifactChecksum);
3884 String hql = "FROM ToscaCsar WHERE artifactChecksum = :artifactChecksum";
3885 Query query = getSession ().createQuery (hql);
3886 query.setParameter ("artifactChecksum", artifactChecksum);
3888 @SuppressWarnings("unchecked")
3889 List <ToscaCsar> resultList = query.list ();
3891 // See if something came back. Name is unique, so
3892 if (resultList.isEmpty ()) {
3893 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsar", null);
3896 // Collections.sort (resultList, new MavenLikeVersioningComparator ());
3897 // Collections.reverse (resultList);
3899 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsar", null);
3900 return resultList.get (0);
3904 public void saveTempNetworkHeatTemplateLookup (TempNetworkHeatTemplateLookup tempNetworkHeatTemplateLookup) {
3905 long startTime = System.currentTimeMillis ();
3906 LOGGER.debug ("Catalog database - save TempNetworkHeatTemplateLookup with Network Model Name " + tempNetworkHeatTemplateLookup.getNetworkResourceModelName() +
3907 " and Heat Template Artifact UUID " + tempNetworkHeatTemplateLookup.getHeatTemplateArtifactUuid());
3909 this.getSession ().save (tempNetworkHeatTemplateLookup);
3912 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveTempNetworkHeatTemplateLookup", null);
3916 public void saveVfModuleToHeatFiles (VfModuleToHeatFiles vfModuleToHeatFiles) {
3917 long startTime = System.currentTimeMillis ();
3918 LOGGER.debug ("Catalog database - save VfModuleToHeatFiles with VF Module UUID " + vfModuleToHeatFiles.getVfModuleModelUuid() +
3919 " and Heat Files Artifact UUID " + vfModuleToHeatFiles.getHeatFilesArtifactUuid());
3922 this.getSession ().save (vfModuleToHeatFiles);
3925 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVFModuleToHeatFiles", null);
3929 public void saveVnfResourceToVfModuleCustomization(VnfResourceCustomization vnfResourceCustomizationUUID, VfModuleCustomization vfModuleCustomizationUUID) throws RecordNotFoundException {
3930 long startTime = System.currentTimeMillis ();
3931 VnfResCustomToVfModuleCustom vnfResCustomToVfModuleCustom = new VnfResCustomToVfModuleCustom();
3933 if(vnfResourceCustomizationUUID != null && vfModuleCustomizationUUID != null){
3934 vnfResCustomToVfModuleCustom.setVnfResourceCustModelCustomizationUuid(vnfResourceCustomizationUUID.getModelCustomizationUuid());
3935 vnfResCustomToVfModuleCustom.setVfModuleCustModelCustomizationUuid(vfModuleCustomizationUUID.getModelCustomizationUuid());
3936 String vnfId = vnfResourceCustomizationUUID.getModelCustomizationUuid();
3937 String vfId = vfModuleCustomizationUUID.getModelCustomizationUuid();
3938 LOGGER.debug ("Catalog database - save VnfResCustomToVfModuleCustom with vnf=" + vnfId + ", vf=" + vfId);
3940 VnfResCustomToVfModuleCustom existing = this.getVnfResCustomToVfModule(vnfId, vfId);
3941 if (existing == null) {
3942 LOGGER.debug("No existing entry found - will now try to save");
3943 this.getSession ().save (vnfResCustomToVfModuleCustom);
3945 LOGGER.debug("Existing entry already found - no save needed");
3948 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceToVfModuleCustomization", null);
3953 public void saveNetworkResourceCustomization (NetworkResourceCustomization networkResourceCustomization) throws RecordNotFoundException {
3954 long startTime = System.currentTimeMillis ();
3955 LOGGER.debug ("Catalog database - save Network Resource Customization with Network Name " + networkResourceCustomization.getModelInstanceName());
3957 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3958 List<NetworkResourceCustomization> networkResourceCustomizationList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3959 // Do any matching customization records exist?
3960 if(networkResourceCustomizationList.size() == 0){
3962 // Retreive the record from the Network_Resource table associated to the Customization record based on ModelName
3963 // ?? is it modelInstanceName with 1707?
3964 NetworkResource networkResource = getNetworkResource(networkResourceCustomization.getModelInstanceName());
3966 if(networkResource == null){
3967 throw new RecordNotFoundException("No record found in NETWORK_RESOURCE table for model name " + networkResourceCustomization.getModelInstanceName());
3970 networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUUID());
3972 this.getSession ().save(networkResourceCustomization);
3977 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3981 @Deprecated // table is gone - mapped to ServiceToResource
3982 public void saveServiceToNetworks (ServiceToNetworks serviceToNetworks) {
3983 long startTime = System.currentTimeMillis ();
3984 LOGGER.debug ("Catalog database - save to ServiceToNetworks table with NetworkModelCustomizationUUID of " + serviceToNetworks.getNetworkModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToNetworks.getServiceModelUuid());
3986 this.getSession ().save(serviceToNetworks);
3989 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3993 public void saveServiceToResourceCustomization(ServiceToResourceCustomization serviceToResource) {
3994 long startTime = System.currentTimeMillis ();
3995 LOGGER.debug ("Catalog database - save to ServiceToResourceCustomization table with ServiceModelUuid of " + serviceToResource.getServiceModelUUID() + ", ResourceModelUUID of " + serviceToResource.getResourceModelCustomizationUUID() + " and model_type=" + serviceToResource.getModelType());
3996 ServiceToResourceCustomization strc = this.getServiceToResourceCustomization(serviceToResource.getServiceModelUUID(), serviceToResource.getResourceModelCustomizationUUID(), serviceToResource.getModelType());
3999 LOGGER.debug("**This ServiceToResourceCustomization record already exists - no need to save");
4001 this.getSession ().save(serviceToResource);
4004 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToResourceCustomization", null);
4008 @Deprecated // table is gone - mapped to ServiceToResourceCustomization
4009 public void saveServiceToAllottedResources (ServiceToAllottedResources serviceToAllottedResources) {
4010 long startTime = System.currentTimeMillis ();
4011 LOGGER.debug ("Catalog database - save to serviceToAllottedResources table with ARModelCustomizationUUID of " + serviceToAllottedResources.getArModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToAllottedResources.getServiceModelUuid());
4013 this.getSession ().save(serviceToAllottedResources);
4016 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToAllottedResources", null);
4020 public void saveService (Service service) {
4021 long startTime = System.currentTimeMillis ();
4022 LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getModelName()+"/"+service.getVersion()+"/"+service.getModelUUID());
4024 Service serviceInvariantDB = null;
4025 // Retrieve existing service record by nameVersionId
4026 Service serviceDB = this.getServiceByModelUUID(service.getModelUUID());
4027 if (serviceDB == null) {
4028 // 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.
4029 serviceInvariantDB = this.getServiceByInvariantUUID(service.getModelInvariantUUID());
4030 // Save the new Service record
4031 this.getSession ().save (service);
4034 if(serviceInvariantDB != null){ // existing modelInvariantId was found.
4035 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
4036 List<ServiceRecipe> serviceRecipes = getServiceRecipes(serviceInvariantDB.getModelUUID());
4038 if(serviceRecipes != null && serviceRecipes.size() > 0){
4039 for(ServiceRecipe serviceRecipe : serviceRecipes){
4040 if(serviceRecipe != null){
4041 // 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.
4042 Service newService = this.getServiceByModelUUID(service.getModelUUID());
4043 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
4044 ServiceRecipe newServiceRecipe = new ServiceRecipe();
4045 newServiceRecipe.setAction(serviceRecipe.getAction());
4046 newServiceRecipe.setDescription(serviceRecipe.getDescription());
4047 newServiceRecipe.setOrchestrationUri(serviceRecipe.getOrchestrationUri());
4048 newServiceRecipe.setRecipeTimeout(serviceRecipe.getRecipeTimeout());
4049 newServiceRecipe.setServiceParamXSD(serviceRecipe.getServiceParamXSD());
4050 newServiceRecipe.setServiceModelUUID(newService.getModelUUID());
4051 newServiceRecipe.setVersion(serviceRecipe.getVersion());
4052 // Check recipe does not exist before inserting
4053 ServiceRecipe recipe = getServiceRecipeByModelUUID(newServiceRecipe.getServiceModelUUID(), newServiceRecipe.getAction());
4054 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
4056 this.getSession ().save (newServiceRecipe);
4065 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
4069 public void saveOrUpdateVfModule (VfModule vfModule) {
4070 long startTime = System.currentTimeMillis ();
4071 LOGGER.debug ("Catalog database - save or update VF Module with VF Model Name " + vfModule.getModelName());
4072 VfModule vfModuleInvariantDB = null;
4074 LOGGER.debug("heat template id = " + vfModule.getHeatTemplateArtifactUUId() + ", vol template id = "+ vfModule.getVolHeatTemplateArtifactUUId());
4075 LOGGER.debug(vfModule.toString());
4076 } catch (Exception e) {
4077 LOGGER.debug("unable to print vfmodule " + e.getMessage());
4080 VfModule existing = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4081 if (existing == null) {
4082 // 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.
4083 vfModuleInvariantDB = this.getVfModuleByModelInvariantUuid(vfModule.getModelInvariantUUID());
4084 LOGGER.debug("No existing entry found, attempting to save...");
4085 this.getSession ().save (vfModule);
4088 LOGGER.debug("Found an existing vf module!\n" + existing.toString());
4089 } catch (Exception e) {
4090 LOGGER.debug("unable to print vfmodule2 " + e.getMessage());
4094 if(vfModuleInvariantDB != null){ // existing modelInvariantId was found.
4095 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
4096 List<VnfComponentsRecipe> vfRecipes = getVnfComponentRecipes(vfModuleInvariantDB.getModelUUID());
4099 if(vfRecipes != null && vfRecipes.size() > 0){
4100 for(VnfComponentsRecipe vfRecipe : vfRecipes){
4101 if(vfRecipe != null){
4102 // 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.
4103 VfModule newRecipe = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4104 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
4105 VnfComponentsRecipe newVnfRecipe = new VnfComponentsRecipe();
4106 newVnfRecipe.setAction(vfRecipe.getAction());
4107 newVnfRecipe.setDescription(vfRecipe.getDescription());
4108 newVnfRecipe.setOrchestrationUri(vfRecipe.getOrchestrationUri());
4109 newVnfRecipe.setRecipeTimeout(vfRecipe.getRecipeTimeout());
4110 newVnfRecipe.setVnfComponentParamXSD(vfRecipe.getVnfComponentParamXSD());
4111 newVnfRecipe.setVfModuleModelUUId(newRecipe.getModelUUID());
4112 newVnfRecipe.setVersion(vfRecipe.getVersion());
4113 newVnfRecipe.setVnfComponentType(vfRecipe.getVnfComponentType());
4114 newVnfRecipe.setVnfType(vfRecipe.getVnfType());
4115 // Check recipe does not exist before inserting
4116 // VnfComponentsRecipe recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4117 List<VnfComponentsRecipe> recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4118 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
4119 // if(recipe == null){
4120 this.getSession ().save (newVnfRecipe);
4129 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
4133 public void saveOrUpdateVfModuleCustomization (VfModuleCustomization vfModuleCustomization) {
4134 long startTime = System.currentTimeMillis ();
4135 LOGGER.debug ("Catalog database - save VF Module Customization with VF Customization Model Name UUID " + vfModuleCustomization.getVfModuleModelUuid());
4137 LOGGER.debug("env id = " + vfModuleCustomization.getHeatEnvironmentArtifactUuid() + ", vol Env=" + vfModuleCustomization.getVolEnvironmentArtifactUuid());
4138 LOGGER.debug(vfModuleCustomization.toString());
4139 } catch (Exception e) {
4140 LOGGER.debug("unable to print vfmodulecust " + e.getMessage());
4143 VfModuleCustomization existing = this.getVfModuleCustomizationByModelCustomizationId(vfModuleCustomization.getModelCustomizationUuid());
4144 if (existing == null) {
4145 LOGGER.debug("No existing entry found, attempting to save...");
4146 this.getSession ().save (vfModuleCustomization);
4149 LOGGER.debug("Found an existing vf module customization entry\n" + existing.toString());
4150 } catch (Exception e) {
4151 LOGGER.debug("unable to print vfmodulecust2 " + e.getMessage());
4156 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModuleCustomization", null);
4161 public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
4162 long startTime = System.currentTimeMillis ();
4163 LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
4164 + parentTemplateId +"-"+childTemplateId);
4166 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4167 // nestedTemplate.setParentTemplateId (parentTemplateId);
4168 // nestedTemplate.setChildTemplateId (childTemplateId);
4170 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
4172 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
4177 public HeatNestedTemplate getNestedHeatTemplate(String parentTemplateId, String childTemplateId) {
4178 long startTime = System.currentTimeMillis ();
4179 LOGGER.debug ("Catalog database - get nested Heat template with PerentId="
4180 + parentTemplateId +", ChildId="+childTemplateId);
4182 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4183 nestedTemplate.setParentTemplateId (parentTemplateId);
4184 nestedTemplate.setChildTemplateId (childTemplateId);
4186 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
4188 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
4193 public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4195 long startTime = System.currentTimeMillis ();
4196 LOGGER.debug ("Catalog database - save nested Heat template with name "
4197 + childTemplate.getTemplateName ());
4200 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4201 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
4202 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4203 nestedTemplate.setParentTemplateId (parentTemplateId);
4204 nestedTemplate.setChildTemplateId (childTemplate.getId ());
4205 nestedTemplate.setProviderResourceFile (yamlFile);
4206 session.save (nestedTemplate);
4209 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4215 public void saveNestedHeatTemplate (String parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4216 long startTime = System.currentTimeMillis ();
4217 LOGGER.debug ("Catalog database - save nested Heat template with name "
4218 + childTemplate.getTemplateName () + ",parentId=" + parentTemplateId + ",childId=" + childTemplate.getArtifactUuid() + ", providerResourceFile=" + yamlFile);
4221 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4222 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getArtifactUuid()) == null) {
4223 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4224 nestedTemplate.setParentTemplateId (parentTemplateId);
4225 nestedTemplate.setChildTemplateId (childTemplate.getArtifactUuid ());
4226 nestedTemplate.setProviderResourceFile (yamlFile);
4228 session.save (nestedTemplate);
4231 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4236 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
4237 long startTime = System.currentTimeMillis ();
4238 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
4239 + " and vnfResourceID "
4241 // + " and ASDC resource name "
4246 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
4247 Query query = getSession ().createQuery (hql);
4248 query.setParameter ("fileName", fileName);
4249 query.setParameter ("vnfResourceId", vnfResourceId);
4250 query.setParameter ("asdcResourceName", asdcResourceName);
4251 query.setParameter ("version", version);
4253 @SuppressWarnings("unchecked")
4255 HeatFiles heatFilesResult = null;
4257 heatFilesResult = (HeatFiles) query.uniqueResult ();
4258 } catch (org.hibernate.NonUniqueResultException nure) {
4259 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);
4260 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);
4261 heatFilesResult = null;
4263 } catch (org.hibernate.HibernateException he) {
4264 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + he.getMessage());
4265 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);
4266 heatFilesResult = null;
4268 } catch (Exception e) {
4269 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + e.getMessage());
4270 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);
4271 heatFilesResult = null;
4275 // See if something came back.
4276 if (heatFilesResult == null) {
4277 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4280 // Name + Version is unique, so should only be one element
4281 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4282 return heatFilesResult;
4285 public HeatFiles getHeatFiles(String artifactUuid) {
4286 long startTime = System.currentTimeMillis ();
4287 LOGGER.debug ("Catalog database - getHeatFiles with artifactUuid " + artifactUuid);
4289 String hql = "FROM HeatFiles WHERE artifactUuid = :artifactUuid";
4290 Query query = getSession ().createQuery (hql);
4291 query.setParameter ("artifactUuid", artifactUuid);
4293 @SuppressWarnings("unchecked")
4295 HeatFiles heatFilesResult = null;
4297 heatFilesResult = (HeatFiles) query.uniqueResult ();
4298 } catch (org.hibernate.NonUniqueResultException nure) {
4299 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: artifactUuid='" + artifactUuid );
4300 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid=" + artifactUuid);
4301 heatFilesResult = null;
4303 } catch (org.hibernate.HibernateException he) {
4304 LOGGER.debug("Hibernate Exception - while searching for: artifactUuid='" + artifactUuid + " " + he.getMessage());
4305 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + artifactUuid);
4306 heatFilesResult = null;
4308 } catch (Exception e) {
4309 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + " " + e.getMessage());
4310 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUuid=" + artifactUuid , "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + artifactUuid);
4311 heatFilesResult = null;
4315 // See if something came back.
4316 if (heatFilesResult == null) {
4317 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4320 // Name + Version is unique, so should only be one element
4321 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4322 return heatFilesResult;
4325 public void saveHeatFiles (HeatFiles childFile) {
4326 long startTime = System.currentTimeMillis ();
4327 LOGGER.debug ("Catalog database - save Heat File with name "
4328 + childFile.getFileName());
4330 // HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
4331 HeatFiles heatFiles = getHeatFiles (childFile.getArtifactUuid());
4332 if (heatFiles == null) {
4334 // asdc_heat_files_save
4335 this.getSession ().save (childFile);
4338 /* replaced 'heatFiles' by 'childFile'
4339 Based on following comment:
4340 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
4342 childFile.setArtifactUuid(heatFiles.getArtifactUuid());
4346 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
4351 public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
4353 long startTime = System.currentTimeMillis ();
4354 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4355 + childFile.getFileName());
4357 saveHeatFiles (childFile);
4358 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4359 vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
4360 vfModuleToHeatFile.setHeatFilesId(childFile.getId());
4362 session.save (vfModuleToHeatFile);
4365 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4370 public void saveVfModuleToHeatFiles (String parentVfModuleId, HeatFiles childFile) {
4371 long startTime = System.currentTimeMillis ();
4372 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4373 + childFile.getFileName());
4375 saveHeatFiles (childFile);
4376 VfModuleToHeatFiles checkExistingEntry = this.getVfModuleToHeatFilesEntry(parentVfModuleId, childFile.getArtifactUuid());
4377 if (checkExistingEntry == null) {
4378 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4379 vfModuleToHeatFile.setVfModuleModelUuid(parentVfModuleId);
4380 vfModuleToHeatFile.setHeatFilesArtifactUuid(childFile.getArtifactUuid());
4382 session.save (vfModuleToHeatFile);
4384 LOGGER.debug("**Found existing VfModuleToHeatFiles entry for " + checkExistingEntry.toString());
4385 LOGGER.debug("No need to save...");
4389 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4394 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4396 * @param networkType
4398 * @param serviceType
4399 * @return NetworkRecipe object or null if none found
4401 public NetworkResource getNetworkResourceByModelUuid(String modelUUID) {
4403 long startTime = System.currentTimeMillis ();
4404 LOGGER.debug ("Catalog database - get network resource with modelUUID " + modelUUID);
4407 String hql = "FROM NetworkResource WHERE modelUUID=:modelUUID";
4408 Query query = getSession ().createQuery (hql);
4409 query.setParameter (MODEL_UUID, modelUUID);
4411 @SuppressWarnings("unchecked")
4412 List <NetworkResource> resultList = query.list ();
4414 if (resultList.isEmpty ()) {
4418 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4419 Collections.reverse (resultList);
4421 return resultList.get (0);
4422 } catch (Exception e) {
4423 LOGGER.debug("Error trying to find Network Resource with " + modelUUID +", " + e.getMessage());
4425 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelUuid", null);
4432 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
4434 * @param networkType
4436 * @param serviceType
4437 * @return NetworkRecipe object or null if none found
4439 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
4441 long startTime = System.currentTimeMillis ();
4442 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
4445 + " and service type "
4450 if (serviceType == null) {
4451 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
4453 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
4455 Query query = getSession ().createQuery (hql);
4456 query.setParameter (NETWORK_TYPE, networkType);
4457 query.setParameter (ACTION, action);
4458 if (serviceType != null) {
4459 query.setParameter ("serviceType", serviceType);
4462 @SuppressWarnings("unchecked")
4463 List <NetworkRecipe> resultList = query.list ();
4465 if (resultList.isEmpty ()) {
4469 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4470 Collections.reverse (resultList);
4472 return resultList.get (0);
4474 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4480 * Return a Network recipe that matches a given MODEL_NAME and ACTION
4484 * @return NetworkRecipe object or null if none found
4486 public NetworkRecipe getNetworkRecipe (String modelName, String action) {
4488 long startTime = System.currentTimeMillis ();
4489 LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
4495 String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND action = :action";
4497 Query query = getSession ().createQuery (hql);
4498 query.setParameter (MODEL_NAME, modelName);
4499 query.setParameter (ACTION, action);
4501 @SuppressWarnings("unchecked")
4502 List <NetworkRecipe> resultList = query.list ();
4504 if (resultList.isEmpty ()) {
4508 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4509 Collections.reverse (resultList);
4511 return resultList.get (0);
4513 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4518 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4520 * @param networkType
4522 * @param serviceType
4523 * @return NetworkRecipe object or null if none found
4525 public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
4527 long startTime = System.currentTimeMillis ();
4528 LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
4531 String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.modelUUID=c.networkResourceModelUuid and c.modelCustomizationUuid = :modelCustomizationUuid";
4532 Query query = getSession ().createQuery (hql);
4533 query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
4535 @SuppressWarnings("unchecked")
4536 List <NetworkResource> resultList = query.list ();
4538 if (resultList.isEmpty ()) {
4542 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4543 Collections.reverse (resultList);
4545 return resultList.get (0);
4546 } catch (Exception e) {
4547 LOGGER.debug("Error trying to find Network Resource with " + modelCustomizationUuid +", " + e.getMessage());
4549 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelCustUuid", null);
4555 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
4559 * @param vnfComponentType
4561 * @param serviceType
4562 * @return VnfComponentsRecipe object or null if none found
4564 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
4565 String vnfComponentType,
4567 String serviceType) {
4569 long startTime = System.currentTimeMillis ();
4570 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
4571 + " and component type "
4575 + " and service type "
4580 if (serviceType == null) {
4581 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
4583 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
4585 Query query = getSession ().createQuery (hql);
4586 query.setParameter (VNF_TYPE, vnfType);
4587 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4588 query.setParameter (ACTION, action);
4589 if (serviceType != null) {
4590 query.setParameter ("serviceType", serviceType);
4593 @SuppressWarnings("unchecked")
4594 List <VnfComponentsRecipe> resultList = query.list ();
4596 if (resultList.isEmpty ()) {
4599 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4600 Collections.reverse (resultList);
4602 return resultList.get (0);
4604 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
4609 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
4612 * @param vnfComponentType
4614 * @return VnfComponentsRecipe object or null if none found
4616 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleModelUUId (String vfModuleModelUUId,
4617 String vnfComponentType,
4620 long startTime = System.currentTimeMillis ();
4621 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleModelUUId " + vfModuleModelUUId
4622 + " and component type "
4629 hql = "FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId AND vnfComponentType = :vnfComponentType AND action = :action ";
4631 Query query = getSession ().createQuery (hql);
4632 query.setParameter (VF_MODULE_MODEL_UUID, vfModuleModelUUId);
4633 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4634 query.setParameter (ACTION, action);
4636 @SuppressWarnings("unchecked")
4637 List <VnfComponentsRecipe> resultList = query.list ();
4639 if (resultList.isEmpty ()) {
4642 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4643 Collections.reverse (resultList);
4645 return resultList.get (0);
4647 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleModelUUId", null);
4651 public List<VnfComponentsRecipe> getVnfComponentRecipes (String vfModuleModelUUId) {
4653 StringBuilder hql = null;
4655 hql = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId");
4657 long startTime = System.currentTimeMillis ();
4658 LOGGER.debug ("Catalog database - get Service recipe with vfModuleModelUUId " + vfModuleModelUUId);
4660 Query query = getSession ().createQuery (hql.toString ());
4661 query.setParameter ("vfModuleModelUUId", vfModuleModelUUId);
4663 @SuppressWarnings("unchecked")
4664 List <VnfComponentsRecipe> resultList = query.list ();
4666 if (resultList.isEmpty ()) {
4667 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getVfModuleRecipes", null);
4671 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4672 Collections.reverse (resultList);
4674 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleRecipes", null);
4680 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
4681 long startTime = System.currentTimeMillis ();
4683 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
4685 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
4689 //if (vnfComponentDb != null) {
4690 // this.getSession ().merge (vnfComponent);
4692 this.getSession ().save (vnfComponent);
4696 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
4701 * Return a VfModule record that matches a given MODEL_NAME
4704 * @return VfModule object or null if none found
4706 public VfModule getVfModule (String modelName) {
4708 long startTime = System.currentTimeMillis ();
4709 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
4714 hql = "FROM VfModule WHERE modelName = :modelName";
4716 Query query = getSession ().createQuery (hql);
4717 query.setParameter (MODEL_NAME, modelName);
4719 @SuppressWarnings("unchecked")
4720 List <VfModule> resultList = query.list ();
4722 if (resultList.isEmpty ()) {
4725 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4726 Collections.reverse (resultList);
4728 return resultList.get (0);
4730 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
4735 * Return a VfModule record that matches a given MODEL_NAME
4738 * @return VfModule object or null if none found
4740 public VfModule getVfModuleByModelUUID (String modelUUID) {
4742 long startTime = System.currentTimeMillis ();
4743 LOGGER.debug ("Catalog database - get vf module with modelUUID " + modelUUID);
4748 hql = "FROM VfModule WHERE modelUUID = :modelUUID";
4750 Query query = getSession ().createQuery (hql);
4751 query.setParameter (MODEL_UUID, modelUUID);
4753 @SuppressWarnings("unchecked")
4754 List <VfModule> resultList = query.list ();
4756 if (resultList.isEmpty ()) {
4759 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4760 Collections.reverse (resultList);
4762 return resultList.get (0);
4764 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUUID", null);
4769 * Return a Service recipe that matches a given service ModelUUID and action
4770 * (modelUUID) and ACTION
4774 * @return ServiceRecipe object or null if none found
4776 public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
4778 long startTime = System.currentTimeMillis();
4779 LOGGER.debug("Catalog database - get Service recipe with modelUUID=" + modelUUID + " and action=" + action);
4783 // based on the new SERVICE_RECIPE schema where SERVICE_MODEL_UUID == MODEL_UUID, a JOIN with the SERVICE table is no longer needed
4784 // hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4785 // "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4786 // "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4787 // "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4788 // "WHERE SR.serviceModelUUID = :modelUUID AND SR.action = :action";
4789 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :modelUUID AND action = :action";
4790 Query query = getSession().createQuery(hql);
4791 query.setParameter(MODEL_UUID, modelUUID);
4792 query.setParameter(ACTION, action);
4794 @SuppressWarnings("unchecked")
4795 List<ServiceRecipe> recipeResultList = query.list();
4796 if (recipeResultList.isEmpty()) {
4797 LOGGER.debug("Catalog database - recipeResultList is null");
4800 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4801 Collections.reverse(recipeResultList);
4802 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4804 return recipeResultList.get(0);
4806 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipeByModelUUID", null);
4811 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
4812 * (MODEL_VERSION_ID) and ACTION
4814 * @param modelVersionId
4816 * @return ServiceRecipe object or null if none found
4819 public ServiceRecipe getServiceRecipe(String modelVersionId,
4822 long startTime = System.currentTimeMillis();
4823 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
4824 + " and action=" + action);
4828 // Note: Even with the implementation of the HQL JOIN below, the code for the two separate
4829 // SELECTs will be retained/commented for now in the event some subsequent JOIN issue arises
4830 // 1st query to get the Service record for the given SERVICE_NAME_VERSION_ID (MODEL_VERSION_ID)
4831 /* hql = "FROM Service WHERE serviceNameVersionId = :serviceNameVersionId";
4832 Query query = getSession().createQuery(hql);
4833 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
4835 @SuppressWarnings("unchecked")
4836 List<Service> serviceResultList = query.list();
4837 if (serviceResultList.isEmpty()) {
4838 LOGGER.debug("Catalog database - serviceResultList is null");
4841 Collections.sort(serviceResultList, new MavenLikeVersioningComparator());
4842 Collections.reverse(serviceResultList);
4843 LOGGER.debug("Catalog database - serviceResultList contains " + serviceResultList.get(0).toString());
4845 // 2nd query to get the ServiceRecipe record corresponding to the Service from the 1st query
4846 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action";
4847 query = getSession().createQuery(hql);
4848 // The SERVICE table 'id' field maps to the SERVICE_RECIPE table 'SERVICE_ID' field
4849 query.setParameter(SERVICE_ID, serviceResultList.get(0).getId());
4850 query.setParameter(ACTION, action);
4852 // The following SELECT performs a JOIN across the SERVICE and SERVICE_RECIPE tables. It required a new
4853 // CTR in the ServiceRecipe Class to populate that object (the other option was to parse the Object[]
4854 // returned by createQuery() and manually populate the ServiceRecipe object). Two of the 'int' fields in the
4855 // SERVICE_RECIPE DB schema (the timeouts) permit NULL values which required some additional code in the
4856 // SELECT to generate a default of 0 (needed by the CTR) in the cases where the value is NULL.
4857 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4858 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4859 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4860 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4861 "WHERE SR.serviceModelUUID = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
4862 Query query = getSession().createQuery(hql);
4863 query.setParameter(MODEL_UUID, modelVersionId);
4864 query.setParameter(ACTION, action);
4866 @SuppressWarnings("unchecked")
4867 List<ServiceRecipe> recipeResultList = query.list();
4868 if (recipeResultList.isEmpty()) {
4869 LOGGER.debug("Catalog database - recipeResultList is null");
4872 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4873 Collections.reverse(recipeResultList);
4874 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4876 return recipeResultList.get(0);
4878 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
4883 * Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
4884 * Note: This method is not currently used but was retained in the event the
4885 * architecture moves back to a MODEL/MODEL_RECIPE structure.
4888 * @param modelVersionId
4890 * @return ModelRecipe object or null if none found
4892 public ModelRecipe getModelRecipe(String modelType,
4893 String modelVersionId,
4896 long startTime = System.currentTimeMillis();
4897 LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
4898 + " and modeVersionId=" + modelVersionId
4899 + " and action=" + action);
4903 // TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
4904 // the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
4905 // There seems to be 2 issues: formatting a hql query that executes successfully
4906 // and then being able to generate a result that will fit into the ModelRecipe class.
4908 // 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
4909 hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
4910 Query query = getSession().createQuery(hql);
4911 query.setParameter(MODEL_TYPE, modelType);
4912 query.setParameter(MODEL_VERSION_ID, modelVersionId);
4914 @SuppressWarnings("unchecked")
4915 List<Model> modelResultList = query.list();
4916 if (modelResultList.isEmpty()) {
4917 LOGGER.debug("Catalog database - modelResultList is null");
4920 Collections.sort(modelResultList, new MavenLikeVersioningComparator());
4921 Collections.reverse(modelResultList);
4922 LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
4924 // 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
4925 hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
4926 query = getSession().createQuery(hql);
4927 // The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
4928 query.setParameter(MODEL_ID, modelResultList.get(0).getId());
4929 query.setParameter(ACTION, action);
4931 @SuppressWarnings("unchecked")
4932 List<ModelRecipe> recipeResultList = query.list();
4933 if (recipeResultList.isEmpty()) {
4934 LOGGER.debug("Catalog database - recipeResultList is null");
4937 Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
4938 Collections.reverse(recipeResultList);
4939 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4941 return recipeResultList.get(0);
4943 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
4949 * Verify the health of the DB.
4951 * @return boolean value indicate whether DB is healthy
4953 public boolean healthCheck () {
4954 long startTime = System.currentTimeMillis ();
4955 Session session = this.getSession ();
4957 // Query query = session.createQuery (" from ActiveRequests ");
4958 Query query = session.createSQLQuery (" show tables ");
4960 List<?> list = query.list();
4961 LOGGER.debug("healthCheck CatalogDB - Successful");
4965 public < E > E executeQuerySingleRow(String hql, HashMap<String, String> variables, boolean retry) {
4966 long startTime = System.currentTimeMillis ();
4967 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
4968 Query query = getSession().createQuery(hql);
4970 StringBuffer sb = new StringBuffer();
4971 if (variables != null) {
4972 for (String key : variables.keySet()) {
4973 sb.append(key + "=" + variables.get(key) + "\n");
4974 query.setParameter(key, variables.get(key));
4977 LOGGER.debug("Variables:\n" + sb.toString());
4981 theObject = (E) query.uniqueResult ();
4982 } catch (org.hibernate.NonUniqueResultException nure) {
4983 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row");
4984 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for " + hql, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for " + hql );
4987 } catch (org.hibernate.HibernateException he) {
4988 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
4989 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
4992 LOGGER.debug("***WILL RETRY***");
4993 return this.executeQuerySingleRow(hql, variables, false);
4997 } catch (Exception e) {
4998 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
4999 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
5002 LOGGER.debug("***WILL RETRY***");
5003 return this.executeQuerySingleRow(hql, variables, false);
5009 if (theObject == null) {
5010 LOGGER.debug("Returning null");
5011 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
5013 LOGGER.debug("Returning an Object");
5014 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
5019 public < E > List<E> executeQueryMultipleRows(String hql, HashMap<String, String> variables, boolean retry) {
5020 long startTime = System.currentTimeMillis ();
5021 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
5022 Query query = getSession().createQuery(hql);
5024 StringBuffer sb = new StringBuffer();
5025 if (variables != null) {
5026 for (String key : variables.keySet()) {
5027 sb.append(key + "=" + variables.get(key) + "\n");
5028 query.setParameter(key, variables.get(key));
5031 LOGGER.debug("Variables:\n" + sb.toString());
5033 List<E> theObjects = null;
5035 theObjects = (List<E>) query.list ();
5036 } catch (org.hibernate.HibernateException he) {
5037 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
5038 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
5041 LOGGER.debug("***WILL RETRY***");
5042 return this.executeQuerySingleRow(hql, variables, false);
5046 } catch (Exception e) {
5047 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
5048 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
5051 LOGGER.debug("***WILL RETRY***");
5052 return this.executeQuerySingleRow(hql, variables, false);
5058 if (theObjects == null) {
5059 LOGGER.debug("Returning null");
5060 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
5063 LOGGER.debug("Returning theObjects:" + theObjects.size());
5064 } catch (Exception e) {
5065 LOGGER.debug("Returning theObjects");
5067 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);