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());
}
}
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();
}
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();
}
}
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();
}
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);
}
Aggregations