Search in sources :

Example 21 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class DefaultWorkflowBuilder method getRelationshipWeavingDeclarativeWorkflow.

private RelationshipWeavingDeclarativeWorkflow getRelationshipWeavingDeclarativeWorkflow(String relationshipTypeName, TopologyContext toscaTypeFinder, String workflowName) {
    RelationshipType indexedRelationshipType = toscaTypeFinder.findElement(RelationshipType.class, relationshipTypeName);
    List<String> typesToCheck = new ArrayList<>();
    typesToCheck.add(indexedRelationshipType.getElementId());
    if (indexedRelationshipType.getDerivedFrom() != null) {
        typesToCheck.addAll(indexedRelationshipType.getDerivedFrom());
    }
    Map<String, Map<String, RelationshipWeavingDeclarativeWorkflow>> weavingConfigsPerRelationshipType = defaultDeclarativeWorkflows.getRelationshipsWeaving();
    for (String typeToCheck : typesToCheck) {
        if (weavingConfigsPerRelationshipType.containsKey(typeToCheck)) {
            return weavingConfigsPerRelationshipType.get(typeToCheck).get(workflowName);
        }
    }
    // This will never happen if the declarative configuration has tosca.relationships.Root configured
    throw new IllegalStateException("Default declarative configuration for workflow must have tosca.relationships.Root configured");
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 22 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType 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);
        }
    }
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 23 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class TopologyStepDefinitions method i_create_a_relationshiptype_in_an_archive_name_version_with_properties.

@Given("^i create a relationshiptype \"([^\"]*)\" in an archive name \"([^\"]*)\" version \"([^\"]*)\" with properties$")
public void i_create_a_relationshiptype_in_an_archive_name_version_with_properties(String elementId, String archiveName, String archiveVersion, DataTable properties) throws Throwable {
    RelationshipType relationship = new RelationshipType();
    relationship.setArchiveName(archiveName);
    relationship.setArchiveVersion(archiveVersion);
    relationship.setElementId(elementId);
    relationship.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    for (List<String> propertyObject : properties.raw()) {
        if (propertyObject.get(0).equals("validSource")) {
            relationship.setValidSources(propertyObject.get(1).split(","));
        } else if (propertyObject.get(0).equals("validTarget")) {
            relationship.setValidTargets(propertyObject.get(1).split(","));
        } else if (propertyObject.get(0).equals("abstract")) {
            relationship.setAbstract(Boolean.valueOf(propertyObject.get(1)));
        }
    }
    esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, MappingBuilder.indexTypeFromClass(RelationshipType.class)).setSource(JsonUtil.toString(relationship)).setRefresh(true).execute().actionGet();
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Given(cucumber.api.java.en.Given)

Example 24 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType 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);
            }
        }
    }
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 25 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class TopologyService method initializeTypeLoader.

private ToscaTypeLoader initializeTypeLoader(Topology topology, boolean failOnTypeNotFound) {
    // FIXME we should use ToscaContext here, and why not allowing the caller to pass ona Context?
    ToscaTypeLoader loader = new ToscaTypeLoader(csarDependencyLoader);
    Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, failOnTypeNotFound);
    Map<String, RelationshipType> relationshipTypes = topologyServiceCore.getIndexedRelationshipTypesFromTopology(topology, failOnTypeNotFound);
    Map<String, PolicyType> policyTypes = topologyServiceCore.getPolicyTypesFromTopology(topology, failOnTypeNotFound);
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
        // just load found types: the type might be null when failOnTypeNotFound is set to false.
        if (nodeType != null) {
            loader.loadType(nodeTemplate.getType(), csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()));
        }
        for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
            RelationshipType relationshipType = relationshipTypes.get(relationshipTemplate.getType());
            // just load found types: the type might be null when failOnTypeNotFound is set to false.
            if (relationshipType != null) {
                loader.loadType(relationshipTemplate.getType(), csarDependencyLoader.buildDependencyBean(relationshipType.getArchiveName(), relationshipType.getArchiveVersion()));
            }
        }
    }
    for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
        PolicyType policyType = policyTypes.get(policyTemplate.getType());
        if (policyType != null) {
            loader.loadType(policyTemplate.getType(), csarDependencyLoader.buildDependencyBean(policyType.getArchiveName(), policyType.getArchiveVersion()));
        }
    }
    if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
        NodeType substitutionType = nodeTypes.get(topology.getSubstitutionMapping().getSubstitutionType());
        loader.loadType(substitutionType.getElementId(), csarDependencyLoader.buildDependencyBean(substitutionType.getArchiveName(), substitutionType.getArchiveVersion()));
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
            initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
        }
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
            initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
        }
    }
    return loader;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Aggregations

RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)41 NodeType (org.alien4cloud.tosca.model.types.NodeType)22 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)15 Set (java.util.Set)14 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)14 Test (org.junit.Test)14 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)9 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)9 Csar (org.alien4cloud.tosca.model.Csar)8 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)8 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)5 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)5 Interface (org.alien4cloud.tosca.model.definitions.Interface)5 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)4 NotFoundException (alien4cloud.exception.NotFoundException)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)3 Capability (org.alien4cloud.tosca.model.templates.Capability)3 DataType (org.alien4cloud.tosca.model.types.DataType)3 ParsingError (alien4cloud.tosca.parser.ParsingError)2