7e50eab8e8444da821e8346b4aef82c4979cb8a3
[vnfsdk/refrepo.git] /
1 /**
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.vnfsdk.marketplace.resource;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20
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;
34
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;
44
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;
50
51 /**
52  * csar package service.
53  *
54  * @author 10189609
55  *
56  */
57 @Path("/PackageResource")
58 @Api(tags = {"Package Resource"})
59 public class PackageResource {
60
61     @Path("/updatestatus")
62     @POST
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);
79
80     }
81
82
83     @Path("/csars")
84     @GET
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);
103     }
104
105     @Path("/csars/{csarId}")
106     @GET
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);
120     }
121     @Path("/csars")
122     @POST
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);
140     }
141
142     @Path("/csars/{csarId}")
143     @DELETE
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);
154     }
155
156     @Path("/csars/{csarId}/files")
157     @GET
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);
170     }
171
172     @Path("/csars/{csarId}/downloaded")
173     @GET
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);
177     }
178
179     @Path("/csars/{csarId}/reupload")
180     @POST
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);
199     }
200
201     @Path("/csars/{csarId}/onboardstatus")
202     @GET
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)
208     {
209         return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
210     }
211
212     @Path("/csars/{csarId}/operresult")
213     @GET
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);
219     }
220
221     @Path("/csars/onboardsteps")
222     @GET
223     @ApiOperation(value="Get VNF OnBoarded Steps", response=Response.class)
224     @Produces(MediaType.APPLICATION_JSON)
225     public Response getOnBoardingSteps()
226     {
227         return PackageWrapper.getInstance().getOnBoardingSteps();
228     }
229 }
230