use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class TopologyCompositionService method processComposition.
/**
* Process the composition:
* <ul>
* <li>remove the 'proxy' node from the parent.
* <li>merge the child topology nodes into the parent nodes.
* <li>
* </ul>
*
* @param compositionCouple
*/
private void processComposition(CompositionCouple compositionCouple) {
// first of all, remove the proxy node from the parent
NodeTemplate proxyNodeTemplate = compositionCouple.parent.getNodeTemplates().remove(compositionCouple.nodeName);
// properties of the proxy are used to feed the property values of child node that use get_input
for (NodeTemplate childNodeTemplate : compositionCouple.child.getNodeTemplates().values()) {
for (Entry<String, AbstractPropertyValue> propertyEntry : childNodeTemplate.getProperties().entrySet()) {
AbstractPropertyValue pValue = propertyEntry.getValue();
if (isGetInput(pValue)) {
String inputName = ((FunctionPropertyValue) pValue).getTemplateName();
propertyEntry.setValue(proxyNodeTemplate.getProperties().get(inputName));
}
}
for (Entry<String, Capability> capabilityEntry : childNodeTemplate.getCapabilities().entrySet()) {
if (capabilityEntry.getValue().getProperties() != null) {
for (Entry<String, AbstractPropertyValue> propertyEntry : capabilityEntry.getValue().getProperties().entrySet()) {
AbstractPropertyValue pValue = propertyEntry.getValue();
if (isGetInput(pValue)) {
String inputName = ((FunctionPropertyValue) pValue).getTemplateName();
propertyEntry.setValue(proxyNodeTemplate.getProperties().get(inputName));
}
}
}
}
}
// all relations from the proxy must now start from the corresponding node
if (proxyNodeTemplate.getRelationships() != null) {
for (Entry<String, RelationshipTemplate> e : proxyNodeTemplate.getRelationships().entrySet()) {
String relationShipKey = e.getKey();
RelationshipTemplate proxyRelationShip = e.getValue();
String requirementName = proxyRelationShip.getRequirementName();
SubstitutionTarget substitutionTarget = compositionCouple.child.getSubstitutionMapping().getRequirements().get(requirementName);
NodeTemplate nodeTemplate = compositionCouple.child.getNodeTemplates().get(substitutionTarget.getNodeTemplateName());
if (nodeTemplate.getRelationships() == null) {
Map<String, RelationshipTemplate> relationships = Maps.newHashMap();
nodeTemplate.setRelationships(relationships);
}
nodeTemplate.getRelationships().put(relationShipKey, proxyRelationShip);
proxyRelationShip.setRequirementName(substitutionTarget.getTargetId());
}
}
// all relations that target the proxy must be redirected to the corresponding child node
for (NodeTemplate otherNodes : compositionCouple.parent.getNodeTemplates().values()) {
if (otherNodes.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : otherNodes.getRelationships().values()) {
if (relationshipTemplate.getTarget().equals(compositionCouple.nodeName)) {
SubstitutionTarget st = compositionCouple.child.getSubstitutionMapping().getCapabilities().get(relationshipTemplate.getTargetedCapabilityName());
relationshipTemplate.setTarget(st.getNodeTemplateName());
relationshipTemplate.setTargetedCapabilityName(st.getTargetId());
}
}
}
}
if (compositionCouple.parent.getOutputAttributes() != null) {
Set<String> outputAttributes = compositionCouple.parent.getOutputAttributes().remove(compositionCouple.nodeName);
if (outputAttributes != null) {
for (String proxyAttributeName : outputAttributes) {
sustituteGetAttribute(compositionCouple.child, compositionCouple.parent, proxyAttributeName);
}
}
}
// the parent itself expose stuffs, we eventually need to replace substitution targets
if (compositionCouple.parent.getSubstitutionMapping() != null) {
if (compositionCouple.parent.getSubstitutionMapping().getCapabilities() != null) {
for (Entry<String, SubstitutionTarget> substitutionCapabilityEntry : compositionCouple.parent.getSubstitutionMapping().getCapabilities().entrySet()) {
if (substitutionCapabilityEntry.getValue().getNodeTemplateName().equals(compositionCouple.nodeName)) {
String targetCapability = substitutionCapabilityEntry.getValue().getTargetId();
// just substitute the substitution target
substitutionCapabilityEntry.setValue(compositionCouple.child.getSubstitutionMapping().getCapabilities().get(targetCapability));
}
}
}
if (compositionCouple.parent.getSubstitutionMapping().getRequirements() != null) {
for (Entry<String, SubstitutionTarget> e : compositionCouple.parent.getSubstitutionMapping().getRequirements().entrySet()) {
if (e.getValue().getNodeTemplateName().equals(compositionCouple.nodeName)) {
String targetCapability = e.getValue().getTargetId();
// just substitute the substitution target
e.setValue(compositionCouple.child.getSubstitutionMapping().getRequirements().get(targetCapability));
}
}
}
}
// merge each child nodes into the parent
compositionCouple.parent.getNodeTemplates().putAll(compositionCouple.child.getNodeTemplates());
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue 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.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class ArchiveRootPostProcessor method processRepositoriesDefinitions.
private void processRepositoriesDefinitions(Map<String, RepositoryDefinition> repositories) {
if (MapUtils.isNotEmpty(repositories)) {
DataType credentialType = ToscaContext.get(DataType.class, NormativeCredentialConstant.DATA_TYPE);
repositories.values().forEach(repositoryDefinition -> {
if (repositoryDefinition.getCredential() != null) {
credentialType.getProperties().forEach((propertyName, propertyDefinition) -> {
// Fill with default value
if (!repositoryDefinition.getCredential().getValue().containsKey(propertyName)) {
AbstractPropertyValue defaultValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(propertyDefinition);
if (defaultValue instanceof PropertyValue) {
repositoryDefinition.getCredential().getValue().put(propertyName, ((PropertyValue) defaultValue).getValue());
}
}
});
Node credentialNode = ParsingContextExecution.getObjectToNodeMap().get(repositoryDefinition.getCredential());
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(NormativeCredentialConstant.DATA_TYPE);
propertyValueChecker.checkProperty("credential", credentialNode, repositoryDefinition.getCredential(), propertyDefinition, repositoryDefinition.getId());
}
});
}
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class AbstractTemplateMatcher method isValidTemplatePropertiesMatch.
/**
* Add filters ent/ICSARRepositorySearchService.java from the matching configuration to the node filter that will be applied for matching only if a value is
* specified on the configuration template.
*
* @param templatePropertyValues The properties values from the template to match.
* @param candidatePropertyValues The values defined on the Location Template.
* @param propertyDefinitions The properties definitions associated with the node.
* @param configuredFilters The filtering map (based on constraints) from matching configuration, other properties fall backs to an equal constraint/filter.
*/
protected boolean isValidTemplatePropertiesMatch(Map<String, AbstractPropertyValue> templatePropertyValues, Map<String, AbstractPropertyValue> candidatePropertyValues, Map<String, PropertyDefinition> propertyDefinitions, Map<String, List<IMatchPropertyConstraint>> configuredFilters) {
// We perform matching on every property that is defined on the candidate (admin node) and that has a value defined in the topology.
for (Map.Entry<String, AbstractPropertyValue> candidateValueEntry : safe(candidatePropertyValues).entrySet()) {
List<IMatchPropertyConstraint> filter = safe(configuredFilters).get(candidateValueEntry.getKey());
AbstractPropertyValue templatePropertyValue = templatePropertyValues.get(candidateValueEntry.getKey());
// For now we support matching only on scalar properties.
if (candidateValueEntry.getValue() != null && candidateValueEntry.getValue() instanceof ScalarPropertyValue && templatePropertyValue != null && templatePropertyValue instanceof ScalarPropertyValue) {
try {
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinitions.get(candidateValueEntry.getKey()).getType());
if (filter == null) {
// If no filter is defined then process matching using an equal constraint.
filter = Lists.newArrayList(new EqualConstraint());
}
// set the constraint value and add it to the node filter
for (IMatchPropertyConstraint constraint : filter) {
constraint.setConstraintValue(toscaType, ((ScalarPropertyValue) candidateValueEntry.getValue()).getValue());
try {
constraint.validate(toscaType, ((ScalarPropertyValue) templatePropertyValue).getValue());
} catch (ConstraintViolationException e) {
return false;
}
}
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
log.debug("The value of property for a constraint is not valid.", e);
}
}
}
return true;
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class SuggestionService method checkProperties.
private void checkProperties(String nodePrefix, Map<String, AbstractPropertyValue> propertyValueMap, Class<? extends AbstractInheritableToscaType> type, String elementId, ParsingContext context) {
if (MapUtils.isNotEmpty(propertyValueMap)) {
for (Map.Entry<String, AbstractPropertyValue> propertyValueEntry : propertyValueMap.entrySet()) {
String propertyName = propertyValueEntry.getKey();
AbstractPropertyValue propertyValue = propertyValueEntry.getValue();
if (propertyValue instanceof ScalarPropertyValue) {
String propertyTextValue = ((ScalarPropertyValue) propertyValue).getValue();
checkProperty(nodePrefix, propertyName, propertyTextValue, type, elementId, context);
}
}
}
}
Aggregations