Search in sources :

Example 1 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class IndexedModelTest method testMergeInterfaceOperationsFromNull.

@Test
public void testMergeInterfaceOperationsFromNull() {
    // FROM's operation is null
    Map<String, Interface> from = Maps.newHashMap();
    Interface i1 = new Interface();
    from.put("i1", i1);
    Map<String, Interface> to = Maps.newHashMap();
    Interface i2 = new Interface();
    Map<String, Operation> ios2 = Maps.newHashMap();
    Operation o2 = new Operation();
    ios2.put("o1", o2);
    i2.setOperations(ios2);
    to.put("i1", i2);
    Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
    assertEquals(1, merged.size());
    assertSame(merged.get("i1").getOperations().get("o1"), o2);
}
Also used : Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface) Test(org.junit.Test)

Example 2 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method processOperationsInputsForOperationOutputs.

/**
 * Check operations input of every operations of all interfaces of a IPaaSTemplate for get_operation_output usage, and register in the related operation
 * the output name
 *
 * @param paaSTemplate
 * @param paaSNodeTemplates
 */
private <V extends AbstractInstantiableToscaType> void processOperationsInputsForOperationOutputs(final IPaaSTemplate<V> paaSTemplate, final Map<String, PaaSNodeTemplate> paaSNodeTemplates) {
    Map<String, Interface> interfaces = ((AbstractInstantiableToscaType) paaSTemplate.getIndexedToscaElement()).getInterfaces();
    if (interfaces != null) {
        for (Interface interfass : interfaces.values()) {
            for (Operation operation : interfass.getOperations().values()) {
                Map<String, IValue> inputsParams = operation.getInputParameters();
                if (inputsParams != null) {
                    for (Entry<String, IValue> input : inputsParams.entrySet()) {
                        String name = input.getKey();
                        IValue value = input.getValue();
                        processIValueForOperationOutput(name, value, paaSTemplate, paaSNodeTemplates, false);
                    }
                }
            }
        }
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 3 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class RuntimeController method validateOperation.

private void validateOperation(Interface interfass, OperationExecRequest operationRequest, Set<CSARDependency> dependencies) throws ConstraintFunctionalException {
    Operation operation = interfass.getOperations().get(operationRequest.getOperationName());
    if (operation == null) {
        throw new NotFoundException("Operation [" + operationRequest.getOperationName() + "] is not defined in the interface [" + operationRequest.getInterfaceName() + "] of the node [" + operationRequest.getNodeTemplateName() + "]");
    }
    // validate parameters (value/type and required value)
    validateParameters(interfass, operationRequest, dependencies);
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) Operation(org.alien4cloud.tosca.model.definitions.Operation)

Example 4 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation 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 5 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class WorkflowUtils method getOperation.

/**
 * @return the operation browsing the type hierarchy
 *         FIXME: should we browse hierarchy ? what about order ?
 */
public static Operation getOperation(String nodeTypeName, String interfaceName, String operationName, TopologyContext topologyContext) {
    NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTypeName);
    if (nodeType == null) {
        return null;
    }
    if (nodeType.getInterfaces() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    Interface interfaceType = nodeType.getInterfaces().get(interfaceName);
    if (interfaceType == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    if (interfaceType.getOperations() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    Operation operation = interfaceType.getOperations().get(operationName);
    if (interfaceType.getOperations() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    return operation;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Aggregations

Operation (org.alien4cloud.tosca.model.definitions.Operation)19 Interface (org.alien4cloud.tosca.model.definitions.Interface)16 Test (org.junit.Test)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)4 Map (java.util.Map)3 IValue (org.alien4cloud.tosca.model.definitions.IValue)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)2 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)2 AbstractInstantiableToscaType (org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType)2 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)2 NotFoundException (alien4cloud.exception.NotFoundException)1 ArtifactSupport (alien4cloud.model.orchestrators.ArtifactSupport)1 IllegalOperationWarning (alien4cloud.topology.warning.IllegalOperationWarning)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ParsingContextExecution (alien4cloud.tosca.parser.ParsingContextExecution)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1 ParsingErrorLevel (alien4cloud.tosca.parser.ParsingErrorLevel)1