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