use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class TopologyServiceInterfaceOverrideCheckerService method findWarnings.
public List<IllegalOperationWarning> findWarnings(Topology topology) {
Set<IllegalOperationWarning> warnings = Sets.newHashSet();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
for (Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
NodeTemplate nodeTemplate = nodeTempEntry.getValue();
Map<String, RelationshipTemplate> relationships = nodeTemplate.getRelationships();
if (relationships != null) {
for (Entry<String, RelationshipTemplate> entry : relationships.entrySet()) {
RelationshipTemplate relationshipTemplate = entry.getValue();
String target = relationshipTemplate.getTarget();
NodeTemplate targetNodeTemplate = nodeTemplates.get(target);
boolean serviceIsSource = isService(nodeTemplate);
boolean serviceIsTarget = isService(targetNodeTemplate);
if (serviceIsSource || serviceIsTarget) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
if (relationshipType != null) {
Map<String, Interface> interfaces = relationshipType.getInterfaces();
if (interfaces != null) {
interfaces.forEach((relationshipName, relationshipInterface) -> {
Map<String, Operation> operations = relationshipInterface.getOperations();
if (operations != null) {
operations.forEach((operationName, operation) -> {
String serviceName;
if (serviceIsTarget) {
serviceName = nodeTemplate.getName();
switch(operationName.toLowerCase()) {
case "add_source":
case "remove_source":
case "source_changed":
case "post_configure_target":
case "pre_configure_target":
ImplementationArtifact artifact = operation.getImplementationArtifact();
boolean stepDoSomething = artifact != null;
if (stepDoSomething) {
addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
}
break;
}
}
if (serviceIsSource) {
serviceName = targetNodeTemplate.getName();
switch(operationName.toLowerCase()) {
case "add_target":
case "remove_target":
case "target_changed":
case "pre_configure_source":
case "post_configure_source":
ImplementationArtifact artifact = operation.getImplementationArtifact();
boolean stepDoSomething = artifact != null;
if (stepDoSomething) {
addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
}
break;
}
}
});
}
});
}
}
}
}
}
}
return warnings.isEmpty() ? null : new ArrayList<>(warnings);
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class WorkflowUtils method getOperation.
/**
* @return the operation browsing the type hierarchy
* FIXME: should we browse hierarchy ? what about order ?
*/
public static Operation getOperation(String nodeTypeName, String interfaceName, String operationName, TopologyContext topologyContext) {
NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTypeName);
if (nodeType == null) {
return null;
}
if (nodeType.getInterfaces() == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
Interface interfaceType = nodeType.getInterfaces().get(interfaceName);
if (interfaceType == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
if (interfaceType.getOperations() == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
Operation operation = interfaceType.getOperations().get(operationName);
if (interfaceType.getOperations() == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
return operation;
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class ServiceResourceRelationshipService method processSourceOperations.
private void processSourceOperations(PaaSRelationshipTemplate paaSRelationshipTemplate, ServiceResource serviceResource, Interface templateInterface) {
// Drop default source operations as the service is the source of a relationship
dropOperations(templateInterface, PRE_CONFIGURE_SOURCE, POST_CONFIGURE_SOURCE, ADD_TARGET, REMOVE_TARGET);
// for services that are source of a relationship, all operations related to source (the service) are not run.
String relationshipTypeId = serviceResource.getRequirementsRelationshipTypes().get(paaSRelationshipTemplate.getTemplate().getRequirementName());
if (relationshipTypeId != null) {
// The relationship may not exist in the topology archive so we don't use the TOSCA context but make a direct query
RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId);
Interface serviceInterface = safe(relationshipType.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE);
if (serviceInterface != null) {
overrideOperations(paaSRelationshipTemplate.getTemplate(), templateInterface, relationshipType, serviceInterface, PRE_CONFIGURE_SOURCE, POST_CONFIGURE_SOURCE, ADD_TARGET, REMOVE_TARGET);
}
}
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class RelationshipTemplateParser method parse.
@Override
public RelationshipTemplate parse(Node node, ParsingContextExecution context) {
// To parse a relationship template we actually get the parent node to retrieve the requirement name;
if (!(node instanceof MappingNode) || ((MappingNode) node).getValue().size() != 1) {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
MappingNode assignmentNode = (MappingNode) node;
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
String relationshipId = scalarParser.parse(assignmentNode.getValue().get(0).getKeyNode(), context);
// The relationship's id which is used to identify the relationship within the source
relationshipTemplate.setName(relationshipId);
// By default the relationship id is the requirement name, it can be overridden with 'type_requirement'
relationshipTemplate.setRequirementName(relationshipId);
// Now parse the content of the relationship assignment.
node = assignmentNode.getValue().get(0).getValueNode();
if (node instanceof ScalarNode) {
// Short notation (host: compute)
relationshipTemplate.setTarget(scalarParser.parse(node, context));
} else if (node instanceof MappingNode) {
MappingNode mappingNode = (MappingNode) node;
for (NodeTuple nodeTuple : mappingNode.getValue()) {
String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
switch(key) {
case "node":
relationshipTemplate.setTarget(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "capability":
relationshipTemplate.setTargetedCapabilityName(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "type_requirement":
relationshipTemplate.setRequirementName(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "relationship":
relationshipTemplate.setType(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "properties":
INodeParser<AbstractPropertyValue> propertyValueParser = context.getRegistry().get("node_template_property");
MapParser<AbstractPropertyValue> mapParser = baseParserFactory.getMapParser(propertyValueParser, "node_template_property");
relationshipTemplate.setProperties(mapParser.parse(nodeTuple.getValueNode(), context));
break;
case "interfaces":
INodeParser<Map<String, Interface>> interfacesParser = context.getRegistry().get("interfaces");
relationshipTemplate.setInterfaces(interfacesParser.parse(nodeTuple.getValueNode(), context));
break;
default:
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_ARTIFACT_KEY, null, node.getStartMark(), "Unrecognized key while parsing implementation artifact", node.getEndMark(), key));
}
}
} else {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
return relationshipTemplate;
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class RelationshipTemplateParser method parse.
@Override
public RelationshipTemplate parse(Node node, ParsingContextExecution context) {
// To parse a relationship template we actually get the parent node to retrieve the requirement name;
if (!(node instanceof MappingNode) || ((MappingNode) node).getValue().size() != 1) {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
MappingNode assignmentNode = (MappingNode) node;
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
relationshipTemplate.setRequirementName(scalarParser.parse(assignmentNode.getValue().get(0).getKeyNode(), context));
// Now parse the content of the relationship assignment.
node = assignmentNode.getValue().get(0).getValueNode();
if (node instanceof ScalarNode) {
// Short notation (host: compute)
relationshipTemplate.setTarget(scalarParser.parse(node, context));
} else if (node instanceof MappingNode) {
MappingNode mappingNode = (MappingNode) node;
for (NodeTuple nodeTuple : mappingNode.getValue()) {
String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
switch(key) {
case "node":
relationshipTemplate.setTarget(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "capability":
relationshipTemplate.setTargetedCapabilityName(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "relationship":
relationshipTemplate.setType(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "properties":
INodeParser<AbstractPropertyValue> propertyValueParser = context.getRegistry().get("node_template_property");
MapParser<AbstractPropertyValue> mapParser = baseParserFactory.getMapParser(propertyValueParser, "node_template_property");
relationshipTemplate.setProperties(mapParser.parse(nodeTuple.getValueNode(), context));
break;
case "interfaces":
INodeParser<Map<String, Interface>> interfacesParser = context.getRegistry().get("interfaces");
relationshipTemplate.setInterfaces(interfacesParser.parse(nodeTuple.getValueNode(), context));
break;
default:
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_ARTIFACT_KEY, null, node.getStartMark(), "Unrecognized key while parsing implementation artifact", node.getEndMark(), key));
}
}
} else {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
return relationshipTemplate;
}
Aggregations