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