use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationVersionService method update.
/**
* Update an application version and all it's topology versions.
*
* @param applicationVersionId The application version for which to update all versions.
* @param newVersion The updated version number.
* @param newDescription The new description.
*/
public void update(String applicationId, String applicationVersionId, String newVersion, String newDescription) {
ApplicationVersion applicationVersion = getOrFail(applicationVersionId);
if (!applicationId.equals(applicationVersion.getApplicationId())) {
throw new AuthorizationServiceException("It is not authorize to change an application with a wrong application id: request application id [" + applicationId + "] version application id: [" + applicationVersion.getApplicationId() + "]");
}
if (newDescription != null) {
applicationVersion.setDescription(newDescription);
}
if (newVersion != null && !applicationVersion.getVersion().equals(newVersion)) {
// if the version is a release it is not possible to change it's version number
if (applicationVersion.isReleased()) {
throw new UpdateApplicationVersionException("The application version " + applicationVersion.getId() + " is released and cannot be update.");
}
if (applicationVersionNameExists(applicationVersion.getApplicationId(), newVersion)) {
throw new AlreadyExistException("An application version already exist for this application with the version :" + newVersion);
}
ApplicationEnvironment[] relatedEnvironments = findAllApplicationVersionUsage(applicationVersion.getApplicationId(), applicationVersion.getVersion());
if (ArrayUtils.isNotEmpty(relatedEnvironments)) {
// should fal the update if linked to deployed environment
failIfAnyEnvironmentDeployed(relatedEnvironments);
// Should fail the update if exposed as a service
failIfAnyEnvironmentExposedAsService(applicationId, relatedEnvironments);
}
// When changing the version number we actually perform a full version creation and then delete the previous one.
ApplicationVersion newApplicationVersion = new ApplicationVersion();
newApplicationVersion.setVersion(newVersion);
newApplicationVersion.setNestedVersion(VersionUtil.parseVersion(newVersion));
newApplicationVersion.setDescription(applicationVersion.getDescription());
newApplicationVersion.setApplicationId(applicationVersion.getApplicationId());
newApplicationVersion.setReleased(!VersionUtil.isSnapshot(newVersion));
newApplicationVersion.setTopologyVersions(Maps.newHashMap());
importTopologiesFromPreviousVersion(newApplicationVersion, applicationVersion);
// save the new version
alienDAO.save(newApplicationVersion);
resourceUpdateInterceptor.runOnTopologyVersionReleased(new TopologyVersionUpdated(applicationVersion, newApplicationVersion));
// update topology versions on related objects: (environments, deploymentTopologies)
updateTopologyVersion(relatedEnvironments, applicationVersion, newApplicationVersion);
// delete the previous version
deleteVersion(applicationVersion);
} else {
// save the new version
alienDAO.save(applicationVersion);
}
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ManagedServiceResourceService method checkAndGetApplicationEnvironment.
/**
* Get application environment, checks for DEPLOYMENT_MANAGEMENT rights on it.
*
* @param environmentId
* @return the environment if the current user has the proper rights on it
* @throws java.nio.file.AccessDeniedException if the current user doesn't have proper rights on the requested environment
*/
private ApplicationEnvironment checkAndGetApplicationEnvironment(String environmentId) {
ApplicationEnvironment environment = environmentService.getOrFail(environmentId);
Application application = applicationService.getOrFail(environment.getApplicationId());
// Only a user with deployment rĂ´le on the environment can create an associated service.
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
return environment;
}
use of alien4cloud.model.application.ApplicationEnvironment 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.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class InputService method onCopyConfiguration.
@EventListener
@Order(10)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (deploymentInputs == null || MapUtils.isEmpty(deploymentInputs.getInputs())) {
// Nothing to copy
return;
}
Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
if (MapUtils.isNotEmpty(topology.getInputs())) {
Map<String, PropertyDefinition> inputsDefinitions = topology.getInputs();
Map<String, AbstractPropertyValue> inputsToCopy = deploymentInputs.getInputs().entrySet().stream().filter(inputEntry -> inputsDefinitions.containsKey(inputEntry.getKey())).filter(inputEntry -> {
// Copy only inputs which satisfy the new input definition
try {
if (!(inputEntry.getValue() instanceof FunctionPropertyValue)) {
ConstraintPropertyService.checkPropertyConstraint(inputEntry.getKey(), PropertyService.asPropertyValue(inputEntry.getValue()), inputsDefinitions.get(inputEntry.getKey()));
}
return true;
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
return false;
}
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(inputsToCopy)) {
DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
if (targetDeploymentInputs == null) {
targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
}
// Copy inputs from original topology
targetDeploymentInputs.setInputs(inputsToCopy);
deploymentConfigurationDao.save(targetDeploymentInputs);
}
}
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class LocationMatchService method onCopyConfiguration.
@EventListener
// We must process location copy before copy of elements that depends from the location.
@Order(20)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups())) {
// Nothing to copy
return;
}
// Set the location policy to the target environment.
setLocationPolicy(onDeploymentConfigCopyEvent.getTargetEnvironment(), sourceConfiguration.getOrchestratorId(), sourceConfiguration.getLocationIds());
}
Aggregations