Search in sources :

Example 46 with Topology

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();
}
Also used : FilterBuilder(org.elasticsearch.index.query.FilterBuilder) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 47 with Topology

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();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) ArchiveUsageRequestEvent(org.alien4cloud.tosca.catalog.events.ArchiveUsageRequestEvent) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) Location(alien4cloud.model.orchestrators.locations.Location)

Example 48 with Topology

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();
    }
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 49 with Topology

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);
}
Also used : AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) IEditorCommitableProcessor(org.alien4cloud.tosca.editor.processors.IEditorCommitableProcessor) Topology(org.alien4cloud.tosca.model.templates.Topology) IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)

Example 50 with Topology

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();
    }
}
Also used : Path(java.nio.file.Path) EditorIOException(org.alien4cloud.tosca.editor.exception.EditorIOException) Topology(org.alien4cloud.tosca.model.templates.Topology) IOException(java.io.IOException) EditorIOException(org.alien4cloud.tosca.editor.exception.EditorIOException)

Aggregations

Topology (org.alien4cloud.tosca.model.templates.Topology)79 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)22 Map (java.util.Map)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)17 Csar (org.alien4cloud.tosca.model.Csar)16 Application (alien4cloud.model.application.Application)15 NotFoundException (alien4cloud.exception.NotFoundException)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)9 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 IOException (java.io.IOException)8 List (java.util.List)8 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)8 Component (org.springframework.stereotype.Component)8 Audit (alien4cloud.audit.annotation.Audit)7