use of org.alien4cloud.tosca.model.templates.RelationshipTemplate 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.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class InputsModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
EnvironmentContext environmentContext = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context."));
ApplicationEnvironment environment = environmentContext.getEnvironment();
DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
if (deploymentInputs.getInputs() == null) {
deploymentInputs.setInputs(Maps.newHashMap());
}
Map<String, Location> locations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
Map<String, PropertyValue> applicationInputs = inputService.getAppContextualInputs(context.getEnvironmentContext().get().getApplication(), topology.getInputs());
Map<String, PropertyValue> locationInputs = inputService.getLocationContextualInputs(locations, topology.getInputs());
// If the initial topology or any modifier configuration has changed since last inputs update then we refresh inputs.
if (deploymentInputs.getLastUpdateDate() == null || deploymentInputs.getLastUpdateDate().before(context.getLastFlowParamUpdate())) {
// FIXME exclude the application and location provided inputs from this method as it process them...
boolean updated = deploymentInputService.synchronizeInputs(topology.getInputs(), deploymentInputs.getInputs());
if (updated) {
// save the config if changed. This is for ex, if an input has been deleted from the topology
context.saveConfiguration(deploymentInputs);
}
}
PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputsModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
Map<String, AbstractPropertyValue> inputValues = Maps.newHashMap(deploymentInputs.getInputs());
inputValues.putAll(applicationInputs);
inputValues.putAll(locationInputs);
inputValues.putAll(preconfiguredInputsConfiguration.getInputs());
// Now that we have inputs ready let's process get_input functions in the topology to actually replace values.
if (topology.getNodeTemplates() != null) {
FunctionEvaluatorContext evaluatorContext = new FunctionEvaluatorContext(topology, inputValues);
for (Entry<String, NodeTemplate> entry : topology.getNodeTemplates().entrySet()) {
NodeTemplate nodeTemplate = entry.getValue();
processGetInput(evaluatorContext, nodeTemplate, nodeTemplate.getProperties());
if (nodeTemplate.getRelationships() != null) {
for (Entry<String, RelationshipTemplate> relEntry : nodeTemplate.getRelationships().entrySet()) {
RelationshipTemplate relationshipTemplate = relEntry.getValue();
processGetInput(evaluatorContext, relationshipTemplate, relationshipTemplate.getProperties());
}
}
if (nodeTemplate.getCapabilities() != null) {
for (Entry<String, Capability> capaEntry : nodeTemplate.getCapabilities().entrySet()) {
Capability capability = capaEntry.getValue();
processGetInput(evaluatorContext, nodeTemplate, capability.getProperties());
}
}
if (nodeTemplate.getRequirements() != null) {
for (Entry<String, Requirement> requirementEntry : nodeTemplate.getRequirements().entrySet()) {
Requirement requirement = requirementEntry.getValue();
processGetInput(evaluatorContext, nodeTemplate, requirement.getProperties());
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class SuggestionService method postProcessSuggestionFromArchive.
public void postProcessSuggestionFromArchive(ParsingResult<ArchiveRoot> parsingResult) {
ArchiveRoot archiveRoot = parsingResult.getResult();
ParsingContext context = parsingResult.getContext();
if (archiveRoot.hasToscaTopologyTemplate()) {
Topology topology = archiveRoot.getTopology();
Map<String, NodeTemplate> nodeTemplateMap = topology.getNodeTemplates();
if (MapUtils.isEmpty(nodeTemplateMap)) {
return;
}
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplateMap.entrySet()) {
NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
String nodeName = nodeTemplateEntry.getKey();
if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
checkProperties(nodeName, nodeTemplate.getProperties(), NodeType.class, nodeTemplate.getType(), context);
}
Map<String, Capability> capabilityMap = nodeTemplate.getCapabilities();
if (MapUtils.isNotEmpty(capabilityMap)) {
for (Map.Entry<String, Capability> capabilityEntry : capabilityMap.entrySet()) {
String capabilityName = capabilityEntry.getKey();
Capability capability = capabilityEntry.getValue();
if (MapUtils.isNotEmpty(capability.getProperties())) {
checkProperties(nodeName + ".capabilities." + capabilityName, capability.getProperties(), CapabilityType.class, capability.getType(), context);
}
}
}
Map<String, RelationshipTemplate> relationshipTemplateMap = nodeTemplate.getRelationships();
if (MapUtils.isNotEmpty(relationshipTemplateMap)) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipTemplateMap.entrySet()) {
String relationshipName = relationshipEntry.getKey();
RelationshipTemplate relationship = relationshipEntry.getValue();
if (MapUtils.isNotEmpty(relationship.getProperties())) {
checkProperties(nodeName + ".relationships." + relationshipName, relationship.getProperties(), RelationshipType.class, relationship.getType(), context);
}
}
}
}
}
if (archiveRoot.hasToscaTypes()) {
Map<String, NodeType> allNodeTypes = archiveRoot.getNodeTypes();
if (MapUtils.isNotEmpty(allNodeTypes)) {
for (Map.Entry<String, NodeType> nodeTypeEntry : allNodeTypes.entrySet()) {
NodeType nodeType = nodeTypeEntry.getValue();
if (nodeType.getRequirements() != null && !nodeType.getRequirements().isEmpty()) {
for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
if (nodeFilter != null) {
Map<String, FilterDefinition> capabilitiesFilters = nodeFilter.getCapabilities();
if (MapUtils.isNotEmpty(capabilitiesFilters)) {
for (Map.Entry<String, FilterDefinition> capabilityFilterEntry : capabilitiesFilters.entrySet()) {
FilterDefinition filterDefinition = capabilityFilterEntry.getValue();
for (Map.Entry<String, List<PropertyConstraint>> constraintEntry : filterDefinition.getProperties().entrySet()) {
List<PropertyConstraint> constraints = constraintEntry.getValue();
checkPropertyConstraints("node_filter.capabilities", CapabilityType.class, capabilityFilterEntry.getKey(), constraintEntry.getKey(), constraints, context);
}
}
}
// FIXME check also the value properties filter of a node filter
}
}
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class CfyMultirelationshipErrorModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
// Check if orchestrator is cloudify
Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, LocationMatchingModifier.class.getSimpleName());
if (!configurationOptional.isPresent()) {
context.log().error(new LocationPolicyTask());
return;
}
DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
Orchestrator orchestrator = orchestratorService.getOrFail(matchingConfiguration.getOrchestratorId());
if (!orchestrator.getPluginId().contains("cloudify")) {
return;
}
// For every node check that there is not two relationships defined
for (Entry<String, NodeTemplate> nodeTemplateEntry : safe(topology.getNodeTemplates()).entrySet()) {
// Keep track of the relationship id
Set<String> relationshipTargets = Sets.newHashSet();
for (Entry<String, RelationshipTemplate> relationshipTemplateEntry : safe(nodeTemplateEntry.getValue().getRelationships()).entrySet()) {
if (relationshipTargets.contains(relationshipTemplateEntry.getValue().getTarget())) {
context.log().error(TaskCode.CFY_MULTI_RELATIONS, "Cloudify orchestrator does not support multiple relationships between the same source and target nodes. Topology defines more than one between " + nodeTemplateEntry.getKey() + " and " + relationshipTemplateEntry.getValue().getTarget() + ".");
return;
}
relationshipTargets.add(relationshipTemplateEntry.getValue().getTarget());
}
}
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class PaaSUtils method processRelationshipTemplateProperties.
/**
* Inject relationshipTemplate, source, target and targeted capability properties as input parameters for all its interfaces operations <br>
* The injected input names are uppercased and is in form:
* <ul>
* <li>{@code SELF_<PROPERTY_NAME>} for relationship property
* <li>{@code SOURCE_<PROPERTY_NAME>} for source property
* <li>{@code TARGET_<PROPERTY_NAME>} for target property
* <li>{@code TARGET_CAPABILITIES_<CAPABILITY_NAME>_<PROPERTY_NAME>} for capability property
* </ul>
* In case of name conflict, the overriding order is: (--> = overrides)
*
* <pre>
* declared input --> relationship property input --> source property input --> target property input --> targeted capability property input
* </pre>
*
* @param paaSRelationshipTemplate The {@link PaaSRelationshipTemplate} to process
* @param paaSNodeTemplates All the nodes of the topology
*/
public static void processRelationshipTemplateProperties(PaaSRelationshipTemplate paaSRelationshipTemplate, Map<String, PaaSNodeTemplate> paaSNodeTemplates) {
RelationshipTemplate template = paaSRelationshipTemplate.getTemplate();
// inject relationship properties
injectPropertiesAsInputs(ToscaFunctionConstants.SELF, null, template.getProperties(), paaSRelationshipTemplate.getInterfaces(), baseName -> StringUtils.joinWith(AlienUtils.DEFAULT_PREFIX_SEPARATOR, ToscaFunctionConstants.SELF, baseName));
// inject source properties
injectSourcePropertiesAsInputs(paaSNodeTemplates.get(paaSRelationshipTemplate.getSource()), paaSRelationshipTemplate.getInterfaces());
// inject target properties
injectTargetPropertiesAsInputs(paaSNodeTemplates.get(template.getTarget()), paaSRelationshipTemplate.getInterfaces());
// inject related target capability properties
injectTargetedCapabilityProperties(paaSNodeTemplates.get(template.getTarget()), template.getTargetedCapabilityName(), paaSRelationshipTemplate.getInterfaces());
}
Aggregations