From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../sdcrests/vsp/rest/VnfPackageRepository.java | 47 ++++++--------- .../rest/services/VnfPackageRepositoryImpl.java | 68 +++++++++------------- 2 files changed, 45 insertions(+), 70 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VnfPackageRepository.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VnfPackageRepository.java index 9617c61836..1412c332cb 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VnfPackageRepository.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VnfPackageRepository.java @@ -13,12 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.vsp.rest; import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.tags.Tags; import java.io.File; import javax.validation.constraints.NotNull; import javax.ws.rs.Consumes; @@ -30,15 +36,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.info.Info; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.tags.Tags; import org.openecomp.sdcrests.vendorsoftwareproducts.types.UploadFileResponseDto; import org.springframework.validation.annotation.Validated; @@ -52,31 +49,23 @@ public interface VnfPackageRepository extends VspEntities { @GET @Path("/vnfpackages") @Produces(MediaType.APPLICATION_OCTET_STREAM) - @Operation(description = "Get VNF packages from VNF Repository", - summary = "Call VNF Repository to get VNF package details", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = File.class)))) - Response getVnfPackages(@PathParam("vspId") String vspId, - @Parameter(description= "Version Id") @PathParam("versionId") String versionId, - @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user) throws Exception; + @Operation(description = "Get VNF packages from VNF Repository", summary = "Call VNF Repository to get VNF package details", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = File.class)))) + Response getVnfPackages(@PathParam("vspId") String vspId, @Parameter(description = "Version Id") @PathParam("versionId") String versionId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user) throws Exception; @GET @Path("/vnfpackage/{csarId}/download") @Produces(MediaType.APPLICATION_OCTET_STREAM) - @Operation(description = "Download VNF package from VNF Repository", - summary = "Download VNF package from VNF repository and send to client", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = File.class)))) - Response downloadVnfPackage(@PathParam("vspId") String vspId, - @Parameter(description = "Version Id") @PathParam("versionId") String versionId, - @PathParam("csarId") String csarId, - @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user) throws Exception; + @Operation(description = "Download VNF package from VNF Repository", summary = "Download VNF package from VNF repository and send to client", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = File.class)))) + Response downloadVnfPackage(@PathParam("vspId") String vspId, @Parameter(description = "Version Id") @PathParam("versionId") String versionId, + @PathParam("csarId") String csarId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user) throws Exception; @POST @Path("/vnfpackage/{csarId}/import") @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Import VNF package from VNF Repository", - summary = "Call VNF Repository to download VNF package, validate it and send the response", - responses = @ApiResponse(content = @Content(schema = @Schema(implementation = UploadFileResponseDto.class)))) - Response importVnfPackage(@PathParam("vspId") String vspId, - @Parameter(description = "Version Id") @PathParam("versionId") String versionId, - @PathParam("csarId") String csarId, - @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user) throws Exception; - + @Operation(description = "Import VNF package from VNF Repository", summary = "Call VNF Repository to download VNF package, validate it and send the response", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = UploadFileResponseDto.class)))) + Response importVnfPackage(@PathParam("vspId") String vspId, @Parameter(description = "Version Id") @PathParam("versionId") String versionId, + @PathParam("csarId") String csarId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user) throws Exception; } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java index 9ee86889f5..88ee6fa43d 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java @@ -14,9 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.vsp.rest.services; +import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION; +import static org.openecomp.core.utilities.file.FileUtils.getFileExtension; +import static org.openecomp.core.utilities.file.FileUtils.getNetworkPackageName; + import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.security.KeyManagementException; @@ -54,10 +57,6 @@ import org.openecomp.sdcrests.vsp.rest.mapping.MapUploadFileResponseToUploadFile import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; -import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION; -import static org.openecomp.core.utilities.file.FileUtils.getFileExtension; -import static org.openecomp.core.utilities.file.FileUtils.getNetworkPackageName; - /** * Enables integration API interface with VNF Repository (VNFSDK). *
    @@ -80,20 +79,23 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository { try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[]{new X509TrustManager() { - public void checkClientTrusted(X509Certificate[] c, String s) {} - public void checkServerTrusted(X509Certificate[] c, String s) {} - public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } - }}, new java.security.SecureRandom()); + public void checkClientTrusted(X509Certificate[] c, String s) { + } + + public void checkServerTrusted(X509Certificate[] c, String s) { + } - return ClientBuilder.newBuilder() - .sslContext(sslcontext) - .hostnameVerifier((a, b) -> true) - .build(); + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + }}, new java.security.SecureRandom()); + return ClientBuilder.newBuilder().sslContext(sslcontext).hostnameVerifier((a, b) -> true).build(); } catch (NoSuchAlgorithmException | KeyManagementException e) { LOGGER.error("Failed to initialize SSL unsecure context", e); } return ClientBuilder.newClient(); } + private final Configuration config; public VnfPackageRepositoryImpl(Configuration config) { @@ -120,35 +122,28 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository { public Response importVnfPackage(String vspId, String versionId, String csarId, String user) { LOGGER.debug("Import VNF Packages from Repository: {}", csarId); final String downloadPackageUri = String.format(config.getDownloadUri(), csarId); - Response remoteResponse = CLIENT.target(downloadPackageUri).request().get(); if (remoteResponse.getStatus() != Response.Status.OK.getStatusCode()) { return handleUnexpectedStatus("downloading VNF package", downloadPackageUri, remoteResponse); } - LOGGER.debug("Response from VNF Repository for download package is success. URI={}", downloadPackageUri); byte[] payload = remoteResponse.readEntity(String.class).getBytes(StandardCharsets.ISO_8859_1); return uploadVnfPackage(vspId, versionId, csarId, payload); } - private Response uploadVnfPackage(final String vspId, final String versionId, - final String csarId, final byte[] payload) { + private Response uploadVnfPackage(final String vspId, final String versionId, final String csarId, final byte[] payload) { try { - final OrchestrationTemplateCandidateManager candidateManager = - OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(); + final OrchestrationTemplateCandidateManager candidateManager = OrchestrationTemplateCandidateManagerFactory.getInstance() + .createInterface(); final String filename = formatFilename(csarId); final String fileExtension = getFileExtension(filename); - final OnboardPackageInfo onboardPackageInfo = - new OnboardPackageInfo(getNetworkPackageName(filename), fileExtension, ByteBuffer.wrap(payload), - OnboardingTypesEnum.getOnboardingTypesEnum(fileExtension)); + final OnboardPackageInfo onboardPackageInfo = new OnboardPackageInfo(getNetworkPackageName(filename), fileExtension, + ByteBuffer.wrap(payload), OnboardingTypesEnum.getOnboardingTypesEnum(fileExtension)); final VspDetails vspDetails = new VspDetails(vspId, getVersion(vspId, versionId)); final UploadFileResponse response = candidateManager.upload(vspDetails, onboardPackageInfo); - final UploadFileResponseDto uploadFileResponse = - new MapUploadFileResponseToUploadFileResponseDto() - .applyMapping(response, UploadFileResponseDto.class); - + final UploadFileResponseDto uploadFileResponse = new MapUploadFileResponseToUploadFileResponseDto() + .applyMapping(response, UploadFileResponseDto.class); return Response.ok(uploadFileResponse).build(); - } catch (final Exception e) { ErrorCode error = new GeneralErrorBuilder().build(); LOGGER.error("Exception while uploading package received from VNF Repository", new CoreException(error, e)); @@ -160,16 +155,13 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository { public Response downloadVnfPackage(String vspId, String versionId, String csarId, String user) { LOGGER.debug("Download VNF package from repository: csarId={}", csarId); final String downloadPackageUri = String.format(config.getDownloadUri(), csarId); - Response remoteResponse = CLIENT.target(downloadPackageUri).request().get(); if (remoteResponse.getStatus() != Response.Status.OK.getStatusCode()) { return handleUnexpectedStatus("downloading VNF package", downloadPackageUri, remoteResponse); } - byte[] payload = remoteResponse.readEntity(String.class).getBytes(StandardCharsets.ISO_8859_1); Response.ResponseBuilder response = Response.ok(payload); response.header(CONTENT_DISPOSITION, "attachment; filename=" + formatFilename(csarId)); - LOGGER.debug("Response from VNF Repository for download package is success. URI={}", downloadPackageUri); return response.build(); } @@ -184,15 +176,12 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository { } private static Response handleUnexpectedStatus(String action, String uri, Response response) { - ErrorCode error = new GeneralErrorBuilder().build(); - if (LOGGER.isErrorEnabled()) { String body = response.hasEntity() ? response.readEntity(String.class) : ""; - LOGGER.error("Unexpected response status while {}: URI={}, status={}, body={}", action, uri, - response.getStatus(), body, new CoreException(error)); + LOGGER.error("Unexpected response status while {}: URI={}, status={}, body={}", action, uri, response.getStatus(), body, + new CoreException(error)); } - return generateInternalServerError(error); } @@ -206,7 +195,9 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository { } interface Configuration { + String getGetUri(); + String getDownloadUri(); } @@ -225,16 +216,12 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository { private static class LazyFileConfiguration implements Configuration { private static final String CONFIG_NAMESPACE = "vnfrepo"; - private static final String DEFAULT_HOST = "localhost"; private static final String DEFAULT_PORT = "8702"; - private static final String DEFAULT_URI_PREFIX = "/onapapi/vnfsdk-marketplace/v1/PackageResource/csars"; private static final String DEFAULT_LIST_URI = DEFAULT_URI_PREFIX + "/"; private static final String DEFAULT_DOWNLOAD_URI = DEFAULT_URI_PREFIX + "/%s/files"; - private static final LazyFileConfiguration INSTANCE = new LazyFileConfiguration(); - private final String getUri; private final String downloadUri; @@ -253,8 +240,7 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository { String value = config.getAsString(CONFIG_NAMESPACE, key); return (value == null) ? defaultValue : value; } catch (Exception e) { - LOGGER.error("Failed to read VNF repository configuration key '{}', default value '{}' will be used", - key, defaultValue, e); + LOGGER.error("Failed to read VNF repository configuration key '{}', default value '{}' will be used", key, defaultValue, e); return defaultValue; } } -- cgit 1.2.3-korg