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.
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.exception.MarketplaceResourceException;
41 import org.onap.vnfsdk.marketplace.db.resource.PackageManager;
42 import org.onap.vnfsdk.marketplace.entity.response.CsarFileUriResponse;
43 import org.onap.vnfsdk.marketplace.entity.response.PackageMeta;
44 import org.onap.vnfsdk.marketplace.entity.response.UploadPackageResponse;
45 import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
46 import org.onap.vnfsdk.marketplace.rest.RestConstant;
47 import org.onap.vnfsdk.marketplace.rest.RestResponse;
48 import org.onap.vnfsdk.marketplace.rest.RestfulClient;
49 import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper;
51 import io.swagger.annotations.Api;
52 import io.swagger.annotations.ApiOperation;
53 import io.swagger.annotations.ApiParam;
54 import io.swagger.annotations.ApiResponse;
55 import io.swagger.annotations.ApiResponses;
58 * csar package service.
62 @Path("/PackageResource")
63 @Api(tags = {"Package Resource"})
64 public class PackageResource {
66 @Path("/updatestatus")
68 @ApiOperation(value = "update validate and lifecycle test status", response = UploadPackageResponse.class)
69 @Consumes(MediaType.APPLICATION_JSON)
70 @Produces(MediaType.APPLICATION_JSON)
71 @ApiResponses(value = {
72 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
73 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
74 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "update error", response = String.class)})
75 public Response updateValidateStatus(@ApiParam(value = "http request body") @Context HttpServletRequest request,
76 @ApiParam(value = "http header") @Context HttpHeaders head) throws IOException {
77 InputStream input = request.getInputStream();
78 return PackageWrapper.getInstance().updateValidateStatus(input);
84 @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class, responseContainer = "List")
85 @Produces(MediaType.APPLICATION_JSON)
86 @ApiResponses(value = {
87 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
88 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
89 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class)})
90 public Response queryPackageListByCond(@ApiParam(value = "csar name") @QueryParam("name") String name,
91 @ApiParam(value = "csar provider") @QueryParam("provider") String provider,
92 @ApiParam(value = "csar version") @QueryParam("version") String version,
93 @ApiParam(value = "delay to delete") @QueryParam("deletionPending") String deletionPending,
94 @ApiParam(value = "csar type") @QueryParam("type") String type) {
95 return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version, deletionPending, type);
98 @Path("/csars/{csarId}")
100 @ApiOperation(value = "get csar package list", response = PackageMeta.class, responseContainer = "List")
101 @Produces(MediaType.APPLICATION_JSON)
102 @ApiResponses(value = {
103 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
104 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
105 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class)})
106 public Response queryPackageById(@ApiParam(value = "csar id") @PathParam("csarId") String csarId) {
107 return PackageWrapper.getInstance().queryPackageById(csarId);
112 @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class)
113 @Consumes(MediaType.MULTIPART_FORM_DATA)
114 @Produces(MediaType.APPLICATION_JSON)
115 @ApiResponses(value = {
116 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
117 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
118 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class)})
119 public Response uploadPackage(
120 @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
121 @FormDataParam("params") String details,
122 @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
123 @ApiParam(value = "http header") @Context HttpHeaders head)
124 throws IOException, MarketplaceResourceException {
125 return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, details, head);
128 @Path("/csars/{csarId}")
130 @ApiOperation(value = "delete a package")
131 @ApiResponses(value = {
132 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
133 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
134 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class)})
135 public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
136 return PackageWrapper.getInstance().delPackage(csarId);
139 @Path("/csars/{csarId}/files")
141 @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class)
142 @Produces(MediaType.APPLICATION_JSON)
143 @ApiResponses(value = {
144 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
145 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
146 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class)})
147 public Response getCsarFileUri(@ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId) {
148 return PackageWrapper.getInstance().getCsarFileUri(csarId);
151 @Path("/csars/{csarId}/downloaded")
153 @ApiOperation(value = "update download count for a package", response = Response.class)
154 public Response updateDwonloadCount(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
155 return PackageWrapper.getInstance().updateDwonloadCount(csarId);
158 @Path("/csars/{csarId}/reupload")
160 @ApiOperation(value = "re-upload csar package", response = UploadPackageResponse.class)
161 @Consumes(MediaType.MULTIPART_FORM_DATA)
162 @Produces(MediaType.APPLICATION_JSON)
163 @ApiResponses(value = {
164 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
165 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
166 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class)})
167 public Response reUploadPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
168 @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
169 @FormDataParam("params") String details,
170 @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
171 @ApiParam(value = "http header") @Context HttpHeaders head)
172 throws IOException, MarketplaceResourceException {
173 return PackageWrapper.getInstance().reUploadPackage(csarId, uploadedInputStream, fileDetail, details, head);
176 @Path("/csars/{csarId}/onboardstatus")
178 @ApiOperation(value = "Get VNF OnBoarding Result", response = OnBoardingResult.class)
179 @Produces(MediaType.APPLICATION_JSON)
180 public Response getOnBoardingResult(@ApiParam("csar Id") @PathParam("csarId") String csarId,
181 @ApiParam("operation type") @QueryParam("operTypeId") String operTypeId,
182 @ApiParam("operation id") @QueryParam("operId") String operId) {
183 return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
186 @Path("/csars/{csarId}/operresult")
188 @ApiOperation(value = "Get VNF OnBoarded Opeartion Result", response = Response.class)
189 @Produces(MediaType.APPLICATION_JSON)
190 public Response getOperStatus(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
191 @ApiParam(value = "operation type") @QueryParam("operTypeId") String operTypeId) {
192 return PackageWrapper.getInstance().getOperResultByOperTypeId(csarId, operTypeId);
195 @Path("/csars/onboardsteps")
197 @ApiOperation(value = "Get VNF OnBoarded Steps", response = Response.class)
198 @Produces(MediaType.APPLICATION_JSON)
199 public Response getOnBoardingSteps() {
200 return PackageWrapper.getInstance().getOnBoardingSteps();
203 @Path("/healthcheck")
205 @ApiOperation(value = "Health for VNF Repository", response = Response.class)
206 @Produces(MediaType.APPLICATION_JSON)
207 public Response healthCheck() {
209 // Step 1: Check whether tomcat server is up
210 RestResponse resp = RestfulClient.get("127.0.0.1", CommonConstant.HTTP_PORT, CommonConstant.BASE_URL);
211 if(RestConstant.RESPONSE_CODE_200 != resp.getStatusCode()) {
212 return Response.serverError().build();
215 // Step 2: Check whether postgres database is up
217 PackageManager.getInstance().queryPackageByCsarId("01");
218 } catch(Exception e) {
219 return Response.serverError().build();
222 return Response.ok().build();