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;
55 import javax.ws.rs.GET;
56 import javax.ws.rs.HEAD;
57 import javax.ws.rs.Path;
58 import javax.ws.rs.PathParam;
59 import javax.ws.rs.Produces;
60 import javax.ws.rs.QueryParam;
61 import javax.ws.rs.core.Response;
62 import javax.ws.rs.core.GenericEntity;
63 import javax.ws.rs.core.HttpHeaders;
64 import javax.ws.rs.core.MediaType;
65 import org.apache.http.HttpStatus;
67 import org.openecomp.mso.logger.MessageEnum;
68 import org.openecomp.mso.logger.MsoLogger;
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.CatalogQuery;
72 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceVnfs;
73 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceNetworks;
74 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
75 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization;
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.VnfResourceCustomization;
79 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
80 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
81 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
82 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
85 * This class services calls to the REST interface for VF Modules (http://host:port/ecomp/mso/catalog/v1)
86 * Both XML and JSON can be produced/consumed. Set Accept: and Content-Type: headers appropriately. XML is the default.
87 * Requests respond synchronously only
89 @Path("/{version: v[0-9]+}")
90 public class CatalogDbAdapterRest {
91 private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
92 private static final boolean IS_ARRAY = true;
94 public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
97 //.entity(new GenericEntity<QueryServiceVnfs>(qryResp) {})
98 .entity(qryResp.toJsonString(version, isArray))
99 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
106 @Produces(MediaType.TEXT_HTML)
107 public Response healthcheck (
108 @PathParam("version") String version
110 String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application "+ version+ " ready</body></html>";
111 return Response.ok().entity(CHECK_HTML).build();
115 @Path("vnfResources/{vnfModelCustomizationUuid}")
116 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
117 public Response serviceVnfs (
118 @PathParam("version") String version,
119 @PathParam("vnfModelCustomizationUuid") String vnfUuid
121 return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null);
126 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
127 public Response serviceVnfs(
128 @PathParam("version") String version,
129 @QueryParam("vnfModelCustomizationUuid") String vnfUuid,
130 @QueryParam("serviceModelUuid") String smUuid,
131 @QueryParam("serviceModelInvariantUuid") String smiUuid,
132 @QueryParam("serviceModelVersion") String smVer,
133 @QueryParam("serviceModelName") String smName
135 return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
138 public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String smUuid, String smiUuid, String smVer, String smName) {
139 QueryServiceVnfs qryResp;
140 int respStatus = HttpStatus.SC_OK;
142 List<VnfResourceCustomization> ret;
144 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
145 if (vnfUuid != null && !vnfUuid.equals("")) {
147 LOGGER.debug ("Query serviceVnfs getAllVnfsByVnfModelCustomizationUuid vnfModelCustomizationUuid: " + uuid);
148 ret = db.getAllVnfsByVnfModelCustomizationUuid(uuid);
150 else if (smUuid != null && !smUuid.equals("")) {
152 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceModelUuid serviceModelUuid: " + uuid);
153 ret = db.getAllVnfsByServiceModelUuid(uuid);
155 else if (smiUuid != null && !smiUuid.equals("")) {
157 if (smVer != null && !smVer.equals("")) {
158 LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
159 ret = db.getAllVnfsByServiceModelInvariantUuid(uuid, smVer);
162 LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
163 ret = db.getAllVnfsByServiceModelInvariantUuid(uuid);
166 else if (smName != null && !smName.equals("")) {
167 if (smVer != null && !smVer.equals("")) {
168 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelInvariantName: " + smName+ " serviceModelVersion: "+ smVer);
169 ret = db.getAllVnfsByServiceName(smName, smVer);
172 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelName: " + smName);
173 ret = db.getAllVnfsByServiceName(smName);
177 throw(new Exception("no matching parameters"));
180 if (ret == null || ret.isEmpty()) {
181 LOGGER.debug ("serviceVnfs not found");
182 respStatus = HttpStatus.SC_NOT_FOUND;
183 qryResp = new QueryServiceVnfs();
185 LOGGER.debug ("serviceVnfs found");
186 qryResp = new QueryServiceVnfs(ret);
187 LOGGER.debug ("serviceVnfs qryResp="+ qryResp);
189 LOGGER.debug ("Query serviceVnfs exit");
190 return respond(version, respStatus, isArray, qryResp);
191 } catch (Exception e) {
192 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceVnfs", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceVnfs", e);
193 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
195 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
196 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
202 @Path("networkResources/{networkModelCustomizationUuid}")
203 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
204 public Response serviceNetworks (
205 @PathParam("version") String version,
206 @PathParam("networkModelCustomizationUuid") String nUuid
208 return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null);
212 @Path("serviceNetworks")
213 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
214 public Response serviceNetworks (
215 @PathParam("version") String version,
216 @QueryParam("networkModelCustomizationUuid") String nUuid,
217 @QueryParam("networkType") String nType,
218 @QueryParam("networkModelName") String nModelName,
219 @QueryParam("serviceModelUuid") String smUuid,
220 @QueryParam("serviceModelInvariantUuid") String smiUuid,
221 @QueryParam("serviceModelVersion") String smVer,
222 @QueryParam("networkModelVersion") String nmVer
224 if (nModelName != null && !nModelName.equals("")) {
227 return serviceNetworksImpl (version, IS_ARRAY, nUuid, nType, smUuid, smiUuid, smVer);
230 public Response serviceNetworksImpl (String version, boolean isArray, String nUuid, String nType, String smUuid, String smiUuid, String smVer) {
231 QueryServiceNetworks qryResp;
232 int respStatus = HttpStatus.SC_OK;
234 List<NetworkResourceCustomization> ret;
236 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
237 if (nUuid != null && !nUuid.equals("")) {
239 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkModelCustomizationUuid networkModelCustomizationUuid: " + uuid);
240 ret = db.getAllNetworksByNetworkModelCustomizationUuid(uuid);
242 else if (smUuid != null && !smUuid.equals("")) {
244 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelUuid serviceModelUuid: " + uuid);
245 ret = db.getAllNetworksByServiceModelUuid(uuid);
247 else if (nType != null && !nType.equals("")) {
249 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkType serviceModelUuid: " + uuid);
250 ret = db.getAllNetworksByNetworkType(uuid);
252 else if (smiUuid != null && !smiUuid.equals("")) {
254 if (smVer != null && !smVer.equals("")) {
255 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
256 ret = db.getAllNetworksByServiceModelInvariantUuid(uuid, smVer);
259 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
260 ret = db.getAllNetworksByServiceModelInvariantUuid(uuid);
264 throw(new Exception("no matching parameters"));
267 if (ret == null || ret.isEmpty()) {
268 LOGGER.debug ("serviceNetworks not found");
269 respStatus = HttpStatus.SC_NOT_FOUND;
270 qryResp = new QueryServiceNetworks();
272 LOGGER.debug ("serviceNetworks found");
273 qryResp = new QueryServiceNetworks(ret);
274 LOGGER.debug ("serviceNetworks qryResp="+ qryResp);
276 LOGGER.debug ("Query serviceNetworks exit");
277 return respond(version, respStatus, isArray, qryResp);
278 } catch (Exception e) {
279 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceNetworks", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceNetworks", e);
280 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
282 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
283 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
289 @Path("serviceResources")
290 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
291 public Response serviceResources(
292 @PathParam("version") String version,
293 @QueryParam("serviceModelUuid") String smUuid,
294 @QueryParam("serviceModelInvariantUuid") String smiUuid,
295 @QueryParam("serviceModelVersion") String smVer) {
296 QueryServiceMacroHolder qryResp;
297 int respStatus = HttpStatus.SC_OK;
299 ServiceMacroHolder ret;
301 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
302 if (smUuid != null && !smUuid.equals("")) {
304 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: " + uuid);
305 ret = db.getAllResourcesByServiceModelUuid(uuid);
307 else if (smiUuid != null && !smiUuid.equals("")) {
309 if (smVer != null && !smVer.equals("")) {
310 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
311 ret = db.getAllResourcesByServiceModelInvariantUuid(uuid, smVer);
314 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
315 ret = db.getAllResourcesByServiceModelInvariantUuid(uuid);
319 throw(new Exception("no matching parameters"));
323 LOGGER.debug ("serviceMacroHolder not found");
324 respStatus = HttpStatus.SC_NOT_FOUND;
325 qryResp = new QueryServiceMacroHolder();
327 LOGGER.debug ("serviceMacroHolder found");
328 qryResp = new QueryServiceMacroHolder(ret);
329 LOGGER.debug ("serviceMacroHolder qryResp="+ qryResp);
331 LOGGER.debug ("Query serviceMacroHolder exit");
332 return respond(version, respStatus, IS_ARRAY, qryResp);
333 } catch (Exception e) {
334 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceMacroHolder", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceMacroHolder", e);
335 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
337 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
338 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
344 @Path("allottedResources/{arModelCustomizationUuid}")
345 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
346 public Response serviceAllottedResources (
347 @PathParam("version") String version,
348 @PathParam("arModelCustomizationUuid") String aUuid
350 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
354 @Path("serviceAllottedResources")
355 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
356 public Response serviceAllottedResources(
357 @PathParam("version") String version,
358 @QueryParam("serviceModelUuid") String smUuid,
359 @QueryParam("serviceModelInvariantUuid") String smiUuid,
360 @QueryParam("serviceModelVersion") String smVer,
361 @QueryParam("arModelCustomizationUuid") String aUuid
363 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
366 public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String smiUuid, String smVer) {
367 QueryAllottedResourceCustomization qryResp;
368 int respStatus = HttpStatus.SC_OK;
370 List<AllottedResourceCustomization > ret;
372 try (CatalogDatabase db = CatalogDatabase.getInstance()) {
373 if (smUuid != null && !smUuid.equals("")) {
375 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelUuid serviceModelUuid: " + uuid);
376 ret = db.getAllAllottedResourcesByServiceModelUuid(uuid);
378 else if (smiUuid != null && !smiUuid.equals("")) {
380 if (smVer != null && !smVer.equals("")) {
381 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
382 ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid, smVer);
385 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
386 ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid);
389 else if (aUuid != null && !aUuid.equals("")) {
391 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByArModelCustomizationUuid serviceModelUuid: " + uuid);
392 ret = db.getAllAllottedResourcesByArModelCustomizationUuid(uuid);
395 throw(new Exception("no matching parameters"));
398 if (ret == null || ret.isEmpty()) {
399 LOGGER.debug ("AllottedResourceCustomization not found");
400 respStatus = HttpStatus.SC_NOT_FOUND;
401 qryResp = new QueryAllottedResourceCustomization();
403 LOGGER.debug ("AllottedResourceCustomization found");
404 qryResp = new QueryAllottedResourceCustomization(ret);
405 LOGGER.debug ("AllottedResourceCustomization qryResp="+ qryResp);
407 LOGGER.debug ("Query AllottedResourceCustomization exit");
408 return respond(version, respStatus, isArray, qryResp);
409 } catch (Exception e) {
410 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryAllottedResourceCustomization", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryAllottedResourceCustomization", e);
411 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
413 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
414 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
419 // Added for DHV in 1702. Might be a temporary solution!
420 // Changing to use QueryVfModule so the modelCustomizationUuid is included in response
423 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
424 public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
425 QueryVfModule qryResp;
426 int respStatus = HttpStatus.SC_OK;
427 List<VfModuleCustomization> ret = null;
428 CatalogDatabase db = CatalogDatabase.getInstance();
431 if(vfModuleModelName != null && !vfModuleModelName.equals("")){
432 LOGGER.debug ("Query vfModules by vfModuleModuleName: " + vfModuleModelName);
433 VfModuleCustomization vfModule = db.getVfModuleCustomizationByModelName(vfModuleModelName);
434 if(vfModule != null){
435 ret = new ArrayList<VfModuleCustomization>(1);
439 throw(new Exception("Incoming parameter is null or blank"));
441 if(ret == null || ret.isEmpty()){
442 LOGGER.debug ("vfModules not found");
443 respStatus = HttpStatus.SC_NOT_FOUND;
444 qryResp = new QueryVfModule();
446 LOGGER.debug ("vfModules found");
447 qryResp = new QueryVfModule(ret);
448 LOGGER.debug ("vfModules query Results is: "+ qryResp);
449 LOGGER.debug ("vfModules tojsonstring is: "+ qryResp.JSON2(false, false));
451 LOGGER.debug ("Query vfModules exit");
454 .entity(qryResp.JSON2(false, false))
455 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
458 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleModelName, "", "queryVfModules", MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query VfModules by vfModuleModuleName: ", e);
459 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
461 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
462 .entity(new GenericEntity<CatalogQueryException>(excResp) {})