fca1d3a45eb9f51a37296222e24c4fe230dbf5f8
[so.git] /
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
27 import java.util.ArrayList;
28 import java.util.List;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.PathParam;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.QueryParam;
34 import javax.ws.rs.core.GenericEntity;
35 import javax.ws.rs.core.HttpHeaders;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
38 import org.apache.http.HttpStatus;
39 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQuery;
40 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException;
41 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory;
42 import org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization;
43 import org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe;
44 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar;
45 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
46 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks;
47 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceVnfs;
48 import org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule;
49 import org.onap.so.db.catalog.beans.*;
50 import org.onap.so.db.catalog.data.repository.*;
51 import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.stereotype.Component;
56 import org.springframework.transaction.annotation.Transactional;
57
58
59 @Path("/{version: v[0-9]+}")
60 @Component
61 public class CatalogDbAdapterRest {
62     protected static Logger logger = LoggerFactory.getLogger(CatalogDbAdapterRest.class);
63     private static final boolean IS_ARRAY = true;
64     private static final String NETWORK_SERVICE = "network service";
65
66     @Autowired
67     private VnfCustomizationRepository vnfCustomizationRepo;
68
69     @Autowired
70     private ServiceRepository serviceRepo;
71
72     @Autowired
73     private NetworkResourceCustomizationRepository networkCustomizationRepo;
74
75     @Autowired
76     private NetworkResourceRepository networkResourceRepo;
77
78     @Autowired
79     private AllottedResourceCustomizationRepository allottedCustomizationRepo;
80
81     @Autowired
82     private ToscaCsarRepository toscaCsarRepo;
83
84     @Autowired
85     private VFModuleRepository vfModuleRepo;
86
87     @Autowired
88     private VnfRecipeRepository vnfRecipeRepo;
89
90     @Autowired
91     private NetworkRecipeRepository networkRecipeRepo;
92
93     @Autowired
94     private ArRecipeRepository arRecipeRepo;
95
96     @Autowired
97     private VnfResourceRepository vnfResourceRepo;
98
99     @Autowired
100     private AllottedResourceRepository arResourceRepo;
101
102     @Autowired
103     private InstanceGroupRepository instanceGroupRepository;
104
105     @Autowired
106     private ServiceInfoRepository serviceInfoRepository;
107
108     private static final String NO_MATCHING_PARAMETERS = "no matching parameters";
109
110     public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
111         return Response.status(respStatus).entity(qryResp.toJsonString(version, isArray))
112                 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
113     }
114
115     @GET
116     @Path("vnfResources/{vnfModelCustomizationUuid}")
117     @Transactional(readOnly = true)
118     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
119     public Response serviceVnfs(@PathParam("version") String version,
120             @PathParam("vnfModelCustomizationUuid") String vnfUuid) {
121         return serviceVnfsImpl(version, !IS_ARRAY, vnfUuid, null, null, null, null);
122     }
123
124     @GET
125     @Path("serviceVnfs")
126     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
127     @Transactional(readOnly = true)
128     public Response serviceVnfs(@PathParam("version") String version,
129             @QueryParam("vnfModelCustomizationUuid") String vnfUuid, @QueryParam("serviceModelUuid") String smUuid,
130             @QueryParam("serviceModelInvariantUuid") String smiUuid, @QueryParam("serviceModelVersion") String smVer,
131             @QueryParam("serviceModelName") String smName) {
132         return serviceVnfsImpl(version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
133     }
134
135     public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID,
136             String smiUuid, String smVer, String smName) {
137         QueryServiceVnfs qryResp = null;
138         int respStatus = HttpStatus.SC_OK;
139         List<VnfResourceCustomization> ret = new ArrayList<>();
140         Service service = null;
141         try {
142             if (vnfUuid != null && !"".equals(vnfUuid))
143                 ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid);
144             else if (serviceModelUUID != null && !"".equals(serviceModelUUID))
145                 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID);
146             else if (smiUuid != null && !"".equals(smiUuid))
147                 if (smVer != null && !"".equals(smVer))
148                     service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, smiUuid);
149                 else
150                     service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid);
151             else if (smName != null && !"".equals(smName)) {
152                 if (smVer != null && !"".equals(smVer))
153                     service = serviceRepo.findByModelNameAndModelVersion(smName, smVer);
154                 else
155                     service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName);
156             } else {
157                 throw (new Exception(NO_MATCHING_PARAMETERS));
158             }
159
160             if (service == null && ret.isEmpty()) {
161                 respStatus = HttpStatus.SC_NOT_FOUND;
162                 qryResp = new QueryServiceVnfs();
163             } else if (service == null && !ret.isEmpty()) {
164                 qryResp = new QueryServiceVnfs(ret);
165             } else if (service != null) {
166                 qryResp = new QueryServiceVnfs(service.getVnfCustomizations());
167             }
168             logger.debug("serviceVnfs qryResp= {}", qryResp);
169             return respond(version, respStatus, isArray, qryResp);
170         } catch (Exception e) {
171             logger.error("Exception - queryServiceVnfs", e);
172             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
173                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
174             return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
175                     .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
176         }
177     }
178
179     @GET
180     @Path("networkResources/{networkModelCustomizationUuid}")
181     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
182     @Transactional(readOnly = true)
183     public Response serviceNetworks(@PathParam("version") String version,
184             @PathParam("networkModelCustomizationUuid") String nUuid) {
185         return serviceNetworksImpl(version, !IS_ARRAY, nUuid, null, null, null, null);
186     }
187
188     @GET
189     @Path("serviceNetworks")
190     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
191     @Transactional(readOnly = true)
192     public Response serviceNetworks(@PathParam("version") String version,
193             @QueryParam("networkModelCustomizationUuid") String networkModelCustomizationUuid,
194             @QueryParam("networkType") String networkType, @QueryParam("networkModelName") String networkModelName,
195             @QueryParam("serviceModelUuid") String serviceModelUuid,
196             @QueryParam("serviceModelInvariantUuid") String serviceModelInvariantUuid,
197             @QueryParam("serviceModelVersion") String serviceModelVersion,
198             @QueryParam("networkModelVersion") String networkModelVersion) {
199         if (networkModelName != null && !"".equals(networkModelName)) {
200             networkType = networkModelName;
201         }
202         return serviceNetworksImpl(version, IS_ARRAY, networkModelCustomizationUuid, networkType, serviceModelUuid,
203                 serviceModelInvariantUuid, serviceModelVersion);
204     }
205
206     public Response serviceNetworksImpl(String version, boolean isArray, String networkModelCustomizationUuid,
207             String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
208         QueryServiceNetworks qryResp;
209         int respStatus = HttpStatus.SC_OK;
210         String uuid = "";
211         List<NetworkResourceCustomization> ret = new ArrayList<>();
212         Service service = null;
213
214         try {
215             if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
216                 uuid = networkModelCustomizationUuid;
217                 ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
218             } else if (networkType != null && !"".equals(networkType)) {
219                 uuid = networkType;
220                 NetworkResource networkResources =
221                         networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
222                 if (networkResources != null)
223                     ret = networkResources.getNetworkResourceCustomization();
224             } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
225                 uuid = serviceModelInvariantUuid;
226                 if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {
227                     service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
228                 } else {
229                     service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
230                 }
231             } else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
232                 uuid = serviceModelUuid;
233                 service = serviceRepo.findOneByModelUUID(serviceModelUuid);
234             } else {
235                 throw (new Exception(NO_MATCHING_PARAMETERS));
236             }
237
238             if (service != null)
239                 ret = service.getNetworkCustomizations();
240
241             if (ret == null || ret.isEmpty()) {
242                 logger.debug("serviceNetworks not found");
243                 respStatus = HttpStatus.SC_NOT_FOUND;
244                 qryResp = new QueryServiceNetworks();
245             } else {
246                 qryResp = new QueryServiceNetworks(ret);
247                 logger.debug("serviceNetworks found qryResp= {}", qryResp);
248             }
249             return respond(version, respStatus, isArray, qryResp);
250         } catch (Exception e) {
251             logger.error("Exception - queryServiceNetworks", e);
252             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
253                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
254             return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
255                     .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
256         }
257     }
258
259     @GET
260     @Path("serviceResources")
261     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
262     @Transactional(readOnly = true)
263     public Response serviceResources(@PathParam("version") String version,
264             @QueryParam("serviceModelUuid") String modelUUID,
265             @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID,
266             @QueryParam("serviceModelVersion") String modelVersion) {
267
268         QueryServiceMacroHolder qryResp;
269         int respStatus = HttpStatus.SC_OK;
270         String uuid = "";
271         ServiceMacroHolder ret = new ServiceMacroHolder();
272
273         try {
274             if (modelUUID != null && !"".equals(modelUUID)) {
275                 uuid = modelUUID;
276                 logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}", uuid);
277                 Service serv = serviceRepo.findOneByModelUUID(uuid);
278
279                 if (serv != null) {
280                     ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations()));
281                     ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations()));
282                     ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations()));
283                 }
284                 ret.setService(serv);
285             } else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
286                 uuid = modelInvariantUUID;
287                 if (modelVersion != null && !"".equals(modelVersion)) {
288                     logger.debug(
289                             "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {}  serviceModelVersion: {}",
290                             uuid, modelVersion);
291                     Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid);
292
293                     ret.setService(serv);
294                 } else {
295                     logger.debug(
296                             "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}",
297                             uuid);
298                     Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
299                     ret.setService(serv);
300                 }
301             } else {
302                 throw (new Exception(NO_MATCHING_PARAMETERS));
303             }
304
305             if (ret.getService() == null) {
306                 logger.debug("serviceMacroHolder not found");
307                 respStatus = HttpStatus.SC_NOT_FOUND;
308                 qryResp = new QueryServiceMacroHolder();
309             } else {
310                 ServiceInfo serviceInfo = serviceInfoRepository.findByService(ret.getService());
311                 ret.setServiceInfo(serviceInfo);
312                 qryResp = new QueryServiceMacroHolder(ret);
313                 logger.debug("serviceMacroHolder qryResp= {}", qryResp);
314             }
315             return respond(version, respStatus, IS_ARRAY, qryResp);
316         } catch (Exception e) {
317             logger.error("Exception - queryServiceMacroHolder", e);
318             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
319                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
320             return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
321                     .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
322         }
323     }
324
325
326     @GET
327     @Path("allottedResources/{arModelCustomizationUuid}")
328     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
329     @Transactional(readOnly = true)
330     public Response serviceAllottedResources(@PathParam("version") String version,
331             @PathParam("arModelCustomizationUuid") String aUuid) {
332         return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
333     }
334
335     @GET
336     @Path("serviceAllottedResources")
337     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
338     @Transactional(readOnly = true)
339     public Response serviceAllottedResources(@PathParam("version") String version,
340             @QueryParam("serviceModelUuid") String smUuid, @QueryParam("serviceModelInvariantUuid") String smiUuid,
341             @QueryParam("serviceModelVersion") String smVer, @QueryParam("arModelCustomizationUuid") String aUuid) {
342         return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
343     }
344
345     public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid,
346             String serviceModelInvariantUuid, String smVer) {
347         QueryAllottedResourceCustomization qryResp;
348         int respStatus = HttpStatus.SC_OK;
349         String uuid = "";
350         List<AllottedResourceCustomization> ret = new ArrayList<>();
351         Service service = null;
352         try {
353             if (smUuid != null && !"".equals(smUuid)) {
354                 uuid = smUuid;
355                 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);
356             } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
357                 uuid = serviceModelInvariantUuid;
358                 if (smVer != null && !"".equals(smVer)) {
359                     service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid);
360                 } else {
361                     service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
362                 }
363             } else if (aUuid != null && !"".equals(aUuid)) {
364                 uuid = aUuid;
365                 ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
366             } else {
367                 throw (new Exception(NO_MATCHING_PARAMETERS));
368             }
369
370             if (service != null)
371                 ret = service.getAllottedCustomizations();
372
373             if (ret == null || ret.isEmpty()) {
374                 logger.debug("AllottedResourceCustomization not found");
375                 respStatus = HttpStatus.SC_NOT_FOUND;
376                 qryResp = new QueryAllottedResourceCustomization();
377             } else {
378                 qryResp = new QueryAllottedResourceCustomization(ret);
379                 logger.debug("AllottedResourceCustomization qryResp= {}", qryResp);
380             }
381             return respond(version, respStatus, isArray, qryResp);
382         } catch (Exception e) {
383             logger.error("Exception - queryAllottedResourceCustomization", e);
384             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
385                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
386             return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
387                     .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
388         }
389     }
390
391     @GET
392     @Path("vfModules")
393     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
394     @Transactional(readOnly = true)
395     public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
396         QueryVfModule qryResp;
397         int respStatus = HttpStatus.SC_OK;
398         List<VfModuleCustomization> ret = null;
399         try {
400             if (vfModuleModelName != null && !"".equals(vfModuleModelName)) {
401                 VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
402                 if (vfModule != null)
403                     ret = vfModule.getVfModuleCustomization();
404             } else {
405                 throw (new Exception(NO_MATCHING_PARAMETERS));
406             }
407
408             if (ret == null || ret.isEmpty()) {
409                 logger.debug("vfModules not found");
410                 respStatus = HttpStatus.SC_NOT_FOUND;
411                 qryResp = new QueryVfModule();
412             } else {
413                 qryResp = new QueryVfModule(ret);
414                 if (logger.isDebugEnabled())
415                     logger.debug("vfModules tojsonstring is: {}", qryResp.JSON2(false, false));
416             }
417             return Response.status(respStatus).entity(qryResp.JSON2(false, false))
418                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
419         } catch (Exception e) {
420             logger.error("Exception during query VfModules by vfModuleModuleName: ", e);
421             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
422                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
423             return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
424                     .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
425         }
426     }
427
428     /**
429      * Get the tosca csar info from catalog <br>
430      * 
431      * @param smUuid service model uuid
432      * @return the tosca csar information of the serivce.
433      * @since ONAP Beijing Release
434      */
435     @GET
436     @Path("serviceToscaCsar")
437     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
438     public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
439         int respStatus = HttpStatus.SC_OK;
440         String entity = "";
441         try {
442             if (smUuid != null && !"".equals(smUuid)) {
443                 logger.debug("Query Csar by service model uuid: {}", smUuid);
444
445                 Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid);
446
447                 if (service != null) {
448                     ToscaCsar toscaCsar = service.getCsar();
449                     if (toscaCsar != null) {
450                         QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
451                         entity = serviceCsar.JSON2(false, false);
452                     } else {
453                         respStatus = HttpStatus.SC_NOT_FOUND;
454                     }
455                 } else {
456                     respStatus = HttpStatus.SC_NOT_FOUND;
457                 }
458
459             } else {
460                 throw (new Exception("Incoming parameter is null or blank"));
461             }
462             return Response.status(respStatus).entity(entity)
463                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
464         } catch (Exception e) {
465             logger.error("Exception during query csar by service model uuid: ", e);
466             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
467                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
468             return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
469                     .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
470         }
471     }
472
473     /**
474      * Get the resource recipe info from catalog <br>
475      * 
476      * @param rmUuid resource model uuid
477      * @return the recipe information of the resource.
478      * @since ONAP Beijing Release
479      */
480     @GET
481     @Path("resourceRecipe")
482     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
483     public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid,
484             @QueryParam("action") String action) {
485         int respStatus = HttpStatus.SC_OK;
486         String entity = "";
487         try {
488             if (rmUuid != null && !"".equals(rmUuid)) {
489                 logger.debug("Query recipe by resource model uuid: {}", rmUuid);
490                 // check vnf and network and ar, the resource could be any resource.
491                 Recipe recipe = null;
492
493                 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
494                 if (vnf != null) {
495                     recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action,
496                             vnf.getModelVersion());
497
498                     // for network service fetch the default recipe
499                     if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
500                         recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
501                     }
502                 }
503
504
505                 if (null == recipe) {
506                     NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
507
508                     if (nResource != null) {
509                         recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(),
510                                 action, nResource.getModelVersion());
511
512                         // for network fetch the default recipe
513                         if (recipe == null) {
514                             recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
515                         }
516                     }
517                 }
518
519                 if (null == recipe) {
520                     AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
521                     if (arResource != null) {
522                         recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action,
523                                 arResource.getModelVersion());
524                     }
525                 }
526
527                 if (null == recipe) {
528                     InstanceGroup grpResource = instanceGroupRepository.findByModelUUID(rmUuid);
529                     if (grpResource != null) {
530                         recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(
531                                 grpResource.getModelName(), action, grpResource.getModelVersion());
532                     }
533
534                 }
535
536                 if (recipe != null) {
537                     QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
538                     entity = resourceRecipe.JSON2(false, false);
539                 } else {
540                     respStatus = HttpStatus.SC_NOT_FOUND;
541                 }
542             } else {
543                 throw new Exception("Incoming parameter is null or blank");
544             }
545             return Response.status(respStatus).entity(entity)
546                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
547         } catch (Exception e) {
548             logger.error("Exception during query recipe by resource model uuid: ", e);
549             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
550                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
551             return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
552                     .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
553         }
554     }
555 }