Search in sources :

Example 16 with IOrchestratorPlugin

use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.

the class DeploymentRuntimeService method doScaleNode.

private void doScaleNode(final String nodeTemplateId, final int instances, final IPaaSCallback<Object> callback, final Deployment deployment, final DeploymentTopology topology, NodeTemplate nodeTemplate, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
    final Capability capability = NodeTemplateUtils.getCapabilityByTypeOrFail(nodeTemplate, NormativeCapabilityTypes.SCALABLE);
    final int previousInitialInstances = TopologyUtils.getScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, capability);
    final int newInitialInstances = previousInitialInstances + instances;
    log.info("Scaling [ {} ] node from [ {} ] to [ {} ]. Updating runtime topology...", nodeTemplateId, previousInitialInstances, newInitialInstances);
    TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, newInitialInstances, capability);
    alienMonitorDao.save(topology);
    IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
    PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, topology, secretProviderConfigurationAndCredentials);
    orchestratorPlugin.scale(deploymentContext, nodeTemplateId, instances, new IPaaSCallback() {

        @Override
        public void onFailure(Throwable throwable) {
            log.info("Failed to scale [ {} ] node from [ {} ] to [ {} ]. rolling back to {}...", nodeTemplateId, previousInitialInstances, newInitialInstances, previousInitialInstances);
            TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, previousInitialInstances, capability);
            alienMonitorDao.save(topology);
            callback.onFailure(throwable);
        }

        @Override
        public void onSuccess(Object data) {
            callback.onSuccess(data);
        }
    });
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) IPaaSCallback(alien4cloud.paas.IPaaSCallback) Capability(org.alien4cloud.tosca.model.templates.Capability) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 17 with IOrchestratorPlugin

use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.

the class DeploymentRuntimeService method triggerOperationExecution.

/**
 * Trigger the execution of an operation on a node.
 *
 * @param request the operation's execution description ( see {@link alien4cloud.paas.model.OperationExecRequest})
 * @param callback the callback when execution finishes
 * @throws alien4cloud.paas.exception.OperationExecutionException runtime exception during an operation
 */
public void triggerOperationExecution(OperationExecRequest request, IPaaSCallback<Map<String, String>> callback) throws OperationExecutionException {
    PaaSTopologyDeploymentContext context = buildPaaSTopologyDeploymentContext(request);
    IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(context.getDeployment().getOrchestratorId());
    orchestratorPlugin.executeOperation(context, request, callback);
}
Also used : PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 18 with IOrchestratorPlugin

use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.

the class DeploymentRuntimeStateService method getDeploymentStatus.

/**
 * Get the current deployment status for a topology.
 *
 * @param deployment deployment for which we want the status.
 * @param callback that will be called when status is available
 * @return The status of the topology.
 * @throws alien4cloud.paas.exception.OrchestratorDisabledException In case the cloud selected for the topology is disabled.
 */
public void getDeploymentStatus(final Deployment deployment, final IPaaSCallback<DeploymentStatus> callback) throws OrchestratorDisabledException {
    deploymentLockService.doWithDeploymentReadLock(deployment.getOrchestratorDeploymentId(), () -> {
        if (deployment == null) {
            callback.onSuccess(DeploymentStatus.UNDEPLOYED);
            return null;
        }
        IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
        PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, getRuntimeTopology(deployment.getId()), null);
        IPaaSCallback<DeploymentStatus> esCallback = new IPaaSCallback<DeploymentStatus>() {

            @Override
            public void onSuccess(DeploymentStatus data) {
                callback.onSuccess(data);
            }

            @Override
            public void onFailure(Throwable throwable) {
                callback.onFailure(throwable);
            }
        };
        orchestratorPlugin.getStatus(deploymentContext, esCallback);
        return null;
    });
}
Also used : IPaaSCallback(alien4cloud.paas.IPaaSCallback) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 19 with IOrchestratorPlugin

use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.

the class UndeployService method undeploy.

private void undeploy(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, final Deployment deployment) {
    deploymentLockService.doWithDeploymentWriteLock(deployment.getOrchestratorDeploymentId(), () -> {
        log.info("Un-deploying deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
        IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
        DeploymentTopology deployedTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
        Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deployedTopology);
        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, deployedTopology, authResponse);
        orchestratorPlugin.undeploy(deploymentContext, new IPaaSCallback<ResponseEntity>() {

            @Override
            public void onSuccess(ResponseEntity data) {
                deploymentService.markUndeployed(deployment);
                log.info("Un-deployed deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
            }

            @Override
            public void onFailure(Throwable throwable) {
                log.warn("Fail while Undeploying deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
            }
        });
        return null;
    });
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) ResponseEntity(org.springframework.http.ResponseEntity) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Location(alien4cloud.model.orchestrators.locations.Location)

Example 20 with IOrchestratorPlugin

use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.

the class LocationService method autoConfigure.

/**
 * This method calls the orchestrator plugin to try to auto-configure the
 *
 * @param orchestrator The orchestrator for which to auto-configure a location.
 * @param location The location to auto-configure
 * @return the List of {@link LocationResourceTemplate} generated from the location auto-configuration call, null is a valid answer.
 */
private List<LocationResourceTemplate> autoConfigure(Orchestrator orchestrator, Location location) throws UnsupportedOperationException {
    // get the orchestrator plugin instance
    IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    ILocationResourceAccessor accessor = locationResourceService.accessor(location.getId());
    // let's try to auto-configure the location
    List<LocationResourceTemplate> templates = configuratorPlugin.instances(accessor);
    if (templates != null) {
        // save the instances
        for (LocationResourceTemplate template : templates) {
            // initialize the instances from data.
            template.setId(UUID.randomUUID().toString());
            template.setLocationId(location.getId());
            template.setGenerated(true);
            template.setEnabled(true);
            NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, template.getTemplate().getType(), location.getDependencies());
            nodeType.getDerivedFrom().add(0, template.getTemplate().getType());
            template.setTypes(nodeType.getDerivedFrom());
            LocationTemplateCreated event = new LocationTemplateCreated(this);
            event.setTemplate(template);
            event.setLocation(location);
            event.setToscaType(nodeType);
            applicationContext.publishEvent(event);
        }
        alienDAO.save(templates.toArray(new LocationResourceTemplate[templates.size()]));
        alienDAO.save(location);
    }
    return templates;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) NodeType(org.alien4cloud.tosca.model.types.NodeType) LocationTemplateCreated(alien4cloud.events.LocationTemplateCreated) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Aggregations

IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)22 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)6 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)6 Deployment (alien4cloud.model.deployment.Deployment)5 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)5 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)5 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)5 Location (alien4cloud.model.orchestrators.locations.Location)4 OrchestratorConfiguration (alien4cloud.model.orchestrators.OrchestratorConfiguration)3 IPaaSCallback (alien4cloud.paas.IPaaSCallback)3 PaaSTopologyDeploymentContext (alien4cloud.paas.model.PaaSTopologyDeploymentContext)3 Map (java.util.Map)3 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2 Test (org.junit.Test)2 DeploymentCreatedEvent (alien4cloud.events.DeploymentCreatedEvent)1 LocationTemplateCreated (alien4cloud.events.LocationTemplateCreated)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 Usage (alien4cloud.model.common.Usage)1