1f6de0a0bac4b0e8bf1058cd3f3206f7fce4b47e
[vnfsdk/refrepo.git] /
1 /**
2  * Copyright 2017-18 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
17 package org.onap.vnfsdk.marketplace.resource;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21
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;
35
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.db.connection.ConnectionUtil;
40 import org.onap.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
41 import org.onap.vnfsdk.marketplace.entity.response.CsarFileUriResponse;
42 import org.onap.vnfsdk.marketplace.entity.response.PackageMeta;
43 import org.onap.vnfsdk.marketplace.entity.response.UploadPackageResponse;
44 import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
45 import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper;
46
47 import io.swagger.annotations.Api;
48 import io.swagger.annotations.ApiOperation;
49 import io.swagger.annotations.ApiParam;
50 import io.swagger.annotations.ApiResponse;
51 import io.swagger.annotations.ApiResponses;
52
53
54 @Path("/PackageResource")
55 @Api(tags = { "Package Resource" })
56 public class PackageResource {
57
58     @Path("/updatestatus")
59     @POST
60     @ApiOperation(value = "update validate and lifecycle test status", response = UploadPackageResponse.class)
61     @Consumes(MediaType.APPLICATION_JSON)
62     @Produces(MediaType.APPLICATION_JSON)
63     @ApiResponses(value = {
64             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
65             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
66             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "update  error", response = String.class) })
67     public Response updateValidateStatus(@ApiParam(value = "http request body") @Context HttpServletRequest request,
68             @ApiParam(value = "http header") @Context HttpHeaders head) throws IOException {
69         InputStream input = request.getInputStream();
70         return PackageWrapper.getInstance().updateValidateStatus(input);
71
72     }
73
74     @Path("/csars")
75     @GET
76     @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class, responseContainer = "List")
77     @Produces(MediaType.APPLICATION_JSON)
78     @ApiResponses(value = {
79             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
80             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
81             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
82     public Response queryPackageListByCond(@ApiParam(value = "csar name") @QueryParam("name") String name,
83             @ApiParam(value = "csar provider") @QueryParam("provider") String provider,
84             @ApiParam(value = "csar version") @QueryParam("version") String version,
85             @ApiParam(value = "delay to delete") @QueryParam("deletionPending") String deletionPending,
86             @ApiParam(value = "csar type") @QueryParam("type") String type) {
87         return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version, deletionPending, type);
88     }
89
90     @Path("/csars/{csarId}")
91     @GET
92     @ApiOperation(value = "get csar package list", response = PackageMeta.class, responseContainer = "List")
93     @Produces(MediaType.APPLICATION_JSON)
94     @ApiResponses(value = {
95             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
96             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
97             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
98     public Response queryPackageById(@ApiParam(value = "csar id") @PathParam("csarId") String csarId) {
99         return PackageWrapper.getInstance().queryPackageById(csarId);
100     }
101
102     @Path("/csars")
103     @POST
104     @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class)
105     @Consumes(MediaType.MULTIPART_FORM_DATA)
106     @Produces(MediaType.APPLICATION_JSON)
107     @ApiResponses(value = {
108             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
109             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
110             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
111     public Response uploadPackage(
112             @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
113             @FormDataParam("params") String details,
114             @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
115             @ApiParam(value = "http header") @Context HttpHeaders head)
116     {
117         return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, details, head);
118     }
119
120     @Path("/csars/{csarId}")
121     @DELETE
122     @ApiOperation(value = "delete a package")
123     @ApiResponses(value = {
124             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
125             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
126             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
127     public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
128         return PackageWrapper.getInstance().delPackage(csarId);
129     }
130
131     @Path("/csars/{csarId}/files")
132     @GET
133     @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class)
134     @Produces(MediaType.APPLICATION_JSON)
135     @ApiResponses(value = {
136             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
137             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
138             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
139     public Response getCsarFileUri(@ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId) {
140         return PackageWrapper.getInstance().getCsarFileUri(csarId);
141     }
142
143     @Path("/csars/{csarId}/downloaded")
144     @GET
145     @ApiOperation(value = "update download count for a package", response = Response.class)
146     public Response updateDwonloadCount(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
147         return PackageWrapper.getInstance().updateDwonloadCount(csarId);
148     }
149
150     @Path("/csars/{csarId}/reupload")
151     @POST
152     @ApiOperation(value = "re-upload csar package", response = UploadPackageResponse.class)
153     @Consumes(MediaType.MULTIPART_FORM_DATA)
154     @Produces(MediaType.APPLICATION_JSON)
155     @ApiResponses(value = {
156             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
157             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
158             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
159     public Response reUploadPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
160             @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
161             @FormDataParam("params") String details,
162             @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
163             @ApiParam(value = "http header") @Context HttpHeaders head)
164     {
165         return PackageWrapper.getInstance().reUploadPackage(csarId, uploadedInputStream, fileDetail, details, head);
166     }
167
168     @Path("/csars/{csarId}/onboardstatus")
169     @GET
170     @ApiOperation(value = "Get VNF OnBoarding Result", response = OnBoardingResult.class)
171     @Produces(MediaType.APPLICATION_JSON)
172     public Response getOnBoardingResult(@ApiParam("csar Id") @PathParam("csarId") String csarId,
173             @ApiParam("operation type") @QueryParam("operTypeId") String operTypeId,
174             @ApiParam("operation id") @QueryParam("operId") String operId) {
175         return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
176     }
177
178     @Path("/csars/{csarId}/operresult")
179     @GET
180     @ApiOperation(value = "Get VNF OnBoarded Opeartion Result", response = Response.class)
181     @Produces(MediaType.APPLICATION_JSON)
182     public Response getOperStatus(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
183             @ApiParam(value = "operation type") @QueryParam("operTypeId") String operTypeId) {
184         return PackageWrapper.getInstance().getOperResultByOperTypeId(csarId, operTypeId);
185     }
186
187     @Path("/csars/onboardsteps")
188     @GET
189     @ApiOperation(value = "Get VNF OnBoarded Steps", response = Response.class)
190     @Produces(MediaType.APPLICATION_JSON)
191     public Response getOnBoardingSteps() {
192         return PackageWrapper.getInstance().getOnBoardingSteps();
193     }
194
195     @Path("/healthcheck")
196     @GET
197     @ApiOperation(value = "Health for VNF Repository", response = Response.class)
198     @Produces(MediaType.APPLICATION_JSON)
199     public Response healthCheck() {
200         if (ConnectionUtil.getSession() == null){
201             return Response.serverError().build();
202         }
203
204         return Response.ok().build();
205     }
206
207 }