use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class TopologyServiceCore method getIndexedRelationshipTypesFromTopology.
/**
* Get IndexedRelationshipType in a topology
*
* @param topology the topology to find all relationship types
* @param failOnTypeNotFound
* @return the map containing rel
*/
public Map<String, RelationshipType> getIndexedRelationshipTypesFromTopology(Topology topology, boolean failOnTypeNotFound) {
Map<String, RelationshipType> relationshipTypes = Maps.newHashMap();
if (topology.getNodeTemplates() == null) {
return relationshipTypes;
}
for (Map.Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
if (template.getRelationships() != null) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : template.getRelationships().entrySet()) {
RelationshipTemplate relationship = relationshipEntry.getValue();
if (!relationshipTypes.containsKey(relationship.getType())) {
RelationshipType relationshipType = getFromContextIfDefined(RelationshipType.class, relationship.getType(), topology.getDependencies(), failOnTypeNotFound);
relationshipTypes.put(relationship.getType(), relationshipType);
}
}
}
}
if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
addRelationshipTypeFromSubstitutionTarget(topology, relationshipTypes, substitutionTarget, failOnTypeNotFound);
}
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
addRelationshipTypeFromSubstitutionTarget(topology, relationshipTypes, substitutionTarget, failOnTypeNotFound);
}
}
return relationshipTypes;
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validateRequirementFilters.
/**
* Performs validation of the node filters to check that relationships targets the filter requirements.
*/
private List<NodeFiltersTask> validateRequirementFilters(Topology topology, boolean skipInputs) {
List<NodeFiltersTask> toReturnTaskList = Lists.newArrayList();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, true, true);
Map<String, CapabilityType> capabilityTypes = topologyServiceCore.getIndexedCapabilityTypesFromTopology(topology);
for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
Map<String, RelationshipTemplate> relationshipsMap = nodeTempEntry.getValue().getRelationships();
if (relationshipsMap == null || relationshipsMap.isEmpty()) {
continue;
}
NodeType sourceNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTempEntry.getValue().getType(), topology.getDependencies());
if (sourceNodeType.isAbstract()) {
continue;
}
NodeFiltersTask task = new NodeFiltersTask();
task.setNodeTemplateName(nodeTempEntry.getKey());
task.setCode(TaskCode.NODE_FILTER_INVALID);
task.setComponent(sourceNodeType);
task.setNodeFiltersToSatisfy(Lists.<NodeFilterToSatisfy>newArrayList());
validateFiltersForNode(sourceNodeType, relationshipsMap, topology, nodeTypes, capabilityTypes, task, skipInputs);
if (!task.getNodeFiltersToSatisfy().isEmpty()) {
toReturnTaskList.add(task);
}
}
return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class DeleteFileProcessor method process.
@Override
public void process(Csar csar, Topology topology, DeleteFileOperation operation) {
if (csar.getYamlFilePath().equals(operation.getPath())) {
throw new InvalidPathException("Topology yaml file cannot be removed.");
}
TreeNode target = FileProcessorHelper.getFileTreeNode(operation.getPath());
target.getParent().getChildren().remove(target);
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
for (DeploymentArtifact artifact : safe(nodeTemplate.getArtifacts()).values()) {
resetRemovedArtifact(artifact, operation.getPath());
}
cleanupInterfaces(nodeTemplate.getInterfaces(), operation.getPath());
for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
cleanupInterfaces(relationshipTemplate.getInterfaces(), operation.getPath());
}
}
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class RenameInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, RenameInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + " not found");
}
if (operation.getInputName().equals(operation.getNewInputName())) {
// nothing has changed.
return;
}
if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
}
if (inputs.containsKey(operation.getNewInputName())) {
throw new AlreadyExistException("Input " + operation.getNewInputName() + " already existed");
}
PropertyDefinition propertyDefinition = inputs.remove(operation.getInputName());
inputs.put(operation.getNewInputName(), propertyDefinition);
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
for (NodeTemplate nodeTemp : safe(nodeTemplates).values()) {
renameInputInProperties(nodeTemp.getProperties(), operation.getInputName(), operation.getNewInputName());
if (nodeTemp.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemp.getRelationships().values()) {
renameInputInProperties(relationshipTemplate.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
if (nodeTemp.getCapabilities() != null) {
for (Capability capability : nodeTemp.getCapabilities().values()) {
renameInputInProperties(capability.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
}
// rename preconfigured input
renamePreconfiguredInput(csar, topology, operation);
log.debug("Change the name of an input parameter [ {} ] to [ {} ] for the topology ", operation.getInputName(), operation.getNewInputName(), topology.getId());
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class ReplaceNodeProcessor method addTheRelationshipsOnSource.
private void addTheRelationshipsOnSource(Topology topology, Map<String, Map<String, RelationshipTemplate>> relationshipDeleted) {
for (String nodeName : relationshipDeleted.keySet()) {
NodeTemplate nodeTemplate = safe(topology.getNodeTemplates()).get(nodeName);
Map<String, RelationshipTemplate> relationship = relationshipDeleted.get(nodeName);
for (String targetId : relationship.keySet()) {
nodeTemplate.getRelationships().put(targetId, relationship.get(targetId));
}
}
}
Aggregations