use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class DeploymentTopologyStepDefinitions method assertCapabilityPropertyValueEquals.
private void assertCapabilityPropertyValueEquals(NodeTemplate node, String capabilityName, String propertyName, String expectedPropertyValue) {
assertNotNull(node);
Capability capability = MapUtils.getObject(node.getCapabilities(), capabilityName);
assertNotNull(capability);
AbstractPropertyValue abstractProperty = MapUtils.getObject(capability.getProperties(), propertyName);
assertEquals(expectedPropertyValue, PropertyUtil.getScalarValue(abstractProperty));
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class DeploymentTopologyStepDefinitions method The_deployment_topology_sould_have_the_following_input_properties.
@Then("^the deployment topology should have the following inputs properties$")
public void The_deployment_topology_sould_have_the_following_input_properties(Map<String, String> expectedStringInputProperties) throws Throwable {
DeploymentTopologyDTO dto = getDTOAndassertNotNull();
Map<String, AbstractPropertyValue> expectedInputProperties = Maps.newHashMap();
for (Entry<String, String> inputEntry : expectedStringInputProperties.entrySet()) {
expectedInputProperties.put(inputEntry.getKey(), new ScalarPropertyValue(inputEntry.getValue()));
}
assertPropMapContains(dto.getTopology().getAllInputProperties(), expectedInputProperties);
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validatePropertyFilters.
private List<Violations> validatePropertyFilters(Map<String, List<PropertyConstraint>> propertyFilters, Map<String, AbstractPropertyValue> propertyValues, Map<String, PropertyDefinition> propertyDefinitionMap, boolean skipInputs) {
List<Violations> violations = Lists.newArrayList();
for (Map.Entry<String, List<PropertyConstraint>> propertyEntry : propertyFilters.entrySet()) {
Violations violation = new Violations(propertyEntry.getKey());
List<NodeFilterConstraintViolation> violatedConstraints = Lists.newArrayList();
violation.violatedConstraints = violatedConstraints;
AbstractPropertyValue value = propertyValues.get(propertyEntry.getKey());
String propertyValue = null;
if (value == null) {
propertyValue = null;
} else if (value instanceof ScalarPropertyValue) {
propertyValue = ((ScalarPropertyValue) value).getValue();
} else {
if (skipInputs) {
continue;
}
if (FunctionEvaluator.isGetInput((FunctionPropertyValue) value)) {
violation.relatedInput = ((FunctionPropertyValue) value).getElementNameToFetch();
}
}
for (PropertyConstraint constraint : propertyEntry.getValue()) {
if (!propertyDefinitionMap.containsKey(propertyEntry.getKey())) {
continue;
}
// the constraint need to be initiazed with the type of the property (to check that actual value type matches the definition type).
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinitionMap.get(propertyEntry.getKey()).getType());
try {
constraint.initialize(toscaType);
constraint.validate(toscaType, propertyValue);
} catch (ConstraintViolationException e) {
violatedConstraints.add(new NodeFilterConstraintViolation(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR, e.getMessage(), e.getConstraintInformation()));
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
violatedConstraints.add(new NodeFilterConstraintViolation(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR, e.getMessage(), null));
}
}
if (!violatedConstraints.isEmpty()) {
violations.add(violation);
}
}
return violations;
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class TopologyPropertiesValidationService method verifyScalableProperties.
private void verifyScalableProperties(Map<String, AbstractPropertyValue> scalableProperties, List<PropertiesTask> toReturnTaskList, String nodeTemplateId, boolean skipInputProperties) {
Set<String> missingProperties = Sets.newHashSet();
Set<String> errorProperties = Sets.newHashSet();
if (skipInputProperties) {
for (Entry<String, AbstractPropertyValue> entry : scalableProperties.entrySet()) {
if (entry.getValue() instanceof FunctionPropertyValue) {
return;
}
}
}
if (MapUtils.isEmpty(scalableProperties)) {
missingProperties.addAll(Lists.newArrayList(NormativeComputeConstants.SCALABLE_MIN_INSTANCES, NormativeComputeConstants.SCALABLE_MAX_INSTANCES, NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES));
} else {
int min = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_MIN_INSTANCES, missingProperties, errorProperties);
int max = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_MAX_INSTANCES, missingProperties, errorProperties);
int init = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, missingProperties, errorProperties);
if (min > 0 && max > 0 && init > 0) {
if (min > init || min > max) {
errorProperties.add(NormativeComputeConstants.SCALABLE_MIN_INSTANCES);
}
if (init > max || init < min) {
errorProperties.add(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES);
}
if (max < min || max < init) {
errorProperties.add(NormativeComputeConstants.SCALABLE_MAX_INSTANCES);
}
}
}
if (!missingProperties.isEmpty()) {
ScalableTask scalableTask = new ScalableTask(nodeTemplateId);
scalableTask.getProperties().put(TaskLevel.REQUIRED, Lists.newArrayList(missingProperties));
toReturnTaskList.add(scalableTask);
}
if (!errorProperties.isEmpty()) {
ScalableTask scalableTask = new ScalableTask(nodeTemplateId);
scalableTask.getProperties().put(TaskLevel.ERROR, Lists.newArrayList(errorProperties));
toReturnTaskList.add(scalableTask);
}
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class TopologyPropertiesValidationService method validateNodeTemplate.
public void validateNodeTemplate(List<PropertiesTask> toReturnTaskList, NodeType relatedIndexedNodeType, NodeTemplate nodeTemplate, String nodeTempalteName, boolean skipInputProperties) {
// Define a task regarding properties
PropertiesTask task = new PropertiesTask();
task.setNodeTemplateName(nodeTempalteName);
task.setComponent(relatedIndexedNodeType);
task.setCode(TaskCode.PROPERTIES);
task.setProperties(Maps.newHashMap());
// Check the properties of node template
if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
addRequiredPropertyIdToTaskProperties(null, nodeTemplate.getProperties(), relatedIndexedNodeType.getProperties(), task, skipInputProperties);
}
// Check relationships PD
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : safe(nodeTemplate.getRelationships()).entrySet()) {
RelationshipTemplate relationship = relationshipEntry.getValue();
if (relationship.getProperties() == null || relationship.getProperties().isEmpty()) {
continue;
}
addRequiredPropertyIdToTaskProperties("relationships[" + relationshipEntry.getKey() + "]", relationship.getProperties(), safe(ToscaContext.getOrFail(RelationshipType.class, relationshipEntry.getValue().getType()).getProperties()), task, skipInputProperties);
}
for (Map.Entry<String, Capability> capabilityEntry : safe(nodeTemplate.getCapabilities()).entrySet()) {
Capability capability = capabilityEntry.getValue();
if (capability.getProperties() == null || capability.getProperties().isEmpty()) {
continue;
}
addRequiredPropertyIdToTaskProperties("capabilities[" + capabilityEntry.getKey() + "]", capability.getProperties(), safe(ToscaContext.getOrFail(CapabilityType.class, capabilityEntry.getValue().getType()).getProperties()), task, skipInputProperties);
if (capability.getType().equals(NormativeCapabilityTypes.SCALABLE)) {
Map<String, AbstractPropertyValue> scalableProperties = capability.getProperties();
verifyScalableProperties(scalableProperties, toReturnTaskList, nodeTempalteName, skipInputProperties);
}
}
if (MapUtils.isNotEmpty(task.getProperties())) {
toReturnTaskList.add(task);
}
}
Aggregations