Search in sources :

Example 1 with IllegalOperationWarning

use of alien4cloud.topology.warning.IllegalOperationWarning 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);
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Operation(org.alien4cloud.tosca.model.definitions.Operation) IllegalOperationWarning(alien4cloud.topology.warning.IllegalOperationWarning) ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 2 with IllegalOperationWarning

use of alien4cloud.topology.warning.IllegalOperationWarning in project alien4cloud by alien4cloud.

the class TopologyServiceInterfaceOverrideCheckerService method addWarning.

private void addWarning(Set<IllegalOperationWarning> warnings, NodeTemplate nodeTemplate, Interface toscaInterface, String operationName, String serviceName, String relationshipType) {
    IllegalOperationWarning illegalOperationWarning = new IllegalOperationWarning();
    illegalOperationWarning.setNodeTemplateName(nodeTemplate.getName());
    illegalOperationWarning.setOperationName(operationName);
    illegalOperationWarning.setServiceName(serviceName);
    illegalOperationWarning.setRelationshipType(relationshipType);
    illegalOperationWarning.setInterfaceName(toscaInterface.getType());
    warnings.add(illegalOperationWarning);
}
Also used : IllegalOperationWarning(alien4cloud.topology.warning.IllegalOperationWarning)

Aggregations

IllegalOperationWarning (alien4cloud.topology.warning.IllegalOperationWarning)2 ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)1 Interface (org.alien4cloud.tosca.model.definitions.Interface)1 Operation (org.alien4cloud.tosca.model.definitions.Operation)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1