Search in sources :

Example 1 with EditorToscaYamlNotSupportedException

use of org.alien4cloud.tosca.editor.exception.EditorToscaYamlNotSupportedException in project alien4cloud by alien4cloud.

the class EditorTopologyUploadService method processTopologyParseResult.

private void processTopologyParseResult(Path archivePath, ParsingResult<ArchiveRoot> parsingResult, String workspace) {
    // parse the archive.
    parsingResult = postProcessor.process(archivePath, parsingResult, workspace);
    // 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.
        throw new EditorToscaYamlParsingException("Uploaded yaml files is not a valid tosca template", ArchiveParserUtil.toSimpleResult(parsingResult));
    }
    if (parsingResult.getResult().hasToscaTypes()) {
        throw new EditorToscaYamlNotSupportedException("Tosca types are currently not supported in the topology editor context.");
    }
    if (!parsingResult.getResult().hasToscaTopologyTemplate()) {
        throw new EditorToscaYamlNotSupportedException("A topology template is required in the topology edition context.");
    }
    Topology currentTopology = EditionContextManager.getTopology();
    Topology parsedTopology = parsingResult.getResult().getTopology();
    final String definitionVersion = parsingResult.getResult().getArchive().getToscaDefinitionsVersion();
    if (!currentTopology.getArchiveName().equals(parsedTopology.getArchiveName()) || !currentTopology.getArchiveVersion().equals(parsedTopology.getArchiveVersion())) {
        throw new EditorToscaYamlNotSupportedException("Template name and version must be set to [" + currentTopology.getArchiveName() + ":" + currentTopology.getArchiveVersion() + "] and cannot be updated to [" + parsedTopology.getArchiveName() + ":" + parsedTopology.getArchiveVersion() + "]");
    }
    // Copy static elements from the topology
    parsedTopology.setId(currentTopology.getId());
    // Update editor tosca context
    ToscaContext.get().resetDependencies(parsedTopology.getDependencies());
    // init the workflows for the topology based on the yaml
    TopologyContext topologyContext = workflowBuilderService.buildCachedTopologyContext(new TopologyContext() {

        @Override
        public String getDSLVersion() {
            return definitionVersion;
        }

        @Override
        public Topology getTopology() {
            return parsedTopology;
        }

        @Override
        public <T extends AbstractToscaType> T findElement(Class<T> clazz, String id) {
            return ToscaContext.get(clazz, id);
        }
    });
    for (Workflow wf : safe(topologyContext.getTopology().getWorkflows()).values()) {
        wf.setHasCustomModifications(true);
    }
    workflowBuilderService.initWorkflows(topologyContext);
    // update the topology in the edition context with the new one
    EditionContextManager.get().setTopology(parsingResult.getResult().getTopology());
}
Also used : EditorToscaYamlParsingException(org.alien4cloud.tosca.editor.exception.EditorToscaYamlParsingException) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Topology(org.alien4cloud.tosca.model.templates.Topology) TopologyContext(alien4cloud.paas.wf.TopologyContext) EditorToscaYamlNotSupportedException(org.alien4cloud.tosca.editor.exception.EditorToscaYamlNotSupportedException)

Aggregations

TopologyContext (alien4cloud.paas.wf.TopologyContext)1 EditorToscaYamlNotSupportedException (org.alien4cloud.tosca.editor.exception.EditorToscaYamlNotSupportedException)1 EditorToscaYamlParsingException (org.alien4cloud.tosca.editor.exception.EditorToscaYamlParsingException)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)1