Search in sources :

Example 16 with ParsingError

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);
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) CsarUploadResult(alien4cloud.rest.csar.CsarUploadResult) List(java.util.List) Map(java.util.Map) Then(cucumber.api.java.en.Then)

Example 17 with ParsingError

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)));
    }
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) ImageUploadException(alien4cloud.images.exception.ImageUploadException) ImageData(alien4cloud.images.ImageData) IOException(java.io.IOException)

Example 18 with ParsingError

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);
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) CSARUsedInActiveDeployment(alien4cloud.component.repository.exception.CSARUsedInActiveDeployment) ToscaTypeAlreadyDefinedInOtherCSAR(alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 19 with ParsingError

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());
        }
    }
}
Also used : RepositoryDefinition(org.alien4cloud.tosca.model.definitions.RepositoryDefinition) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) ArtifactType(org.alien4cloud.tosca.model.types.ArtifactType) Node(org.yaml.snakeyaml.nodes.Node)

Example 20 with ParsingError

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;
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) ArtifactType(org.alien4cloud.tosca.model.types.ArtifactType)

Aggregations

ParsingError (alien4cloud.tosca.parser.ParsingError)46 Node (org.yaml.snakeyaml.nodes.Node)21 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)13 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)7 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)7 Map (java.util.Map)6 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)4 Csar (org.alien4cloud.tosca.model.Csar)4 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)4 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)4 ToscaContext (alien4cloud.tosca.context.ToscaContext)3 INodeParser (alien4cloud.tosca.parser.INodeParser)3 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)3 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)2 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2