2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.mso.db.catalog;
24 import java.io.Closeable;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.List;
33 import org.hibernate.HibernateException;
34 import org.hibernate.Query;
35 import org.hibernate.Session;
36 import org.openecomp.mso.db.AbstractSessionFactoryManager;
37 import org.openecomp.mso.db.catalog.beans.AllottedResource;
38 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
39 import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
40 import org.openecomp.mso.db.catalog.beans.HeatFiles;
41 import org.openecomp.mso.db.catalog.beans.HeatNestedTemplate;
42 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
43 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
44 import org.openecomp.mso.db.catalog.beans.Model;
45 import org.openecomp.mso.db.catalog.beans.ModelRecipe;
46 import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
47 import org.openecomp.mso.db.catalog.beans.NetworkResource;
48 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
49 import org.openecomp.mso.db.catalog.beans.Service;
50 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
51 import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
52 import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
53 import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
54 import org.openecomp.mso.db.catalog.beans.ServiceToResourceCustomization;
55 import org.openecomp.mso.db.catalog.beans.TempNetworkHeatTemplateLookup;
56 import org.openecomp.mso.db.catalog.beans.ToscaCsar;
57 import org.openecomp.mso.db.catalog.beans.VfModule;
58 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
59 import org.openecomp.mso.db.catalog.beans.VfModuleToHeatFiles;
60 import org.openecomp.mso.db.catalog.beans.VnfComponent;
61 import org.openecomp.mso.db.catalog.beans.VnfComponentsRecipe;
62 import org.openecomp.mso.db.catalog.beans.VnfRecipe;
63 import org.openecomp.mso.db.catalog.beans.VnfResCustomToVfModuleCustom;
64 import org.openecomp.mso.db.catalog.beans.VnfResource;
65 import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
66 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
67 import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
68 import org.openecomp.mso.logger.MessageEnum;
69 import org.openecomp.mso.logger.MsoLogger;
72 * This class encapsulates all of the objects that can be queried from a Catalog database.
73 * Clients must use these methods to retrieve catalog objects. The session is not
74 * available for clients to do their own direct queries to the database.
78 public class CatalogDatabase implements Closeable {
80 protected final AbstractSessionFactoryManager sessionFactoryCatalogDB;
82 private static final String NETWORK_TYPE = "networkType";
83 private static final String ACTION = "action";
84 private static final String VNF_TYPE = "vnfType";
85 private static final String SERVICE_TYPE = "serviceType";
86 private static final String MODEL_UUID= "modelUUID";
87 private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
88 private static final String MODEL_ID = "modelId";
89 private static final String MODEL_NAME = "modelName";
90 private static final String MODEL_VERSION = "version";
91 private static final String TYPE = "type";
92 private static final String MODEL_TYPE = "modelType";
93 private static final String MODEL_VERSION_ID = "modelVersionId";
94 private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
95 private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId";
97 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
99 protected Session session = null;
101 protected CatalogDatabase (AbstractSessionFactoryManager sessionFactoryCatalog) {
102 sessionFactoryCatalogDB = sessionFactoryCatalog;
105 public static CatalogDatabase getInstance() {
106 return new CatalogDatabase(new CatalogDbSessionFactoryManager ());
109 private Session getSession () {
111 if (session == null) {
113 session = sessionFactoryCatalogDB.getSessionFactory ().openSession ();
114 session.beginTransaction ();
115 } catch (HibernateException he) {
116 LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Error creating Hibernate Session: " + he, "", "", MsoLogger.ErrorCode.DataError, "Error creating Hibernate Session: " + he);
125 * Close an open Catalog Database session.
126 * This method should always be called when a client is finished using a
127 * CatalogDatabase instance.
130 public void close () {
131 if (session != null) {
138 * Commits the current transaction on this session and starts a fresh one.
140 public void commit () {
141 getSession ().getTransaction ().commit ();
142 getSession ().beginTransaction ();
146 * Rolls back current transaction and starts a fresh one.
148 public void rollback () {
149 getSession ().getTransaction ().rollback ();
150 getSession ().beginTransaction ();
154 * Return all Heat Templates in the Catalog DB
156 * @return A list of HeatTemplate objects
158 @SuppressWarnings("unchecked")
159 public List <HeatTemplate> getAllHeatTemplates() {
160 long startTime = System.currentTimeMillis();
161 LOGGER.debug("Catalog database - get all Heat templates");
162 String hql = "FROM HeatTemplate";
163 Query query = getSession().createQuery(hql);
165 List <HeatTemplate> result = query.list();
166 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatTemplates", null);
171 * Fetch a specific Heat Template by ID.
173 * @param templateId template id
174 * @return HeatTemplate object or null if none found
177 public HeatTemplate getHeatTemplate(int templateId) {
178 long startTime = System.currentTimeMillis();
179 LOGGER.debug ("Catalog database - get Heat template with id " + templateId);
181 HeatTemplate template = (HeatTemplate) getSession().get(HeatTemplate.class, templateId);
182 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
187 * Return the newest version of a specific Heat Template (queried by Name).
189 * @param templateName template name
190 * @return HeatTemplate object or null if none found
192 public HeatTemplate getHeatTemplate(String templateName) {
194 long startTime = System.currentTimeMillis();
195 LOGGER.debug("Catalog database - get Heat template with name " + templateName);
197 String hql = "FROM HeatTemplate WHERE templateName = :template_name";
198 Query query = getSession().createQuery (hql);
199 query.setParameter("template_name", templateName);
201 @SuppressWarnings("unchecked")
202 List <HeatTemplate> resultList = query.list();
204 // See if something came back. Name is unique, so
205 if (resultList.isEmpty ()) {
206 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null);
209 resultList.sort(new MavenLikeVersioningComparator());
210 Collections.reverse(resultList);
212 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
213 return resultList.get(0);
217 * Return a specific version of a specific Heat Template (queried by Name).
219 * @param templateName
221 * @return HeatTemplate object or null if none found
223 public HeatTemplate getHeatTemplate(String templateName, String version) {
225 long startTime = System.currentTimeMillis();
226 LOGGER.debug("Catalog database - get Heat template with name " + templateName
230 String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version";
231 Query query = getSession().createQuery(hql);
232 query.setParameter("template_name", templateName);
233 query.setParameter("version", version);
235 @SuppressWarnings("unchecked")
236 List <HeatTemplate> resultList = query.list();
238 // See if something came back.
239 if (resultList.isEmpty()) {
240 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found.", "CatalogDB", "getHeatTemplate", null);
243 // Name + Version is unique, so should only be one element
244 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
245 return resultList.get(0);
249 * Return a specific Heat Template by ARTIFACT_UUID).
251 * @param artifactUuid
252 * @return HeatTemplate object or null if none found
255 public HeatTemplate getHeatTemplateByArtifactUuid(String artifactUuid) {
256 long startTime = System.currentTimeMillis ();
257 LOGGER.debug ("Catalog database - get Heat template with artifactUuid " + artifactUuid);
259 // Will this work if the id is a string?
260 HeatTemplate template = (HeatTemplate) getSession ().get (HeatTemplate.class, artifactUuid);
261 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
266 * Return a specific Heat Template by ARTIFACT_UUID using standard query method. unique record expected.
268 * @param artifactUuid
269 * @return HeatTemplate object or null if none found
271 public HeatTemplate getHeatTemplateByArtifactUuidRegularQuery(String artifactUuid) {
272 long startTime = System.currentTimeMillis();
273 LOGGER.debug("Catalog database - get Heat template (regular query) with artifactUuid " + artifactUuid);
275 String hql = "FROM HeatTemplate WHERE artifactUuid = :artifactUuidValue";
276 HashMap<String, String> variables = new HashMap<>();
277 variables.put("artifactUuidValue", artifactUuid);
278 HeatTemplate template = (HeatTemplate) this.executeQuerySingleRow(hql, variables, true);
280 if (template == null) {
281 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
283 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
288 public List<HeatTemplateParam> getParametersForHeatTemplate(String heatTemplateArtifactUuid) {
289 LOGGER.debug ("Catalog database - getParametersForHeatTemplate with artifactUuid " + heatTemplateArtifactUuid);
291 String hql = "FROM HeatTemplateParams WHERE artifactUuid = :artifactUuidValue";
292 Query query = getSession().createQuery(hql);
293 query.setParameter ("artifactUuidValue", heatTemplateArtifactUuid);
294 List<HeatTemplateParam> resultList = new ArrayList<>();
296 resultList = query.list ();
297 } catch (org.hibernate.HibernateException he) {
298 LOGGER.debug("Hibernate Exception - while searching HeatTemplateParams for: heatTemplateArtifactUuid='" + heatTemplateArtifactUuid + "'" + he.getMessage());
299 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching HeatTemplateParams for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + heatTemplateArtifactUuid);
301 } catch (Exception e) {
302 LOGGER.debug("Generic Exception - while searching HeatTemplateParam for: artifactUuid='" + heatTemplateArtifactUuid + "'" + e.getMessage());
303 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching HeatTemplate for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + heatTemplateArtifactUuid);
312 * Return a specific Heat Environment by ARTIFACT_UUID using standard query method. unique record expected.
314 * @param artifactUuid
315 * @return HeatEnvironment object or null if none found
317 public HeatEnvironment getHeatEnvironmentByArtifactUuid(String artifactUuid) {
318 long startTime = System.currentTimeMillis();
319 LOGGER.debug("Catalog database - get Heat Environment with artifactUuid " + artifactUuid);
321 String hql = "FROM HeatEnvironment WHERE artifactUuid = :artifactUuidValue";
322 Query query = getSession().createQuery(hql);
323 query.setParameter("artifactUuidValue", artifactUuid);
324 HeatEnvironment environment = null;
326 environment = (HeatEnvironment) query.uniqueResult();
327 } catch (org.hibernate.NonUniqueResultException nure) {
328 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row for Envt - data integrity error: artifactUuid='" + artifactUuid +"'", nure);
329 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for heatEnvironment artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid==" + artifactUuid);
330 } catch (org.hibernate.HibernateException he) {
331 LOGGER.debug("Hibernate Exception - while searching for envt: artifactUuid='" + artifactUuid + "' " + he.getMessage());
332 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching envt for artifactUuid=" + artifactUuid);
335 } catch (Exception e) {
336 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + "' " + e.getMessage());
337 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching envt for artifactUuid=" + artifactUuid);
342 if (environment == null) {
343 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
345 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
351 * Fetch a Service definition by InvariantUUID
353 public Service getServiceByInvariantUUID (String modelInvariantUUID) {
355 long startTime = System.currentTimeMillis();
356 LOGGER.debug("Catalog database - get service with Invariant UUID " + modelInvariantUUID);
358 String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid";
359 Query query = getSession().createQuery(hql);
360 query.setParameter ("model_invariant_uuid", modelInvariantUUID);
362 @SuppressWarnings("unchecked")
363 List <Service> resultList = query.list ();
365 // See if something came back.
366 if (resultList.isEmpty ()) {
367 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
370 resultList.sort(new MavenLikeVersioningComparator());
371 Collections.reverse (resultList);
373 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
374 return resultList.get (0);
378 * Fetch a Service definition
380 public Service getService (String modelName) {
382 long startTime = System.currentTimeMillis();
383 LOGGER.debug("Catalog database - get service with name " + modelName);
385 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
386 Query query = getSession().createQuery(hql);
387 query.setParameter("MODEL_NAME", modelName);
389 Service service = null;
391 service = (Service) query.uniqueResult();
392 } catch (org.hibernate.NonUniqueResultException nure) {
393 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelName='" + modelName + "'");
394 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelName=" + modelName);
396 } catch (org.hibernate.HibernateException he) {
397 LOGGER.debug("Hibernate Exception - while searching for: modelName='" + modelName + "' " + he.getMessage());
398 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelName=" + modelName);
400 } catch (Exception e) {
401 LOGGER.debug("Generic Exception - while searching for: modelName='" + modelName + " " + e.getMessage());
402 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelName=" + modelName);
405 if (service == null) {
406 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
408 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
414 public Service getServiceByModelUUID (String modelUUID) {
416 long startTime = System.currentTimeMillis();
417 LOGGER.debug("Catalog database - get service with Model UUID " + modelUUID);
419 String hql = "FROM Service WHERE modelUUID = :MODEL_UUID";
420 HashMap<String, String> parameters = new HashMap<>();
421 parameters.put("MODEL_UUID", modelUUID);
424 Service service = this.executeQuerySingleRow(hql, parameters, true);
428 service = (Service) query.uniqueResult ();
429 } catch (org.hibernate.NonUniqueResultException nure) {
430 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelUUID='" + modelUUID + "'");
431 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelUUID=" + modelUUID);
433 } catch (org.hibernate.HibernateException he) {
434 LOGGER.debug("Hibernate Exception - while searching for: modelUUID='" + modelUUID + "' " + he.getMessage());
435 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUUID=" + modelUUID);
437 } catch (Exception e) {
438 LOGGER.debug("Generic Exception - while searching for: modelUUID='" + modelUUID + " " + e.getMessage());
439 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUUID=" + modelUUID);
443 if (service == null) {
444 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getServiceByModelUUID", null);
446 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelUUID", null);
453 * Fetch the Common Service API definition using Http Method + serviceNameVersionId
455 public Service getService(Map<String, String> map, String httpMethod) {
457 String serviceNameVersionId = map.get("serviceNameVersionId");
459 String serviceId = "not_set";
460 String serviceVersion = "not_set";
462 if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
463 LOGGER.debug ("Catalog database - get service modelUUID with id " + serviceNameVersionId);
465 String hql = "FROM Service WHERE MODEL_UUID = :MODEL_UUID and http_method = :http_method";
466 query = getSession().createQuery(hql);
467 query.setParameter("MODEL_UUID", serviceNameVersionId);
469 serviceId = map.get("serviceId");
470 serviceVersion = map.get("serviceVersion");
471 LOGGER.debug("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
473 String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
474 query = getSession().createQuery(hql);
475 query.setParameter("service_id", serviceId);
476 query.setParameter("service_version", serviceVersion);
479 query.setParameter("http_method", httpMethod);
481 long startTime = System.currentTimeMillis();
482 Service service = null;
484 service = (Service) query.uniqueResult();
485 } catch (org.hibernate.NonUniqueResultException nure) {
486 LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
487 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);
490 } catch (org.hibernate.HibernateException he) {
491 LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + he.getMessage());
492 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);
495 } catch (Exception e) {
496 LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
497 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);
501 if (service == null) {
502 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
504 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
510 * Return the newest version of a Service (queried by Name).
513 * @return Service object or null if none found
515 public Service getServiceByModelName(String modelName){
517 long startTime = System.currentTimeMillis();
518 LOGGER.debug("Catalog database - get service with name " + modelName);
520 String hql = "FROM Service WHERE modelName = :MODEL_NAME";
521 Query query = getSession().createQuery(hql);
522 query.setParameter("MODEL_NAME", modelName);
524 @SuppressWarnings("unchecked")
525 List <Service> resultList = query.list();
527 // See if something came back.
528 if (resultList.isEmpty()) {
529 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null);
532 resultList.sort(new MavenLikeVersioningComparator());
533 Collections.reverse(resultList);
535 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null);
536 return resultList.get(0);
539 public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
540 long startTime = System.currentTimeMillis();
541 LOGGER.debug("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion);
543 String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR";
544 Query query = getSession().createQuery(hql);
545 query.setParameter("MODEL_INVARIANT_UUID", modelInvariantId);
546 query.setParameter("VERSION_STR", modelVersion);
548 Service result = null;
550 result = (Service) query.uniqueResult();
551 } catch (org.hibernate.NonUniqueResultException nure) {
552 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'", nure);
553 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantId=" + modelInvariantId + " and modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId);
554 throw new Exception("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
556 // See if something came back.
558 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null);
562 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null);
567 * Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
569 * @param serviceModelUUID
571 * @return ServiceRecipe object or null if none found
574 public ServiceRecipe getServiceRecipe (int serviceModelUUID, String action) {
579 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
581 hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action ");
584 long startTime = System.currentTimeMillis ();
585 LOGGER.debug ("Catalog database - get Service recipe with serviceModelUUID " + Integer.toString(serviceModelUUID)
590 Query query = getSession ().createQuery (hql.toString ());
591 query.setParameter ("serviceModelUUID", serviceModelUUID);
593 query.setParameter (ACTION, action);
596 @SuppressWarnings("unchecked")
597 List <ServiceRecipe> resultList = query.list ();
599 if (resultList.isEmpty ()) {
600 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
604 resultList.sort(new MavenLikeVersioningComparator());
605 Collections.reverse (resultList);
607 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
608 return resultList.get (0);
612 * Return a newest version of Service recipe that matches a given SERVICE_MODEL_UUID and ACTION
614 * @param serviceModelUuid
616 * @return ServiceRecipe object or null if none found
618 public ServiceRecipe getServiceRecipeByServiceModelUuid(String serviceModelUuid, String action) {
623 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid");
625 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action ");
628 long startTime = System.currentTimeMillis ();
629 LOGGER.debug("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid
634 Query query = getSession().createQuery(hql.toString());
635 query.setParameter("serviceModelUuid", serviceModelUuid);
637 query.setParameter(ACTION, action);
640 @SuppressWarnings("unchecked")
641 List <ServiceRecipe> resultList = query.list();
643 if (resultList.isEmpty()) {
644 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
648 resultList.sort(new MavenLikeVersioningComparator());
649 Collections.reverse(resultList);
651 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
652 return resultList.get(0);
655 public List<ServiceRecipe> getServiceRecipes(String serviceModelUuid) {
659 hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
661 long startTime = System.currentTimeMillis();
662 LOGGER.debug("Catalog database - get Service recipe with serviceModelUUID " + serviceModelUuid);
664 Query query = getSession().createQuery(hql.toString());
665 query.setParameter("serviceModelUUID", serviceModelUuid);
667 @SuppressWarnings("unchecked")
668 List <ServiceRecipe> resultList = query.list();
670 if (resultList.isEmpty()) {
671 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null);
672 return Collections.EMPTY_LIST;
675 resultList.sort(new MavenLikeVersioningComparator());
676 Collections.reverse(resultList);
678 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null);
684 * Return the VNF component data - queried by the VNFs ID and the component type.
688 * @return VnfComponent object or null if none found
691 public VnfComponent getVnfComponent (int vnfId, String type) {
693 long startTime = System.currentTimeMillis();
694 LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
696 String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
697 Query query = getSession ().createQuery (hql);
698 query.setParameter ("vnf_id", vnfId);
699 query.setParameter ("type", type);
701 VnfComponent result = null;
703 result = (VnfComponent) query.uniqueResult();
704 } catch (org.hibernate.NonUniqueResultException nure) {
705 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
706 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);
709 } catch (org.hibernate.HibernateException he) {
710 LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + he.getMessage());
711 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);
714 } catch (Exception e) {
715 LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + e.getMessage());
716 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);
721 if (result != null) {
722 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
724 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
730 * Return the newest version of a specific VNF resource (queried by Name).
733 * @return VnfResource object or null if none found
735 public VnfResource getVnfResource (String vnfType) {
737 long startTime = System.currentTimeMillis();
738 LOGGER.debug("Catalog database - get vnf resource with model_name " + vnfType);
740 String hql = "FROM VnfResource WHERE modelName = :vnf_name";
741 Query query = getSession().createQuery(hql);
742 query.setParameter("vnf_name", vnfType);
744 @SuppressWarnings("unchecked")
745 List <VnfResource> resultList = query.list();
747 // See if something came back. Name is unique, so
748 if (resultList.isEmpty()) {
749 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
752 resultList.sort(new MavenLikeVersioningComparator());
753 Collections.reverse(resultList);
755 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
756 return resultList.get(0);
760 * Return the newest version of a specific VNF resource (queried by Name).
763 * @param serviceVersion
764 * @return VnfResource object or null if none found
766 public VnfResource getVnfResource (String vnfType, String serviceVersion) {
768 long startTime = System.currentTimeMillis();
769 LOGGER.debug("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion);
771 String hql = "FROM VnfResource WHERE modelName = :vnfName and version = :serviceVersion";
772 Query query = getSession().createQuery(hql);
773 query.setParameter("vnfName", vnfType);
774 query.setParameter("serviceVersion", serviceVersion);
776 VnfResource resource = null;
778 resource = (VnfResource) query.uniqueResult();
779 } catch (org.hibernate.NonUniqueResultException nure) {
780 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
781 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
784 } catch (org.hibernate.HibernateException he) {
785 LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "' " + he.getMessage());
786 LOGGER.debug(Arrays.toString(he.getStackTrace()));
787 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
790 } catch (Exception e) {
791 LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
792 LOGGER.debug(Arrays.toString(e.getStackTrace()));
793 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
797 if (resource == null) {
798 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
800 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
806 * Return VnfResource (queried by modelCustomizationId).
808 * @param modelCustomizationId
809 * @return VnfResource object or null if none found
811 public VnfResource getVnfResourceByModelCustomizationId(String modelCustomizationId) {
813 long startTime = System.currentTimeMillis();
814 LOGGER.debug("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
816 String hql = "SELECT vr "
817 + "FROM VnfResource as vr JOIN vr.vnfResourceCustomizations as vrc "
818 + "WHERE vrc.modelCustomizationUuid = :modelCustomizationId";
820 Query query = getSession().createQuery(hql);
821 query.setParameter("modelCustomizationId", modelCustomizationId);
823 VnfResource resource = null;
825 resource = (VnfResource) query.uniqueResult();
826 } catch(org.hibernate.NonUniqueResultException nure) {
827 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "'");
828 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
831 } catch (org.hibernate.HibernateException he) {
832 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
833 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationId=" + modelCustomizationId);
836 } catch (Exception e) {
837 LOGGER.debug("Generic Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
838 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationId=" + modelCustomizationId);
842 if (resource == null) {
843 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
845 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
852 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
854 * @return {@link VnfResourceCustomization} object or null if none found
856 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationName (String modelCustomizationName, String modelVersionId) {
858 long startTime = System.currentTimeMillis();
859 LOGGER.debug("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId);
861 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.modelCustomizationUuid IN "
862 + "(SELECT src.resourceModelCustomizationUUID FROM ServiceToResourceCustomization src "
863 + "WHERE src.serviceModelUUID = :modelVersionId)"
864 + "AND vrc.modelInstanceName = :modelCustomizationName";
866 Query query = getSession().createQuery(hql);
867 query.setParameter("modelCustomizationName", modelCustomizationName);
868 query.setParameter("modelVersionId", modelVersionId);
870 @SuppressWarnings("unchecked")
871 List<VnfResourceCustomization> resultList = query.list();
873 if (resultList.isEmpty()) {
874 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
878 resultList.sort(new MavenLikeVersioningComparator());
879 Collections.reverse(resultList);
881 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
882 return resultList.get(0);
887 * Return the newest version of a specific VNF resource (queried by modelInvariantId).
889 * @param modelInvariantUuid model invariant ID
890 * @param modelVersion model version
891 * @return VnfResource object or null if none found
893 public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) {
895 long startTime = System.currentTimeMillis();
896 LOGGER.debug("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
898 String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion";
899 Query query = getSession().createQuery(hql);
900 query.setParameter("modelInvariantUuid", modelInvariantUuid);
901 query.setParameter("serviceVersion", modelVersion);
903 VnfResource resource = null;
905 resource = (VnfResource) query.uniqueResult();
906 } catch (org.hibernate.NonUniqueResultException nure) {
907 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'");
908 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid);
911 } catch (org.hibernate.HibernateException he) {
912 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', asdc_service_model_version='" + modelVersion + "' " + he.getMessage());
913 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid);
916 } catch (Exception e) {
917 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "' " + e.getMessage());
918 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid);
922 if (resource == null) {
923 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
925 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
931 * Return the newest version of a specific VNF resource (queried by ID).
933 * @param id The vnf id
934 * @return VnfResource object or null if none found
937 public VnfResource getVnfResourceById (int id) {
939 long startTime = System.currentTimeMillis ();
940 LOGGER.debug ("Catalog database - get VNF resource with id " + id);
942 String hql = "FROM VnfResource WHERE id = :id";
943 Query query = getSession ().createQuery (hql);
944 query.setParameter ("id", id);
946 @SuppressWarnings("unchecked")
947 List <VnfResource> resultList = query.list ();
949 // See if something came back. Name is unique, so
950 if (resultList.isEmpty ()) {
951 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
954 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
955 return resultList.get (0);
959 * Return the newest version of a vfModule - 1607
962 public VfModule getVfModuleModelName(String modelName) {
964 long startTime = System.currentTimeMillis();
965 LOGGER.debug("Catalog database - get vfModuleModelName with name " + modelName);
967 String hql = "FROM VfModule WHERE modelName = :model_name";
968 Query query = getSession().createQuery(hql);
969 query.setParameter("model_name", modelName);
971 @SuppressWarnings("unchecked")
972 List<VfModule> resultList = query.list();
974 // See if something came back. Name is unique, so
975 if (resultList.isEmpty()) {
976 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
979 resultList.sort(new MavenLikeVersioningComparator());
980 Collections.reverse(resultList);
982 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
983 return resultList.get(0);
986 public VfModule getVfModuleModelName(String modelName, String model_version) {
988 long startTime = System.currentTimeMillis();
989 LOGGER.debug("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
991 String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
992 Query query = getSession().createQuery(hql);
993 query.setParameter("modelName", modelName);
994 query.setParameter("model_version", model_version);
996 VfModule module = null;
998 module = (VfModule) query.uniqueResult();
999 } catch (org.hibernate.NonUniqueResultException nure) {
1000 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 + "'");
1001 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
1004 } catch (org.hibernate.HibernateException he) {
1005 LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + he.getMessage());
1006 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
1009 } catch (Exception e) {
1010 LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + e.getMessage());
1011 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
1015 if (module == null) {
1016 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
1018 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
1024 * Need this for 1707 DHV. This may be a temporary solution. May
1025 * change it to get resources using service's model name.
1030 public VfModuleCustomization getVfModuleCustomizationByModelName(String modelName) {
1032 long startTime = System.currentTimeMillis();
1033 LOGGER.debug("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
1035 String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.modelName = :model_name";
1036 Query query = getSession().createQuery(hql);
1037 query.setParameter("model_name", modelName);
1039 @SuppressWarnings("unchecked")
1040 List<VfModuleCustomization> resultList = query.list();
1042 // See if something came back. Name is unique, so
1043 if (resultList.isEmpty()) {
1044 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1048 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query ", "CatalogDB", "getVfModuleCustomizationByModelName", null);
1049 return resultList.get(0);
1054 * Return the newest version of a specific Network resource (queried by Type).
1056 * @param networkType
1057 * @return NetworkResource object or null if none found
1059 public NetworkResource getNetworkResource(String networkType) {
1061 long startTime = System.currentTimeMillis();
1062 LOGGER.debug("Catalog database - get network resource with type " + networkType);
1064 String hql = "FROM NetworkResource WHERE model_name = :network_type";
1065 Query query = getSession().createQuery(hql);
1066 query.setParameter("network_type", networkType);
1068 @SuppressWarnings("unchecked")
1069 List <NetworkResource> resultList = query.list();
1071 // See if something came back. Name is unique, so
1072 if (resultList.isEmpty()) {
1073 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
1077 resultList.sort(new MavenLikeVersioningComparator());
1078 Collections.reverse(resultList);
1079 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
1080 return resultList.get(0);
1084 * Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
1088 * @param serviceType The service Name, if null or empty is provided, it won't be taken into account
1089 * @return VnfRecipe object or null if none found
1091 public VnfRecipe getVnfRecipe(String vnfType, String action, String serviceType) {
1092 boolean withServiceType = false;
1094 StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1097 if (serviceType == null || serviceType.isEmpty()) {
1098 hql.append("AND serviceType is NULL ");
1100 hql.append("AND serviceType = :serviceType ");
1101 withServiceType = true;
1104 long startTime = System.currentTimeMillis();
1105 LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
1108 + " and service type "
1111 Query query = getSession().createQuery(hql.toString());
1112 query.setParameter(VNF_TYPE, vnfType);
1113 query.setParameter(ACTION, action);
1114 if (withServiceType) {
1115 query.setParameter(SERVICE_TYPE, serviceType);
1118 @SuppressWarnings("unchecked")
1119 List <VnfRecipe> resultList = query.list();
1121 if (resultList.isEmpty()) {
1122 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1126 resultList.sort(new MavenLikeVersioningComparator());
1127 Collections.reverse(resultList);
1129 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1130 return resultList.get(0);
1136 * Return a VNF recipe that matches a given VNF_TYPE and ACTION
1140 * @return VnfRecipe object or null if none found
1142 public VnfRecipe getVnfRecipe(String vnfType, String action) {
1144 long startTime = System.currentTimeMillis();
1145 LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
1149 Query query = getSession().createQuery("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
1150 query.setParameter(VNF_TYPE, vnfType);
1151 query.setParameter(ACTION, action);
1153 @SuppressWarnings("unchecked")
1154 List <VnfRecipe> resultList = query.list();
1156 if (resultList.isEmpty()) {
1157 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1161 resultList.sort(new MavenLikeVersioningComparator());
1162 Collections.reverse(resultList);
1164 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1165 return resultList.get(0);
1169 * Return a VNF recipe that matches a given ModelName and Modelversion and ACTION
1172 * @param modelVersion
1174 * @return VnfRecipe object or null if none found
1176 public VnfRecipe getVnfRecipeByNameVersion(String modelName, String modelVersion, String action) {
1177 StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND version= :version AND action = :action ");
1179 long startTime = System.currentTimeMillis();
1180 LOGGER.debug("Catalog database - get VNF recipe with name " + modelName
1184 Query query = getSession().createQuery(hql.toString());
1185 query.setParameter(VNF_TYPE, modelName);
1186 query.setParameter(MODEL_VERSION, modelVersion);
1187 query.setParameter(ACTION, action);
1189 @SuppressWarnings("unchecked")
1190 List <VnfRecipe> resultList = query.list();
1192 if (resultList.isEmpty()) {
1193 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
1197 Collections.sort(resultList, new MavenLikeVersioningComparator());
1198 Collections.reverse(resultList);
1200 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
1201 return resultList.get(0);
1205 * Return a Network recipe that matches a given MODEL_UUID and ACTION
1209 * @return NetworkRecipe object or null if none found
1211 public VnfRecipe getVnfRecipeByModuleUuid (String vnfModelUuid, String action) {
1212 LOGGER.debug ("Catalog database - get vnf recipe with vnf resource model uuid " + vnfModelUuid
1216 VnfResource vnfResource = getVnfResourceByModelUuid(vnfModelUuid);
1217 if(null == vnfResource){
1221 VnfRecipe recipe = this.getVnfRecipeByNameVersion(vnfResource.getModelName(), vnfResource.getModelVersion(), action);
1226 * Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
1230 * @return VnfRecipe object or null if none found
1232 public VnfRecipe getVnfRecipeByVfModuleId(String vnfType, String vfModuleId, String action) {
1234 long startTime = System.currentTimeMillis();
1235 LOGGER.debug("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
1237 Query query = getSession().createQuery("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
1238 query.setParameter(VF_MODULE_MODEL_UUID, vfModuleId);
1239 query.setParameter(ACTION, action);
1241 @SuppressWarnings("unchecked")
1242 List <VnfRecipe> resultList = query.list();
1244 if (resultList.isEmpty()) {
1245 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1249 resultList.sort(new MavenLikeVersioningComparator());
1250 Collections.reverse(resultList);
1252 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
1253 return resultList.get(0);
1256 public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
1257 long startTime = System.currentTimeMillis();
1258 LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
1260 String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
1261 Query query = getSession().createQuery(hql);
1262 query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
1264 VfModule module = null;
1266 module = (VfModule) query.uniqueResult();
1267 } catch (org.hibernate.NonUniqueResultException nure) {
1268 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1269 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1272 } catch (org.hibernate.HibernateException he) {
1273 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1274 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1277 } catch (Exception e) {
1278 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1279 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1283 if (module == null) {
1284 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
1286 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
1292 public VfModule getVfModuleType(String type) {
1293 long startTime = System.currentTimeMillis();
1294 LOGGER.debug("Catalog database - get vfModuleType with type " + type);
1296 String hql = "FROM VfModule WHERE type = :type";
1297 Query query = getSession().createQuery(hql);
1298 query.setParameter("type", type);
1300 @SuppressWarnings("unchecked")
1301 List<VfModule> resultList = query.list();
1302 if (resultList.isEmpty()) {
1303 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
1306 resultList.sort(new MavenLikeVersioningComparator());
1307 Collections.reverse (resultList);
1309 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1310 return resultList.get (0);
1314 public VfModule getVfModuleType(String type, String version) {
1316 long startTime = System.currentTimeMillis();
1317 LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
1319 String hql = "FROM VfModule WHERE type = :type and version = :version";
1320 Query query = getSession().createQuery(hql);
1321 query.setParameter ("type", type);
1322 query.setParameter ("version", version);
1323 VfModule module = null;
1325 module = (VfModule) query.uniqueResult ();
1326 } catch (org.hibernate.NonUniqueResultException nure) {
1327 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 + "'");
1328 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
1331 } catch (org.hibernate.HibernateException he) {
1332 LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + he.getMessage());
1333 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
1336 } catch (Exception e) {
1337 LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + e.getMessage());
1338 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
1342 if (module == null) {
1343 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1345 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1350 public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
1351 long startTime = System.currentTimeMillis();
1352 LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
1354 String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
1355 Query query = getSession().createQuery(hql);
1356 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
1357 VnfResource vnfResource = null;
1359 vnfResource = (VnfResource) query.uniqueResult();
1360 } catch (org.hibernate.NonUniqueResultException nure) {
1361 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
1362 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
1365 } catch (org.hibernate.HibernateException he) {
1366 LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + he.getMessage());
1367 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1370 } catch (Exception e) {
1371 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + e.getMessage());
1372 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
1376 if (vnfResource == null) {
1377 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1379 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1384 public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
1385 long startTime = System.currentTimeMillis();
1386 LOGGER.debug("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
1388 String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
1389 Query query = getSession().createQuery(hql);
1390 query.setParameter("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
1391 VnfResource vnfResource = null;
1393 vnfResource = (VnfResource) query.uniqueResult();
1394 } catch (org.hibernate.NonUniqueResultException nure) {
1395 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
1396 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
1399 } catch (org.hibernate.HibernateException he) {
1400 LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + he.getMessage());
1401 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1404 } catch (Exception e) {
1405 LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + e.getMessage());
1406 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
1410 if (vnfResource == null) {
1411 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
1413 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
1418 public VnfResource getVnfResourceByType(String vnfType) {
1419 return this.getVnfResource(vnfType);
1422 public VfModule getVfModuleByModelInvariantUuid(String modelInvariantUUID) {
1423 long startTime = System.currentTimeMillis();
1424 LOGGER.debug ("Catalog database - get vfModuleTypeByModelInvariantUuid with uuid " + modelInvariantUUID);
1426 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUUID ";
1427 HashMap<String, String> parameters = new HashMap<>();
1428 parameters.put("modelInvariantUUID", modelInvariantUUID);
1429 List<VfModule> modules = this.executeQueryMultipleRows(hql, parameters, true);
1430 VfModule module = null;
1432 if (modules != null && ! modules.isEmpty()) {
1433 modules.sort(new MavenLikeVersioningComparator());
1434 Collections.reverse (modules);
1435 module = modules.get(0);
1438 if (module == null) {
1439 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1441 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
1446 public VfModuleCustomization getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
1447 long startTime = System.currentTimeMillis();
1448 LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
1450 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid ";
1451 Query query = getSession().createQuery(hql);
1452 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1453 VfModuleCustomization module = null;
1455 module = (VfModuleCustomization) query.uniqueResult ();
1456 } catch (org.hibernate.NonUniqueResultException nure) {
1457 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
1458 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1461 } catch (org.hibernate.HibernateException he) {
1462 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1463 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1466 } catch (Exception e) {
1467 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1468 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1472 if (module == null) {
1473 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1475 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
1481 public VfModule getVfModuleByModelInvariantUuidAndModelVersion(String modelInvariantUuid, String modelVersion) {
1482 long startTime = System.currentTimeMillis();
1483 LOGGER.debug ("Catalog database - get getVfModuleByModelInvariantUuidAndModelVersion with modelInvariantUuid: " + modelInvariantUuid + ", modelVersion: " + modelVersion);
1485 String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUuid and version = :modelVersion";
1486 Query query = getSession().createQuery(hql);
1487 query.setParameter ("modelInvariantUuid", modelInvariantUuid);
1488 query.setParameter("modelVersion", modelVersion);
1489 VfModule module = null;
1491 module = (VfModule) query.uniqueResult ();
1492 } catch (org.hibernate.NonUniqueResultException nure) {
1493 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "'");
1494 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);
1496 } catch (org.hibernate.HibernateException he) {
1497 LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + he.getMessage());
1498 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1500 } catch (Exception e) {
1501 LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + e.getMessage());
1502 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
1505 if (module == null) {
1506 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1508 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
1514 * Return the VfModuleCustomization object identified by the given modelCustomizationUuid 1707
1516 * @param modelCustomizationUuid
1517 * @return VfModuleCustomization or null if not found
1519 public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {
1520 long startTime = System.currentTimeMillis();
1521 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByModelCustomizationId with modelCustomizationUuid: " + modelCustomizationUuid);
1523 String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1524 Query query = getSession().createQuery(hql);
1525 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1526 VfModuleCustomization VfModuleCustomization = null;
1528 VfModuleCustomization = (VfModuleCustomization) query.uniqueResult ();
1529 } catch (org.hibernate.NonUniqueResultException nure) {
1530 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1531 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1533 } catch (org.hibernate.HibernateException he) {
1534 LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1535 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1537 } catch (Exception e) {
1538 LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1539 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1542 if (VfModuleCustomization != null) {
1543 LOGGER.debug("Found VMC of " + VfModuleCustomization.getModelCustomizationUuid() + ", now looking for vfModule=" + VfModuleCustomization.getVfModuleModelUuid());
1544 VfModuleCustomization.setVfModule(this.getVfModuleByModelUuid(VfModuleCustomization.getVfModuleModelUuid()));
1547 if (VfModuleCustomization == null) {
1548 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1550 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
1552 return VfModuleCustomization;
1556 * Return the VfModule object identified by the given modelUuid 1707
1557 * per Mike Z. - this may return more than one row - and even if it does,
1558 * the heat template will be the same - so just return any of the rows.
1561 * @return VfModule or null if not found
1563 public VfModule getVfModuleByModelUuid(String modelUuid) {
1564 long startTime = System.currentTimeMillis();
1565 LOGGER.debug ("Catalog database - get getVfModuleByModelUuid with modelUuid: " + modelUuid);
1567 String hql = "FROM VfModule WHERE modelUUID = :modelUuidValue";
1568 Query query = getSession().createQuery(hql);
1569 query.setParameter ("modelUuidValue", modelUuid);
1570 List<VfModule> vfModules = null;
1572 vfModules = query.list ();
1573 } catch (org.hibernate.HibernateException he) {
1574 LOGGER.debug("Hibernate Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + he.getMessage());
1575 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VfModule for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUuid=" + modelUuid);
1577 } catch (Exception e) {
1578 LOGGER.debug("Generic Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + e.getMessage());
1579 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUuid=" + modelUuid);
1583 if (vfModules == null || vfModules.isEmpty()) {
1584 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelUuid", null);
1587 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUuid", null);
1589 return vfModules.get(0);
1592 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1593 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1595 * @param modelCustomizationUuid
1596 * @return VnfResourceCustomization or null if not found
1598 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUuid(String modelCustomizationUuid) {
1599 long startTime = System.currentTimeMillis();
1600 LOGGER.debug ("Catalog database - get getVnfResourceByModelCustomizatonUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1602 String hql = "FROM VnfResourceCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
1603 Query query = getSession().createQuery(hql);
1604 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1605 VnfResourceCustomization vnfResourceCustomization = null;
1607 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1608 } catch (org.hibernate.NonUniqueResultException nure) {
1609 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
1610 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
1612 } catch (org.hibernate.HibernateException he) {
1613 LOGGER.debug("Hibernate Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
1614 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1616 } catch (Exception e) {
1617 LOGGER.debug("Generic Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
1618 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1621 if (vnfResourceCustomization != null) {
1622 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1623 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1624 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1625 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1628 if (vnfResourceCustomization == null) {
1629 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1631 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
1633 return vnfResourceCustomization;
1637 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1638 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1640 * @param getVnfResourceCustomizationByModelVersionId
1641 * @return VnfResourceCustomization or null if not found
1643 public VnfResourceCustomization getVnfResourceCustomizationByModelVersionId(String modelVersionId) {
1644 long startTime = System.currentTimeMillis();
1645 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelVersionId with modelVersionId: " + modelVersionId);
1647 String hql = "FROM VnfResourceCustomization WHERE vnfResourceModelUuid = :modelVersionId";
1648 Query query = getSession().createQuery(hql);
1649 query.setParameter ("modelVersionId", modelVersionId);
1650 VnfResourceCustomization vnfResourceCustomization = null;
1652 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1653 } catch (org.hibernate.NonUniqueResultException nure) {
1654 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"'");
1655 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId==" + modelVersionId);
1657 } catch (org.hibernate.HibernateException he) {
1658 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + he.getMessage());
1659 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId);
1661 } catch (Exception e) {
1662 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + e.getMessage());
1663 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId);
1666 if (vnfResourceCustomization != null) {
1667 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1668 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
1669 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1670 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1673 if (vnfResourceCustomization == null) {
1674 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1676 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
1678 return vnfResourceCustomization;
1682 * Return the VfModule object identified by the given modelCustomizationId, modelVersionId 1707
1684 * @param modelVersionId, modelCustomizationId
1685 * @return VfModule or null if not found
1687 public VfModule getVfModuleByModelCustomizationIdAndVersion(String modelCustomizationId, String modelVersionId) {
1688 long startTime = System.currentTimeMillis();
1689 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdAndVersion with modelVersionId: " + modelVersionId + " modelCustomizationId: " + modelCustomizationId);
1691 // select * from vf_module vfm where vfm.MODEL_UUID IN (
1692 // select vfmc.VF_MODULE_MODEL_UUID from vf_module_customization vfmc where vfmc.MODEL_CUSTOMIZATION_UUID='222bd8f2-341d-4419-aa0e-98398fa34050')
1693 // and vfm.MODEL_UUID = 'fa1c8558-006c-4fb6-82f2-4fc0646d6b06';
1695 String hql = "Select vfm FROM VfModule as vfm WHERE vfm.modelUUID IN ("
1696 + "SELECT vfmc.vfModuleModelUuid FROM VfModuleCustomization as vfmc "
1697 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId) "
1698 + "AND vfm.modelUUID = :modelVersionId";
1699 Query query = getSession().createQuery(hql);
1700 query.setParameter ("modelVersionId", modelVersionId);
1701 query.setParameter ("modelCustomizationId", modelCustomizationId);
1702 VfModule vfModule = null;
1704 vfModule = (VfModule) query.uniqueResult ();
1705 } catch (org.hibernate.NonUniqueResultException nure) {
1706 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"' modelCustomizationId='" + modelCustomizationId + "'");
1707 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1709 } catch (org.hibernate.HibernateException he) {
1710 LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1711 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1713 } catch (Exception e) {
1714 LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1715 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
1719 if (vfModule == null) {
1720 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1722 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
1728 * Return the VfModule object identified by the given modelCustomizationId, modelVersion, modelInvariantId 1707
1730 * @param modelCustomizationId, modelVersion, modelInvariantId
1731 * @return VfModule or null if not found
1733 public VfModule getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId(String modelCustomizationId, String modelVersion, String modelInvariantId) {
1734 long startTime = System.currentTimeMillis();
1735 LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId with modelVersionId: " + modelVersion);
1737 //select * from vf_module vfm left outer join vf_module_customization vfmc on vfmc.VF_MODULE_MODEL_UUID = vfm.MODEL_UUID
1738 // where vfmc.MODEL_CUSTOMIZATION_UUID='52643a8e-7953-4e48-8eab-97165b2b3a4b' and vfm.MODEL_UUID = ''
1740 String hql = "Select vfm FROM VfModule as vfm LEFT OUTER JOIN VfModuleCustomization as vfmc on vfmc.vfModuleModelUuid = vfm.modelUUID"
1741 + "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId AND vfm.modelInvariantUUID = :modelInvariantId AND vfm.modelVersion = :modelVersion";
1742 Query query = getSession().createQuery(hql);
1743 query.setParameter ("modelInvariantId", modelInvariantId);
1744 query.setParameter ("modelCustomizationId", modelCustomizationId);
1745 query.setParameter ("modelVersion", modelVersion);
1746 VfModule vfModule = null;
1748 vfModule = (VfModule) query.uniqueResult ();
1749 } catch (org.hibernate.NonUniqueResultException nure) {
1750 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 +"'");
1751 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);
1753 } catch (org.hibernate.HibernateException he) {
1754 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
1755 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);
1757 } catch (Exception e) {
1758 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
1759 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);
1763 if (vfModule == null) {
1764 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1766 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
1772 * Return the VnfResourceCustomization object identified by the given modelCustomizationName, modelInvariantId and modelVersion 1707
1774 * @param modelInvariantId, modelVersion, modelCustomizationName
1775 * @return VnfResourceCustomization or null if not found
1777 public VnfResourceCustomization getVnfResourceCustomizationByModelInvariantId(String modelInvariantId, String modelVersion, String modelCustomizationName) {
1778 long startTime = System.currentTimeMillis();
1779 LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelInvariantId with modelInvariantId: " + modelInvariantId + ", modelVersion: "
1780 + modelVersion + ", modelCustomizationName: " + modelCustomizationName);
1782 String hql = "SELECT VnfResourceCustomization FROM VnfResourceCustomization as vrc "
1783 + "LEFT OUTER JOIN VnfResource as vr "
1784 + "on vr.modelUuid =vrc.vnfResourceModelUuid "
1785 + "WHERE vr.modelInvariantUuid = :modelInvariantId AND vr.modelVersion = :modelVersion AND vrc.modelInstanceName = :modelCustomizationName";
1787 Query query = getSession().createQuery(hql);
1788 query.setParameter ("modelInvariantId", modelInvariantId);
1789 query.setParameter("modelVersion", modelVersion);
1790 query.setParameter("modelCustomizationName", modelCustomizationName);
1791 VnfResourceCustomization vnfResourceCustomization = null;
1793 vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
1794 } catch (org.hibernate.NonUniqueResultException nure) {
1795 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 + "'");
1796 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 + "'");
1798 } catch (org.hibernate.HibernateException he) {
1799 LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "' " + he.getMessage());
1800 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 + "'");
1802 } catch (Exception e) {
1803 LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' " + e.getMessage());
1804 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 + "'");
1807 if (vnfResourceCustomization != null) {
1808 LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
1809 vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUUID()));
1810 LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
1811 vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
1814 if (vnfResourceCustomization == null) {
1815 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1817 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
1819 return vnfResourceCustomization;
1823 * Return list of VnfResourceCustomization objects identified by the given modelCustomizationUuid 1707
1825 * @param modelCustomizationUuid
1826 * @return List<VfModuleCustomization> or null if not found
1828 public List<VfModuleCustomization> getVfModuleCustomizationByVnfModuleCustomizationUuid(String modelCustomizationUuid) {
1829 long startTime = System.currentTimeMillis();
1830 LOGGER.debug ("Catalog database - get getVfModuleCustomizationByVnfModuleCustomizationUuid with modelCustomizationUuid: " + modelCustomizationUuid);
1832 // select * from vf_module_customization as vfmc where vfmc.MODEL_CUSTOMIZATION_UUID IN(
1833 // select vrcmc.VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID from vnf_res_custom_to_vf_module_custom as vrcmc
1834 // where vrcmc.VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID = 'd279139c-4b85-48ff-8ac4-9b83a6fc6da7')
1836 String hql = "SELECT vfmc FROM VfModuleCustomization as vfmc where vfmc.modelCustomizationUuid "
1837 + "IN(select vrcmc.vfModuleCustModelCustomizationUuid from VnfResCustomToVfModuleCustom as vrcmc "
1838 + "WHERE vrcmc.vnfResourceCustModelCustomizationUuid = :modelCustomizationUuid)";
1840 Query query = getSession().createQuery(hql);
1841 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
1842 List<VfModuleCustomization> resultList = null;
1844 resultList = query.list();
1845 } catch (org.hibernate.HibernateException he) {
1846 LOGGER.debug("Hibernate Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + he.getMessage());
1847 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1849 } catch (Exception e) {
1850 LOGGER.debug("Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + e.getMessage());
1851 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
1855 if (resultList == null) {
1856 resultList = new ArrayList<>();
1858 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByVnfModuleCustomizationUuid", null);
1863 * Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
1865 * @return {@link VnfResourceCustomization} object or null if none found
1867 public VnfResourceCustomization getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId (String modelCustomizationName, String modelVersionId) {
1869 long startTime = System.currentTimeMillis ();
1870 LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " modelUUID " + modelVersionId);
1872 String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.vnfResourceModelUuid IN "
1873 + "(SELECT vr.modelUuid FROM VnfResource vr "
1874 + "WHERE vr.modelUuid = :modelVersionId)"
1875 + "AND vrc.modelInstanceName = :modelCustomizationName";
1877 Query query = getSession ().createQuery (hql);
1878 query.setParameter ("modelCustomizationName", modelCustomizationName);
1879 query.setParameter ("modelVersionId", modelVersionId);
1881 @SuppressWarnings("unchecked")
1882 List <VnfResourceCustomization> resultList = query.list ();
1884 if (resultList.isEmpty ()) {
1885 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1889 resultList.sort(new MavenLikeVersioningComparator());
1890 Collections.reverse (resultList);
1892 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
1893 return resultList.get (0);
1896 public ArrayList<VfModuleCustomization> getAllVfModuleCustomizations(String vnfResourceCustomizationMCU) {
1897 LOGGER.debug ("Catalog database - getAllVfModuleCustomizations with vnfResourceCustomizationMCU " + vnfResourceCustomizationMCU);
1899 List<VnfResCustomToVfModuleCustom> matches = this.getVRCtoVFMC(vnfResourceCustomizationMCU, null);
1900 if (matches == null || matches.isEmpty()) {
1901 LOGGER.debug("Found no vf modules for " + vnfResourceCustomizationMCU);
1902 return new ArrayList<>();
1904 ArrayList<VfModuleCustomization> list = new ArrayList<>();
1905 for (VnfResCustomToVfModuleCustom v : matches) {
1906 String m = v.getVfModuleCustModelCustomizationUuid();
1907 LOGGER.debug("VfModule to match: " + m);
1908 VfModuleCustomization c = this.getVfModuleCustomizationByModelCustomizationId(m);
1912 LOGGER.debug("**UNABLE to find vfModule " + m);
1919 * Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
1920 * Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
1922 * @param modelCustomizationUuid
1923 * @return VnfResourceCustomization or null if not found
1925 public VnfResource getVnfResourceByModelUuid(String modelUuid) {
1926 long startTime = System.currentTimeMillis();
1927 LOGGER.debug ("Catalog database - get VnfResource with modelUuid " + modelUuid);
1929 String hql = "FROM VnfResource WHERE modelUuid = :modelUuid";
1930 Query query = getSession().createQuery(hql);
1931 query.setParameter ("modelUuid", modelUuid);
1932 VnfResource vnfResource = null;
1934 vnfResource = (VnfResource) query.uniqueResult ();
1935 } catch (org.hibernate.NonUniqueResultException nure) {
1936 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique Vnf_Resource row - data integrity error: modelUuid='" + modelUuid);
1937 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for Vnf Resource modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResource modelUuid==" + modelUuid);
1939 } catch (org.hibernate.HibernateException he) {
1940 LOGGER.debug("Hibernate Exception - while searching for: VnfResource modelUuid='" + modelUuid + "' " + he.getMessage());
1941 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResource modelUuid=" + modelUuid);
1943 } catch (Exception e) {
1944 LOGGER.debug("Generic Exception - while searching for: vnfResource ModelUuid='" + modelUuid + "'");
1945 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResource modelUuid=" + modelUuid);
1948 if (vnfResource == null) {
1949 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelUuid", null);
1951 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelUuid", null);
1956 public VnfResCustomToVfModuleCustom getVnfResCustomToVfModule(String vnfId, String vfId) {
1957 long startTime = System.currentTimeMillis();
1958 LOGGER.debug("Catalog database - getVnfResCustomToVfModule - vnfResourceCustModelCustUuid: " + vnfId + ", vfModuleCustModelCustomUuid=" + vfId);
1959 HashMap<String, String> parameters = new HashMap<>();
1960 parameters.put("vnfIdValue", vnfId);
1961 parameters.put("vfIdValue", vfId);
1962 VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow(
1963 "FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue", parameters, true);
1964 if (vrctvmc == null) {
1965 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResCustomToVfModule", null);
1967 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResCustomToVfModule", null);
1972 public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
1973 if (vnfResource == null)
1974 return Collections.EMPTY_LIST;
1975 String vnfResourceModelUuid = vnfResource.getModelUuid();
1977 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
1979 return this.getVfModulesForVnfResource(vnfResourceModelUuid);
1983 public List<VfModule> getVfModulesForVnfResource(String vnfResourceModelUuid) {
1984 long startTime = System.currentTimeMillis();
1985 LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceModelUuid: " + vnfResourceModelUuid);
1986 Query query = getSession().createQuery("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId");
1987 query.setParameter("vnfResourceModelUUId", vnfResourceModelUuid);
1988 List<VfModule> resultList = null;
1990 resultList = query.list();
1991 if (resultList != null)
1992 LOGGER.debug("\tQuery found " + resultList.size() + " records.");
1994 LOGGER.debug("\tQuery found no records.");
1995 } catch (org.hibernate.HibernateException he) {
1996 LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + he.getMessage());
1997 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
1999 } catch (Exception e) {
2000 LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + e.getMessage());
2001 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
2004 if (resultList == null) {
2005 resultList = new ArrayList<>();
2007 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
2011 public Service getServiceByUuid (String serviceModelInvariantUuid) {
2013 long startTime = System.currentTimeMillis ();
2014 LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
2016 String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
2017 Query query = getSession ().createQuery (hql);
2018 query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
2020 Service service = null;
2022 service = (Service) query.uniqueResult ();
2023 } catch (org.hibernate.NonUniqueResultException nure) {
2024 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
2025 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2027 } catch (org.hibernate.HibernateException he) {
2028 LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "' " + he.getMessage());
2029 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2031 } catch (Exception e) {
2032 LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + " " + e.getMessage());
2033 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2036 if (service == null) {
2037 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
2039 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
2045 public NetworkResource getNetworkResourceById(Integer id) {
2046 long startTime = System.currentTimeMillis ();
2047 LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
2049 String hql = "FROM NetworkResource WHERE id = :id";
2050 Query query = getSession ().createQuery (hql);
2051 query.setParameter ("id", id);
2053 NetworkResource networkResource = null;
2055 networkResource = (NetworkResource) query.uniqueResult ();
2056 } catch (org.hibernate.NonUniqueResultException nure) {
2057 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
2058 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
2060 } catch (org.hibernate.HibernateException he) {
2061 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2062 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
2064 } catch (Exception e) {
2065 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2066 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
2070 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2071 return networkResource;
2075 public NetworkResource getNetworkResourceById(String id) {
2076 long startTime = System.currentTimeMillis ();
2077 LOGGER.debug ("Catalog database - getNetworkResource with model_uuid " + id);
2079 String hql = "FROM NetworkResource WHERE modelUUID = :model_uuid";
2080 Query query = getSession ().createQuery (hql);
2081 query.setParameter ("model_uuid", id);
2083 List<NetworkResource> networkResources = null;
2085 networkResources = query.list ();
2086 } catch (org.hibernate.HibernateException he) {
2087 LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
2088 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);
2090 } catch (Exception e) {
2091 LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
2092 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);
2096 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
2097 if (networkResources == null || networkResources.isEmpty())
2100 return networkResources.get(0);
2105 public static boolean isEmptyOrNull(String str) {
2108 if ("null".equals(str))
2115 public List<ServiceToResourceCustomization> getSTR(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
2116 LOGGER.debug("Catalog database: getSTR - smu=" + serviceModelUuid + ", rmcu=" + resourceModelCustomizationUuid + ", modelType = " + modelType);
2118 if (isEmptyOrNull(serviceModelUuid) && isEmptyOrNull(resourceModelCustomizationUuid) && isEmptyOrNull(modelType))
2121 StringBuilder hql = new StringBuilder("FROM ServiceToResourceCustomization WHERE ");
2122 boolean first = true;
2123 if (serviceModelUuid != null && !serviceModelUuid.equals("")) {
2124 hql.append("serviceModelUUID = :smu");
2127 if (resourceModelCustomizationUuid != null && !resourceModelCustomizationUuid.equals("")) {
2129 hql.append(" AND ");
2131 hql.append("resourceModelCustomizationUUID = :rmcu");
2134 if (modelType != null && !modelType.equals("")) {
2136 hql.append(" AND ");
2139 hql.append("modelType = :modelType");
2142 Query query = getSession().createQuery(hql.toString());
2143 if (hql.toString().contains(":smu"))
2144 query.setParameter("smu", serviceModelUuid);
2145 if (hql.toString().contains(":rmcu"))
2146 query.setParameter("rmcu", resourceModelCustomizationUuid);
2147 if (hql.toString().contains(":modelType"))
2148 query.setParameter("modelType", modelType);
2149 LOGGER.debug("query - " + hql.toString());
2151 @SuppressWarnings("unchecked")
2152 List<ServiceToResourceCustomization> resultList = query.list();
2153 if (resultList == null || resultList.isEmpty()) {
2154 LOGGER.debug("Found no matches to the query - " + hql.toString());
2155 return new ArrayList<>();
2160 public List<VnfResCustomToVfModuleCustom> getVRCtoVFMC (String vrc_mcu, String vfmc_mcu) {
2161 LOGGER.debug("Catalog database: getVRCtoVFMC - vrc_mcu=" + vrc_mcu + ", vfmc_mcu=" + vfmc_mcu);
2163 if (isEmptyOrNull(vrc_mcu) && isEmptyOrNull(vfmc_mcu))
2166 StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom WHERE ");
2167 boolean first = true;
2168 if (vrc_mcu != null && !vrc_mcu.equals("")) {
2169 hql.append("vnfResourceCustModelCustomizationUuid = :vrc_mcu");
2172 if (vfmc_mcu != null && !vfmc_mcu.equals("")) {
2174 hql.append(" AND ");
2176 hql.append("vfModuleCustModelCustomizationUuid = :vfmc_mcu");
2179 Query query = getSession().createQuery(hql.toString());
2180 if (hql.toString().contains(":vrc_mcu"))
2181 query.setParameter("vrc_mcu", vrc_mcu);
2182 if (hql.toString().contains(":vfmc_mcu"))
2183 query.setParameter("vfmc_mcu", vfmc_mcu);
2184 @SuppressWarnings("unchecked")
2185 List<VnfResCustomToVfModuleCustom> resultList = query.list();
2186 if (resultList == null || resultList.isEmpty()) {
2187 LOGGER.debug("Found no matches to the query - " + hql.toString());
2188 return new ArrayList<>();
2193 @SuppressWarnings("unchecked")
2194 public List <TempNetworkHeatTemplateLookup> getTempNetworkHeatTemplateLookup (String networkResourceModelName) {
2196 long startTime = System.currentTimeMillis ();
2197 LOGGER.debug ("Catalog database - GetTempNetworkHeatTemplateLookup for Network Name " + networkResourceModelName);
2199 String hql = "FROM TempNetworkHeatTemplateLookup where networkResourceModelName = :networkResourceModelName";
2200 Query query = getSession ().createQuery (hql);
2201 query.setParameter ("networkResourceModelName", networkResourceModelName);
2203 List <TempNetworkHeatTemplateLookup> result = query.list ();
2204 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getTempNetworkHeatTemplateLookup", null);
2208 // 1702 API Spec - Query for all networks in a Service:
2209 public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
2210 long startTime = System.currentTimeMillis();
2211 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
2213 List<ServiceToResourceCustomization> strMappings = this.getSTR(serviceModelUuid, null, "network");
2214 if (strMappings == null || strMappings.isEmpty()) {
2215 LOGGER.debug("Found NO matches for NRC with ServiceModelUuid=" + serviceModelUuid);
2216 return new ArrayList<>();
2218 LOGGER.debug("Found " + strMappings.size() + " entries in ServiceToResourceCustomizations.network with smu=" + serviceModelUuid);
2220 ArrayList<NetworkResourceCustomization> masterList = new ArrayList<>();
2221 for (ServiceToResourceCustomization stn : strMappings) {
2222 String networkModelCustomizationUuid = stn.getResourceModelCustomizationUUID();
2223 LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
2224 List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
2225 masterList.addAll(resultSet);
2227 LOGGER.debug("Returning " + masterList.size() + " NRC records");
2228 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
2231 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2232 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2234 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2235 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2236 @SuppressWarnings("unchecked")
2237 List<Service> serviceList = query.list();
2239 if (serviceList.isEmpty()) {
2240 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2241 return new ArrayList<>();
2244 serviceList.sort(new MavenLikeVersioningComparator());
2245 Collections.reverse (serviceList);
2246 Service service = serviceList.get(0);
2248 String serviceNameVersionId = service.getModelUUID();
2249 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
2251 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2252 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2254 public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2255 LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2257 Query query = getSession().createQuery(
2258 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2259 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2260 query.setParameter("serviceModelVersion", serviceModelVersion);
2263 //can fix this later - no time - could do a unique query here - but this should work
2264 @SuppressWarnings("unchecked")
2265 List<Service> serviceList = query.list();
2267 if (serviceList.isEmpty()) {
2268 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2269 return new ArrayList<>();
2272 serviceList.sort(new MavenLikeVersioningComparator());
2273 Collections.reverse (serviceList);
2274 Service service = serviceList.get(0);
2276 String serviceNameVersionId = service.getModelUUID();
2278 // Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
2279 return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
2282 public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
2283 long startTime = System.currentTimeMillis();
2284 LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
2286 //Query query = getSession().createQuery(hql.toString());
2287 //query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
2288 //LOGGER.debug("QUERY: " + hql.toString() + ", networkModelCustomizationUuid=" + networkModelCustomizationUuid);
2290 //@SuppressWarnings("unchecked")
2291 //List<NetworkResourceCustomization> resultList = query.list();
2293 HashMap<String, String> params = new HashMap<>();
2294 params.put("networkModelCustomizationUuid", networkModelCustomizationUuid);
2296 List<NetworkResourceCustomization> resultList = this.executeQueryMultipleRows(
2297 "FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid", params, true);
2299 if (resultList.isEmpty()) {
2300 LOGGER.debug("Unable to find an NMC with nmcu=" + networkModelCustomizationUuid);
2301 return new ArrayList<>();
2303 for (NetworkResourceCustomization nrc : resultList) {
2304 nrc.setNetworkResource(this.getNetworkResourceById(nrc.getNetworkResourceModelUuid()));
2307 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
2311 public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
2312 long startTime = System.currentTimeMillis();
2313 LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
2315 NetworkResource nr = this.getNetworkResource(networkType);
2317 return new ArrayList<>();
2319 String networkResourceId = nr.getModelUUID();
2321 LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
2323 Query query = getSession().createQuery(
2324 "FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId");
2325 query.setParameter("networkResourceId", networkResourceId);
2327 @SuppressWarnings("unchecked")
2328 List<NetworkResourceCustomization> resultList = query.list();
2330 if (resultList != null && ! resultList.isEmpty()) {
2331 LOGGER.debug("Found " + resultList.size() + " results");
2332 for (NetworkResourceCustomization nrc : resultList) {
2333 nrc.setNetworkType(networkType);
2334 nrc.setNetworkResource(nr);
2337 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
2341 public ArrayList<VfModuleCustomization> getAllVfmcForVrc(VnfResourceCustomization vrc) {
2342 LOGGER.debug("Catalog database: getAllVfmcForVrc - " + vrc.getModelCustomizationUuid());
2344 List<VnfResCustomToVfModuleCustom> vfmcs = this.getVRCtoVFMC(vrc.getModelCustomizationUuid(), null);
2345 if (vfmcs == null || vfmcs.isEmpty()) {
2346 return new ArrayList<>();
2348 ArrayList<VfModuleCustomization> vfModuleCusts = new ArrayList<>();
2349 for (VnfResCustomToVfModuleCustom vfmc : vfmcs) {
2350 VfModuleCustomization vfmcust = this.getVfModuleCustomizationByModelCustomizationId(vfmc.getVfModuleCustModelCustomizationUuid());
2351 if (vfmcust != null) {
2352 vfModuleCusts.add(vfmcust);
2355 return vfModuleCusts;
2358 //1702 API Spec cont'd - Query for all VnfResources in a Service:
2359 //1707 modified for db refactoring
2360 public List<VnfResourceCustomization> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
2361 LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
2363 Query query = getSession().createQuery("FROM Service WHERE modelUUID = :serviceModelUuid");
2364 query.setParameter("serviceModelUuid", serviceModelUuid);
2365 @SuppressWarnings("unchecked")
2366 List<Service> serviceList = query.list();
2368 if (serviceList.isEmpty()) {
2369 LOGGER.debug("Unable to find a service with modelUuid=" + serviceModelUuid);
2370 return new ArrayList<>();
2373 serviceList.sort(new MavenLikeVersioningComparator());
2374 Collections.reverse (serviceList);
2376 // Step 2 - Now query to get the related VnfResourceCustomizations
2378 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "vnf");
2380 if (strcs.isEmpty()) {
2381 LOGGER.debug("Unable to find any related vnfs to a service with modelUuid=" + serviceModelUuid);
2382 return new ArrayList<>();
2385 ArrayList<VnfResourceCustomization> allVrcs = new ArrayList<>();
2386 for (ServiceToResourceCustomization strc : strcs) {
2387 LOGGER.debug("Try to find VRC for mcu=" + strc.getResourceModelCustomizationUUID());
2388 VnfResourceCustomization vrc = this.getVnfResourceCustomizationByModelCustomizationUuid(strc.getResourceModelCustomizationUUID());
2395 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2396 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2398 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2399 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2400 @SuppressWarnings("unchecked")
2401 List<Service> resultList = query.list();
2403 if (resultList.isEmpty()) {
2404 return new ArrayList<>();
2406 resultList.sort(new MavenLikeVersioningComparator());
2407 Collections.reverse (resultList);
2408 Service service = resultList.get(0);
2409 //now just call the method that takes the version - the service object will have the highest version
2410 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2412 public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2413 long startTime = System.currentTimeMillis();
2414 LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2416 Query query = getSession().createQuery(
2417 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2418 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2419 query.setParameter("serviceModelVersion", serviceModelVersion);
2421 @SuppressWarnings("unchecked")
2422 List<Service> resultList = query.list();
2424 if (resultList.isEmpty()) {
2425 return new ArrayList<>();
2427 resultList.sort(new MavenLikeVersioningComparator());
2428 Collections.reverse (resultList);
2429 Service service = resultList.get(0);
2430 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
2431 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2434 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
2435 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
2436 if (serviceVersion == null || serviceVersion.equals("")) {
2437 return this.getAllVnfsByServiceName(serviceName);
2440 Query query = getSession().createQuery(
2441 "FROM Service WHERE modelName = :serviceName and version = :serviceVersion");
2442 query.setParameter("serviceName", serviceName);
2443 query.setParameter("serviceVersion", serviceVersion);
2445 @SuppressWarnings("unchecked")
2446 List<Service> resultList = query.list();
2448 if (resultList.isEmpty()) {
2449 return Collections.EMPTY_LIST;
2451 Service service = resultList.get(0);
2452 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2454 public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName) {
2455 LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
2457 Query query = getSession().createQuery("FROM Service WHERE modelName = :serviceName");
2458 query.setParameter("serviceName", serviceName);
2460 @SuppressWarnings("unchecked")
2461 List<Service> resultList = query.list();
2463 if (resultList.isEmpty()) {
2464 return Collections.EMPTY_LIST;
2466 resultList.sort(new MavenLikeVersioningComparator());
2467 Collections.reverse (resultList);
2468 Service service = resultList.get(0);
2470 return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2473 public List<VnfResourceCustomization> getAllVnfsByVnfModelCustomizationUuid(String vnfModelCustomizationUuid) {
2474 long startTime = System.currentTimeMillis();
2475 LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid);
2477 Query query1 = getSession().createQuery("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu");
2478 query1.setParameter("vrcmcu", vnfModelCustomizationUuid);
2479 @SuppressWarnings("unchecked")
2480 List<VnfResourceCustomization> resultList1 = query1.list();
2482 if (resultList1.isEmpty()) {
2483 LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
2484 return Collections.EMPTY_LIST;
2487 for (VnfResourceCustomization vrc : resultList1) {
2488 VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid());
2489 vrc.setVnfResource(vr);
2490 vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc));
2493 LOGGER.debug("Returning " + resultList1.size() + " vnf modules");
2494 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
2498 //1702 API Spec cont'd - Query for all allotted resources in a Service
2500 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
2501 long startTime = System.currentTimeMillis();
2502 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
2504 List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "allottedResource");
2505 if (strcs == null || strcs.isEmpty()) {
2506 LOGGER.debug("No AR entries found for " + serviceModelUuid);
2507 return new ArrayList<>();
2509 LOGGER.debug("Found " + strcs.size() + " entries in ServiceToResourceCustomizations with smu=" + serviceModelUuid + ", allottedResource");
2511 ArrayList<AllottedResourceCustomization> masterList = new ArrayList<>();
2512 for (ServiceToResourceCustomization star : strcs) {
2513 String arModelCustomizationUuid = star.getResourceModelCustomizationUUID();
2514 LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
2515 List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
2516 masterList.addAll(resultSet);
2518 LOGGER.debug("Returning " + masterList.size() + " ARC records");
2519 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
2523 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2524 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2526 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2527 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2528 @SuppressWarnings("unchecked")
2529 List<Service> serviceList = query.list();
2531 if (serviceList.isEmpty()) {
2532 LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
2533 return new ArrayList<>();
2536 serviceList.sort(new MavenLikeVersioningComparator());
2537 Collections.reverse (serviceList);
2538 Service service = serviceList.get(0);
2540 String serviceModelUuid = service.getModelUUID();
2541 LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceModelUuid);
2543 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2546 public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2547 LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2549 Query query = getSession().createQuery(
2550 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2551 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2552 query.setParameter("serviceModelVersion", serviceModelVersion);
2554 @SuppressWarnings("unchecked")
2555 List<Service> serviceList = query.list();
2557 if (serviceList.isEmpty()) {
2558 LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
2559 return new ArrayList<>();
2562 serviceList.sort(new MavenLikeVersioningComparator());
2563 Collections.reverse (serviceList);
2564 Service service = serviceList.get(0);
2566 String serviceModelUuid = service.getModelUUID();
2568 return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2571 public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
2572 long startTime = System.currentTimeMillis();
2573 LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
2575 Query query = getSession().createQuery(
2576 "FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
2577 query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
2579 @SuppressWarnings("unchecked")
2580 List<AllottedResourceCustomization> resultList = query.list();
2582 if (resultList.isEmpty()) {
2583 LOGGER.debug("No ARC found with arc_mcu=" + arModelCustomizationUuid);
2584 return new ArrayList<>();
2586 // There should only be one - but we'll handle if multiple
2587 for (AllottedResourceCustomization arc : resultList) {
2588 AllottedResource ar = this.getAllottedResourceByModelUuid(arc.getArModelUuid());
2589 arc.setAllottedResource(ar);
2592 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
2596 public AllottedResource getAllottedResourceByModelUuid(String arModelUuid) {
2597 long startTime = System.currentTimeMillis ();
2598 LOGGER.debug ("Catalog database - get Allotted Resource with modelUuid= " + arModelUuid);
2600 String hql = "FROM AllottedResource WHERE modelUuid = :arModelUuid";
2601 Query query = getSession ().createQuery (hql);
2602 query.setParameter ("arModelUuid", arModelUuid);
2604 @SuppressWarnings("unchecked")
2605 List <AllottedResource> resultList = query.list ();
2607 // See if something came back. Name is unique, so
2608 if (resultList.isEmpty ()) {
2609 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. AllottedResource not found", "CatalogDB", "getAllottedResourceByModelUuid", null);
2612 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllottedResourceByModelUuid", null);
2613 return resultList.get (0);
2617 //1702 API Spec cont'd - Query for all resources in a Service:
2618 public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
2619 long startTime = System.currentTimeMillis();
2620 LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
2622 StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
2623 Query query = getSession().createQuery(hql.toString());
2624 query.setParameter("serviceModelUuid", serviceModelUuid);
2625 LOGGER.debug("Query: " + hql.toString() + ", smu=" + serviceModelUuid);
2626 @SuppressWarnings("unchecked")
2627 List<Service> serviceList = query.list();
2629 if (serviceList.isEmpty()) {
2630 LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
2631 return new ServiceMacroHolder();
2634 serviceList.sort(new MavenLikeVersioningComparator());
2635 Collections.reverse (serviceList);
2636 Service service = serviceList.get(0);
2638 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2639 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
2640 smh.setNetworkResourceCustomization(nrcList);
2641 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
2642 smh.setAllottedResourceCustomization(arcList);
2643 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(serviceModelUuid);
2644 smh.setVnfResourceCustomizations(vnfList);
2646 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
2649 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
2650 long startTime = System.currentTimeMillis();
2651 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
2653 Query query = getSession().createQuery("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
2654 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2655 @SuppressWarnings("unchecked")
2656 List<Service> serviceList = query.list();
2658 if (serviceList.isEmpty()) {
2659 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
2660 return new ServiceMacroHolder();
2663 serviceList.sort(new MavenLikeVersioningComparator());
2664 Collections.reverse (serviceList);
2665 Service service = serviceList.get(0);
2667 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2668 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2669 smh.setNetworkResourceCustomization(nrcList);
2670 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2671 smh.setAllottedResourceCustomization(arcList);
2672 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2673 smh.setVnfResourceCustomizations(vnfList);
2675 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
2679 public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
2680 long startTime = System.currentTimeMillis();
2681 LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
2683 Query query = getSession().createQuery(
2684 "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
2685 query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
2686 query.setParameter("serviceModelVersion", serviceModelVersion);
2687 //TODO make this a unique query
2688 @SuppressWarnings("unchecked")
2689 List<Service> serviceList = query.list();
2691 if (serviceList.isEmpty()) {
2692 LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
2693 return new ServiceMacroHolder();
2696 serviceList.sort(new MavenLikeVersioningComparator());
2697 Collections.reverse (serviceList);
2698 Service service = serviceList.get(0);
2700 ServiceMacroHolder smh = new ServiceMacroHolder(service);
2701 ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
2702 smh.setNetworkResourceCustomization(nrcList);
2703 ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
2704 smh.setAllottedResourceCustomization(arcList);
2705 ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
2706 smh.setVnfResourceCustomizations(vnfList);
2708 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
2712 // 1707 New API queries
2713 public NetworkResourceCustomization getSingleNetworkByModelCustomizationUuid(String modelCustomizationUuid) {
2714 LOGGER.debug("Catalog database; getSingleNetworkByModelCustomizationUuid - " + modelCustomizationUuid);
2715 List<NetworkResourceCustomization> resultList = this.getAllNetworksByNetworkModelCustomizationUuid(modelCustomizationUuid);
2716 if (resultList == null || resultList.isEmpty()) {
2719 return resultList.get(0);
2721 public AllottedResourceCustomization getSingleAllottedResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2722 LOGGER.debug("Catalog database; getSingleAllottedResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2723 List<AllottedResourceCustomization> resultList = this.getAllAllottedResourcesByArModelCustomizationUuid(modelCustomizationUuid);
2724 if (resultList == null || resultList.isEmpty()) {
2727 return resultList.get(0);
2730 public VnfResource getSingleVnfResourceByModelCustomizationUuid(String modelCustomizationUuid) {
2732 long startTime = System.currentTimeMillis();
2733 LOGGER.debug("Catalog database; getSingleVnfResourceByModelCustomizationUuid - " + modelCustomizationUuid);
2734 List<VnfResource> resultList = this.getAllVnfsByVnfModelCustomizationUuid(modelCustomizationUuid);
2735 if (resultList == null || resultList.size() < 1) {
2738 return resultList.get(0);
2743 private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
2744 HashMap<String, NetworkResource> networkResources = new HashMap<>();
2746 for (NetworkResourceCustomization nrc : resultList) {
2747 String network_id = nrc.getNetworkResourceModelUuid();
2748 if (network_id == null) {
2749 nrc.setNetworkResource(null);
2750 nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
2753 if (networkResources.containsKey(network_id)) {
2754 nrc.setNetworkResource(networkResources.get(network_id));
2755 nrc.setNetworkType(networkResources.get(network_id).getModelName());
2757 NetworkResource nr = this.getNetworkResourceById(network_id);
2759 nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
2761 nrc.setNetworkType(nr.getModelName());
2762 nrc.setNetworkResource(nr);
2763 networkResources.put(network_id, nr);
2770 * Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
2771 * first query VF_MODULE table by type, and then use the ID to query
2772 * VNF_RECIPE by VF_MODULE_ID and ACTION
2775 * @parm vfModuleModelName
2777 * @return VnfRecipe object or null if none found
2779 public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
2780 String vfModuleType = vnfType + "::" + vfModuleModelName;
2782 long startTime = System.currentTimeMillis ();
2783 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
2785 Query query = getSession ().createQuery ("FROM VfModule WHERE type = :type ");
2786 query.setParameter (TYPE, vfModuleType);
2788 @SuppressWarnings("unchecked")
2789 List <VfModule> resultList = query.list ();
2791 if (resultList.isEmpty ()) {
2792 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
2796 resultList.sort(new MavenLikeVersioningComparator());
2797 Collections.reverse (resultList);
2799 VfModule vfMod = resultList.get(0);
2801 String vfModuleId = vfMod.getModelUUID();
2803 LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
2807 Query query1 = getSession ().createQuery ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2808 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2809 query1.setParameter (ACTION, action);
2811 @SuppressWarnings("unchecked")
2812 List <VnfRecipe> resultList1 = query1.list ();
2814 if (resultList1.isEmpty ()) {
2815 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
2819 resultList1.sort(new MavenLikeVersioningComparator());
2820 Collections.reverse (resultList1);
2822 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
2823 return resultList1.get (0);
2827 * Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2828 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2830 * @param vnfModuleType
2831 * @parm modelCustomizationUuid
2832 * @param asdcServiceModelVersion
2833 * @param modelVersion
2835 * @return VfModule list
2837 public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2840 if(modelCustomizationUuid != null){
2841 hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
2843 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2845 query = getSession ().createQuery (hql.toString ());
2846 query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
2847 query.setParameter ("version", asdcServiceModelVersion);
2849 hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
2851 LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
2853 query = getSession ().createQuery (hql.toString ());
2854 query.setParameter (TYPE, vfModuleType);
2855 query.setParameter ("version", asdcServiceModelVersion);
2856 query.setParameter ("modelVersion", modelVersion);
2859 @SuppressWarnings("unchecked")
2860 List <VfModule> resultList = query.list ();
2866 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2867 * MODEL_CUSTOMIZATION_UUID, ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2868 * first query VF_MODULE table by type, and then use the ID to query
2869 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2872 * @parm vfModuleModelName
2874 * @return VnfRecipe object or null if none found
2876 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
2877 String vfModuleType = vnfType + "::" + vfModuleModelName;
2878 long startTime = System.currentTimeMillis ();
2879 List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
2881 if (resultList.isEmpty ()) {
2882 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2886 resultList.sort(new MavenLikeVersioningComparator());
2887 Collections.reverse (resultList);
2889 VfModule vfMod = resultList.get(0);
2891 String vfModuleId = vfMod.getModelUUID();
2893 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2897 Query query1 = getSession ().createQuery (
2898 "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2899 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2900 query1.setParameter (ACTION, action);
2902 @SuppressWarnings("unchecked")
2903 List <VnfComponentsRecipe> resultList1 = query1.list ();
2905 if (resultList1.isEmpty ()) {
2906 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2910 resultList1.sort(new MavenLikeVersioningComparator());
2911 Collections.reverse (resultList1);
2913 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2914 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2915 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);
2918 return resultList1.get (0);
2922 * Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
2923 * ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
2924 * first query VF_MODULE table by type, and then use the ID to query
2925 * VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
2928 * @parm vfModuleModelName
2930 * @return VnfRecipe object or null if none found
2932 public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
2933 long startTime = System.currentTimeMillis ();
2935 if (resultList.isEmpty ()) {
2936 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
2940 resultList.sort(new MavenLikeVersioningComparator());
2941 Collections.reverse (resultList);
2943 VfModule vfMod = resultList.get(0);
2945 String vfModuleId = vfMod.getModelName();
2947 LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
2951 Query query1 = getSession ().createQuery (
2952 "FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
2953 query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
2954 query1.setParameter (ACTION, action);
2956 @SuppressWarnings("unchecked")
2957 List <VnfComponentsRecipe> resultList1 = query1.list ();
2959 if (resultList1.isEmpty ()) {
2960 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
2964 resultList1.sort(new MavenLikeVersioningComparator());
2965 Collections.reverse (resultList1);
2967 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
2968 if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
2969 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);
2972 return resultList1.get (0);
2977 * Return all VNF Resources in the Catalog DB
2979 * @return A list of VnfResource objects
2981 @SuppressWarnings("unchecked")
2982 public List <VnfResource> getAllVnfResources () {
2984 long startTime = System.currentTimeMillis ();
2985 LOGGER.debug ("Catalog database - get all VNF resources");
2987 String hql = "FROM VnfResource";
2988 Query query = getSession ().createQuery (hql);
2990 List <VnfResource> result = query.list ();
2991 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
2996 * Return VNF Resources in the Catalog DB that match a given VNF role
2998 * @return A list of VnfResource objects
3000 @SuppressWarnings("unchecked")
3001 @Deprecated // vnfRole is no longer in VnfResource
3002 public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
3004 long startTime = System.currentTimeMillis ();
3005 LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
3007 String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
3008 Query query = getSession ().createQuery (hql);
3009 query.setParameter ("vnfRole", vnfRole);
3011 List <VnfResource> resources = query.list ();
3012 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
3017 * Return VNF Resources in the Catalog DB that match a given VNF role
3019 * @return A list of VnfResource objects
3021 @SuppressWarnings("unchecked")
3022 public List<VnfResourceCustomization> getVnfResourceCustomizationsByRole(String vnfRole) {
3023 long startTime = System.currentTimeMillis ();
3024 LOGGER.debug ("Catalog database - get all VNF resource customizations for role " + vnfRole);
3026 String hql = "FROM VnfResourceCustomization WHERE nfRole = :vnfRole";
3027 Query query = getSession ().createQuery (hql);
3028 query.setParameter ("vnfRole", vnfRole);
3030 List <VnfResourceCustomization> resources = query.list ();
3031 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationsByRole", null);
3036 * Return all Network Resources in the Catalog DB
3038 * @return A list of NetworkResource objects
3040 @SuppressWarnings("unchecked")
3041 public List <NetworkResource> getAllNetworkResources () {
3043 long startTime = System.currentTimeMillis ();
3044 LOGGER.debug ("Catalog database - get all network resources");
3046 String hql = "FROM NetworkResource";
3047 Query query = getSession ().createQuery (hql);
3049 List <NetworkResource> result = query.list ();
3050 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
3054 @SuppressWarnings("unchecked")
3055 public List<NetworkResourceCustomization> getAllNetworkResourceCustomizations() {
3056 long startTime = System.currentTimeMillis ();
3057 LOGGER.debug ("Catalog database - get all network resource customizations");
3059 String hql = "FROM NetworkResourceCustomization";
3060 Query query = getSession ().createQuery (hql);
3062 List <NetworkResourceCustomization> result = query.list ();
3063 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResourceCustomizations", null);
3068 * Return all VF Modules in the Catalog DB
3070 * @return A list of VfModule objects
3072 @SuppressWarnings("unchecked")
3073 public List <VfModule> getAllVfModules () {
3075 long startTime = System.currentTimeMillis ();
3076 LOGGER.debug ("Catalog database - get all vf modules");
3078 String hql = "FROM VfModule";
3079 Query query = getSession ().createQuery (hql);
3081 List <VfModule> result = query.list ();
3082 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
3086 @SuppressWarnings("unchecked")
3087 public List <VfModuleCustomization> getAllVfModuleCustomizations () {
3089 long startTime = System.currentTimeMillis ();
3090 LOGGER.debug ("Catalog database - get all vf module customizations");
3092 String hql = "FROM VfModuleCustomization";
3093 Query query = getSession ().createQuery (hql);
3095 List <VfModuleCustomization> result = query.list ();
3096 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModuleCustomizations", null);
3102 * Return all HeatEnvironment in the Catalog DB
3104 * @return A list of HeatEnvironment objects
3106 @SuppressWarnings("unchecked")
3107 public List <HeatEnvironment> getAllHeatEnvironment () {
3109 long startTime = System.currentTimeMillis ();
3110 LOGGER.debug ("Catalog database - get all Heat environments");
3112 String hql = "FROM HeatEnvironment";
3113 Query query = getSession ().createQuery (hql);
3115 List <HeatEnvironment> result = query.list ();
3116 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
3121 * Fetch the Environment by Environment ID - 1510
3123 @Deprecated // no longer in heat envt table
3124 public HeatEnvironment getHeatEnvironment (int id) {
3126 long startTime = System.currentTimeMillis ();
3127 LOGGER.debug ("Catalog database - get Heat environment with id " + id);
3129 String hql = "FROM HeatEnvironment WHERE id = :idValue";
3131 LOGGER.debug ("getHeatEnvironment called with id=" + id);
3133 Query query = getSession ().createQuery (hql);
3134 query.setParameter ("idValue", id);
3136 @SuppressWarnings("unchecked")
3137 List <HeatEnvironment> resultList = query.list ();
3139 // See if something came back.
3140 if (resultList.isEmpty ()) {
3141 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
3144 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
3145 return resultList.get (0);
3149 * Fetch the nested templates - 1510
3153 public Map <String, Object> getNestedTemplates (int templateId) {
3154 Map <String, Object> nestedTemplates;
3155 long startTime = System.currentTimeMillis ();
3156 LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
3158 String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
3160 Query query = getSession ().createQuery (hql);
3161 query.setParameter ("parentIdValue", templateId);
3163 @SuppressWarnings("unchecked")
3164 List <HeatNestedTemplate> resultList = query.list ();
3165 // If nothing comes back, there are no nested templates
3166 if (resultList.isEmpty ()) {
3167 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3168 LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
3171 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3172 nestedTemplates = new HashMap <> ();
3173 for (HeatNestedTemplate hnt : resultList) {
3174 LOGGER.debug ("Querying for " + hnt);
3175 HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
3177 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3180 String providerResourceFile = hnt.getProviderResourceFile ();
3181 String heatTemplateBody = ht.getTemplateBody ();
3182 if (providerResourceFile != null && heatTemplateBody != null) {
3183 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3185 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3188 // Make sure we're not returning an empty map - if so, just return null
3189 if (nestedTemplates.isEmpty ()) {
3190 LOGGER.debug ("nestedTemplates is empty - just return null");
3191 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3194 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3195 return nestedTemplates;
3198 * Return a Map<String, Object> for returning the child templates and their contents
3200 * @param parentHeatTemplateId
3201 * @return Map<String,Object> or null if none found
3203 public Map <String, Object> getNestedTemplates (String parentHeatTemplateId) {
3204 Map <String, Object> nestedTemplates;
3205 long startTime = System.currentTimeMillis ();
3206 LOGGER.debug ("Catalog database - getNestedTemplates called with parentTemplateId " + parentHeatTemplateId);
3208 String hql = "FROM HeatNestedTemplate where parentTemplateId = :parentHeatTemplateId";
3210 Query query = getSession ().createQuery (hql);
3211 query.setParameter ("parentHeatTemplateId", parentHeatTemplateId);
3213 @SuppressWarnings("unchecked")
3214 List <HeatNestedTemplate> resultList = query.list ();
3215 // If nothing comes back, there are no nested templates
3216 if (resultList.isEmpty ()) {
3217 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
3218 LOGGER.debug ("No nestedTemplates found for templateId=" + parentHeatTemplateId + ", " + hql);
3221 // Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
3222 nestedTemplates = new HashMap <> ();
3223 for (HeatNestedTemplate hnt : resultList) {
3224 LOGGER.debug ("Querying for " + hnt);
3225 HeatTemplate ht = this.getHeatTemplateByArtifactUuid (hnt.getChildTemplateId ());
3227 LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
3230 String providerResourceFile = hnt.getProviderResourceFile ();
3231 String heatTemplateBody = ht.getTemplateBody ();
3232 if (providerResourceFile != null && heatTemplateBody != null) {
3233 nestedTemplates.put (providerResourceFile, heatTemplateBody);
3235 LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
3238 // Make sure we're not returning an empty map - if so, just return null
3239 if (nestedTemplates.isEmpty ()) {
3240 LOGGER.debug ("nestedTemplates is empty - just return null");
3241 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
3244 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
3245 return nestedTemplates;
3249 * Fetch any files in the HEAT_FILES table 1510
3252 public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
3253 Map <String, HeatFiles> heatFiles;
3255 long startTime = System.currentTimeMillis ();
3256 LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
3257 String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
3259 Query query = getSession ().createQuery (hql);
3260 query.setParameter ("vnfResourceIdValue", vnfResourceId);
3262 @SuppressWarnings("unchecked")
3263 List <HeatFiles> resultList = query.list ();
3264 // If nothing comes back, there are no heat files
3265 if (resultList.isEmpty ()) {
3266 LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
3267 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
3270 // Now, we just need to return a HashMap (key=fileName, object=fileBody)
3271 heatFiles = new HashMap <> ();
3272 for (HeatFiles hf : resultList) {
3273 LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
3274 heatFiles.put (hf.getFileName (), hf);
3276 // Make sure we're not returning an empty map - if so, just return null
3277 if (heatFiles.isEmpty ()) {
3278 LOGGER.debug ("heatFiles is empty - just return null");
3279 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
3282 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
3286 // New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
3288 public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
3290 Map <String, HeatFiles> heatFiles = null;
3292 long startTime = System.currentTimeMillis ();
3293 LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
3294 String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
3296 Query query = getSession ().createQuery (hql);
3297 query.setParameter ("vfModuleIdValue", vfModuleId);
3299 List<VfModuleToHeatFiles> mapList = query.list();
3300 if (mapList.isEmpty()) {
3301 LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
3302 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
3305 //Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
3306 heatFiles = new HashMap<String, HeatFiles>();
3307 for (VfModuleToHeatFiles vmthf : mapList) {
3308 int heatFilesId = vmthf.getHeatFilesId();
3309 hql = "FROM HeatFiles where id = :id_value";
3310 query = getSession().createQuery(hql);
3311 query.setParameter("id_value", heatFilesId);
3312 List<HeatFiles> fileList = query.list();
3313 if (fileList.isEmpty()) {
3314 // Should this throw an exception??
3315 LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
3316 String errorString = "_ERROR|" + heatFilesId;
3317 // The receiving code needs to know to throw an exception for this - or ignore it.
3318 heatFiles.put(errorString, null);
3320 // Should only ever have 1 result - add it to our Map
3321 LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
3322 for (HeatFiles hf : fileList) {
3323 LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
3324 heatFiles.put(hf.getFileName(), hf);
3328 if (heatFiles.isEmpty()) {
3329 LOGGER.debug ("heatFiles is empty - just return null");
3330 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
3333 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
3340 * Return a VfModuleToHeatFiles object
3342 * @param vfModuleModelUuid, heatFilesArtifactUuid
3343 * @return VfModuleToHeatFiles or null if none found
3345 public VfModuleToHeatFiles getVfModuleToHeatFilesEntry(String vfModuleModelUuid, String heatFilesArtifactUuid) {
3347 LOGGER.debug ("Catalog database - getVfModuleToHeatFilesEntry with vfModuleModelUuid " + vfModuleModelUuid + ", heatFilesArtifactUuid=" + heatFilesArtifactUuid);
3348 String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue and heatFilesArtifactUuid = :heatFilesArtifactUuidValue";
3350 HashMap<String, String> parameters = new HashMap<>();
3351 parameters.put("vfModuleModelUuidValue", vfModuleModelUuid);
3352 parameters.put("heatFilesArtifactUuidValue", heatFilesArtifactUuid);
3354 VfModuleToHeatFiles vmthf = null;
3357 vmthf = this.executeQuerySingleRow(hql, parameters, true);
3358 } catch (Exception e) {
3366 * Return a ServiceToResourceCustomization object
3368 * @param vfModuleModelUuid, heatFilesArtifactUuid
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 parentHeatTemplateId
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 name 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).
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 (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4211 long startTime = System.currentTimeMillis ();
4212 LOGGER.debug ("Catalog database - save nested Heat template with name "
4213 + childTemplate.getTemplateName ());
4216 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4217 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
4218 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4219 nestedTemplate.setParentTemplateId (parentTemplateId);
4220 nestedTemplate.setChildTemplateId (childTemplate.getId ());
4221 nestedTemplate.setProviderResourceFile (yamlFile);
4222 session.save (nestedTemplate);
4225 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4231 public void saveNestedHeatTemplate (String parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
4232 long startTime = System.currentTimeMillis ();
4233 LOGGER.debug ("Catalog database - save nested Heat template with name "
4234 + childTemplate.getTemplateName () + ",parentId=" + parentTemplateId + ",childId=" + childTemplate.getArtifactUuid() + ", providerResourceFile=" + yamlFile);
4237 saveHeatTemplate(childTemplate, childTemplate.getParameters());
4238 if (getNestedHeatTemplate(parentTemplateId,childTemplate.getArtifactUuid()) == null) {
4239 HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
4240 nestedTemplate.setParentTemplateId (parentTemplateId);
4241 nestedTemplate.setChildTemplateId (childTemplate.getArtifactUuid ());
4242 nestedTemplate.setProviderResourceFile (yamlFile);
4244 session.save (nestedTemplate);
4247 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
4252 public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
4253 long startTime = System.currentTimeMillis ();
4254 LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
4255 + " and vnfResourceID "
4257 // + " and ASDC resource name "
4262 String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
4263 Query query = getSession ().createQuery (hql);
4264 query.setParameter ("fileName", fileName);
4265 query.setParameter ("vnfResourceId", vnfResourceId);
4266 query.setParameter ("asdcResourceName", asdcResourceName);
4267 query.setParameter ("version", version);
4269 @SuppressWarnings("unchecked")
4271 HeatFiles heatFilesResult = null;
4273 heatFilesResult = (HeatFiles) query.uniqueResult ();
4274 } catch (org.hibernate.NonUniqueResultException nure) {
4275 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);
4276 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);
4278 } catch (org.hibernate.HibernateException he) {
4279 LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + he.getMessage());
4280 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);
4282 } catch (Exception e) {
4283 LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + e.getMessage());
4284 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);
4288 // See if something came back.
4289 if (heatFilesResult == null) {
4290 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4293 // Name + Version is unique, so should only be one element
4294 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4295 return heatFilesResult;
4298 public HeatFiles getHeatFiles(String artifactUuid) {
4299 long startTime = System.currentTimeMillis ();
4300 LOGGER.debug ("Catalog database - getHeatFiles with artifactUuid " + artifactUuid);
4302 String hql = "FROM HeatFiles WHERE artifactUuid = :artifactUuid";
4303 Query query = getSession ().createQuery (hql);
4304 query.setParameter ("artifactUuid", artifactUuid);
4306 @SuppressWarnings("unchecked")
4308 HeatFiles heatFilesResult = null;
4310 heatFilesResult = (HeatFiles) query.uniqueResult ();
4311 } catch (org.hibernate.NonUniqueResultException nure) {
4312 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: artifactUuid='" + artifactUuid );
4313 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid=" + artifactUuid);
4315 } catch (org.hibernate.HibernateException he) {
4316 LOGGER.debug("Hibernate Exception - while searching for: artifactUuid='" + artifactUuid + " " + he.getMessage());
4317 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + artifactUuid);
4319 } catch (Exception e) {
4320 LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + " " + e.getMessage());
4321 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUuid=" + artifactUuid , "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + artifactUuid);
4325 // See if something came back.
4326 if (heatFilesResult == null) {
4327 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
4330 // Name + Version is unique, so should only be one element
4331 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
4332 return heatFilesResult;
4335 public void saveHeatFiles (HeatFiles childFile) {
4336 long startTime = System.currentTimeMillis ();
4337 LOGGER.debug ("Catalog database - save Heat File with name "
4338 + childFile.getFileName());
4340 // HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
4341 HeatFiles heatFiles = getHeatFiles (childFile.getArtifactUuid());
4342 if (heatFiles == null) {
4344 // asdc_heat_files_save
4345 this.getSession ().save (childFile);
4348 /* replaced 'heatFiles' by 'childFile'
4349 Based on following comment:
4350 It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
4352 childFile.setArtifactUuid(heatFiles.getArtifactUuid());
4356 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
4361 public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
4363 long startTime = System.currentTimeMillis ();
4364 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4365 + childFile.getFileName());
4367 saveHeatFiles (childFile);
4368 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4369 vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
4370 vfModuleToHeatFile.setHeatFilesId(childFile.getId());
4372 session.save (vfModuleToHeatFile);
4375 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4380 public void saveVfModuleToHeatFiles (String parentVfModuleId, HeatFiles childFile) {
4381 long startTime = System.currentTimeMillis ();
4382 LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
4383 + childFile.getFileName());
4385 saveHeatFiles (childFile);
4386 VfModuleToHeatFiles checkExistingEntry = this.getVfModuleToHeatFilesEntry(parentVfModuleId, childFile.getArtifactUuid());
4387 if (checkExistingEntry == null) {
4388 VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
4389 vfModuleToHeatFile.setVfModuleModelUuid(parentVfModuleId);
4390 vfModuleToHeatFile.setHeatFilesArtifactUuid(childFile.getArtifactUuid());
4392 session.save (vfModuleToHeatFile);
4394 LOGGER.debug("**Found existing VfModuleToHeatFiles entry for " + checkExistingEntry.toString());
4395 LOGGER.debug("No need to save...");
4399 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
4404 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4406 * @param networkType
4408 * @param serviceType
4409 * @return NetworkRecipe object or null if none found
4411 public NetworkResource getNetworkResourceByModelUuid(String modelUUID) {
4413 long startTime = System.currentTimeMillis ();
4414 LOGGER.debug ("Catalog database - get network resource with modelUUID " + modelUUID);
4417 String hql = "FROM NetworkResource WHERE modelUUID=:modelUUID";
4418 Query query = getSession ().createQuery (hql);
4419 query.setParameter (MODEL_UUID, modelUUID);
4421 @SuppressWarnings("unchecked")
4422 List <NetworkResource> resultList = query.list ();
4424 if (resultList.isEmpty ()) {
4428 resultList.sort(new MavenLikeVersioningComparator());
4429 Collections.reverse (resultList);
4431 return resultList.get (0);
4432 } catch (Exception e) {
4433 LOGGER.debug("Error trying to find Network Resource with " + modelUUID +", " + e.getMessage(),e);
4435 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelUuid", null);
4442 * Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
4444 * @param networkType
4446 * @param serviceType
4447 * @return NetworkRecipe object or null if none found
4449 public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
4451 long startTime = System.currentTimeMillis ();
4452 LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
4455 + " and service type "
4460 if (serviceType == null) {
4461 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
4463 hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
4465 Query query = getSession ().createQuery (hql);
4466 query.setParameter (NETWORK_TYPE, networkType);
4467 query.setParameter (ACTION, action);
4468 if (serviceType != null) {
4469 query.setParameter ("serviceType", serviceType);
4472 @SuppressWarnings("unchecked")
4473 List <NetworkRecipe> resultList = query.list ();
4475 if (resultList.isEmpty ()) {
4479 resultList.sort(new MavenLikeVersioningComparator());
4480 Collections.reverse (resultList);
4482 return resultList.get (0);
4484 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4489 * Return a Network recipe that matches a given MODEL_UUID and ACTION
4493 * @return NetworkRecipe object or null if none found
4495 public NetworkRecipe getNetworkRecipeByModuleUuid (String networkModelUuid, String action) {
4496 LOGGER.debug ("Catalog database - get network recipe with network model uuid " + networkModelUuid
4500 NetworkResource networkResource = getNetworkResourceByModelUuid(networkModelUuid);
4501 if(null == networkResource){
4505 NetworkRecipe recipe = getNetworkRecipeByNameVersion(networkResource.getModelName(), networkResource.getModelVersion(), action);
4510 * Return a Network recipe that matches a given MODEL_NAME and ACTION
4514 * @return NetworkRecipe object or null if none found
4516 public NetworkRecipe getNetworkRecipe (String modelName, String action) {
4518 long startTime = System.currentTimeMillis ();
4519 LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
4525 String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND action = :action";
4527 Query query = getSession ().createQuery (hql);
4528 query.setParameter (MODEL_NAME, modelName);
4529 query.setParameter (ACTION, action);
4531 @SuppressWarnings("unchecked")
4532 List <NetworkRecipe> resultList = query.list ();
4534 if (resultList.isEmpty ()) {
4538 resultList.sort(new MavenLikeVersioningComparator());
4539 Collections.reverse (resultList);
4541 return resultList.get (0);
4543 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4548 * get network recipe by module name and version and action.
4552 * @param modelVersion
4555 * @since ONAP Beijing Release
4557 public NetworkRecipe getNetworkRecipeByNameVersion(String modelName, String modelVersion, String action) {
4559 long startTime = System.currentTimeMillis ();
4560 LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
4561 +"model version " + modelVersion + " and action " + action);
4564 String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND version=:version AND action = :action";
4566 Query query = getSession ().createQuery (hql);
4567 query.setParameter (MODEL_NAME, modelName);
4568 query.setParameter (MODEL_VERSION, modelVersion);
4569 query.setParameter (ACTION, action);
4571 @SuppressWarnings("unchecked")
4572 List <NetworkRecipe> resultList = query.list ();
4574 if (resultList.isEmpty ()) {
4578 Collections.sort (resultList, new MavenLikeVersioningComparator ());
4579 Collections.reverse (resultList);
4581 return resultList.get (0);
4583 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
4588 * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
4590 * @param networkType
4592 * @param serviceType
4593 * @return NetworkRecipe object or null if none found
4595 public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
4597 long startTime = System.currentTimeMillis ();
4598 LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
4601 String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.modelUUID=c.networkResourceModelUuid and c.modelCustomizationUuid = :modelCustomizationUuid";
4602 Query query = getSession ().createQuery (hql);
4603 query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
4605 @SuppressWarnings("unchecked")
4606 List <NetworkResource> resultList = query.list ();
4608 if (resultList.isEmpty ()) {
4612 resultList.sort(new MavenLikeVersioningComparator());
4613 Collections.reverse (resultList);
4615 return resultList.get (0);
4616 } catch (Exception e) {
4617 LOGGER.debug("Error trying to find Network Resource with " + modelCustomizationUuid +", " + e.getMessage(),e);
4619 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelCustUuid", null);
4625 * Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
4629 * @param vnfComponentType
4631 * @param serviceType
4632 * @return VnfComponentsRecipe object or null if none found
4634 public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
4635 String vnfComponentType,
4637 String serviceType) {
4639 long startTime = System.currentTimeMillis ();
4640 LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
4641 + " and component type "
4645 + " and service type "
4650 if (serviceType == null) {
4651 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
4653 hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
4655 Query query = getSession ().createQuery (hql);
4656 query.setParameter (VNF_TYPE, vnfType);
4657 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4658 query.setParameter (ACTION, action);
4659 if (serviceType != null) {
4660 query.setParameter ("serviceType", serviceType);
4663 @SuppressWarnings("unchecked")
4664 List <VnfComponentsRecipe> resultList = query.list ();
4666 if (resultList.isEmpty ()) {
4669 resultList.sort(new MavenLikeVersioningComparator());
4670 Collections.reverse (resultList);
4672 return resultList.get (0);
4674 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
4679 * Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
4682 * @param vnfComponentType
4684 * @return VnfComponentsRecipe object or null if none found
4686 public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleModelUUId (String vfModuleModelUUId,
4687 String vnfComponentType,
4690 long startTime = System.currentTimeMillis ();
4691 LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleModelUUId " + vfModuleModelUUId
4692 + " and component type "
4699 hql = "FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId AND vnfComponentType = :vnfComponentType AND action = :action ";
4701 Query query = getSession ().createQuery (hql);
4702 query.setParameter (VF_MODULE_MODEL_UUID, vfModuleModelUUId);
4703 query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
4704 query.setParameter (ACTION, action);
4706 @SuppressWarnings("unchecked")
4707 List <VnfComponentsRecipe> resultList = query.list ();
4709 if (resultList.isEmpty ()) {
4712 resultList.sort(new MavenLikeVersioningComparator());
4713 Collections.reverse (resultList);
4715 return resultList.get (0);
4717 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleModelUUId", null);
4721 public List<VnfComponentsRecipe> getVnfComponentRecipes (String vfModuleModelUUId) {
4723 StringBuilder hql = null;
4725 hql = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId");
4727 long startTime = System.currentTimeMillis ();
4728 LOGGER.debug ("Catalog database - get Service recipe with vfModuleModelUUId " + vfModuleModelUUId);
4730 Query query = getSession ().createQuery (hql.toString ());
4731 query.setParameter ("vfModuleModelUUId", vfModuleModelUUId);
4733 @SuppressWarnings("unchecked")
4734 List <VnfComponentsRecipe> resultList = query.list ();
4736 if (resultList.isEmpty ()) {
4737 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getVfModuleRecipes", null);
4738 return Collections.EMPTY_LIST;
4741 resultList.sort(new MavenLikeVersioningComparator());
4742 Collections.reverse (resultList);
4744 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleRecipes", null);
4750 public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
4751 long startTime = System.currentTimeMillis ();
4753 LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
4755 VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
4759 this.getSession ().save (vnfComponent);
4762 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
4767 * Return a VfModule record that matches a given MODEL_NAME
4770 * @return VfModule object or null if none found
4772 public VfModule getVfModule (String modelName) {
4774 long startTime = System.currentTimeMillis ();
4775 LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
4780 hql = "FROM VfModule WHERE modelName = :modelName";
4782 Query query = getSession ().createQuery (hql);
4783 query.setParameter (MODEL_NAME, modelName);
4785 @SuppressWarnings("unchecked")
4786 List <VfModule> resultList = query.list ();
4788 if (resultList.isEmpty ()) {
4791 resultList.sort(new MavenLikeVersioningComparator());
4792 Collections.reverse (resultList);
4794 return resultList.get (0);
4796 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
4801 * Return a VfModule record that matches a given MODEL_NAME
4804 * @return VfModule object or null if none found
4806 public VfModule getVfModuleByModelUUID (String modelUUID) {
4808 long startTime = System.currentTimeMillis ();
4809 LOGGER.debug ("Catalog database - get vf module with modelUUID " + modelUUID);
4814 hql = "FROM VfModule WHERE modelUUID = :modelUUID";
4816 Query query = getSession ().createQuery (hql);
4817 query.setParameter (MODEL_UUID, modelUUID);
4819 @SuppressWarnings("unchecked")
4820 List <VfModule> resultList = query.list ();
4822 if (resultList.isEmpty ()) {
4825 resultList.sort(new MavenLikeVersioningComparator());
4826 Collections.reverse (resultList);
4828 return resultList.get (0);
4830 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUUID", null);
4835 * Return a Service recipe that matches a given service ModelUUID and action
4836 * (modelUUID) and ACTION
4840 * @return ServiceRecipe object or null if none found
4842 public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
4844 long startTime = System.currentTimeMillis();
4845 LOGGER.debug("Catalog database - get Service recipe with modelUUID=" + modelUUID + " and action=" + action);
4849 // based on the new SERVICE_RECIPE schema where SERVICE_MODEL_UUID == MODEL_UUID, a JOIN with the SERVICE table is no longer needed
4850 // hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4851 // "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4852 // "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4853 // "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4854 // "WHERE SR.serviceModelUUID = :modelUUID AND SR.action = :action";
4855 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :modelUUID AND action = :action";
4856 Query query = getSession().createQuery(hql);
4857 query.setParameter(MODEL_UUID, modelUUID);
4858 query.setParameter(ACTION, action);
4860 @SuppressWarnings("unchecked")
4861 List<ServiceRecipe> recipeResultList = query.list();
4862 if (recipeResultList.isEmpty()) {
4863 LOGGER.debug("Catalog database - recipeResultList is null");
4866 recipeResultList.sort(new MavenLikeVersioningComparator());
4867 Collections.reverse(recipeResultList);
4868 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4870 return recipeResultList.get(0);
4872 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipeByModelUUID", null);
4877 * Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
4878 * (MODEL_VERSION_ID) and ACTION
4880 * @param modelVersionId
4882 * @return ServiceRecipe object or null if none found
4885 public ServiceRecipe getServiceRecipe(String modelVersionId,
4888 long startTime = System.currentTimeMillis();
4889 LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
4890 + " and action=" + action);
4894 // Note: Even with the implementation of the HQL JOIN below, the code for the two separate
4895 // SELECTs will be retained/commented for now in the event some subsequent JOIN issue arises
4896 // 1st query to get the Service record for the given SERVICE_NAME_VERSION_ID (MODEL_VERSION_ID)
4897 /* hql = "FROM Service WHERE serviceNameVersionId = :serviceNameVersionId";
4898 Query query = getSession().createQuery(hql);
4899 query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
4901 @SuppressWarnings("unchecked")
4902 List<Service> serviceResultList = query.list();
4903 if (serviceResultList.isEmpty()) {
4904 LOGGER.debug("Catalog database - serviceResultList is null");
4907 Collections.sort(serviceResultList, new MavenLikeVersioningComparator());
4908 Collections.reverse(serviceResultList);
4909 LOGGER.debug("Catalog database - serviceResultList contains " + serviceResultList.get(0).toString());
4911 // 2nd query to get the ServiceRecipe record corresponding to the Service from the 1st query
4912 hql = "FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action";
4913 query = getSession().createQuery(hql);
4914 // The SERVICE table 'id' field maps to the SERVICE_RECIPE table 'SERVICE_ID' field
4915 query.setParameter(SERVICE_ID, serviceResultList.get(0).getId());
4916 query.setParameter(ACTION, action);
4918 // The following SELECT performs a JOIN across the SERVICE and SERVICE_RECIPE tables. It required a new
4919 // CTR in the ServiceRecipe Class to populate that object (the other option was to parse the Object[]
4920 // returned by createQuery() and manually populate the ServiceRecipe object). Two of the 'int' fields in the
4921 // SERVICE_RECIPE DB schema (the timeouts) permit NULL values which required some additional code in the
4922 // SELECT to generate a default of 0 (needed by the CTR) in the cases where the value is NULL.
4923 hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
4924 "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
4925 "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
4926 "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
4927 "WHERE SR.serviceModelUUID = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
4928 Query query = getSession().createQuery(hql);
4929 query.setParameter(MODEL_UUID, modelVersionId);
4930 query.setParameter(ACTION, action);
4932 @SuppressWarnings("unchecked")
4933 List<ServiceRecipe> recipeResultList = query.list();
4934 if (recipeResultList.isEmpty()) {
4935 LOGGER.debug("Catalog database - recipeResultList is null");
4938 recipeResultList.sort(new MavenLikeVersioningComparator());
4939 Collections.reverse(recipeResultList);
4940 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
4942 return recipeResultList.get(0);
4944 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
4949 * Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
4950 * Note: This method is not currently used but was retained in the event the
4951 * architecture moves back to a MODEL/MODEL_RECIPE structure.
4954 * @param modelVersionId
4956 * @return ModelRecipe object or null if none found
4958 public ModelRecipe getModelRecipe(String modelType,
4959 String modelVersionId,
4962 long startTime = System.currentTimeMillis();
4963 LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
4964 + " and modeVersionId=" + modelVersionId
4965 + " and action=" + action);
4969 // TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
4970 // the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
4971 // There seems to be 2 issues: formatting a hql query that executes successfully
4972 // and then being able to generate a result that will fit into the ModelRecipe class.
4974 // 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
4975 hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
4976 Query query = getSession().createQuery(hql);
4977 query.setParameter(MODEL_TYPE, modelType);
4978 query.setParameter(MODEL_VERSION_ID, modelVersionId);
4980 @SuppressWarnings("unchecked")
4981 List<Model> modelResultList = query.list();
4982 if (modelResultList.isEmpty()) {
4983 LOGGER.debug("Catalog database - modelResultList is null");
4986 modelResultList.sort(new MavenLikeVersioningComparator());
4987 Collections.reverse(modelResultList);
4988 LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
4990 // 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
4991 hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
4992 query = getSession().createQuery(hql);
4993 // The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
4994 query.setParameter(MODEL_ID, modelResultList.get(0).getId());
4995 query.setParameter(ACTION, action);
4997 @SuppressWarnings("unchecked")
4998 List<ModelRecipe> recipeResultList = query.list();
4999 if (recipeResultList.isEmpty()) {
5000 LOGGER.debug("Catalog database - recipeResultList is null");
5003 recipeResultList.sort(new MavenLikeVersioningComparator());
5004 Collections.reverse(recipeResultList);
5005 LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
5007 return recipeResultList.get(0);
5009 LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
5015 * Verify the health of the DB.
5017 * @return boolean value indicate whether DB is healthy
5019 public boolean healthCheck () {
5020 long startTime = System.currentTimeMillis ();
5021 Session session = this.getSession ();
5023 // Query query = session.createQuery (" from ActiveRequests ");
5024 Query query = session.createSQLQuery (" show tables ");
5026 List<?> list = query.list();
5027 LOGGER.debug("healthCheck CatalogDB - Successful");
5031 public < E > E executeQuerySingleRow(String hql, HashMap<String, String> variables, boolean retry) {
5032 long startTime = System.currentTimeMillis();
5033 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
5034 Query query = getSession().createQuery(hql);
5036 StringBuilder sb = new StringBuilder();
5037 if (variables != null) {
5038 for(Map.Entry<String, String> entry : variables.entrySet()){
5039 sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
5040 query.setParameter(entry.getKey(), entry.getValue());
5043 LOGGER.debug("Variables:\n" + sb.toString());
5047 theObject = (E) query.uniqueResult();
5048 } catch (org.hibernate.NonUniqueResultException nure) {
5049 LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row");
5050 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for " + hql, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for " + hql );
5052 } catch (org.hibernate.HibernateException he) {
5053 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
5054 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
5056 LOGGER.debug("***WILL RETRY***");
5057 return this.executeQuerySingleRow(hql, variables, false);
5061 } catch (Exception e) {
5062 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
5063 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
5065 LOGGER.debug("***WILL RETRY***");
5066 return this.executeQuerySingleRow(hql, variables, false);
5072 if (theObject == null) {
5073 LOGGER.debug("Returning null");
5074 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
5076 LOGGER.debug("Returning an Object");
5077 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
5082 public < E > List<E> executeQueryMultipleRows(String hql, HashMap<String, String> variables, boolean retry) {
5083 long startTime = System.currentTimeMillis ();
5084 LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
5085 Query query = getSession().createQuery(hql);
5087 StringBuilder sb = new StringBuilder();
5088 if (variables != null) {
5089 for(Map.Entry<String, String> entry : variables.entrySet()){
5090 sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
5091 query.setParameter(entry.getKey(), entry.getValue());
5094 LOGGER.debug("Variables:\n" + sb.toString());
5096 List<E> theObjects = null;
5098 theObjects = (List<E>) query.list ();
5099 } catch (org.hibernate.HibernateException he) {
5100 LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
5101 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
5103 LOGGER.debug("***WILL RETRY***");
5104 return this.executeQuerySingleRow(hql, variables, false);
5108 } catch (Exception e) {
5109 LOGGER.debug("Generic Exception - while performing '" + hql + "'");
5110 LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
5112 LOGGER.debug("***WILL RETRY***");
5113 return this.executeQuerySingleRow(hql, variables, false);
5119 if (theObjects == null) {
5120 LOGGER.debug("Returning null");
5121 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
5124 LOGGER.debug("Returning theObjects:" + theObjects.size());
5125 } catch (Exception e) {
5126 LOGGER.debug("Returning theObjects",e);
5128 LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);