diff options
Diffstat (limited to 'catalog-model/src')
3 files changed, 69 insertions, 0 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/api/OnboardingClient.java b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/api/OnboardingClient.java index 34db17c4af..1abb1bf08a 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/api/OnboardingClient.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/api/OnboardingClient.java @@ -50,4 +50,13 @@ public interface OnboardingClient { */ Optional<VendorSoftwareProduct> findVendorSoftwareProduct(String id, String versionId, String userId); + /** + * Finds the latest version of the Vendor Software Product (VSP) from the onboarding repository. + * + * @param id the VSP id + * @param userId the logged user id + * @return a VSP representation if found, empty otherwise. + */ + Optional<VendorSoftwareProduct> findLatestVendorSoftwareProduct(String id, String userId); + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/impl/OnboardingClientImpl.java b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/impl/OnboardingClientImpl.java index 1aa6cd8157..ebc9996975 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/impl/OnboardingClientImpl.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/impl/OnboardingClientImpl.java @@ -143,6 +143,53 @@ public class OnboardingClientImpl implements OnboardingClient { return Optional.of(vendorSoftwareProduct); } + @Override + public Optional<VendorSoftwareProduct> findLatestVendorSoftwareProduct(final String id, final String userId) { + final Either<Map<String, byte[]>, StorageOperationStatus> csarEither = this.findLatestPackage(id, userId); + if (csarEither.isRight()) { + final StorageOperationStatus operationStatus = csarEither.right().value(); + if (operationStatus == StorageOperationStatus.CSAR_NOT_FOUND || operationStatus == StorageOperationStatus.NOT_FOUND) { + return Optional.empty(); + } + var errorMsg = String.format("An error has occurred while retrieving the latest package with for '%s': '%s'", + id, operationStatus); + throw new OnboardingClientException(errorMsg); + } + final String url = buildGetLatestVspUrl(id); + final Properties headers = buildDefaultHeader(userId); + headers.put(ACCEPT, APPLICATION_JSON); + LOGGER.debug("Find VSP built url '{}', with headers '{}'", url, headers); + final HttpResponse<String> httpResponse; + try { + httpResponse = HttpRequest.get(url, headers); + } catch (final Exception e) { + throw new OnboardingClientException("An error has occurred while retrieving the package", e); + } + + if (httpResponse.getStatusCode() == HttpStatus.SC_NOT_FOUND) { + return Optional.empty(); + } + + if (httpResponse.getStatusCode() != HttpStatus.SC_OK) { + var errorMsg = String.format("An error has occurred while retrieving the package. Http status was %s", httpResponse.getStatusCode()); + throw new OnboardingClientException(errorMsg); + } + + final String responseData = httpResponse.getResponse(); + LOGGER.debug("Find vsp response data: '{}'", responseData); + + final VendorSoftwareProductDto vendorSoftwareProductDto; + try { + vendorSoftwareProductDto = new ObjectMapper().readValue(responseData, VendorSoftwareProductDto.class); + } catch (final JsonProcessingException e) { + throw new OnboardingClientException("Could not parse retrieve package response to VendorSoftwareProductDto.class.", e); + } + final Map<String, byte[]> csarFileMap = csarEither.left().value(); + final var vendorSoftwareProduct = VendorSoftwareProductMapper.mapFrom(vendorSoftwareProductDto); + vendorSoftwareProduct.setFileMap(csarFileMap); + return Optional.of(vendorSoftwareProduct); + } + private Properties buildDefaultHeader(final String userId) { final var headers = new Properties(); if (userId != null) { @@ -180,6 +227,15 @@ public class OnboardingClientImpl implements OnboardingClient { return String.format("%s://%s:%s%s", protocol, host, port, uri); } + private String buildGetLatestVspUrl(final String id) { + final var onboardingConfig = getOnboardingConfig(); + final String protocol = onboardingConfig.getProtocol(); + final String host = onboardingConfig.getHost(); + final Integer port = onboardingConfig.getPort(); + final var uri = String.format(onboardingConfig.getGetLatestVspUri(), id); + return String.format("%s://%s:%s%s", protocol, host, port, uri); + } + private OnboardingConfig getOnboardingConfig() { return ConfigurationManager.getConfigurationManager().getConfiguration().getOnboarding(); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java index bcdcb0e6d1..5a90bb8382 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java @@ -74,4 +74,8 @@ public class CsarOperation { return onboardingClient.findVendorSoftwareProduct(id, versionId, user.getUserId()); } + public Optional<VendorSoftwareProduct> findLatestVsp(final String id, final User user) { + return onboardingClient.findLatestVendorSoftwareProduct(id, user.getUserId()); + } + } |