use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class CsarService method getDependantTopologies.
/**
* Get teh topologies that depends on this csar.
* Do not return a topology if this csar is his own
*
* @return an array of <code>Topology</code>s that depend on this name:version.
*/
public Topology[] getDependantTopologies(String name, String version) {
FilterBuilder notSelf = FilterBuilders.notFilter(FilterBuilders.andFilter(FilterBuilders.termFilter("archiveName", name), FilterBuilders.termFilter("archiveVersion", version)));
GetMultipleDataResult<Topology> result = csarDAO.buildQuery(Topology.class).prepareSearch().setFilters(fromKeyValueCouples("dependencies.name", name, "dependencies.version", version), notSelf).search(0, Integer.MAX_VALUE);
return result.getData();
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class CsarService method getCsarRelatedResourceList.
/**
* Get the list of resources that are using the given archive.
*
* @param csar The archive for which to get usage.
* @return The list of usage of the archive.
*/
public List<Usage> getCsarRelatedResourceList(Csar csar) {
if (csar == null) {
log.debug("You have requested a resource list for a invalid csar object : <" + csar + ">");
return Lists.newArrayList();
}
ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, csar.getName(), csar.getVersion());
// Archive from applications are used by the application.
if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
// The CSAR is from an application's topology
Application application = applicationService.checkAndGetApplication(csar.getDelegateId());
archiveUsageRequestEvent.addUsage(new Usage(application.getName(), Application.class.getSimpleName().toLowerCase(), csar.getDelegateId(), csar.getWorkspace()));
}
// a csar that is a dependency of another csar can not be deleted
Csar[] relatedCsars = getDependantCsars(csar.getName(), csar.getVersion());
if (ArrayUtils.isNotEmpty(relatedCsars)) {
archiveUsageRequestEvent.addUsages(generateCsarsInfo(relatedCsars));
}
// check if some of the nodes are used in topologies.
Topology[] topologies = getDependantTopologies(csar.getName(), csar.getVersion());
if (topologies != null && topologies.length > 0) {
archiveUsageRequestEvent.addUsages(generateTopologiesInfo(topologies));
}
// a csar that is a dependency of location can not be deleted
Location[] relatedLocations = getDependantLocations(csar.getName(), csar.getVersion());
if (relatedLocations != null && relatedLocations.length > 0) {
archiveUsageRequestEvent.addUsages(generateLocationsInfo(relatedLocations));
}
publisher.publishEvent(archiveUsageRequestEvent);
return archiveUsageRequestEvent.getUsages();
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class EditorNodeReplacementService method getReplacementForNode.
/**
* Utility method to get possible replacement indexedNodeTypes for a node template
*
* @param topologyId The id of the topology for which to find possible nodes replacement.
* @param nodeTemplateName The name of the node template for which to get possible nodes replacement.
* @return An array of possible replacement for a node template.
*/
public NodeType[] getReplacementForNode(String topologyId, String nodeTemplateName) {
try {
editionContextManager.init(topologyId);
// check authorization to update a topology
topologyService.checkEditionAuthorizations(EditionContextManager.getTopology());
Topology topology = EditionContextManager.getTopology();
TopologyUtils.getNodeTemplate(topologyId, nodeTemplateName, TopologyUtils.getNodeTemplates(topology));
return topologyService.findReplacementForNode(nodeTemplateName, topology);
} finally {
editionContextManager.destroy();
}
}
use of org.alien4cloud.tosca.model.templates.Topology 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);
}
use of org.alien4cloud.tosca.model.templates.Topology 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();
}
}
Aggregations