Search in sources :

Example 51 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class EditorService method process.

/**
 * FIXME there is a cyclic dependency on beans here.
 * Finds the proper processor and process an operation
 *
 * @param operation The operation to process
 * @param <T> Type of the operation to process
 */
public <T extends AbstractEditorOperation> void process(T operation) {
    Topology topology = EditionContextManager.getTopology();
    Csar csar = EditionContextManager.getCsar();
    IEditorOperationProcessor<T> processor = (IEditorOperationProcessor<T>) processorMap.get(operation.getClass());
    processor.process(csar, topology, operation);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Topology(org.alien4cloud.tosca.model.templates.Topology) IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)

Example 52 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class EditorService method override.

/**
 * Override the content of an archive from a full exising archive.
 *
 * @param topologyId The if of the topology to process.
 * @param inputStream The input stream of the file that contains the archive.
 */
public void override(String topologyId, InputStream inputStream) throws IOException {
    Path tempPath = null;
    try {
        // Initialize the editon context, null last operation id means that we just accept a context with no pending operations
        initContext(topologyId, (String) null);
        // first we need to copy the content to a temporary location, unzip and parse the archive
        tempPath = Files.createTempFile(Paths.get(tempUploadDir), "", null);
        Files.copy(inputStream, tempPath, StandardCopyOption.REPLACE_EXISTING);
        // This throws an exception if not successful
        topologyUploadService.processTopology(tempPath, EditionContextManager.get().getTopology().getWorkspace());
        // meaning the topology is well imported in the editor context: override all the content of the git repository
        // erase all content but .git directory
        FileUtil.delete(EditionContextManager.get().getLocalGitPath(), EditionContextManager.get().getLocalGitPath().resolve(".git"));
        // copy the archive content
        if (isZipFile(tempPath)) {
            // unzip the content
            FileUtil.unzip(tempPath, EditionContextManager.get().getLocalGitPath());
        } else {
            // just copy the file
            Path targetPath = EditionContextManager.get().getLocalGitPath().resolve(tempPath.getFileName());
            Files.copy(tempPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
        }
        // and finally save and commit
        Topology topology = EditionContextManager.getTopology();
        String commitMessage = AuthorizationUtil.getCurrentUser().getUserId() + ": Override all content of the topology archive from REST API.";
        topologyServiceCore.save(topology);
        // Topology has changed means that dependencies might have changed, must update the dependencies
        csarService.setDependencies(topology.getId(), topology.getDependencies());
        topologySubstitutionServive.updateSubstitutionType(topology, EditionContextManager.getCsar());
        // Local git commit
        repositoryService.commit(EditionContextManager.get().getCsar(), commitMessage);
    } finally {
        EditionContextManager.get().setCurrentOperation(null);
        editionContextManager.destroy();
    }
}
Also used : Path(java.nio.file.Path) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 53 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class ArchiveIndexer method indexTopology.

private void indexTopology(final ArchiveRoot archiveRoot, List<ParsingError> parsingErrors, String archiveName, String archiveVersion) {
    Topology topology = archiveRoot.getTopology();
    if (topology == null || topology.isEmpty()) {
        return;
    }
    topology.setTags(archiveRoot.getArchive().getTags());
    if (archiveRoot.hasToscaTypes()) {
        // The archive contains types, we assume those types are used in the embedded topology so we add the dependency to this CSAR
        CSARDependency selfDependency = new CSARDependency(archiveRoot.getArchive().getName(), archiveRoot.getArchive().getVersion(), archiveRoot.getArchive().getHash());
        topology.getDependencies().add(selfDependency);
    }
    // init the workflows
    TopologyContext topologyContext = workflowBuilderService.buildCachedTopologyContext(new TopologyContext() {

        @Override
        public String getDSLVersion() {
            return archiveRoot.getArchive().getToscaDefinitionsVersion();
        }

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

        @Override
        public <T extends AbstractToscaType> T findElement(Class<T> clazz, String elementId) {
            return ToscaContext.get(clazz, elementId);
        }
    });
    workflowBuilderService.initWorkflows(topologyContext);
    parsingErrors.add(new ParsingError(ParsingErrorLevel.INFO, ErrorCode.TOPOLOGY_DETECTED, "", null, "A topology template has been detected", null, archiveName));
    topologyServiceCore.saveTopology(topology);
    topologySubstitutionService.updateSubstitutionType(topology, archiveRoot.getArchive());
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) Topology(org.alien4cloud.tosca.model.templates.Topology) TopologyContext(alien4cloud.paas.wf.TopologyContext) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 54 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class RemoveWorkflowProcessor method processWorkflowOperation.

@Override
protected void processWorkflowOperation(Csar csar, Topology topology, RemoveWorkflowOperation operation, Workflow workflow) {
    ensureNotStandard(workflow, "standard workflow <" + workflow.getName() + "> can not be removed");
    log.debug("removing workflow [ {} ] from topology [ {} ]", operation.getWorkflowName(), topology.getId());
    topology.getWorkflows().remove(operation.getWorkflowName());
    topology.getWorkflows().values().forEach(wf -> wf.getSteps().values().forEach(step -> {
        if (step.getActivity() instanceof InlineWorkflowActivity) {
            InlineWorkflowActivity inlineWorkflowActivity = (InlineWorkflowActivity) step.getActivity();
            if (inlineWorkflowActivity.getInline().equals(workflow.getName())) {
                throw new BadWorkflowOperationException("Workflow " + inlineWorkflowActivity.getInline() + " is inlined in workflow " + wf.getName() + " in step " + step.getName());
            }
        }
    }));
}
Also used : Component(org.springframework.stereotype.Component) Slf4j(lombok.extern.slf4j.Slf4j) RemoveWorkflowOperation(org.alien4cloud.tosca.editor.operations.workflow.RemoveWorkflowOperation) Csar(org.alien4cloud.tosca.model.Csar) InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) BadWorkflowOperationException(alien4cloud.paas.wf.exception.BadWorkflowOperationException) EditionContextManager(org.alien4cloud.tosca.editor.EditionContextManager) Topology(org.alien4cloud.tosca.model.templates.Topology) InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) BadWorkflowOperationException(alien4cloud.paas.wf.exception.BadWorkflowOperationException)

Example 55 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class EditorStepDefs method i_create_an_empty_topology_template_version.

@Given("^I create an empty topology template \"([^\"]*)\" version \"([^\"]*)\"$")
public void i_create_an_empty_topology_template_version(String topologyTemplateName, String version) throws Throwable {
    try {
        Topology topology = catalogService.createTopologyAsTemplate(topologyTemplateName, null, version, AlienConstants.GLOBAL_WORKSPACE_ID, null);
        topologyIds.addLast(topology.getId());
        topologyEvaluationContext = new StandardEvaluationContext(topology);
    } catch (Exception e) {
        log.error("Exception occurred while creating a topology template", e);
        thrownException = e;
        exceptionEvaluationContext = new StandardEvaluationContext(e);
    }
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Topology(org.alien4cloud.tosca.model.templates.Topology) NotFoundException(alien4cloud.exception.NotFoundException) IOException(java.io.IOException) Given(cucumber.api.java.en.Given)

Aggregations

Topology (org.alien4cloud.tosca.model.templates.Topology)79 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)22 Map (java.util.Map)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)17 Csar (org.alien4cloud.tosca.model.Csar)16 Application (alien4cloud.model.application.Application)15 NotFoundException (alien4cloud.exception.NotFoundException)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)9 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 IOException (java.io.IOException)8 List (java.util.List)8 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)8 Component (org.springframework.stereotype.Component)8 Audit (alien4cloud.audit.annotation.Audit)7