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.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 @Path("/PackageResource")
59 @Api(tags = { "Package Resource" })
60 public class PackageResource {
65 @Path("/updatestatus")
67 @ApiOperation(value = "update validate and lifecycle test status", response = UploadPackageResponse.class)
68 @Consumes(MediaType.APPLICATION_JSON)
69 @Produces(MediaType.APPLICATION_JSON)
70 @ApiResponses(value = {
71 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
72 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
73 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "update error", response = String.class) })
74 public Response updateValidateStatus(@ApiParam(value = "http request body") @Context HttpServletRequest request,
75 @ApiParam(value = "http header") @Context HttpHeaders head) throws IOException {
76 InputStream input = request.getInputStream();
77 return PackageWrapper.getInstance().updateValidateStatus(input);
83 @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class, responseContainer = "List")
84 @Produces(MediaType.APPLICATION_JSON)
85 @ApiResponses(value = {
86 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
87 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
88 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
89 public Response queryPackageListByCond(@ApiParam(value = "csar name") @QueryParam("name") String name,
90 @ApiParam(value = "csar provider") @QueryParam("provider") String provider,
91 @ApiParam(value = "csar version") @QueryParam("version") String version,
92 @ApiParam(value = "delay to delete") @QueryParam("deletionPending") String deletionPending,
93 @ApiParam(value = "csar type") @QueryParam("type") String type) {
94 return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version, deletionPending, type);
97 @Path("/csars/{csarId}")
99 @ApiOperation(value = "get csar package list", response = PackageMeta.class, responseContainer = "List")
100 @Produces(MediaType.APPLICATION_JSON)
101 @ApiResponses(value = {
102 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
103 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
104 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
105 public Response queryPackageById(@ApiParam(value = "csar id") @PathParam("csarId") String csarId) {
106 return PackageWrapper.getInstance().queryPackageById(csarId);
111 @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class)
112 @Consumes(MediaType.MULTIPART_FORM_DATA)
113 @Produces(MediaType.APPLICATION_JSON)
114 @ApiResponses(value = {
115 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
116 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
117 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
118 public Response uploadPackage(
119 @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
120 @FormDataParam("params") String details,
121 @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
122 @ApiParam(value = "http header") @Context HttpHeaders head)
123 throws IOException, MarketplaceResourceException {
124 return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, details, head);
127 @Path("/csars/{csarId}")
129 @ApiOperation(value = "delete a package")
130 @ApiResponses(value = {
131 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
132 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
133 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
134 public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
135 return PackageWrapper.getInstance().delPackage(csarId);
138 @Path("/csars/{csarId}/files")
140 @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class)
141 @Produces(MediaType.APPLICATION_JSON)
142 @ApiResponses(value = {
143 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
144 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
145 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
146 public Response getCsarFileUri(@ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId) {
147 return PackageWrapper.getInstance().getCsarFileUri(csarId);
150 @Path("/csars/{csarId}/downloaded")
152 @ApiOperation(value = "update download count for a package", response = Response.class)
153 public Response updateDwonloadCount(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
154 return PackageWrapper.getInstance().updateDwonloadCount(csarId);
157 @Path("/csars/{csarId}/reupload")
159 @ApiOperation(value = "re-upload csar package", response = UploadPackageResponse.class)
160 @Consumes(MediaType.MULTIPART_FORM_DATA)
161 @Produces(MediaType.APPLICATION_JSON)
162 @ApiResponses(value = {
163 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
164 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
165 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", response = String.class) })
166 public Response reUploadPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
167 @ApiParam(value = "file inputstream", required = true) @FormDataParam("file") InputStream uploadedInputStream,
168 @FormDataParam("params") String details,
169 @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
170 @ApiParam(value = "http header") @Context HttpHeaders head)
171 throws IOException, MarketplaceResourceException {
172 return PackageWrapper.getInstance().reUploadPackage(csarId, uploadedInputStream, fileDetail, details, head);
175 @Path("/csars/{csarId}/onboardstatus")
177 @ApiOperation(value = "Get VNF OnBoarding Result", response = OnBoardingResult.class)
178 @Produces(MediaType.APPLICATION_JSON)
179 public Response getOnBoardingResult(@ApiParam("csar Id") @PathParam("csarId") String csarId,
180 @ApiParam("operation type") @QueryParam("operTypeId") String operTypeId,
181 @ApiParam("operation id") @QueryParam("operId") String operId) {
182 return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
185 @Path("/csars/{csarId}/operresult")
187 @ApiOperation(value = "Get VNF OnBoarded Opeartion Result", response = Response.class)
188 @Produces(MediaType.APPLICATION_JSON)
189 public Response getOperStatus(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
190 @ApiParam(value = "operation type") @QueryParam("operTypeId") String operTypeId) {
191 return PackageWrapper.getInstance().getOperResultByOperTypeId(csarId, operTypeId);
194 @Path("/csars/onboardsteps")
196 @ApiOperation(value = "Get VNF OnBoarded Steps", response = Response.class)
197 @Produces(MediaType.APPLICATION_JSON)
198 public Response getOnBoardingSteps() {
199 return PackageWrapper.getInstance().getOnBoardingSteps();
202 @Path("/healthcheck")
204 @ApiOperation(value = "Health for VNF Repository", response = Response.class)
205 @Produces(MediaType.APPLICATION_JSON)
206 public Response healthCheck() {
208 // Step 1: Check whether tomcat server is up
209 RestResponse resp = RestfulClient.get("127.0.0.1", CommonConstant.HTTP_PORT, CommonConstant.BASE_URL);
210 if (RestConstant.RESPONSE_CODE_200 != resp.getStatusCode()) {
211 return Response.serverError().build();
214 // Step 2: Check whether postgres database is up
216 PackageManager.getInstance().queryPackageByCsarId("01");
217 } catch (Exception e) {
218 return Response.serverError().build();
221 return Response.ok().build();