2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.mso.db.catalog;
24 import java.io.Closeable;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.List;
33 import org.hibernate.HibernateException;
34 import org.hibernate.Query;
35 import org.hibernate.Session;
36 import org.openecomp.mso.db.AbstractSessionFactoryManager;
37 import org.openecomp.mso.db.catalog.beans.AllottedResource;
38 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
39 import org.openecomp.mso.db.catalog.beans.ArRecipe;
40 import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
41 import org.openecomp.mso.db.catalog.beans.HeatFiles;
42 import org.openecomp.mso.db.catalog.beans.HeatNestedTemplate;
43 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
44 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
45 import org.openecomp.mso.db.catalog.beans.Model;
46 import org.openecomp.mso.db.catalog.beans.ModelRecipe;
47 import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
48 import org.openecomp.mso.db.catalog.beans.NetworkResource;
49 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
50 import org.openecomp.mso.db.catalog.beans.Service;
51 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
52 import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
53 import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
54 import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
55 import org.openecomp.mso.db.catalog.beans.ServiceToResourceCustomization;
56 import org.openecomp.mso.db.catalog.beans.TempNetworkHeatTemplateLookup;
57 import org.openecomp.mso.db.catalog.beans.ToscaCsar;
58 import org.openecomp.mso.db.catalog.beans.VfModule;
59 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
60 import org.openecomp.mso.db.catalog.beans.VfModuleToHeatFiles;
61 import org.openecomp.mso.db.catalog.beans.VnfComponent;
62 import org.openecomp.mso.db.catalog.beans.VnfComponentsRecipe;
63 import org.openecomp.mso.db.catalog.beans.VnfRecipe;
64 import org.openecomp.mso.db.catalog.beans.VnfResCustomToVfModuleCustom;
65 import org.openecomp.mso.db.catalog.beans.VnfResource;
66 import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
67 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
68 import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
69 import org.openecomp.mso.logger.MessageEnum;
70 import org.openecomp.mso.logger.MsoLogger;
73 * This class encapsulates all of the objects that can be queried from a Catalog database.
74 * Clients must use these methods to retrieve catalog objects. The session is not
75 * available for clients to do their own direct queries to the database.
79 public class CatalogDatabase implements Closeable {
81 protected final AbstractSessionFactoryManager sessionFactoryCatalogDB;
83 private static final String NETWORK_TYPE = "networkType";
84 private static final String ACTION = "action";
85 private static final String VNF_TYPE = "vnfType";
86 private static final String SERVICE_TYPE = "serviceType";
87 private static final String MODEL_UUID= "modelUUID";
88 private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
89 private static final String MODEL_ID = "modelId";
90 private static final String MODEL_NAME = "modelName";
91 private static final String MODEL_VERSION = "version";
92 private static final String TYPE = "type";
93 private static final String MODEL_TYPE = "modelType";
94 private static final String MODEL_VERSION_ID = "modelVersionId";
95 private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
96 private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId";
98 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
100 protected Session session = null;
102 protected CatalogDatabase (AbstractSessionFactoryManager sessionFactoryCatalog) {
103 sessionFactoryCatalogDB = sessionFactoryCatalog;
106 public static CatalogDatabase getInstance() {
107 return new CatalogDatabase(new CatalogDbSessionFactoryManager ());
110 private Session getSession () {
112 if (session == null) {
114 session = sessionFactoryCatalogDB.getSessionFactory ().openSession ();
115 session.beginTransaction ();
116 } catch (HibernateException he) {
117 LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Error creating Hibernate Session: " + he, "", "", MsoLogger.ErrorCode.DataError, "Error creating Hibernate Session: " + he);
126 * Close an open Catalog Database session.
127 * This method should always be called when a client is finished using a
128 * CatalogDatabase instance.
131 public void close () {
132 if (session != null) {
139 * Commits the current transaction on this session and starts a fresh one.
141 public void commit () {
142 getSession ().getTransaction ().commit ();
143 getSession ().beginTransaction ();
147 * Rolls back current transaction and starts a fresh one.
149 public void rollback () {
150 getSession ().getTransaction ().rollback ();
151 getSession ().beginTransaction ();
155 * Return all Heat Templates in the Catalog DB
157 * @return A list of HeatTemplate objects
159 @SuppressWarnings("unchecked")
160 public List <HeatTemplate> getAllHeatTemplates() {
161 long startTime = System.currentTimeMillis();
162 LOGGER.debug("Catalog database - get all Heat templates");
163 String hql = "FROM HeatTemplate";
164 Query query = getSession().createQuery(hql);
166 List <HeatTemplate> result = query.list();
167 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatTemplates", null);
172 * Fetch a specific Heat Template by ID.
174 * @param templateId template id
175 * @return HeatTemplate object or null if none found
178 public HeatTemplate getHeatTemplate(int templateId) {
179 long startTime = System.currentTimeMillis();
180 LOGGER.debug ("Catalog database - get Heat template with id " + templateId);
182 HeatTemplate template = (HeatTemplate) getSession().get(HeatTemplate.class, templateId);
183 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
188 * Return the newest version of a specific Heat Template (queried by Name).
190 * @param templateName template name
191 * @return HeatTemplate object or null if none found
193 public HeatTemplate getHeatTemplate(String templateName) {
195 long startTime = System.currentTimeMillis();
196 LOGGER.debug("Catalog database - get Heat template with name " + templateName);
198 String hql = "FROM HeatTemplate WHERE templateName = :template_name";
199 Query query = getSession().createQuery (hql);
200 query.setParameter("template_name", templateName);
202 @SuppressWarnings("unchecked")
203 List <HeatTemplate> resultList = query.list();
205 // See if something came back. Name is unique, so
206 if (resultList.isEmpty ()) {
207 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null);
210 resultList.sort(new MavenLikeVersioningComparator());
211 Collections.reverse(resultList);
213 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
214 return resultList.get(0);
218 * Return a specific version of a specific Heat Template (queried by Name).
220 * @param templateName
222 * @return HeatTemplate object or null if none found
224 public HeatTemplate getHeatTemplate(String templateName, String version) {
226 long startTime = System.currentTimeMillis();
227 LOGGER.debug("Catalog database - get Heat template with name " + templateName
231 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version";
232 Query query = getSession().createQuery(hql);
233 query.setParameter("template_name", templateName);
234 query.setParameter("version", version);
236 @SuppressWarnings("unchecked")
237 List <HeatTemplate> resultList = query.list();
239 // See if something came back.
240 if (resultList.isEmpty()) {
241 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found.", "CatalogDB", "getHeatTemplate", null);
244 // Name + Version is unique, so should only be one element
245 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
246 return resultList.get(0);
250 * Return a specific Heat Template by ARTIFACT_UUID).
252 * @param artifactUuid
253 * @return HeatTemplate object or null if none found
256 public HeatTemplate getHeatTemplateByArtifactUuid(String artifactUuid) {
257 long startTime = System.currentTimeMillis ();
258 LOGGER.debug ("Catalog database - get Heat template with artifactUuid " + artifactUuid);
260 // Will this work if the id is a string?
261 HeatTemplate template = (HeatTemplate) getSession ().get (HeatTemplate.class, artifactUuid);
262 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
267 * Return a specific Heat Template by ARTIFACT_UUID using standard query method. unique record expected.
269 * @param artifactUuid
270 * @return HeatTemplate object or null if none found
272 public HeatTemplate getHeatTemplateByArtifactUuidRegularQuery(String artifactUuid) {
273 long startTime = System.currentTimeMillis();
274 LOGGER.debug("Catalog database - get Heat template (regular query) with artifactUuid " + artifactUuid);
276 String hql = "FROM HeatTemplate WHERE artifactUuid = :artifactUuidValue";
277 HashMap<String, String> variables = new HashMap<>();
278 variables.put("artifactUuidValue", artifactUuid);
279 HeatTemplate template = (HeatTemplate) this.executeQuerySingleRow(hql, 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 LOGGER.debug ("Catalog database - getParametersForHeatTemplate with artifactUuid " + heatTemplateArtifactUuid);
292 String hql = "FROM HeatTemplateParams WHERE artifactUuid = :artifactUuidValue";
293 Query query = getSession().createQuery(hql);
294 query.setParameter ("artifactUuidValue", heatTemplateArtifactUuid);
295 List<HeatTemplateParam> resultList = new ArrayList<>();
297 resultList = query.list ();
298 } catch (org.hibernate.HibernateException he) {
299 LOGGER.debug("Hibernate Exception - while searching HeatTemplateParams for: heatTemplateArtifactUuid='" + heatTemplateArtifactUuid + "'" + he.getMessage());
300 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching HeatTemplateParams for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + heatTemplateArtifactUuid);
302 } catch (Exception e) {
303 LOGGER.debug("Generic Exception - while searching HeatTemplateParam for: artifactUuid='" + heatTemplateArtifactUuid + "'" + e.getMessage());
304 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching HeatTemplate for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + heatTemplateArtifactUuid);
313 * Return a specific Heat Environment by ARTIFACT_UUID using standard query method. unique record expected.
315 * @param artifactUuid
316 * @return HeatEnvironment object or null if none found
318 public HeatEnvironment getHeatEnvironmentByArtifactUuid(String artifactUuid) {
319 long startTime = System.currentTimeMillis();
320 LOGGER.debug("Catalog database - get Heat Environment with artifactUuid " + artifactUuid);
322 String hql = "FROM HeatEnvironment WHERE artifactUuid = :artifactUuidValue";
323 Query query = getSession().createQuery(hql);
324 query.setParameter("artifactUuidValue", artifactUuid);
325 HeatEnvironment environment = null;
327 environment = (HeatEnvironment) query.uniqueResult();
328 } catch (org.hibernate.NonUniqueResultException nure) {
329 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row for Envt - data integrity error: artifactUuid='" + artifactUuid +"'", nure);
330 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for heatEnvironment artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid==" + artifactUuid);
331 } catch (org.hibernate.HibernateException he) {
332 LOGGER.debug("Hibernate Exception - while searching for envt: artifactUuid='" + artifactUuid + "' " + he.getMessage());
333 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching envt for artifactUuid=" + artifactUuid);
336 } catch (Exception e) {
337 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + "' " + e.getMessage());
338 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching envt for artifactUuid=" + artifactUuid);
343 if (environment == null) {
344 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
346 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
352 * Fetch a Service definition by InvariantUUID
354 public Service getServiceByInvariantUUID (String modelInvariantUUID) {
356 long startTime = System.currentTimeMillis();
357 LOGGER.debug("Catalog database - get service with Invariant UUID " + modelInvariantUUID);
359 String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid";
360 Query query = getSession().createQuery(hql);
361 query.setParameter ("model_invariant_uuid", modelInvariantUUID);
363 @SuppressWarnings("unchecked")
364 List <Service> resultList = query.list ();
366 // See if something came back.
367 if (resultList.isEmpty ()) {
368 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
371 resultList.sort(new MavenLikeVersioningComparator());
372 Collections.reverse (resultList);
374 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
375 return resultList.get (0);
379 * Fetch a Service definition
381 public Service getService (String modelName) {
383 long startTime = System.currentTimeMillis();
384 LOGGER.debug("Catalog database - get service with name " + modelName);
386 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
387 Query query = getSession().createQuery(hql);
388 query.setParameter("MODEL_NAME", modelName);
390 Service service = null;
392 service = (Service) query.uniqueResult();
393 } catch (org.hibernate.NonUniqueResultException nure) {
394 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelName='" + modelName + "'");
395 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelName=" + modelName);
397 } catch (org.hibernate.HibernateException he) {
398 LOGGER.debug("Hibernate Exception - while searching for: modelName='" + modelName + "' " + he.getMessage());
399 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelName=" + modelName);
401 } catch (Exception e) {
402 LOGGER.debug("Generic Exception - while searching for: modelName='" + modelName + " " + e.getMessage());
403 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelName=" + modelName);
406 if (service == null) {
407 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
409 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
415 public Service getServiceByModelUUID (String modelUUID) {
417 long startTime = System.currentTimeMillis();
418 LOGGER.debug("Catalog database - get service with Model UUID " + modelUUID);
420 String hql = "FROM Service WHERE modelUUID = :MODEL_UUID";
421 HashMap<String, String> parameters = new HashMap<>();
422 parameters.put("MODEL_UUID", modelUUID);
425 Service service = this.executeQuerySingleRow(hql, parameters, true);
429 service = (Service) query.uniqueResult ();
430 } catch (org.hibernate.NonUniqueResultException nure) {
431 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelUUID='" + modelUUID + "'");
432 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelUUID=" + modelUUID);
434 } catch (org.hibernate.HibernateException he) {
435 LOGGER.debug("Hibernate Exception - while searching for: modelUUID='" + modelUUID + "' " + he.getMessage());
436 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUUID=" + modelUUID);
438 } catch (Exception e) {
439 LOGGER.debug("Generic Exception - while searching for: modelUUID='" + modelUUID + " " + e.getMessage());
440 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUUID=" + modelUUID);
444 if (service == null) {
445 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getServiceByModelUUID", null);
447 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelUUID", null);
454 * Fetch the Common Service API definition using Http Method + serviceNameVersionId
456 public Service getService(Map<String, String> map, String httpMethod) {
458 String serviceNameVersionId = map.get("serviceNameVersionId");
460 String serviceId = "not_set";
461 String serviceVersion = "not_set";
463 if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
464 LOGGER.debug ("Catalog database - get service modelUUID with id " + serviceNameVersionId);
466 String hql = "FROM Service WHERE MODEL_UUID = :MODEL_UUID and http_method = :http_method";
467 query = getSession().createQuery(hql);
468 query.setParameter("MODEL_UUID", serviceNameVersionId);
470 serviceId = map.get("serviceId");
471 serviceVersion = map.get("serviceVersion");
472 LOGGER.debug("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
474 String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
475 query = getSession().createQuery(hql);
476 query.setParameter("service_id", serviceId);
477 query.setParameter("service_version", serviceVersion);
480 query.setParameter("http_method", httpMethod);
482 long startTime = System.currentTimeMillis();
483 Service service = null;
485 service = (Service) query.uniqueResult();
486 } catch (org.hibernate.NonUniqueResultException nure) {
487 LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
488 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);
491 } catch (org.hibernate.HibernateException he) {
492 LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + he.getMessage());
493 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);
496 } catch (Exception e) {
497 LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
498 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);
502 if (service == null) {
503 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
505 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
511 * Return the newest version of a Service (queried by Name).
514 * @return Service object or null if none found
516 public Service getServiceByModelName(String modelName){
518 long startTime = System.currentTimeMillis();
519 LOGGER.debug("Catalog database - get service with name " + modelName);
521 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
522 Query query = getSession().createQuery(hql);
523 query.setParameter("MODEL_NAME", modelName);
525 @SuppressWarnings("unchecked")
526 List <Service> resultList = query.list();
528 // See if something came back.
529 if (resultList.isEmpty()) {
530 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null);
533 resultList.sort(new MavenLikeVersioningComparator());
534 Collections.reverse(resultList);
536 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null);
537 return resultList.get(0);
540 public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
541 long startTime = System.currentTimeMillis();
542 LOGGER.debug("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion);
544 String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR";
545 Query query = getSession().createQuery(hql);
546 query.setParameter("MODEL_INVARIANT_UUID", modelInvariantId);
547 query.setParameter("VERSION_STR", modelVersion);
549 Service result = null;
551 result = (Service) query.uniqueResult();
552 } catch (org.hibernate.NonUniqueResultException nure) {
553 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'", nure);
554 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantId=" + modelInvariantId + " and modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId);
555 throw new Exception("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
557 // See if something came back.
559 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null);
563 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null);
568 * Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
570 * @param serviceModelUUID
572 * @return ServiceRecipe object or null if none found
575 public ServiceRecipe getServiceRecipe (int serviceModelUUID, String action) {
580 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
582 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action ");
585 long startTime = System.currentTimeMillis ();
586 LOGGER.debug ("Catalog database - get Service recipe with serviceModelUUID " + Integer.toString(serviceModelUUID)
591 Query query = getSession ().createQuery (hql.toString ());
592 query.setParameter ("serviceModelUUID", serviceModelUUID);
594 query.setParameter (ACTION, action);
597 @SuppressWarnings("unchecked")
598 List <ServiceRecipe> resultList = query.list ();
600 if (resultList.isEmpty ()) {
601 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
605 resultList.sort(new MavenLikeVersioningComparator());
606 Collections.reverse (resultList);
608 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
609 return resultList.get (0);
613 * Return a newest version of Service recipe that matches a given SERVICE_MODEL_UUID and ACTION
615 * @param serviceModelUuid
617 * @return ServiceRecipe object or null if none found
619 public ServiceRecipe getServiceRecipeByServiceModelUuid(String serviceModelUuid, String action) {
624 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid");
626 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action ");
629 long startTime = System.currentTimeMillis ();
630 LOGGER.debug("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid
635 Query query = getSession().createQuery(hql.toString());
636 query.setParameter("serviceModelUuid", serviceModelUuid);
638 query.setParameter(ACTION, action);
641 @SuppressWarnings("unchecked")
642 List <ServiceRecipe> resultList = query.list();
644 if (resultList.isEmpty()) {
645 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
649 resultList.sort(new MavenLikeVersioningComparator());
650 Collections.reverse(resultList);
652 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
653 return resultList.get(0);
656 public List<ServiceRecipe> getServiceRecipes(String serviceModelUuid) {
660 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
662 long startTime = System.currentTimeMillis();
663 LOGGER.debug("Catalog database - get Service recipe with serviceModelUUID " + serviceModelUuid);
665 Query query = getSession().createQuery(hql.toString());
666 query.setParameter("serviceModelUUID", serviceModelUuid);
668 @SuppressWarnings("unchecked")
669 List <ServiceRecipe> resultList = query.list();
671 if (resultList.isEmpty()) {
672 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null);
673 return Collections.EMPTY_LIST;
676 resultList.sort(new MavenLikeVersioningComparator());
677 Collections.reverse(resultList);
679 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null);
685 * Return the VNF component data - queried by the VNFs ID and the component type.
689 * @return VnfComponent object or null if none found
692 public VnfComponent getVnfComponent (int vnfId, String type) {
694 long startTime = System.currentTimeMillis();
695 LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
697 String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
698 Query query = getSession ().createQuery (hql);
699 query.setParameter ("vnf_id", vnfId);
700 query.setParameter ("type", type);
702 VnfComponent result = null;
704 result = (VnfComponent) query.uniqueResult();
705 } catch (org.hibernate.NonUniqueResultException nure) {
706 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
707 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);
710 } catch (org.hibernate.HibernateException he) {
711 LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + he.getMessage());
712 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);
715 } catch (Exception e) {
716 LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + e.getMessage());
717 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);
722 if (result != null) {
723 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
725 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
731 * Return the newest version of a specific VNF resource (queried by Name).
734 * @return VnfResource object or null if none found
736 public VnfResource getVnfResource (String vnfType) {
738 long startTime = System.currentTimeMillis();
739 LOGGER.debug("Catalog database - get vnf resource with model_name " + vnfType);
741 String hql = "FROM VnfResource WHERE modelName = :vnf_name";
742 Query query = getSession().createQuery(hql);
743 query.setParameter("vnf_name", vnfType);
745 @SuppressWarnings("unchecked")
746 List <VnfResource> resultList = query.list();
748 // See if something came back. Name is unique, so
749 if (resultList.isEmpty()) {
750 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
753 resultList.sort(new MavenLikeVersioningComparator());
754 Collections.reverse(resultList);
756 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
757 return resultList.get(0);
761 * Return the newest version of a specific VNF resource (queried by Name).
764 * @param serviceVersion
765 * @return VnfResource object or null if none found
767 public VnfResource getVnfResource (String vnfType, String serviceVersion) {
769 long startTime = System.currentTimeMillis();
770 LOGGER.debug("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion);
772 String hql = "FROM VnfResource WHERE modelName = :vnfName and version = :serviceVersion";
773 Query query = getSession().createQuery(hql);
774 query.setParameter("vnfName", vnfType);
775 query.setParameter("serviceVersion", serviceVersion);
777 VnfResource resource = null;
779 resource = (VnfResource) query.uniqueResult();
780 } catch (org.hibernate.NonUniqueResultException nure) {
781 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
782 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
785 } catch (org.hibernate.HibernateException he) {
786 LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "' " + he.getMessage());
787 LOGGER.debug(Arrays.toString(he.getStackTrace()));
788 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
791 } catch (Exception e) {
792 LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
793 LOGGER.debug(Arrays.toString(e.getStackTrace()));
794 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
798 if (resource == null) {
799 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
801 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
807 * Return VnfResource (queried by modelCustomizationId).
809 * @param modelCustomizationId
810 * @return VnfResource object or null if none found
812 public VnfResource getVnfResourceByModelCustomizationId(String modelCustomizationId) {
814 long startTime = System.currentTimeMillis();
815 LOGGER.debug("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
817 String hql = "SELECT vr "
818 + "FROM VnfResource as vr JOIN vr.vnfResourceCustomizations as vrc "
819 + "WHERE vrc.modelCustomizationUuid = :modelCustomizationId";
821 Query query = getSession().createQuery(hql);
822 query.setParameter("modelCustomizationId", modelCustomizationId);
824 VnfResource resource = null;
826 resource = (VnfResource) query.uniqueResult();
827 } catch(org.hibernate.NonUniqueResultException nure) {
828 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "'");
829 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
832 } catch (org.hibernate.HibernateException he) {
833 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
834 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationId=" + modelCustomizationId);
837 } catch (Exception e) {
838 LOGGER.debug("Generic Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
839 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationId=" + modelCustomizationId);
843 if (resource == null) {
844 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
846 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
853 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
855 * @return {@link VnfResourceCustomization} object or null if none found
857 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationName (String modelCustomizationName, String modelVersionId) {
859 long startTime = System.currentTimeMillis();
860 LOGGER.debug("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId);
862 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.modelCustomizationUuid IN "
863 + "(SELECT src.resourceModelCustomizationUUID FROM ServiceToResourceCustomization src "
864 + "WHERE src.serviceModelUUID = :modelVersionId)"
865 + "AND vrc.modelInstanceName = :modelCustomizationName";
867 Query query = getSession().createQuery(hql);
868 query.setParameter("modelCustomizationName", modelCustomizationName);
869 query.setParameter("modelVersionId", modelVersionId);
871 @SuppressWarnings("unchecked")
872 List<VnfResourceCustomization> resultList = query.list();
874 if (resultList.isEmpty()) {
875 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
879 resultList.sort(new MavenLikeVersioningComparator());
880 Collections.reverse(resultList);
882 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
883 return resultList.get(0);
888 * Return the newest version of a specific VNF resource (queried by modelInvariantId).
890 * @param modelInvariantUuid model invariant ID
891 * @param modelVersion model version
892 * @return VnfResource object or null if none found
894 public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) {
896 long startTime = System.currentTimeMillis();
897 LOGGER.debug("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
899 String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion";
900 Query query = getSession().createQuery(hql);
901 query.setParameter("modelInvariantUuid", modelInvariantUuid);
902 query.setParameter("serviceVersion", modelVersion);
904 VnfResource resource = null;
906 resource = (VnfResource) query.uniqueResult();
907 } catch (org.hibernate.NonUniqueResultException nure) {
908 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'");
909 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid);
912 } catch (org.hibernate.HibernateException he) {
913 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', asdc_service_model_version='" + modelVersion + "' " + he.getMessage());
914 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid);
917 } catch (Exception e) {
918 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "' " + e.getMessage());
919 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid);
923 if (resource == null) {
924 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
926 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
932 * Return the newest version of a specific VNF resource (queried by ID).
934 * @param id The vnf id
935 * @return VnfResource object or null if none found
938 public VnfResource getVnfResourceById (int id) {
940 long startTime = System.currentTimeMillis ();
941 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
943 String hql = "FROM VnfResource WHERE id = :id";
944 Query query = getSession ().createQuery (hql);
945 query.setParameter ("id", id);
947 @SuppressWarnings("unchecked")
948 List <VnfResource> resultList = query.list ();
950 // See if something came back. Name is unique, so
951 if (resultList.isEmpty ()) {
952 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
955 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
956 return resultList.get (0);
960 * Return the newest version of a vfModule - 1607
963 public VfModule getVfModuleModelName(String modelName) {
965 long startTime = System.currentTimeMillis();
966 LOGGER.debug("Catalog database - get vfModuleModelName with name " + modelName);
968 String hql = "FROM VfModule WHERE modelName = :model_name";
969 Query query = getSession().createQuery(hql);
970 query.setParameter("model_name", modelName);
972 @SuppressWarnings("unchecked")
973 List<VfModule> resultList = query.list();
975 // See if something came back. Name is unique, so
976 if (resultList.isEmpty()) {
977 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
980 resultList.sort(new MavenLikeVersioningComparator());
981 Collections.reverse(resultList);
983 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
984 return resultList.get(0);
987 public VfModule getVfModuleModelName(String modelName, String model_version) {
989 long startTime = System.currentTimeMillis();
990 LOGGER.debug("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
992 String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
993 Query query = getSession().createQuery(hql);
994 query.setParameter("modelName", modelName);
995 query.setParameter("model_version", model_version);
997 VfModule module = null;
999 module = (VfModule) query.uniqueResult();
1000 } catch (org.hibernate.NonUniqueResultException nure) {
1001 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 + "'");
1002 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
1005 } catch (org.hibernate.HibernateException he) {
1006 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + he.getMessage());
1007 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
1010 } catch (Exception e) {
1011 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + e.getMessage());
1012 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
1016 if (module == null) {
1017 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
1019 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
1025 * Need this for 1707 DHV. This may be a temporary solution. May
1026 * change it to get resources using service's model name.
1031 public VfModuleCustomization getVfModuleCustomizationByModelName(String modelName) {
1033 long startTime = System.currentTimeMillis();
1034 LOGGER.debug("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
1036 String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.modelName = :model_name";
1037 Query query = getSession().createQuery(hql);
1038 query.setParameter("model_name", modelName);
1040 @SuppressWarnings("unchecked")
1041 List<VfModuleCustomization> resultList = query.list();
1043 // See if something came back. Name is unique, so
1044 if (resultList.isEmpty()) {
1045 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1049 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query ", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1050 return resultList.get(0);
1055 * Return the newest version of a specific Network resource (queried by Type).
1057 * @param networkType
1058 * @return NetworkResource object or null if none found
1060 public NetworkResource getNetworkResource(String networkType) {
1062 long startTime = System.currentTimeMillis();
1063 LOGGER.debug("Catalog database - get network resource with type " + networkType);
1065 String hql = "FROM NetworkResource WHERE model_name = :network_type";
1066 Query query = getSession().createQuery(hql);
1067 query.setParameter("network_type", networkType);
1069 @SuppressWarnings("unchecked")
1070 List <NetworkResource> resultList = query.list();
1072 // See if something came back. Name is unique, so
1073 if (resultList.isEmpty()) {
1074 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
1078 resultList.sort(new MavenLikeVersioningComparator());
1079 Collections.reverse(resultList);
1080 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
1081 return resultList.get(0);
1085 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
1089 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
1090 * @return VnfRecipe object or null if none found
1092 public VnfRecipe getVnfRecipe(String vnfType, String action, String serviceType) {
1093 boolean withServiceType = false;
1095 StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1098 if (serviceType == null || serviceType.isEmpty()) {
1099 hql.append("AND serviceType is NULL ");
1101 hql.append("AND serviceType = :serviceType ");
1102 withServiceType = true;
1105 long startTime = System.currentTimeMillis();
1106 LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
1109 + " and service type "
1112 Query query = getSession().createQuery(hql.toString());
1113 query.setParameter(VNF_TYPE, vnfType);
1114 query.setParameter(ACTION, action);
1115 if (withServiceType) {
1116 query.setParameter(SERVICE_TYPE, serviceType);
1119 @SuppressWarnings("unchecked")
1120 List <VnfRecipe> resultList = query.list();
1122 if (resultList.isEmpty()) {
1123 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1127 resultList.sort(new MavenLikeVersioningComparator());
1128 Collections.reverse(resultList);
1130 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1131 return resultList.get(0);
1137 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
1141 * @return VnfRecipe object or null if none found
1143 public VnfRecipe getVnfRecipe(String vnfType, String action) {
1145 long startTime = System.currentTimeMillis();
1146 LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
1150 Query query = getSession().createQuery("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1151 query.setParameter(VNF_TYPE, vnfType);
1152 query.setParameter(ACTION, action);
1154 @SuppressWarnings("unchecked")
1155 List <VnfRecipe> resultList = query.list();
1157 if (resultList.isEmpty()) {
1158 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1162 resultList.sort(new MavenLikeVersioningComparator());
1163 Collections.reverse(resultList);
1165 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1166 return resultList.get(0);
1170 * Return a VNF recipe that matches a given ModelName and Modelversion and ACTION
1173 * @param modelVersion
1175 * @return VnfRecipe object or null if none found
1177 public VnfRecipe getVnfRecipeByNameVersion(String modelName, String modelVersion, String action) {
1179 long startTime = System.currentTimeMillis();
1180 LOGGER.debug("Catalog database - get VNF recipe with name " + modelName + " and action " + action);
1182 Query query = getSession().createQuery("FROM VnfRecipe WHERE vnfType = :vnfType AND version= :version AND action = :action ");
1183 query.setParameter(VNF_TYPE, modelName);
1184 query.setParameter(MODEL_VERSION, modelVersion);
1185 query.setParameter(ACTION, action);
1187 @SuppressWarnings("unchecked")
1188 List <VnfRecipe> resultList = query.list();
1190 if (resultList.isEmpty()) {
1191 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1195 resultList.sort(new MavenLikeVersioningComparator());
1196 Collections.reverse(resultList);
1198 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1199 return resultList.get(0);
1203 * Return a Network recipe that matches a given MODEL_UUID and ACTION
1207 * @return NetworkRecipe object or null if none found
1209 public VnfRecipe getVnfRecipeByModuleUuid (String vnfModelUuid, String action) {
1210 LOGGER.debug ("Catalog database - get vnf recipe with vnf resource model uuid " + vnfModelUuid
1214 VnfResource vnfResource = getVnfResourceByModelUuid(vnfModelUuid);
1215 if(null == vnfResource){
1219 VnfRecipe recipe = this.getVnfRecipeByNameVersion(vnfResource.getModelName(), vnfResource.getModelVersion(), action);
1224 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
1228 * @return VnfRecipe object or null if none found
1230 public VnfRecipe getVnfRecipeByVfModuleId(String vnfType, String vfModuleId, String action) {
1232 long startTime = System.currentTimeMillis();
1233 LOGGER.debug("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
1235 Query query = getSession().createQuery("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
1236 query.setParameter(VF_MODULE_MODEL_UUID, vfModuleId);
1237 query.setParameter(ACTION, action);
1239 @SuppressWarnings("unchecked")
1240 List <VnfRecipe> resultList = query.list();
1242 if (resultList.isEmpty()) {
1243 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1247 resultList.sort(new MavenLikeVersioningComparator());
1248 Collections.reverse(resultList);
1250 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1251 return resultList.get(0);
1254 public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
1255 long startTime = System.currentTimeMillis();
1256 LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
1258 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
1259 Query query = getSession().createQuery(hql);
1260 query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
1262 VfModule module = null;
1264 module = (VfModule) query.uniqueResult();
1265 } catch (org.hibernate.NonUniqueResultException nure) {
1266 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1267 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1270 } catch (org.hibernate.HibernateException he) {
1271 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1272 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1275 } catch (Exception e) {
1276 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1277 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1281 if (module == null) {
1282 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
1284 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
1290 public VfModule getVfModuleType(String type) {
1291 long startTime = System.currentTimeMillis();
1292 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
1294 String hql = "FROM VfModule WHERE type = :type";
1295 Query query = getSession().createQuery(hql);
1296 query.setParameter("type", type);
1298 @SuppressWarnings("unchecked")
1299 List<VfModule> resultList = query.list();
1300 if (resultList.isEmpty()) {
1301 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
1304 resultList.sort(new MavenLikeVersioningComparator());
1305 Collections.reverse (resultList);
1307 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1308 return resultList.get (0);
1312 public VfModule getVfModuleType(String type, String version) {
1314 long startTime = System.currentTimeMillis();
1315 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
1317 String hql = "FROM VfModule WHERE type = :type and version = :version";
1318 Query query = getSession().createQuery(hql);
1319 query.setParameter ("type", type);
1320 query.setParameter ("version", version);
1321 VfModule module = null;
1323 module = (VfModule) query.uniqueResult ();
1324 } catch (org.hibernate.NonUniqueResultException nure) {
1325 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 + "'");
1326 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
1329 } catch (org.hibernate.HibernateException he) {
1330 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + he.getMessage());
1331 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
1334 } catch (Exception e) {
1335 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + e.getMessage());
1336 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
1340 if (module == null) {
1341 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1343 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1348 public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
1349 long startTime = System.currentTimeMillis();
1350 LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
1352 String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
1353 Query query = getSession().createQuery(hql);
1354 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1355 VnfResource vnfResource = null;
1357 vnfResource = (VnfResource) query.uniqueResult();
1358 } catch (org.hibernate.NonUniqueResultException nure) {
1359 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1360 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
1363 } catch (org.hibernate.HibernateException he) {
1364 LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + he.getMessage());
1365 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1368 } catch (Exception e) {
1369 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + e.getMessage());
1370 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1374 if (vnfResource == null) {
1375 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1377 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1382 public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
1383 long startTime = System.currentTimeMillis();
1384 LOGGER.debug("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
1386 String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
1387 Query query = getSession().createQuery(hql);
1388 query.setParameter("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
1389 VnfResource vnfResource = null;
1391 vnfResource = (VnfResource) query.uniqueResult();
1392 } catch (org.hibernate.NonUniqueResultException nure) {
1393 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
1394 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
1397 } catch (org.hibernate.HibernateException he) {
1398 LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + he.getMessage());
1399 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1402 } catch (Exception e) {
1403 LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + e.getMessage());
1404 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1408 if (vnfResource == null) {
1409 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1411 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1416 public VnfResource getVnfResourceByType(String vnfType) {
1417 return this.getVnfResource(vnfType);
1420 public VfModule getVfModuleByModelInvariantUuid(String modelInvariantUUID) {
1421 long startTime = System.currentTimeMillis();
1422 LOGGER.debug ("Catalog database - get vfModuleTypeByModelInvariantUuid with uuid " + modelInvariantUUID);
1424 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUUID ";
1425 HashMap<String, String> parameters = new HashMap<>();
1426 parameters.put("modelInvariantUUID", modelInvariantUUID);
1427 List<VfModule> modules = this.executeQueryMultipleRows(hql, parameters, true);
1428 VfModule module = null;
1430 if (modules != null && ! modules.isEmpty()) {
1431 modules.sort(new MavenLikeVersioningComparator());
1432 Collections.reverse (modules);
1433 module = modules.get(0);
1436 if (module == null) {
1437 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1439 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1444 public VfModuleCustomization getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
1445 long startTime = System.currentTimeMillis();
1446 LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
1448 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid ";
1449 Query query = getSession().createQuery(hql);
1450 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1451 VfModuleCustomization module = null;
1453 module = (VfModuleCustomization) query.uniqueResult ();
1454 } catch (org.hibernate.NonUniqueResultException nure) {
1455 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1456 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1459 } catch (org.hibernate.HibernateException he) {
1460 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1461 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1464 } catch (Exception e) {
1465 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1466 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1470 if (module == null) {
1471 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1473 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1479 public VfModule getVfModuleByModelInvariantUuidAndModelVersion(String modelInvariantUuid, String modelVersion) {
1480 long startTime = System.currentTimeMillis();
1481 LOGGER.debug ("Catalog database - get getVfModuleByModelInvariantUuidAndModelVersion with modelInvariantUuid: " + modelInvariantUuid + ", modelVersion: " + modelVersion);
1483 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUuid and version = :modelVersion";
1484 Query query = getSession().createQuery(hql);
1485 query.setParameter ("modelInvariantUuid", modelInvariantUuid);
1486 query.setParameter("modelVersion", modelVersion);
1487 VfModule module = null;
1489 module = (VfModule) query.uniqueResult ();
1490 } catch (org.hibernate.NonUniqueResultException nure) {
1491 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "'");
1492 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);
1494 } catch (org.hibernate.HibernateException he) {
1495 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + he.getMessage());
1496 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1498 } catch (Exception e) {
1499 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + e.getMessage());
1500 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1503 if (module == null) {
1504 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1506 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1512 * Return the VfModuleCustomization object identified by the given modelCustomizationUuid 1707
1514 * @param modelCustomizationUuid
1515 * @return VfModuleCustomization or null if not found
1517 public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {
1518 long startTime = System.currentTimeMillis();
1519 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByModelCustomizationId with modelCustomizationUuid: " + modelCustomizationUuid);
1521 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1522 Query query = getSession().createQuery(hql);
1523 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1524 VfModuleCustomization VfModuleCustomization = null;
1526 VfModuleCustomization = (VfModuleCustomization) query.uniqueResult ();
1527 } catch (org.hibernate.NonUniqueResultException nure) {
1528 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1529 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1531 } catch (org.hibernate.HibernateException he) {
1532 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1533 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1535 } catch (Exception e) {
1536 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1537 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1540 if (VfModuleCustomization != null) {
1541 LOGGER.debug("Found VMC of " + VfModuleCustomization.getModelCustomizationUuid() + ", now looking for vfModule=" + VfModuleCustomization.getVfModuleModelUuid());
1542 VfModuleCustomization.setVfModule(this.getVfModuleByModelUuid(VfModuleCustomization.getVfModuleModelUuid()));
1545 if (VfModuleCustomization == null) {
1546 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1548 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1550 return VfModuleCustomization;
1554 * Return the VfModule object identified by the given modelUuid 1707
1555 * per Mike Z. - this may return more than one row - and even if it does,
1556 * the heat template will be the same - so just return any of the rows.
1559 * @return VfModule or null if not found
1561 public VfModule getVfModuleByModelUuid(String modelUuid) {
1562 long startTime = System.currentTimeMillis();
1563 LOGGER.debug ("Catalog database - get getVfModuleByModelUuid with modelUuid: " + modelUuid);
1565 String hql = "FROM VfModule WHERE modelUUID = :modelUuidValue";
1566 Query query = getSession().createQuery(hql);
1567 query.setParameter ("modelUuidValue", modelUuid);
1568 List<VfModule> vfModules = null;
1570 vfModules = query.list ();
1571 } catch (org.hibernate.HibernateException he) {
1572 LOGGER.debug("Hibernate Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + he.getMessage());
1573 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VfModule for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUuid=" + modelUuid);
1575 } catch (Exception e) {
1576 LOGGER.debug("Generic Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + e.getMessage());
1577 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUuid=" + modelUuid);
1581 if (vfModules == null || vfModules.isEmpty()) {
1582 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelUuid", null);
1585 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUuid", null);
1587 return vfModules.get(0);
1590 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1591 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1593 * @param modelCustomizationUuid
1594 * @return VnfResourceCustomization or null if not found
1596 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUuid(String modelCustomizationUuid) {
1597 long startTime = System.currentTimeMillis();
1598 LOGGER.debug ("Catalog database - get getVnfResourceByModelCustomizatonUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1600 String hql = "FROM VnfResourceCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1601 Query query = getSession().createQuery(hql);
1602 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1603 VnfResourceCustomization vnfResourceCustomization = null;
1605 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1606 } catch (org.hibernate.NonUniqueResultException nure) {
1607 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1608 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1610 } catch (org.hibernate.HibernateException he) {
1611 LOGGER.debug("Hibernate Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1612 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1614 } catch (Exception e) {
1615 LOGGER.debug("Generic Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1616 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1619 if (vnfResourceCustomization != null) {
1620 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1621 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1622 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1623 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1626 if (vnfResourceCustomization == null) {
1627 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1629 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1631 return vnfResourceCustomization;
1635 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1636 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1638 * @param modelVersionId
1639 * @return VnfResourceCustomization or null if not found
1641 public VnfResourceCustomization getVnfResourceCustomizationByModelVersionId(String modelVersionId) {
1642 long startTime = System.currentTimeMillis();
1643 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelVersionId with modelVersionId: " + modelVersionId);
1645 String hql = "FROM VnfResourceCustomization WHERE vnfResourceModelUuid = :modelVersionId";
1646 Query query = getSession().createQuery(hql);
1647 query.setParameter ("modelVersionId", modelVersionId);
1648 VnfResourceCustomization vnfResourceCustomization = null;
1650 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1651 } catch (org.hibernate.NonUniqueResultException nure) {
1652 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"'");
1653 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId==" + modelVersionId);
1655 } catch (org.hibernate.HibernateException he) {
1656 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + he.getMessage());
1657 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId);
1659 } catch (Exception e) {
1660 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + e.getMessage());
1661 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId);
1664 if (vnfResourceCustomization != null) {
1665 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1666 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1667 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1668 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1671 if (vnfResourceCustomization == null) {
1672 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1674 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1676 return vnfResourceCustomization;
1680 * Return the VfModule object identified by the given modelCustomizationId, modelVersionId 1707
1682 * @param modelVersionId, modelCustomizationId
1683 * @return VfModule or null if not found
1685 public VfModule getVfModuleByModelCustomizationIdAndVersion(String modelCustomizationId, String modelVersionId) {
1686 long startTime = System.currentTimeMillis();
1687 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdAndVersion with modelVersionId: " + modelVersionId + " modelCustomizationId: " + modelCustomizationId);
1689 // select * from vf_module vfm where vfm.MODEL_UUID IN (
1690 // select vfmc.VF_MODULE_MODEL_UUID from vf_module_customization vfmc where vfmc.MODEL_CUSTOMIZATION_UUID='222bd8f2-341d-4419-aa0e-98398fa34050')
1691 // and vfm.MODEL_UUID = 'fa1c8558-006c-4fb6-82f2-4fc0646d6b06';
1693 String hql = "Select vfm FROM VfModule as vfm WHERE vfm.modelUUID IN ("
1694 + "SELECT vfmc.vfModuleModelUuid FROM VfModuleCustomization as vfmc "
1695 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId) "
1696 + "AND vfm.modelUUID = :modelVersionId";
1697 Query query = getSession().createQuery(hql);
1698 query.setParameter ("modelVersionId", modelVersionId);
1699 query.setParameter ("modelCustomizationId", modelCustomizationId);
1700 VfModule vfModule = null;
1702 vfModule = (VfModule) query.uniqueResult ();
1703 } catch (org.hibernate.NonUniqueResultException nure) {
1704 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"' modelCustomizationId='" + modelCustomizationId + "'");
1705 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1707 } catch (org.hibernate.HibernateException he) {
1708 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1709 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1711 } catch (Exception e) {
1712 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1713 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1717 if (vfModule == null) {
1718 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1720 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1726 * Return the VfModule object identified by the given modelCustomizationId, modelVersion, modelInvariantId 1707
1728 * @param modelCustomizationId, modelVersion, modelInvariantId
1729 * @return VfModule or null if not found
1731 public VfModule getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId(String modelCustomizationId, String modelVersion, String modelInvariantId) {
1732 long startTime = System.currentTimeMillis();
1733 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId with modelVersionId: " + modelVersion);
1735 //select * from vf_module vfm left outer join vf_module_customization vfmc on vfmc.VF_MODULE_MODEL_UUID = vfm.MODEL_UUID
1736 // where vfmc.MODEL_CUSTOMIZATION_UUID='52643a8e-7953-4e48-8eab-97165b2b3a4b' and vfm.MODEL_UUID = ''
1738 String hql = "Select vfm FROM VfModule as vfm LEFT OUTER JOIN VfModuleCustomization as vfmc on vfmc.vfModuleModelUuid = vfm.modelUUID"
1739 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId AND vfm.modelInvariantUUID = :modelInvariantId AND vfm.modelVersion = :modelVersion";
1740 Query query = getSession().createQuery(hql);
1741 query.setParameter ("modelInvariantId", modelInvariantId);
1742 query.setParameter ("modelCustomizationId", modelCustomizationId);
1743 query.setParameter ("modelVersion", modelVersion);
1744 VfModule vfModule = null;
1746 vfModule = (VfModule) query.uniqueResult ();
1747 } catch (org.hibernate.NonUniqueResultException nure) {
1748 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 +"'");
1749 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);
1751 } catch (org.hibernate.HibernateException he) {
1752 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1753 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);
1755 } catch (Exception e) {
1756 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1757 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);
1761 if (vfModule == null) {
1762 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1764 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1770 * Return the VnfResourceCustomization object identified by the given modelCustomizationName, modelInvariantId and modelVersion 1707
1772 * @param modelInvariantId, modelVersion, modelCustomizationName
1773 * @return VnfResourceCustomization or null if not found
1775 public VnfResourceCustomization getVnfResourceCustomizationByModelInvariantId(String modelInvariantId, String modelVersion, String modelCustomizationName) {
1776 long startTime = System.currentTimeMillis();
1777 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelInvariantId with modelInvariantId: " + modelInvariantId + ", modelVersion: "
1778 + modelVersion + ", modelCustomizationName: " + modelCustomizationName);
1780 String hql = "SELECT VnfResourceCustomization FROM VnfResourceCustomization as vrc "
1781 + "LEFT OUTER JOIN VnfResource as vr "
1782 + "on vr.modelUuid =vrc.vnfResourceModelUuid "
1783 + "WHERE vr.modelInvariantUuid = :modelInvariantId AND vr.modelVersion = :modelVersion AND vrc.modelInstanceName = :modelCustomizationName";
1785 Query query = getSession().createQuery(hql);
1786 query.setParameter ("modelInvariantId", modelInvariantId);
1787 query.setParameter("modelVersion", modelVersion);
1788 query.setParameter("modelCustomizationName", modelCustomizationName);
1789 VnfResourceCustomization vnfResourceCustomization = null;
1791 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1792 } catch (org.hibernate.NonUniqueResultException nure) {
1793 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 + "'");
1794 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 + "'");
1796 } catch (org.hibernate.HibernateException he) {
1797 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "' " + he.getMessage());
1798 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 + "'");
1800 } catch (Exception e) {
1801 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' " + e.getMessage());
1802 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 + "'");
1805 if (vnfResourceCustomization != null) {
1806 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1807 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUUID()));
1808 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1809 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1812 if (vnfResourceCustomization == null) {
1813 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1815 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1817 return vnfResourceCustomization;
1821 * Return list of VnfResourceCustomization objects identified by the given modelCustomizationUuid 1707
1823 * @param modelCustomizationUuid
1824 * @return List<VfModuleCustomization> or null if not found
1826 public List<VfModuleCustomization> getVfModuleCustomizationByVnfModuleCustomizationUuid(String modelCustomizationUuid) {
1827 long startTime = System.currentTimeMillis();
1828 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByVnfModuleCustomizationUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1830 // select * from vf_module_customization as vfmc where vfmc.MODEL_CUSTOMIZATION_UUID IN(
1831 // select vrcmc.VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID from vnf_res_custom_to_vf_module_custom as vrcmc
1832 // where vrcmc.VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID = 'd279139c-4b85-48ff-8ac4-9b83a6fc6da7')
1834 String hql = "SELECT vfmc FROM VfModuleCustomization as vfmc where vfmc.modelCustomizationUuid "
1835 + "IN(select vrcmc.vfModuleCustModelCustomizationUuid from VnfResCustomToVfModuleCustom as vrcmc "
1836 + "WHERE vrcmc.vnfResourceCustModelCustomizationUuid = :modelCustomizationUuid)";
1838 Query query = getSession().createQuery(hql);
1839 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1840 List<VfModuleCustomization> resultList = null;
1842 resultList = query.list();
1843 } catch (org.hibernate.HibernateException he) {
1844 LOGGER.debug("Hibernate Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + he.getMessage());
1845 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1847 } catch (Exception e) {
1848 LOGGER.debug("Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + e.getMessage());
1849 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1853 if (resultList == null) {
1854 resultList = new ArrayList<>();
1856 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByVnfModuleCustomizationUuid", null);
1861 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
1863 * @return {@link VnfResourceCustomization} object or null if none found
1865 public VnfResourceCustomization getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId (String modelCustomizationName, String modelVersionId) {
1867 long startTime = System.currentTimeMillis ();
1868 LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " modelUUID " + modelVersionId);
1870 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.vnfResourceModelUuid IN "
1871 + "(SELECT vr.modelUuid FROM VnfResource vr "
1872 + "WHERE vr.modelUuid = :modelVersionId)"
1873 + "AND vrc.modelInstanceName = :modelCustomizationName";
1875 Query query = getSession ().createQuery (hql);
1876 query.setParameter ("modelCustomizationName", modelCustomizationName);
1877 query.setParameter ("modelVersionId", modelVersionId);
1879 @SuppressWarnings("unchecked")
1880 List <VnfResourceCustomization> resultList = query.list ();
1882 if (resultList.isEmpty ()) {
1883 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1887 resultList.sort(new MavenLikeVersioningComparator());
1888 Collections.reverse (resultList);
1890 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1891 return resultList.get (0);
1894 public ArrayList<VfModuleCustomization> getAllVfModuleCustomizations(String vnfResourceCustomizationMCU) {
1895 LOGGER.debug ("Catalog database - getAllVfModuleCustomizations with vnfResourceCustomizationMCU " + vnfResourceCustomizationMCU);
1897 List<VnfResCustomToVfModuleCustom> matches = this.getVRCtoVFMC(vnfResourceCustomizationMCU, null);
1898 if (matches == null || matches.isEmpty()) {
1899 LOGGER.debug("Found no vf modules for " + vnfResourceCustomizationMCU);
1900 return new ArrayList<>();
1902 ArrayList<VfModuleCustomization> list = new ArrayList<>();
1903 for (VnfResCustomToVfModuleCustom v : matches) {
1904 String m = v.getVfModuleCustModelCustomizationUuid();
1905 LOGGER.debug("VfModule to match: " + m);
1906 VfModuleCustomization c = this.getVfModuleCustomizationByModelCustomizationId(m);
1910 LOGGER.debug("**UNABLE to find vfModule " + m);
1917 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1918 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1921 * @return VnfResourceCustomization or null if not found
1923 public VnfResource getVnfResourceByModelUuid(String modelUuid) {
1924 long startTime = System.currentTimeMillis();
1925 LOGGER.debug ("Catalog database - get VnfResource with modelUuid " + modelUuid);
1927 String hql = "FROM VnfResource WHERE modelUuid = :modelUuid";
1928 Query query = getSession().createQuery(hql);
1929 query.setParameter ("modelUuid", modelUuid);
1930 VnfResource vnfResource = null;
1932 vnfResource = (VnfResource) query.uniqueResult ();
1933 } catch (org.hibernate.NonUniqueResultException nure) {
1934 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique Vnf_Resource row - data integrity error: modelUuid='" + modelUuid);
1935 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for Vnf Resource modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResource modelUuid==" + modelUuid);
1937 } catch (org.hibernate.HibernateException he) {
1938 LOGGER.debug("Hibernate Exception - while searching for: VnfResource modelUuid='" + modelUuid + "' " + he.getMessage());
1939 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResource modelUuid=" + modelUuid);
1941 } catch (Exception e) {
1942 LOGGER.debug("Generic Exception - while searching for: vnfResource ModelUuid='" + modelUuid + "'");
1943 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResource modelUuid=" + modelUuid);
1946 if (vnfResource == null) {
1947 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelUuid", null);
1949 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelUuid", null);
1954 public VnfResCustomToVfModuleCustom getVnfResCustomToVfModule(String vnfId, String vfId) {
1955 long startTime = System.currentTimeMillis();
1956 LOGGER.debug("Catalog database - getVnfResCustomToVfModule - vnfResourceCustModelCustUuid: " + vnfId + ", vfModuleCustModelCustomUuid=" + vfId);
1957 HashMap<String, String> parameters = new HashMap<>();
1958 parameters.put("vnfIdValue", vnfId);
1959 parameters.put("vfIdValue", vfId);
1960 VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow(
1961 "FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue", parameters, true);
1962 if (vrctvmc == null) {
1963 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResCustomToVfModule", null);
1965 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResCustomToVfModule", null);
1970 public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
1971 if (vnfResource == null)
1972 return Collections.EMPTY_LIST;
1973 String vnfResourceModelUuid = vnfResource.getModelUuid();
1975 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
1977 return this.getVfModulesForVnfResource(vnfResourceModelUuid);
1981 public List<VfModule> getVfModulesForVnfResource(String vnfResourceModelUuid) {
1982 long startTime = System.currentTimeMillis();
1983 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceModelUuid: " + vnfResourceModelUuid);
1984 Query query = getSession().createQuery("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId");
1985 query.setParameter("vnfResourceModelUUId", vnfResourceModelUuid);
1986 List<VfModule> resultList = null;
1988 resultList = query.list();
1989 if (resultList != null)
1990 LOGGER.debug("\tQuery found " + resultList.size() + " records.");
1992 LOGGER.debug("\tQuery found no records.");
1993 } catch (org.hibernate.HibernateException he) {
1994 LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + he.getMessage());
1995 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1997 } catch (Exception e) {
1998 LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + e.getMessage());
1999 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
2002 if (resultList == null) {
2003 resultList = new ArrayList<>();
2005 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
2009 public Service getServiceByUuid (String serviceModelInvariantUuid) {
2011 long startTime = System.currentTimeMillis ();
2012 LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
2014 String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
2015 Query query = getSession ().createQuery (hql);
2016 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
2018 Service service = null;
2020 service = (Service) query.uniqueResult ();
2021 } catch (org.hibernate.NonUniqueResultException nure) {
2022 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
2023 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2025 } catch (org.hibernate.HibernateException he) {
2026 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "' " + he.getMessage());
2027 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2029 } catch (Exception e) {
2030 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + " " + e.getMessage());
2031 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2034 if (service == null) {
2035 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
2037 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
2043 public NetworkResource getNetworkResourceById(Integer id) {
2044 long startTime = System.currentTimeMillis ();
2045 LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
2047 String hql = "FROM NetworkResource WHERE id = :id";
2048 Query query = getSession ().createQuery (hql);
2049 query.setParameter ("id", id);
2051 NetworkResource networkResource = null;
2053 networkResource = (NetworkResource) query.uniqueResult ();
2054 } catch (org.hibernate.NonUniqueResultException nure) {
2055 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
2056 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
2058 } catch (org.hibernate.HibernateException he) {
2059 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2060 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
2062 } catch (Exception e) {
2063 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2064 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
2068 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2069 return networkResource;
2073 public NetworkResource getNetworkResourceById(String id) {
2074 long startTime = System.currentTimeMillis ();
2075 LOGGER.debug ("Catalog database - getNetworkResource with model_uuid " + id);
2077 String hql = "FROM NetworkResource WHERE modelUUID = :model_uuid";
2078 Query query = getSession ().createQuery (hql);
2079 query.setParameter ("model_uuid", id);
2081 List<NetworkResource> networkResources = null;
2083 networkResources = query.list ();
2084 } catch (org.hibernate.HibernateException he) {
2085 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2086 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);
2088 } catch (Exception e) {
2089 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2090 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);
2094 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2095 if (networkResources == null || networkResources.isEmpty())
2098 return networkResources.get(0);
2103 public static boolean isEmptyOrNull(String str) {
2106 if ("null".equals(str))
2113 public List<ServiceToResourceCustomization> getSTR(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
2114 LOGGER.debug("Catalog database: getSTR - smu=" + serviceModelUuid + ", rmcu=" + resourceModelCustomizationUuid + ", modelType = " + modelType);
2116 if (isEmptyOrNull(serviceModelUuid) && isEmptyOrNull(resourceModelCustomizationUuid) && isEmptyOrNull(modelType))
2119 StringBuilder hql = new StringBuilder("FROM ServiceToResourceCustomization WHERE ");
2120 boolean first = true;
2121 if (serviceModelUuid != null && !serviceModelUuid.equals("")) {
2122 hql.append("serviceModelUUID = :smu");
2125 if (resourceModelCustomizationUuid != null && !resourceModelCustomizationUuid.equals("")) {
2127 hql.append(" AND ");
2129 hql.append("resourceModelCustomizationUUID = :rmcu");
2132 if (modelType != null && !modelType.equals("")) {
2134 hql.append(" AND ");
2137 hql.append("modelType = :modelType");
2140 Query query = getSession().createQuery(hql.toString());
2141 if (hql.toString().contains(":smu"))
2142 query.setParameter("smu", serviceModelUuid);
2143 if (hql.toString().contains(":rmcu"))
2144 query.setParameter("rmcu", resourceModelCustomizationUuid);
2145 if (hql.toString().contains(":modelType"))
2146 query.setParameter("modelType", modelType);
2147 LOGGER.debug("query - " + hql.toString());
2149 @SuppressWarnings("unchecked")
2150 List<ServiceToResourceCustomization> resultList = query.list();
2151 if (resultList == null || resultList.isEmpty()) {
2152 LOGGER.debug("Found no matches to the query - " + hql.toString());
2153 return new ArrayList<>();
2158 public List<VnfResCustomToVfModuleCustom> getVRCtoVFMC (String vrc_mcu, String vfmc_mcu) {
2159 LOGGER.debug("Catalog database: getVRCtoVFMC - vrc_mcu=" + vrc_mcu + ", vfmc_mcu=" + vfmc_mcu);
2161 if (isEmptyOrNull(vrc_mcu) && isEmptyOrNull(vfmc_mcu))
2164 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom WHERE ");
2165 boolean first = true;
2166 if (vrc_mcu != null && !vrc_mcu.equals("")) {
2167 hql.append("vnfResourceCustModelCustomizationUuid = :vrc_mcu");
2170 if (vfmc_mcu != null && !vfmc_mcu.equals("")) {
2172 hql.append(" AND ");
2174 hql.append("vfModuleCustModelCustomizationUuid = :vfmc_mcu");
2177 Query query = getSession().createQuery(hql.toString());
2178 if (hql.toString().contains(":vrc_mcu"))
2179 query.setParameter("vrc_mcu", vrc_mcu);
2180 if (hql.toString().contains(":vfmc_mcu"))
2181 query.setParameter("vfmc_mcu", vfmc_mcu);
2182 @SuppressWarnings("unchecked")
2183 List<VnfResCustomToVfModuleCustom> resultList = query.list();
2184 if (resultList == null || resultList.isEmpty()) {
2185 LOGGER.debug("Found no matches to the query - " + hql.toString());
2186 return new ArrayList<>();
2191 @SuppressWarnings("unchecked")
2192 public List <TempNetworkHeatTemplateLookup> getTempNetworkHeatTemplateLookup (String networkResourceModelName) {
2194 long startTime = System.currentTimeMillis ();
2195 LOGGER.debug ("Catalog database - GetTempNetworkHeatTemplateLookup for Network Name " + networkResourceModelName);
2197 String hql = "FROM TempNetworkHeatTemplateLookup where networkResourceModelName = :networkResourceModelName";
2198 Query query = getSession ().createQuery (hql);
2199 query.setParameter ("networkResourceModelName", networkResourceModelName);
2201 List <TempNetworkHeatTemplateLookup> result = query.list ();
2202 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getTempNetworkHeatTemplateLookup", null);
2206 // 1702 API Spec - Query for all networks in a Service:
2207 public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
2208 long startTime = System.currentTimeMillis();
2209 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
2211 List<ServiceToResourceCustomization> strMappings = this.getSTR(serviceModelUuid, null, "network");
2212 if (strMappings == null || strMappings.isEmpty()) {
2213 LOGGER.debug("Found NO matches for NRC with ServiceModelUuid=" + serviceModelUuid);
2214 return new ArrayList<>();
2216 LOGGER.debug("Found " + strMappings.size() + " entries in ServiceToResourceCustomizations.network with smu=" + serviceModelUuid);
2218 ArrayList<NetworkResourceCustomization> masterList = new ArrayList<>();
2219 for (ServiceToResourceCustomization stn : strMappings) {
2220 String networkModelCustomizationUuid = stn.getResourceModelCustomizationUUID();
2221 LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
2222 List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
2223 masterList.addAll(resultSet);
2225 LOGGER.debug("Returning " + masterList.size() + " NRC records");
2226 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
2229 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2230 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2232 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2233 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2234 @SuppressWarnings("unchecked")
2235 List<Service> serviceList = query.list();
2237 if (serviceList.isEmpty()) {
2238 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2239 return new ArrayList<>();
2242 serviceList.sort(new MavenLikeVersioningComparator());
2243 Collections.reverse (serviceList);
2244 Service service = serviceList.get(0);
2246 String serviceNameVersionId = service.getModelUUID();
2247 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
2249 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2250 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2252 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2253 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2255 Query query = getSession().createQuery(
2256 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2257 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2258 query.setParameter("serviceModelVersion", serviceModelVersion);
2261 //can fix this later - no time - could do a unique query here - but this should work
2262 @SuppressWarnings("unchecked")
2263 List<Service> serviceList = query.list();
2265 if (serviceList.isEmpty()) {
2266 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2267 return new ArrayList<>();
2270 serviceList.sort(new MavenLikeVersioningComparator());
2271 Collections.reverse (serviceList);
2272 Service service = serviceList.get(0);
2274 String serviceNameVersionId = service.getModelUUID();
2276 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2277 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2280 public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
2281 long startTime = System.currentTimeMillis();
2282 LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
2284 //Query query = getSession().createQuery(hql.toString());
2285 //query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
2286 //LOGGER.debug("QUERY: " + hql.toString() + ", networkModelCustomizationUuid=" + networkModelCustomizationUuid);
2288 //@SuppressWarnings("unchecked")
2289 //List<NetworkResourceCustomization> resultList = query.list();
2291 HashMap<String, String> params = new HashMap<>();
2292 params.put("networkModelCustomizationUuid", networkModelCustomizationUuid);
2294 List<NetworkResourceCustomization> resultList = this.executeQueryMultipleRows(
2295 "FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid", params, true);
2297 if (resultList.isEmpty()) {
2298 LOGGER.debug("Unable to find an NMC with nmcu=" + networkModelCustomizationUuid);
2299 return new ArrayList<>();
2301 for (NetworkResourceCustomization nrc : resultList) {
2302 nrc.setNetworkResource(this.getNetworkResourceById(nrc.getNetworkResourceModelUuid()));
2305 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
2309 public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
2310 long startTime = System.currentTimeMillis();
2311 LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
2313 NetworkResource nr = this.getNetworkResource(networkType);
2315 return new ArrayList<>();
2317 String networkResourceId = nr.getModelUUID();
2319 LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
2321 Query query = getSession().createQuery(
2322 "FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId");
2323 query.setParameter("networkResourceId", networkResourceId);
2325 @SuppressWarnings("unchecked")
2326 List<NetworkResourceCustomization> resultList = query.list();
2328 if (resultList != null && ! resultList.isEmpty()) {
2329 LOGGER.debug("Found " + resultList.size() + " results");
2330 for (NetworkResourceCustomization nrc : resultList) {
2331 nrc.setNetworkType(networkType);
2332 nrc.setNetworkResource(nr);
2335 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
2339 public ArrayList<VfModuleCustomization> getAllVfmcForVrc(VnfResourceCustomization vrc) {
2340 LOGGER.debug("Catalog database: getAllVfmcForVrc - " + vrc.getModelCustomizationUuid());
2342 List<VnfResCustomToVfModuleCustom> vfmcs = this.getVRCtoVFMC(vrc.getModelCustomizationUuid(), null);
2343 if (vfmcs == null || vfmcs.isEmpty()) {
2344 return new ArrayList<>();
2346 ArrayList<VfModuleCustomization> vfModuleCusts = new ArrayList<>();
2347 for (VnfResCustomToVfModuleCustom vfmc : vfmcs) {
2348 VfModuleCustomization vfmcust = this.getVfModuleCustomizationByModelCustomizationId(vfmc.getVfModuleCustModelCustomizationUuid());
2349 if (vfmcust != null) {
2350 vfModuleCusts.add(vfmcust);
2353 return vfModuleCusts;
2356 //1702 API Spec cont'd - Query for all VnfResources in a Service:
2357 //1707 modified for db refactoring
2358 public List<VnfResourceCustomization> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
2359 LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
2361 Query query = getSession().createQuery("FROM Service WHERE modelUUID = :serviceModelUuid");
2362 query.setParameter("serviceModelUuid", serviceModelUuid);
2363 @SuppressWarnings("unchecked")
2364 List<Service> serviceList = query.list();
2366 if (serviceList.isEmpty()) {
2367 LOGGER.debug("Unable to find a service with modelUuid=" + serviceModelUuid);
2368 return new ArrayList<>();
2371 serviceList.sort(new MavenLikeVersioningComparator());
2372 Collections.reverse (serviceList);
2374 // Step 2 - Now query to get the related VnfResourceCustomizations
2376 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "vnf");
2378 if (strcs.isEmpty()) {
2379 LOGGER.debug("Unable to find any related vnfs to a service with modelUuid=" + serviceModelUuid);
2380 return new ArrayList<>();
2383 ArrayList<VnfResourceCustomization> allVrcs = new ArrayList<>();
2384 for (ServiceToResourceCustomization strc : strcs) {
2385 LOGGER.debug("Try to find VRC for mcu=" + strc.getResourceModelCustomizationUUID());
2386 VnfResourceCustomization vrc = this.getVnfResourceCustomizationByModelCustomizationUuid(strc.getResourceModelCustomizationUUID());
2393 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2394 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2396 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2397 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2398 @SuppressWarnings("unchecked")
2399 List<Service> resultList = query.list();
2401 if (resultList.isEmpty()) {
2402 return new ArrayList<>();
2404 resultList.sort(new MavenLikeVersioningComparator());
2405 Collections.reverse (resultList);
2406 Service service = resultList.get(0);
2407 //now just call the method that takes the version - the service object will have the highest version
2408 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2410 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2411 long startTime = System.currentTimeMillis();
2412 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2414 Query query = getSession().createQuery(
2415 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2416 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2417 query.setParameter("serviceModelVersion", serviceModelVersion);
2419 @SuppressWarnings("unchecked")
2420 List<Service> resultList = query.list();
2422 if (resultList.isEmpty()) {
2423 return new ArrayList<>();
2425 resultList.sort(new MavenLikeVersioningComparator());
2426 Collections.reverse (resultList);
2427 Service service = resultList.get(0);
2428 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
2429 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2432 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
2433 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
2434 if (serviceVersion == null || serviceVersion.equals("")) {
2435 return this.getAllVnfsByServiceName(serviceName);
2438 Query query = getSession().createQuery(
2439 "FROM Service WHERE modelName = :serviceName and version = :serviceVersion");
2440 query.setParameter("serviceName", serviceName);
2441 query.setParameter("serviceVersion", serviceVersion);
2443 @SuppressWarnings("unchecked")
2444 List<Service> resultList = query.list();
2446 if (resultList.isEmpty()) {
2447 return Collections.EMPTY_LIST;
2449 Service service = resultList.get(0);
2450 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2452 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName) {
2453 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
2455 Query query = getSession().createQuery("FROM Service WHERE modelName = :serviceName");
2456 query.setParameter("serviceName", serviceName);
2458 @SuppressWarnings("unchecked")
2459 List<Service> resultList = query.list();
2461 if (resultList.isEmpty()) {
2462 return Collections.EMPTY_LIST;
2464 resultList.sort(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 Query query1 = getSession().createQuery("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu");
2476 query1.setParameter("vrcmcu", vnfModelCustomizationUuid);
2477 @SuppressWarnings("unchecked")
2478 List<VnfResourceCustomization> resultList1 = query1.list();
2480 if (resultList1.isEmpty()) {
2481 LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
2482 return Collections.EMPTY_LIST;
2485 for (VnfResourceCustomization vrc : resultList1) {
2486 VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid());
2487 vrc.setVnfResource(vr);
2488 vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc));
2491 LOGGER.debug("Returning " + resultList1.size() + " vnf modules");
2492 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
2496 //1702 API Spec cont'd - Query for all allotted resources in a Service
2498 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
2499 long startTime = System.currentTimeMillis();
2500 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
2502 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "allottedResource");
2503 if (strcs == null || strcs.isEmpty()) {
2504 LOGGER.debug("No AR entries found for " + serviceModelUuid);
2505 return new ArrayList<>();
2507 LOGGER.debug("Found " + strcs.size() + " entries in ServiceToResourceCustomizations with smu=" + serviceModelUuid + ", allottedResource");
2509 ArrayList<AllottedResourceCustomization> masterList = new ArrayList<>();
2510 for (ServiceToResourceCustomization star : strcs) {
2511 String arModelCustomizationUuid = star.getResourceModelCustomizationUUID();
2512 LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
2513 List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
2514 masterList.addAll(resultSet);
2516 LOGGER.debug("Returning " + masterList.size() + " ARC records");
2517 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
2521 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2522 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2524 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2525 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2526 @SuppressWarnings("unchecked")
2527 List<Service> serviceList = query.list();
2529 if (serviceList.isEmpty()) {
2530 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2531 return new ArrayList<>();
2534 serviceList.sort(new MavenLikeVersioningComparator());
2535 Collections.reverse (serviceList);
2536 Service service = serviceList.get(0);
2538 String serviceModelUuid = service.getModelUUID();
2539 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceModelUuid);
2541 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2544 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2545 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2547 Query query = getSession().createQuery(
2548 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2549 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2550 query.setParameter("serviceModelVersion", serviceModelVersion);
2552 @SuppressWarnings("unchecked")
2553 List<Service> serviceList = query.list();
2555 if (serviceList.isEmpty()) {
2556 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2557 return new ArrayList<>();
2560 serviceList.sort(new MavenLikeVersioningComparator());
2561 Collections.reverse (serviceList);
2562 Service service = serviceList.get(0);
2564 String serviceModelUuid = service.getModelUUID();
2566 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2569 public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
2570 long startTime = System.currentTimeMillis();
2571 LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
2573 Query query = getSession().createQuery(
2574 "FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
2575 query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
2577 @SuppressWarnings("unchecked")
2578 List<AllottedResourceCustomization> resultList = query.list();
2580 if (resultList.isEmpty()) {
2581 LOGGER.debug("No ARC found with arc_mcu=" + arModelCustomizationUuid);
2582 return new ArrayList<>();
2584 // There should only be one - but we'll handle if multiple
2585 for (AllottedResourceCustomization arc : resultList) {
2586 AllottedResource ar = this.getAllottedResourceByModelUuid(arc.getArModelUuid());
2587 arc.setAllottedResource(ar);
2590 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
2594 public AllottedResource getAllottedResourceByModelUuid(String arModelUuid) {
2595 long startTime = System.currentTimeMillis ();
2596 LOGGER.debug ("Catalog database - get Allotted Resource with modelUuid= " + arModelUuid);
2598 String hql = "FROM AllottedResource WHERE modelUuid = :arModelUuid";
2599 Query query = getSession ().createQuery (hql);
2600 query.setParameter ("arModelUuid", arModelUuid);
2602 @SuppressWarnings("unchecked")
2603 List <AllottedResource> resultList = query.list ();
2605 // See if something came back. Name is unique, so
2606 if (resultList.isEmpty ()) {
2607 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. AllottedResource not found", "CatalogDB", "getAllottedResourceByModelUuid", null);
2610 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllottedResourceByModelUuid", null);
2611 return resultList.get (0);
2615 //1702 API Spec cont'd - Query for all resources in a Service:
2616 public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
2617 long startTime = System.currentTimeMillis();
2618 LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
2620 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2621 Query query = getSession().createQuery(hql.toString());
2622 query.setParameter("serviceModelUuid", serviceModelUuid);
2623 LOGGER.debug("Query: " + hql.toString() + ", smu=" + serviceModelUuid);
2624 @SuppressWarnings("unchecked")
2625 List<Service> serviceList = query.list();
2627 if (serviceList.isEmpty()) {
2628 LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
2629 return new ServiceMacroHolder();
2632 serviceList.sort(new MavenLikeVersioningComparator());
2633 Collections.reverse (serviceList);
2634 Service service = serviceList.get(0);
2636 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2637 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
2638 smh.setNetworkResourceCustomization(nrcList);
2639 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2640 smh.setAllottedResourceCustomization(arcList);
2641 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(serviceModelUuid);
2642 smh.setVnfResourceCustomizations(vnfList);
2644 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
2647 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2648 long startTime = System.currentTimeMillis();
2649 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2651 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2652 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2653 @SuppressWarnings("unchecked")
2654 List<Service> serviceList = query.list();
2656 if (serviceList.isEmpty()) {
2657 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2658 return new ServiceMacroHolder();
2661 serviceList.sort(new MavenLikeVersioningComparator());
2662 Collections.reverse (serviceList);
2663 Service service = serviceList.get(0);
2665 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2666 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2667 smh.setNetworkResourceCustomization(nrcList);
2668 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2669 smh.setAllottedResourceCustomization(arcList);
2670 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2671 smh.setVnfResourceCustomizations(vnfList);
2673 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
2677 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2678 long startTime = System.currentTimeMillis();
2679 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2681 Query query = getSession().createQuery(
2682 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2683 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2684 query.setParameter("serviceModelVersion", serviceModelVersion);
2685 //TODO make this a unique query
2686 @SuppressWarnings("unchecked")
2687 List<Service> serviceList = query.list();
2689 if (serviceList.isEmpty()) {
2690 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
2691 return new ServiceMacroHolder();
2694 serviceList.sort(new MavenLikeVersioningComparator());
2695 Collections.reverse (serviceList);
2696 Service service = serviceList.get(0);
2698 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2699 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2700 smh.setNetworkResourceCustomization(nrcList);
2701 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2702 smh.setAllottedResourceCustomization(arcList);
2703 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2704 smh.setVnfResourceCustomizations(vnfList);
2706 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
2710 // 1707 New API queries
2711 public NetworkResourceCustomization getSingleNetworkByModelCustomizationUuid(String modelCustomizationUuid) {
2712 LOGGER.debug("Catalog database; getSingleNetworkByModelCustomizationUuid - " + modelCustomizationUuid);
2713 List<NetworkResourceCustomization> resultList = this.getAllNetworksByNetworkModelCustomizationUuid(modelCustomizationUuid);
2714 if (resultList == null || resultList.isEmpty()) {
2717 return resultList.get(0);
2719 public AllottedResourceCustomization getSingleAllottedResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2720 LOGGER.debug("Catalog database; getSingleAllottedResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2721 List<AllottedResourceCustomization> resultList = this.getAllAllottedResourcesByArModelCustomizationUuid(modelCustomizationUuid);
2722 if (resultList == null || resultList.isEmpty()) {
2725 return resultList.get(0);
2728 public VnfResource getSingleVnfResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2730 long startTime = System.currentTimeMillis();
2731 LOGGER.debug("Catalog database; getSingleVnfResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2732 List<VnfResource> resultList = this.getAllVnfsByVnfModelCustomizationUuid(modelCustomizationUuid);
2733 if (resultList == null || resultList.size() < 1) {
2736 return resultList.get(0);
2741 private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
2742 HashMap<String, NetworkResource> networkResources = new HashMap<>();
2744 for (NetworkResourceCustomization nrc : resultList) {
2745 String network_id = nrc.getNetworkResourceModelUuid();
2746 if (network_id == null) {
2747 nrc.setNetworkResource(null);
2748 nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
2751 if (networkResources.containsKey(network_id)) {
2752 nrc.setNetworkResource(networkResources.get(network_id));
2753 nrc.setNetworkType(networkResources.get(network_id).getModelName());
2755 NetworkResource nr = this.getNetworkResourceById(network_id);
2757 nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
2759 nrc.setNetworkType(nr.getModelName());
2760 nrc.setNetworkResource(nr);
2761 networkResources.put(network_id, nr);
2768 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
2769 * first query VF_MODULE table by type, and then use the ID to query
2770 * VNF_RECIPE by VF_MODULE_ID and ACTION
2773 * @parm vfModuleModelName
2775 * @return VnfRecipe object or null if none found
2777 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
2778 String vfModuleType = vnfType + "::" + vfModuleModelName;
2780 long startTime = System.currentTimeMillis ();
2781 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
2783 Query query = getSession ().createQuery ("FROM VfModule WHERE type = :type ");
2784 query.setParameter (TYPE, vfModuleType);
2786 @SuppressWarnings("unchecked")
2787 List <VfModule> resultList = query.list ();
2789 if (resultList.isEmpty ()) {
2790 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
2794 resultList.sort(new MavenLikeVersioningComparator());
2795 Collections.reverse (resultList);
2797 VfModule vfMod = resultList.get(0);
2799 String vfModuleId = vfMod.getModelUUID();
2801 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
2805 Query query1 = getSession ().createQuery ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2806 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2807 query1.setParameter (ACTION, action);
2809 @SuppressWarnings("unchecked")
2810 List <VnfRecipe> resultList1 = query1.list ();
2812 if (resultList1.isEmpty ()) {
2813 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
2817 resultList1.sort(new MavenLikeVersioningComparator());
2818 Collections.reverse (resultList1);
2820 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
2821 return resultList1.get (0);
2825 * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2826 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2828 * @param vfModuleType
2829 * @parm modelCustomizationUuid
2830 * @param asdcServiceModelVersion
2831 * @param modelVersion
2833 * @return VfModule list
2835 public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2838 if(modelCustomizationUuid != null){
2839 hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
2841 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2843 query = getSession ().createQuery (hql.toString ());
2844 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
2845 query.setParameter ("version", asdcServiceModelVersion);
2847 hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
2849 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2851 query = getSession ().createQuery (hql.toString ());
2852 query.setParameter (TYPE, vfModuleType);
2853 query.setParameter ("version", asdcServiceModelVersion);
2854 query.setParameter ("modelVersion", modelVersion);
2857 @SuppressWarnings("unchecked")
2858 List <VfModule> resultList = query.list ();
2864 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2865 * MODEL_CUSTOMIZATION_UUID, ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2866 * first query VF_MODULE table by type, and then use the ID to query
2867 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2870 * @parm vfModuleModelName
2872 * @return VnfRecipe object or null if none found
2874 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2875 String vfModuleType = vnfType + "::" + vfModuleModelName;
2876 long startTime = System.currentTimeMillis ();
2877 List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
2879 if (resultList.isEmpty ()) {
2880 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2884 resultList.sort(new MavenLikeVersioningComparator());
2885 Collections.reverse (resultList);
2887 VfModule vfMod = resultList.get(0);
2889 String vfModuleId = vfMod.getModelUUID();
2891 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2895 Query query1 = getSession ().createQuery (
2896 "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2897 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2898 query1.setParameter (ACTION, action);
2900 @SuppressWarnings("unchecked")
2901 List <VnfComponentsRecipe> resultList1 = query1.list ();
2903 if (resultList1.isEmpty ()) {
2904 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2908 resultList1.sort(new MavenLikeVersioningComparator());
2909 Collections.reverse (resultList1);
2911 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2912 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2913 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);
2916 return resultList1.get (0);
2920 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2921 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2922 * first query VF_MODULE table by type, and then use the ID to query
2923 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2926 * @parm vfModuleModelName
2928 * @return VnfRecipe object or null if none found
2930 public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
2931 long startTime = System.currentTimeMillis ();
2933 if (resultList.isEmpty ()) {
2934 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2938 resultList.sort(new MavenLikeVersioningComparator());
2939 Collections.reverse (resultList);
2941 VfModule vfMod = resultList.get(0);
2943 String vfModuleId = vfMod.getModelName();
2945 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2949 Query query1 = getSession ().createQuery (
2950 "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2951 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2952 query1.setParameter (ACTION, action);
2954 @SuppressWarnings("unchecked")
2955 List <VnfComponentsRecipe> resultList1 = query1.list ();
2957 if (resultList1.isEmpty ()) {
2958 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2962 resultList1.sort(new MavenLikeVersioningComparator());
2963 Collections.reverse (resultList1);
2965 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2966 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2967 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);
2970 return resultList1.get (0);
2975 * Return all VNF Resources in the Catalog DB
2977 * @return A list of VnfResource objects
2979 @SuppressWarnings("unchecked")
2980 public List <VnfResource> getAllVnfResources () {
2982 long startTime = System.currentTimeMillis ();
2983 LOGGER.debug ("Catalog database - get all VNF resources");
2985 String hql = "FROM VnfResource";
2986 Query query = getSession ().createQuery (hql);
2988 List <VnfResource> result = query.list ();
2989 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
2994 * Return VNF Resources in the Catalog DB that match a given VNF role
2996 * @return A list of VnfResource objects
2998 @SuppressWarnings("unchecked")
2999 @Deprecated // vnfRole is no longer in VnfResource
3000 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
3002 long startTime = System.currentTimeMillis ();
3003 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
3005 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
3006 Query query = getSession ().createQuery (hql);
3007 query.setParameter ("vnfRole", vnfRole);
3009 List <VnfResource> resources = query.list ();
3010 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
3015 * Return VNF Resources in the Catalog DB that match a given VNF role
3017 * @return A list of VnfResource objects
3019 @SuppressWarnings("unchecked")
3020 public List<VnfResourceCustomization> getVnfResourceCustomizationsByRole(String vnfRole) {
3021 long startTime = System.currentTimeMillis ();
3022 LOGGER.debug ("Catalog database - get all VNF resource customizations for role " + vnfRole);
3024 String hql = "FROM VnfResourceCustomization WHERE nfRole = :vnfRole";
3025 Query query = getSession ().createQuery (hql);
3026 query.setParameter ("vnfRole", vnfRole);
3028 List <VnfResourceCustomization> resources = query.list ();
3029 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationsByRole", null);
3034 * Return all Network Resources in the Catalog DB
3036 * @return A list of NetworkResource objects
3038 @SuppressWarnings("unchecked")
3039 public List <NetworkResource> getAllNetworkResources () {
3041 long startTime = System.currentTimeMillis ();
3042 LOGGER.debug ("Catalog database - get all network resources");
3044 String hql = "FROM NetworkResource";
3045 Query query = getSession ().createQuery (hql);
3047 List <NetworkResource> result = query.list ();
3048 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
3052 @SuppressWarnings("unchecked")
3053 public List<NetworkResourceCustomization> getAllNetworkResourceCustomizations() {
3054 long startTime = System.currentTimeMillis ();
3055 LOGGER.debug ("Catalog database - get all network resource customizations");
3057 String hql = "FROM NetworkResourceCustomization";
3058 Query query = getSession ().createQuery (hql);
3060 List <NetworkResourceCustomization> result = query.list ();
3061 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResourceCustomizations", null);
3066 * Return all VF Modules in the Catalog DB
3068 * @return A list of VfModule objects
3070 @SuppressWarnings("unchecked")
3071 public List <VfModule> getAllVfModules () {
3073 long startTime = System.currentTimeMillis ();
3074 LOGGER.debug ("Catalog database - get all vf modules");
3076 String hql = "FROM VfModule";
3077 Query query = getSession ().createQuery (hql);
3079 List <VfModule> result = query.list ();
3080 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
3084 @SuppressWarnings("unchecked")
3085 public List <VfModuleCustomization> getAllVfModuleCustomizations () {
3087 long startTime = System.currentTimeMillis ();
3088 LOGGER.debug ("Catalog database - get all vf module customizations");
3090 String hql = "FROM VfModuleCustomization";
3091 Query query = getSession ().createQuery (hql);
3093 List <VfModuleCustomization> result = query.list ();
3094 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModuleCustomizations", null);
3100 * Return all HeatEnvironment in the Catalog DB
3102 * @return A list of HeatEnvironment objects
3104 @SuppressWarnings("unchecked")
3105 public List <HeatEnvironment> getAllHeatEnvironment () {
3107 long startTime = System.currentTimeMillis ();
3108 LOGGER.debug ("Catalog database - get all Heat environments");
3110 String hql = "FROM HeatEnvironment";
3111 Query query = getSession ().createQuery (hql);
3113 List <HeatEnvironment> result = query.list ();
3114 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
3119 * Fetch the Environment by Environment ID - 1510
3121 @Deprecated // no longer in heat envt table
3122 public HeatEnvironment getHeatEnvironment (int id) {
3124 long startTime = System.currentTimeMillis ();
3125 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
3127 String hql = "FROM HeatEnvironment WHERE id = :idValue";
3129 LOGGER.debug ("getHeatEnvironment called with id=" + id);
3131 Query query = getSession ().createQuery (hql);
3132 query.setParameter ("idValue", id);
3134 @SuppressWarnings("unchecked")
3135 List <HeatEnvironment> resultList = query.list ();
3137 // See if something came back.
3138 if (resultList.isEmpty ()) {
3139 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
3142 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
3143 return resultList.get (0);
3147 * Fetch the nested templates - 1510
3151 public Map <String, Object> getNestedTemplates (int templateId) {
3152 Map <String, Object> nestedTemplates;
3153 long startTime = System.currentTimeMillis ();
3154 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
3156 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
3158 Query query = getSession ().createQuery (hql);
3159 query.setParameter ("parentIdValue", templateId);
3161 @SuppressWarnings("unchecked")
3162 List <HeatNestedTemplate> resultList = query.list ();
3163 // If nothing comes back, there are no nested templates
3164 if (resultList.isEmpty ()) {
3165 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3166 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
3169 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3170 nestedTemplates = new HashMap <> ();
3171 for (HeatNestedTemplate hnt : resultList) {
3172 LOGGER.debug ("Querying for " + hnt);
3173 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
3175 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3178 String providerResourceFile = hnt.getProviderResourceFile ();
3179 String heatTemplateBody = ht.getTemplateBody ();
3180 if (providerResourceFile != null && heatTemplateBody != null) {
3181 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3183 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3186 // Make sure we're not returning an empty map - if so, just return null
3187 if (nestedTemplates.isEmpty ()) {
3188 LOGGER.debug ("nestedTemplates is empty - just return null");
3189 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3192 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3193 return nestedTemplates;
3196 * Return a Map<String, Object> for returning the child templates and their contents
3198 * @param parentHeatTemplateId
3199 * @return Map<String,Object> or null if none found
3201 public Map <String, Object> getNestedTemplates (String parentHeatTemplateId) {
3202 Map <String, Object> nestedTemplates;
3203 long startTime = System.currentTimeMillis ();
3204 LOGGER.debug ("Catalog database - getNestedTemplates called with parentTemplateId " + parentHeatTemplateId);
3206 String hql = "FROM HeatNestedTemplate where parentTemplateId = :parentHeatTemplateId";
3208 Query query = getSession ().createQuery (hql);
3209 query.setParameter ("parentHeatTemplateId", parentHeatTemplateId);
3211 @SuppressWarnings("unchecked")
3212 List <HeatNestedTemplate> resultList = query.list ();
3213 // If nothing comes back, there are no nested templates
3214 if (resultList.isEmpty ()) {
3215 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3216 LOGGER.debug ("No nestedTemplates found for templateId=" + parentHeatTemplateId + ", " + hql);
3219 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3220 nestedTemplates = new HashMap <> ();
3221 for (HeatNestedTemplate hnt : resultList) {
3222 LOGGER.debug ("Querying for " + hnt);
3223 HeatTemplate ht = this.getHeatTemplateByArtifactUuid (hnt.getChildTemplateId ());
3225 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3228 String providerResourceFile = hnt.getProviderResourceFile ();
3229 String heatTemplateBody = ht.getTemplateBody ();
3230 if (providerResourceFile != null && heatTemplateBody != null) {
3231 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3233 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3236 // Make sure we're not returning an empty map - if so, just return null
3237 if (nestedTemplates.isEmpty ()) {
3238 LOGGER.debug ("nestedTemplates is empty - just return null");
3239 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3242 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3243 return nestedTemplates;
3247 * Fetch any files in the HEAT_FILES table 1510
3250 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
3251 Map <String, HeatFiles> heatFiles;
3253 long startTime = System.currentTimeMillis ();
3254 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
3255 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
3257 Query query = getSession ().createQuery (hql);
3258 query.setParameter ("vnfResourceIdValue", vnfResourceId);
3260 @SuppressWarnings("unchecked")
3261 List <HeatFiles> resultList = query.list ();
3262 // If nothing comes back, there are no heat files
3263 if (resultList.isEmpty ()) {
3264 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
3265 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
3268 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
3269 heatFiles = new HashMap <> ();
3270 for (HeatFiles hf : resultList) {
3271 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
3272 heatFiles.put (hf.getFileName (), hf);
3274 // Make sure we're not returning an empty map - if so, just return null
3275 if (heatFiles.isEmpty ()) {
3276 LOGGER.debug ("heatFiles is empty - just return null");
3277 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
3280 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
3284 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
3286 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
3288 Map <String, HeatFiles> heatFiles = null;
3290 long startTime = System.currentTimeMillis ();
3291 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
3292 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
3294 Query query = getSession ().createQuery (hql);
3295 query.setParameter ("vfModuleIdValue", vfModuleId);
3297 List<VfModuleToHeatFiles> mapList = query.list();
3298 if (mapList.isEmpty()) {
3299 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
3300 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3303 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3304 heatFiles = new HashMap<String, HeatFiles>();
3305 for (VfModuleToHeatFiles vmthf : mapList) {
3306 int heatFilesId = vmthf.getHeatFilesId();
3307 hql = "FROM HeatFiles where id = :id_value";
3308 query = getSession().createQuery(hql);
3309 query.setParameter("id_value", heatFilesId);
3310 List<HeatFiles> fileList = query.list();
3311 if (fileList.isEmpty()) {
3312 // Should this throw an exception??
3313 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
3314 String errorString = "_ERROR|" + heatFilesId;
3315 // The receiving code needs to know to throw an exception for this - or ignore it.
3316 heatFiles.put(errorString, null);
3318 // Should only ever have 1 result - add it to our Map
3319 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
3320 for (HeatFiles hf : fileList) {
3321 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3322 heatFiles.put(hf.getFileName(), hf);
3326 if (heatFiles.isEmpty()) {
3327 LOGGER.debug ("heatFiles is empty - just return null");
3328 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3331 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3338 * Return a VfModuleToHeatFiles object
3340 * @param vfModuleModelUuid, heatFilesArtifactUuid
3341 * @return VfModuleToHeatFiles or null if none found
3343 public VfModuleToHeatFiles getVfModuleToHeatFilesEntry(String vfModuleModelUuid, String heatFilesArtifactUuid) {
3345 LOGGER.debug ("Catalog database - getVfModuleToHeatFilesEntry with vfModuleModelUuid " + vfModuleModelUuid + ", heatFilesArtifactUuid=" + heatFilesArtifactUuid);
3346 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue and heatFilesArtifactUuid = :heatFilesArtifactUuidValue";
3348 HashMap<String, String> parameters = new HashMap<>();
3349 parameters.put("vfModuleModelUuidValue", vfModuleModelUuid);
3350 parameters.put("heatFilesArtifactUuidValue", heatFilesArtifactUuid);
3352 VfModuleToHeatFiles vmthf = null;
3355 vmthf = this.executeQuerySingleRow(hql, parameters, true);
3356 } catch (Exception e) {
3364 * Return a ServiceToResourceCustomization object
3366 * @param serviceModelUuid
3367 * @param resourceModelCustomizationUuid
3369 * @return VfModuleToHeatFiles or null if none found
3371 public ServiceToResourceCustomization getServiceToResourceCustomization(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
3373 LOGGER.debug ("Catalog database - getServiceToResourceCustomization with serviceModelUuid=" + serviceModelUuid + ", resourceModelCustomizationUuid=" + resourceModelCustomizationUuid + ", modelType=" + modelType);
3374 String hql = "FROM ServiceToResourceCustomization where serviceModelUUID = :serviceModelUuidValue and resourceModelCustomizationUUID = :resourceModelCustomizationUuidValue and modelType = :modelTypeValue ";
3376 HashMap<String, String> parameters = new HashMap<>();
3377 parameters.put("serviceModelUuidValue", serviceModelUuid);
3378 parameters.put("resourceModelCustomizationUuidValue", resourceModelCustomizationUuid);
3379 parameters.put("modelTypeValue", modelType);
3381 ServiceToResourceCustomization strc = null;
3384 strc = this.executeQuerySingleRow(hql, parameters, true);
3385 } catch (Exception e) {
3392 * Return a Map<String, HeatFiles> for returning the heat files associated with a vfModule 1707
3394 * @param vfModuleModelUuid
3395 * @return Map<String,Object> or null if none found
3397 public Map <String, HeatFiles> getHeatFilesForVfModule(String vfModuleModelUuid) {
3398 Map <String, HeatFiles> heatFiles;
3400 long startTime = System.currentTimeMillis ();
3401 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleModelUuid " + vfModuleModelUuid);
3402 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue";
3404 Query query = getSession ().createQuery (hql);
3405 query.setParameter ("vfModuleModelUuidValue", vfModuleModelUuid);
3407 @SuppressWarnings("unchecked")
3408 List<VfModuleToHeatFiles> mapList = query.list();
3409 if (mapList.isEmpty()) {
3410 LOGGER.debug ("No heatFiles found for vfModuleModelUuid=" + vfModuleModelUuid);
3411 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3414 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3415 heatFiles = new HashMap<>();
3416 for (VfModuleToHeatFiles vmthf : mapList) {
3417 String heatFilesUuid = vmthf.getHeatFilesArtifactUuid();
3418 hql = "FROM HeatFiles where artifactUuid = :heatFilesUuidValue";
3419 query = getSession().createQuery(hql);
3420 query.setParameter("heatFilesUuidValue", heatFilesUuid);
3421 @SuppressWarnings("unchecked")
3422 List<HeatFiles> fileList = query.list();
3423 if (fileList.isEmpty()) {
3424 // Should this throw an exception??
3425 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesUuid);
3426 String errorString = "_ERROR|" + heatFilesUuid;
3427 // The receiving code needs to know to throw an exception for this - or ignore it.
3428 heatFiles.put(errorString, null);
3430 // Should only ever have 1 result - add it to our Map
3431 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesUuid);
3432 for (HeatFiles hf : fileList) {
3433 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3434 heatFiles.put(hf.getFileName(), hf);
3438 if (heatFiles.isEmpty()) {
3439 LOGGER.debug ("heatFiles is empty - just return null");
3440 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3443 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3448 * Get the heat template object based on asdc attributes
3450 * @param templateName The template name, generally the yaml filename. "example.yaml"
3451 * @param version The version as specified by ASDC. "1.1"
3452 * @param asdcResourceName The ASDC resource name provided in the ASDC artifact
3454 * @return The HeatTemplate
3456 @Deprecated // asdcResourceName is no longer in heatTeamplate
3457 public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
3459 long startTime = System.currentTimeMillis ();
3460 LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
3463 + " and ASDC resource name "
3464 + asdcResourceName);
3466 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
3467 Query query = getSession ().createQuery (hql);
3468 query.setParameter ("template_name", templateName);
3469 query.setParameter ("version", version);
3470 query.setParameter ("asdcResourceName", asdcResourceName);
3472 @SuppressWarnings("unchecked")
3473 List <HeatTemplate> resultList = query.list ();
3475 // See if something came back.
3476 if (resultList.isEmpty ()) {
3477 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
3480 // Name + Version is unique, so should only be one element
3481 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3482 return resultList.get (0);
3487 * Save the Heat Template
3489 * @param heat The heat template
3490 * @param paramSet The list of heat template parameters
3492 public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
3494 long startTime = System.currentTimeMillis ();
3495 LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName() + ", artifactUUID=" + heat.getArtifactUuid());
3497 heat.setParameters(null);
3500 HeatTemplate heatTemp = this.getHeatTemplateByArtifactUuidRegularQuery(heat.getArtifactUuid());
3502 if (heatTemp == null) {
3503 this.getSession ().save (heat);
3505 if (paramSet != null) {
3506 StringBuilder sb = new StringBuilder("Parameters: ");
3507 for (HeatTemplateParam param : paramSet) {
3508 param.setHeatTemplateArtifactUuid(heat.getArtifactUuid());
3509 sb.append(param.getParamName()).append(", ");
3511 LOGGER.debug(sb.toString());
3512 heat.setParameters (paramSet);
3514 Session session = this.getSession();
3515 if (!(session.isConnected() && session.isOpen())) {
3516 LOGGER.debug("Initial session is not connected or open - get another");
3517 session = this.getSession();
3520 } catch (HibernateException he1) {
3521 LOGGER.debug("Hibernate Exception encountered on first attempt at save(heat) - try again..." + he1.getMessage(), he1);
3523 Session session = this.getSession();
3525 } catch (HibernateException he2) {
3526 LOGGER.debug("Hibernate Exception encountered on second attempt at save(heat)" + he2.getMessage());
3527 LOGGER.debug(Arrays.toString(he2.getStackTrace()));
3529 } catch (Exception e2) {
3530 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(),e2);
3531 LOGGER.debug(Arrays.toString(e2.getStackTrace()));
3535 } catch (Exception e1) {
3536 LOGGER.debug("General Exception encountered on first attempt at save(heat) - try again..." + e1.getMessage(), e1);
3537 LOGGER.debug(Arrays.toString(e1.getStackTrace()));
3539 Session session = this.getSession();
3541 } catch (HibernateException he2) {
3542 LOGGER.debug("General Exception encountered on second attempt at save(heat)" + he2.getMessage(), he2);
3543 LOGGER.debug(Arrays.toString(he2.getStackTrace()));
3545 } catch (Exception e2) {
3546 LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(), e2);
3547 LOGGER.debug(Arrays.toString(e2.getStackTrace()));
3554 heat.setArtifactUuid(heatTemp.getArtifactUuid());
3557 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3562 * Retrieves a Heat environment from DB based on its unique key.
3564 * @param name the environment artifact name
3565 * @param version the environment resource version
3566 * @param asdcResourceName the environment resource name
3567 * @return the heat environment from DB or null if not found
3570 public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
3571 long startTime = System.currentTimeMillis ();
3572 LOGGER.debug ("Catalog database - get Heat environment with name " + name
3575 + " and ASDC resource name "
3576 + asdcResourceName);
3578 String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
3579 Query query = getSession ().createQuery (hql);
3580 query.setParameter ("name", name);
3581 query.setParameter ("version", version);
3582 query.setParameter ("asdcResourceName", asdcResourceName);
3583 HeatEnvironment env = null;
3585 env = (HeatEnvironment) query.uniqueResult ();
3586 } catch (org.hibernate.NonUniqueResultException nure) {
3587 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + name + "', version='" + version + "' and asdcResourceName=" + asdcResourceName, nure);
3588 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);
3590 } catch (org.hibernate.HibernateException he) {
3591 LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, he);
3592 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);
3594 } catch (Exception e) {
3595 LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, e);
3596 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);
3600 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3602 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3608 * Retrieves a Heat environment from DB based on its unique key. 1707
3610 * @param artifactUuid the environment artifact name
3611 * @param version the environment resource version
3612 * @return the heat environment from DB or null if not found
3614 public HeatEnvironment getHeatEnvironment (String artifactUuid, String version) {
3615 long startTime = System.currentTimeMillis ();
3616 LOGGER.debug ("Catalog database - get Heat environment with uuid " + artifactUuid
3620 String hql = "FROM HeatEnvironment WHERE artifactUuid=:artifactUuid AND version=:version";
3621 Query query = getSession ().createQuery (hql);
3622 query.setParameter ("artifactUuid", artifactUuid);
3623 query.setParameter ("version", version);
3624 HeatEnvironment env = null;
3626 env = (HeatEnvironment) query.uniqueResult ();
3627 } catch (org.hibernate.NonUniqueResultException nure) {
3628 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + artifactUuid + "', version='" + version);
3629 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "non unique result for ArtifactUUID=" + artifactUuid);
3631 } catch (org.hibernate.HibernateException he) {
3632 LOGGER.debug("Hibernate Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + he.getMessage() );
3633 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUUID=" + artifactUuid + " and version=" + version , "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUUID=" + artifactUuid);
3635 } catch (Exception e) {
3636 LOGGER.debug("Generic Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + e.getMessage());
3637 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUUID=" + artifactUuid);
3641 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
3643 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
3649 * Save the HeatEnvironment
3651 * @param env The Environment
3653 public void saveHeatEnvironment (HeatEnvironment env) {
3654 long startTime = System.currentTimeMillis ();
3655 LOGGER.debug ("Catalog database - save Heat environment with name "
3656 + env.getEnvironment() + " and ArtifactUUID " + env.getArtifactUuid());
3658 HeatEnvironment dbEnv = getHeatEnvironment (env.getArtifactUuid(), env.getVersion ());
3659 if (dbEnv == null) {
3661 this.getSession ().save (env);
3664 env.setArtifactUuid(dbEnv.getArtifactUuid());
3668 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3673 * Save the heatTemplate
3675 * @param heat The heat template
3677 public void saveHeatTemplate (HeatTemplate heat) {
3678 long startTime = System.currentTimeMillis ();
3679 LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
3681 this.getSession ().update (heat);
3683 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
3687 public void saveHeatFile (HeatFiles heatFile) {
3688 long startTime = System.currentTimeMillis ();
3689 LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
3691 this.getSession ().save (heatFile);
3693 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
3697 public void saveVnfRecipe (VnfRecipe vnfRecipe) {
3698 long startTime = System.currentTimeMillis ();
3699 LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
3701 this.getSession ().save (vnfRecipe);
3703 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
3707 public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
3708 long startTime = System.currentTimeMillis ();
3709 LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
3711 this.getSession ().save (vnfComponentsRecipe);
3713 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
3718 public void saveOrUpdateVnfResource (VnfResource vnfResource) {
3719 long startTime = System.currentTimeMillis ();
3720 LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getModelName());
3723 VnfResource existing = this.getVnfResourceByModelUuid(vnfResource.getModelUuid());
3724 if (existing == null) {
3725 LOGGER.debug("No existing entry found - attempting to save...");
3726 this.getSession ().save (vnfResource);
3728 LOGGER.debug("Existing vnf resource found!");
3732 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
3736 public boolean saveVnfResourceCustomization (VnfResourceCustomization vnfResourceCustomization) {
3737 long startTime = System.currentTimeMillis ();
3738 LOGGER.debug ("Catalog database - save VNF Resource Customization with Name " + vnfResourceCustomization.getModelInstanceName());
3740 LOGGER.debug(vnfResourceCustomization.toString());
3741 } catch (Exception e) {
3742 LOGGER.debug("Unable to print VRC " + e.getMessage(), e);
3745 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3746 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3747 // Do any matching customization records exist?
3748 // if(networkResourceList.size() == 0){
3750 // networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUuid());
3751 // this.getSession().flush();
3752 // this.getSession().clear();
3754 VnfResourceCustomization existing = this.getVnfResourceCustomizationByModelCustomizationUuid(vnfResourceCustomization.getModelCustomizationUuid());
3756 if (existing == null) {
3757 LOGGER.debug("No existing entry found...attempting to save...");
3758 this.getSession ().save (vnfResourceCustomization);
3762 LOGGER.debug("Existing VRC entry found\n" + existing.toString());
3763 } catch (Exception e) {
3764 LOGGER.debug("Unable to print VRC2 " + e.getMessage(), e);
3770 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceCustomization", null);
3774 public void saveAllottedResourceCustomization (AllottedResourceCustomization resourceCustomization) {
3775 long startTime = System.currentTimeMillis ();
3776 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + resourceCustomization.getModelInstanceName());
3778 List<AllottedResourceCustomization> allottedResourcesList = getAllAllottedResourcesByArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
3780 if(allottedResourcesList.isEmpty()){
3781 this.getSession ().save(resourceCustomization);
3785 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3789 public void saveAllottedResource (AllottedResource allottedResource) {
3790 long startTime = System.currentTimeMillis ();
3791 LOGGER.debug ("Catalog database - save Allotted Resource with Name " + allottedResource.getModelName());
3793 AllottedResource existing = this.getAllottedResourceByModelUuid(allottedResource.getModelUuid());
3794 if (existing == null) {
3795 this.getSession ().save (allottedResource);
3797 LOGGER.debug("Found existing allottedResource with this modelUuid - no need to save");
3801 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
3805 public void saveNetworkResource (NetworkResource networkResource) throws RecordNotFoundException {
3806 long startTime = System.currentTimeMillis ();
3807 LOGGER.debug ("Catalog database - save Network Resource with Network Name " + networkResource.getModelName());
3809 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3810 // List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3811 // Do any matching customization records exist?
3812 if(getNetworkResourceByModelUuid(networkResource.getModelUUID()) == null){
3813 this.getSession ().save(networkResource);
3818 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3822 public void saveToscaCsar (ToscaCsar toscaCsar) throws RecordNotFoundException {
3825 long startTime = System.currentTimeMillis ();
3826 LOGGER.debug ("Catalog database - save Tosca Csar with Name " + toscaCsar.getName());
3829 if(getToscaCsar(toscaCsar.getArtifactChecksum()) == null){
3830 this.getSession ().save (toscaCsar);
3832 LOGGER.debug("Temporarily disabling saveToscaCsar pending further investigation 2017-06-02");
3835 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveToscaCsar", null);
3841 * Return the newest version of a specific Tosca CSAR Record resource (queried by Name).
3843 * @param artifactChecksum
3844 * @return ToscaCsar object or null if none found
3846 public ToscaCsar getToscaCsar (String artifactChecksum) {
3848 long startTime = System.currentTimeMillis ();
3849 LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactChecksum " + artifactChecksum);
3851 String hql = "FROM ToscaCsar WHERE artifactChecksum = :artifactChecksum";
3852 Query query = getSession ().createQuery (hql);
3853 query.setParameter ("artifactChecksum", artifactChecksum);
3855 @SuppressWarnings("unchecked")
3856 List <ToscaCsar> resultList = query.list ();
3858 // See if something came back. Name is unique, so
3859 if (resultList.isEmpty ()) {
3860 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsar", null);
3864 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsar", null);
3865 return resultList.get (0);
3869 * Return a specific Tosca CSAR Record resource (queried by atrifact uuid).
3871 * @param toscaCsarArtifactUUID the artifact uuid of the tosca csar
3872 * @return ToscaCsar object or null if none found
3874 public ToscaCsar getToscaCsarByUUID(String toscaCsarArtifactUUID){
3875 long startTime = System.currentTimeMillis ();
3876 LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactUUID " + toscaCsarArtifactUUID);
3878 String hql = "FROM ToscaCsar WHERE artifactUUID = :toscaCsarArtifactUUID";
3879 Query query = getSession ().createQuery (hql);
3880 query.setParameter ("toscaCsarArtifactUUID", toscaCsarArtifactUUID);
3882 @SuppressWarnings("unchecked")
3883 List <ToscaCsar> resultList = query.list ();
3885 // See if something came back. Name is unique, so
3886 if (resultList.isEmpty ()) {
3887 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsarByUUID", null);
3891 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsarByUUID", null);
3892 return resultList.get (0);
3896 * Return a specific Tosca CSAR Record resource (queried by service model uuid).
3899 * @param serviceModelUUID the service model uuid
3900 * @return ToscaCsar object or null if none found
3901 * @since ONAP Beijing Release
3903 public ToscaCsar getToscaCsarByServiceModelUUID(String serviceModelUUID){
3904 long startTime = System.currentTimeMillis ();
3905 LOGGER.debug ("Catalog database - get Tosca CSAR record with serviceModelUUID " + serviceModelUUID);
3906 Service service = getServiceByModelUUID(serviceModelUUID);
3907 if(null == service){
3908 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Service not found", "CatalogDB", "getToscaCsarByServiceModelUUID", null);
3911 ToscaCsar csar = getToscaCsarByUUID(service.getToscaCsarArtifactUUID());
3913 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Tosca csar of the service not found", "CatalogDB", "getToscaCsarByServiceModelUUID", null);
3916 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsarByServiceModelUUID", null);
3920 public void saveTempNetworkHeatTemplateLookup (TempNetworkHeatTemplateLookup tempNetworkHeatTemplateLookup) {
3921 long startTime = System.currentTimeMillis ();
3922 LOGGER.debug ("Catalog database - save TempNetworkHeatTemplateLookup with Network Model Name " + tempNetworkHeatTemplateLookup.getNetworkResourceModelName() +
3923 " and Heat Template Artifact UUID " + tempNetworkHeatTemplateLookup.getHeatTemplateArtifactUuid());
3925 this.getSession ().save (tempNetworkHeatTemplateLookup);
3928 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveTempNetworkHeatTemplateLookup", null);
3932 public void saveVfModuleToHeatFiles (VfModuleToHeatFiles vfModuleToHeatFiles) {
3933 long startTime = System.currentTimeMillis ();
3934 LOGGER.debug ("Catalog database - save VfModuleToHeatFiles with VF Module UUID " + vfModuleToHeatFiles.getVfModuleModelUuid() +
3935 " and Heat Files Artifact UUID " + vfModuleToHeatFiles.getHeatFilesArtifactUuid());
3938 this.getSession ().save (vfModuleToHeatFiles);
3941 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVFModuleToHeatFiles", null);
3945 public void saveVnfResourceToVfModuleCustomization(VnfResourceCustomization vnfResourceCustomizationUUID, VfModuleCustomization vfModuleCustomizationUUID) throws RecordNotFoundException {
3946 long startTime = System.currentTimeMillis ();
3947 VnfResCustomToVfModuleCustom vnfResCustomToVfModuleCustom = new VnfResCustomToVfModuleCustom();
3949 if(vnfResourceCustomizationUUID != null && vfModuleCustomizationUUID != null){
3950 vnfResCustomToVfModuleCustom.setVnfResourceCustModelCustomizationUuid(vnfResourceCustomizationUUID.getModelCustomizationUuid());
3951 vnfResCustomToVfModuleCustom.setVfModuleCustModelCustomizationUuid(vfModuleCustomizationUUID.getModelCustomizationUuid());
3952 String vnfId = vnfResourceCustomizationUUID.getModelCustomizationUuid();
3953 String vfId = vfModuleCustomizationUUID.getModelCustomizationUuid();
3954 LOGGER.debug ("Catalog database - save VnfResCustomToVfModuleCustom with vnf=" + vnfId + ", vf=" + vfId);
3956 VnfResCustomToVfModuleCustom existing = this.getVnfResCustomToVfModule(vnfId, vfId);
3957 if (existing == null) {
3958 LOGGER.debug("No existing entry found - will now try to save");
3959 this.getSession ().save (vnfResCustomToVfModuleCustom);
3961 LOGGER.debug("Existing entry already found - no save needed");
3964 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceToVfModuleCustomization", null);
3969 public void saveNetworkResourceCustomization (NetworkResourceCustomization networkResourceCustomization) throws RecordNotFoundException {
3970 long startTime = System.currentTimeMillis ();
3971 LOGGER.debug ("Catalog database - save Network Resource Customization with Network Name " + networkResourceCustomization.getModelInstanceName());
3973 // Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
3974 List<NetworkResourceCustomization> networkResourceCustomizationList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
3975 // Do any matching customization records exist?
3976 if(networkResourceCustomizationList.isEmpty()){
3978 // Retreive the record from the Network_Resource table associated to the Customization record based on ModelName
3979 // ?? is it modelInstanceName with 1707?
3980 NetworkResource networkResource = getNetworkResource(networkResourceCustomization.getModelInstanceName());
3982 if(networkResource == null){
3983 throw new RecordNotFoundException("No record found in NETWORK_RESOURCE table for model name " + networkResourceCustomization.getModelInstanceName());
3986 networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUUID());
3988 this.getSession ().save(networkResourceCustomization);
3993 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
3997 @Deprecated // table is gone - mapped to ServiceToResource
3998 public void saveServiceToNetworks (ServiceToNetworks serviceToNetworks) {
3999 long startTime = System.currentTimeMillis ();
4000 LOGGER.debug ("Catalog database - save to ServiceToNetworks table with NetworkModelCustomizationUUID of " + serviceToNetworks.getNetworkModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToNetworks.getServiceModelUuid());
4002 this.getSession ().save(serviceToNetworks);
4005 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
4009 public void saveServiceToResourceCustomization(ServiceToResourceCustomization serviceToResource) {
4010 long startTime = System.currentTimeMillis ();
4011 LOGGER.debug ("Catalog database - save to ServiceToResourceCustomization table with ServiceModelUuid of " + serviceToResource.getServiceModelUUID() + ", ResourceModelUUID of " + serviceToResource.getResourceModelCustomizationUUID() + " and model_type=" + serviceToResource.getModelType());
4012 ServiceToResourceCustomization strc = this.getServiceToResourceCustomization(serviceToResource.getServiceModelUUID(), serviceToResource.getResourceModelCustomizationUUID(), serviceToResource.getModelType());
4015 LOGGER.debug("**This ServiceToResourceCustomization record already exists - no need to save");
4017 this.getSession ().save(serviceToResource);
4020 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToResourceCustomization", null);
4024 @Deprecated // table is gone - mapped to ServiceToResourceCustomization
4025 public void saveServiceToAllottedResources (ServiceToAllottedResources serviceToAllottedResources) {
4026 long startTime = System.currentTimeMillis ();
4027 LOGGER.debug ("Catalog database - save to serviceToAllottedResources table with ARModelCustomizationUUID of " + serviceToAllottedResources.getArModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToAllottedResources.getServiceModelUuid());
4029 this.getSession ().save(serviceToAllottedResources);
4032 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToAllottedResources", null);
4036 public void saveService (Service service) {
4037 long startTime = System.currentTimeMillis ();
4038 LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getModelName()+"/"+service.getVersion()+"/"+service.getModelUUID());
4040 Service serviceInvariantDB = null;
4041 // Retrieve existing service record by nameVersionId
4042 Service serviceDB = this.getServiceByModelUUID(service.getModelUUID());
4043 if (serviceDB == null) {
4044 // 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.
4045 serviceInvariantDB = this.getServiceByInvariantUUID(service.getModelInvariantUUID());
4046 // Save the new Service record
4047 this.getSession ().save (service);
4050 if(serviceInvariantDB != null){ // existing modelInvariantId was found.
4051 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
4052 List<ServiceRecipe> serviceRecipes = getServiceRecipes(serviceInvariantDB.getModelUUID());
4054 if(serviceRecipes != null && ! serviceRecipes.isEmpty()){
4055 for(ServiceRecipe serviceRecipe : serviceRecipes){
4056 if(serviceRecipe != null){
4057 // 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.
4058 Service newService = this.getServiceByModelUUID(service.getModelUUID());
4059 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
4060 ServiceRecipe newServiceRecipe = new ServiceRecipe();
4061 newServiceRecipe.setAction(serviceRecipe.getAction());
4062 newServiceRecipe.setDescription(serviceRecipe.getDescription());
4063 newServiceRecipe.setOrchestrationUri(serviceRecipe.getOrchestrationUri());
4064 newServiceRecipe.setRecipeTimeout(serviceRecipe.getRecipeTimeout());
4065 newServiceRecipe.setServiceParamXSD(serviceRecipe.getServiceParamXSD());
4066 newServiceRecipe.setServiceModelUUID(newService.getModelUUID());
4067 newServiceRecipe.setVersion(serviceRecipe.getVersion());
4068 // Check recipe does not exist before inserting
4069 ServiceRecipe recipe = getServiceRecipeByModelUUID(newServiceRecipe.getServiceModelUUID(), newServiceRecipe.getAction());
4070 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
4072 this.getSession ().save (newServiceRecipe);
4081 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
4085 public void saveOrUpdateVfModule (VfModule vfModule) {
4086 long startTime = System.currentTimeMillis ();
4087 LOGGER.debug ("Catalog database - save or update VF Module with VF Model Name " + vfModule.getModelName());
4088 VfModule vfModuleInvariantDB = null;
4090 LOGGER.debug("heat template id = " + vfModule.getHeatTemplateArtifactUUId() + ", vol template id = "+ vfModule.getVolHeatTemplateArtifactUUId());
4091 LOGGER.debug(vfModule.toString());
4092 } catch (Exception e) {
4093 LOGGER.debug("unable to print vfmodule " + e.getMessage(), e);
4096 VfModule existing = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4097 if (existing == null) {
4098 // 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.
4099 vfModuleInvariantDB = this.getVfModuleByModelInvariantUuid(vfModule.getModelInvariantUUID());
4100 LOGGER.debug("No existing entry found, attempting to save...");
4101 this.getSession ().save (vfModule);
4104 LOGGER.debug("Found an existing vf module!\n" + existing.toString());
4105 } catch (Exception e) {
4106 LOGGER.debug("unable to print vfmodule2 " + e.getMessage(), e);
4110 if(vfModuleInvariantDB != null){ // existing modelInvariantId was found.
4111 // copy the recipe record with the matching invariant id. We will duplicate this for the new service record
4112 List<VnfComponentsRecipe> vfRecipes = getVnfComponentRecipes(vfModuleInvariantDB.getModelUUID());
4115 if(vfRecipes != null && ! vfRecipes.isEmpty()){
4116 for(VnfComponentsRecipe vfRecipe : vfRecipes){
4117 if(vfRecipe != null){
4118 // 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.
4119 VfModule newRecipe = this.getVfModuleByModelUUID(vfModule.getModelUUID());
4120 // Create a new ServiceRecipe record based on the existing one we just copied from the DB.
4121 VnfComponentsRecipe newVnfRecipe = new VnfComponentsRecipe();
4122 newVnfRecipe.setAction(vfRecipe.getAction());
4123 newVnfRecipe.setDescription(vfRecipe.getDescription());
4124 newVnfRecipe.setOrchestrationUri(vfRecipe.getOrchestrationUri());
4125 newVnfRecipe.setRecipeTimeout(vfRecipe.getRecipeTimeout());
4126 newVnfRecipe.setParamXSD(vfRecipe.getParamXSD());
4127 newVnfRecipe.setVfModuleModelUUId(newRecipe.getModelUUID());
4128 newVnfRecipe.setVersion(vfRecipe.getVersion());
4129 newVnfRecipe.setVnfComponentType(vfRecipe.getVnfComponentType());
4130 newVnfRecipe.setVnfType(vfRecipe.getVnfType());
4131 // Check recipe does not exist before inserting
4132 // VnfComponentsRecipe recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4133 List<VnfComponentsRecipe> recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
4134 // Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
4135 // if(recipe == null){
4136 this.getSession ().save (newVnfRecipe);
4145 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
4149 public void saveOrUpdateVfModuleCustomization (VfModuleCustomization vfModuleCustomization) {
4150 long startTime = System.currentTimeMillis ();
4151 LOGGER.debug ("Catalog database - save VF Module Customization with VF Customization Model Name UUID " + vfModuleCustomization.getVfModuleModelUuid());
4153 LOGGER.debug("env id = " + vfModuleCustomization.getHeatEnvironmentArtifactUuid() + ", vol Env=" + vfModuleCustomization.getVolEnvironmentArtifactUuid());
4154 LOGGER.debug(vfModuleCustomization.toString());
4155 } catch (Exception e) {
4156 LOGGER.debug("unable to print vfmodulecust " + e.getMessage(), e);
4159 VfModuleCustomization existing = this.getVfModuleCustomizationByModelCustomizationId(vfModuleCustomization.getModelCustomizationUuid());
4160 if (existing == null) {
4161 LOGGER.debug("No existing entry found, attempting to save...");
4162 this.getSession ().save (vfModuleCustomization);
4165 LOGGER.debug("Found an existing vf module customization entry\n" + existing.toString());
4166 } catch (Exception e) {
4167 LOGGER.debug("unable to print vfmodulecust2 " + e.getMessage(), e);
4172 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModuleCustomization", null);
4177 public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
4178 long startTime = System.currentTimeMillis ();
4179 LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
4180 + parentTemplateId +"-"+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 HeatNestedTemplate getNestedHeatTemplate(String parentTemplateId, String childTemplateId) {
4194 long startTime = System.currentTimeMillis ();
4195 LOGGER.debug ("Catalog database - get nested Heat template with PerentId="
4196 + parentTemplateId +", ChildId="+childTemplateId);
4198 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4199 nestedTemplate.setParentTemplateId (parentTemplateId);
4200 nestedTemplate.setChildTemplateId (childTemplateId);
4202 return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
4204 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
4209 public void saveNestedHeatTemplate (String parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4210 long startTime = System.currentTimeMillis ();
4211 LOGGER.debug ("Catalog database - save nested Heat template with name "
4212 + childTemplate.getTemplateName () + ",parentId=" + parentTemplateId + ",childId=" + childTemplate.getArtifactUuid() + ", providerResourceFile=" + yamlFile);
4215 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4216 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getArtifactUuid()) == null) {
4217 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4218 nestedTemplate.setParentTemplateId (parentTemplateId);
4219 nestedTemplate.setChildTemplateId (childTemplate.getArtifactUuid ());
4220 nestedTemplate.setProviderResourceFile (yamlFile);
4222 session.save (nestedTemplate);
4225 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4230 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
4231 long startTime = System.currentTimeMillis ();
4232 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
4233 + " and vnfResourceID "
4235 // + " and ASDC resource name "
4240 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
4241 Query query = getSession ().createQuery (hql);
4242 query.setParameter ("fileName", fileName);
4243 query.setParameter ("vnfResourceId", vnfResourceId);
4244 query.setParameter ("asdcResourceName", asdcResourceName);
4245 query.setParameter ("version", version);
4247 @SuppressWarnings("unchecked")
4249 HeatFiles heatFilesResult = null;
4251 heatFilesResult = (HeatFiles) query.uniqueResult ();
4252 } catch (org.hibernate.NonUniqueResultException nure) {
4253 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);
4254 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);
4256 } catch (org.hibernate.HibernateException he) {
4257 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + he.getMessage());
4258 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);
4260 } catch (Exception e) {
4261 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + e.getMessage());
4262 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);
4266 // See if something came back.
4267 if (heatFilesResult == null) {
4268 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4271 // Name + Version is unique, so should only be one element
4272 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4273 return heatFilesResult;
4276 public HeatFiles getHeatFiles(String artifactUuid) {
4277 long startTime = System.currentTimeMillis ();
4278 LOGGER.debug ("Catalog database - getHeatFiles with artifactUuid " + artifactUuid);
4280 String hql = "FROM HeatFiles WHERE artifactUuid = :artifactUuid";
4281 Query query = getSession ().createQuery (hql);
4282 query.setParameter ("artifactUuid", artifactUuid);
4284 @SuppressWarnings("unchecked")
4286 HeatFiles heatFilesResult = null;
4288 heatFilesResult = (HeatFiles) query.uniqueResult ();
4289 } catch (org.hibernate.NonUniqueResultException nure) {
4290 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: artifactUuid='" + artifactUuid );
4291 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid=" + artifactUuid);
4293 } catch (org.hibernate.HibernateException he) {
4294 LOGGER.debug("Hibernate Exception - while searching for: artifactUuid='" + artifactUuid + " " + he.getMessage());
4295 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + artifactUuid);
4297 } catch (Exception e) {
4298 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + " " + e.getMessage());
4299 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUuid=" + artifactUuid , "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + artifactUuid);
4303 // See if something came back.
4304 if (heatFilesResult == null) {
4305 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4308 // Name + Version is unique, so should only be one element
4309 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4310 return heatFilesResult;
4313 public void saveHeatFiles (HeatFiles childFile) {
4314 long startTime = System.currentTimeMillis ();
4315 LOGGER.debug ("Catalog database - save Heat File with name "
4316 + childFile.getFileName());
4318 // HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
4319 HeatFiles heatFiles = getHeatFiles (childFile.getArtifactUuid());
4320 if (heatFiles == null) {
4322 // asdc_heat_files_save
4323 this.getSession ().save (childFile);
4326 /* replaced 'heatFiles' by 'childFile'
4327 Based on following comment:
4328 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
4330 childFile.setArtifactUuid(heatFiles.getArtifactUuid());
4334 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
4338 public void saveVfModuleToHeatFiles (String parentVfModuleId, HeatFiles childFile) {
4339 long startTime = System.currentTimeMillis ();
4340 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4341 + childFile.getFileName());
4343 saveHeatFiles (childFile);
4344 VfModuleToHeatFiles checkExistingEntry = this.getVfModuleToHeatFilesEntry(parentVfModuleId, childFile.getArtifactUuid());
4345 if (checkExistingEntry == null) {
4346 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4347 vfModuleToHeatFile.setVfModuleModelUuid(parentVfModuleId);
4348 vfModuleToHeatFile.setHeatFilesArtifactUuid(childFile.getArtifactUuid());
4350 session.save (vfModuleToHeatFile);
4352 LOGGER.debug("**Found existing VfModuleToHeatFiles entry for " + checkExistingEntry.toString());
4353 LOGGER.debug("No need to save...");
4357 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4362 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4365 * @return NetworkRecipe object or null if none found
4367 public NetworkResource getNetworkResourceByModelUuid(String modelUUID) {
4369 long startTime = System.currentTimeMillis ();
4370 LOGGER.debug ("Catalog database - get network resource with modelUUID " + modelUUID);
4373 String hql = "FROM NetworkResource WHERE modelUUID=:modelUUID";
4374 Query query = getSession ().createQuery (hql);
4375 query.setParameter (MODEL_UUID, modelUUID);
4377 @SuppressWarnings("unchecked")
4378 List <NetworkResource> resultList = query.list ();
4380 if (resultList.isEmpty ()) {
4384 resultList.sort(new MavenLikeVersioningComparator());
4385 Collections.reverse (resultList);
4387 return resultList.get (0);
4388 } catch (Exception e) {
4389 LOGGER.debug("Error trying to find Network Resource with " + modelUUID +", " + e.getMessage(),e);
4391 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelUuid", null);
4398 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
4400 * @param networkType
4402 * @param serviceType
4403 * @return NetworkRecipe object or null if none found
4405 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
4407 long startTime = System.currentTimeMillis ();
4408 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
4411 + " and service type "
4416 if (serviceType == null) {
4417 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
4419 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
4421 Query query = getSession ().createQuery (hql);
4422 query.setParameter (NETWORK_TYPE, networkType);
4423 query.setParameter (ACTION, action);
4424 if (serviceType != null) {
4425 query.setParameter ("serviceType", serviceType);
4428 @SuppressWarnings("unchecked")
4429 List <NetworkRecipe> resultList = query.list ();
4431 if (resultList.isEmpty ()) {
4435 resultList.sort(new MavenLikeVersioningComparator());
4436 Collections.reverse (resultList);
4438 return resultList.get (0);
4440 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4445 * Return a Network recipe that matches a given MODEL_UUID and ACTION
4449 * @return NetworkRecipe object or null if none found
4451 public NetworkRecipe getNetworkRecipeByModuleUuid (String networkModelUuid, String action) {
4452 LOGGER.debug ("Catalog database - get network recipe with network model uuid " + networkModelUuid
4456 NetworkResource networkResource = getNetworkResourceByModelUuid(networkModelUuid);
4457 if(null == networkResource){
4461 NetworkRecipe recipe = getNetworkRecipeByNameVersion(networkResource.getModelName(), networkResource.getModelVersion(), action);
4466 * Return a Network recipe that matches a given MODEL_NAME and ACTION
4470 * @return NetworkRecipe object or null if none found
4472 public NetworkRecipe getNetworkRecipe (String modelName, String action) {
4474 long startTime = System.currentTimeMillis ();
4475 LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
4481 String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND action = :action";
4483 Query query = getSession ().createQuery (hql);
4484 query.setParameter (MODEL_NAME, modelName);
4485 query.setParameter (ACTION, action);
4487 @SuppressWarnings("unchecked")
4488 List <NetworkRecipe> resultList = query.list ();
4490 if (resultList.isEmpty ()) {
4494 resultList.sort(new MavenLikeVersioningComparator());
4495 Collections.reverse (resultList);
4497 return resultList.get (0);
4499 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4504 * get network recipe by module name and version and action.
4508 * @param modelVersion
4511 * @since ONAP Beijing Release
4513 public NetworkRecipe getNetworkRecipeByNameVersion(String modelName, String modelVersion, String action) {
4515 long startTime = System.currentTimeMillis ();
4516 LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
4517 +"model version " + modelVersion + " and action " + action);
4520 String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND version=:version AND action = :action";
4522 Query query = getSession ().createQuery (hql);
4523 query.setParameter (MODEL_NAME, modelName);
4524 query.setParameter (MODEL_VERSION, modelVersion);
4525 query.setParameter (ACTION, action);
4527 @SuppressWarnings("unchecked")
4528 List <NetworkRecipe> resultList = query.list ();
4530 if (resultList.isEmpty ()) {
4534 resultList.sort(new MavenLikeVersioningComparator());
4535 Collections.reverse (resultList);
4537 return resultList.get (0);
4539 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4544 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4546 * @param modelCustomizationUuid
4547 * @return NetworkRecipe object or null if none found
4549 public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
4551 long startTime = System.currentTimeMillis ();
4552 LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
4555 String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.modelUUID=c.networkResourceModelUuid and c.modelCustomizationUuid = :modelCustomizationUuid";
4556 Query query = getSession ().createQuery (hql);
4557 query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
4559 @SuppressWarnings("unchecked")
4560 List <NetworkResource> resultList = query.list ();
4562 if (resultList.isEmpty ()) {
4566 resultList.sort(new MavenLikeVersioningComparator());
4567 Collections.reverse (resultList);
4569 return resultList.get (0);
4570 } catch (Exception e) {
4571 LOGGER.debug("Error trying to find Network Resource with " + modelCustomizationUuid +", " + e.getMessage(),e);
4573 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelCustUuid", null);
4579 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
4583 * @param vnfComponentType
4585 * @param serviceType
4586 * @return VnfComponentsRecipe object or null if none found
4588 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
4589 String vnfComponentType,
4591 String serviceType) {
4593 long startTime = System.currentTimeMillis ();
4594 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
4595 + " and component type "
4599 + " and service type "
4604 if (serviceType == null) {
4605 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
4607 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
4609 Query query = getSession ().createQuery (hql);
4610 query.setParameter (VNF_TYPE, vnfType);
4611 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4612 query.setParameter (ACTION, action);
4613 if (serviceType != null) {
4614 query.setParameter ("serviceType", serviceType);
4617 @SuppressWarnings("unchecked")
4618 List <VnfComponentsRecipe> resultList = query.list ();
4620 if (resultList.isEmpty ()) {
4623 resultList.sort(new MavenLikeVersioningComparator());
4624 Collections.reverse (resultList);
4626 return resultList.get (0);
4628 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
4633 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
4635 * @param vfModuleModelUUId
4636 * @param vnfComponentType
4638 * @return VnfComponentsRecipe object or null if none found
4640 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleModelUUId (String vfModuleModelUUId,
4641 String vnfComponentType,
4644 long startTime = System.currentTimeMillis ();
4645 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleModelUUId " + vfModuleModelUUId
4646 + " and component type "
4653 hql = "FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId AND vnfComponentType = :vnfComponentType AND action = :action ";
4655 Query query = getSession ().createQuery (hql);
4656 query.setParameter (VF_MODULE_MODEL_UUID, vfModuleModelUUId);
4657 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4658 query.setParameter (ACTION, action);
4660 @SuppressWarnings("unchecked")
4661 List <VnfComponentsRecipe> resultList = query.list ();
4663 if (resultList.isEmpty ()) {
4666 resultList.sort(new MavenLikeVersioningComparator());
4667 Collections.reverse (resultList);
4669 return resultList.get (0);
4671 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleModelUUId", null);
4675 public List<VnfComponentsRecipe> getVnfComponentRecipes (String vfModuleModelUUId) {
4677 StringBuilder hql = null;
4679 hql = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId");
4681 long startTime = System.currentTimeMillis ();
4682 LOGGER.debug ("Catalog database - get Service recipe with vfModuleModelUUId " + vfModuleModelUUId);
4684 Query query = getSession ().createQuery (hql.toString ());
4685 query.setParameter ("vfModuleModelUUId", vfModuleModelUUId);
4687 @SuppressWarnings("unchecked")
4688 List <VnfComponentsRecipe> resultList = query.list ();
4690 if (resultList.isEmpty ()) {
4691 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getVfModuleRecipes", null);
4692 return Collections.EMPTY_LIST;
4695 resultList.sort(new MavenLikeVersioningComparator());
4696 Collections.reverse (resultList);
4698 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleRecipes", null);
4704 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
4705 long startTime = System.currentTimeMillis ();
4707 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
4709 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
4713 this.getSession ().save (vnfComponent);
4716 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
4721 * Return a VfModule record that matches a given MODEL_NAME
4724 * @return VfModule object or null if none found
4726 public VfModule getVfModule (String modelName) {
4728 long startTime = System.currentTimeMillis ();
4729 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
4734 hql = "FROM VfModule WHERE modelName = :modelName";
4736 Query query = getSession ().createQuery (hql);
4737 query.setParameter (MODEL_NAME, modelName);
4739 @SuppressWarnings("unchecked")
4740 List <VfModule> resultList = query.list ();
4742 if (resultList.isEmpty ()) {
4745 resultList.sort(new MavenLikeVersioningComparator());
4746 Collections.reverse (resultList);
4748 return resultList.get (0);
4750 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
4755 * Return a VfModule record that matches a given MODEL_NAME
4758 * @return VfModule object or null if none found
4760 public VfModule getVfModuleByModelUUID (String modelUUID) {
4762 long startTime = System.currentTimeMillis ();
4763 LOGGER.debug ("Catalog database - get vf module with modelUUID " + modelUUID);
4768 hql = "FROM VfModule WHERE modelUUID = :modelUUID";
4770 Query query = getSession ().createQuery (hql);
4771 query.setParameter (MODEL_UUID, modelUUID);
4773 @SuppressWarnings("unchecked")
4774 List <VfModule> resultList = query.list ();
4776 if (resultList.isEmpty ()) {
4779 resultList.sort(new MavenLikeVersioningComparator());
4780 Collections.reverse (resultList);
4782 return resultList.get (0);
4784 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUUID", null);
4789 * Return a Service recipe that matches a given service ModelUUID and action
4790 * (modelUUID) and ACTION
4794 * @return ServiceRecipe object or null if none found
4796 public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
4798 long startTime = System.currentTimeMillis();
4799 LOGGER.debug("Catalog database - get Service recipe with modelUUID=" + modelUUID + " and action=" + action);
4803 // based on the new SERVICE_RECIPE schema where SERVICE_MODEL_UUID == MODEL_UUID, a JOIN with the SERVICE table is no longer needed
4804 // hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4805 // "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4806 // "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4807 // "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4808 // "WHERE SR.serviceModelUUID = :modelUUID AND SR.action = :action";
4809 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :modelUUID AND action = :action";
4810 Query query = getSession().createQuery(hql);
4811 query.setParameter(MODEL_UUID, modelUUID);
4812 query.setParameter(ACTION, action);
4814 @SuppressWarnings("unchecked")
4815 List<ServiceRecipe> recipeResultList = query.list();
4816 if (recipeResultList.isEmpty()) {
4817 LOGGER.debug("Catalog database - recipeResultList is null");
4820 recipeResultList.sort(new MavenLikeVersioningComparator());
4821 Collections.reverse(recipeResultList);
4822 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4824 return recipeResultList.get(0);
4826 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipeByModelUUID", null);
4831 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
4832 * (MODEL_VERSION_ID) and ACTION
4834 * @param modelVersionId
4836 * @return ServiceRecipe object or null if none found
4839 public ServiceRecipe getServiceRecipe(String modelVersionId,
4842 long startTime = System.currentTimeMillis();
4843 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
4844 + " and action=" + action);
4848 // Note: Even with the implementation of the HQL JOIN below, the code for the two separate
4849 // SELECTs will be retained/commented for now in the event some subsequent JOIN issue arises
4850 // 1st query to get the Service record for the given SERVICE_NAME_VERSION_ID (MODEL_VERSION_ID)
4851 /* hql = "FROM Service WHERE serviceNameVersionId = :serviceNameVersionId";
4852 Query query = getSession().createQuery(hql);
4853 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
4855 @SuppressWarnings("unchecked")
4856 List<Service> serviceResultList = query.list();
4857 if (serviceResultList.isEmpty()) {
4858 LOGGER.debug("Catalog database - serviceResultList is null");
4861 Collections.sort(serviceResultList, new MavenLikeVersioningComparator());
4862 Collections.reverse(serviceResultList);
4863 LOGGER.debug("Catalog database - serviceResultList contains " + serviceResultList.get(0).toString());
4865 // 2nd query to get the ServiceRecipe record corresponding to the Service from the 1st query
4866 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action";
4867 query = getSession().createQuery(hql);
4868 // The SERVICE table 'id' field maps to the SERVICE_RECIPE table 'SERVICE_ID' field
4869 query.setParameter(SERVICE_ID, serviceResultList.get(0).getId());
4870 query.setParameter(ACTION, action);
4872 // The following SELECT performs a JOIN across the SERVICE and SERVICE_RECIPE tables. It required a new
4873 // CTR in the ServiceRecipe Class to populate that object (the other option was to parse the Object[]
4874 // returned by createQuery() and manually populate the ServiceRecipe object). Two of the 'int' fields in the
4875 // SERVICE_RECIPE DB schema (the timeouts) permit NULL values which required some additional code in the
4876 // SELECT to generate a default of 0 (needed by the CTR) in the cases where the value is NULL.
4877 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4878 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4879 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4880 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4881 "WHERE SR.serviceModelUUID = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
4882 Query query = getSession().createQuery(hql);
4883 query.setParameter(MODEL_UUID, modelVersionId);
4884 query.setParameter(ACTION, action);
4886 @SuppressWarnings("unchecked")
4887 List<ServiceRecipe> recipeResultList = query.list();
4888 if (recipeResultList.isEmpty()) {
4889 LOGGER.debug("Catalog database - recipeResultList is null");
4892 recipeResultList.sort(new MavenLikeVersioningComparator());
4893 Collections.reverse(recipeResultList);
4894 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4896 return recipeResultList.get(0);
4898 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
4903 * Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
4904 * Note: This method is not currently used but was retained in the event the
4905 * architecture moves back to a MODEL/MODEL_RECIPE structure.
4908 * @param modelVersionId
4910 * @return ModelRecipe object or null if none found
4912 public ModelRecipe getModelRecipe(String modelType,
4913 String modelVersionId,
4916 long startTime = System.currentTimeMillis();
4917 LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
4918 + " and modeVersionId=" + modelVersionId
4919 + " and action=" + action);
4923 // TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
4924 // the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
4925 // There seems to be 2 issues: formatting a hql query that executes successfully
4926 // and then being able to generate a result that will fit into the ModelRecipe class.
4928 // 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
4929 hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
4930 Query query = getSession().createQuery(hql);
4931 query.setParameter(MODEL_TYPE, modelType);
4932 query.setParameter(MODEL_VERSION_ID, modelVersionId);
4934 @SuppressWarnings("unchecked")
4935 List<Model> modelResultList = query.list();
4936 if (modelResultList.isEmpty()) {
4937 LOGGER.debug("Catalog database - modelResultList is null");
4940 modelResultList.sort(new MavenLikeVersioningComparator());
4941 Collections.reverse(modelResultList);
4942 LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
4944 // 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
4945 hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
4946 query = getSession().createQuery(hql);
4947 // The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
4948 query.setParameter(MODEL_ID, modelResultList.get(0).getId());
4949 query.setParameter(ACTION, action);
4951 @SuppressWarnings("unchecked")
4952 List<ModelRecipe> recipeResultList = query.list();
4953 if (recipeResultList.isEmpty()) {
4954 LOGGER.debug("Catalog database - recipeResultList is null");
4957 recipeResultList.sort(new MavenLikeVersioningComparator());
4958 Collections.reverse(recipeResultList);
4959 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4961 return recipeResultList.get(0);
4963 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
4969 * Verify the health of the DB.
4971 * @return boolean value indicate whether DB is healthy
4973 public boolean healthCheck () {
4974 long startTime = System.currentTimeMillis ();
4975 Session session = this.getSession ();
4977 // Query query = session.createQuery (" from ActiveRequests ");
4978 Query query = session.createSQLQuery (" show tables ");
4980 List<?> list = query.list();
4981 LOGGER.debug("healthCheck CatalogDB - Successful");
4985 public < E > E executeQuerySingleRow(String hql, HashMap<String, String> variables, boolean retry) {
4986 long startTime = System.currentTimeMillis();
4987 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
4988 Query query = getSession().createQuery(hql);
4990 StringBuilder sb = new StringBuilder();
4991 if (variables != null) {
4992 for(Map.Entry<String, String> entry : variables.entrySet()){
4993 sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
4994 query.setParameter(entry.getKey(), entry.getValue());
4997 LOGGER.debug("Variables:\n" + sb.toString());
5001 theObject = (E) query.uniqueResult();
5002 } catch (org.hibernate.NonUniqueResultException nure) {
5003 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row");
5004 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for " + hql, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for " + hql );
5006 } catch (org.hibernate.HibernateException he) {
5007 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
5008 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
5010 LOGGER.debug("***WILL RETRY***");
5011 return this.executeQuerySingleRow(hql, variables, false);
5015 } catch (Exception e) {
5016 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
5017 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
5019 LOGGER.debug("***WILL RETRY***");
5020 return this.executeQuerySingleRow(hql, variables, false);
5026 if (theObject == null) {
5027 LOGGER.debug("Returning null");
5028 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
5030 LOGGER.debug("Returning an Object");
5031 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
5036 public < E > List<E> executeQueryMultipleRows(String hql, HashMap<String, String> variables, boolean retry) {
5037 long startTime = System.currentTimeMillis ();
5038 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
5039 Query query = getSession().createQuery(hql);
5041 StringBuilder sb = new StringBuilder();
5042 if (variables != null) {
5043 for(Map.Entry<String, String> entry : variables.entrySet()){
5044 sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
5045 query.setParameter(entry.getKey(), entry.getValue());
5048 LOGGER.debug("Variables:\n" + sb.toString());
5050 List<E> theObjects = null;
5052 theObjects = (List<E>) query.list ();
5053 } catch (org.hibernate.HibernateException he) {
5054 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
5055 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
5057 LOGGER.debug("***WILL RETRY***");
5058 return this.executeQuerySingleRow(hql, variables, false);
5062 } catch (Exception e) {
5063 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
5064 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
5066 LOGGER.debug("***WILL RETRY***");
5067 return this.executeQuerySingleRow(hql, variables, false);
5073 if (theObjects == null) {
5074 LOGGER.debug("Returning null");
5075 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
5078 LOGGER.debug("Returning theObjects:" + theObjects.size());
5079 } catch (Exception e) {
5080 LOGGER.debug("Returning theObjects",e);
5082 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
5089 * get allotted resource recipe by module name and version and action.
5093 * @param modelVersion
5096 * @since ONAP Beijing Release
5098 public ArRecipe getArRecipeByNameVersion(String modelName, String modelVersion, String action) {
5100 long startTime = System.currentTimeMillis ();
5101 LOGGER.debug ("Catalog database - get ar recipe with ar model name " + modelName
5102 +"model version " + modelVersion + " and action " + action);
5105 String hql = "FROM ArRecipe WHERE modelName = :modelName AND version=:version AND action = :action";
5107 Query query = getSession ().createQuery (hql);
5108 query.setParameter (MODEL_NAME, modelName);
5109 query.setParameter (MODEL_VERSION, modelVersion);
5110 query.setParameter (ACTION, action);
5112 @SuppressWarnings("unchecked")
5113 List <ArRecipe> resultList = query.list ();
5115 if (resultList.isEmpty ()) {
5119 resultList.sort(new MavenLikeVersioningComparator());
5120 Collections.reverse (resultList);
5122 return resultList.get (0);
5124 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
5129 * Return a allotted resource recipe that matches a given MODEL_UUID and ACTION
5133 * @return ArRecipe object or null if none found
5135 public ArRecipe getArRecipeByModuleUuid (String ArModelUuid, String action) {
5136 LOGGER.debug ("Catalog database - get ar recipe with ar model uuid " + ArModelUuid
5140 AllottedResource arResource = this.getAllottedResourceByModelUuid(ArModelUuid);
5141 if(null == arResource){
5145 ArRecipe recipe = getArRecipeByNameVersion(arResource.getModelName(), arResource.getModelVersion(), action);