use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class UploadCSARSStepDefinition method I_should_receive_a_RestResponse_with_compilation_alerts_in_file_s.
@Then("^I should receive a RestResponse with (\\d+) alerts in (\\d+) files : (\\d+) errors (\\d+) warnings and (\\d+) infos$")
public void I_should_receive_a_RestResponse_with_compilation_alerts_in_file_s(int expectedAlertCount, int errornousFiles, int exptectedErrorCount, int exptectedWarningCount, int exptectedInfoCount) throws Throwable {
RestResponse<CsarUploadResult> result = JsonUtil.read(Context.getInstance().getRestResponse(), CsarUploadResult.class);
Assert.assertFalse("We should have alerts", result.getData().getErrors().isEmpty());
Assert.assertEquals(errornousFiles, result.getData().getErrors().size());
int alertCount = 0;
int errorCount = 0;
int warningCount = 0;
int infoCount = 0;
for (Map.Entry<String, List<ParsingError>> errorEntry : result.getData().getErrors().entrySet()) {
alertCount += errorEntry.getValue().size();
for (ParsingError pe : errorEntry.getValue()) {
switch(pe.getErrorLevel()) {
case ERROR:
errorCount++;
break;
case WARNING:
warningCount++;
break;
case INFO:
infoCount++;
break;
}
}
}
Assert.assertEquals(expectedAlertCount, alertCount);
Assert.assertEquals(exptectedErrorCount, errorCount);
Assert.assertEquals(exptectedWarningCount, warningCount);
Assert.assertEquals(exptectedInfoCount, infoCount);
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class ArchiveImageLoader method importImage.
private void importImage(Path archiveFile, List<ParsingError> parsingErrors, Tag iconTag) {
FileSystem csarFS = null;
Path iconPath = null;
try {
csarFS = FileSystems.newFileSystem(archiveFile, null);
iconPath = csarFS.getPath(iconTag.getValue());
if (!Files.isDirectory(iconPath)) {
String iconId = UUID.randomUUID().toString();
// Saving the image
ImageData imageData = new ImageData();
imageData.setData(Files.readAllBytes(iconPath));
imageData.setId(iconId);
imageDAO.writeImage(imageData);
// Replace the image uri by the indexed image ID
iconTag.setValue(iconId);
} else {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.INVALID_ICON_FORMAT, "Icon loading", null, "Invalid icon format at path <" + iconPath + ">", null, safeToString(iconPath)));
}
} catch (NoSuchFileException | InvalidPathException e) {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.MISSING_FILE, "Icon loading", null, "No icon file found at path <" + iconPath + ">", null, safeToString(iconPath)));
} catch (ImageUploadException e) {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.INVALID_ICON_FORMAT, "Icon loading", null, "Invalid icon format at path <" + iconPath + ">", null, safeToString(iconPath)));
} catch (IOException e) {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.FAILED_TO_READ_FILE, "Icon loading", null, "IO error while loading icon at path <" + iconPath + ">", null, safeToString(iconPath)));
}
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class UploadExceptionUtil method parsingErrorFromException.
public static ParsingError parsingErrorFromException(Exception e) {
log.debug("Archive import failed", e);
if (e instanceof AlreadyExistException) {
return new ParsingError(ErrorCode.CSAR_ALREADY_EXISTS, "CSAR already exists", null, "Unable to override an existing CSAR if the version is not a SNAPSHOT version.", null, null);
} else if (e instanceof CSARUsedInActiveDeployment) {
return new ParsingError(ErrorCode.CSAR_USED_IN_ACTIVE_DEPLOYMENT, "CSAR used in active deployment", null, "Unable to override a csar used in an active deployment.", null, null);
} else if (e instanceof ToscaTypeAlreadyDefinedInOtherCSAR) {
return new ParsingError(ErrorCode.TOSCA_TYPE_ALREADY_EXISTS_IN_OTHER_CSAR, "Tosca type conflict", null, e.getMessage(), null, null);
}
log.error("Unexpected error while parsing archive.", e);
return new ParsingError(ErrorCode.ERRONEOUS_ARCHIVE_FILE, "Failed to process archive for unexpected reason", null, e.getMessage(), null, null);
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class AbstractArtifactPostProcessor method process.
@Override
public void process(AbstractArtifact instance) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
postProcessArtifactRef(node, instance.getArtifactRef());
ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
// If archive name is already defined (by the type for example then don't override it)
if (StringUtils.isBlank(instance.getArchiveName())) {
instance.setArchiveName(archiveRoot.getArchive().getName());
instance.setArchiveVersion(archiveRoot.getArchive().getVersion());
}
if (instance.getArtifactType() == null) {
// try to get type from extension
instance.setArtifactType(getArtifactTypeByExtension(instance.getArtifactRef(), node, archiveRoot));
} else {
// check the type reference
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getArtifactType(), ArtifactType.class));
}
if (instance.getRepositoryName() != null) {
RepositoryDefinition repositoryDefinition = archiveRoot.getRepositories() != null ? archiveRoot.getRepositories().get(instance.getRepositoryName()) : null;
if (repositoryDefinition == null) {
// Sometimes the information about repository has already been filled in the parent type
if (instance.getRepositoryURL() == null) {
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.UNKNOWN_REPOSITORY, "Implementation artifact", node.getStartMark(), "Repository definition not found", node.getEndMark(), instance.getArtifactRepository()));
}
} else {
instance.setRepositoryURL(repositoryDefinition.getUrl());
instance.setRepositoryCredential(repositoryDefinition.getCredential() != null ? repositoryDefinition.getCredential().getValue() : null);
instance.setRepositoryName(repositoryDefinition.getId());
instance.setArtifactRepository(repositoryDefinition.getType());
}
}
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class AbstractArtifactPostProcessor method getArtifactTypeByExtension.
private String getArtifactTypeByExtension(String artifactReference, Node node, ArchiveRoot archiveRoot) {
int dotIndex = artifactReference.lastIndexOf('.');
String extension = (dotIndex == -1) ? "" : artifactReference.substring(dotIndex + 1);
String type = null;
ArtifactType indexedType = getFromArchiveRootWithExtension(archiveRoot, extension);
if (indexedType == null) {
ArtifactType artifactType = repositorySearchService.getElementInDependencies(ArtifactType.class, archiveRoot.getArchive().getDependencies(), "fileExt", extension);
if (artifactType != null) {
type = artifactType.getElementId();
}
if (type == null) {
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "Implementation artifact", node.getStartMark(), "No artifact type in the repository references the artifact's extension", node.getEndMark(), extension));
type = "unknown";
}
} else {
type = indexedType.getElementId();
}
return type;
}
Aggregations