use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class InputService method onCopyConfiguration.
@EventListener
@Order(10)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (deploymentInputs == null || MapUtils.isEmpty(deploymentInputs.getInputs())) {
// Nothing to copy
return;
}
Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
if (MapUtils.isNotEmpty(topology.getInputs())) {
Map<String, PropertyDefinition> inputsDefinitions = topology.getInputs();
Map<String, AbstractPropertyValue> inputsToCopy = deploymentInputs.getInputs().entrySet().stream().filter(inputEntry -> inputsDefinitions.containsKey(inputEntry.getKey())).filter(inputEntry -> {
// Copy only inputs which satisfy the new input definition
try {
if (!(inputEntry.getValue() instanceof FunctionPropertyValue)) {
ConstraintPropertyService.checkPropertyConstraint(inputEntry.getKey(), PropertyService.asPropertyValue(inputEntry.getValue()), inputsDefinitions.get(inputEntry.getKey()));
}
return true;
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
return false;
}
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(inputsToCopy)) {
DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
if (targetDeploymentInputs == null) {
targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
}
// Copy inputs from original topology
targetDeploymentInputs.setInputs(inputsToCopy);
deploymentConfigurationDao.save(targetDeploymentInputs);
}
}
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class PaaSUtils method injectInputIntoOperations.
private static void injectInputIntoOperations(String inputName, List<String> path, AbstractPropertyValue value, Map<String, Operation> operations) {
if (MapUtils.isEmpty(operations)) {
return;
}
if (value != null) {
value = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, path);
} else {
value = new ScalarPropertyValue();
}
// the input name should be uppercase
AbstractPropertyValue finalValue = value;
operations.forEach((operationName, operation) -> {
if (operation.getInputParameters() == null) {
operation.setInputParameters(Maps.newHashMap());
}
// DO NOT OVERRIDE
operation.getInputParameters().putIfAbsent(inputName, finalValue);
});
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method processIValueForOperationOutput.
private <V extends AbstractInstantiableToscaType> void processIValueForOperationOutput(String name, IValue iValue, final IPaaSTemplate<V> paaSTemplate, final Map<String, PaaSNodeTemplate> paaSNodeTemplates, final boolean fromAttributes) {
if (iValue instanceof FunctionPropertyValue) {
FunctionPropertyValue function = (FunctionPropertyValue) iValue;
if (ToscaFunctionConstants.GET_OPERATION_OUTPUT.equals(function.getFunction())) {
String formatedAttributeName = null;
List<? extends IPaaSTemplate> paaSTemplates = FunctionEvaluator.getPaaSTemplatesFromKeyword(paaSTemplate, function.getTemplateName(), paaSNodeTemplates);
if (fromAttributes) {
// nodeId:attributeName
formatedAttributeName = AlienUtils.prefixWith(AlienUtils.COLON_SEPARATOR, name, paaSTemplate.getId());
}
registerOperationOutput(paaSTemplates, function.getInterfaceName(), function.getOperationName(), function.getElementNameToFetch(), formatedAttributeName);
}
} else if (iValue instanceof ConcatPropertyValue) {
ConcatPropertyValue concatFunction = (ConcatPropertyValue) iValue;
for (IValue param : concatFunction.getParameters()) {
processIValueForOperationOutput(name, param, paaSTemplate, paaSNodeTemplates, false);
}
}
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class PropertyService method asFunctionPropertyValue.
public static <T extends AbstractPropertyValue> T asFunctionPropertyValue(Object propertyValue) {
if (propertyValue instanceof Map) {
Map valueAsMap = (Map) propertyValue;
if (valueAsMap.keySet().contains("function") && valueAsMap.keySet().contains("parameters")) {
if (!ToscaFunctionConstants.GET_SECRET.equals(valueAsMap.get("function"))) {
throw new InvalidArgumentException("Property function " + valueAsMap.get("function") + " is invalid");
}
FunctionPropertyValue functionPropertyValue = new FunctionPropertyValue();
functionPropertyValue.setFunction((String) valueAsMap.get("function"));
functionPropertyValue.setParameters((List<String>) valueAsMap.get("parameters"));
return (T) functionPropertyValue;
}
}
return (T) new ComplexPropertyValue((Map<String, Object>) propertyValue);
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class AbstractSetMatchedPropertyModifier method setProperty.
protected void setProperty(FlowExecutionContext context, V resourceTemplate, U template, DeploymentMatchingConfiguration matchingConfiguration) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
PropertyDefinition propertyDefinition = ((T) ToscaContext.getOrFail(AbstractToscaType.class, resourceTemplate.getTemplate().getType())).getProperties().get(propertyName);
if (propertyDefinition == null) {
throw new NotFoundException("No property of name [" + propertyName + "] can be found on the " + getSubject() + " template [" + templateId + "] of type [" + resourceTemplate.getTemplate().getType() + "]");
}
AbstractPropertyValue locationResourcePropertyValue = resourceTemplate.getTemplate().getProperties().get(propertyName);
ensureNotSet(locationResourcePropertyValue, "by the admin in the Location Resource Template", propertyName, propertyValue);
ensureNotSet(template.getProperties().get(propertyName), "in the portable topology", propertyName, propertyValue);
// Update the configuration
NodePropsOverride nodePropsOverride = getTemplatePropsOverride(matchingConfiguration);
// Perform the update of the property
if (propertyValue == null) {
nodePropsOverride.getProperties().remove(propertyName);
} else {
AbstractPropertyValue abstractPropertyValue = PropertyService.asPropertyValue(propertyValue);
if (!(abstractPropertyValue instanceof FunctionPropertyValue)) {
ConstraintPropertyService.checkPropertyConstraint(propertyName, propertyValue, propertyDefinition);
}
nodePropsOverride.getProperties().put(propertyName, abstractPropertyValue);
}
context.saveConfiguration(matchingConfiguration);
}
Aggregations