2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vnfmadapter.rest;
23 import static org.onap.so.adapters.vnfmadapter.Constants.APPLICATION_ZIP;
24 import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
25 import static org.slf4j.LoggerFactory.getLogger;
26 import java.util.List;
27 import java.util.Optional;
28 import javax.ws.rs.core.MediaType;
29 import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.EtsiCatalogServiceProvider;
30 import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
31 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
32 import org.slf4j.Logger;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.stereotype.Controller;
37 import org.springframework.web.bind.annotation.GetMapping;
38 import org.springframework.web.bind.annotation.PathVariable;
39 import org.springframework.web.bind.annotation.RequestMapping;
42 * Controller for handling the VNF Package Management. For further information please read:
43 * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/003/02.05.01_60/gs_nfv-sol003v020501p.pdf Use the section number
44 * above each endpoint to find the corresponding section in the above document.
46 * @author gareth.roper@est.tech
49 @RequestMapping(value = PACKAGE_MANAGEMENT_BASE_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
50 public class Sol003PackageManagementController {
52 private final EtsiCatalogServiceProvider etsiCatalogServiceProvider;
55 Sol003PackageManagementController(final EtsiCatalogServiceProvider etsiCatalogServiceProvider) {
56 this.etsiCatalogServiceProvider = etsiCatalogServiceProvider;
60 private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {}";
61 private static final Logger logger = getLogger(Sol003PackageManagementController.class);
64 * GET VNF packages information. Will return zero or more VNF package representations that match the attribute
65 * filter. These representations will be in a list. Section Number: 10.4.2
67 * @return A List of all VNF packages. Object: List<InlineResponse2001> Response Code: 200 OK
70 @GetMapping(value = "/vnf_packages", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
71 public ResponseEntity<List<InlineResponse2001>> getVnfPackages() {
72 logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages.");
73 return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
77 * GET VNF package information. Will return a specific VNF package representation that match the attribute filter.
78 * Section Number: 10.4.3
80 * @param vnfPkgId The ID of the VNF Package that you want to query.
81 * @return A VNF package based on vnfPkgId. Object: VnfPkgInfo Response Code: 200 OK
83 @GetMapping(value = "/vnf_packages/{vnfPkgId}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
84 public ResponseEntity<InlineResponse2001> getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) {
85 logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage: ", vnfPkgId);
86 return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
90 * GET VNFD, from VNF package. Will return a copy of the file representing the VNFD or a ZIP file that contains the
91 * file/multiple files representing the VNFD specified. Section Number: 10.4.4
93 * @param vnfPkgId The ID of the VNF Package that you want to retrieve the VNFD from.
94 * @return The VNFD of a VNF Package as a single file or within a ZIP file. Object: byte[] Response Code: 200 OK
96 @GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd",
97 produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP, MediaType.APPLICATION_JSON})
98 public ResponseEntity<byte[]> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) {
99 logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd: ", vnfPkgId);
100 return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
104 * GET Package Content, from VNF Package. Will return a copy of the VNF package file that you specified. Section
107 * @param vnfPkgId The ID of the VNF Package that you want to retrieve the "package_content" from.
108 * @return The Package Content of a VNF Package. Object: byte[] Response Code: 200 OK
110 @GetMapping(value = "/vnf_packages/{vnfPkgId}/package_content",
111 produces = {MediaType.APPLICATION_JSON, APPLICATION_ZIP, MediaType.APPLICATION_OCTET_STREAM})
112 public ResponseEntity getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) {
113 logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Endpoint Invoked with VNF Package ID: ", vnfPkgId);
114 final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageContent(vnfPkgId);
115 if (response.isPresent()) {
116 logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Response: ", HttpStatus.OK);
117 return new ResponseEntity(response.get(), HttpStatus.OK);
119 logger.error("Null response was received from the EtsiCatalogManager using the GET \"package_content\"");
120 return new ResponseEntity(buildProblemDetails("An error occurred, a null response was received by the\n"
121 + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"package_content\" \n"
122 + "endpoint."), HttpStatus.INTERNAL_SERVER_ERROR);
126 * GET Artifact, from VNF Package Will return a the content of the artifact that you specified. Section Number:
129 * @param vnfPkgId The ID of the VNF Package that you want to retrieve an artifact from.
130 * @param artifactPath The path of the artifact that you want to retrieve.
131 * @return An Artifact from a VNF Package. Object: byte[] Response Code: 200 OK
133 @GetMapping(value = "/vnf_packages/{vnfPkgId}/artifacts/{artifactPath}",
134 produces = {MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
135 public ResponseEntity<byte[]> getVnfPackageArtifact(@PathVariable("vnfPkgId") final String vnfPkgId,
136 @PathVariable("artifactPath") final String artifactPath) {
137 logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact: vnfPkgId=", vnfPkgId, " artifactPath=", artifactPath);
138 return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
142 * Builds the ProblemDetails Object, using the provided error message.
144 * @param detail The error message retrieved from the exception thrown.
145 * @return ProblemDetails Object, containing error information.
147 private ProblemDetails buildProblemDetails(String detail) {
148 final ProblemDetails problemDetails = new ProblemDetails();
149 problemDetails.setDetail(detail);
150 return problemDetails;