- 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.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);
-
- // 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(
- babelArtifactConverter.convertToModel(artifactMap.get(BabelArtifact.ArtifactType.MODEL)));
- artifactMap.remove(BabelArtifact.ArtifactType.MODEL);
- }
-
- if (artifactMap.containsKey(BabelArtifact.ArtifactType.VNFCATALOG)) {
- catalogArtifacts.addAll(babelArtifactConverter
- .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());
- }
- }
-
- BabelServiceClient createBabelServiceClient(IArtifactInfo artifact, String serviceVersion)
- throws ProcessToscaArtifactsException {
- BabelServiceClient babelClient;
- try {
- logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Creating Babel client");
- babelClient = clientFactory.create(config);
- } catch (BabelServiceClientException e) {
- logger.error(ModelLoaderMsgs.BABEL_REST_REQUEST_ERROR, e, "POST", config.getBabelBaseUrl(),
- "Error posting artifact " + artifact.getArtifactName() + " " + serviceVersion + " to Babel: "
- + e.getLocalizedMessage());
- throw new ProcessToscaArtifactsException(
- "An error occurred tyring to convert the tosca artifacts to xml artifacts: "
- + e.getLocalizedMessage());
- }
-
- return babelClient;
- }
-