use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillAttributesFromOutputCapabilitiesProperties.
private void fillAttributesFromOutputCapabilitiesProperties(Topology topology, NodeType substituteNodeType) {
Map<String, Map<String, Set<String>>> outputCapabilityProperties = topology.getOutputCapabilityProperties();
if (outputCapabilityProperties != null) {
for (Map.Entry<String, Map<String, Set<String>>> ocpe : outputCapabilityProperties.entrySet()) {
String nodeName = ocpe.getKey();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
for (Map.Entry<String, Set<String>> cpe : ocpe.getValue().entrySet()) {
String capabilityName = cpe.getKey();
String capabilityTypeName = nodeTemplate.getCapabilities().get(capabilityName).getType();
CapabilityType capabilityType = ToscaContext.getOrFail(CapabilityType.class, capabilityTypeName);
for (String propertyName : cpe.getValue()) {
PropertyDefinition pd = capabilityType.getProperties().get(propertyName);
// there is a conflict
addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
}
}
}
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class TopologyDTOBuilder method getCapabilityTypes.
private <T extends Topology> Map<String, CapabilityType> getCapabilityTypes(AbstractTopologyDTO<T> topologyDTO) {
Map<String, CapabilityType> types = Maps.newHashMap();
Map<String, NodeType> delayedNodeTypeAddMap = Maps.newHashMap();
for (NodeType nodeType : topologyDTO.getNodeTypes().values()) {
if (nodeType != null) {
for (CapabilityDefinition capabilityDefinition : safe(nodeType.getCapabilities())) {
types.put(capabilityDefinition.getType(), ToscaContext.get(CapabilityType.class, capabilityDefinition.getType()));
}
for (RequirementDefinition requirementDefinition : safe(nodeType.getRequirements())) {
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
if (capabilityType != null) {
types.put(requirementDefinition.getType(), capabilityType);
} else {
// requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
NodeType indexedNodeType = ToscaContext.get(NodeType.class, requirementDefinition.getType());
// add it to the actual node types map
delayedNodeTypeAddMap.put(requirementDefinition.getType(), indexedNodeType);
}
}
}
}
for (Map.Entry<String, NodeType> delayedNodeType : delayedNodeTypeAddMap.entrySet()) {
topologyDTO.getNodeTypes().put(delayedNodeType.getKey(), delayedNodeType.getValue());
}
return types;
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class SetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
if (operation.getCapabilityName().equals(FORBIDDEN_CAPABILITY)) {
throw new UnsupportedSecretException("We cannot set a secret on the capability " + operation.getCapabilityName());
}
if ("".equals(operation.getSecretPath())) {
throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + "is null.");
}
FunctionPropertyValue getSecret = new FunctionPropertyValue();
getSecret.setFunction(ToscaFunctionConstants.GET_SECRET);
getSecret.setParameters(Arrays.asList(operation.getSecretPath()));
nodeTemplate.getCapabilities().get(operation.getCapabilityName()).getProperties().put(operation.getPropertyName(), getSecret);
log.debug("Set the property [ {} ] of capability template [ {} ] of node [ {} ] to the secret path [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class UnsetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
// check if the node property value is a get_secret
AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
if (currentValue != null && !isGetSecret(currentValue)) {
throw new NotFoundException("Property {} of node {} is not an secret.", operation.getPropertyName(), operation.getNodeName());
}
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
log.debug("Remove secret property [ {} ] of capability template [ {} ] of node [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.types.CapabilityType 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);
}
Aggregations