Search in sources :

Example 1 with IEditorOperationProcessor

use of org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor in project alien4cloud by alien4cloud.

the class EditorService method initialize.

@PostConstruct
public void initialize() {
    Map<String, IEditorOperationProcessor> processors = applicationContext.getBeansOfType(IEditorOperationProcessor.class);
    for (IEditorOperationProcessor processor : processors.values()) {
        Class<?> operationClass = ReflectionUtil.getGenericArgumentType(processor.getClass(), IEditorOperationProcessor.class, 0);
        processorMap.put(operationClass, processor);
    }
}
Also used : IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor) PostConstruct(javax.annotation.PostConstruct)

Example 2 with IEditorOperationProcessor

use of org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor in project alien4cloud by alien4cloud.

the class EditorService method undoRedo.

/**
 * Undo or redo operations until the given index (including)
 *
 * @param topologyId The id of the topology for which to undo or redo operations.
 * @param at The index on which to place the undo/redo cursor (-1 means no operations, then 0 is first operation etc.)
 * @param lastOperationId The last known operation id for client optimistic locking.
 * @return The topology DTO.
 */
public TopologyDTO undoRedo(String topologyId, int at, String lastOperationId) {
    try {
        initContext(topologyId, lastOperationId);
        if (-1 > at || at > EditionContextManager.get().getOperations().size()) {
            throw new NotFoundException("Unable to find the requested index for undo/redo");
        }
        checkTopologyRecovery();
        if (at == EditionContextManager.get().getLastOperationIndex()) {
            // nothing to change.
            return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
        }
        // TODO Improve this by avoiding dao query for (deep) cloning topology and keeping cache for TOSCA types that are required.
        editionContextManager.reset();
        Topology topology = EditionContextManager.getTopology();
        Csar csar = EditionContextManager.getCsar();
        for (int i = 0; i < at + 1; i++) {
            AbstractEditorOperation operation = EditionContextManager.get().getOperations().get(i);
            IEditorOperationProcessor processor = processorMap.get(operation.getClass());
            processor.process(csar, topology, operation);
        }
        EditionContextManager.get().setLastOperationIndex(at);
        return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
    } catch (IOException e) {
        // FIXME undo should be fail-safe...
        return null;
    } finally {
        EditionContextManager.get().setCurrentOperation(null);
        editionContextManager.destroy();
    }
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) NotFoundException(alien4cloud.exception.NotFoundException) AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) Topology(org.alien4cloud.tosca.model.templates.Topology) IOException(java.io.IOException) EditorIOException(org.alien4cloud.tosca.editor.exception.EditorIOException) IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)

Example 3 with IEditorOperationProcessor

use of org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor 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 4 with IEditorOperationProcessor

use of org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor 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)

Aggregations

IEditorOperationProcessor (org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)4 Topology (org.alien4cloud.tosca.model.templates.Topology)3 AbstractEditorOperation (org.alien4cloud.tosca.editor.operations.AbstractEditorOperation)2 Csar (org.alien4cloud.tosca.model.Csar)2 NotFoundException (alien4cloud.exception.NotFoundException)1 IOException (java.io.IOException)1 PostConstruct (javax.annotation.PostConstruct)1 EditorIOException (org.alien4cloud.tosca.editor.exception.EditorIOException)1 IEditorCommitableProcessor (org.alien4cloud.tosca.editor.processors.IEditorCommitableProcessor)1