summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-09-17 15:48:43 +0100
committerandre.schmid <andre.schmid@est.tech>2021-09-17 16:19:57 +0100
commitd6b83fce723703f4dea0bce3675ecbf6996aaf9a (patch)
tree4c8e463a3f24cefdd18e3bb28a8573f7fae4f15b /catalog-model/src/main
parentb3fca719b446b6ad72d723e0043219b249ab5752 (diff)
Fix Update VSP when no version id is provided
Issue-ID: SDC-3730 Change-Id: Ic5a5a6ecf3b6775e022be649145e44b0907cbecf Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/api/OnboardingClient.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/impl/OnboardingClientImpl.java56
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java4
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());
+ }
+
}