X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fmodel-loader.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fnotification%2FArtifactDownloadManager.java;h=58bb074ca19b6315be7b08c18f8bac72342802dc;hp=febc99a3b4583bc7ec1aca28759f05854492325e;hb=7e6fe8c29c5a5cfa5caf6ab47b30280e1fc20432;hpb=c5aea4a8bc398fc1c6220875e55b9520fd7f7524 diff --git a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java index febc99a..58bb074 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java +++ b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java @@ -1,5 +1,5 @@ /** - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. @@ -38,6 +38,7 @@ import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; 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; @@ -68,6 +69,7 @@ public class ArtifactDownloadManager { private BabelArtifactConverter babelArtifactConverter; private ModelLoaderConfig config; private BabelServiceClientFactory clientFactory; + private VnfCatalogExtractor vnfCatalogExtractor; public ArtifactDownloadManager(IDistributionClient client, ModelLoaderConfig config, BabelServiceClientFactory clientFactory) { @@ -148,13 +150,33 @@ public class ArtifactDownloadManager { } public void processToscaArtifacts(List modelArtifacts, List 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 csarCatalogArtifacts = getVnfCatalogExtractor().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 modelArtifacts, List 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 babelArtifacts = babelClient.postArtifact(payload, artifactInfo.getArtifactName(), serviceVersion, distributionId); @@ -251,4 +273,12 @@ public class ArtifactDownloadManager { return babelArtifactConverter; } + + private VnfCatalogExtractor getVnfCatalogExtractor() { + if (vnfCatalogExtractor == null) { + vnfCatalogExtractor = new VnfCatalogExtractor(); + } + + return vnfCatalogExtractor; + } }