Search in sources :

Example 66 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class MockPaaSProvider method scale.

@Override
public void scale(PaaSDeploymentContext deploymentContext, String nodeTemplateId, final int instances, IPaaSCallback<?> callback) {
    MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
    if (runtimeDeploymentInfo == null) {
        return;
    }
    Topology topology = runtimeDeploymentInfo.getDeploymentContext().getDeploymentTopology();
    final Map<String, Map<String, InstanceInformation>> existingInformations = runtimeDeploymentInfo.getInstanceInformations();
    if (existingInformations != null && existingInformations.containsKey(nodeTemplateId)) {
        ScalingVisitor scalingVisitor = new ScalingVisitor() {

            @Override
            public void visit(String nodeTemplateId) {
                Map<String, InstanceInformation> nodeInformations = existingInformations.get(nodeTemplateId);
                if (nodeInformations != null) {
                    int currentSize = nodeInformations.size();
                    if (instances > 0) {
                        for (int i = currentSize + 1; i < currentSize + instances + 1; i++) {
                            nodeInformations.put(String.valueOf(i), newInstance(i));
                        }
                    } else {
                        for (int i = currentSize + instances + 1; i < currentSize + 1; i++) {
                            if (nodeInformations.containsKey(String.valueOf(i))) {
                                nodeInformations.get(String.valueOf(i)).setState("stopping");
                                nodeInformations.get(String.valueOf(i)).setInstanceStatus(InstanceStatus.PROCESSING);
                            }
                        }
                    }
                }
            }
        };
        doScaledUpNode(scalingVisitor, nodeTemplateId, topology.getNodeTemplates());
    }
}
Also used : InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map)

Example 67 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class TopologyCatalogController method getVersions.

/**
 * Get all versions of the given topology.
 *
 * @param archiveName The name of the archive for which we want to get versions.
 * @return A {@link RestResponse} that contains an array of {@link CatalogVersionResult} .
 */
@ApiOperation(value = "Get all the versions for a given archive (name)")
@RequestMapping(value = "/{archiveName:.+}/versions", method = RequestMethod.GET)
@PreAuthorize("hasAnyAuthority('ADMIN', 'COMPONENTS_MANAGER', 'COMPONENTS_BROWSER', 'ARCHITECT')")
public RestResponse<CatalogVersionResult[]> getVersions(@PathVariable String archiveName) {
    Topology[] topologies = catalogService.getAll(fromKeyValueCouples(), archiveName);
    if (topologies != null) {
        CatalogVersionResult[] versions = new CatalogVersionResult[topologies.length];
        for (int i = 0; i < topologies.length; i++) {
            Topology topology = topologies[i];
            versions[i] = new CatalogVersionResult(topology.getId(), topology.getArchiveVersion());
        }
        return RestResponseBuilder.<CatalogVersionResult[]>builder().data(versions).build();
    }
    return RestResponseBuilder.<CatalogVersionResult[]>builder().data(new CatalogVersionResult[0]).build();
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class EditorRepositoryController method getAvailableRepositories.

/**
 * Get the available repositories regarding archive repositories and A4C repositories.
 */
@ApiOperation(value = "Get the available repositories regarding archive repositories and A4C repositories", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ]")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<AvailableTopologyRepositories> getAvailableRepositories(@ApiParam(value = "The topology id.", required = true) @NotBlank @PathVariable final String topologyId) {
    try {
        editionContextManager.init(topologyId);
        Topology topology = EditionContextManager.getTopology();
        List<AvailableTopologyRepository> archiveRepositories = Lists.newArrayList();
        List<AvailableTopologyRepository> alienRepositories = Lists.newArrayList();
        List<String> repositoryTypes = Lists.newArrayList();
        AvailableTopologyRepositories result = new AvailableTopologyRepositories(archiveRepositories, alienRepositories, repositoryTypes);
        Set<String> repositoriesName = Sets.newHashSet();
        Set<String> repositoriesUrl = Sets.newHashSet();
        for (NodeTemplate node : topology.getNodeTemplates().values()) {
            if (node.getArtifacts() != null && CollectionUtils.isNotEmpty(node.getArtifacts().values())) {
                for (DeploymentArtifact artifact : node.getArtifacts().values()) {
                    if (artifact.getRepositoryURL() != null && !repositoriesName.contains(artifact.getRepositoryName())) {
                        AvailableTopologyRepository atr = new AvailableTopologyRepository(artifact.getRepositoryName(), artifact.getArtifactRepository(), artifact.getRepositoryURL());
                        archiveRepositories.add(atr);
                        repositoriesName.add(artifact.getRepositoryName());
                        repositoriesUrl.add(artifact.getRepositoryURL());
                    }
                }
            }
        }
        FilteredSearchRequest searchRequest = new FilteredSearchRequest();
        searchRequest.setFrom(0);
        searchRequest.setSize(Integer.MAX_VALUE);
        FacetedSearchResult<Repository> searchResult = repositoryService.search(searchRequest);
        for (Repository repository : searchResult.getData()) {
            String url = repositoryService.getRepositoryUrl(repository);
            if (!repositoriesUrl.contains(url)) {
                // only return this repository if it's url doesn't not match existing archive repository url
                AvailableTopologyRepository atr = new AvailableTopologyRepository(repository.getName(), repository.getRepositoryType(), url);
                alienRepositories.add(atr);
            }
        }
        List<RepositoryPluginComponent> plugins = repositoryService.listPluginComponents();
        for (RepositoryPluginComponent repositoryPluginComponent : plugins) {
            repositoryTypes.add(repositoryPluginComponent.getRepositoryType());
        }
        return RestResponseBuilder.<AvailableTopologyRepositories>builder().data(result).build();
    } finally {
        ToscaContext.destroy();
    }
}
Also used : RepositoryPluginComponent(alien4cloud.repository.model.RepositoryPluginComponent) AvailableTopologyRepositories(alien4cloud.repository.model.AvailableTopologyRepositories) Topology(org.alien4cloud.tosca.model.templates.Topology) FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) Repository(alien4cloud.model.repository.Repository) AvailableTopologyRepository(alien4cloud.repository.model.AvailableTopologyRepository) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) AvailableTopologyRepository(alien4cloud.repository.model.AvailableTopologyRepository) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class ToscaContextualAspect method findDependencies.

