use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidListProperty.
@Test(expected = ConstraintViolationException.class)
public void testInvalidListProperty() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(ToscaTypes.LIST);
PropertyDefinition entrySchema = new PropertyDefinition();
entrySchema.setType(ToscaTypes.STRING);
propertyDefinition.setEntrySchema(entrySchema);
Object propertyValue = ImmutableMap.builder().put("aa", "bb").build();
ToscaContext.init(new HashSet<>());
ICSARRepositorySearchService originalCsarRepositorySearchService = ToscaContext.getCsarRepositorySearchService();
ICSARRepositorySearchService mockSearchService = Mockito.mock(ICSARRepositorySearchService.class);
try {
ToscaContext.setCsarRepositorySearchService(mockSearchService);
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
} finally {
ToscaContext.setCsarRepositorySearchService(originalCsarRepositorySearchService);
ToscaContext.destroy();
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class PropertyDefinitionUtils method buildPropDef.
public static PropertyDefinition buildPropDef(String type, boolean required) {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(type);
propertyDefinition.setRequired(required);
propertyDefinition.setPassword(false);
propertyDefinition.setEntrySchema(null);
return propertyDefinition;
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class PropertyDefinitionUtils method buildPropDef.
public static PropertyDefinition buildPropDef(String type, PropertyDefinition entrySchema, boolean required) {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(type);
propertyDefinition.setRequired(required);
propertyDefinition.setPassword(false);
propertyDefinition.setEntrySchema(entrySchema);
return propertyDefinition;
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class LocationResourceService method setTemplateCapabilityProperty.
private void setTemplateCapabilityProperty(LocationResourceTemplate resourceTemplate, String capabilityName, String propertyName, Object propertyValue) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
Location location = locationService.getOrFail(resourceTemplate.getLocationId());
NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
Capability capability = getOrFailCapability(resourceTemplate.getTemplate(), capabilityName);
CapabilityDefinition capabilityDefinition = getOrFailCapabilityDefinition(resourceType, capabilityName);
CapabilityType capabilityType = csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), location.getDependencies());
PropertyDefinition propertyDefinition = getOrFailCapabilityPropertyDefinition(capabilityType, propertyName);
propertyService.setCapabilityPropertyValue(location.getDependencies(), capability, propertyDefinition, propertyName, propertyValue);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class FunctionEvaluator method parseAttribute.
/**
* Parse an attribute value that can be : {@link ConcatPropertyValue} / {@link AttributeDefinition}
*
* @param attributeId
* @param attributeValue
* @param topology
* @param runtimeInformations
* @param currentInstance
* @param basePaaSTemplate
* @param builtPaaSTemplates
* @return
*/
public static String parseAttribute(String attributeId, IValue attributeValue, Topology topology, Map<String, Map<String, InstanceInformation>> runtimeInformations, String currentInstance, IPaaSTemplate<? extends AbstractToscaType> basePaaSTemplate, Map<String, PaaSNodeTemplate> builtPaaSTemplates) {
if (attributeValue == null) {
return null;
}
// handle AttributeDefinition type
if (attributeValue instanceof AttributeDefinition) {
String runtimeAttributeValue = extractRuntimeInformationAttribute(runtimeInformations, currentInstance, Lists.newArrayList(basePaaSTemplate), attributeId);
if (runtimeAttributeValue != null) {
if (!runtimeAttributeValue.contains("=Error!]") && !runtimeAttributeValue.equals("")) {
return runtimeAttributeValue;
}
}
return ((AttributeDefinition) attributeValue).getDefault();
}
// handle concat function
if (attributeValue instanceof ConcatPropertyValue) {
StringBuilder evaluatedAttribute = new StringBuilder();
ConcatPropertyValue concatPropertyValue = (ConcatPropertyValue) attributeValue;
for (IValue concatParam : concatPropertyValue.getParameters()) {
// scalar type
if (concatParam instanceof ScalarPropertyValue) {
// scalar case
evaluatedAttribute.append(((ScalarPropertyValue) concatParam).getValue());
} else if (concatParam instanceof PropertyDefinition) {
// Definition case
// TODO : ?? what should i do here ?? currently returns default value in the definition
evaluatedAttribute.append(((PropertyDefinition) concatParam).getDefault());
} else if (concatParam instanceof FunctionPropertyValue) {
// Function case
FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) concatParam;
List<? extends IPaaSTemplate> paasTemplates = getPaaSTemplatesFromKeyword(basePaaSTemplate, functionPropertyValue.getTemplateName(), builtPaaSTemplates);
switch(functionPropertyValue.getFunction()) {
case ToscaFunctionConstants.GET_ATTRIBUTE:
evaluatedAttribute.append(extractRuntimeInformationAttribute(runtimeInformations, currentInstance, paasTemplates, functionPropertyValue.getElementNameToFetch()));
break;
case ToscaFunctionConstants.GET_PROPERTY:
evaluatedAttribute.append(extractRuntimeInformationProperty(topology, functionPropertyValue.getElementNameToFetch(), paasTemplates));
break;
case ToscaFunctionConstants.GET_OPERATION_OUTPUT:
String defaultValue = "<" + functionPropertyValue.getElementNameToFetch() + ">";
evaluatedAttribute.append(extractRuntimeInformationOperationOutput(runtimeInformations, currentInstance, paasTemplates, functionPropertyValue, defaultValue));
break;
default:
log.warn("Function [{}] is not yet handled in concat operation.", functionPropertyValue.getFunction());
break;
}
}
}
return evaluatedAttribute.toString();
}
// handle functions. For now, only support Get_OPERATION_OUTPUT on attributes scope
if (attributeValue instanceof FunctionPropertyValue) {
FunctionPropertyValue function = (FunctionPropertyValue) attributeValue;
switch(function.getFunction()) {
case ToscaFunctionConstants.GET_OPERATION_OUTPUT:
List<? extends IPaaSTemplate> paasTemplates = getPaaSTemplatesFromKeyword(basePaaSTemplate, function.getTemplateName(), builtPaaSTemplates);
return extractRuntimeInformationOperationOutput(runtimeInformations, currentInstance, paasTemplates, function, null);
default:
return null;
}
}
return null;
}
Aggregations