use of org.alien4cloud.tosca.editor.exception.EditorIOException in project alien4cloud by alien4cloud.
the class EditorService method save.
/**
* Save a topology under edition. It updates the local repository files, the topology in elastic-search and perform a local git commit.
*
* @param topologyId The id of the topology under edition.
* @param lastOperationId The id of the last operation.
*/
public TopologyDTO save(String topologyId, String lastOperationId) {
try {
initContext(topologyId, lastOperationId);
doSave();
return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
} catch (IOException e) {
// FIXME git revert to put back the local files state in the initial state.
throw new EditorIOException("Error while saving files state in local repository", e);
} finally {
EditionContextManager.get().setCurrentOperation(null);
editionContextManager.destroy();
}
}
use of org.alien4cloud.tosca.editor.exception.EditorIOException in project alien4cloud by alien4cloud.
the class EditorService method pull.
/**
* Performs a git pull.
*/
public TopologyDTO pull(String topologyId, String username, String password, String remoteBranch) {
Path tempPath = null;
try {
editionContextManager.init(topologyId);
Path topologyPath = EditionContextManager.get().getLocalGitPath();
tempPath = Files.createTempDirectory(Paths.get(tempUploadDir), "");
repositoryService.copy(tempPath, EditionContextManager.getCsar());
if (EditionContextManager.get().getLastSavedOperationIndex() == -1) {
repositoryService.clean(tempPath);
}
Topology topology = EditionContextManager.getTopology();
repositoryService.pull(tempPath, EditionContextManager.getCsar(), username, password, remoteBranch);
topologyUploadService.processTopologyDir(tempPath, EditionContextManager.get().getTopology().getWorkspace());
try {
FileUtil.delete(topologyPath);
} catch (IOException e) {
// Ignored
}
FileUtil.copy(tempPath, topologyPath);
repositoryService.updateArchiveZip(EditionContextManager.getCsar().getName(), EditionContextManager.getCsar().getVersion());
// and finally save and commit
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());
return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
} catch (IOException e) {
throw new EditorIOException("Error while pulling remote branch into local repository for " + topologyId + " for user " + username, e);
} finally {
if (tempPath != null) {
try {
FileUtil.delete(tempPath);
} catch (IOException e) {
// Ignored
}
}
editionContextManager.destroy();
}
}
use of org.alien4cloud.tosca.editor.exception.EditorIOException in project alien4cloud by alien4cloud.
the class EditorService method executeAndSave.
/**
* Execute an operation and directly trigger the save process
*
* @param topologyId The id of the topology.
* @param operation The operation to execute.
* @param <T>
* @return a {@link TopologyDTO}
*/
private <T extends AbstractEditorOperation> TopologyDTO executeAndSave(String topologyId, T operation) {
try {
// init the context.
initContext(topologyId, operation);
// execute the operation
doExecute(operation);
// save the context
doSave();
// return the topology DTO
return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
} catch (IOException e) {
// FIXME git revert to put back the local files state in the initial state.
throw new EditorIOException("Error while saving files state in local repository", e);
} finally {
EditionContextManager.get().setCurrentOperation(null);
editionContextManager.destroy();
}
}
Aggregations