/**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
import org.onap.aai.modelloader.entity.model.IModelParser;
import org.onap.aai.modelloader.entity.model.NamedQueryArtifactParser;
import org.onap.aai.modelloader.extraction.InvalidArchiveException;
+import org.onap.aai.modelloader.extraction.VnfCatalogExtractor;
import org.onap.aai.modelloader.restclient.BabelServiceClient;
import org.onap.aai.modelloader.restclient.BabelServiceClientException;
import org.onap.aai.modelloader.service.BabelServiceClientFactory;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.utils.ArtifactTypeEnum;
import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.springframework.stereotype.Component;
/**
* This class is responsible for downloading the artifacts from the ASDC.
*
* TOSCA_CSAR file artifacts will be converted into XML and returned as model artifacts.
*/
+@Component
public class ArtifactDownloadManager {
private static Logger logger = LoggerFactory.getInstance().getLogger(ArtifactDownloadManager.class);
- private IDistributionClient client;
- private NotificationPublisher notificationPublisher;
- private BabelArtifactConverter babelArtifactConverter;
- private ModelLoaderConfig config;
- private BabelServiceClientFactory clientFactory;
+ private final IDistributionClient client;
+ private final NotificationPublisher notificationPublisher;
+ private final BabelArtifactConverter babelArtifactConverter;
+ private final ModelLoaderConfig config;
+ private final BabelServiceClientFactory clientFactory;
+ private final VnfCatalogExtractor vnfCatalogExtractor;
public ArtifactDownloadManager(IDistributionClient client, ModelLoaderConfig config,
- BabelServiceClientFactory clientFactory) {
+ BabelServiceClientFactory clientFactory, BabelArtifactConverter babelArtifactConverter, NotificationPublisher notificationPublisher, VnfCatalogExtractor vnfCatalogExtractor) {
this.client = client;
+ this.notificationPublisher = notificationPublisher;
+ this.babelArtifactConverter = babelArtifactConverter;
this.config = config;
this.clientFactory = clientFactory;
+ this.vnfCatalogExtractor = vnfCatalogExtractor;
}
/**
IDistributionClientDownloadResult downloadResult = downloadIndividualArtifacts(data, artifact);
processDownloadedArtifacts(modelArtifacts, catalogArtifacts, artifact, downloadResult, data);
} catch (DownloadFailureException e) {
- getNotificationPublisher().publishDownloadFailure(client, data, artifact, e.getMessage());
+ notificationPublisher.publishDownloadFailure(client, data, artifact, e.getMessage());
success = false;
} catch (Exception e) {
- getNotificationPublisher().publishDeployFailure(client, data, artifact);
+ notificationPublisher.publishDeployFailure(client, data, artifact);
success = false;
}
if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult())) {
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Downloaded artifact: " + artifact.getArtifactName());
- getNotificationPublisher().publishDownloadSuccess(client, data, artifact);
+ notificationPublisher.publishDownloadSuccess(client, data, artifact);
} else {
throw new DownloadFailureException(downloadResult.getDistributionMessageResult());
}
}
public void processToscaArtifacts(List<Artifact> modelArtifacts, List<Artifact> catalogArtifacts, byte[] payload,
+ IArtifactInfo artifactInfo, String distributionId, String serviceVersion)
+ throws ProcessToscaArtifactsException, InvalidArchiveException {
+ // Get translated artifacts from Babel Service
+ invokeBabelService(modelArtifacts, catalogArtifacts, payload, artifactInfo, distributionId, serviceVersion);
+
+ // Get VNF Catalog artifacts directly from CSAR
+ List<Artifact> csarCatalogArtifacts = vnfCatalogExtractor.extract(payload, artifactInfo.getArtifactName());
+
+ // Throw an error if VNF Catalog data is present in the Babel payload and directly in the CSAR
+ if (!catalogArtifacts.isEmpty() && !csarCatalogArtifacts.isEmpty()) {
+ logger.error(ModelLoaderMsgs.DUPLICATE_VNFC_DATA_ERROR, artifactInfo.getArtifactName());
+ throw new InvalidArchiveException("CSAR: " + artifactInfo.getArtifactName()
+ + " contains VNF Catalog data in the format of both TOSCA and XML files. Only one format can be used for each CSAR file.");
+ } else if (!csarCatalogArtifacts.isEmpty()) {
+ catalogArtifacts.addAll(csarCatalogArtifacts);
+ }
+ }
+
+ public void invokeBabelService(List<Artifact> modelArtifacts, List<Artifact> catalogArtifacts, byte[] payload,
IArtifactInfo artifactInfo, String distributionId, String serviceVersion)
throws ProcessToscaArtifactsException {
try {
BabelServiceClient babelClient = createBabelServiceClient(artifactInfo, serviceVersion);
- logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT,
- "Posting artifact: " + artifactInfo.getArtifactName() + ", version: " + serviceVersion);
+ logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
+ "Posting artifact: " + artifactInfo.getArtifactName() + ", service version: " + serviceVersion
+ + ", artifact version: " + artifactInfo.getArtifactVersion());
List<BabelArtifact> babelArtifacts =
babelClient.postArtifact(payload, artifactInfo.getArtifactName(), serviceVersion, distributionId);
if (artifactMap.containsKey(BabelArtifact.ArtifactType.MODEL)) {
modelArtifacts.addAll(
- getBabelArtifactConverter().convertToModel(artifactMap.get(BabelArtifact.ArtifactType.MODEL)));
+ babelArtifactConverter.convertToModel(artifactMap.get(BabelArtifact.ArtifactType.MODEL)));
artifactMap.remove(BabelArtifact.ArtifactType.MODEL);
}
if (artifactMap.containsKey(BabelArtifact.ArtifactType.VNFCATALOG)) {
- catalogArtifacts.addAll(getBabelArtifactConverter()
+ catalogArtifacts.addAll(babelArtifactConverter
.convertToCatalog(artifactMap.get(BabelArtifact.ArtifactType.VNFCATALOG)));
artifactMap.remove(BabelArtifact.ArtifactType.VNFCATALOG);
}
private boolean parsedArtifactsExist(List<Artifact> parsedArtifacts) {
return parsedArtifacts != null && !parsedArtifacts.isEmpty();
}
-
- private NotificationPublisher getNotificationPublisher() {
- if (notificationPublisher == null) {
- notificationPublisher = new NotificationPublisher();
- }
-
- return notificationPublisher;
- }
-
- private BabelArtifactConverter getBabelArtifactConverter() {
- if (babelArtifactConverter == null) {
- babelArtifactConverter = new BabelArtifactConverter();
- }
-
- return babelArtifactConverter;
- }
}