use of alien4cloud.model.deployment.DeploymentTopology in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method scale.
/**
* Scale up/down a node in a topology
*
* @param applicationEnvironmentId id of the targeted environment
* @param nodeTemplateId id of the compute node to scale up
* @param instances the number of instances to be added (if positive) or removed (if negative)
*/
public void scale(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, String applicationEnvironmentId, final String nodeTemplateId, int instances, final IPaaSCallback<Object> callback) throws OrchestratorDisabledException {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
final DeploymentTopology topology = alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
toscaContextualAspect.execInToscaContext(() -> {
doScale(nodeTemplateId, instances, callback, deployment, topology, secretProviderConfigurationAndCredentials);
return null;
}, false, topology);
}
use of alien4cloud.model.deployment.DeploymentTopology in project alien4cloud by alien4cloud.
the class WorkflowExecutionService method launchWorkflow.
/**
* Launch a given workflow.
*/
public synchronized void launchWorkflow(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, String applicationEnvironmentId, String workflowName, Map<String, Object> params, IPaaSCallback<?> iPaaSCallback) {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
final DeploymentTopology topology = alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
// get the secret provider configuration from the location
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(topology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
SecretProviderConfigurationAndCredentials authResponse = null;
if (secretProviderService.isSecretProvided(secretProviderConfigurationAndCredentials)) {
authResponse = secretProviderService.generateToken(locations, secretProviderConfigurationAndCredentials.getSecretProviderConfiguration().getPluginName(), secretProviderConfigurationAndCredentials.getCredentials());
}
PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, deploymentTopology, authResponse);
orchestratorPlugin.launchWorkflow(deploymentContext, workflowName, params, iPaaSCallback);
}
use of alien4cloud.model.deployment.DeploymentTopology in project alien4cloud by alien4cloud.
the class ManagedServiceResourceEventService method updateRunningService.
private void updateRunningService(ServiceResource serviceResource, String deploymentId, String state) {
Deployment deployment = deploymentService.get(deploymentId);
if (deployment == null) {
log.error("Unable to update service [ {} ] as deployment [ {} ] cannot be found.", serviceResource.getId(), deploymentId);
resetRunningServiceResource(serviceResource);
return;
}
DeploymentTopology topology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
updateRunningService(topology, serviceResource, deployment, state);
}
use of alien4cloud.model.deployment.DeploymentTopology in project alien4cloud by alien4cloud.
the class ManagedServiceResourceService method create.
/**
* Create a Service resource associated with the given environment.
*
* @param environmentId The environment to create a service for, the service version will be the one of the environment current associated version.
* @param serviceName The name of the service as it should appears.
* @param fromRuntime If we should try to create the service from the runtime topology related to the environment.
* @return the id of the created service
*
* @throws AlreadyExistException if a service with the given name, or related to the given environment already exists
* @throws alien4cloud.exception.NotFoundException if <b>fromRuntime</b> is set to true, but the environment is not deployed
* @throws MissingSubstitutionException if topology related to the environment doesn't define a substitution type
*/
public synchronized String create(String serviceName, String environmentId, boolean fromRuntime) {
ApplicationEnvironment environment = checkAndGetApplicationEnvironment(environmentId);
// check that the service does not exists already for this environment
if (alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("environmentId", environmentId)).count() > 0) {
throw new AlreadyExistException("A service resource for environment <" + environmentId + "> and version <" + environment.getTopologyVersion() + "> already exists.");
}
Topology topology;
String state = ToscaNodeLifecycleConstants.INITIAL;
Deployment deployment = null;
if (fromRuntime) {
deployment = deploymentService.getActiveDeploymentOrFail(environmentId);
topology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
DeploymentStatus currentStatus = deploymentRuntimeStateService.getDeploymentStatus(deployment);
state = managedServiceResourceEventService.getInstanceStateFromDeploymentStatus(currentStatus);
if (state == null) {
// We need a valid deployment state to expose as service.
throw new InvalidDeploymentStatusException("Creating a service out of a running deployment is possible only when it's status is one of [DEPLOYED, FAILURE, UNDEPLOYED] current was <" + currentStatus + ">", currentStatus);
}
} else {
topology = topologyServiceCore.getOrFail(Csar.createId(environment.getApplicationId(), environment.getTopologyVersion()));
}
if (topology.getSubstitutionMapping() == null) {
throw new MissingSubstitutionException("Substitution is required to expose a topology.");
}
// The elementId of the type created out of the substitution is currently the archive name.
String serviceId = serviceResourceService.create(serviceName, environment.getTopologyVersion(), topology.getArchiveName(), environment.getTopologyVersion(), environmentId);
// Update the service relationships definition from the topology substitution
updateServiceRelationship(serviceId, topology);
if (fromRuntime) {
managedServiceResourceEventService.updateRunningService((DeploymentTopology) topology, serviceResourceService.getOrFail(serviceId), deployment, state);
}
ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
// trigger a ManagedServiceCreatedEvent
publisher.publishEvent(new ManagedServiceCreatedEvent(this, serviceResource));
return serviceId;
}
use of alien4cloud.model.deployment.DeploymentTopology in project alien4cloud by alien4cloud.
the class DeployService method update.
public void update(SecretProviderCredentials secretProviderCredentials, final DeploymentTopology deploymentTopology, final IDeploymentSource deploymentSource, final Deployment existingDeployment, final IPaaSCallback<Object> callback) {
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deploymentTopology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
final Location firstLocation = locations.values().iterator().next();
deploymentLockService.doWithDeploymentWriteLock(existingDeployment.getOrchestratorDeploymentId(), () -> {
// Get the orchestrator that will perform the deployment
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(firstLocation.getOrchestratorId());
PaaSTopologyDeploymentContext deploymentContext = saveDeploymentTopologyAndGenerateDeploymentContext(secretProviderCredentials, deploymentTopology, existingDeployment, locations);
// After update we allow running a post_update workflow automatically, however as adding workflow in update depends on orchestrator we have to check
// if such option is possible on the selected orchestrator.
final DeploymentTopology deployedTopology = alienMonitorDao.findById(DeploymentTopology.class, existingDeployment.getId());
// enrich the callback
IPaaSCallback<Object> callbackWrapper = new IPaaSCallback<Object>() {
@Override
public void onSuccess(Object data) {
existingDeployment.setVersionId(deploymentTopology.getVersionId());
alienDao.save(existingDeployment);
// Trigger post update workflow if defined in both the initial and current topologies.
if (deploymentTopology.getWorkflows().get(NormativeWorkflowNameConstants.POST_UPDATE) != null && deployedTopology.getWorkflows().get(NormativeWorkflowNameConstants.POST_UPDATE) != null) {
scheduler.execute(() -> tryLaunchingPostUpdateWorkflow(System.currentTimeMillis(), existingDeployment, orchestratorPlugin, deploymentContext, callback));
}
}
@Override
public void onFailure(Throwable throwable) {
log(existingDeployment, throwable);
callback.onFailure(throwable);
}
};
// Build the context for deployment and deploy
orchestratorPlugin.update(deploymentContext, callbackWrapper);
log.debug("Triggered deployment of topology [{}] on location [{}], generated deployment with id [{}]", deploymentTopology.getInitialTopologyId(), firstLocation.getId(), existingDeployment.getId());
return null;
});
}
Aggregations