2 * Copyright 2017-18 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.
17 package org.onap.vnfsdk.marketplace.resource;
19 import java.io.IOException;
20 import java.io.InputStream;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.ws.rs.Consumes;
24 import javax.ws.rs.DELETE;
25 import javax.ws.rs.GET;
26 import javax.ws.rs.POST;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.PathParam;
29 import javax.ws.rs.Produces;
30 import javax.ws.rs.QueryParam;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.HttpHeaders;
33 import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.Response;
36 import org.eclipse.jetty.http.HttpStatus;
37 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
38 import org.glassfish.jersey.media.multipart.FormDataParam;
39 import org.onap.vnfsdk.marketplace.common.CommonConstant;
40 import org.onap.vnfsdk.marketplace.db.connection.ConnectionUtil;
41 import org.onap.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
42 import org.onap.vnfsdk.marketplace.db.resource.PackageManager;
43 import org.onap.vnfsdk.marketplace.entity.response.CsarFileUriResponse;
44 import org.onap.vnfsdk.marketplace.entity.response.PackageMeta;
45 import org.onap.vnfsdk.marketplace.entity.response.UploadPackageResponse;
46 import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
47 import org.onap.vnfsdk.marketplace.rest.RestConstant;
48 import org.onap.vnfsdk.marketplace.rest.RestResponse;
49 import org.onap.vnfsdk.marketplace.rest.RestfulClient;
50 import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper;
52 import io.swagger.annotations.Api;
53 import io.swagger.annotations.ApiOperation;
54 import io.swagger.annotations.ApiParam;
55 import io.swagger.annotations.ApiResponse;
56 import io.swagger.annotations.ApiResponses;
59 @Path("/PackageResource")
60 @Api(tags = { "Package Resource" })
61 public class PackageResource {
63 @Path("/updatestatus")
65 @ApiOperation(value = "update validate and lifecycle test status", response = UploadPackageResponse.class)
66 @Consumes(MediaType.APPLICATION_JSON)
67 @Produces(MediaType.APPLICATION_JSON)
68 @ApiResponses(value = {
69 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
70 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
71 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "update error", response = String.class) })
72 public Response updateValidateStatus(@ApiParam(value = "http request body") @Context HttpServletRequest request,
73 @ApiParam(value = "http header") @Context HttpHeaders head) throws IOException {
74 InputStream input = request.getInputStream();
75 return PackageWrapper.getInstance().updateValidateStatus(input);
81 @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class, responseContainer = "List")
82 @Produces(MediaType.APPLICATION_JSON)
83 @ApiResponses(value = {
84 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
85 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
86 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
87 public Response queryPackageListByCond(@ApiParam(value = "csar name") @QueryParam("name") String name,
88 @ApiParam(value = "csar provider") @QueryParam("provider") String provider,
89 @ApiParam(value = "csar version") @QueryParam("version") String version,
90 @ApiParam(value = "delay to delete") @QueryParam("deletionPending") String deletionPending,
91 @ApiParam(value = "csar type") @QueryParam("type") String type) {
92 return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version, deletionPending, type);
95 @Path("/csars/{csarId}")
97 @ApiOperation(value = "get csar package list", response = PackageMeta.class, responseContainer = "List")
98 @Produces(MediaType.APPLICATION_JSON)
99 @ApiResponses(value = {
100 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
101 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
102 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
103 public Response queryPackageById(@ApiParam(value = "csar id") @PathParam("csarId") String csarId) {
104 return PackageWrapper.getInstance().queryPackageById(csarId);
109 @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class)
110 @Consumes(MediaType.MULTIPART_FORM_DATA)
111 @Produces(MediaType.APPLICATION_JSON)
112 @ApiResponses(value = {
113 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
114 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
115 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
116 public Response uploadPackage(
117 @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
118 @FormDataParam("params") String details,
119 @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
120 @ApiParam(value = "http header") @Context HttpHeaders head)
121 throws IOException, MarketplaceResourceException {
122 return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, details, head);
125 @Path("/csars/{csarId}")
127 @ApiOperation(value = "delete a package")
128 @ApiResponses(value = {
129 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
130 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
131 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
132 public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
133 return PackageWrapper.getInstance().delPackage(csarId);
136 @Path("/csars/{csarId}/files")
138 @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class)
139 @Produces(MediaType.APPLICATION_JSON)
140 @ApiResponses(value = {
141 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
142 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
143 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
144 public Response getCsarFileUri(@ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId) {
145 return PackageWrapper.getInstance().getCsarFileUri(csarId);
148 @Path("/csars/{csarId}/downloaded")
150 @ApiOperation(value = "update download count for a package", response = Response.class)
151 public Response updateDwonloadCount(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
152 return PackageWrapper.getInstance().updateDwonloadCount(csarId);
155 @Path("/csars/{csarId}/reupload")
157 @ApiOperation(value = "re-upload csar package", response = UploadPackageResponse.class)
158 @Consumes(MediaType.MULTIPART_FORM_DATA)
159 @Produces(MediaType.APPLICATION_JSON)
160 @ApiResponses(value = {
161 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
162 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
163 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
164 public Response reUploadPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
165 @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
166 @FormDataParam("params") String details,
167 @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
168 @ApiParam(value = "http header") @Context HttpHeaders head)
169 throws IOException, MarketplaceResourceException {
170 return PackageWrapper.getInstance().reUploadPackage(csarId, uploadedInputStream, fileDetail, details, head);
173 @Path("/csars/{csarId}/onboardstatus")
175 @ApiOperation(value = "Get VNF OnBoarding Result", response = OnBoardingResult.class)
176 @Produces(MediaType.APPLICATION_JSON)
177 public Response getOnBoardingResult(@ApiParam("csar Id") @PathParam("csarId") String csarId,
178 @ApiParam("operation type") @QueryParam("operTypeId") String operTypeId,
179 @ApiParam("operation id") @QueryParam("operId") String operId) {
180 return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
183 @Path("/csars/{csarId}/operresult")
185 @ApiOperation(value = "Get VNF OnBoarded Opeartion Result", response = Response.class)
186 @Produces(MediaType.APPLICATION_JSON)
187 public Response getOperStatus(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
188 @ApiParam(value = "operation type") @QueryParam("operTypeId") String operTypeId) {
189 return PackageWrapper.getInstance().getOperResultByOperTypeId(csarId, operTypeId);
192 @Path("/csars/onboardsteps")
194 @ApiOperation(value = "Get VNF OnBoarded Steps", response = Response.class)
195 @Produces(MediaType.APPLICATION_JSON)
196 public Response getOnBoardingSteps() {
197 return PackageWrapper.getInstance().getOnBoardingSteps();
200 @Path("/healthcheck")
202 @ApiOperation(value = "Health for VNF Repository", response = Response.class)
203 @Produces(MediaType.APPLICATION_JSON)
204 public Response healthCheck() {
205 if (ConnectionUtil.getSession() == null){
206 return Response.serverError().build();
209 return Response.ok().build();