use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class InputArtifactsModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
if (deploymentInputs.getInputArtifacts() == null) {
deploymentInputs.setInputArtifacts(Maps.newHashMap());
}
boolean updated = false;
// Cleanup inputs artifacts that does not exists anymore
Iterator<Entry<String, DeploymentArtifact>> inputArtifactsIterator = safe(deploymentInputs.getInputArtifacts()).entrySet().iterator();
while (inputArtifactsIterator.hasNext()) {
Entry<String, DeploymentArtifact> inputArtifactEntry = inputArtifactsIterator.next();
if (!topology.getInputArtifacts().containsKey(inputArtifactEntry.getKey())) {
inputArtifactsIterator.remove();
updated = true;
}
}
processInputArtifacts(topology, deploymentInputs.getInputArtifacts());
// should save if deploymentInput updated
if (updated) {
context.saveConfiguration(deploymentInputs);
}
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs 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 org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class InputArtifactService method updateInputArtifact.
public void updateInputArtifact(ApplicationEnvironment environment, Topology topology, String inputArtifactId, DeploymentArtifact updatedArtifact) {
checkInputArtifactExist(inputArtifactId, topology);
DeploymentInputs deploymentInputs = getDeploymentInputs(environment.getTopologyVersion(), environment.getId());
DeploymentArtifact artifact = getDeploymentArtifact(inputArtifactId, deploymentInputs);
artifact.setArtifactName(updatedArtifact.getArtifactName());
artifact.setArtifactRef(updatedArtifact.getArtifactRef());
artifact.setArtifactRepository(updatedArtifact.getArtifactRepository());
artifact.setArtifactType(updatedArtifact.getArtifactType());
artifact.setRepositoryName(updatedArtifact.getRepositoryName());
artifact.setRepositoryURL(updatedArtifact.getRepositoryURL());
artifact.setRepositoryCredential(updatedArtifact.getRepositoryCredential());
artifact.setArchiveName(updatedArtifact.getArchiveName());
artifact.setArchiveVersion(updatedArtifact.getArchiveVersion());
deploymentConfigurationDao.save(deploymentInputs);
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs 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 org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class InputService method setInputValues.
public void setInputValues(ApplicationEnvironment environment, Topology topology, Map<String, Object> inputProperties) {
if (safe(inputProperties).isEmpty()) {
return;
}
// Get the configuration object
DeploymentInputs configuration = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
if (configuration == null) {
configuration = new DeploymentInputs(environment.getTopologyVersion(), environment.getId());
}
for (Map.Entry<String, Object> inputPropertyValue : inputProperties.entrySet()) {
if (topology.getInputs() == null || topology.getInputs().get(inputPropertyValue.getKey()) == null) {
throw new NotFoundException("Input", inputPropertyValue.getKey(), "Input <" + inputPropertyValue.getKey() + "> cannot be found on topology for application <" + environment.getApplicationId() + "> environement <" + environment.getId() + ">");
}
try {
propertyService.setPropertyValue(configuration.getInputs(), topology.getInputs().get(inputPropertyValue.getKey()), inputPropertyValue.getKey(), inputPropertyValue.getValue());
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
throw new ConstraintTechnicalException("Dispatching constraint violation.", e);
}
}
// Save configuration
deploymentConfigurationDao.save(configuration);
}
Aggregations