use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class InterfaceParser method parseInterfaceDefinition.
private Interface parseInterfaceDefinition(MappingNode node, ParsingContextExecution context) {
Interface interfaz = new Interface();
Map<String, Operation> operations = Maps.newHashMap();
interfaz.setOperations(operations);
Map<String, IValue> interfaceInputs = null;
for (NodeTuple entry : node.getValue()) {
String key = scalarParser.parse(entry.getKeyNode(), context);
if (INPUTS_KEY.equals(key)) {
interfaceInputs = inputsParser.parse(entry.getValueNode(), context);
} else if (DESCRIPTION_KEY.equals(key)) {
interfaz.setDescription(scalarParser.parse(entry.getValueNode(), context));
} else if (TYPE_KEY.equals(key)) {
interfaz.setType(getInterfaceType(scalarParser.parse(entry.getValueNode(), context)));
} else {
if (entry.getValueNode() instanceof ScalarNode) {
Operation operation = new Operation();
// implementation artifact parsing should be done using a deferred parser as we need to look for artifact types.
operation.setImplementationArtifact(implementationArtifactParser.parse(entry.getValueNode(), context));
operations.put(key, operation);
} else {
operations.put(key, operationParser.parse(entry.getValueNode(), context));
}
}
}
if (interfaceInputs != null) {
for (Operation operation : operations.values()) {
if (operation.getInputParameters() == null) {
operation.setInputParameters(Maps.newHashMap());
}
for (Entry<String, IValue> inputEntry : interfaceInputs.entrySet()) {
if (!operation.getInputParameters().containsKey(inputEntry.getKey())) {
operation.getInputParameters().put(inputEntry.getKey(), inputEntry.getValue());
}
}
}
}
return interfaz;
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class InterfacesParser method parse.
@Override
public Map<String, Interface> parse(Node node, ParsingContextExecution context) {
if (node instanceof MappingNode) {
Map<String, Interface> interfaces = super.parse(node, context);
Map<String, Interface> cleanedInterfaces = Maps.newHashMap();
for (Map.Entry<String, Interface> entry : interfaces.entrySet()) {
String interfaceType = InterfaceParser.getInterfaceType(entry.getKey());
if (entry.getValue().getType() == null) {
entry.getValue().setType(interfaceType);
}
cleanedInterfaces.put(interfaceType, entry.getValue());
}
return cleanedInterfaces;
}
// In a node type interfaces definition allow to reference an interface type or multiple ones using array, in that case the keyname of the interface is
// the actual value type.
Map<String, Interface> interfaces = Maps.newHashMap();
if (node instanceof SequenceNode) {
for (Node interfaceTypeNode : ((SequenceNode) node).getValue()) {
if (interfaceTypeNode instanceof ScalarNode) {
addInterfaceFromType((ScalarNode) interfaceTypeNode, interfaces, context);
} else {
ParserUtils.addTypeError(interfaceTypeNode, context.getParsingErrors(), "interface");
}
}
} else if (node instanceof ScalarNode) {
addInterfaceFromType((ScalarNode) node, interfaces, context);
} else {
ParserUtils.addTypeError(node, context.getParsingErrors(), "interfaces");
}
return interfaces;
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class ServiceResourceRelationshipService method processTargetOperations.
private void processTargetOperations(PaaSRelationshipTemplate paaSRelationshipTemplate, ServiceResource serviceResource, Interface templateInterface) {
// Drop default target operations as the service is the target of a relationship
dropOperations(templateInterface, PRE_CONFIGURE_TARGET, POST_CONFIGURE_TARGET, ADD_SOURCE, REMOVE_SOURCE);
// for services that are target of a relationship, all operations related to target (the service) are not run.
if (paaSRelationshipTemplate.getTemplate().getTargetedCapabilityName() != null && serviceResource.getCapabilitiesRelationshipTypes() != null) {
String relationshipTypeId = serviceResource.getCapabilitiesRelationshipTypes().get(paaSRelationshipTemplate.getTemplate().getTargetedCapabilityName());
if (relationshipTypeId != null) {
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_TARGET, POST_CONFIGURE_TARGET, ADD_SOURCE, REMOVE_SOURCE);
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class ServiceResourceRelationshipService method processService.
private void processService(PaaSNodeTemplate paaSNodeTemplate) {
ServiceNodeTemplate serviceNodeTemplate = (ServiceNodeTemplate) paaSNodeTemplate.getTemplate();
ServiceResource serviceResource = serviceResourceService.getOrFail(serviceNodeTemplate.getServiceResourceId());
for (PaaSRelationshipTemplate paaSRelationshipTemplate : paaSNodeTemplate.getRelationshipTemplates()) {
Interface templateInterface = safe(paaSRelationshipTemplate.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE);
if (templateInterface != null) {
if (paaSRelationshipTemplate.getSource().equals(paaSNodeTemplate.getId())) {
processSourceOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
} else {
processTargetOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class LocationMatchNodesArtifactsElector method isEligible.
private boolean isEligible(AbstractInstantiableTemplate template, LocationMatchNodeFilter.NodeMatchContext matchContext) {
if (template == null) {
return true;
}
ArtifactSupport artifactSupport = matchContext.getArtifactSupport();
// if no supported artifact defined, then return true
if (artifactSupport == null || ArrayUtils.isEmpty(artifactSupport.getTypes())) {
return true;
}
String[] supportedArtifacts = artifactSupport.getTypes();
AbstractInstantiableToscaType indexedArtifactToscaElement = matchContext.getElement(AbstractInstantiableToscaType.class, template.getType());
if (MapUtils.isNotEmpty(indexedArtifactToscaElement.getInterfaces())) {
for (Interface interfaz : indexedArtifactToscaElement.getInterfaces().values()) {
for (Operation operation : interfaz.getOperations().values()) {
if (operation.getImplementationArtifact() != null) {
String artifactTypeString = operation.getImplementationArtifact().getArtifactType();
ArtifactType artifactType = matchContext.getElement(ArtifactType.class, artifactTypeString);
// stop the checking once one artifactType is not supported
if (!isFromOneOfTypes(supportedArtifacts, artifactType)) {
return false;
}
}
}
}
}
return true;
}
Aggregations