use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputValidationModifier method process.
/**
* Validate all required input is provided with a non null value.
*
* @param topology The topology to process.
* @param context The object that stores warnings and errors (tasks) associated with the execution flow. Note that the flow will end-up if an error
*/
@Override
public void process(Topology topology, FlowExecutionContext context) {
Optional<DeploymentInputs> inputsOptional = context.getConfiguration(DeploymentInputs.class, InputValidationModifier.class.getSimpleName());
PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputValidationModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
// Define a task regarding properties
PropertiesTask task = new PropertiesTask();
task.setCode(TaskCode.INPUT_PROPERTY);
task.setProperties(Maps.newHashMap());
task.getProperties().put(TaskLevel.REQUIRED, Lists.newArrayList());
Map<String, AbstractPropertyValue> inputValues = safe(inputsOptional.orElse(new DeploymentInputs()).getInputs());
Map<String, PropertyValue> predefinedInputValues = safe(preconfiguredInputsConfiguration.getInputs());
// override deployer inputValues with predefinedInputValues
inputValues = Maps.newHashMap(inputValues);
inputValues.putAll(predefinedInputValues);
for (Entry<String, PropertyDefinition> propDef : safe(topology.getInputs()).entrySet()) {
if (propDef.getValue().isRequired() && inputValues.get(propDef.getKey()) == null) {
task.getProperties().get(TaskLevel.REQUIRED).add(propDef.getKey());
}
}
if (CollectionUtils.isNotEmpty(task.getProperties().get(TaskLevel.REQUIRED))) {
context.log().error(task);
}
// Check input artifacts
deploymentInputArtifactValidationService.validate(topology, inputsOptional.orElse(new DeploymentInputs())).forEach(inputArtifactTask -> context.log().error(inputArtifactTask));
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class EditorInputHelperService method getInputCandidates.
/**
* Utility method to get the list of inputs (ids) that are compatible with the given property definition (no constraint conflicts)..
*
* @param topologyId The id of the topology for which to find input candidates.
* @param nodeTemplateName The name of the node template for which to get input candidates.
* @param propertyDefinitionGetter Implementation on how to get the property definition (from node properties, capabilities properties, relationships
* properties).
* @return A list of input candidates that are compatible with the requested property definition.
*/
public List<String> getInputCandidates(String topologyId, String nodeTemplateName, IPropertyDefinitionGetter propertyDefinitionGetter) {
try {
editionContextManager.init(topologyId);
// check authorization to update a topology
topologyService.checkEditionAuthorizations(EditionContextManager.getTopology());
Topology topology = EditionContextManager.getTopology();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateName);
PropertyDefinition pd = propertyDefinitionGetter.get(nodeTemplate);
if (pd == null) {
throw new NotFoundException("Unexpected error, property definition cannot be found for node <" + nodeTemplateName + ">");
}
Map<String, PropertyDefinition> inputs = topology.getInputs();
List<String> inputIds = new ArrayList<String>();
if (inputs != null && !inputs.isEmpty()) {
// iterate overs existing inputs and filter them by checking constraint compatibility
for (Map.Entry<String, PropertyDefinition> inputEntry : inputs.entrySet()) {
try {
inputEntry.getValue().checkIfCompatibleOrFail(pd);
inputIds.add(inputEntry.getKey());
} catch (IncompatiblePropertyDefinitionException e) {
// Nothing to do here, the id won't be added to the list
}
}
}
return inputIds;
} finally {
editionContextManager.destroy();
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class UpdatePolicyPropertyValueProcessor method process.
@Override
protected void process(Csar csar, Topology topology, UpdatePolicyPropertyValueOperation operation, PolicyTemplate policyTemplate) {
PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
PropertyDefinition propertyDefinition = AlienUtils.getOrFail(policyType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for policy [ {} ].", operation.getPropertyName(), policyTemplate.getType(), operation.getPolicyName());
log.debug("Updating property [ {} ] of the policy template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", operation.getPropertyName(), operation.getPolicyName(), topology.getId(), policyTemplate.getProperties().get(operation.getPropertyName()), operation.getPropertyValue());
try {
propertyService.setPropertyValue(policyTemplate, propertyDefinition, operation.getPropertyName(), operation.getPropertyValue());
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting policy " + operation.getPolicyName() + " property.", e, operation.getPropertyName(), operation.getPropertyValue());
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class DeleteInputProcessor method removeInputIdInProperties.
/**
* Remove the inputId for the {@link FunctionPropertyValue} of a Map of properties.
*
* @param properties the list of properties values currently defined in the topology.
* @param propertyDefinitions the list of definitions of properties (matching the list of values).
* @param inputId The id of the input to remove.
*/
private void removeInputIdInProperties(final Map<String, AbstractPropertyValue> properties, final Map<String, PropertyDefinition> propertyDefinitions, final String inputId) {
if (properties == null) {
return;
}
for (Map.Entry<String, AbstractPropertyValue> propertyEntry : properties.entrySet()) {
if (propertyEntry.getValue() instanceof FunctionPropertyValue) {
FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) propertyEntry.getValue();
if (ToscaFunctionConstants.GET_INPUT.equals(functionPropertyValue.getFunction()) && functionPropertyValue.getTemplateName().equals(inputId)) {
PropertyDefinition pd = propertyDefinitions.get(propertyEntry.getKey());
AbstractPropertyValue pv = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(pd);
propertyEntry.setValue(pv);
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class RenameInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, RenameInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + " not found");
}
if (operation.getInputName().equals(operation.getNewInputName())) {
// nothing has changed.
return;
}
if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
}
if (inputs.containsKey(operation.getNewInputName())) {
throw new AlreadyExistException("Input " + operation.getNewInputName() + " already existed");
}
PropertyDefinition propertyDefinition = inputs.remove(operation.getInputName());
inputs.put(operation.getNewInputName(), propertyDefinition);
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
for (NodeTemplate nodeTemp : safe(nodeTemplates).values()) {
renameInputInProperties(nodeTemp.getProperties(), operation.getInputName(), operation.getNewInputName());
if (nodeTemp.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemp.getRelationships().values()) {
renameInputInProperties(relationshipTemplate.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
if (nodeTemp.getCapabilities() != null) {
for (Capability capability : nodeTemp.getCapabilities().values()) {
renameInputInProperties(capability.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
}
// rename preconfigured input
renamePreconfiguredInput(csar, topology, operation);
log.debug("Change the name of an input parameter [ {} ] to [ {} ] for the topology ", operation.getInputName(), operation.getNewInputName(), topology.getId());
}
Aggregations