use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class UndeployService method undeploy.
/**
* Un-deploy from a deployment setup.
*
* @param deploymentTopology setup object containing information to deploy
*/
public void undeploy(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, DeploymentTopology deploymentTopology) {
Deployment activeDeployment = deploymentService.getActiveDeploymentOrFail(deploymentTopology.getEnvironmentId());
undeploy(secretProviderConfigurationAndCredentials, activeDeployment);
}
use of alien4cloud.model.deployment.Deployment 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.Deployment 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.Deployment in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method switchMaintenanceMode.
/**
* Switch all instances in a deployment to maintenance mode. If so the orchestrator should not perform self healing operations for this instance.
*
* @param applicationEnvironmentId The id of the application environment.
* @param maintenanceModeOn true if we should enable the maintenance mode, false if we should disable it.
* @throws MaintenanceModeException In case the operation fails.
*/
public void switchMaintenanceMode(String applicationEnvironmentId, boolean maintenanceModeOn) throws MaintenanceModeException {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, deploymentTopology, null);
orchestratorPlugin.switchMaintenanceMode(deploymentContext, maintenanceModeOn);
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method buildPaaSTopologyDeploymentContext.
/**
* Build the deployment context from an operation execution request
*
* @param request the operation execution request
* @return the deployment context
*/
public PaaSTopologyDeploymentContext buildPaaSTopologyDeploymentContext(OperationExecRequest request) {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(request.getApplicationEnvironmentId());
DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deploymentTopology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials = secretProviderService.generateToken(locations, request.getSecretProviderPluginName(), request.getSecretProviderCredentials());
return deploymentContextService.buildTopologyDeploymentContext(secretProviderConfigurationAndCredentials, deployment, deploymentTopologyService.getLocations(deploymentTopology), deploymentTopology);
}
Aggregations