eaf3e125a10f9478b8c157e996f776baf30456b1
[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
344                 if (serv != null) {
345                     ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations()));
346                     ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations()));
347                     ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations()));
348                 }
349                 ret.setService(serv);
350             }
351             else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
352                 uuid = modelInvariantUUID;
353                 if (modelVersion != null && !"".equals(modelVersion)) {
354                     logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {}  serviceModelVersion: {}",uuid, modelVersion);
355                     Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid);
356
357                     ret.setService(serv);
358                 }
359                 else {
360                     logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}" , uuid);
361                     Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
362                     ret.setService(serv);
363                 }
364             }
365             else {
366                 throw(new Exception(NO_MATCHING_PARAMETERS));
367             }
368
369             if (ret.getService() == null) {
370                 logger.debug ("serviceMacroHolder not found");
371                 respStatus = HttpStatus.SC_NOT_FOUND;
372                 qryResp = new QueryServiceMacroHolder();
373             } else {
374                 qryResp = new QueryServiceMacroHolder(ret);
375                 logger.debug ("serviceMacroHolder qryResp= {}", qryResp);
376             }
377             return respond(version, respStatus, IS_ARRAY, qryResp);
378         } catch (Exception e) {
379             logger.error ("Exception - queryServiceMacroHolder", e);
380             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
381             return Response
382                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
383                     .entity(new GenericEntity<CatalogQueryException>(excResp){} )
384                     .build();
385         }
386     }
387
388
389     @GET
390     @Path("allottedResources/{arModelCustomizationUuid}")
391     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
392     @Transactional( readOnly = true)
393     public Response serviceAllottedResources (
394             @PathParam("version") String version,
395             @PathParam("arModelCustomizationUuid") String aUuid
396             ) {
397         return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
398     }
399
400     @GET
401     @Path("serviceAllottedResources")
402     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
403     @Transactional( readOnly = true)
404     public Response serviceAllottedResources(
405             @PathParam("version") String version,
406             @QueryParam("serviceModelUuid") String smUuid,
407             @QueryParam("serviceModelInvariantUuid") String smiUuid,
408             @QueryParam("serviceModelVersion") String smVer,
409             @QueryParam("arModelCustomizationUuid") String aUuid
410             ) {
411         return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
412     }
413
414     public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String serviceModelInvariantUuid, String smVer) {
415         QueryAllottedResourceCustomization qryResp;
416         int respStatus = HttpStatus.SC_OK;
417         String uuid = "";
418         List<AllottedResourceCustomization> ret = new ArrayList<>();
419         Service service = null;
420         try{
421             if (smUuid != null && !"".equals(smUuid)) {
422                 uuid = smUuid;                          
423                 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);                     
424             }
425             else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
426                 uuid = serviceModelInvariantUuid;
427                 if (smVer != null && !"".equals(smVer)) {                                       
428                     service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid);
429                 }
430                 else {                          
431                     service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
432                 }
433             }
434             else if (aUuid != null && !"".equals(aUuid)) {
435                 uuid = aUuid;                           
436                 ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
437             }
438             else {
439                 throw(new Exception(NO_MATCHING_PARAMETERS));
440             }
441
442             if(service != null)
443                 ret=service.getAllottedCustomizations();
444
445             if (ret == null || ret.isEmpty()) {
446                 logger.debug ("AllottedResourceCustomization not found");
447                 respStatus = HttpStatus.SC_NOT_FOUND;
448                 qryResp = new QueryAllottedResourceCustomization();
449             } else {                            
450                 qryResp = new QueryAllottedResourceCustomization(ret);
451                 logger.debug ("AllottedResourceCustomization qryResp= {}", qryResp);
452             }                   
453             return respond(version, respStatus, isArray, qryResp);
454         } catch (Exception e) {
455             logger.error ("Exception - queryAllottedResourceCustomization", e);
456             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
457             return Response
458                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
459                     .entity(new GenericEntity<CatalogQueryException>(excResp) {})
460                     .build();
461         }
462     }
463
464     @GET
465     @Path("vfModules")
466     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
467     @Transactional( readOnly = true)
468     public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
469         QueryVfModule qryResp;
470         int respStatus = HttpStatus.SC_OK;
471         List<VfModuleCustomization> ret = null; 
472         try{
473             if(vfModuleModelName != null && !"".equals(vfModuleModelName)){
474                 VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
475                 if(vfModule != null)
476                     ret = vfModule.getVfModuleCustomization();                          
477             }else{
478                 throw(new Exception(NO_MATCHING_PARAMETERS));
479             }
480
481             if(ret == null || ret.isEmpty()){
482                 logger.debug ("vfModules not found");
483                 respStatus = HttpStatus.SC_NOT_FOUND;
484                 qryResp = new QueryVfModule();
485             }else{                      
486                 qryResp = new QueryVfModule(ret);                               
487                 if(logger.isDebugEnabled())
488                     logger.debug ("vfModules tojsonstring is: {}", qryResp.JSON2(false, false));
489             }                   
490             return Response
491                     .status(respStatus)
492                     .entity(qryResp.JSON2(false, false)) 
493                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
494                     .build();
495         }catch(Exception e){
496             logger.error ("Exception during query VfModules by vfModuleModuleName: ", e);
497             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
498             return Response
499                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
500                     .entity(new GenericEntity<CatalogQueryException>(excResp) {})
501                     .build();
502         }
503     }
504     /**
505      * Get the tosca csar info from catalog
506      * <br>
507      * 
508      * @param smUuid service model uuid
509      * @return the tosca csar information of the serivce.
510      * @since ONAP Beijing Release
511      */
512     @GET
513     @Path("serviceToscaCsar")
514     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
515     public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
516         int respStatus = HttpStatus.SC_OK;
517         String entity = "";
518         try {
519             if (smUuid != null && !"".equals(smUuid)) {
520                 logger.debug("Query Csar by service model uuid: {}",smUuid);
521                 ToscaCsar toscaCsar = toscaCsarRepo.findOne(smUuid);
522                 if (toscaCsar != null) {
523                     QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
524                     entity = serviceCsar.JSON2(false, false);
525                 } else {
526                     respStatus = HttpStatus.SC_NOT_FOUND;
527                 }
528             } else {
529                 throw (new Exception("Incoming parameter is null or blank"));
530             }
531             return Response
532                     .status(respStatus)
533                     .entity(entity)
534                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
535                     .build();
536         } catch (Exception e) {
537             logger.error("Exception during query csar by service model uuid: ", e);
538             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
539                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
540             return Response
541                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
542                     .entity(new GenericEntity<CatalogQueryException>(excResp) {
543                     })
544                     .build();
545         }
546     }
547
548     /**
549      * Get the resource recipe info from catalog
550      * <br>
551      * 
552      * @param rmUuid resource model uuid
553      * @return the recipe information of the resource.
554      * @since ONAP Beijing Release
555      */
556     @GET
557     @Path("resourceRecipe")
558     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
559     public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, @QueryParam("action") String action) {
560         int respStatus = HttpStatus.SC_OK;
561         String entity = "";
562         try {
563             if (rmUuid != null && !"".equals(rmUuid)) {
564                 logger.debug("Query recipe by resource model uuid: {}", rmUuid);
565                 //check vnf and network and ar, the resource could be any resource.
566                 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
567                 Recipe recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction(vnf.getModelName(), action);
568                 if (null == recipe) {
569                     NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
570                     recipe = networkRecipeRepo.findFirstByModelNameAndAction(nResource.getModelName(), action);
571                 }
572                 if (null == recipe) {
573                     AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
574                     recipe = arRecipeRepo.findByModelNameAndAction(arResource.getModelName(), action);
575                 }
576                 if (recipe != null) {
577                     QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
578                     entity = resourceRecipe.JSON2(false, false);
579                 } else {
580                     respStatus = HttpStatus.SC_NOT_FOUND;
581                 }
582             } else {
583                 throw new Exception("Incoming parameter is null or blank");
584             }
585             return Response
586                     .status(respStatus)
587                     .entity(entity)
588                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
589                     .build();
590         } catch (Exception e) {
591             logger.error("Exception during query recipe by resource model uuid: ", e);
592             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
593                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
594             return Response
595                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
596                     .entity(new GenericEntity<CatalogQueryException>(excResp) {
597                     })
598                     .build();
599         }
600     }
601 }