use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyService method checkListPropertyConstraint.
private static void checkListPropertyConstraint(String propertyName, List<Object> listPropertyValue, PropertyDefinition propertyDefinition, Consumer<String> missingPropertyConsumer) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
if (!ToscaTypes.LIST.equals(propertyDefinition.getType())) {
throwConstraintValueDoNotMatchPropertyTypeException("The property definition should be a list but we found " + propertyDefinition.getType(), propertyName, ToscaTypes.LIST, null);
}
PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
if (entrySchema == null) {
throw new ConstraintValueDoNotMatchPropertyTypeException("value is a list but type actually is <" + propertyDefinition.getType() + ">");
}
checkLengthConstraints(propertyDefinition.getConstraints(), listPropertyValue);
for (int i = 0; i < listPropertyValue.size(); i++) {
checkPropertyConstraint(propertyName + "[" + String.valueOf(i) + "]", listPropertyValue.get(i), entrySchema, missingPropertyConsumer);
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class RuntimeController method validateParameters.
private void validateParameters(Interface interfass, OperationExecRequest operationRequest, Set<CSARDependency> dependencies) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException, ConstraintRequiredParameterException {
try {
if (dependencies != null) {
ToscaContext.init(dependencies);
}
ArrayList<String> missingParams = Lists.newArrayList();
Operation operation = interfass.getOperations().get(operationRequest.getOperationName());
if (operation.getInputParameters() != null) {
for (Entry<String, IValue> inputParameter : operation.getInputParameters().entrySet()) {
if (inputParameter.getValue().isDefinition()) {
Object requestInputParameter = operationRequest.getParameters() == null ? null : operationRequest.getParameters().get(inputParameter.getKey());
PropertyDefinition currentOperationParameter = (PropertyDefinition) inputParameter.getValue();
if (requestInputParameter != null) {
if (!(requestInputParameter instanceof Map) || !FunctionEvaluator.containGetSecretFunction(PropertyService.asFunctionPropertyValue(requestInputParameter))) {
// recover the good property definition for the current parameter
ConstraintPropertyService.checkPropertyConstraint(inputParameter.getKey(), requestInputParameter, currentOperationParameter);
}
} else if (currentOperationParameter.isRequired()) {
// input param not in the request, id required this is a missing parameter...
missingParams.add(inputParameter.getKey());
} else {
// set the value to null
operation.getInputParameters().put(inputParameter.getKey(), null);
}
}
}
}
// check required input issue
if (!missingParams.isEmpty()) {
log.error("Missing required parameter", missingParams);
ConstraintInformation constraintInformation = new ConstraintInformation(null, null, missingParams.toString(), "required");
throw new ConstraintRequiredParameterException("Missing required parameters", null, constraintInformation);
}
} finally {
if (ToscaContext.get() != null) {
ToscaContext.destroy();
}
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method The_topology_should_not_have_the_property_defined_as_input_property.
@Then("^The topology should not have the property \"([^\"]*)\" defined as input property$")
public void The_topology_should_not_have_the_property_defined_as_input_property(String inputId) throws Throwable {
TopologyDTO topologyDTO = JsonUtil.read(Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId()), TopologyDTO.class, Context.getJsonMapper()).getData();
Map<String, PropertyDefinition> inputProperties = topologyDTO.getTopology().getInputs();
Assert.assertFalse(inputProperties.containsKey(inputId));
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method The_topology_should_have_the_property_of_the_node_defined_as_input_property.
@Then("^The topology should have the property \"([^\"]*)\" defined as input property$")
public void The_topology_should_have_the_property_of_the_node_defined_as_input_property(String inputId) throws Throwable {
String response = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId());
JavaType restResponseType = Context.getJsonMapper().getTypeFactory().constructParametricType(RestResponse.class, TopologyDTO.class);
TopologyDTO topologyDTO = ((RestResponse<TopologyDTO>) Context.getJsonMapper().readValue(response, restResponseType)).getData();
Map<String, PropertyDefinition> inputProperties = topologyDTO.getTopology().getInputs();
Assert.assertNotNull(inputProperties);
PropertyDefinition inputPropertieDefinition = inputProperties.get(inputId);
Assert.assertNotNull(inputPropertieDefinition);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class PropertyValueChecker method checkProperties.
/**
* Check that the value of a property has the right type and match constraints.
*
* @param type The type that defines the properties (NodeType, CapabilityType, RequirementType).
* @param propertyValues The map of values.
* @param templateName The name of the node template /capability template / requirement template.
*/
public void checkProperties(final AbstractInheritableToscaType type, final Map<String, AbstractPropertyValue> propertyValues, final String templateName) {
if (type == null) {
// if the type is null we cannot check properties against their definition. Error is managed elsewhere.
return;
}
ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance();
Topology topology = archiveRoot.getTopology();
for (Map.Entry<String, AbstractPropertyValue> propertyEntry : safe(propertyValues).entrySet()) {
String propertyName = propertyEntry.getKey();
AbstractPropertyValue propertyValue = propertyEntry.getValue();
Node propertyValueNode = ParsingContextExecution.getObjectToNodeMap().get(propertyValue);
if (type.getProperties() == null || !type.getProperties().containsKey(propertyName)) {
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.UNRECOGNIZED_PROPERTY, templateName, propertyValueNode.getStartMark(), "Property " + propertyName + " does not exist in type " + type.getElementId(), propertyValueNode.getEndMark(), propertyName));
continue;
}
PropertyDefinition propertyDefinition = type.getProperties().get(propertyName);
checkProperty(propertyName, propertyValueNode, propertyValue, propertyDefinition, topology.getInputs(), templateName);
}
}
Aggregations