aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-04-30 11:22:07 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-04-30 11:22:07 +0200
commita61b2948f9cbe25d0ec6cd957671d51d83c62a1a (patch)
tree8683bf7996f3eeff9bca0eb2c34ed590e53261af /src/main/java
parent98fe4a42e555975fa36ad40020424902cd15be38 (diff)
Return List<Artifact> in ArtifactDownloadManager
- return processed artifacts as List<Artifact> instead of updating the parameters in ArtifactDownloadManager - use exceptions to signal exceptional behaviour instead of boolean success = false; Issue-ID: AAI-3841 Change-Id: Ie99c5da1f553bebd70665914fa6be9c460fa412c Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java53
-rw-r--r--src/main/java/org/onap/aai/modelloader/notification/EventCallback.java22
-rw-r--r--src/main/java/org/onap/aai/modelloader/service/BabelServiceClientFactory.java30
3 files changed, 39 insertions, 66 deletions
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 90e20bd..e2c5e27 100644
--- a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java
+++ b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java
@@ -22,6 +22,7 @@ package org.onap.aai.modelloader.notification;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.stream.Collectors;
@@ -86,29 +87,25 @@ public class ArtifactDownloadManager {
* @param modelArtifacts collection of artifacts for model query specs
* @param catalogArtifacts collection of artifacts that represent vnf catalog files
* @return boolean <code>true</code> if the download process was successful otherwise <code>false</code>
+ * @throws Exception
*/
- boolean downloadArtifacts(INotificationData data, List<IArtifactInfo> artifacts, List<Artifact> modelArtifacts,
- List<Artifact> catalogArtifacts) {
- boolean success = true;
+ List<Artifact> downloadArtifacts(INotificationData data, List<IArtifactInfo> artifacts) throws Exception {
+ List<Artifact> allArtifacts = new ArrayList<>();
for (IArtifactInfo artifact : artifacts) {
try {
IDistributionClientDownloadResult downloadResult = downloadIndividualArtifacts(data, artifact);
- processDownloadedArtifacts(modelArtifacts, catalogArtifacts, artifact, downloadResult, data);
+ List<Artifact> processedArtifacts = processDownloadedArtifacts(artifact, downloadResult, data);
+ allArtifacts.addAll(processedArtifacts);
} catch (DownloadFailureException e) {
notificationPublisher.publishDownloadFailure(client, data, artifact, e.getMessage());
- success = false;
- } catch (Exception e) {
+ throw e;
+ } catch (ProcessToscaArtifactsException | InvalidArchiveException | BabelArtifactParsingException e) {
notificationPublisher.publishDeployFailure(client, data, artifact);
- success = false;
- }
-
- if (!success) {
- break;
+ throw e;
}
}
-
- return success;
+ return allArtifacts;
}
private IDistributionClientDownloadResult downloadIndividualArtifacts(INotificationData data,
@@ -134,30 +131,25 @@ public class ArtifactDownloadManager {
return downloadResult;
}
- private void processDownloadedArtifacts(List<Artifact> modelArtifacts, List<Artifact> catalogArtifacts,
+ private List<Artifact> processDownloadedArtifacts(
IArtifactInfo artifactInfo, IDistributionClientDownloadResult downloadResult, INotificationData data)
throws ProcessToscaArtifactsException, InvalidArchiveException, BabelArtifactParsingException {
- List<Artifact> artifacts = null;
+ List<Artifact> artifacts = new ArrayList<>();
+ List<Artifact> querySpecArtifacts = new ArrayList<>();
if ("TOSCA_CSAR".equalsIgnoreCase(artifactInfo.getArtifactType())) {
artifacts = processToscaArtifacts(downloadResult.getArtifactPayload(), artifactInfo,
data.getDistributionID(), data.getServiceVersion());
} else if (ArtifactTypeEnum.MODEL_QUERY_SPEC.toString().equalsIgnoreCase(artifactInfo.getArtifactType())) {
- processModelQuerySpecArtifact(modelArtifacts, downloadResult);
+ querySpecArtifacts = processModelQuerySpecArtifact(downloadResult);
} else {
logger.info(ModelLoaderMsgs.UNSUPPORTED_ARTIFACT_TYPE, artifactInfo.getArtifactName(),
artifactInfo.getArtifactType());
throw new InvalidArchiveException("Unsupported artifact type: " + artifactInfo.getArtifactType());
}
- if(artifacts != null) {
- for(Artifact artifact : artifacts) {
- if(artifact.getType() == ArtifactType.VNF_CATALOG || artifact.getType() == ArtifactType.VNF_CATALOG_XML) {
- catalogArtifacts.add(artifact);
- } else {
- modelArtifacts.add(artifact);
- }
- }
- }
+ return Stream
+ .concat(artifacts.stream(), querySpecArtifacts.stream())
+ .collect(Collectors.toList());
}
public List<Artifact> processToscaArtifacts(byte[] payload, IArtifactInfo artifactInfo, String distributionId, String serviceVersion)
@@ -191,8 +183,7 @@ public class ArtifactDownloadManager {
return !csarCatalogArtifacts.isEmpty() && !babelIsEmpty;
}
- private void processModelQuerySpecArtifact(List<Artifact> modelArtifacts,
- IDistributionClientDownloadResult downloadResult) throws BabelArtifactParsingException {
+ private List<Artifact> processModelQuerySpecArtifact(IDistributionClientDownloadResult downloadResult) throws BabelArtifactParsingException {
logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Processing named query artifact.");
IModelParser parser = new NamedQueryArtifactParser();
@@ -200,15 +191,11 @@ public class ArtifactDownloadManager {
List<Artifact> parsedArtifacts =
parser.parse(new String(downloadResult.getArtifactPayload()), downloadResult.getArtifactFilename());
- if (parsedArtifactsExist(parsedArtifacts)) {
- modelArtifacts.addAll(parsedArtifacts);
+ if (parsedArtifacts != null && !parsedArtifacts.isEmpty()) {
+ return parsedArtifacts;
} else {
throw new BabelArtifactParsingException(
"Could not parse generated XML: " + new String(downloadResult.getArtifactPayload()));
}
}
-
- private boolean parsedArtifactsExist(List<Artifact> parsedArtifacts) {
- return parsedArtifacts != null && !parsedArtifacts.isEmpty();
- }
}
diff --git a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java
index d047bf9..6993948 100644
--- a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java
+++ b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java
@@ -27,6 +27,7 @@ import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.ArtifactType;
import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor;
import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
@@ -60,11 +61,26 @@ public class EventCallback implements INotificationCallback {
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received distribution " + data.getDistributionID());
List<IArtifactInfo> artifacts = new ArtifactInfoExtractor().extract(data);
+ boolean success = true;
+ List<Artifact> downloadedArtifacts = new ArrayList<>();
+ try {
+ downloadedArtifacts =
+ artifactDownloadManager.downloadArtifacts(data, artifacts);
+ } catch (Exception e) {
+ success = false;
+ }
+
List<Artifact> catalogArtifacts = new ArrayList<>();
List<Artifact> modelArtifacts = new ArrayList<>();
-
- boolean success =
- artifactDownloadManager.downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
+ if(downloadedArtifacts != null) {
+ for(Artifact artifact : downloadedArtifacts) {
+ if(artifact.getType() == ArtifactType.VNF_CATALOG || artifact.getType() == ArtifactType.VNF_CATALOG_XML) {
+ catalogArtifacts.add(artifact);
+ } else {
+ modelArtifacts.add(artifact);
+ }
+ }
+ }
if (success) {
success = artifactDeploymentManager.deploy(data.getDistributionID(), modelArtifacts, catalogArtifacts);
diff --git a/src/main/java/org/onap/aai/modelloader/service/BabelServiceClientFactory.java b/src/main/java/org/onap/aai/modelloader/service/BabelServiceClientFactory.java
deleted file mode 100644
index ce690c5..0000000
--- a/src/main/java/org/onap/aai/modelloader/service/BabelServiceClientFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
- * ================================================================================
- * 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.onap.aai.modelloader.service;
-
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.restclient.BabelServiceClient;
-import org.onap.aai.modelloader.restclient.BabelServiceClientException;
-
-public interface BabelServiceClientFactory {
- public BabelServiceClient create(ModelLoaderConfig config) throws BabelServiceClientException;
-}