Containerization feature of SO
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / onap / so / adapters / catalogdb / rest / CatalogDbAdapterRest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.catalogdb.rest;
22
23 /*
24 Create an initial query to retrieve a VNF Resource definition (including a list of possible module types)
25 within the context of a given service. Input is a vnf resource model customization ID (new field for 1702),
26 or a composite key (from 1610) of service name, service version, vnf instance name
27
28 Returns a structure (JSON?) containing VNF RESOURCE attributes, plus a list of VF Module structures.
29
30 Query a NETWORK_RESOURCE from the MSO Catalog, based on a networkModelCustomizationUUID (new for 1702),
31 a network type (unique type identifier in 1610), or based on network role within a service.
32
33 Create Adapter framework for access to Catalog DB, including connection management,
34 login/password access, transaction logic, etc. This can be modeled after the Request DB Adapter
35
36 Update the MSO Catalog DB schema to include the new fields defined in this user story.
37
38 Note that the resourceModelCustomizationUUID (or vfModuleModelCustomizationUUID) will be unique keys (indexes)
39 on the VNF_RESOURCE and VF_MODULE tables respectively.
40 The previously constructed "vnf-type" and "vf-module-type" field may continue to be populated,
41 but should no longer be needed and can deprecate in future release.
42
43 For migration, a new randomly generated UUID field may be generated for the *ModelCustomizationUUID" fields
44 until such time that the model is redistributed from ASDC.
45
46 All other fields Check with Mike Z for appropriate value for the vfModuleLabel.
47 We might be able to derive it's value from the current vnf-type (using the "middle" piece that identifies the module type).
48
49 min and initial counts can be 0. max can be null to indicate no maximum.
50
51 Once the network-level distribution artifacts are defined, similar updates can be made to the NETWORK_RESOURCE table.
52 */
53
54 import java.util.ArrayList;
55 import java.util.List;
56
57 import javax.ws.rs.GET;
58 import javax.ws.rs.Path;
59 import javax.ws.rs.PathParam;
60 import javax.ws.rs.Produces;
61 import javax.ws.rs.QueryParam;
62 import javax.ws.rs.core.GenericEntity;
63 import javax.ws.rs.core.HttpHeaders;
64 import javax.ws.rs.core.MediaType;
65 import javax.ws.rs.core.Response;
66
67 import org.apache.http.HttpStatus;
68 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQuery;
69 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException;
70 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory;
71 import org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization;
72 import org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe;
73 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar;
74 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
75 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks;
76 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceVnfs;
77 import org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule;
78 import org.onap.so.db.catalog.beans.AllottedResource;
79 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
80 import org.onap.so.db.catalog.beans.NetworkResource;
81 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
82 import org.onap.so.db.catalog.beans.Recipe;
83 import org.onap.so.db.catalog.beans.Service;
84 import org.onap.so.db.catalog.beans.ToscaCsar;
85 import org.onap.so.db.catalog.beans.VfModule;
86 import org.onap.so.db.catalog.beans.VfModuleCustomization;
87 import org.onap.so.db.catalog.beans.VnfResource;
88 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
89 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
90 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
91 import org.onap.so.db.catalog.data.repository.ArRecipeRepository;
92 import org.onap.so.db.catalog.data.repository.NetworkRecipeRepository;
93 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
94 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
95 import org.onap.so.db.catalog.data.repository.ServiceRepository;
96 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
97 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
98 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
99 import org.onap.so.db.catalog.data.repository.VnfRecipeRepository;
100 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
101 import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder;
102 import org.onap.so.logger.MessageEnum;
103 import org.onap.so.logger.MsoLogger;
104 import org.springframework.beans.factory.annotation.Autowired;
105 import org.springframework.stereotype.Component;
106 import org.springframework.transaction.annotation.Transactional;
107
108 /**
109  * This class services calls to the REST interface for VF Modules (http://host:port/ecomp/mso/catalog/v1)
110  * Both XML and JSON can be produced/consumed.  Set Accept: and Content-Type: headers appropriately.  XML is the default.
111  * Requests respond synchronously only
112  */
113 @Path("/{version: v[0-9]+}")
114 @Component
115 public class CatalogDbAdapterRest {
116         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA,CatalogDbAdapterRest.class);
117         private static final boolean IS_ARRAY = true;
118         
119         @Autowired
120         private VnfCustomizationRepository vnfCustomizationRepo;
121         
122         @Autowired
123         private ServiceRepository serviceRepo;
124         
125         @Autowired
126         private NetworkResourceCustomizationRepository networkCustomizationRepo;
127         
128         @Autowired
129         private NetworkResourceRepository networkResourceRepo;
130         
131         @Autowired
132         private AllottedResourceCustomizationRepository allottedCustomizationRepo;
133         
134         @Autowired
135         private ToscaCsarRepository toscaCsarRepo;
136         
137         @Autowired
138         private VFModuleRepository vfModuleRepo;
139         
140         @Autowired
141         private VnfRecipeRepository vnfRecipeRepo;
142         
143         @Autowired
144         private NetworkRecipeRepository networkRecipeRepo;
145         
146         @Autowired
147         private ArRecipeRepository arRecipeRepo;
148         
149         @Autowired
150         private VnfResourceRepository vnfResourceRepo;
151         
152         @Autowired
153         private AllottedResourceRepository arResourceRepo;
154         
155         private static final String NO_MATCHING_PARAMETERS = "no matching parameters";
156
157         public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
158                 return Response
159                                 .status(respStatus)
160                                 //.entity(new GenericEntity<QueryServiceVnfs>(qryResp) {})
161                                 .entity(qryResp.toJsonString(version, isArray))
162                                 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
163                                 .build();
164         }
165
166         @GET
167         @Path("vnfResources/{vnfModelCustomizationUuid}")
168         @Transactional( readOnly = true)
169         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
170         public Response serviceVnfs (
171                         @PathParam("version") String version,
172                         @PathParam("vnfModelCustomizationUuid") String vnfUuid
173         ) {
174                 return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null);
175         }
176
177         @GET
178         @Path("serviceVnfs")
179         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
180         @Transactional( readOnly = true)
181         public Response serviceVnfs(
182                         @PathParam("version") String version,
183                         @QueryParam("vnfModelCustomizationUuid") String vnfUuid,
184                         @QueryParam("serviceModelUuid") String smUuid,
185                         @QueryParam("serviceModelInvariantUuid") String smiUuid,
186                         @QueryParam("serviceModelVersion") String smVer,
187                         @QueryParam("serviceModelName") String smName
188         ) {
189                 return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
190         }
191
192         public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID, String smiUuid, String smVer, String smName) {
193                 QueryServiceVnfs qryResp = null;
194                 int respStatus = HttpStatus.SC_OK;              
195                 List<VnfResourceCustomization> ret = new ArrayList<>();
196                 Service service = null;
197                 try {
198                         if (vnfUuid != null && !"".equals(vnfUuid)) 
199                                 ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid);                       
200                         else if (serviceModelUUID != null && !"".equals(serviceModelUUID))                              
201                                 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID);
202                         else if (smiUuid != null && !"".equals(smiUuid))                        
203                                 if (smVer != null && !"".equals(smVer)) 
204                                         service = serviceRepo.findByModelVersionAndModelInvariantUUID(smVer,smiUuid);                                   
205                                 else                                    
206                                         service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid);
207                         else if (smName != null && !"".equals(smName)) {
208                                 if (smVer != null && !"".equals(smVer))                                         
209                                         service = serviceRepo.findByModelNameAndModelVersion(smName, smVer);
210                                 else 
211                                         service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName);                      
212                         }
213                         else {
214                                 throw(new Exception(NO_MATCHING_PARAMETERS));
215                         }
216                         
217                         if (service == null && ret.isEmpty()) {
218                                 respStatus = HttpStatus.SC_NOT_FOUND;
219                                 qryResp = new QueryServiceVnfs();
220                         }else if( service == null && !ret.isEmpty()){
221                                 qryResp = new QueryServiceVnfs(ret);                            
222                         } else if (service != null) {
223                                 qryResp = new QueryServiceVnfs(service.getVnfCustomizations());                         
224                         }
225                         LOGGER.debug ("serviceVnfs qryResp="+ qryResp);
226                         return respond(version, respStatus, isArray, qryResp);
227                 } catch (Exception e) {
228                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  "", "", "queryServiceVnfs", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceVnfs", e);
229                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
230                         return Response
231                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
232                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
233                                 .build();
234                 }
235         }
236
237         @GET
238         @Path("networkResources/{networkModelCustomizationUuid}")
239         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
240         @Transactional( readOnly = true)
241         public Response serviceNetworks (
242                         @PathParam("version") String version,
243                         @PathParam("networkModelCustomizationUuid") String nUuid
244         ) {
245                 return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null);
246         }
247
248         @GET
249         @Path("serviceNetworks")
250         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
251         @Transactional( readOnly = true)
252         public Response serviceNetworks (
253                         @PathParam("version") String version,
254                         @QueryParam("networkModelCustomizationUuid") String networkModelCustomizationUuid,
255                         @QueryParam("networkType") String networkType,
256                 @QueryParam("networkModelName") String networkModelName,
257                         @QueryParam("serviceModelUuid") String serviceModelUuid,
258                         @QueryParam("serviceModelInvariantUuid") String serviceModelInvariantUuid,
259                 @QueryParam("serviceModelVersion") String serviceModelVersion,
260                 @QueryParam("networkModelVersion") String networkModelVersion
261         ) {
262                 if (networkModelName != null && !"".equals(networkModelName)) {
263                         networkType = networkModelName;
264                 }
265                 return serviceNetworksImpl (version, IS_ARRAY,  networkModelCustomizationUuid, networkType, serviceModelUuid, serviceModelInvariantUuid, serviceModelVersion);
266         }
267
268         public Response serviceNetworksImpl (String version, boolean isArray, String  networkModelCustomizationUuid, String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
269                 QueryServiceNetworks qryResp;
270                 int respStatus = HttpStatus.SC_OK;
271                 String uuid = "";
272                 List<NetworkResourceCustomization> ret = new ArrayList<>();
273                 Service service = null;
274                 
275                 try{
276                         if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
277                                 uuid = networkModelCustomizationUuid;                           
278                                 ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
279                         }else if (networkType != null && !"".equals(networkType)) {
280                                 uuid = networkType;                             
281                                 NetworkResource networkResources = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
282                                 if(networkResources != null)
283                                         ret=networkResources.getNetworkResourceCustomization();
284                         }
285                         else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
286                                 uuid = serviceModelInvariantUuid;
287                                 if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {                                   
288                                         service = serviceRepo.findByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
289                                 }
290                                 else {                                  
291                                         service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
292                                 }
293                         }else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
294                                 uuid = serviceModelUuid;                                
295                                 service = serviceRepo.findOneByModelUUID(serviceModelUuid);
296                         }
297                         else {
298                                 throw(new Exception(NO_MATCHING_PARAMETERS));
299                         }
300                         
301                         if(service != null)
302                                 ret = service.getNetworkCustomizations();
303
304                         if (ret == null || ret.isEmpty()) {
305                                 LOGGER.debug ("serviceNetworks not found");
306                                 respStatus = HttpStatus.SC_NOT_FOUND;
307                                 qryResp = new QueryServiceNetworks();
308                         } else {
309                                 LOGGER.debug ("serviceNetworks found");
310                                 qryResp = new QueryServiceNetworks(ret);
311                                 LOGGER.debug ("serviceNetworks qryResp="+ qryResp);
312                         }
313                         LOGGER.debug ("Query serviceNetworks exit");
314                         return respond(version, respStatus, isArray, qryResp);
315                 } catch (Exception e) {
316                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  uuid, "", "queryServiceNetworks", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceNetworks", e);
317                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
318                         return Response
319                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
320                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
321                                 .build();
322                 }
323         }
324
325         @GET
326         @Path("serviceResources")
327         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
328         @Transactional(readOnly = true)
329         public Response serviceResources(
330                         @PathParam("version") String version,
331                         @QueryParam("serviceModelUuid") String modelUUID,
332                         @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID,
333                         @QueryParam("serviceModelVersion") String modelVersion) {
334                 QueryServiceMacroHolder qryResp;
335                 int respStatus = HttpStatus.SC_OK;
336                 String uuid = "";
337                 ServiceMacroHolder ret = new ServiceMacroHolder();
338                 
339                 try{
340                         if (modelUUID != null && !"".equals(modelUUID)) {
341                                 uuid = modelUUID;
342                                 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: " + uuid);
343                                 Service serv =serviceRepo.findOneByModelUUID(uuid);
344                                 ret.setService(serv);                           
345                         }
346                         else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
347                                 uuid = modelInvariantUUID;
348                                 if (modelVersion != null && !"".equals(modelVersion)) {
349                                         LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ modelVersion);
350                                         Service serv = serviceRepo.findByModelVersionAndModelInvariantUUID(modelVersion, uuid);
351                                         ret.setService(serv);   
352                                 }
353                                 else {
354                                         LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
355                                         Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
356                                         ret.setService(serv);
357                                 }
358                         }
359                         else {
360                                 throw(new Exception(NO_MATCHING_PARAMETERS));
361                         }
362
363                         if (ret.getService() == null) {
364                                 LOGGER.debug ("serviceMacroHolder not found");
365                                 respStatus = HttpStatus.SC_NOT_FOUND;
366                                 qryResp = new QueryServiceMacroHolder();
367                         } else {
368                                 LOGGER.debug ("serviceMacroHolder found");
369                                 qryResp = new QueryServiceMacroHolder(ret);
370                                 LOGGER.debug ("serviceMacroHolder qryResp="+ qryResp);
371                         }
372                         LOGGER.debug ("Query serviceMacroHolder exit");
373                         return respond(version, respStatus, IS_ARRAY, qryResp);
374                 } catch (Exception e) {
375                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  uuid, "", "queryServiceMacroHolder", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceMacroHolder", e);
376                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
377                         return Response
378                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
379                                 .entity(new GenericEntity<CatalogQueryException>(excResp){} )
380                                 .build();
381                 }
382         }
383         
384
385         @GET
386         @Path("allottedResources/{arModelCustomizationUuid}")
387         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
388         @Transactional( readOnly = true)
389         public Response serviceAllottedResources (
390                         @PathParam("version") String version,
391                         @PathParam("arModelCustomizationUuid") String aUuid
392         ) {
393                 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
394         }
395
396         @GET
397         @Path("serviceAllottedResources")
398         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
399         @Transactional( readOnly = true)
400         public Response serviceAllottedResources(
401                         @PathParam("version") String version,
402                         @QueryParam("serviceModelUuid") String smUuid,
403                         @QueryParam("serviceModelInvariantUuid") String smiUuid,
404                         @QueryParam("serviceModelVersion") String smVer,
405                         @QueryParam("arModelCustomizationUuid") String aUuid
406         ) {
407                 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
408         }
409
410         public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String serviceModelInvariantUuid, String smVer) {
411                 QueryAllottedResourceCustomization qryResp;
412                 int respStatus = HttpStatus.SC_OK;
413                 String uuid = "";
414                 List<AllottedResourceCustomization> ret = new ArrayList<>();
415                 Service service = null;
416                 try{
417                         if (smUuid != null && !"".equals(smUuid)) {
418                                 uuid = smUuid;                          
419                                 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);                     
420                         }
421                         else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
422                                 uuid = serviceModelInvariantUuid;
423                                 if (smVer != null && !"".equals(smVer)) {                                       
424                                         service = serviceRepo.findByModelVersionAndModelInvariantUUID(smVer, uuid);
425                                 }
426                                 else {                          
427                                         service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
428                                 }
429                         }
430                         else if (aUuid != null && !"".equals(aUuid)) {
431                                 uuid = aUuid;                           
432                                 ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
433                         }
434                         else {
435                                 throw(new Exception(NO_MATCHING_PARAMETERS));
436                         }
437                         
438                         if(service != null)
439                                 ret=service.getAllottedCustomizations();
440
441                         if (ret == null || ret.isEmpty()) {
442                                 LOGGER.debug ("AllottedResourceCustomization not found");
443                                 respStatus = HttpStatus.SC_NOT_FOUND;
444                                 qryResp = new QueryAllottedResourceCustomization();
445                         } else {                                
446                                 qryResp = new QueryAllottedResourceCustomization(ret);
447                                 LOGGER.debug ("AllottedResourceCustomization qryResp="+ qryResp);
448                         }                       
449                         return respond(version, respStatus, isArray, qryResp);
450                 } catch (Exception e) {
451                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  uuid, "", "queryAllottedResourceCustomization", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryAllottedResourceCustomization", e);
452                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
453                         return Response
454                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
455                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
456                                 .build();
457                 }
458         }
459         
460         @GET
461         @Path("vfModules")
462         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
463         @Transactional( readOnly = true)
464         public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
465                 QueryVfModule qryResp;
466                 int respStatus = HttpStatus.SC_OK;
467                 List<VfModuleCustomization> ret = null; 
468                 try{
469                         if(vfModuleModelName != null && !"".equals(vfModuleModelName)){
470                                 VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
471                                 if(vfModule != null)
472                                         ret = vfModule.getVfModuleCustomization();                              
473                         }else{
474                                 throw(new Exception(NO_MATCHING_PARAMETERS));
475                         }
476                         
477                         if(ret == null || ret.isEmpty()){
478                                 LOGGER.debug ("vfModules not found");
479                                 respStatus = HttpStatus.SC_NOT_FOUND;
480                                 qryResp = new QueryVfModule();
481                         }else{                  
482                                 qryResp = new QueryVfModule(ret);                               
483                                 LOGGER.debug ("vfModules tojsonstring is: "+ qryResp.JSON2(false, false));
484                         }                       
485                         return Response
486                                         .status(respStatus)
487                                         .entity(qryResp.JSON2(false, false)) 
488                                         .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
489                                         .build();
490                 }catch(Exception e){
491                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  vfModuleModelName, "", "queryVfModules", MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query VfModules by vfModuleModuleName: ", e);
492                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
493                         return Response
494                                         .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
495                                         .entity(new GenericEntity<CatalogQueryException>(excResp) {})
496                                         .build();
497                 }
498         }
499         /**
500          * Get the tosca csar info from catalog
501          * <br>
502          * 
503          * @param smUuid service model uuid
504          * @return the tosca csar information of the serivce.
505          * @since ONAP Beijing Release
506          */
507         @GET
508         @Path("serviceToscaCsar")
509         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
510         public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
511                 int respStatus = HttpStatus.SC_OK;
512                 String entity = "";
513                 try {
514                         if (smUuid != null && !"".equals(smUuid)) {
515                                 LOGGER.debug("Query Csar by service model uuid: " + smUuid);
516                                 ToscaCsar toscaCsar = toscaCsarRepo.findOne(smUuid);
517                                 if (toscaCsar != null) {
518                                         QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
519                                         entity = serviceCsar.JSON2(false, false);
520                                 } else {
521                                         respStatus = HttpStatus.SC_NOT_FOUND;
522                                 }
523                         } else {
524                                 throw (new Exception("Incoming parameter is null or blank"));
525                         }
526                         LOGGER.debug("Query Csar exit");
527                         return Response
528                                         .status(respStatus)
529                                         .entity(entity)
530                                         .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
531                                         .build();
532                 } catch (Exception e) {
533                         LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, smUuid, "", "ServiceToscaCsar",
534                                         MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query csar by service model uuid: ", e);
535                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
536                                         CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
537                         return Response
538                                         .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
539                                         .entity(new GenericEntity<CatalogQueryException>(excResp) {
540                                         })
541                                         .build();
542                 }
543         }
544
545         /**
546          * Get the resource recipe info from catalog
547          * <br>
548          * 
549          * @param rmUuid resource model uuid
550          * @return the recipe information of the resource.
551          * @since ONAP Beijing Release
552          */
553         @GET
554         @Path("resourceRecipe")
555         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
556         public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, @QueryParam("action") String action) {
557                 int respStatus = HttpStatus.SC_OK;
558                 String entity = "";
559                 try {
560                         if (rmUuid != null && !"".equals(rmUuid)) {
561                                 LOGGER.debug("Query recipe by resource model uuid: " + rmUuid);
562                                 //check vnf and network and ar, the resource could be any resource.
563                                 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
564                                 Recipe recipe = vnfRecipeRepo.findVnfRecipeByNfRoleAndAction(vnf.getModelName(), action);
565                                 if (null == recipe) {
566                                         NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
567                                         recipe = networkRecipeRepo.findByModelNameAndAction(nResource.getModelName(), action);
568                                 }
569                                 if (null == recipe) {
570                                         AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
571                                         recipe = arRecipeRepo.findByModelNameAndAction(arResource.getModelName(), action);
572                                 }
573                                 if (recipe != null) {
574                                         QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
575                                         entity = resourceRecipe.JSON2(false, false);
576                                 } else {
577                                         respStatus = HttpStatus.SC_NOT_FOUND;
578                                 }
579                         } else {
580                                 throw (new Exception("Incoming parameter is null or blank"));
581                         }
582                         LOGGER.debug("Query recipe exit");
583                         return Response
584                                 .status(respStatus)
585                                 .entity(entity)
586                                 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
587                                 .build();
588                 } catch (Exception e) {
589                         LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, rmUuid, "", "resourceRecipe",
590                                 MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query recipe by resource model uuid: ", e);
591                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
592                                 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
593                         return Response
594                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
595                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {
596                                 })
597                                 .build();
598                 }
599         }
600 }