Search in sources :

Example 1 with PaaSTopologyDeploymentContext

use of alien4cloud.paas.model.PaaSTopologyDeploymentContext in project yorc-a4c-plugin by ystia.

the class YorcPaaSProvider method init.

// ------------------------------------------------------------------------------------------------------
// IPaaSProvider implementation
// ------------------------------------------------------------------------------------------------------
/**
 * This method is called by Alien in order to restore the state of the paaS provider after a restart.
 * The provider must implement this method in order to restore its state
 *
 * @param activeDeployments the currently active deployments that Alien has
 */
@Override
public void init(Map<String, PaaSTopologyDeploymentContext> activeDeployments) {
    log.info("Init plugin for " + activeDeployments.size() + " active deployments");
    // Update deployment info for all active deployments
    for (Map.Entry<String, PaaSTopologyDeploymentContext> entry : activeDeployments.entrySet()) {
        String key = entry.getKey();
        PaaSTopologyDeploymentContext ctx = entry.getValue();
        log.info("Active deployment: " + key);
        doUpdateDeploymentInfo(ctx);
    }
    // prov
    log.info(fileRepository.getRootPath().toString());
    // Listen Events and logs from yorc about the deployment
    log.info("Starting Yorc events & logs listeners");
    addTask(new EventListenerTask(this));
    addTask(new LogListenerTask(this));
}
Also used : PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) Map(java.util.Map)

Example 2 with PaaSTopologyDeploymentContext

use of alien4cloud.paas.model.PaaSTopologyDeploymentContext in project alien4cloud by alien4cloud.

the class DeploymentContextService method buildTopologyDeploymentContext.

/**
 * Build a topology deployment context from a given topology and deployment.
 *
 * @param deployment The deployment object.
 * @param topology The topology that will be processed.
 * @return A PaaSTopologyDeploymentContext matching the input topology.
 */
public PaaSTopologyDeploymentContext buildTopologyDeploymentContext(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, Deployment deployment, Map<String, Location> locations, DeploymentTopology topology) {
    PaaSTopology paaSTopology = topologyTreeBuilderService.buildPaaSTopology(topology);
    PaaSTopologyDeploymentContext topologyDeploymentContext = new PaaSTopologyDeploymentContext();
    topologyDeploymentContext.setLocations(locations);
    topologyDeploymentContext.setDeployment(deployment);
    topologyDeploymentContext.setPaaSTopology(paaSTopology);
    topologyDeploymentContext.setDeploymentTopology(topology);
    topologyDeploymentContext.setDeployment(deployment);
    topologyDeploymentContext.setSecretProviderConfigurationAndCredentials(secretProviderConfigurationAndCredentials);
    return topologyDeploymentContext;
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext)

Example 3 with PaaSTopologyDeploymentContext

use of alien4cloud.paas.model.PaaSTopologyDeploymentContext 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();
    });
}
Also used : DeploymentCreatedEvent(alien4cloud.events.DeploymentCreatedEvent) PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) Deployment(alien4cloud.model.deployment.Deployment) Date(java.util.Date) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Location(alien4cloud.model.orchestrators.locations.Location)

Example 4 with PaaSTopologyDeploymentContext

use of alien4cloud.paas.model.PaaSTopologyDeploymentContext 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;
    });
}
Also used : IPaaSCallback(alien4cloud.paas.IPaaSCallback) PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Location(alien4cloud.model.orchestrators.locations.Location) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 5 with PaaSTopologyDeploymentContext

use of alien4cloud.paas.model.PaaSTopologyDeploymentContext in project alien4cloud by alien4cloud.

the class DeployService method saveDeploymentTopologyAndGenerateDeploymentContext.

private PaaSTopologyDeploymentContext saveDeploymentTopologyAndGenerateDeploymentContext(final SecretProviderCredentials secretProviderCredentials, final DeploymentTopology deploymentTopology, final Deployment deployment, final Map<String, Location> locations) {
    String deploymentTopologyId = deploymentTopology.getId();
    // save the topology as a deployed topology.
    // change the Id before saving
    deploymentTopology.setId(deployment.getId());
    deploymentTopology.setDeployed(true);
    alienMonitorDao.save(deploymentTopology);
    // put back the old Id for deployment
    deploymentTopology.setId(deploymentTopologyId);
    SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials = null;
    if (secretProviderCredentials != null) {
        secretProviderConfigurationAndCredentials = secretProviderService.generateToken(locations, secretProviderCredentials.getPluginName(), secretProviderCredentials.getCredentials());
    }
    PaaSTopologyDeploymentContext deploymentContext = deploymentContextService.buildTopologyDeploymentContext(secretProviderConfigurationAndCredentials, deployment, locations, deploymentTopology);
    // Process services relationships to inject the service side based on the service resource.
    serviceResourceRelationshipService.process(deploymentContext);
    // Download and process all remote artifacts before deployment
    artifactProcessorService.processArtifacts(deploymentContext);
    return deploymentContext;
}
Also used : PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)

Aggregations

PaaSTopologyDeploymentContext (alien4cloud.paas.model.PaaSTopologyDeploymentContext)8 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)3 Deployment (alien4cloud.model.deployment.Deployment)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 Location (alien4cloud.model.orchestrators.locations.Location)2 Map (java.util.Map)2 ArtifactRepositoryConstants (alien4cloud.component.repository.ArtifactRepositoryConstants)1 IFileRepository (alien4cloud.component.repository.IFileRepository)1 UnresolvableArtifactException (alien4cloud.deployment.exceptions.UnresolvableArtifactException)1 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)1 DeploymentCreatedEvent (alien4cloud.events.DeploymentCreatedEvent)1 NotFoundException (alien4cloud.exception.NotFoundException)1 IPaaSCallback (alien4cloud.paas.IPaaSCallback)1 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)1 PaaSTopology (alien4cloud.paas.model.PaaSTopology)1 RepositoryService (alien4cloud.repository.services.RepositoryService)1 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)1 FileUtil (alien4cloud.utils.FileUtil)1 IOException (java.io.IOException)1