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);
}
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);
}
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);
}
});
}
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();
}
}
Aggregations