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