- 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>
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
- <version>2.1.0</version>
+ <version>3.3.3</version>
<relativePath />
</parent>
<start-class>org.onap.aai.modelloader.service.ModelLoaderApplication</start-class>
<nexusproxy>https://nexus.onap.org</nexusproxy>
<docker.location>${basedir}/target</docker.location>
- <spring-boot.version>2.4.13</spring-boot.version>
- <spring-cloud.version>2020.0.2</spring-cloud.version>
+ <spring-boot.version>2.7.18</spring-boot.version>
+ <spring-cloud.version>2021.0.8</spring-cloud.version>
<apache.commons-text.version>1.10.0</apache.commons-text.version>
<commons-compress.version>1.22</commons-compress.version>
<gson.version>2.10.1</gson.version>
<hamcrest-all.version>1.3</hamcrest-all.version>
<babel.version>1.13.0</babel.version>
- <aai.rest.client.version>1.2.1</aai.rest.client.version>
<sdc-distribution-client.version>2.1.1</sdc-distribution-client.version>
<logback.version>1.2.11</logback.version>
<!-- docker related properties -->
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-common</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.aai</groupId>
- <artifactId>rest-client</artifactId>
- <version>${aai.rest.client.version}</version>
- </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<artifactId>sdc-distribution-client</artifactId>
<version>${sdc-distribution-client.version}</version>
</dependency>
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>20131018</version>
- <!--$NO-MVN-MAN-VER$ -->
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-security</artifactId>
- </dependency>
- <dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- <version>2.12.1</version>
- </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>3.0.0-M4</version>
+ <version>3.1.2</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
- <version>3.0.0-M4</version>
+ <version>3.1.2</version>
<executions>
<!-- Ensures that both integration-test and verify goals of the Failsafe
Maven plugin are executed. -->
--- /dev/null
+distribution_type: container
+container_release_tag: 1.14.0
+project: model-loader
+ref: de4e6c93f2f4038167e8b5fef92426c4daac4b83
+containers:
+ - name: model-loader
+ version: 1.14-STAGING-20240425T063121Z
*/
package org.onap.aai.modelloader.babel;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
import org.onap.aai.babel.service.data.BabelArtifact;
-import org.onap.aai.babel.service.data.BabelRequest;
import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType;
+import org.onap.aai.babel.service.data.BabelRequest;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.entity.Artifact;
@Service
public class BabelArtifactService {
- private static Logger logger = LoggerFactory.getInstance().getLogger(BabelArtifactService.class);
+ private static Logger logger = LoggerFactory.getInstance().getLogger(BabelArtifactService.class);
+
+ private final BabelServiceClient babelServiceClient;
+ private final BabelArtifactConverter babelArtifactConverter;
+
+ public BabelArtifactService(BabelServiceClient babelServiceClient, BabelArtifactConverter babelArtifactConverter) {
+ this.babelServiceClient = babelServiceClient;
+ this.babelArtifactConverter = babelArtifactConverter;
+ }
+
+ public List<Artifact> invokeBabelService(BabelRequest babelRequest, String distributionId)
+ throws ProcessToscaArtifactsException {
+ try {
+ logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
+ "Posting artifact: " + babelRequest.getArtifactName() + ", service version: "
+ + babelRequest.getArtifactVersion()
+ + ", artifact version: " + babelRequest.getArtifactVersion());
+
+ List<BabelArtifact> babelArtifacts = babelServiceClient.postArtifact(babelRequest, distributionId);
+
+ List<Artifact> convertedArtifacts = new ArrayList<>();
+ for(BabelArtifact babelArtifact : babelArtifacts) {
+ if(!isUnknownType(babelArtifact)) {
+ if(babelArtifact.getType() == ArtifactType.MODEL) {
+ convertedArtifacts.addAll(babelArtifactConverter.convertToModel(babelArtifact));
+ } else {
+ convertedArtifacts.add(babelArtifactConverter.convertToCatalog(babelArtifact));
+ }
+ }
+ }
+
+ return convertedArtifacts;
- private final BabelServiceClient babelServiceClient;
- private final BabelArtifactConverter babelArtifactConverter;
+ } catch (BabelArtifactParsingException e) {
+ logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR,
+ "Error for artifact " + babelRequest.getArtifactName() + " " + babelRequest.getArtifactVersion()
+ + " " + 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",
+ "Error posting artifact " + babelRequest.getArtifactName() + " " + babelRequest.getArtifactVersion()
+ + " to Babel: "
+ + e.getLocalizedMessage());
+ throw new ProcessToscaArtifactsException(
+ "An error occurred while calling the Babel service: " + e.getLocalizedMessage());
+ }
+ }
- public BabelArtifactService(BabelServiceClient babelServiceClient, BabelArtifactConverter babelArtifactConverter) {
- this.babelServiceClient = babelServiceClient;
- this.babelArtifactConverter = babelArtifactConverter;
- }
+ private boolean isUnknownType(BabelArtifact babelArtifact) {
+ if (babelArtifact.getType() == ArtifactType.MODEL || babelArtifact.getType() == ArtifactType.VNFCATALOG) {
+ return false;
+ } else {
+ logger.warn(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR,
+ babelArtifact.getName() + " " + babelArtifact.getType()
+ + ". Unexpected artifact types returned by the babel service: "
+ + babelArtifact.getPayload());
+ return true;
+ }
+ }
- public void invokeBabelService(List<Artifact> modelArtifacts, List<Artifact> catalogArtifacts, BabelRequest babelRequest, String distributionId)
- throws ProcessToscaArtifactsException {
- try {
- logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
- "Posting artifact: " + babelRequest.getArtifactName() + ", service version: " + babelRequest.getArtifactVersion()
- + ", artifact version: " + babelRequest.getArtifactVersion());
-
- List<BabelArtifact> babelArtifacts =
- babelServiceClient.postArtifact(babelRequest, 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,
- babelRequest.getArtifactName() + " " + babelRequest.getArtifactVersion()
- + ". Unexpected artifact types returned by the babel service: "
- + artifactMap.keySet().toString());
- }
-
- } catch (BabelArtifactParsingException e) {
- logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR,
- "Error for artifact " + babelRequest.getArtifactName() + " " + babelRequest.getArtifactVersion() + " " + 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",
- "Error posting artifact " + babelRequest.getArtifactName() + " " + babelRequest.getArtifactVersion() + " to Babel: "
- + e.getLocalizedMessage());
- throw new ProcessToscaArtifactsException(
- "An error occurred while calling the Babel service: " + e.getLocalizedMessage());
- }
- }
-
-}
+}
\ No newline at end of file
import java.util.List;\r
import org.onap.aai.modelloader.config.ModelLoaderConfig;\r
import org.onap.aai.modelloader.restclient.AaiRestClient;\r
-import org.springframework.web.client.RestTemplate;\r
\r
public abstract class ArtifactHandler {\r
\r
import org.springframework.http.MediaType;\r
import org.springframework.http.ResponseEntity;\r
import org.springframework.stereotype.Component;\r
-import org.springframework.web.client.RestTemplate;\r
import org.w3c.dom.Document;\r
import org.w3c.dom.Element;\r
import org.w3c.dom.Node;\r
IModelArtifact model = parseModel(doc.getDocumentElement(), artifactPayload);
- if (!processParsedModel(modelList, artifactName, model)) {
+ boolean success = processParsedModel(modelList, artifactName, model);
+ if (!success) {
modelList = null;
}
} catch (Exception ex) {
package org.onap.aai.modelloader.entity.model;
import java.util.List;
+
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.config.ModelLoaderConfig;
import org.onap.aai.modelloader.entity.Artifact;
import org.onap.aai.modelloader.entity.ArtifactType;
import org.onap.aai.modelloader.restclient.AaiRestClient;
+import org.onap.aai.modelloader.service.ModelLoaderMsgs;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
public class ModelArtifact extends AbstractModelArtifact {
+ private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifact.class);
+
private static final String AAI_MODEL_VER_SUB_URL = "/model-vers/model-ver";
private static final String FAILURE_MSG_PREFIX = "Ingestion failed for ";
* @return true if the resource PUT as XML media was successful (status OK)
*/
private boolean putXmlResource(AaiRestClient aaiClient, String distId, String resourceUrl, String payload) {
- ResponseEntity<String> putResponse =
- aaiClient.putResource(resourceUrl, payload, distId, MediaType.APPLICATION_XML, String.class);
+ ResponseEntity<String> putResponse = null;
+ try {
+ putResponse =
+ aaiClient.putResource(resourceUrl, payload, distId, MediaType.APPLICATION_XML, String.class);
+ } catch (HttpClientErrorException | HttpServerErrorException e) {
+ logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "Error putting resource: " + e.toString());
+ }
return putResponse != null && putResponse.getStatusCode() == HttpStatus.CREATED;
}
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.entity.Artifact;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
+import org.springframework.stereotype.Component;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+@Component
public class ModelArtifactParser extends AbstractModelArtifactParser {
public static final String MODEL_VER = "model-ver";
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import jline.internal.Log;
+
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.entity.Artifact;
/**
*/
public class ModelSorter {
+ private static Logger logger = LoggerFactory.getInstance().getLogger(ModelSorter.class);
+
/**
* Wraps a Model object to form dependencies other Models using Edges.
*/
// create node
AbstractModelArtifact referencedModel = versionIdToModelMap.get(referencedModelId);
if (referencedModel == null) {
- Log.debug("ignoring " + referencedModelId);
+ logger.debug("ignoring " + referencedModelId);
continue; // referenced model not supplied, no need to sort it
}
referencedNode = new Node(referencedModel);
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;
+import java.util.stream.Stream;
+
import org.onap.aai.babel.service.data.BabelRequest;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.cl.mdc.MdcOverride;
import org.onap.aai.modelloader.babel.BabelArtifactService;
import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.ArtifactType;
+import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifact;
import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
import org.onap.aai.modelloader.entity.model.IModelParser;
import org.onap.aai.modelloader.entity.model.NamedQueryArtifactParser;
* @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,
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 = new ArrayList<>();
+ List<Artifact> querySpecArtifacts = new ArrayList<>();
if ("TOSCA_CSAR".equalsIgnoreCase(artifactInfo.getArtifactType())) {
- processToscaArtifacts(modelArtifacts, catalogArtifacts, downloadResult.getArtifactPayload(), artifactInfo,
+ 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());
}
+ return Stream
+ .concat(artifacts.stream(), querySpecArtifacts.stream())
+ .collect(Collectors.toList());
}
- public void processToscaArtifacts(List<Artifact> modelArtifacts, List<Artifact> catalogArtifacts, byte[] payload,
- IArtifactInfo artifactInfo, String distributionId, String serviceVersion)
+ 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);
- babelArtifactService.invokeBabelService(modelArtifacts, catalogArtifacts, babelRequest, distributionId);
+ 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 (!catalogArtifacts.isEmpty() && !csarCatalogArtifacts.isEmpty()) {
+ 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.");
- } else if (!csarCatalogArtifacts.isEmpty()) {
- catalogArtifacts.addAll(csarCatalogArtifacts);
}
+ return Stream
+ .concat(artifacts.stream(), csarCatalogArtifacts.stream())
+ .collect(Collectors.toList());
+
}
- private void processModelQuerySpecArtifact(List<Artifact> modelArtifacts,
- IDistributionClientDownloadResult downloadResult) throws BabelArtifactParsingException {
+ private boolean isDuplicateVnfCatalogData(List<Artifact> babelArtifacts, List<Artifact> csarCatalogArtifacts) {
+ boolean babelIsEmpty = babelArtifacts.stream()
+ .filter(VnfCatalogArtifact.class::isInstance)
+ .findAny().isEmpty();
+ return !csarCatalogArtifacts.isEmpty() && !babelIsEmpty;
+ }
+
+ private List<Artifact> processModelQuerySpecArtifact(IDistributionClientDownloadResult downloadResult) throws BabelArtifactParsingException {
logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Processing named query artifact.");
IModelParser parser = new NamedQueryArtifactParser();
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();
- }
}
*/
package org.onap.aai.modelloader.notification;
-import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.onap.aai.babel.service.data.BabelArtifact;
@Component
public class BabelArtifactConverter {
+ private final ModelArtifactParser modelArtifactParser;
+
+ public BabelArtifactConverter(ModelArtifactParser modelArtifactParser) {
+ this.modelArtifactParser = modelArtifactParser;
+ }
+
/**
* This method converts BabelArtifacts into instances of {@link ModelArtifact}.
*
* @throws BabelArtifactParsingException if an error occurs trying to parse the generated XML files that were
* converted from tosca artifacts
*/
- public List<Artifact> convertToModel(List<BabelArtifact> xmlArtifacts) throws BabelArtifactParsingException {
- Objects.requireNonNull(xmlArtifacts);
- List<Artifact> modelArtifacts = new ArrayList<>();
- ModelArtifactParser modelArtParser = new ModelArtifactParser();
-
- // Parse TOSCA payloads
- for (BabelArtifact xmlArtifact : xmlArtifacts) {
-
- List<Artifact> parsedArtifacts = modelArtParser.parse(xmlArtifact.getPayload(), xmlArtifact.getName());
-
- if (parsedArtifacts == null || parsedArtifacts.isEmpty()) {
- throw new BabelArtifactParsingException("Could not parse generated XML: " + xmlArtifact.getPayload());
- }
-
- modelArtifacts.addAll(parsedArtifacts);
+ public List<Artifact> convertToModel(BabelArtifact babelArtifact) throws BabelArtifactParsingException {
+ Objects.requireNonNull(babelArtifact);
+ List<Artifact> parsedArtifacts = modelArtifactParser.parse(babelArtifact.getPayload(), babelArtifact.getName());
+
+ if (parsedArtifacts == null || parsedArtifacts.isEmpty()) {
+ throw new BabelArtifactParsingException("Could not parse generated XML: " + babelArtifact.getPayload());
}
- return modelArtifacts;
+ return parsedArtifacts;
}
/**
* @param xmlArtifacts xml artifacts to be parsed
* @return List<org.openecomp.modelloader.entity.Artifact> list of converted catalog artifacts
*/
- public List<Artifact> convertToCatalog(List<BabelArtifact> xmlArtifacts) {
- Objects.requireNonNull(xmlArtifacts);
- List<Artifact> catalogArtifacts = new ArrayList<>();
-
- for (BabelArtifact xmlArtifact : xmlArtifacts) {
- catalogArtifacts.add(new VnfCatalogArtifact(xmlArtifact.getPayload()));
- }
-
- return catalogArtifacts;
+ public Artifact convertToCatalog(BabelArtifact babelArtifact) {
+ return new VnfCatalogArtifact(babelArtifact.getPayload());
}
-}
+}
\ No newline at end of file
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;
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, modelArtifacts, catalogArtifacts);
+ success = artifactDeploymentManager.deploy(data.getDistributionID(), modelArtifacts, catalogArtifacts);
}
String statusString = success ? "SUCCESS" : "FAILURE";
@Override
public List<BabelArtifact> postArtifact(BabelRequest babelRequest, String transactionId) throws BabelServiceClientException {
- if (logger.isInfoEnabled()) {
- logger.info(ModelLoaderMsgs.BABEL_REST_REQUEST_PAYLOAD, " Artifact Name: " + babelRequest.getArtifactName()
+ if (logger.isDebugEnabled()) {
+ logger.debug(ModelLoaderMsgs.BABEL_REST_REQUEST_PAYLOAD, " Artifact Name: " + babelRequest.getArtifactName()
+ " Artifact version: " + babelRequest.getArtifactVersion() + " Artifact payload: " + babelRequest.getCsar());
}
import java.util.ArrayList;
import java.util.List;
+
import org.onap.aai.modelloader.entity.Artifact;
import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifactHandler;
import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
import org.onap.aai.modelloader.restclient.AaiRestClient;
-import org.onap.sdc.api.notification.INotificationData;
import org.springframework.stereotype.Component;
/**
/**
* Deploys model and catalog artifacts to A&AI.
*
- * @param data data about the notification that is being processed
+ * @param distributionId data about the notification that is being processed
* @param modelArtifacts collection of artifacts that represent yml files found in a TOSCA_CSAR file that have been
* converted to XML and also those for model query specs
* @param catalogArtifacts collection of artifacts that represent vnf catalog files
* @return boolean <code>true</code> if all deployments were successful otherwise <code>false</code>
*/
- public boolean deploy(final INotificationData data, final List<Artifact> modelArtifacts,
+ public boolean deploy(final String distributionId, final List<Artifact> modelArtifacts,
final List<Artifact> catalogArtifacts) {
- String distributionId = data.getDistributionID();
-
List<Artifact> completedArtifacts = new ArrayList<>();
boolean deploySuccess =
modelArtifactHandler.pushArtifacts(modelArtifacts, distributionId, completedArtifacts, aaiClient);
return deploySuccess;
}
-}
+}
\ No newline at end of file
+++ /dev/null
-/**
- * ============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;
-}
import java.util.Base64;
import java.util.List;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.config.ModelLoaderConfig;
import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.ArtifactType;
import org.onap.aai.modelloader.notification.ArtifactDownloadManager;
import org.onap.aai.modelloader.notification.NotificationDataImpl;
import org.onap.aai.modelloader.notification.NotificationPublisher;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.notification.IArtifactInfo;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("/services/model-loader/v1/model-service")
-public class ModelController implements ModelLoaderInterface {
+public class ModelController {
private static final Logger logger = LoggerFactory.getInstance().getLogger(ModelController.class);
this.artifactDownloadManager = artifactDownloadManager;
}
- /**
- * (non-Javadoc)
- *
- * @see org.onap.aai.modelloader.service.ModelLoaderInterface#loadModel(java.lang.String)
- */
- @Override
- public Response loadModel(@PathVariable String modelid) {
- return Response.ok("{\"model_loaded\":\"" + modelid + "\"}").build();
+ @GetMapping(value = "/loadModel/{modelid}", produces = "application/json")
+ public ResponseEntity<String> loadModel(@PathVariable String modelid) {
+ return ResponseEntity.ok("{\"model_loaded\":\"" + modelid + "\"}");
}
- /**
- * (non-Javadoc)
- *
- * @see org.onap.aai.modelloader.service.ModelLoaderInterface#saveModel(java.lang.String, java.lang.String)
- */
- @Override
- public Response saveModel(@PathVariable String modelid, @PathVariable String modelname) {
- return Response.ok("{\"model_saved\":\"" + modelid + "-" + modelname + "\"}").build();
+ @PutMapping(value = "/saveModel/{modelid}/{modelname}", produces = "application/json")
+ public ResponseEntity<String> saveModel(@PathVariable String modelid, @PathVariable String modelname) {
+ return ResponseEntity.ok("{\"model_saved\":\"" + modelid + "-" + modelname + "\"}");
}
- @Override
- public Response ingestModel(@PathVariable String modelName, @PathVariable String modelVersion,
+ @PostMapping(value = "/ingestModel/{modelName}/{modelVersion}", produces = "application/json")
+ public ResponseEntity<String> ingestModel(@PathVariable String modelName, @PathVariable String modelVersion,
@RequestBody String payload) throws IOException {
- Response response;
+ ResponseEntity<String> response;
if (config.getIngestSimulatorEnabled()) {
response = processTestArtifact(modelName, modelVersion, payload);
} else {
logger.debug("Simulation interface disabled");
- response = Response.serverError().build();
+ response = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
return response;
}
- private Response processTestArtifact(String modelName, String modelVersion, String payload) {
+ private ResponseEntity<String> processTestArtifact(String modelName, String modelVersion, String payload) {
IArtifactInfo artifactInfo = new ArtifactInfoImpl();
((ArtifactInfoImpl) artifactInfo).setArtifactName(modelName);
((ArtifactInfoImpl) artifactInfo).setArtifactVersion(modelVersion);
- Response response;
+ ResponseEntity<String> response;
try {
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received test artifact " + modelName + " " + modelVersion);
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Generating XML models from test artifact");
+ List<Artifact> artifacts = artifactDownloadManager.processToscaArtifacts(csarFile, artifactInfo, "test-transaction-id", modelVersion);
List<Artifact> modelArtifacts = new ArrayList<>();
List<Artifact> catalogArtifacts = new ArrayList<>();
-
- artifactDownloadManager.processToscaArtifacts(modelArtifacts,
- catalogArtifacts, csarFile, artifactInfo, "test-transaction-id", modelVersion);
+ for(Artifact artifact : artifacts) {
+ if(artifact.getType().equals(ArtifactType.MODEL)) {
+ modelArtifacts.add(artifact);
+ } else {
+ catalogArtifacts.add(artifact);
+ }
+ }
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Loading xml models from test artifacts: "
+ modelArtifacts.size() + " model(s) and " + catalogArtifacts.size() + " catalog(s)");
NotificationDataImpl notificationData = new NotificationDataImpl();
notificationData.setDistributionID("TestDistributionID");
boolean success =
- artifactDeploymentManager.deploy(notificationData, modelArtifacts, catalogArtifacts);
+ artifactDeploymentManager.deploy(notificationData.getDistributionID(), modelArtifacts, catalogArtifacts);
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Deployment success was " + success);
- response = success ? Response.ok().build() : Response.serverError().build();
+ response = success ? ResponseEntity.ok().build() : ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
} catch (Exception e) {
String responseMessage = e.getMessage();
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Exception handled: " + responseMessage);
} else {
responseMessage += "\nSDC publishing is enabled but has been bypassed";
}
- response = Response.serverError().entity(responseMessage).type(MediaType.APPLICATION_XML).build();
+ response = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseMessage);
}
return response;
}
+++ /dev/null
-/**
- * ============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 java.io.IOException;
-import javax.ws.rs.core.Response;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-public interface ModelLoaderInterface {
-
- @GetMapping(value = "/loadModel/{modelid}", produces = "application/json")
- @ResponseBody
- Response loadModel(String modelid);
-
- @PutMapping(value = "/saveModel/{modelid}/{modelname}", produces = "application/json")
- @ResponseBody
- Response saveModel(String modelid, String modelname);
-
- @PostMapping(value = "/ingestModel/{modelName}/{modelVersion}", produces = "application/json")
- @ResponseBody
- Response ingestModel(String modelid, String modelVersion, String payload) throws IOException;
-}
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.junit.jupiter.api.Test;
import org.onap.aai.modelloader.DistributionClientTestConfiguration;
import org.onap.aai.modelloader.entity.Artifact;
import org.onap.aai.modelloader.entity.ArtifactType;
+import org.onap.aai.modelloader.entity.model.ModelArtifact;
import org.onap.aai.modelloader.service.ArtifactInfoImpl;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.test.context.EmbeddedKafka;
import org.springframework.test.annotation.DirtiesContext;
-import com.fasterxml.jackson.core.JsonProcessingException;
-
@DirtiesContext
@AutoConfigureWireMock(port = 0)
@EmbeddedKafka(partitions = 1, ports = 9092, topics = {"${topics.distribution.notification}"})
@Autowired ArtifactDownloadManager artifactDownloadManager;
@Test
- public void downloadArtifacts() throws JsonProcessingException {
+ public void downloadArtifacts() throws Exception {
NotificationDataImpl notificationData = new NotificationDataImpl();
notificationData.setDistributionID("distributionID");
notificationData.setServiceVersion("2.0");
artifactInfo.setArtifactUUID("f6f907f1-3f45-4fb4-8cbe-15a4c6ee16db");
List<IArtifactInfo> artifacts = new ArrayList<>();
artifacts.add(artifactInfo);
- List<Artifact> modelArtifacts = new ArrayList<>(); // processed artifacts will be written to this list
- List<Artifact> catalogArtifacts = new ArrayList<>(); // processed artifacts will be written to this list
- boolean result = artifactDownloadManager.downloadArtifacts(notificationData, artifacts, modelArtifacts, catalogArtifacts);
+ List<Artifact> result = artifactDownloadManager.downloadArtifacts(notificationData, artifacts);
- assertEquals(1, modelArtifacts.size());
- assertEquals(ArtifactType.MODEL, modelArtifacts.get(0).getType());
- assertTrue(result);
+ assertEquals(1, result.size());
+ ModelArtifact modelArtifact = (ModelArtifact) result.get(0);
+ assertEquals(ArtifactType.MODEL, modelArtifact.getType());
+ assertEquals("3c8bc8e7-e387-46ed-8616-70e99e2206dc", modelArtifact.getModelInvariantId());
+ assertEquals("http://org.onap.aai.inventory/v28", modelArtifact.getModelNamespace());
+ assertEquals("v28", modelArtifact.getModelNamespaceVersion());
+ assertEquals("71f47717-b100-4eac-940b-7d4e86a4cbb7", modelArtifact.getModelVerId());
+ assertEquals(Set.of("82194af1-3c2c-485a-8f44-420e22a9eaa4|46b92144-923a-4d20-b85a-3cbd847668a9"), modelArtifact.getDependentModelIds());
}
}
*/
package org.onap.aai.modelloader.notification;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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.aai.modelloader.util.ArtifactTestUtils;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.notification.IArtifactInfo;
@Mock private IDistributionClient mockDistributionClient;
@Mock private NotificationPublisher mockNotificationPublisher;
@Mock private BabelArtifactConverter mockBabelArtifactConverter;
- @Mock private BabelServiceClientFactory mockClientFactory;
@Mock private VnfCatalogExtractor mockVnfCatalogExtractor;
@InjectMocks private BabelArtifactService babelArtifactService;
@BeforeEach
public void setup() throws Exception {
MockitoAnnotations.openMocks(this);
- when(mockClientFactory.create(Mockito.any())).thenReturn(mockBabelClient);
Properties configProperties = new Properties();
configProperties.load(this.getClass().getClassLoader().getResourceAsStream("model-loader.properties"));
@Test
public void downloadArtifacts_validToscaVnfcCsarFile()
- throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ throws Exception {
INotificationData data = getNotificationDataWithToscaCsarFile();
IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifacts());
when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(new ArrayList<>());
- List<Artifact> modelArtifacts = new ArrayList<>();
- List<Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
- is(true));
-
- assertEquals(2, catalogFiles.size(), "There should have been some catalog files");
+ List<Artifact> artifacts = downloadManager.downloadArtifacts(data, data.getServiceArtifacts());
+ List<Artifact> catalogArtifacts = artifacts.stream()
+ .filter(VnfCatalogArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ List<Artifact> modelArtifacts = artifacts.stream()
+ .filter(ModelArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ assertEquals(1, catalogArtifacts.size(), "There should be a catalog artifact");
+ assertEquals(1, modelArtifacts.size(), "There should be a model artifact");
}
@Test
public void downloadArtifacts_validXmlVnfcCsarFile()
- throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ throws Exception {
INotificationData data = getNotificationDataWithToscaCsarFile();
IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifactsNoVnfc());
when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(createXmlVnfcArtifacts());
- List<Artifact> modelArtifacts = new ArrayList<>();
- List<Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
- is(true));
+ List<Artifact> artifacts = downloadManager.downloadArtifacts(data, data.getServiceArtifacts());
- assertEquals(3, catalogFiles.size(), "There should have been some catalog files");
+ List<Artifact> catalogArtifacts = artifacts.stream()
+ .filter(VnfCatalogArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ List<Artifact> modelArtifacts = artifacts.stream()
+ .filter(ModelArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ assertEquals(3, catalogArtifacts.size(), "There should be three catalog artifacts");
+ assertEquals(1, modelArtifacts.size(), "There should be a model artifact");
}
@Test
public void downloadArtifacts_validNoVnfcCsarFile()
- throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ throws Exception {
INotificationData data = getNotificationDataWithToscaCsarFile();
IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifactsNoVnfc());
when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(new ArrayList<>());
- List<Artifact> modelArtifacts = new ArrayList<>();
- List<Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
- is(true));
+ List<Artifact> artifacts = downloadManager.downloadArtifacts(data, data.getServiceArtifacts());
+ List<Artifact> catalogArtifacts = artifacts.stream()
+ .filter(VnfCatalogArtifact.class::isInstance)
+ .collect(Collectors.toList());
- assertEquals(0, catalogFiles.size(), "There should not have been any catalog files");
+ assertEquals(0, catalogArtifacts.size(), "There should not have been any catalog files");
}
@Test
public void downloadArtifacts_invalidXmlAndToscaVnfcCsarFile()
- throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ throws Exception {
INotificationData data = getNotificationDataWithToscaCsarFile();
IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(createXmlVnfcArtifacts());
doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
- List<Artifact> modelArtifacts = new ArrayList<>();
- List<Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
- is(false));
+ InvalidArchiveException invalidArchiveException = assertThrows(InvalidArchiveException.class,
+ () -> downloadManager.downloadArtifacts(data, data.getServiceArtifacts()));
Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
}
when(mockDistributionClient.download(artifactInfo))
.thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar")));
- when(mockBabelArtifactConverter.convertToModel(Mockito.anyList())).thenReturn(createModelArtifacts());
- when(mockBabelArtifactConverter.convertToCatalog(Mockito.anyList())).thenReturn(createToscaVnfcArtifacts());
+ when(mockBabelArtifactConverter.convertToModel(Mockito.any(BabelArtifact.class))).thenReturn(createModelArtifacts());
+ when(mockBabelArtifactConverter.convertToCatalog(Mockito.any(BabelArtifact.class))).thenReturn(new VnfCatalogArtifact("Some VNFC payload"));
}
private List<BabelArtifact> createBabelArtifacts() {
private List<Artifact> createModelArtifacts() {
List<Artifact> modelArtifacts = new ArrayList<>();
modelArtifacts.add(new ModelArtifact());
- modelArtifacts.add(new ModelArtifact());
return modelArtifacts;
}
- private List<Artifact> createToscaVnfcArtifacts() {
- List<Artifact> vnfcArtifacts = new ArrayList<>();
- vnfcArtifacts.add(new VnfCatalogArtifact("Some VNFC payload"));
- vnfcArtifacts.add(new VnfCatalogArtifact("Some VNFC payload"));
- return vnfcArtifacts;
- }
-
private List<Artifact> createXmlVnfcArtifacts() {
List<Artifact> vnfcArtifacts = new ArrayList<>();
vnfcArtifacts.add(new VnfCatalogArtifact(ArtifactType.VNF_CATALOG_XML, "Some VNFC payload"));
import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifactHandler;
import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
+import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
import org.onap.aai.modelloader.extraction.InvalidArchiveException;
import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
import org.onap.aai.modelloader.restclient.AaiRestClient;
public void deploy_csarDeploymentsFailed() throws IOException, BabelArtifactParsingException {
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
- List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
+ List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
.thenReturn(false);
- assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data, modelArtifacts, new ArrayList<>()), is(false));
+ assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), modelArtifacts, new ArrayList<>()), is(false));
Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
any());
eq(data.getDistributionID()), any());
}
- private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
- List<BabelArtifact> toscaArtifacts = new ArrayList<>();
+ private BabelArtifact setupTest(byte[] xml, INotificationData data) throws IOException {
org.onap.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
BabelArtifact xmlArtifact =
new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml));
- toscaArtifacts.add(xmlArtifact);
- return toscaArtifacts;
+ return xmlArtifact;
}
@Test
when(vnfCatalogArtifactHandlerMock.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
.thenReturn(false);
- assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data, new ArrayList<>(), catalogFiles), is(false));
+ assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), new ArrayList<>(), catalogFiles), is(false));
Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(new ArrayList<Artifact>()),
eq(data.getDistributionID()), any(), any());
throws IOException, BabelArtifactParsingException, InvalidArchiveException {
INotificationData data = getNotificationDataWithOneOfEach();
byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
- List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
+ List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
.thenReturn(modelsDeployed);
- assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data, modelArtifacts, catalogFiles), is(false));
+ assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), modelArtifacts, catalogFiles), is(false));
// Catalog artifacts are only pushed if models are successful.
Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
public void testDeploySuccess() throws IOException, BabelArtifactParsingException, InvalidArchiveException {
INotificationData data = getNotificationDataWithOneOfEach();
byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
- List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
+ List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
.thenReturn(true);
- assertThat(manager.deploy(data, modelArtifacts, catalogFiles), is(true));
+ assertThat(manager.deploy(data.getDistributionID(), modelArtifacts, catalogFiles), is(true));
Mockito.verify(vnfCatalogArtifactHandlerMock).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
any(), any());
package org.onap.aai.modelloader.notification;
import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsEmptyCollection.empty;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithInvalidType;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import java.util.stream.Collectors;
-import org.hamcrest.collection.IsEmptyCollection;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.aai.babel.service.data.BabelArtifact;
import org.onap.aai.modelloader.babel.BabelArtifactService;
import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifact;
import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
+import org.onap.aai.modelloader.entity.model.ModelArtifact;
+import org.onap.aai.modelloader.entity.model.NamedQueryArtifact;
+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.aai.modelloader.util.ArtifactTestUtils;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.notification.IArtifactInfo;
@Mock private IDistributionClient mockDistributionClient;
@Mock private NotificationPublisher mockNotificationPublisher;
@Mock private BabelArtifactConverter mockBabelArtifactConverter;
- @Mock private BabelServiceClientFactory mockClientFactory;
@InjectMocks BabelArtifactService babelArtifactService;
private VnfCatalogExtractor vnfCatalogExtractor;
public void setup() throws Exception {
MockitoAnnotations.openMocks(this);
vnfCatalogExtractor = new VnfCatalogExtractor();
- when(mockClientFactory.create(any())).thenReturn(mockBabelClient);
Properties configProperties = new Properties();
configProperties.load(this.getClass().getClassLoader().getResourceAsStream("model-loader.properties"));
/**
* Test downloading zero artifacts from SDC.
+ * @throws Exception
*/
@Test
- public void testDownloadWithZeroArtifacts() {
- List<Artifact> modelFiles = new ArrayList<>();
- List<Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(getNotificationDataWithOneService(), new ArrayList<>(), modelFiles,
- catalogFiles), is(true));
- assertThat(modelFiles, is(empty()));
- assertThat(catalogFiles, is(empty()));
+ public void testDownloadWithZeroArtifacts() throws Exception {
+ List<Artifact> artifacts = downloadManager.downloadArtifacts(getNotificationDataWithOneService(), new ArrayList<>());
+ assertThat(artifacts, is(empty()));
Mockito.verifyNoInteractions(mockBabelClient, mockDistributionClient, mockNotificationPublisher,
mockBabelArtifactConverter);
}
doNothing().when(mockNotificationPublisher).publishDownloadFailure(mockDistributionClient, data, artifact,
errorMessage);
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null), is(false));
+ assertThrows(DownloadFailureException.class,
+ () -> downloadManager.downloadArtifacts(data, data.getServiceArtifacts()));
Mockito.verify(mockDistributionClient).download(artifact);
Mockito.verify(mockNotificationPublisher).publishDownloadFailure(mockDistributionClient, data, artifact,
Mockito.verifyNoInteractions(mockBabelClient, mockBabelArtifactConverter);
}
- @Test
- public void testErrorCreatingBabelClient() throws Exception {
- when(mockClientFactory.create(any())).thenThrow(new BabelServiceClientException(new Exception()));
-
- INotificationData data = getNotificationDataWithToscaCsarFile();
- IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
- setupValidDownloadCsarMocks(data, artifactInfo, new ArtifactTestUtils());
- doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
-
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null), is(false));
-
- Mockito.verify(mockDistributionClient).download(artifactInfo);
- Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifactInfo);
- Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
- }
-
@Test
public void downloadArtifacts_invalidToscaCsarFile() throws IOException, BabelServiceClientException {
INotificationData data = getNotificationDataWithToscaCsarFile();
when(mockBabelClient.postArtifact(any(), any())).thenThrow(new BabelServiceClientException(""));
doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact);
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null), is(false));
+ assertThrows(ProcessToscaArtifactsException.class,
+ () -> downloadManager.downloadArtifacts(data, data.getServiceArtifacts()));
Mockito.verify(mockDistributionClient).download(artifact);
Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
DistributionActionResultEnum.SUCCESS, null, "This is not a valid Model Query Spec".getBytes()));
doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, null),
- is(false));
+ assertThrows(BabelArtifactParsingException.class,
+ () -> downloadManager.downloadArtifacts(data, data.getServiceArtifacts()));
Mockito.verify(mockDistributionClient).download(artifact);
Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
@Test
public void downloadArtifacts_validToscaCsarFile()
- throws IOException, BabelServiceClientException, BabelArtifactParsingException {
+ throws Exception {
INotificationData data = getNotificationDataWithToscaCsarFile();
IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
setupValidDownloadCsarMocks(data, artifactInfo, new ArtifactTestUtils());
- List<org.onap.aai.modelloader.entity.Artifact> modelArtifacts = new ArrayList<>();
- List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
- is(true));
- assertThat(catalogFiles.size(), is(0));
+ List<Artifact> artifacts = downloadManager.downloadArtifacts(data, data.getServiceArtifacts());
+ List<Artifact> modelArtifacts = artifacts.stream().filter(ModelArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ List<Artifact> catalogArtifacts = artifacts.stream().filter(VnfCatalogArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ assertThat(modelArtifacts.size(), is(1));
+ assertThat(catalogArtifacts.size(), is(1));
Mockito.verify(mockDistributionClient).download(artifactInfo);
Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifactInfo);
}
private void setupValidDownloadCsarMocks(INotificationData data, IArtifactInfo artifactInfo,
- ArtifactTestUtils artifactTestUtils) throws IOException, BabelServiceClientException {
+ ArtifactTestUtils artifactTestUtils) throws IOException, BabelServiceClientException, BabelArtifactParsingException {
when(mockDistributionClient.download(artifactInfo))
.thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
artifactTestUtils.loadResource("compressedArtifacts/service-VscpaasTest-csar.csar")));
when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifacts());
+
+ when(mockBabelArtifactConverter.convertToModel(any(BabelArtifact.class))).thenReturn(List.of(new ModelArtifact()));
+ when(mockBabelArtifactConverter.convertToCatalog(any(BabelArtifact.class))).thenReturn(new VnfCatalogArtifact(""));
}
private List<BabelArtifact> createBabelArtifacts() {
@Test
public void downloadArtifactsWithValidModelQuerySpec()
- throws IOException, BabelServiceClientException, BabelArtifactParsingException {
+ throws Exception {
INotificationData data = getNotificationDataWithModelQuerySpec();
IArtifactInfo artifact = data.getServiceArtifacts().get(0);
setupValidModelQuerySpecMocks(new ArtifactTestUtils(), data, artifact);
- List<org.onap.aai.modelloader.entity.Artifact> modelFiles = new ArrayList<>();
- List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelFiles, catalogFiles),
- is(true));
+ List<Artifact> artifacts = downloadManager.downloadArtifacts(data, data.getServiceArtifacts());
+ List<Artifact> namedQueryArtifacts = artifacts.stream().filter(NamedQueryArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ List<Artifact> catalogArtifacts = artifacts.stream().filter(VnfCatalogArtifact.class::isInstance)
+ .collect(Collectors.toList());
- assertThat(modelFiles, is(not(IsEmptyCollection.empty())));
- assertThat(catalogFiles, is(empty()));
+ assertThat(namedQueryArtifacts.size(), is(1));
+ assertThat(catalogArtifacts, is(empty()));
Mockito.verify(mockDistributionClient).download(artifact);
Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
@Test
public void downloadArtifacts_validCsarAndModelFiles()
- throws IOException, BabelServiceClientException, BabelArtifactParsingException {
+ throws Exception {
ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
INotificationData data = getNotificationDataWithOneOfEach();
- List<IArtifactInfo> artifacts = new ArrayList<>();
+ List<IArtifactInfo> artifactInfos = new ArrayList<>();
IArtifactInfo serviceArtifact = data.getServiceArtifacts().get(0);
IArtifactInfo modelSpecArtifact = data.getResources().get(1).getArtifacts().get(0);
- artifacts.add(serviceArtifact);
- artifacts.add(modelSpecArtifact);
+ artifactInfos.add(serviceArtifact);
+ artifactInfos.add(modelSpecArtifact);
setupValidDownloadCsarMocks(data, serviceArtifact, artifactTestUtils);
setupValidModelQuerySpecMocks(artifactTestUtils, data, modelSpecArtifact);
- List<org.onap.aai.modelloader.entity.Artifact> modelFiles = new ArrayList<>();
- List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, artifacts, modelFiles, catalogFiles), is(true));
+ List<Artifact> artifacts = downloadManager.downloadArtifacts(data, artifactInfos);
+ List<Artifact> modelArtifacts = artifacts.stream().filter(artifact -> !(artifact instanceof VnfCatalogArtifact))
+ .collect(Collectors.toList());
+ List<Artifact> catalogArtifacts = artifacts.stream().filter(VnfCatalogArtifact.class::isInstance)
+ .collect(Collectors.toList());
+ assertThat(modelArtifacts.size(), is(2));
+ assertThat(catalogArtifacts.size(), is(1));
Mockito.verify(mockDistributionClient).download(serviceArtifact);
Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, serviceArtifact);
when(mockDistributionClient.download(artifactInfo))
.thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
artifactTestUtils.loadResource("compressedArtifacts/service-VscpaasTest-csar.csar")));
- when(mockBabelArtifactConverter.convertToModel(anyList()))
+ when(mockBabelArtifactConverter.convertToModel(any()))
.thenThrow(BabelArtifactParsingException.class);
doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifacts());
List<Artifact> modelArtifacts = new ArrayList<>();
List<Artifact> catalogFiles = new ArrayList<>();
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
- is(false));
+ assertThrows(ProcessToscaArtifactsException.class,
+ () -> downloadManager.downloadArtifacts(data, data.getServiceArtifacts()));
+
assertThat(modelArtifacts, is(empty()));
assertThat(catalogFiles, is(empty()));
DistributionActionResultEnum.SUCCESS, null, "This content does not matter.".getBytes()));
doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
- assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, new ArrayList<>()),
- is(false));
+ assertThrows(InvalidArchiveException.class,
+ () -> downloadManager.downloadArtifacts(data, data.getServiceArtifacts()));
+
Mockito.verify(mockDistributionClient).download(artifact);
Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact);
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.onap.aai.modelloader.entity.Artifact;
import org.onap.aai.modelloader.entity.ArtifactType;
import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
+import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
import org.onap.aai.modelloader.util.ArtifactTestUtils;
import org.onap.sdc.api.notification.IArtifactInfo;
@Test
public void convert_nullToscaFiles() throws BabelArtifactParsingException {
assertThrows(NullPointerException.class, () -> {
- new BabelArtifactConverter().convertToModel(null);
+ new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(null);
fail("An instance of ArtifactGenerationException should have been thrown");
});
}
- @Test
- public void testEmptyToscaFiles() throws BabelArtifactParsingException {
- assertTrue(new BabelArtifactConverter().convertToModel(new ArrayList<>()).isEmpty(),
- "Nothing should have been returned");
- }
-
@Test
public void testInvalidXml() throws IOException, BabelArtifactParsingException {
assertThrows(BabelArtifactParsingException.class, () -> {
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
- List<BabelArtifact> toscaArtifacts = setupTest(problemXml, data);
+ BabelArtifact toscaArtifact = setupTest(problemXml, data);
- new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
fail("An instance of ModelArtifactParsingException should have been thrown");
});
}
- private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
- List<BabelArtifact> toscaArtifacts = new ArrayList<>();
+ private BabelArtifact setupTest(byte[] xml, INotificationData data) throws IOException {
IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
BabelArtifact xmlArtifact =
new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml));
- toscaArtifacts.add(xmlArtifact);
- return toscaArtifacts;
+ return xmlArtifact;
}
@Test
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
- List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
assertEquals(1, modelArtifacts.size(), "There should have been 1 artifact");
assertEquals(new String(xml), modelArtifacts.get(0).getPayload());
import static org.mockito.Mockito.when;
import java.io.IOException;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
import org.onap.sdc.api.IDistributionClient;
@Test
@SuppressWarnings("unchecked")
- public void activateCallback_downloadFails() {
+ public void activateCallback_downloadFails() throws Exception {
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
- when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class))).thenReturn(false);
+ when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)
+ )).thenThrow(DownloadFailureException.class);
eventCallback.activateCallback(data);
- verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class));
+ verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class));
Mockito.verifyNoInteractions(mockArtifactDeploymentManager);
}
@SuppressWarnings("unchecked")
@Test
- public void activateCallback() throws BabelArtifactParsingException {
+ public void activateCallback() throws Exception {
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
- when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class))).thenReturn(true);
+ when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)))
+ .thenReturn(Collections.emptyList());
- when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class)))
+ when(mockArtifactDeploymentManager.deploy(any(String.class), any(List.class), any(List.class)))
.thenReturn(true);
eventCallback.activateCallback(data);
- verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class));
- verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class));
+ verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class));
+ verify(mockArtifactDeploymentManager).deploy(any(String.class), any(List.class), any(List.class));
}
}
+++ /dev/null
-/**
- * ============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.restclient;
-
-import java.util.Collections;
-import java.util.List;
-import org.onap.aai.babel.service.data.BabelArtifact;
-import org.onap.aai.babel.service.data.BabelRequest;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-
-/**
- * Mocked Client for interfacing with Babel.
- *
- */
-public class MockBabelServiceClient implements BabelServiceClient {
-
- public MockBabelServiceClient(ModelLoaderConfig config) throws BabelServiceClientException {}
-
- @Override
- public List<BabelArtifact> postArtifact(BabelRequest babelRequest, String transactionId)
- throws BabelServiceClientException {
- return Collections.emptyList();
- }
-}
+++ /dev/null
-/**
- * ============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;
-import org.onap.aai.modelloader.restclient.MockBabelServiceClient;
-import org.springframework.stereotype.Service;
-
-@Service
-public class MockBabelServiceClientFactory implements BabelServiceClientFactory {
-
- @Override
- public BabelServiceClient create(ModelLoaderConfig config) throws BabelServiceClientException {
- return new MockBabelServiceClient(config);
- }
-
-}
import java.util.Base64;
import java.util.Collections;
-import javax.ws.rs.core.Response;
-
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.onap.sdc.api.IDistributionClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
/**
@Autowired NotificationPublisher notificationPublisher;
@Autowired VnfCatalogExtractor vnfCatalogExtractor;
- @Mock BabelServiceClientFactory clientFactory;
@Mock BabelServiceClient babelServiceClient;
@InjectMocks BabelArtifactService babelArtifactService;
@BeforeEach
public void init() throws BabelServiceClientException {
- when(clientFactory.create(any())).thenReturn(babelServiceClient);
when(babelServiceClient.postArtifact(any(), any())).thenReturn(Collections.emptyList());
ArtifactDownloadManager artifactDownloadManager = new ArtifactDownloadManager(iDistributionClient, notificationPublisher, vnfCatalogExtractor, babelArtifactService);
this.modelController = new ModelController(iDistributionClient, modelLoaderConfig, artifactDeploymentManager, artifactDownloadManager);
@Test
public void testLoadModel() {
- Response response = modelController.loadModel("");
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ ResponseEntity<String> response = modelController.loadModel("");
+ assertThat(response.getStatusCode(), is(HttpStatus.OK));
}
@Test
public void testSaveModel() {
- Response response = modelController.saveModel("", "");
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ ResponseEntity<String> response = modelController.saveModel("", "");
+ assertThat(response.getStatusCode(), is(HttpStatus.OK));
}
@Test
public void testIngestModel() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ ResponseEntity<String> response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
+ assertThat(response.getStatusCode(), is(HttpStatus.OK));
}
@Test
public void testIngestModelMissingName() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
- assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ ResponseEntity<String> response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
+ assertThat(response.getStatusCode(), is(HttpStatus.INTERNAL_SERVER_ERROR));
}
}
import java.io.IOException;
import java.util.Base64;
-import javax.ws.rs.core.Response;
-
import org.junit.jupiter.api.Test;
+import org.onap.aai.modelloader.config.BeanConfig;
import org.onap.aai.modelloader.util.ArtifactTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
/**
@Test
public void testIngestModel() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = controller.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
- assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ ResponseEntity<String> response = controller.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
+ assertThat(response.getStatusCode(), is(HttpStatus.INTERNAL_SERVER_ERROR));
}
# because they are used in Jenkins, whose plug-in doesn't support
major=1
-minor=13
-patch=6
+minor=14
+patch=0
base_version=${major}.${minor}.${patch}