- public void processToscaArtifacts(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);
-
- List<BabelArtifact> babelArtifacts =
- babelClient.postArtifact(payload, artifactInfo.getArtifactName(), serviceVersion, distributionId);
-
- // Sort Babel artifacts based on type
- Map<ArtifactType, List<BabelArtifact>> artifactMap =
- babelArtifacts.stream().collect(Collectors.groupingBy(BabelArtifact::getType));
-
- if (artifactMap.containsKey(BabelArtifact.ArtifactType.MODEL)) {
- modelArtifacts.addAll(
- getBabelArtifactConverter().convertToModel(artifactMap.get(BabelArtifact.ArtifactType.MODEL)));
- artifactMap.remove(BabelArtifact.ArtifactType.MODEL);
- }
-
- if (artifactMap.containsKey(BabelArtifact.ArtifactType.VNFCATALOG)) {
- catalogArtifacts.addAll(getBabelArtifactConverter()
- .convertToCatalog(artifactMap.get(BabelArtifact.ArtifactType.VNFCATALOG)));
- artifactMap.remove(BabelArtifact.ArtifactType.VNFCATALOG);
- }
-
- // Log unexpected artifact types
- if (!artifactMap.isEmpty()) {
- logger.warn(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR,
- artifactInfo.getArtifactName() + " " + serviceVersion
- + ". Unexpected artifact types returned by the babel service: "
- + artifactMap.keySet().toString());
- }
-
- } catch (BabelArtifactParsingException e) {
- logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR,
- "Error for artifact " + artifactInfo.getArtifactName() + " " + serviceVersion + e);
- throw new ProcessToscaArtifactsException(
- "An error occurred while trying to parse the Babel artifacts: " + e.getLocalizedMessage());
- } catch (Exception e) {
- logger.error(ModelLoaderMsgs.BABEL_REST_REQUEST_ERROR, e, "POST", config.getBabelBaseUrl(),
- "Error posting artifact " + artifactInfo.getArtifactName() + " " + serviceVersion + " to Babel: "
- + e.getLocalizedMessage());
- throw new ProcessToscaArtifactsException(
- "An error occurred while calling the Babel service: " + e.getLocalizedMessage());
+ public List<Artifact> processToscaArtifacts(byte[] payload, IArtifactInfo artifactInfo, String distributionId, String serviceVersion)
+ throws ProcessToscaArtifactsException, InvalidArchiveException {
+ // Get translated artifacts from Babel Service
+ BabelRequest babelRequest = new BabelRequest();
+ babelRequest.setArtifactName(artifactInfo.getArtifactName());
+ babelRequest.setCsar(Base64.getEncoder().encodeToString(payload));
+ babelRequest.setArtifactVersion(serviceVersion);
+ List<Artifact> artifacts = babelArtifactService.invokeBabelService(babelRequest, distributionId);
+
+ // 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 (isDuplicateVnfCatalogData(artifacts, csarCatalogArtifacts)) {
+ 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.");