use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class InputsModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
EnvironmentContext environmentContext = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context."));
ApplicationEnvironment environment = environmentContext.getEnvironment();
DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
if (deploymentInputs.getInputs() == null) {
deploymentInputs.setInputs(Maps.newHashMap());
}
Map<String, Location> locations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
Map<String, PropertyValue> applicationInputs = inputService.getAppContextualInputs(context.getEnvironmentContext().get().getApplication(), topology.getInputs());
Map<String, PropertyValue> locationInputs = inputService.getLocationContextualInputs(locations, topology.getInputs());
// If the initial topology or any modifier configuration has changed since last inputs update then we refresh inputs.
if (deploymentInputs.getLastUpdateDate() == null || deploymentInputs.getLastUpdateDate().before(context.getLastFlowParamUpdate())) {
// FIXME exclude the application and location provided inputs from this method as it process them...
boolean updated = deploymentInputService.synchronizeInputs(topology.getInputs(), deploymentInputs.getInputs());
if (updated) {
// save the config if changed. This is for ex, if an input has been deleted from the topology
context.saveConfiguration(deploymentInputs);
}
}
PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputsModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
Map<String, AbstractPropertyValue> inputValues = Maps.newHashMap(deploymentInputs.getInputs());
inputValues.putAll(applicationInputs);
inputValues.putAll(locationInputs);
inputValues.putAll(preconfiguredInputsConfiguration.getInputs());
// Now that we have inputs ready let's process get_input functions in the topology to actually replace values.
if (topology.getNodeTemplates() != null) {
FunctionEvaluatorContext evaluatorContext = new FunctionEvaluatorContext(topology, inputValues);
for (Entry<String, NodeTemplate> entry : topology.getNodeTemplates().entrySet()) {
NodeTemplate nodeTemplate = entry.getValue();
processGetInput(evaluatorContext, nodeTemplate, nodeTemplate.getProperties());
if (nodeTemplate.getRelationships() != null) {
for (Entry<String, RelationshipTemplate> relEntry : nodeTemplate.getRelationships().entrySet()) {
RelationshipTemplate relationshipTemplate = relEntry.getValue();
processGetInput(evaluatorContext, relationshipTemplate, relationshipTemplate.getProperties());
}
}
if (nodeTemplate.getCapabilities() != null) {
for (Entry<String, Capability> capaEntry : nodeTemplate.getCapabilities().entrySet()) {
Capability capability = capaEntry.getValue();
processGetInput(evaluatorContext, nodeTemplate, capability.getProperties());
}
}
if (nodeTemplate.getRequirements() != null) {
for (Entry<String, Requirement> requirementEntry : nodeTemplate.getRequirements().entrySet()) {
Requirement requirement = requirementEntry.getValue();
processGetInput(evaluatorContext, nodeTemplate, requirement.getProperties());
}
}
}
}
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class LocationMatchingModifier method resetMatchingConfiguration.
private void resetMatchingConfiguration(FlowExecutionContext context) {
ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
context.saveConfiguration(new DeploymentMatchingConfiguration(environment.getTopologyVersion(), environment.getId()));
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class OrchestratorPropertiesValidationModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, OrchestratorPropertiesValidationModifier.class.getSimpleName());
if (!configurationOptional.isPresent()) {
// we should not end-up here as location matching should be processed first
context.log().error(new LocationPolicyTask());
return;
}
ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
OrchestratorDeploymentProperties orchestratorDeploymentProperties = context.getConfiguration(OrchestratorDeploymentProperties.class, OrchestratorPropertiesValidationModifier.class.getSimpleName()).orElse(new OrchestratorDeploymentProperties(environment.getTopologyVersion(), environment.getId(), configurationOptional.get().getOrchestratorId()));
orchestratorPropertiesValidationService.validate(orchestratorDeploymentProperties);
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentService method createApplicationEnvironment.
/**
* Create a new environment for a given application
*
* @param applicationId The id of the application.
* @param name The environment name.
* @param description The environment description.
* @param environmentType The type of environment.
* @return The newly created environment.
*/
public ApplicationEnvironment createApplicationEnvironment(String user, String applicationId, String name, String description, EnvironmentType environmentType, String topologyVersion) {
ApplicationVersion applicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationId, topologyVersion));
if (!applicationVersion.getApplicationId().equals(applicationId)) {
throw new IllegalArgumentException("The topology version with id <" + topologyVersion + "> is not a topology of a version of the application with id <" + applicationId + ">");
}
// unique app env name for a given app
ensureNameUnicity(applicationId, name);
ApplicationEnvironment applicationEnvironment = new ApplicationEnvironment();
applicationEnvironment.setId(UUID.randomUUID().toString());
applicationEnvironment.setName(name);
applicationEnvironment.setDescription(description);
applicationEnvironment.setEnvironmentType(environmentType);
applicationEnvironment.setApplicationId(applicationId);
applicationEnvironment.setVersion(applicationVersion.getVersion());
applicationEnvironment.setTopologyVersion(topologyVersion);
Map<String, Set<String>> userRoles = Maps.newHashMap();
userRoles.put(user, Sets.newHashSet(ApplicationEnvironmentRole.DEPLOYMENT_MANAGER.toString()));
applicationEnvironment.setUserRoles(userRoles);
alienDAO.save(applicationEnvironment);
resourceUpdateInterceptor.runOnNewEnvironment(applicationEnvironment);
return applicationEnvironment;
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentService method updateTopologyVersion.
public void updateTopologyVersion(ApplicationEnvironment applicationEnvironment, String oldTopologyVersion, String newVersion, String newTopologyVersion, String environmentIdToCopyInput) {
applicationEnvironment.setVersion(newVersion);
applicationEnvironment.setTopologyVersion(newTopologyVersion);
if (environmentIdToCopyInput != null) {
ApplicationEnvironment environmentToCopyInput = checkAndGetApplicationEnvironment(environmentIdToCopyInput, ApplicationRole.APPLICATION_MANAGER);
alienDAO.save(applicationEnvironment);
synchronizeEnvironmentInputs(environmentToCopyInput, applicationEnvironment);
} else {
alienDAO.save(applicationEnvironment);
}
publisher.publishEvent(new AfterEnvironmentTopologyVersionChanged(this, oldTopologyVersion, newTopologyVersion, applicationEnvironment.getId(), applicationEnvironment.getApplicationId()));
resourceUpdateInterceptor.runOnEnvironmentTopologyVersionChanged(new TopologyVersionChangedInfo(applicationEnvironment, oldTopologyVersion, newTopologyVersion));
}
Aggregations