use of alien4cloud.events.DeploymentCreatedEvent in project alien4cloud by alien4cloud.
the class DeployService method deploy.
/**
* Deploy a topology and return the deployment ID.
*
* @param deploymentTopology Location aware and matched topology.
* @param deploymentSource Application to be deployed or the Csar that contains test toplogy to be deployed
* @return The id of the generated deployment.
*/
public String deploy(final User deployer, final SecretProviderCredentials secretProviderCredentials, final DeploymentTopology deploymentTopology, IDeploymentSource deploymentSource) {
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deploymentTopology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
final Location firstLocation = locations.values().iterator().next();
String deploymentPaaSId = generateOrchestratorDeploymentId(deploymentTopology.getEnvironmentId(), firstLocation.getOrchestratorId());
return deploymentLockService.doWithDeploymentWriteLock(deploymentPaaSId, () -> {
// Get the orchestrator that will perform the deployment
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(firstLocation.getOrchestratorId());
// Create a deployment object to be kept in ES.
final Deployment deployment = new Deployment();
deployment.setId(UUID.randomUUID().toString());
deployment.setOrchestratorId(firstLocation.getOrchestratorId());
deployment.setLocationIds(locationIds.values().toArray(new String[locationIds.size()]));
deployment.setOrchestratorDeploymentId(deploymentPaaSId);
deployment.setSourceId(deploymentSource.getId());
deployment.setDeployerUsername(deployer.getUsername());
String sourceName;
if (deploymentSource.getName() == null) {
sourceName = UUID.randomUUID().toString();
} else {
sourceName = deploymentSource.getName();
}
deployment.setSourceName(sourceName);
deployment.setSourceType(DeploymentSourceType.fromSourceType(deploymentSource.getClass()));
// mandatory for the moment since we could have deployment with no environment (csar test)
deployment.setEnvironmentId(deploymentTopology.getEnvironmentId());
deployment.setVersionId(deploymentTopology.getVersionId());
deployment.setStartDate(new Date());
setUsedServicesResourcesIds(deploymentTopology, deployment);
alienDao.save(deployment);
// publish an event for the eventual managed service
eventPublisher.publishEvent(new DeploymentCreatedEvent(this, deployment.getId()));
PaaSTopologyDeploymentContext deploymentContext = saveDeploymentTopologyAndGenerateDeploymentContext(secretProviderCredentials, deploymentTopology, deployment, locations);
// Build the context for deployment and deploy
orchestratorPlugin.deploy(deploymentContext, new IPaaSCallback<Object>() {
@Override
public void onSuccess(Object data) {
log.debug("Deployed topology [{}] on location [{}], generated deployment with id [{}]", deploymentTopology.getInitialTopologyId(), firstLocation.getId(), deployment.getId());
}
@Override
public void onFailure(Throwable t) {
log.error("Deployment failed with cause", t);
log(deployment, t);
}
});
log.debug("Triggered deployment of topology [{}] on location [{}], generated deployment with id [{}]", deploymentTopology.getInitialTopologyId(), firstLocation.getId(), deployment.getId());
return deployment.getId();
});
}
Aggregations