summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java6
-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
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java1
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java6
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java9
8 files changed, 91 insertions, 1 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
index 60616c2709..118b48d04b 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
@@ -948,6 +948,7 @@ onboarding:
getVspPackageUri: "/onboarding-api/v1.0/vendor-software-products/packages/%s?versionId=%s" # /onboarding-api/v1.0/vendor-software-products/packages/:vspId?versionId=:vspVersionId
getLatestVspPackageUri: "/onboarding-api/v1.0/vendor-software-products/packages/%s" # /onboarding-api/v1.0/vendor-software-products/packages/:vspId
getVspUri: "/onboarding-api/v1.0/vendor-software-products/%s/versions/%s" # /onboarding-api/v1.0/vendor-software-products/:vspId/versions/:vspVersionId
+ getLatestVspUri: "/onboarding-api/v1.0/vendor-software-products/%s" # /onboarding-api/v1.0/vendor-software-products/:vspId
healthCheckUri: "/onboarding-api/v1.0/healthcheck"
# #GSS IDNS
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
index b8a5d67d4a..a85b5542a0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
@@ -223,7 +223,11 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
private VendorSoftwareProduct getCsar(final Resource resource, final User user) {
final Optional<VendorSoftwareProduct> vendorSoftwareProductOpt;
try {
- vendorSoftwareProductOpt = csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user);
+ if (resource.getCsarVersionId() == null) {
+ vendorSoftwareProductOpt = csarOperation.findLatestVsp(resource.getCsarUUID(), user);
+ } else {
+ vendorSoftwareProductOpt = csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user);
+ }
} catch (final Exception exception) {
log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, CsarBusinessLogic.class.getName(), exception.getMessage());
auditGetCsarError(resource, user, resource.getCsarUUID(), StorageOperationStatus.GENERAL_ERROR);
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());
+ }
+
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
index 96688ce5a8..9b3772f4fc 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
@@ -351,6 +351,7 @@ public class Configuration extends BasicConfiguration {
private String getLatestVspPackageUri;
private String getVspPackageUri;
private String getVspUri;
+ private String getLatestVspUri;
@ToString.Exclude
private String healthCheckUri;
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java
index 328c96254f..fbe7d371ca 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java
@@ -76,6 +76,12 @@ public interface VendorSoftwareProducts extends VspEntities {
@NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user);
@GET
+ @Path("/{vspId}")
+ @Parameter(description = "Get details of the latest certified vendor software product")
+ Response getLatestVsp(@PathParam("vspId") String vspId,
+ @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user);
+
+ @GET
@Path("/{vspId}/versions/{versionId}")
@Parameter(description = "Get details of a vendor software product")
Response getVsp(@PathParam("vspId") String vspId, @PathParam("versionId") String versionId,
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
index 5367e1ea75..76e3f674dd 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
@@ -208,6 +208,15 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
return Response.ok(vspDetailsDto).build();
}
+ @Override
+ public Response getLatestVsp(final String vspId, final String user) {
+ final List<Version> versions = versioningManager.list(vspId);
+ final Version version = versions.stream().filter(ver -> VersionStatus.Certified == ver.getStatus())
+ .max(Comparator.comparingDouble(o -> Double.parseDouble(o.getName())))
+ .orElseThrow(() -> new CoreException(new PackageNotFoundErrorBuilder(vspId).build()));
+ return getVsp(vspId, version.getId(), user);
+ }
+
private void submitHealedVersion(VspDetails vspDetails, String baseVersionId, String user) {
try {
if (vspDetails.getVlmVersion() != null) {