use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillSubstituteAttributesFromTypeAtttributes.
private void fillSubstituteAttributesFromTypeAtttributes(Topology topology, NodeType substituteNodeType) {
Map<String, IValue> attributes = substituteNodeType.getAttributes();
Map<String, Set<String>> outputAttributes = topology.getOutputAttributes();
if (outputAttributes != null) {
for (Map.Entry<String, Set<String>> oae : outputAttributes.entrySet()) {
String nodeName = oae.getKey();
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
for (String attributeName : oae.getValue()) {
IValue ivalue = nodeTemplateType.getAttributes().get(attributeName);
// is a conflict
if (ivalue != null && !attributes.containsKey(attributeName)) {
attributes.put(attributeName, ivalue);
}
}
}
}
}
use of org.alien4cloud.tosca.model.types.NodeType 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.NodeType in project alien4cloud by alien4cloud.
the class AddSubstitutionTypeProcessor method process.
@Override
public void process(Csar csar, Topology topology, AddSubstitutionTypeOperation operation) {
if (topology.getSubstitutionMapping() == null) {
topology.setSubstitutionMapping(new SubstitutionMapping());
}
NodeType nodeType = toscaTypeSearchService.getElementInDependencies(NodeType.class, operation.getElementId(), topology.getDependencies());
// if not null the node type exists in the dependencies, there is no choices for this type version
if (nodeType == null) {
// the node type does'nt exist in this topology dependencies
// we need to find the latest version of this component and use it as default
nodeType = toscaTypeSearchService.findMostRecent(NodeType.class, operation.getElementId());
if (nodeType == null) {
throw new NotFoundException("Node type with name <" + operation.getElementId() + "> cannot be found in the catalog.");
}
topologyService.loadType(topology, nodeType);
}
topology.getSubstitutionMapping().setSubstitutionType(operation.getElementId());
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class EditorTopologyRecoveryHelperService method checkCapability.
/**
* validate that a node still has a capability, by checkibg directly from the related node type
*
* @param capabilityName The name of the capability to check
* @param nodeTemplate The node template in which to check for the capability
*/
private void checkCapability(String capabilityName, NodeTemplate nodeTemplate) {
// FIXME check if the relationship is still valid concerning binded capability
// This call should never throw a NotFoundException
NodeType indexedNodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
Map<String, CapabilityDefinition> capabilitiesMap = AlienUtils.fromListToMap(indexedNodeType.getCapabilities(), "id", true);
if (!AlienUtils.safe(capabilitiesMap).containsKey(capabilityName)) {
throw new InvalidStateException("A capability with name [" + capabilityName + "] cannot be found in the node [" + nodeTemplate.getName() + "].");
}
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class EditorTopologyRecoveryHelperService method validateRelationShip.
/**
* checks if a relationship is still valid
*
* @param nodeTemplate The source node of the relationship
* @param relationshipTemplate The relationship to validate
* @param topology The related topology
*/
private void validateRelationShip(NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate, Topology topology) {
// This call should never throw a NotFoundException
NodeType nodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
// validate the requirement
checkRequirement(relationshipTemplate, nodeTemplate, nodeType);
// validate the targeted capability
checkCapability(relationshipTemplate.getTargetedCapabilityName(), topology.getNodeTemplates().get(relationshipTemplate.getTarget()));
}
Aggregations