Search in sources :

Example 6 with AbstractEditorOperation

use of org.alien4cloud.tosca.editor.operations.AbstractEditorOperation in project alien4cloud by alien4cloud.

the class EditorStepDefinitions method do_i_execute_the_operation.

public static void do_i_execute_the_operation(Map<String, String> operationMap) throws Throwable {
    Class operationClass = Class.forName(operationMap.get("type"));
    AbstractEditorOperation operation = (AbstractEditorOperation) operationClass.newInstance();
    EvaluationContext operationContext = new StandardEvaluationContext(operation);
    SpelParserConfiguration config = new SpelParserConfiguration(true, true);
    SpelExpressionParser parser = new SpelExpressionParser(config);
    for (Map.Entry<String, String> operationEntry : operationMap.entrySet()) {
        if (!"type".equals(operationEntry.getKey())) {
            parser.parseRaw(operationEntry.getKey()).setValue(operationContext, operationEntry.getValue());
        }
    }
    do_i_execute_the_operation(operation);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) SpelParserConfiguration(org.springframework.expression.spel.SpelParserConfiguration)

Example 7 with AbstractEditorOperation

use of org.alien4cloud.tosca.editor.operations.AbstractEditorOperation in project alien4cloud by alien4cloud.

the class EditorService method doSave.

private void doSave() throws IOException {
    EditionContext context = EditionContextManager.get();
    if (context.getLastOperationIndex() <= context.getLastSavedOperationIndex()) {
        // nothing to save..
        return;
    }
    StringBuilder commitMessage = new StringBuilder();
    // copy and cleanup all temporary files from the executed operations.
    for (int i = context.getLastSavedOperationIndex() + 1; i <= context.getLastOperationIndex(); i++) {
        AbstractEditorOperation operation = context.getOperations().get(i);
        IEditorOperationProcessor<?> processor = (IEditorOperationProcessor) processorMap.get(operation.getClass());
        if (processor instanceof IEditorCommitableProcessor) {
            ((IEditorCommitableProcessor) processor).beforeCommit(operation);
        }
        commitMessage.append(operation.getAuthor()).append(": ").append(operation.commitMessage()).append("\n");
    }
    saveYamlAndZipFile();
    Topology topology = EditionContextManager.getTopology();
    // Save the topology in elastic search
    topologyServiceCore.save(topology);
    // Topology has changed means that dependencies might have changed, must update the dependencies
    csarService.setDependencies(EditionContextManager.getCsar(), topology.getDependencies());
    // update substitution type if needed
    topologySubstitutionServive.updateSubstitutionType(topology, EditionContextManager.getCsar());
    // Local git commit
    repositoryService.commit(EditionContextManager.get().getCsar(), commitMessage.toString());
    // TODO add support for undo even after save, this require ability to rollback files to git state, we need file rollback support for that..
    context.setOperations(Lists.newArrayList(context.getOperations().subList(context.getLastOperationIndex() + 1, context.getOperations().size())));
    context.setLastOperationIndex(-1);
}
Also used : AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) IEditorCommitableProcessor(org.alien4cloud.tosca.editor.processors.IEditorCommitableProcessor) Topology(org.alien4cloud.tosca.model.templates.Topology) IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)

Example 8 with AbstractEditorOperation

use of org.alien4cloud.tosca.editor.operations.AbstractEditorOperation in project alien4cloud by alien4cloud.

the class EditorStepDefs method i_execute_the_operation_on_topology_number.

@Given("^I execute the operation on the topology number (\\d+)$")
public void i_execute_the_operation_on_topology_number(int indexOfTopologyId, DataTable operationDT) throws Throwable {
    Map<String, String> operationMap = Maps.newHashMap();
    for (DataTableRow row : operationDT.getGherkinRows()) {
        operationMap.put(row.getCells().get(0), row.getCells().get(1));
    }
    Class operationClass = Class.forName(operationMap.get("type"));
    AbstractEditorOperation operation = (AbstractEditorOperation) operationClass.newInstance();
    EvaluationContext operationContext = new StandardEvaluationContext(operation);
    SpelParserConfiguration config = new SpelParserConfiguration(true, true);
    SpelExpressionParser parser = new SpelExpressionParser(config);
    for (Map.Entry<String, String> operationEntry : operationMap.entrySet()) {
        if (!"type".equals(operationEntry.getKey())) {
            parser.parseRaw(operationEntry.getKey()).setValue(operationContext, getValue(operationEntry.getValue()));
        }
    }
    doExecuteOperation(operation, topologyIds.get(indexOfTopologyId));
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Map(java.util.Map) HashMap(java.util.HashMap) DataTableRow(gherkin.formatter.model.DataTableRow) SpelParserConfiguration(org.springframework.expression.spel.SpelParserConfiguration) Given(cucumber.api.java.en.Given)

Aggregations

AbstractEditorOperation (org.alien4cloud.tosca.editor.operations.AbstractEditorOperation)8 Topology (org.alien4cloud.tosca.model.templates.Topology)3 Map (java.util.Map)2 IEditorOperationProcessor (org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)2 Csar (org.alien4cloud.tosca.model.Csar)2 EvaluationContext (org.springframework.expression.EvaluationContext)2 SpelParserConfiguration (org.springframework.expression.spel.SpelParserConfiguration)2 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)2 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)2 NotFoundException (alien4cloud.exception.NotFoundException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Given (cucumber.api.java.en.Given)1 DataTableRow (gherkin.formatter.model.DataTableRow)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 EditionConcurrencyException (org.alien4cloud.tosca.editor.exception.EditionConcurrencyException)1 EditorIOException (org.alien4cloud.tosca.editor.exception.EditorIOException)1 UpdateFileOperation (org.alien4cloud.tosca.editor.operations.UpdateFileOperation)1