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