private Set<CSARDependency> findDependencies(Object[] args) {
    for (Object arg : args) {
        if (arg instanceof Topology) {
            return ((Topology) arg).getDependencies();
        }
        if (arg instanceof Set) {
            Set set = (Set) arg;
            if (set.size() > 0 && set.iterator().next() instanceof CSARDependency) {
                return (Set<CSARDependency>) arg;
            }
        }
        if (arg instanceof AbstractToscaType) {
            AbstractToscaType type = ((AbstractToscaType) arg);
            Csar csar = csarRepositorySearchService.getArchive(type.getArchiveName(), type.getArchiveVersion());
            if (csar == null) {
                throw new NotFoundException("Unable to find dependencies from type as it's archive cannot be found in the repository.");
            }
            Set<CSARDependency> dependencies = csar.getDependencies() == null ? Sets.newHashSet() : csar.getDependencies();
            dependencies.add(new CSARDependency(type.getArchiveName(), type.getArchiveVersion()));
            return dependencies;
        }
    }
    return Sets.<CSARDependency>newHashSet();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NotFoundException(alien4cloud.exception.NotFoundException) Topology(org.alien4cloud.tosca.model.templates.Topology) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 70 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method deploy.

/**
 * Trigger deployment of the application on the current configured PaaS.
 *
 * @param deployApplicationRequest application details for deployment (applicationId + deploymentProperties)
 * @return An empty rest response.
 */
@ApiOperation(value = "Deploys the application on the configured Cloud.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/deployment", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "secretProviderCredentials" })
public RestResponse<?> deploy(@Valid @RequestBody DeployApplicationRequest deployApplicationRequest) {
    String applicationId = deployApplicationRequest.getApplicationId();
    String environmentId = deployApplicationRequest.getApplicationEnvironmentId();
    Application application = applicationService.checkAndGetApplication(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, environmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Unable to find environment with id <" + environmentId + "> for application <" + applicationId + ">");
    }
    // Security check user must be authorized to deploy the environment (or be application manager)
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    // ensure deployment status is sync with underlying orchestrator
    applicationEnvironmentService.getStatus(environment);
    // check that the environment is not already deployed
    boolean isEnvironmentDeployed = applicationEnvironmentService.isDeployed(environment.getId());
    if (isEnvironmentDeployed) {
        throw new AlreadyExistException("Environment with id <" + environmentId + "> for application <" + applicationId + "> is already deployed");
    }
    // prepare the deployment
    ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
    Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
    return toscaContextualAspect.execInToscaContext(() -> doDeploy(deployApplicationRequest, application, environment, topology), false, topology);
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) AlreadyExistException(alien4cloud.exception.AlreadyExistException) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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