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.
54 import java.util.List;
56 import javax.ws.rs.Consumes;
57 import javax.ws.rs.DELETE;
58 import javax.ws.rs.GET;
59 import javax.ws.rs.HEAD;
60 import javax.ws.rs.POST;
61 import javax.ws.rs.PUT;
62 import javax.ws.rs.Path;
63 import javax.ws.rs.PathParam;
64 import javax.ws.rs.Produces;
65 import javax.ws.rs.QueryParam;
66 import javax.ws.rs.core.Response;
67 import javax.ws.rs.core.GenericEntity;
68 import javax.ws.rs.core.HttpHeaders;
69 import javax.ws.rs.core.MediaType;
70 import javax.xml.ws.Holder;
72 import org.apache.http.HttpStatus;
74 import org.openecomp.mso.logger.MessageEnum;
75 import org.openecomp.mso.logger.MsoLogger;
76 import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQueryException;
77 import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory;
78 import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQuery;
79 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceVnfs;
80 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceNetworks;
81 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
82 import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization;
83 import org.openecomp.mso.db.catalog.CatalogDatabase;
84 import org.openecomp.mso.db.catalog.beans.VnfResource;
85 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
86 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
87 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
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
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;
99 public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
102 //.entity(new GenericEntity<QueryServiceVnfs>(qryResp) {})
103 .entity(qryResp.toJsonString(version, isArray))
104 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
111 @Produces(MediaType.TEXT_HTML)
112 public Response healthcheck (
113 @PathParam("version") String version
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();
120 * GET {http-catalog-adapter-root}/v1/serviceVnfs?vnfModelCustomizationUuid=<vnf-model-customization-uuid>
121 * URL:http://localhost:8080/ecomp/mso/catalog/v1/getVfModuleType?vnfType=Test/vSAMP10&vfModuleType=vSAMP10::base::module-0
123 * {"queryVfModule":{"version":1,"asdcUuid":"MANUAL RECORD","created":{"nanos":0},"description":"vSAMP10","environmentId":15184,"id":2312,"isBase":1,"modelName":"vSAMP10::base::module-0","modelVersion":1,"templateId":15123,"type":"Test\/vSAMP10::vSAMP10::base::module-0","vnfResourceId":15187}}
127 @Path("vnfs/{vnfModelCustomizationUuid}")
128 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
129 public Response serviceVnfs (
130 @PathParam("version") String version,
131 @PathParam("vnfModelCustomizationUuid") String vnfUuid
133 return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null);
138 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
139 public Response serviceVnfs(
140 @PathParam("version") String version,
141 @QueryParam("vnfModelCustomizationUuid") String vnfUuid,
142 @QueryParam("serviceModelUuid") String smUuid,
143 @QueryParam("serviceModelInvariantUuid") String smiUuid,
144 @QueryParam("serviceModelVersion") String smVer,
145 @QueryParam("serviceModelName") String smName
147 return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
150 public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String smUuid, String smiUuid, String smVer, String smName) {
151 QueryServiceVnfs qryResp;
152 int respStatus = HttpStatus.SC_OK;
154 List<VnfResource> ret;
156 try (CatalogDatabase db = new CatalogDatabase()) {
157 if (vnfUuid != null && !vnfUuid.equals("")) {
159 LOGGER.debug ("Query serviceVnfs getAllVnfsByVnfModelCustomizationUuid vnfModelCustomizationUuid: " + uuid);
160 ret = db.getAllVnfsByVnfModelCustomizationUuid(uuid);
162 else if (smUuid != null && !smUuid.equals("")) {
164 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceModelUuid serviceModelUuid: " + uuid);
165 ret = db.getAllVnfsByServiceModelUuid(uuid);
167 else if (smiUuid != null && !smiUuid.equals("")) {
169 if (smVer != null && !smVer.equals("")) {
170 LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
171 ret = db.getAllVnfsByServiceModelInvariantUuid(uuid, smVer);
174 LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
175 ret = db.getAllVnfsByServiceModelInvariantUuid(uuid);
178 else if (smName != null && !smName.equals("")) {
179 if (smVer != null && !smVer.equals("")) {
180 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelInvariantName: " + smName+ " serviceModelVersion: "+ smVer);
181 ret = db.getAllVnfsByServiceName(smName, smVer);
184 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelName: " + smName);
185 ret = db.getAllVnfsByServiceName(smName);
188 else if (smName != null && !smName.equals("")) {
189 if (smVer != null && !smVer.equals("")) {
190 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelInvariantName: " + smName+ " serviceModelVersion: "+ smVer);
191 ret = db.getAllVnfsByServiceName(smName, smVer);
194 LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelName: " + smName);
195 ret = db.getAllVnfsByServiceName(smName);
199 throw(new Exception("no matching parameters"));
202 if (ret == null || ret.isEmpty()) {
203 LOGGER.debug ("serviceVnfs not found");
204 respStatus = HttpStatus.SC_NOT_FOUND;
205 qryResp = new QueryServiceVnfs();
207 LOGGER.debug ("serviceVnfs found");
208 qryResp = new QueryServiceVnfs(ret);
209 LOGGER.debug ("serviceVnfs qryResp="+ qryResp);
211 LOGGER.debug ("Query serviceVnfs exit");
212 return respond(version, respStatus, isArray, qryResp);
213 } catch (Exception e) {
214 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceVnfs", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceVnfs", e);
215 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
217 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
218 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
224 @Path("networks/{networkModelCustomizationUuid}")
225 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
226 public Response serviceNetworks (
227 @PathParam("version") String version,
228 @PathParam("networkModelCustomizationUuid") String nUuid
230 return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null);
234 @Path("serviceNetworks")
235 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
236 public Response serviceNetworks (
237 @PathParam("version") String version,
238 @QueryParam("networkModelCustomizationUuid") String nUuid,
239 @QueryParam("networkType") String nType,
240 @QueryParam("serviceModelUuid") String smUuid,
241 @QueryParam("serviceModelInvariantUuid") String smiUuid,
242 @QueryParam("serviceModelVersion") String smVer
244 return serviceNetworksImpl (version, IS_ARRAY, nUuid, nType, smUuid, smiUuid, smVer);
247 public Response serviceNetworksImpl (String version, boolean isArray, String nUuid, String nType, String smUuid, String smiUuid, String smVer) {
248 QueryServiceNetworks qryResp;
249 int respStatus = HttpStatus.SC_OK;
251 List<NetworkResourceCustomization> ret;
253 try (CatalogDatabase db = new CatalogDatabase()) {
254 if (nUuid != null && !nUuid.equals("")) {
256 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkModelCustomizationUuid networkModelCustomizationUuid: " + uuid);
257 ret = db.getAllNetworksByNetworkModelCustomizationUuid(uuid);
259 else if (smUuid != null && !smUuid.equals("")) {
261 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelUuid serviceModelUuid: " + uuid);
262 ret = db.getAllNetworksByServiceModelUuid(uuid);
264 else if (nType != null && !nType.equals("")) {
266 LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkType serviceModelUuid: " + uuid);
267 ret = db.getAllNetworksByNetworkType(uuid);
269 else if (smiUuid != null && !smiUuid.equals("")) {
271 if (smVer != null && !smVer.equals("")) {
272 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
273 ret = db.getAllNetworksByServiceModelInvariantUuid(uuid, smVer);
276 LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
277 ret = db.getAllNetworksByServiceModelInvariantUuid(uuid);
281 throw(new Exception("no matching parameters"));
284 if (ret == null || ret.isEmpty()) {
285 LOGGER.debug ("serviceNetworks not found");
286 respStatus = HttpStatus.SC_NOT_FOUND;
287 qryResp = new QueryServiceNetworks();
289 LOGGER.debug ("serviceNetworks found");
290 qryResp = new QueryServiceNetworks(ret);
291 LOGGER.debug ("serviceNetworks qryResp="+ qryResp);
293 LOGGER.debug ("Query serviceNetworks exit");
294 return respond(version, respStatus, isArray, qryResp);
295 } catch (Exception e) {
296 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceNetworks", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceNetworks", e);
297 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
299 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
300 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
306 @Path("serviceResources")
307 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
308 public Response serviceResources(
309 @PathParam("version") String version,
310 @QueryParam("serviceModelUuid") String smUuid,
311 @QueryParam("serviceModelInvariantUuid") String smiUuid,
312 @QueryParam("serviceModelVersion") String smVer) {
313 QueryServiceMacroHolder qryResp;
314 int respStatus = HttpStatus.SC_OK;
316 ServiceMacroHolder ret;
318 try (CatalogDatabase db = new CatalogDatabase()) {
319 if (smUuid != null && !smUuid.equals("")) {
321 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: " + uuid);
322 ret = db.getAllResourcesByServiceModelUuid(uuid);
324 else if (smiUuid != null && !smiUuid.equals("")) {
326 if (smVer != null && !smVer.equals("")) {
327 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
328 ret = db.getAllResourcesByServiceModelInvariantUuid(uuid, smVer);
331 LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
332 ret = db.getAllResourcesByServiceModelInvariantUuid(uuid);
336 throw(new Exception("no matching parameters"));
340 LOGGER.debug ("serviceMacroHolder not found");
341 respStatus = HttpStatus.SC_NOT_FOUND;
342 qryResp = new QueryServiceMacroHolder();
344 LOGGER.debug ("serviceMacroHolder found");
345 qryResp = new QueryServiceMacroHolder(ret);
346 LOGGER.debug ("serviceMacroHolder qryResp="+ qryResp);
348 LOGGER.debug ("Query serviceMacroHolder exit");
349 return respond(version, respStatus, IS_ARRAY, qryResp);
350 } catch (Exception e) {
351 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceMacroHolder", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceMacroHolder", e);
352 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
354 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
355 .entity(new GenericEntity<CatalogQueryException>(excResp) {})
361 @Path("allottedResources/{arModelCustomizationUuid}")
362 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
363 public Response serviceAllottedResources (
364 @PathParam("version") String version,
365 @PathParam("arModelCustomizationUuid") String aUuid
367 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
371 @Path("serviceAllottedResources")
372 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
373 public Response serviceAllottedResources(
374 @PathParam("version") String version,
375 @QueryParam("serviceModelUuid") String smUuid,
376 @QueryParam("serviceModelInvariantUuid") String smiUuid,
377 @QueryParam("serviceModelVersion") String smVer,
378 @QueryParam("arModelCustomizationUuid") String aUuid
380 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
383 public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String smiUuid, String smVer) {
384 QueryAllottedResourceCustomization qryResp;
385 int respStatus = HttpStatus.SC_OK;
387 List<AllottedResourceCustomization > ret;
389 try (CatalogDatabase db = new CatalogDatabase()) {
390 if (smUuid != null && !smUuid.equals("")) {
392 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelUuid serviceModelUuid: " + uuid);
393 ret = db.getAllAllottedResourcesByServiceModelUuid(uuid);
395 else if (smiUuid != null && !smiUuid.equals("")) {
397 if (smVer != null && !smVer.equals("")) {
398 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
399 ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid, smVer);
402 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
403 ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid);
406 else if (aUuid != null && !aUuid.equals("")) {
408 LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByArModelCustomizationUuid serviceModelUuid: " + uuid);
409 ret = db.getAllAllottedResourcesByArModelCustomizationUuid(uuid);
412 throw(new Exception("no matching parameters"));
415 if (ret == null || ret.isEmpty()) {
416 LOGGER.debug ("AllottedResourceCustomization not found");
417 respStatus = HttpStatus.SC_NOT_FOUND;
418 qryResp = new QueryAllottedResourceCustomization();
420 LOGGER.debug ("AllottedResourceCustomization found");
421 qryResp = new QueryAllottedResourceCustomization(ret);
422 LOGGER.debug ("AllottedResourceCustomization qryResp="+ qryResp);
424 LOGGER.debug ("Query AllottedResourceCustomization exit");
425 return respond(version, respStatus, isArray, qryResp);
426 } catch (Exception e) {
427 LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryAllottedResourceCustomization", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryAllottedResourceCustomization", e);
428 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
430 .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
431 .entity(new GenericEntity<CatalogQueryException>(excResp) {})