2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.mso.adapters.catalogdb;
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
27 Returns a structure (JSON?) containing VNF RESOURCE attributes, plus a list of VF Module structures.
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.
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
35 Update the MSO Catalog DB schema to include the new fields defined in this user story.
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.
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.
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).
48 min and initial counts can be 0. max can be null to indicate no maximum.
50 Once the network-level distribution artifacts are defined, similar updates can be made to the NETWORK_RESOURCE table.
53 import java.util.ArrayList;
54 import java.util.List;
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;
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;
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
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;
97 public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
100 //.entity(new GenericEntity<QueryServiceVnfs>(qryResp) {})
101 .entity(qryResp.toJsonString(version, isArray))
102 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
109 @Produces(MediaType.TEXT_HTML)
110 public Response healthcheck (
111 @PathParam("version") String version
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();
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
124 return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null);
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
138 return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
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;
145 List<VnfResourceCustomization> ret;
147 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
148 if (vnfUuid != null && !"".equals(vnfUuid)) {
150 LOGGER.debug ("Query serviceVnfs getAllVnfsByVnfModelCustomizationUuid vnfModelCustomizationUuid: " + uuid);
151 ret = db.getAllVnfsByVnfModelCustomizationUuid(uuid);
153 else if (smUuid != null && !"".equals(smUuid)) {
155 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceModelUuid serviceModelUuid: " + uuid);
156 ret = db.getAllVnfsByServiceModelUuid(uuid);
158 else if (smiUuid != null && !"".equals(smiUuid)) {
160 if (smVer != null && !"".equals(smVer)) {
161 LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
162 ret = db.getAllVnfsByServiceModelInvariantUuid(uuid, smVer);
165 LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
166 ret = db.getAllVnfsByServiceModelInvariantUuid(uuid);
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);
175 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelName: " + smName);
176 ret = db.getAllVnfsByServiceName(smName);
180 throw(new Exception("no matching parameters"));
183 if (ret == null || ret.isEmpty()) {
184 LOGGER.debug ("serviceVnfs not found");
185 respStatus = HttpStatus.SC_NOT_FOUND;
186 qryResp = new QueryServiceVnfs();
188 LOGGER.debug ("serviceVnfs found");
189 qryResp = new QueryServiceVnfs(ret);
190 LOGGER.debug ("serviceVnfs qryResp="+ qryResp);
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);
198 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
199 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
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
211 return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null);
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
227 if (nModelName != null && !"".equals(nModelName)) {
230 return serviceNetworksImpl (version, IS_ARRAY, nUuid, nType, smUuid, smiUuid, smVer);
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;
237 List<NetworkResourceCustomization> ret;
239 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
240 if (nUuid != null && !"".equals(nUuid)) {
242 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkModelCustomizationUuid networkModelCustomizationUuid: " + uuid);
243 ret = db.getAllNetworksByNetworkModelCustomizationUuid(uuid);
245 else if (smUuid != null && !"".equals(smUuid)) {
247 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelUuid serviceModelUuid: " + uuid);
248 ret = db.getAllNetworksByServiceModelUuid(uuid);
250 else if (nType != null && !"".equals(nType)) {
252 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkType serviceModelUuid: " + uuid);
253 ret = db.getAllNetworksByNetworkType(uuid);
255 else if (smiUuid != null && !"".equals(smiUuid)) {
257 if (smVer != null && !"".equals(smVer)) {
258 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
259 ret = db.getAllNetworksByServiceModelInvariantUuid(uuid, smVer);
262 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
263 ret = db.getAllNetworksByServiceModelInvariantUuid(uuid);
267 throw(new Exception("no matching parameters"));
270 if (ret == null || ret.isEmpty()) {
271 LOGGER.debug ("serviceNetworks not found");
272 respStatus = HttpStatus.SC_NOT_FOUND;
273 qryResp = new QueryServiceNetworks();
275 LOGGER.debug ("serviceNetworks found");
276 qryResp = new QueryServiceNetworks(ret);
277 LOGGER.debug ("serviceNetworks qryResp="+ qryResp);
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);
285 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
286 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
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;
302 ServiceMacroHolder ret;
304 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
305 if (smUuid != null && !"".equals(smUuid)) {
307 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: " + uuid);
308 ret = db.getAllResourcesByServiceModelUuid(uuid);
310 else if (smiUuid != null && !"".equals(smiUuid)) {
312 if (smVer != null && !"".equals(smVer)) {
313 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
314 ret = db.getAllResourcesByServiceModelInvariantUuid(uuid, smVer);
317 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
318 ret = db.getAllResourcesByServiceModelInvariantUuid(uuid);
322 throw(new Exception("no matching parameters"));
326 LOGGER.debug ("serviceMacroHolder not found");
327 respStatus = HttpStatus.SC_NOT_FOUND;
328 qryResp = new QueryServiceMacroHolder();
330 LOGGER.debug ("serviceMacroHolder found");
331 qryResp = new QueryServiceMacroHolder(ret);
332 LOGGER.debug ("serviceMacroHolder qryResp="+ qryResp);
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);
340 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
341 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
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
353 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
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
366 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
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;
373 List<AllottedResourceCustomization > ret;
375 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
376 if (smUuid != null && !"".equals(smUuid)) {
378 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelUuid serviceModelUuid: " + uuid);
379 ret = db.getAllAllottedResourcesByServiceModelUuid(uuid);
381 else if (smiUuid != null && !"".equals(smiUuid)) {
383 if (smVer != null && !"".equals(smVer)) {
384 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
385 ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid, smVer);
388 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
389 ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid);
392 else if (aUuid != null && !"".equals(aUuid)) {
394 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByArModelCustomizationUuid serviceModelUuid: " + uuid);
395 ret = db.getAllAllottedResourcesByArModelCustomizationUuid(uuid);
398 throw(new Exception("no matching parameters"));
401 if (ret == null || ret.isEmpty()) {
402 LOGGER.debug ("AllottedResourceCustomization not found");
403 respStatus = HttpStatus.SC_NOT_FOUND;
404 qryResp = new QueryAllottedResourceCustomization();
406 LOGGER.debug ("AllottedResourceCustomization found");
407 qryResp = new QueryAllottedResourceCustomization(ret);
408 LOGGER.debug ("AllottedResourceCustomization qryResp="+ qryResp);
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);
416 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
417 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
422 // Added for DHV in 1702. Might be a temporary solution!
423 // Changing to use QueryVfModule so the modelCustomizationUuid is included in response
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;
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);
441 throw (new Exception("Incoming parameter is null or blank"));
443 if (ret == null || ret.isEmpty()) {
444 LOGGER.debug("vfModules not found");
445 respStatus = HttpStatus.SC_NOT_FOUND;
446 qryResp = new QueryVfModule();
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));
453 LOGGER.debug("Query vfModules exit");
456 .entity(qryResp.JSON2(false, false))
457 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
459 } catch (Exception e) {
460 LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleModelName, "", "queryVfModules",
461 MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query VfModules by vfModuleModuleName: ",
463 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
464 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
466 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
467 .entity(new GenericEntity<CatalogQueryException>(excResp) {
474 * Get the tosca csar info from catalog
477 * @param smUuid service model uuid
478 * @return the tosca csar information of the serivce.
479 * @since ONAP Beijing Release
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;
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);
495 respStatus = HttpStatus.SC_NOT_FOUND;
498 throw (new Exception("Incoming parameter is null or blank"));
500 LOGGER.debug("Query Csar exit");
504 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
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);
512 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
513 .entity(new GenericEntity<CatalogQueryException>(excResp) {