aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model')
-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
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java1
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapperTest.java80
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CsarOperationTest.java112
-rw-r--r--catalog-model/src/test/resources/application-context-test.xml3
-rw-r--r--catalog-model/src/test/resources/config/catalog-model/configuration.yaml1
-rw-r--r--catalog-model/src/test/resources/config/configuration.yaml1
16 files changed, 677 insertions, 200 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;
- }
-}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java
index 929441cf01..28e17b5075 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java
@@ -26,6 +26,7 @@ import org.springframework.context.annotation.PropertySource;
@Configuration
@ComponentScan({"org.openecomp.sdc.be.dao.cassandra", "org.openecomp.sdc.be.model.cache",
+ "org.openecomp.sdc.be.client",
"org.openecomp.sdc.be.model.jsonjanusgraph.operations",
"org.openecomp.sdc.be.model.jsonjanusgraph.utils",
"org.openecomp.sdc.be.model.jsonjanusgraph.config",
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapperTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapperTest.java
new file mode 100644
index 0000000000..92b4c82376
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/mapper/VendorSoftwareProductMapperTest.java
@@ -0,0 +1,80 @@
+/*
+ * -
+ * ============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 static org.junit.jupiter.api.Assertions.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
+import org.openecomp.sdc.be.model.dto.VendorSoftwareProductDto;
+
+class VendorSoftwareProductMapperTest {
+
+ @Test
+ void mapFromSuccess() {
+ final var vendorSoftwareProductDto = new VendorSoftwareProductDto();
+ vendorSoftwareProductDto.setName("name");
+ vendorSoftwareProductDto.setDescription("description");
+ vendorSoftwareProductDto.setCategory("category");
+ vendorSoftwareProductDto.setSubCategory("subcategory");
+ vendorSoftwareProductDto.setVendorName("vendorName");
+ vendorSoftwareProductDto.setVendorId("vendorId");
+ vendorSoftwareProductDto.setSelectedModelList(List.of("model1", "model2"));
+ vendorSoftwareProductDto.setOnboardingMethod("onboardingMethod");
+ vendorSoftwareProductDto.setId("id");
+ vendorSoftwareProductDto.setVersionId("versionId");
+ vendorSoftwareProductDto.setOnboardingOrigin("onboardingOrigin");
+ vendorSoftwareProductDto.setNetworkPackageName("packageName");
+ final VendorSoftwareProduct vendorSoftwareProduct = VendorSoftwareProductMapper.mapFrom(vendorSoftwareProductDto);
+ assertVendorSoftwareProduct(vendorSoftwareProduct, vendorSoftwareProductDto);
+ }
+
+ @Test
+ void mapFromNullModelListShouldReturnEmptyModelList() {
+ final var vendorSoftwareProductDto = new VendorSoftwareProductDto();
+ vendorSoftwareProductDto.setSelectedModelList(null);
+ final VendorSoftwareProduct vendorSoftwareProduct = VendorSoftwareProductMapper.mapFrom(vendorSoftwareProductDto);
+ assertVendorSoftwareProduct(vendorSoftwareProduct, vendorSoftwareProductDto);
+ }
+
+ private void assertVendorSoftwareProduct(final VendorSoftwareProduct vendorSoftwareProduct,
+ final VendorSoftwareProductDto vendorSoftwareProductDto) {
+ assertEquals(vendorSoftwareProduct.getId(), vendorSoftwareProductDto.getId(), "id should be equals");
+ assertEquals(vendorSoftwareProduct.getName(), vendorSoftwareProductDto.getName(), "name should be equals");
+ assertEquals(vendorSoftwareProduct.getDescription(), vendorSoftwareProductDto.getDescription(), "description should be equals");
+ assertEquals(vendorSoftwareProduct.getCategory(), vendorSoftwareProductDto.getCategory(), "category should be equals");
+ assertEquals(vendorSoftwareProduct.getSubCategory(), vendorSoftwareProductDto.getSubCategory(), "subCategory should be equals");
+ assertEquals(vendorSoftwareProduct.getVendorName(), vendorSoftwareProductDto.getVendorName(), "vendorName should be equals");
+ assertEquals(vendorSoftwareProduct.getVendorId(), vendorSoftwareProductDto.getVendorId(), "vendorId should be equals");
+ assertEquals(vendorSoftwareProduct.getOnboardingMethod(), vendorSoftwareProductDto.getOnboardingMethod(), "onboardingMethod should be equals");
+ assertEquals(vendorSoftwareProduct.getOnboardingOrigin(), vendorSoftwareProductDto.getOnboardingOrigin(), "onboardingOrigin should be equals");
+ assertEquals(vendorSoftwareProduct.getVersionId(), vendorSoftwareProductDto.getVersionId(), "versionId should be equals");
+ assertEquals(vendorSoftwareProduct.getNetworkPackageName(), vendorSoftwareProductDto.getNetworkPackageName(), "networkPackageName should be equals");
+ if (vendorSoftwareProductDto.getSelectedModelList() == null) {
+ assertTrue(vendorSoftwareProduct.getModelList().isEmpty(), "modelList should be an empty list");
+ } else {
+ assertEquals(vendorSoftwareProduct.getModelList(), vendorSoftwareProductDto.getSelectedModelList(), "modelList should be equals");
+ }
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CsarOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CsarOperationTest.java
new file mode 100644
index 0000000000..fbed5936da
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CsarOperationTest.java
@@ -0,0 +1,112 @@
+/*
+ * -
+ * ============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.operations.impl;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+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;
+
+class CsarOperationTest {
+
+ @Mock
+ private OnboardingClient onboardingClient;
+
+ @InjectMocks
+ private CsarOperation csarOperation;
+
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ void findVspLatestPackageSuccessTest() {
+ final var csarUuid = "csarUuid";
+ var user = new User("userId");
+ final Map<String, byte[]> csarFileMap = new HashMap<>();
+ csarFileMap.put("test", "test".getBytes(StandardCharsets.UTF_8));
+ when(onboardingClient.findLatestPackage(csarUuid, user.getUserId())).thenReturn(Either.left(csarFileMap));
+ final Either<Map<String, byte[]>, StorageOperationStatus> vspLatestPackage = csarOperation.findVspLatestPackage(csarUuid, user);
+ assertTrue(vspLatestPackage.isLeft());
+ final Map<String, byte[]> actualCsarFileMap = vspLatestPackage.left().value();
+ assertEquals(csarFileMap, actualCsarFileMap);
+ }
+
+ @Test
+ void findVspLatestPackage_csarNotFoundTest() {
+ //given
+ final var vspId = "vspId";
+ var user = new User("userId");
+ //when
+ when(onboardingClient.findLatestPackage(vspId, user.getUserId())).thenReturn(Either.right(StorageOperationStatus.CSAR_NOT_FOUND));
+ final Either<Map<String, byte[]>, StorageOperationStatus> vspLatestPackage = csarOperation.findVspLatestPackage(vspId, user);
+ //then
+ assertTrue(vspLatestPackage.isRight());
+ final StorageOperationStatus storageOperationStatus = vspLatestPackage.right().value();
+ assertEquals(StorageOperationStatus.CSAR_NOT_FOUND, storageOperationStatus);
+ }
+
+ @Test
+ void findVspSuccessTest() {
+ //given
+ final var vspId = "vspId";
+ final var vspVersionId = "vspVersionId";
+ var user = new User("userId");
+ var vendorSoftwareProduct = new VendorSoftwareProduct();
+ vendorSoftwareProduct.setId(vspId);
+ vendorSoftwareProduct.setVersionId(vspVersionId);
+ //when
+ when(onboardingClient.findVendorSoftwareProduct(vspId, vspVersionId, user.getUserId())).thenReturn(Optional.of(vendorSoftwareProduct));
+ final Optional<VendorSoftwareProduct> vspOptional = csarOperation.findVsp(vspId, vspVersionId, user);
+ //then
+ assertTrue(vspOptional.isPresent());
+ assertEquals(vendorSoftwareProduct, vspOptional.get());
+ }
+
+ @Test
+ void findVsp_vspNotFoundTest() {
+ //given
+ final var vspId = "vspId";
+ final var vspVersionId = "vspVersionId";
+ var user = new User("userId");
+ //when
+ when(onboardingClient.findVendorSoftwareProduct(vspId, vspVersionId, user.getUserId())).thenReturn(Optional.empty());
+ final Optional<VendorSoftwareProduct> vspOptional = csarOperation.findVsp(vspId, vspVersionId, user);
+ //then
+ assertTrue(vspOptional.isEmpty());
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/test/resources/application-context-test.xml b/catalog-model/src/test/resources/application-context-test.xml
index dc9d5ba7bf..7f4ada2696 100644
--- a/catalog-model/src/test/resources/application-context-test.xml
+++ b/catalog-model/src/test/resources/application-context-test.xml
@@ -3,13 +3,14 @@
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
-
+
<context:component-scan
base-package="org.openecomp.sdc.be.model.operations.impl,
org.openecomp.sdc.be.model.jsonjanusgraph.operations,
org.openecomp.sdc.be.dao.jsongraph,
org.openecomp.sdc.be.model.cache,
+ org.openecomp.sdc.be.client,
org.openecomp.sdc.be.dao.janusgraph,
org.openecomp.sdc.be.dao.cassandra,
org.openecomp.sdc.be.model.jsonjanusgraph.utils,
diff --git a/catalog-model/src/test/resources/config/catalog-model/configuration.yaml b/catalog-model/src/test/resources/config/catalog-model/configuration.yaml
index 7d879260b1..3bb87991b2 100644
--- a/catalog-model/src/test/resources/config/catalog-model/configuration.yaml
+++ b/catalog-model/src/test/resources/config/catalog-model/configuration.yaml
@@ -266,7 +266,6 @@ onboarding:
protocol: http
host: localhost
port: 8080
- downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages"
healthCheckUri: "/onboarding-api/v1.0/healthcheck"
switchoverDetector:
diff --git a/catalog-model/src/test/resources/config/configuration.yaml b/catalog-model/src/test/resources/config/configuration.yaml
index 6705c54dbd..95695b7ce8 100644
--- a/catalog-model/src/test/resources/config/configuration.yaml
+++ b/catalog-model/src/test/resources/config/configuration.yaml
@@ -327,7 +327,6 @@ onboarding:
protocol: http
host: localhost
port: 8080
- downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages"
healthCheckUri: "/onboarding-api/v1.0/healthcheck"