Merge "add update action for e2e svcinst"
[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.QueryServiceCsar;
73 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
74 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceNetworks;
75 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceVnfs;
76 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryVfModule;
77 import org.openecomp.mso.db.catalog.CatalogDatabase;
78 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
79 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
80 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
81 import org.openecomp.mso.db.catalog.beans.ToscaCsar;
82 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
83 import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
84 import org.openecomp.mso.logger.MessageEnum;
85 import org.openecomp.mso.logger.MsoLogger;
86
87 /**
88  * This class services calls to the REST interface for VF Modules (http://host:port/ecomp/mso/catalog/v1)
89  * Both XML and JSON can be produced/consumed.  Set Accept: and Content-Type: headers appropriately.  XML is the default.
90  * Requests respond synchronously only
91  */
92 @Path("/{version: v[0-9]+}")
93 public class CatalogDbAdapterRest {
94         private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
95         private static final boolean IS_ARRAY = true;
96
97         public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
98                 return Response
99                                 .status(respStatus)
100                                 //.entity(new GenericEntity<QueryServiceVnfs>(qryResp) {})
101                                 .entity(qryResp.toJsonString(version, isArray))
102                                 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
103                                 .build();
104         }
105
106         @HEAD
107         @GET
108         @Path("healthcheck")
109         @Produces(MediaType.TEXT_HTML)
110         public Response healthcheck (
111                         @PathParam("version") String version
112         ) {
113                 String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application "+ version+ " ready</body></html>";
114                 return Response.ok().entity(CHECK_HTML).build();
115         }
116
117         @GET
118         @Path("vnfResources/{vnfModelCustomizationUuid}")
119         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
120         public Response serviceVnfs (
121                         @PathParam("version") String version,
122                         @PathParam("vnfModelCustomizationUuid") String vnfUuid
123         ) {
124                 return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null);
125         }
126
127         @GET
128         @Path("serviceVnfs")
129         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
130         public Response serviceVnfs(
131                         @PathParam("version") String version,
132                         @QueryParam("vnfModelCustomizationUuid") String vnfUuid,
133                         @QueryParam("serviceModelUuid") String smUuid,
134                         @QueryParam("serviceModelInvariantUuid") String smiUuid,
135                         @QueryParam("serviceModelVersion") String smVer,
136                         @QueryParam("serviceModelName") String smName
137         ) {
138                 return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
139         }
140
141         public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String smUuid, String smiUuid, String smVer, String smName) {
142                 QueryServiceVnfs qryResp;
143                 int respStatus = HttpStatus.SC_OK;
144                 String uuid = "";
145                 List<VnfResourceCustomization> ret;
146
147                 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
148                         if (vnfUuid != null && !"".equals(vnfUuid)) {
149                                 uuid = vnfUuid;
150                                 LOGGER.debug ("Query serviceVnfs getAllVnfsByVnfModelCustomizationUuid vnfModelCustomizationUuid: " + uuid);
151                                 ret = db.getAllVnfsByVnfModelCustomizationUuid(uuid);
152                         }
153                         else if (smUuid != null && !"".equals(smUuid)) {
154                                 uuid = smUuid;
155                                 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceModelUuid serviceModelUuid: " + uuid);
156                                 ret = db.getAllVnfsByServiceModelUuid(uuid);
157                         }
158                         else if (smiUuid != null && !"".equals(smiUuid)) {
159                                 uuid = smiUuid;
160                                 if (smVer != null && !"".equals(smVer)) {
161                                         LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
162                                         ret = db.getAllVnfsByServiceModelInvariantUuid(uuid, smVer);
163                                 }
164                                 else {
165                                         LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
166                                         ret = db.getAllVnfsByServiceModelInvariantUuid(uuid);
167                                 }
168                         }
169                         else if (smName != null && !"".equals(smName)) {
170                                 if (smVer != null && !"".equals(smVer)) {
171                                         LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelInvariantName: " + smName+ " serviceModelVersion: "+ smVer);
172                                         ret = db.getAllVnfsByServiceName(smName, smVer);
173                                 }
174                                 else {
175                                         LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelName: " + smName);
176                                         ret = db.getAllVnfsByServiceName(smName);
177                                 }
178                         }
179                         else {
180                                 throw(new Exception("no matching parameters"));
181                         }
182
183                         if (ret == null || ret.isEmpty()) {
184                                 LOGGER.debug ("serviceVnfs not found");
185                                 respStatus = HttpStatus.SC_NOT_FOUND;
186                                 qryResp = new QueryServiceVnfs();
187                         } else {
188                                 LOGGER.debug ("serviceVnfs found");
189                                 qryResp = new QueryServiceVnfs(ret);
190                                 LOGGER.debug ("serviceVnfs qryResp="+ qryResp);
191                         }
192                         LOGGER.debug ("Query serviceVnfs exit");
193                         return respond(version, respStatus, isArray, qryResp);
194                 } catch (Exception e) {
195                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  uuid, "", "queryServiceVnfs", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceVnfs", e);
196                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
197                         return Response
198                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
199                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
200                                 .build();
201                 }
202         }
203
204         @GET
205         @Path("networkResources/{networkModelCustomizationUuid}")
206         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
207         public Response serviceNetworks (
208                         @PathParam("version") String version,
209                         @PathParam("networkModelCustomizationUuid") String nUuid
210         ) {
211                 return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null);
212         }
213
214         @GET
215         @Path("serviceNetworks")
216         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
217         public Response serviceNetworks (
218                         @PathParam("version") String version,
219                         @QueryParam("networkModelCustomizationUuid") String nUuid,
220                         @QueryParam("networkType") String nType,
221                 @QueryParam("networkModelName") String nModelName,
222                         @QueryParam("serviceModelUuid") String smUuid,
223                         @QueryParam("serviceModelInvariantUuid") String smiUuid,
224                 @QueryParam("serviceModelVersion") String smVer,
225                 @QueryParam("networkModelVersion") String nmVer
226         ) {
227                 if (nModelName != null && !"".equals(nModelName)) {
228                         nType = nModelName;
229                 }
230                 return serviceNetworksImpl (version, IS_ARRAY, nUuid, nType, smUuid, smiUuid, smVer);
231         }
232
233         public Response serviceNetworksImpl (String version, boolean isArray, String nUuid, String nType, String smUuid, String smiUuid, String smVer) {
234                 QueryServiceNetworks qryResp;
235                 int respStatus = HttpStatus.SC_OK;
236                 String uuid = "";
237                 List<NetworkResourceCustomization> ret;
238
239                 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
240                         if (nUuid != null && !"".equals(nUuid)) {
241                                 uuid = nUuid;
242                                 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkModelCustomizationUuid networkModelCustomizationUuid: " + uuid);
243                                 ret = db.getAllNetworksByNetworkModelCustomizationUuid(uuid);
244                         }
245                         else if (smUuid != null && !"".equals(smUuid)) {
246                                 uuid = smUuid;
247                                 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelUuid serviceModelUuid: " + uuid);
248                                 ret = db.getAllNetworksByServiceModelUuid(uuid);
249                         }
250                         else if (nType != null && !"".equals(nType)) {
251                                 uuid = nType;
252                                 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkType serviceModelUuid: " + uuid);
253                                 ret = db.getAllNetworksByNetworkType(uuid);
254                         }
255                         else if (smiUuid != null && !"".equals(smiUuid)) {
256                                 uuid = smiUuid;
257                                 if (smVer != null && !"".equals(smVer)) {
258                                         LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
259                                         ret = db.getAllNetworksByServiceModelInvariantUuid(uuid, smVer);
260                                 }
261                                 else {
262                                         LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
263                                         ret = db.getAllNetworksByServiceModelInvariantUuid(uuid);
264                                 }
265                         }
266                         else {
267                                 throw(new Exception("no matching parameters"));
268                         }
269
270                         if (ret == null || ret.isEmpty()) {
271                                 LOGGER.debug ("serviceNetworks not found");
272                                 respStatus = HttpStatus.SC_NOT_FOUND;
273                                 qryResp = new QueryServiceNetworks();
274                         } else {
275                                 LOGGER.debug ("serviceNetworks found");
276                                 qryResp = new QueryServiceNetworks(ret);
277                                 LOGGER.debug ("serviceNetworks qryResp="+ qryResp);
278                         }
279                         LOGGER.debug ("Query serviceNetworks exit");
280                         return respond(version, respStatus, isArray, qryResp);
281                 } catch (Exception e) {
282                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  uuid, "", "queryServiceNetworks", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceNetworks", e);
283                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
284                         return Response
285                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
286                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
287                                 .build();
288                 }
289         }
290
291         @GET
292         @Path("serviceResources")
293         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
294         public Response serviceResources(
295                         @PathParam("version") String version,
296                         @QueryParam("serviceModelUuid") String smUuid,
297                         @QueryParam("serviceModelInvariantUuid") String smiUuid,
298                         @QueryParam("serviceModelVersion") String smVer) {
299                 QueryServiceMacroHolder qryResp;
300                 int respStatus = HttpStatus.SC_OK;
301                 String uuid = "";
302                 ServiceMacroHolder ret;
303
304                 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
305                         if (smUuid != null && !"".equals(smUuid)) {
306                                 uuid = smUuid;
307                                 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: " + uuid);
308                                 ret = db.getAllResourcesByServiceModelUuid(uuid);
309                         }
310                         else if (smiUuid != null && !"".equals(smiUuid)) {
311                                 uuid = smiUuid;
312                                 if (smVer != null && !"".equals(smVer)) {
313                                         LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
314                                         ret = db.getAllResourcesByServiceModelInvariantUuid(uuid, smVer);
315                                 }
316                                 else {
317                                         LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
318                                         ret = db.getAllResourcesByServiceModelInvariantUuid(uuid);
319                                 }
320                         }
321                         else {
322                                 throw(new Exception("no matching parameters"));
323                         }
324
325                         if (ret == null) {
326                                 LOGGER.debug ("serviceMacroHolder not found");
327                                 respStatus = HttpStatus.SC_NOT_FOUND;
328                                 qryResp = new QueryServiceMacroHolder();
329                         } else {
330                                 LOGGER.debug ("serviceMacroHolder found");
331                                 qryResp = new QueryServiceMacroHolder(ret);
332                                 LOGGER.debug ("serviceMacroHolder qryResp="+ qryResp);
333                         }
334                         LOGGER.debug ("Query serviceMacroHolder exit");
335                         return respond(version, respStatus, IS_ARRAY, qryResp);
336                 } catch (Exception e) {
337                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  uuid, "", "queryServiceMacroHolder", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceMacroHolder", e);
338                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
339                         return Response
340                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
341                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
342                                 .build();
343                 }
344         }
345
346         @GET
347         @Path("allottedResources/{arModelCustomizationUuid}")
348         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
349         public Response serviceAllottedResources (
350                         @PathParam("version") String version,
351                         @PathParam("arModelCustomizationUuid") String aUuid
352         ) {
353                 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
354         }
355
356         @GET
357         @Path("serviceAllottedResources")
358         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
359         public Response serviceAllottedResources(
360                         @PathParam("version") String version,
361                         @QueryParam("serviceModelUuid") String smUuid,
362                         @QueryParam("serviceModelInvariantUuid") String smiUuid,
363                         @QueryParam("serviceModelVersion") String smVer,
364                         @QueryParam("arModelCustomizationUuid") String aUuid
365         ) {
366                 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
367         }
368
369         public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String smiUuid, String smVer) {
370                 QueryAllottedResourceCustomization qryResp;
371                 int respStatus = HttpStatus.SC_OK;
372                 String uuid = "";
373                 List<AllottedResourceCustomization > ret;
374
375                 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
376                         if (smUuid != null && !"".equals(smUuid)) {
377                                 uuid = smUuid;
378                                 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelUuid serviceModelUuid: " + uuid);
379                                 ret = db.getAllAllottedResourcesByServiceModelUuid(uuid);
380                         }
381                         else if (smiUuid != null && !"".equals(smiUuid)) {
382                                 uuid = smiUuid;
383                                 if (smVer != null && !"".equals(smVer)) {
384                                         LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
385                                         ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid, smVer);
386                                 }
387                                 else {
388                                         LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
389                                         ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid);
390                                 }
391                         }
392                         else if (aUuid != null && !"".equals(aUuid)) {
393                                 uuid = aUuid;
394                                 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByArModelCustomizationUuid serviceModelUuid: " + uuid);
395                                 ret = db.getAllAllottedResourcesByArModelCustomizationUuid(uuid);
396                         }
397                         else {
398                                 throw(new Exception("no matching parameters"));
399                         }
400
401                         if (ret == null || ret.isEmpty()) {
402                                 LOGGER.debug ("AllottedResourceCustomization not found");
403                                 respStatus = HttpStatus.SC_NOT_FOUND;
404                                 qryResp = new QueryAllottedResourceCustomization();
405                         } else {
406                                 LOGGER.debug ("AllottedResourceCustomization found");
407                                 qryResp = new QueryAllottedResourceCustomization(ret);
408                                 LOGGER.debug ("AllottedResourceCustomization qryResp="+ qryResp);
409                         }
410                         LOGGER.debug ("Query AllottedResourceCustomization exit");
411                         return respond(version, respStatus, isArray, qryResp);
412                 } catch (Exception e) {
413                         LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  uuid, "", "queryAllottedResourceCustomization", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryAllottedResourceCustomization", e);
414                         CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
415                         return Response
416                                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
417                                 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
418                                 .build();
419                 }
420         }
421         
422         // Added for DHV in 1702.  Might be a temporary solution!
423         // Changing to use QueryVfModule so the modelCustomizationUuid is included in response
424         @GET
425         @Path("vfModules")
426         @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
427         public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
428                 QueryVfModule qryResp;
429                 int respStatus = HttpStatus.SC_OK;
430                 List<VfModuleCustomization> ret = null;
431
432         try (CatalogDatabase db = CatalogDatabase.getInstance()) {
433             if (vfModuleModelName != null && !"".equals(vfModuleModelName)) {
434                 LOGGER.debug("Query vfModules by vfModuleModuleName: " + vfModuleModelName);
435                 VfModuleCustomization vfModule = db.getVfModuleCustomizationByModelName(vfModuleModelName);
436                 if (vfModule != null) {
437                     ret = new ArrayList<>(1);
438                     ret.add(vfModule);
439                 }
440             } else {
441                 throw (new Exception("Incoming parameter is null or blank"));
442             }
443             if (ret == null || ret.isEmpty()) {
444                 LOGGER.debug("vfModules not found");
445                 respStatus = HttpStatus.SC_NOT_FOUND;
446                 qryResp = new QueryVfModule();
447             } else {
448                 LOGGER.debug("vfModules found");
449                 qryResp = new QueryVfModule(ret);
450                 LOGGER.debug("vfModules query Results is: " + qryResp);
451                 LOGGER.debug("vfModules tojsonstring is: " + qryResp.JSON2(false, false));
452             }
453             LOGGER.debug("Query vfModules exit");
454             return Response
455                 .status(respStatus)
456                 .entity(qryResp.JSON2(false, false))
457                 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
458                 .build();
459         } catch (Exception e) {
460             LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleModelName, "", "queryVfModules",
461                 MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query VfModules by vfModuleModuleName: ",
462                 e);
463             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
464                 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
465             return Response
466                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
467                 .entity(new GenericEntity<CatalogQueryException>(excResp) {
468                 })
469                 .build();
470         }
471         }
472
473         /**
474          * Get the tosca csar info from catalog
475          * <br>
476          * 
477          * @param smUuid service model uuid
478          * @return the tosca csar information of the serivce.
479          * @since ONAP Beijing Release
480          */
481     @GET
482     @Path("serviceToscaCsar")
483     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
484     public Response ServiceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
485         int respStatus = HttpStatus.SC_OK;
486         String entity = "";
487         try (CatalogDatabase db = CatalogDatabase.getInstance()) {
488             if (smUuid != null && !"".equals(smUuid)) {
489                 LOGGER.debug("Query Csar by service model uuid: " + smUuid);
490                 ToscaCsar toscaCsar = db.getToscaCsarByServiceModelUUID(smUuid);
491                 if (toscaCsar != null) {
492                     QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
493                     entity = serviceCsar.JSON2(false, false);
494                 } else {
495                     respStatus = HttpStatus.SC_NOT_FOUND;
496                 }
497             } else {
498                 throw (new Exception("Incoming parameter is null or blank"));
499             }
500             LOGGER.debug("Query Csar exit");
501             return Response
502                 .status(respStatus)
503                 .entity(entity)
504                 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
505                 .build();
506         } catch (Exception e) {
507             LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, smUuid, "", "ServiceToscaCsar",
508                 MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query csar by service model uuid: ", e);
509             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
510                 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
511             return Response
512                 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
513                 .entity(new GenericEntity<CatalogQueryException>(excResp) {
514                 })
515                 .build();
516         }
517     }
518 }