2 * Copyright 2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vnfsdk.marketplace.resource;
18 import java.io.IOException;
19 import java.io.InputStream;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.ws.rs.Consumes;
23 import javax.ws.rs.DELETE;
24 import javax.ws.rs.GET;
25 import javax.ws.rs.POST;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.QueryParam;
30 import javax.ws.rs.core.Context;
31 import javax.ws.rs.core.HttpHeaders;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response;
35 import org.eclipse.jetty.http.HttpStatus;
36 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
37 import org.glassfish.jersey.media.multipart.FormDataParam;
38 import org.onap.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
39 import org.onap.vnfsdk.marketplace.entity.response.CsarFileUriResponse;
40 import org.onap.vnfsdk.marketplace.entity.response.PackageMeta;
41 import org.onap.vnfsdk.marketplace.entity.response.UploadPackageResponse;
42 import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
43 import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper;
45 import io.swagger.annotations.Api;
46 import io.swagger.annotations.ApiOperation;
47 import io.swagger.annotations.ApiParam;
48 import io.swagger.annotations.ApiResponse;
49 import io.swagger.annotations.ApiResponses;
52 * csar package service.
57 @Path("/PackageResource")
58 @Api(tags = {"Package Resource"})
59 public class PackageResource {
61 @Path("/updatestatus")
63 @ApiOperation(value = "update validate and lifecycle test status", response = UploadPackageResponse.class)
64 @Consumes(MediaType.APPLICATION_JSON)
65 @Produces(MediaType.APPLICATION_JSON)
66 @ApiResponses(value = {
67 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
68 response = String.class),
69 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
70 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
71 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "update error",
72 response = String.class)})
73 public Response updateValidateStatus(
74 @ApiParam(value = "http request body") @Context HttpServletRequest request,
75 @ApiParam(value = "http header") @Context HttpHeaders head
76 ) throws IOException {
77 InputStream input = request.getInputStream();
78 return PackageWrapper.getInstance().updateValidateStatus(input);
85 @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class,
86 responseContainer = "List")
87 @Produces(MediaType.APPLICATION_JSON)
88 @ApiResponses(value = {
89 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
90 response = String.class),
91 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
92 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
93 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
94 response = String.class)})
95 public Response queryPackageListByCond(
96 @ApiParam(value = "csar name") @QueryParam("name") String name, @ApiParam(
97 value = "csar provider") @QueryParam("provider") String provider, @ApiParam(
98 value = "csar version") @QueryParam("version") String version, @ApiParam(
99 value = "delay to delete") @QueryParam("deletionPending") String deletionPending,
100 @ApiParam(value = "csar type") @QueryParam("type") String type) {
101 return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version,
102 deletionPending, type);
105 @Path("/csars/{csarId}")
107 @ApiOperation(value = "get csar package list", response = PackageMeta.class,
108 responseContainer = "List")
109 @Produces(MediaType.APPLICATION_JSON)
110 @ApiResponses(value = {
111 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
112 response = String.class),
113 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
114 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
115 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
116 response = String.class)})
117 public Response queryPackageById(
118 @ApiParam(value = "csar id") @PathParam("csarId") String csarId) {
119 return PackageWrapper.getInstance().queryPackageById(csarId);
123 @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class)
124 @Consumes(MediaType.MULTIPART_FORM_DATA)
125 @Produces(MediaType.APPLICATION_JSON)
126 @ApiResponses(value = {
127 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
128 response = String.class),
129 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
130 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
131 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
132 response = String.class)})
133 public Response uploadPackage(
134 @ApiParam(value = "file inputstream",
135 required = true) @FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("params") String details,
136 @ApiParam(value = "file detail",
137 required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
138 @ApiParam(value = "http header") @Context HttpHeaders head) throws IOException, MarketplaceResourceException {
139 return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, details, head);
142 @Path("/csars/{csarId}")
144 @ApiOperation(value = "delete a package")
145 @ApiResponses(value = {
146 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
147 response = String.class),
148 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
149 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
150 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
151 response = String.class)})
152 public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
153 return PackageWrapper.getInstance().delPackage(csarId);
156 @Path("/csars/{csarId}/files")
158 @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class)
159 @Produces(MediaType.APPLICATION_JSON)
160 @ApiResponses(value = {
161 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
162 response = String.class),
163 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
164 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
165 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
166 response = String.class)})
167 public Response getCsarFileUri(
168 @ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId) {
169 return PackageWrapper.getInstance().getCsarFileUri(csarId);
172 @Path("/csars/{csarId}/downloaded")
174 @ApiOperation(value = "update download count for a package",response = Response.class)
175 public Response updateDwonloadCount(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
176 return PackageWrapper.getInstance().updateDwonloadCount(csarId);
179 @Path("/csars/{csarId}/reupload")
181 @ApiOperation(value = "re-upload csar package", response = UploadPackageResponse.class)
182 @Consumes(MediaType.MULTIPART_FORM_DATA)
183 @Produces(MediaType.APPLICATION_JSON)
184 @ApiResponses(value = {
185 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
186 response = String.class),
187 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
188 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
189 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
190 response = String.class)})
191 public Response reUploadPackage(
192 @ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
193 @ApiParam(value = "file inputstream",
194 required = true) @FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("params") String details,
195 @ApiParam(value = "file detail",
196 required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
197 @ApiParam(value = "http header") @Context HttpHeaders head) throws IOException, MarketplaceResourceException {
198 return PackageWrapper.getInstance().reUploadPackage(csarId,uploadedInputStream, fileDetail, details, head);
201 @Path("/csars/{csarId}/onboardstatus")
203 @ApiOperation(value="Get VNF OnBoarding Result", response=OnBoardingResult.class)
204 @Produces(MediaType.APPLICATION_JSON)
205 public Response getOnBoardingResult(@ApiParam("csar Id") @PathParam("csarId") String csarId,
206 @ApiParam("operation type") @QueryParam("operTypeId") String operTypeId,
207 @ApiParam("operation id") @QueryParam("operId") String operId)
209 return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
212 @Path("/csars/{csarId}/operresult")
214 @ApiOperation(value = "Get VNF OnBoarded Opeartion Result", response = Response.class)
215 @Produces(MediaType.APPLICATION_JSON)
216 public Response getOperStatus(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
217 @ApiParam(value = "operation type") @QueryParam("operTypeId") String operTypeId) {
218 return PackageWrapper.getInstance().getOperResultByOperTypeId(csarId,operTypeId);
221 @Path("/csars/onboardsteps")
223 @ApiOperation(value="Get VNF OnBoarded Steps", response=Response.class)
224 @Produces(MediaType.APPLICATION_JSON)
225 public Response getOnBoardingSteps()
227 return PackageWrapper.getInstance().getOnBoardingSteps();