Search in sources :

Example 6 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class ArchiveUploadService method preParsing.

@ToscaContextual
public Map<CSARDependency, CsarDependenciesBean> preParsing(Set<Path> paths, List<ParsingResult<Csar>> parsingResults) {
    Map<CSARDependency, CsarDependenciesBean> csarDependenciesBeans = Maps.newHashMap();
    for (Path path : paths) {
        try {
            // FIXME cleanup git import archives
            ParsingResult<CsarDependenciesBean> parsingResult = parser.parseImports(path);
            parsingResult.getResult().setPath(path);
            csarDependenciesBeans.put(parsingResult.getResult().getSelf(), parsingResult.getResult());
        } catch (ParsingException e) {
            ParsingResult<Csar> failedResult = new ParsingResult<>();
            failedResult.setContext(new ParsingContext(path.getFileName().toString()));
            failedResult.getContext().setParsingErrors(e.getParsingErrors());
            parsingResults.add(failedResult);
            log.debug("Not able to parse archive, ignoring it", e);
        }
    }
    return csarDependenciesBeans;
}
Also used : Path(java.nio.file.Path) ParsingResult(alien4cloud.tosca.parser.ParsingResult) ParsingContext(alien4cloud.tosca.parser.ParsingContext) ParsingException(alien4cloud.tosca.parser.ParsingException) CsarDependenciesBean(org.alien4cloud.tosca.model.CsarDependenciesBean) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 7 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method getNonNativesNodes.

/**
 * Get the non-natives node of a topology.
 *
 * @param topology
 * @return a Map of non-natives nodes.
 */
@ToscaContextual
public Map<String, NodeTemplate> getNonNativesNodes(Topology topology) {
    Map<String, NodeTemplate> nonNativesNode = new HashMap<>();
    if (topology.getNodeTemplates() != null) {
        for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
            NodeTemplate template = templateEntry.getValue();
            NodeType indexedToscaElement = ToscaContext.getOrFail(NodeType.class, template.getType());
            boolean isCompute = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeComputeConstants.COMPUTE_TYPE);
            boolean isNetwork = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeNetworkConstants.NETWORK_TYPE);
            boolean isVolume = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeBlockStorageConstants.BLOCKSTORAGE_TYPE);
            if (!isCompute && !isNetwork && !isVolume) {
                nonNativesNode.put(templateEntry.getKey(), template);
            }
        }
    }
    return nonNativesNode;
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 8 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class ToscaTypeIndexerService method indexInheritableElement.

@Override
@ToscaContextual
public void indexInheritableElement(String archiveName, String archiveVersion, AbstractInheritableToscaType element, Collection<CSARDependency> dependencies) {
    if (CollectionUtils.isNotEmpty(element.getDerivedFrom())) {
        boolean deriveFromSimpleType = false;
        String parentId = element.getDerivedFrom().get(0);
        if (element.getDerivedFrom().size() == 1 && ToscaTypes.isSimple(parentId)) {
            deriveFromSimpleType = true;
        }
        if (!deriveFromSimpleType) {
            AbstractInheritableToscaType superElement = ToscaContext.getOrFail(element.getClass(), parentId);
            IndexedModelUtils.mergeInheritableIndex(superElement, element);
        }
    }
    alienDAO.save(element);
    refreshIndexForSearching();
}
Also used : AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 9 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class CsarDependencyLoader method buildDependencyBean.

@Override
@ToscaContextual
public CSARDependency buildDependencyBean(String name, String version) {
    CSARDependency newDependency = new CSARDependency(name, version);
    Csar csar = ToscaContext.get().getArchive(name, version);
    if (csar != null) {
        newDependency.setHash(csar.getHash());
    }
    return newDependency;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 10 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class ArchiveUploadService method upload.

/**
 * Upload a TOSCA archive and index its components.
 *
 * @param path The archive path.
 * @param csarSource The source of the upload.
 * @return The Csar object from the parsing.
 * @throws ParsingException
 * @throws CSARUsedInActiveDeployment
 */
@ToscaContextual
public ParsingResult<Csar> upload(Path path, CSARSource csarSource, String workspace) throws ParsingException, CSARUsedInActiveDeployment, ToscaTypeAlreadyDefinedInOtherCSAR {
    // parse the archive.
    ParsingResult<ArchiveRoot> parsingResult = parser.parseWithExistingContext(path, workspace);
    final ArchiveRoot archiveRoot = parsingResult.getResult();
    // check if any blocker error has been found during parsing process.
    if (parsingResult.hasError(ParsingErrorLevel.ERROR)) {
        // do not save anything if any blocker error has been found during import.
        return ArchiveParserUtil.toSimpleResult(parsingResult);
    }
    archiveIndexer.importArchive(archiveRoot, csarSource, path, parsingResult.getContext().getParsingErrors());
    try {
        suggestionService.postProcessSuggestionFromArchive(parsingResult);
        suggestionService.setAllSuggestionIdOnPropertyDefinition();
    } catch (Exception e) {
        log.error("Could not post process suggestion for the archive <" + archiveRoot.getArchive().getName() + "/" + archiveRoot.getArchive().getVersion() + ">", e);
    }
    return ArchiveParserUtil.toSimpleResult(parsingResult);
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingException(alien4cloud.tosca.parser.ParsingException) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Aggregations

ToscaContextual (alien4cloud.tosca.context.ToscaContextual)13 TopologyDTO (alien4cloud.topology.TopologyDTO)2 ParsingException (alien4cloud.tosca.parser.ParsingException)2 Path (java.nio.file.Path)2 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 PaaSTopology (alien4cloud.paas.model.PaaSTopology)1 AbstractTopologyDTO (alien4cloud.topology.AbstractTopologyDTO)1 PropertiesTask (alien4cloud.topology.task.PropertiesTask)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ToscaMeta (alien4cloud.tosca.model.ToscaMeta)1 ParsingContext (alien4cloud.tosca.parser.ParsingContext)1 ParsingResult (alien4cloud.tosca.parser.ParsingResult)1 IOException (java.io.IOException)1 FileSystem (java.nio.file.FileSystem)1 ProviderNotFoundException (java.nio.file.ProviderNotFoundException)1 HashMap (java.util.HashMap)1