use of org.alien4cloud.tosca.model.templates.Topology 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);
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class EditorService method override.
/**
* Override the content of an archive from a full exising archive.
*
* @param topologyId The if of the topology to process.
* @param inputStream The input stream of the file that contains the archive.
*/
public void override(String topologyId, InputStream inputStream) throws IOException {
Path tempPath = null;
try {
// Initialize the editon context, null last operation id means that we just accept a context with no pending operations
initContext(topologyId, (String) null);
// first we need to copy the content to a temporary location, unzip and parse the archive
tempPath = Files.createTempFile(Paths.get(tempUploadDir), "", null);
Files.copy(inputStream, tempPath, StandardCopyOption.REPLACE_EXISTING);
// This throws an exception if not successful
topologyUploadService.processTopology(tempPath, EditionContextManager.get().getTopology().getWorkspace());
// meaning the topology is well imported in the editor context: override all the content of the git repository
// erase all content but .git directory
FileUtil.delete(EditionContextManager.get().getLocalGitPath(), EditionContextManager.get().getLocalGitPath().resolve(".git"));
// copy the archive content
if (isZipFile(tempPath)) {
// unzip the content
FileUtil.unzip(tempPath, EditionContextManager.get().getLocalGitPath());
} else {
// just copy the file
Path targetPath = EditionContextManager.get().getLocalGitPath().resolve(tempPath.getFileName());
Files.copy(tempPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
// and finally save and commit
Topology topology = EditionContextManager.getTopology();
String commitMessage = AuthorizationUtil.getCurrentUser().getUserId() + ": Override all content of the topology archive from REST API.";
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());
// Local git commit
repositoryService.commit(EditionContextManager.get().getCsar(), commitMessage);
} finally {
EditionContextManager.get().setCurrentOperation(null);
editionContextManager.destroy();
}
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class ArchiveIndexer method indexTopology.
private void indexTopology(final ArchiveRoot archiveRoot, List<ParsingError> parsingErrors, String archiveName, String archiveVersion) {
Topology topology = archiveRoot.getTopology();
if (topology == null || topology.isEmpty()) {
return;
}
topology.setTags(archiveRoot.getArchive().getTags());
if (archiveRoot.hasToscaTypes()) {
// The archive contains types, we assume those types are used in the embedded topology so we add the dependency to this CSAR
CSARDependency selfDependency = new CSARDependency(archiveRoot.getArchive().getName(), archiveRoot.getArchive().getVersion(), archiveRoot.getArchive().getHash());
topology.getDependencies().add(selfDependency);
}
// init the workflows
TopologyContext topologyContext = workflowBuilderService.buildCachedTopologyContext(new TopologyContext() {
@Override
public String getDSLVersion() {
return archiveRoot.getArchive().getToscaDefinitionsVersion();
}
@Override
public Topology getTopology() {
return topology;
}
@Override
public <T extends AbstractToscaType> T findElement(Class<T> clazz, String elementId) {
return ToscaContext.get(clazz, elementId);
}
});
workflowBuilderService.initWorkflows(topologyContext);
parsingErrors.add(new ParsingError(ParsingErrorLevel.INFO, ErrorCode.TOPOLOGY_DETECTED, "", null, "A topology template has been detected", null, archiveName));
topologyServiceCore.saveTopology(topology);
topologySubstitutionService.updateSubstitutionType(topology, archiveRoot.getArchive());
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class RemoveWorkflowProcessor method processWorkflowOperation.
@Override
protected void processWorkflowOperation(Csar csar, Topology topology, RemoveWorkflowOperation operation, Workflow workflow) {
ensureNotStandard(workflow, "standard workflow <" + workflow.getName() + "> can not be removed");
log.debug("removing workflow [ {} ] from topology [ {} ]", operation.getWorkflowName(), topology.getId());
topology.getWorkflows().remove(operation.getWorkflowName());
topology.getWorkflows().values().forEach(wf -> wf.getSteps().values().forEach(step -> {
if (step.getActivity() instanceof InlineWorkflowActivity) {
InlineWorkflowActivity inlineWorkflowActivity = (InlineWorkflowActivity) step.getActivity();
if (inlineWorkflowActivity.getInline().equals(workflow.getName())) {
throw new BadWorkflowOperationException("Workflow " + inlineWorkflowActivity.getInline() + " is inlined in workflow " + wf.getName() + " in step " + step.getName());
}
}
}));
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class EditorStepDefs method i_create_an_empty_topology_template_version.
@Given("^I create an empty topology template \"([^\"]*)\" version \"([^\"]*)\"$")
public void i_create_an_empty_topology_template_version(String topologyTemplateName, String version) throws Throwable {
try {
Topology topology = catalogService.createTopologyAsTemplate(topologyTemplateName, null, version, AlienConstants.GLOBAL_WORKSPACE_ID, null);
topologyIds.addLast(topology.getId());
topologyEvaluationContext = new StandardEvaluationContext(topology);
} catch (Exception e) {
log.error("Exception occurred while creating a topology template", e);
thrownException = e;
exceptionEvaluationContext = new StandardEvaluationContext(e);
}
}
Aggregations