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