summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-08-18 14:34:33 +0100
committerMichael Morris <michael.morris@est.tech>2021-08-26 12:13:58 +0000
commitaea64ba99fa9c9b51112b30aeb0872c4cdb89759 (patch)
tree8645ba4b820f8615e54ecd053f7232c2fcd7dca9 /catalog-model/src/main
parent5a0703ffad1492ec6b6c78143f63dca83ee030d2 (diff)
Validate the Resource Model before importing VSP
Validates the Resource Model selected during the Import VSP. This model must be aligned with one of the models that the imported VSP relates to. Fix VSP package retrieval to get the exact version from the VSP chosen during the Import VSP process. Introduces a client in the Catalog to retrieve from the Onboarding backend a VSP information using its Id and version Id. Change-Id: Ic8fb52b6daadc0e7203c81a9c15c3e46d5b9fffb Issue-ID: SDC-3675 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.java53
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/exception/OnboardingClientException.java33
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/impl/OnboardingClientImpl.java187
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java44
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/VendorSoftwareProduct.java47
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/VendorSoftwareProductDto.java47
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapper.java54
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java85
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java128
10 files changed, 482 insertions, 197 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
new file mode 100644
index 0000000000..34db17c4af
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/api/OnboardingClient.java
@@ -0,0 +1,53 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.client.onboarding.api;
+
+import fj.data.Either;
+import java.util.Map;
+import java.util.Optional;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public interface OnboardingClient {
+
+ /**
+ * Finds the CSAR package of the latest version of a Vendor Software Product (VSP) from the onboarding repository.
+ *
+ * @param vspId the VSP id
+ * @param userId the logged user id
+ * @return a Map containing the CSAR files <path, bytes> (left), or a StorageOperationStatus if an error occurs (right)
+ */
+ Either<Map<String, byte[]>, StorageOperationStatus> findLatestPackage(String vspId, String userId);
+
+ Either<Map<String, byte[]>, StorageOperationStatus> findPackage(String vspId, String versionId, String userId);
+
+ /**
+ * Finds the Vendor Software Product (VSP) from the onboarding repository.
+ *
+ * @param id the VSP id
+ * @param versionId the VSP version
+ * @param userId the logged user id
+ * @return a VSP representation if found, empty otherwise.
+ */
+ Optional<VendorSoftwareProduct> findVendorSoftwareProduct(String id, String versionId, String userId);
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/exception/OnboardingClientException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/exception/OnboardingClientException.java
new file mode 100644
index 0000000000..4564fcc234
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/exception/OnboardingClientException.java
@@ -0,0 +1,33 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.client.onboarding.exception;
+
+public class OnboardingClientException extends RuntimeException {
+
+ public OnboardingClientException(String message) {
+ super(message);
+ }
+
+ public OnboardingClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
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
new file mode 100644
index 0000000000..1aa6cd8157
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/client/onboarding/impl/OnboardingClientImpl.java
@@ -0,0 +1,187 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modification Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.client.onboarding.impl;
+
+import static javax.ws.rs.core.HttpHeaders.ACCEPT;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import fj.data.Either;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import javax.ws.rs.core.MediaType;
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.client.onboarding.api.OnboardingClient;
+import org.openecomp.sdc.be.client.onboarding.exception.OnboardingClientException;
+import org.openecomp.sdc.be.config.Configuration.OnboardingConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
+import org.openecomp.sdc.be.model.dto.VendorSoftwareProductDto;
+import org.openecomp.sdc.be.model.mapper.VendorSoftwareProductMapper;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.http.client.api.HttpRequest;
+import org.openecomp.sdc.common.http.client.api.HttpResponse;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.zip.ZipUtils;
+
+@org.springframework.stereotype.Component("onboarding-client")
+public class OnboardingClientImpl implements OnboardingClient {
+
+ private static final Logger LOGGER = Logger.getLogger(OnboardingClientImpl.class);
+ private final Properties downloadCsarHeaders;
+
+ public OnboardingClientImpl() {
+ downloadCsarHeaders = new Properties();
+ downloadCsarHeaders.put(ACCEPT, MediaType.APPLICATION_OCTET_STREAM);
+ }
+
+ @Override
+ public Either<Map<String, byte[]>, StorageOperationStatus> findLatestPackage(final String vspId, final String userId) {
+ final String url = buildGetLatestPackageUrl(vspId);
+ return handleGetPackage(userId, url);
+ }
+
+ @Override
+ public Either<Map<String, byte[]>, StorageOperationStatus> findPackage(final String vspId, final String versionId, final String userId) {
+ final String url = buildGetCsarUrl(vspId, versionId);
+ return handleGetPackage(userId, url);
+ }
+
+ private Either<Map<String, byte[]>, StorageOperationStatus> handleGetPackage(final String userId, final String url) {
+ final Properties headers = buildDefaultHeader(userId);
+ downloadCsarHeaders.forEach(headers::put);
+ LOGGER.debug("Get VSP package URL is '{}'. Used headers '{}'", url, headers);
+ try {
+ final HttpResponse<byte[]> httpResponse = HttpRequest.getAsByteArray(url, headers);
+ LOGGER.debug("'{}' HTTP response status was '{}'", url, httpResponse.getStatusCode());
+ switch (httpResponse.getStatusCode()) {
+ case HttpStatus.SC_OK:
+ byte[] data = httpResponse.getResponse();
+ if (data != null && data.length > 0) {
+ Map<String, byte[]> readZip = ZipUtils.readZip(data, false);
+ return Either.left(readZip);
+ }
+ LOGGER.debug("Empty payload received from '{}'", url);
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ case HttpStatus.SC_NOT_FOUND:
+ return Either.right(StorageOperationStatus.CSAR_NOT_FOUND);
+ default:
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ } catch (final Exception e) {
+ LOGGER.debug("Get VSP package request failed with exception", e);
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ }
+
+ @Override
+ public Optional<VendorSoftwareProduct> findVendorSoftwareProduct(final String id, final String versionId, final String userId) {
+ final Either<Map<String, byte[]>, StorageOperationStatus> csarEither = this.findPackage(id, versionId, 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 package with id '%s' and versionId '%s': '%s'",
+ id, versionId, operationStatus);
+ throw new OnboardingClientException(errorMsg);
+ }
+ final String url = buildGetVspUrl(id, versionId);
+ 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) {
+ headers.put(Constants.USER_ID_HEADER, userId);
+ }
+ return headers;
+ }
+
+ private String buildGetCsarUrl(final String vspId, final String versionId) {
+ final var onboardingConfig = getOnboardingConfig();
+ final var uri = String.format(onboardingConfig.getGetVspPackageUri(), vspId, versionId);
+ return buildBaseOnboardingUrl() + uri;
+ }
+
+ private String buildGetLatestPackageUrl(final String vspId) {
+ final var onboardingConfig = getOnboardingConfig();
+ final var uri = String.format(onboardingConfig.getGetLatestVspPackageUri(), vspId);
+ return buildBaseOnboardingUrl() + uri;
+ }
+
+ private String buildBaseOnboardingUrl() {
+ final var onboardingConfig = getOnboardingConfig();
+ final String protocol = onboardingConfig.getProtocol();
+ final String host = onboardingConfig.getHost();
+ final Integer port = onboardingConfig.getPort();
+ return String.format("%s://%s:%s", protocol, host, port);
+ }
+
+ private String buildGetVspUrl(final String id, final String versionId) {
+ 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.getGetVspUri(), id, versionId);
+ 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/config/CatalogModelSpringConfig.java b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
index a4d049d597..19914380a6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
@@ -29,6 +29,7 @@ import org.springframework.context.annotation.Configuration;
// @formatter:off
"org.openecomp.sdc.be.model.operations.impl",
"org.openecomp.sdc.be.model.cache",
+ "org.openecomp.sdc.be.client",
"org.openecomp.sdc.be.model.jsonjanusgraph.utils",
"org.openecomp.sdc.be.model.jsonjanusgraph.operations",
"org.openecomp.sdc.be.model.jsonjanusgraph.config",
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
index 51623a5bda..0b54e0bea7 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
@@ -66,70 +66,82 @@ public class Resource extends Component implements Serializable {
}
public Boolean isAbstract() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).isAbstract();
+ return getResourceMetadataDataDefinition().isAbstract();
}
public void setAbstract(Boolean isAbstract) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setAbstract(isAbstract);
+ getResourceMetadataDataDefinition().setAbstract(isAbstract);
}
public String getCost() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).getCost();
+ return getResourceMetadataDataDefinition().getCost();
}
public void setCost(String cost) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setCost(cost);
+ getResourceMetadataDataDefinition().setCost(cost);
}
public String getLicenseType() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).getLicenseType();
+ return getResourceMetadataDataDefinition().getLicenseType();
}
public void setLicenseType(String licenseType) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setLicenseType(licenseType);
+ getResourceMetadataDataDefinition().setLicenseType(licenseType);
}
public String getToscaResourceName() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName();
+ return getResourceMetadataDataDefinition().getToscaResourceName();
}
public void setToscaResourceName(String toscaResourceName) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setToscaResourceName(toscaResourceName);
+ getResourceMetadataDataDefinition().setToscaResourceName(toscaResourceName);
}
public ResourceTypeEnum getResourceType() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
+ return getResourceMetadataDataDefinition().getResourceType();
}
public void setResourceType(ResourceTypeEnum resourceType) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setResourceType(resourceType);
+ getResourceMetadataDataDefinition().setResourceType(resourceType);
}
public String getVendorName() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).getVendorName();
+ return getResourceMetadataDataDefinition().getVendorName();
}
public void setVendorName(String vendorName) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setVendorName(vendorName);
+ getResourceMetadataDataDefinition().setVendorName(vendorName);
}
public String getVendorRelease() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).getVendorRelease();
+ return getResourceMetadataDataDefinition().getVendorRelease();
}
public void setVendorRelease(String vendorRelease) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setVendorRelease(vendorRelease);
+ getResourceMetadataDataDefinition().setVendorRelease(vendorRelease);
}
public String getResourceVendorModelNumber() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceVendorModelNumber();
+ return getResourceMetadataDataDefinition().getResourceVendorModelNumber();
}
public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
+ getResourceMetadataDataDefinition()
.setResourceVendorModelNumber(resourceVendorModelNumber);
}
+ private ResourceMetadataDataDefinition getResourceMetadataDataDefinition() {
+ return (ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition();
+ }
+
+ public String getCsarVersionId() {
+ return getResourceMetadataDataDefinition().getCsarVersionId();
+ }
+
+ public void setCsarVersionId(String csarVersionId) {
+ getResourceMetadataDataDefinition().setCsarVersionId(csarVersionId);
+ }
+
@Override
public String fetchGenericTypeToscaNameFromConfig() {
return fetchToscaNameFromConfigBasedOnCategory().orElse(fetchToscaNameFromConfigBasedOnAssetType());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/VendorSoftwareProduct.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/VendorSoftwareProduct.java
new file mode 100644
index 0000000000..4dc4469ad4
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/VendorSoftwareProduct.java
@@ -0,0 +1,47 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model;
+
+import java.util.List;
+import java.util.Map;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class VendorSoftwareProduct {
+
+ private String name;
+ private String description;
+ private String category;
+ private String subCategory;
+ private String vendorName;
+ private String vendorId;
+ private List<String> modelList;
+ private String onboardingMethod;
+ private String id;
+ private String versionId;
+ private String onboardingOrigin;
+ private String networkPackageName;
+ private Map<String, byte[]> fileMap;
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/VendorSoftwareProductDto.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/VendorSoftwareProductDto.java
new file mode 100644
index 0000000000..39e070c1d3
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/VendorSoftwareProductDto.java
@@ -0,0 +1,47 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+import lombok.Data;
+
+@Data
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class VendorSoftwareProductDto {
+
+ private String name;
+ private String description;
+ private String category;
+ private String subCategory;
+ private String vendorName;
+ private String vendorId;
+ private List<String> selectedModelList;
+ private String onboardingMethod;
+ private String id;
+ @JsonProperty("version")
+ private String versionId;
+ private String onboardingOrigin;
+ private String networkPackageName;
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapper.java
new file mode 100644
index 0000000000..0cc4add887
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapper.java
@@ -0,0 +1,54 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.mapper;
+
+import java.util.ArrayList;
+import java.util.Objects;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
+import org.openecomp.sdc.be.model.dto.VendorSoftwareProductDto;
+
+public class VendorSoftwareProductMapper {
+
+ private VendorSoftwareProductMapper() {
+ }
+
+ public static VendorSoftwareProduct mapFrom(final VendorSoftwareProductDto vendorSoftwareProductDto) {
+ Objects.requireNonNull(vendorSoftwareProductDto);
+ final var vendorSoftwareProduct = new VendorSoftwareProduct();
+ vendorSoftwareProduct.setName(vendorSoftwareProductDto.getName());
+ vendorSoftwareProduct.setDescription(vendorSoftwareProductDto.getDescription());
+ vendorSoftwareProduct.setCategory(vendorSoftwareProductDto.getCategory());
+ vendorSoftwareProduct.setSubCategory(vendorSoftwareProductDto.getSubCategory());
+ vendorSoftwareProduct.setVendorName(vendorSoftwareProductDto.getVendorName());
+ vendorSoftwareProduct.setVendorId(vendorSoftwareProductDto.getVendorId());
+ vendorSoftwareProduct.setModelList(
+ vendorSoftwareProductDto.getSelectedModelList() == null ? new ArrayList<>() : vendorSoftwareProductDto.getSelectedModelList());
+ vendorSoftwareProduct.setOnboardingMethod(vendorSoftwareProductDto.getOnboardingMethod());
+ vendorSoftwareProduct.setId(vendorSoftwareProductDto.getId());
+ vendorSoftwareProduct.setVersionId(vendorSoftwareProductDto.getVersionId());
+ vendorSoftwareProduct.setOnboardingOrigin(vendorSoftwareProductDto.getOnboardingOrigin());
+ vendorSoftwareProduct.setNetworkPackageName(vendorSoftwareProductDto.getNetworkPackageName());
+ return vendorSoftwareProduct;
+ }
+
+
+}
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 7b40aa012c..bcdcb0e6d1 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
@@ -19,80 +19,59 @@
*/
package org.openecomp.sdc.be.model.operations.impl;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
import fj.data.Either;
import java.util.Map;
-import javax.annotation.PostConstruct;
+import java.util.Optional;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.sdc.be.client.onboarding.api.OnboardingClient;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
@org.springframework.stereotype.Component("csar-operation")
public class CsarOperation {
- private static final Logger log = Logger.getLogger(CsarOperation.class.getName());
- @javax.annotation.Resource
- private OnboardingClient onboardingClient;
+ private static final Logger LOGGER = Logger.getLogger(CsarOperation.class.getName());
- @PostConstruct
- public void init() {
+ private final OnboardingClient onboardingClient;
+
+ @Autowired
+ public CsarOperation(final OnboardingClient onboardingClient) {
+ this.onboardingClient = onboardingClient;
}
/**
- * get csar from remote repository
+ * Finds the CSAR package of the latest version of a Vendor Software Product (VSP) from the onboarding repository.
*
- * @param csarUuid
- * @return
+ * @param csarUuid the VSP id
+ * @param user the logged user
+ * @return a Map containing the CSAR files <path, bytes> (left), or a StorageOperationStatus if an error occurs (right)
*/
- public Either<Map<String, byte[]>, StorageOperationStatus> getCsar(String csarUuid, User user) {
- Either<Map<String, byte[]>, StorageOperationStatus> result = onboardingClient.getCsar(csarUuid, user.getUserId());
+ public Either<Map<String, byte[]>, StorageOperationStatus> findVspLatestPackage(String csarUuid, User user) {
+ final Either<Map<String, byte[]>, StorageOperationStatus> result = onboardingClient.findLatestPackage(csarUuid, user.getUserId());
if (result.isRight()) {
- log.debug("Cannot find csar {}. Staus returned is {}", csarUuid, result.right().value());
- } else {
- Map<String, byte[]> values = result.left().value();
- if (values != null) {
- log.debug("The returned files are {}", values.keySet());
- }
+ LOGGER.debug("Could not find VSP Package '{}'. Status '{}'", csarUuid, result.right().value());
+ return result;
}
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public Either<String, StorageOperationStatus> getCsarLatestVersion(String csarUuid, User user) {
- Either<String, StorageOperationStatus> result = onboardingClient.getPackages(user.getUserId());
- if (result.isRight()) {
- log.debug("Cannot find version for package with Id {}. Status returned is {}", csarUuid, result.right().value());
- } else {
- String latestVersion = null;
- JsonElement root = new JsonParser().parse(result.left().value());
- JsonArray csarsInfo = root.getAsJsonObject().get("results").getAsJsonArray();
- for (JsonElement csarInfo : csarsInfo) {
- Map<String, String> csarInfoMap = new Gson().fromJson(csarInfo, Map.class);
- if (csarInfoMap.get("packageId").equals(csarUuid)) {
- String curVersion = csarInfoMap.get("version");
- if (latestVersion == null || isGreater(latestVersion, curVersion)) {
- latestVersion = curVersion;
- }
- }
- }
- if (latestVersion != null) {
- result = Either.left(latestVersion);
- } else {
- log.debug("The returned packages are {}. Failed to find latest version for package with Id {}. ", result.left().value(), csarUuid);
- result = Either.right(StorageOperationStatus.NOT_FOUND);
- }
+ if (MapUtils.isNotEmpty(result.left().value())) {
+ final Map<String, byte[]> values = result.left().value();
+ LOGGER.debug("The returned files are {}", values.keySet());
}
return result;
}
- private boolean isGreater(String latestVersion, String currentVersion) {
- return Double.parseDouble(latestVersion) < Double.parseDouble(currentVersion);
+ /**
+ * Finds the Vendor Software Product (VSP) from the onboarding repository.
+ *
+ * @param id the VSP id
+ * @param versionId the VSP version
+ * @param user the logged user
+ * @return a VSP representation if found, empty otherwise.
+ */
+ public Optional<VendorSoftwareProduct> findVsp(final String id, final String versionId, final User user) {
+ return onboardingClient.findVendorSoftwareProduct(id, versionId, user.getUserId());
}
- public OnboardingClient getOnboardingClient() {
- return onboardingClient;
- }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java
deleted file mode 100644
index 6032b4ad2e..0000000000
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.sdc.be.model.operations.impl;
-
-import fj.data.Either;
-import java.util.Map;
-import java.util.Properties;
-import lombok.NoArgsConstructor;
-import org.apache.http.HttpStatus;
-import org.openecomp.sdc.be.config.Configuration.OnboardingConfig;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.http.client.api.HttpRequest;
-import org.openecomp.sdc.common.http.client.api.HttpResponse;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.zip.ZipUtils;
-
-@NoArgsConstructor
-@org.springframework.stereotype.Component("onboarding-client")
-public class OnboardingClient {
-
- private static final Logger log = Logger.getLogger(OnboardingClient.class.getName());
- private static Properties downloadCsarHeaders = new Properties();
-
- static {
- downloadCsarHeaders.put("Accept", "application/octet-stream");
- }
-
- public Either<Map<String, byte[]>, StorageOperationStatus> getCsar(String csarUuid, String userId) {
- String url = buildDownloadCsarUrl() + "/" + csarUuid;
- Properties headers = new Properties();
- if (downloadCsarHeaders != null) {
- downloadCsarHeaders.forEach(headers::put);
- }
- if (userId != null) {
- headers.put(Constants.USER_ID_HEADER, userId);
- }
- log.debug("Url for downloading csar is {}. Headers are {}", url, headers);
- try {
- HttpResponse<byte[]> httpResponse = HttpRequest.getAsByteArray(url, headers);
- log.debug("After fetching csar {}. Http return code is {}", csarUuid, httpResponse.getStatusCode());
- switch (httpResponse.getStatusCode()) {
- case HttpStatus.SC_OK:
- byte[] data = httpResponse.getResponse();
- if (data != null && data.length > 0) {
- Map<String, byte[]> readZip = ZipUtils.readZip(data, false);
- return Either.left(readZip);
- } else {
- log.debug("Data received from rest is null or empty");
- return Either.right(StorageOperationStatus.NOT_FOUND);
- }
- case HttpStatus.SC_NOT_FOUND:
- return Either.right(StorageOperationStatus.CSAR_NOT_FOUND);
- default:
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- } catch (Exception e) {
- log.debug("Request failed with exception", e);
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- }
-
- public Either<String, StorageOperationStatus> getPackages(String userId) {
- String url = buildDownloadCsarUrl();
- Properties headers = new Properties();
- headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
-
- if (userId != null) {
- headers.put(Constants.USER_ID_HEADER, userId);
- }
-
- log.debug("Url for downloading packages is {}. Headers are {}", url, headers);
-
- try {
- HttpResponse<String> httpResposne = HttpRequest.get(url, headers);
- log.debug("After fetching packages. Http return code is {}", httpResposne.getStatusCode());
-
- switch (httpResposne.getStatusCode()) {
- case HttpStatus.SC_OK:
- String data = httpResposne.getResponse();
- return Either.left(data);
-
- case HttpStatus.SC_NOT_FOUND:
- return Either.right(StorageOperationStatus.CSAR_NOT_FOUND);
-
- default:
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- } catch (Exception e) {
- log.debug("Request failed with exception", e);
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- }
-
- /**
- * Build the url for download CSAR
- * <p>
- * E.g., http://0.0.0.0:8181/onboarding-api/v1.0/vendor-software-products/packages/
- *
- * @return
- */
- public String buildDownloadCsarUrl() {
- OnboardingConfig onboardingConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getOnboarding();
- String protocol = onboardingConfig.getProtocol();
- String host = onboardingConfig.getHost();
- Integer port = onboardingConfig.getPort();
- String uri = onboardingConfig.getDownloadCsarUri();
- return protocol + "://" + host + ":" + port + uri;
- }
-}