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");
}
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);
}
}
}
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();
}
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);
}
}
}
}
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;
}
Aggregations