Search in sources :

Example 1 with UpdateFileOperation

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

the class EditorStepDefs method i_upload_a_file_located_at_to_the_archive_path.

@Given("^I upload a file located at \"(.*?)\" to the archive path \"(.*?)\"$")
public void i_upload_a_file_located_at_to_the_archive_path(String filePath, String archiveTargetPath) throws Throwable {
    UpdateFileOperation updateFileOperation = new UpdateFileOperation(archiveTargetPath, Files.newInputStream(Paths.get(filePath)));
    doExecuteOperation(updateFileOperation);
}
Also used : UpdateFileOperation(org.alien4cloud.tosca.editor.operations.UpdateFileOperation) Given(cucumber.api.java.en.Given)

Example 2 with UpdateFileOperation

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

the class RenameInputProcessor method renamePreconfiguredInput.

/**
 * Rename the preconfigured input entry in the inputs file
 *
 * @param csar
 * @param topology
 * @param operation
 */
private void renamePreconfiguredInput(Csar csar, Topology topology, RenameInputOperation operation) {
    Map<String, Object> variables = editorFileService.loadInputsVariables(csar.getId());
    if (!variables.containsKey(operation.getInputName())) {
        return;
    }
    Object value = variables.remove(operation.getInputName());
    variables.put(operation.getNewInputName(), value);
    UpdateFileOperation updateFileOperation = new UpdateFileOperation(quickFileStorageService.getRelativeInputsFilePath(), new ByteArrayInputStream(YamlParserUtil.dumpAsMap(variables).getBytes(StandardCharsets.UTF_8)));
    updateFileProcessor.process(csar, topology, updateFileOperation);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UpdateFileOperation(org.alien4cloud.tosca.editor.operations.UpdateFileOperation)

Example 3 with UpdateFileOperation

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

the class EditionContextManager method setup.

@PostConstruct
public void setup() {
    // initialize the cache
    contextCache = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).removalListener(new RemovalListener<String, EditionContext>() {

        @Override
        public void onRemoval(RemovalNotification<String, EditionContext> removalNotification) {
            log.debug("Topology edition context with id {} has been evicted. {} pending operations are lost.", removalNotification.getKey(), removalNotification.getValue().getOperations().size());
            for (AbstractEditorOperation operation : removalNotification.getValue().getOperations()) {
                if (operation instanceof UpdateFileOperation) {
                    String fileId = ((UpdateFileOperation) operation).getTempFileId();
                    if (artifactRepository.isFileExist(fileId)) {
                        artifactRepository.deleteFile(fileId);
                    }
                }
            }
        }
    }).build(new CacheLoader<String, EditionContext>() {

        @Override
        public EditionContext load(String csarId) throws Exception {
            log.debug("Loading edition context for archive {}", csarId);
            Csar csar = csarService.getOrFail(csarId);
            Topology topology = topologyServiceCore.getOrFail(csarId);
            // check if the topology git repository has been created already
            Path topologyGitPath = repositoryService.createGitDirectory(csar);
            log.debug("Edition context for archive {} loaded", csar);
            return new EditionContext(csar, topology, topologyGitPath);
        }
    });
}
Also used : Path(java.nio.file.Path) Csar(org.alien4cloud.tosca.model.Csar) UpdateFileOperation(org.alien4cloud.tosca.editor.operations.UpdateFileOperation) AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) Topology(org.alien4cloud.tosca.model.templates.Topology) PostConstruct(javax.annotation.PostConstruct)

Example 4 with UpdateFileOperation

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

the class EditorController method upload.

/**
 * Method exposed to REST to upload a file in an archive under edition.
 *
 * @param topologyId The id of the topology/archive under edition.
 * @param lastOperationId The id of the user last known operation (for optimistic locking edition).
 * @param path The path in which to save/override the file in the archive.
 * @param file The file to save in the archive.
 */
@ApiIgnore
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{topologyId:.+}/upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<TopologyDTO> upload(@PathVariable String topologyId, @RequestParam("lastOperationId") String lastOperationId, @RequestParam("path") String path, @RequestParam(value = "file") MultipartFile file) throws IOException {
    if (lastOperationId != null && "null".equals(lastOperationId)) {
        lastOperationId = null;
    }
    try (InputStream artifactStream = file.getInputStream()) {
        UpdateFileOperation updateFileOperation = new UpdateFileOperation(path, artifactStream);
        updateFileOperation.setPreviousOperationId(lastOperationId);
        TopologyDTO topologyDTO = editorService.execute(topologyId, updateFileOperation);
        return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTO).build();
    }
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) InputStream(java.io.InputStream) UpdateFileOperation(org.alien4cloud.tosca.editor.operations.UpdateFileOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UpdateFileOperation (org.alien4cloud.tosca.editor.operations.UpdateFileOperation)4 TopologyDTO (alien4cloud.topology.TopologyDTO)1 Given (cucumber.api.java.en.Given)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 PostConstruct (javax.annotation.PostConstruct)1 AbstractEditorOperation (org.alien4cloud.tosca.editor.operations.AbstractEditorOperation)1 Csar (org.alien4cloud.tosca.model.Csar)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ApiIgnore (springfox.documentation.annotations.ApiIgnore)1