use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ToscaPropertyFormDescriptorGenerator method generateDescriptorForDataType.
private Map<String, Object> generateDescriptorForDataType(Set<String> processedDataTypes, DataType dataType, Set<CSARDependency> dependencies) {
Map<String, Object> dataTypeDescriptors = Maps.newHashMap();
if (dataType instanceof PrimitiveDataType) {
dataTypeDescriptors.put(TYPE_KEY, TOSCA_TYPE);
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(dataType.getDerivedFrom().get(0));
propertyDefinition.setConstraints(((PrimitiveDataType) dataType).getConstraints());
dataTypeDescriptors.put(TOSCA_DEFINITION_KEY, propertyDefinition);
} else {
dataTypeDescriptors.put(TYPE_KEY, COMPLEX_TYPE);
Map<String, Object> propertyTypes = Maps.newHashMap();
dataTypeDescriptors.put(PROPERTY_TYPE_KEY, propertyTypes);
if (dataType.getProperties() != null) {
for (Map.Entry<String, PropertyDefinition> propertyDefinitionEntry : dataType.getProperties().entrySet()) {
propertyTypes.put(propertyDefinitionEntry.getKey(), doGenerateDescriptor(processedDataTypes, propertyDefinitionEntry.getValue(), dependencies));
}
dataTypeDescriptors.put(ORDER_KEY, dataType.getProperties().keySet());
}
}
return dataTypeDescriptors;
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class DeploymentInputService method synchronizeInputs.
/**
* Ensure that the specified input values matches the eventually updated input definitions.
*
* @param inputDefinitions Inputs definitions as specified in the topology.
* @param inputValues Input properties values as specified by the user.
* @return true if there is an update on inputValues (removal or addition). false if nothing has changed
*/
public boolean synchronizeInputs(Map<String, PropertyDefinition> inputDefinitions, Map<String, AbstractPropertyValue> inputValues) {
boolean updated = false;
if (!MapUtils.isEmpty(inputValues)) {
// Ensure that previous defined values are still compatible with the latest input definition (as the topology may have changed).
Iterator<Map.Entry<String, AbstractPropertyValue>> inputPropertyEntryIterator = inputValues.entrySet().iterator();
while (inputPropertyEntryIterator.hasNext()) {
Map.Entry<String, AbstractPropertyValue> inputPropertyEntry = inputPropertyEntryIterator.next();
// remove if the value is null, or the input is not register as one
if (inputPropertyEntry.getValue() == null || !safe(inputDefinitions).containsKey(inputPropertyEntry.getKey())) {
inputPropertyEntryIterator.remove();
} else if (!(inputPropertyEntry.getValue() instanceof FunctionPropertyValue)) {
try {
ConstraintPropertyService.checkPropertyConstraint(inputPropertyEntry.getKey(), ((PropertyValue) inputPropertyEntry.getValue()).getValue(), inputDefinitions.get(inputPropertyEntry.getKey()));
} catch (ConstraintViolationException | ConstraintValueDoNotMatchPropertyTypeException e) {
// Property is not valid anymore for the input, remove the old value
inputPropertyEntryIterator.remove();
updated = true;
}
}
}
}
// set default values for every unset property.
for (Map.Entry<String, PropertyDefinition> inputDefinitionEntry : safe(inputDefinitions).entrySet()) {
AbstractPropertyValue existingValue = inputValues.get(inputDefinitionEntry.getKey());
if (existingValue == null) {
// If user has not specified a value and there is
PropertyValue defaultValue = inputDefinitionEntry.getValue().getDefault();
if (defaultValue != null) {
inputValues.put(inputDefinitionEntry.getKey(), defaultValue);
updated = true;
}
}
}
return updated;
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class OrchestratorPropertiesValidationService method validate.
public PropertiesTask validate(OrchestratorDeploymentProperties orchestratorDeploymentProperties) {
if (orchestratorDeploymentProperties == null || StringUtils.isBlank(orchestratorDeploymentProperties.getOrchestratorId())) {
return null;
}
Map<String, PropertyDefinition> deploymentProperties = orchestratorDeploymentService.getDeploymentPropertyDefinitions(orchestratorDeploymentProperties.getOrchestratorId());
if (MapUtils.isEmpty(deploymentProperties)) {
return null;
}
Map<String, String> properties = orchestratorDeploymentProperties.getProviderDeploymentProperties();
if (properties == null) {
properties = Maps.newHashMap();
}
PropertiesTask task = null;
List<String> required = Lists.newArrayList();
for (Entry<String, PropertyDefinition> entry : deploymentProperties.entrySet()) {
if (entry.getValue().isRequired()) {
String value = properties.get(entry.getKey());
if (StringUtils.isBlank(value)) {
required.add(entry.getKey());
}
}
}
if (CollectionUtils.isNotEmpty(required)) {
task = new PropertiesTask(Maps.<TaskLevel, List<String>>newHashMap());
task.setCode(TaskCode.ORCHESTRATOR_PROPERTY);
task.getProperties().put(TaskLevel.REQUIRED, required);
}
return task;
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method getPropertyDefinition.
private PropertyDefinition getPropertyDefinition(String nodeName, String propertyName) throws Throwable {
PropertyDefinition propDef = null;
String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
String response = Context.getRestClientInstance().get(url);
TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
if (template != null) {
NodeType nodeType = MapUtils.getObject(topologyDTO.getNodeTypes(), template.getType());
if (nodeType != null) {
propDef = MapUtils.getObject(nodeType.getProperties(), propertyName);
}
}
if (propDef == null) {
throw new NullPointerException("The property definition is required for node " + nodeName + " and property " + propertyName + ", please check your cucumber scenario.");
}
return propDef;
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method I_define_the_property_of_the_node_as_of_typeId_as_input_property.
@When("^I define the property \"([^\"]*)\" of the node \"([^\"]*)\" of typeId \"([^\"]*)\" as input property$")
public void I_define_the_property_of_the_node_as_of_typeId_as_input_property(String inputId, String nodeName, String typeId) throws Throwable {
// get the component to use the right property definition
String componentResponse = Context.getRestClientInstance().get("/rest/v1/components/" + typeId);
RestResponse<NodeType> componentResult = JsonUtil.read(componentResponse, NodeType.class, Context.getJsonMapper());
PropertyDefinition propertyDefinition = componentResult.getData().getProperties().get(inputId);
String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), inputId);
String json = JsonUtil.toString(propertyDefinition);
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
Aggregations