Search in sources :

Example 1 with Interface

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

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

the class IndexedModelTest method testMergeInterfacesBasic.

@Test
public void testMergeInterfacesBasic() {
    Map<String, Interface> from = Maps.newHashMap();
    Interface i1 = new Interface();
    from.put("i1", i1);
    Map<String, Interface> to = Maps.newHashMap();
    Interface i2 = new Interface();
    to.put("i2", i2);
    Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
    assertEquals(2, merged.size());
    assertSame(merged.get("i1"), i1);
    assertSame(merged.get("i2"), i2);
}
Also used : Interface(org.alien4cloud.tosca.model.definitions.Interface) Test(org.junit.Test)

Example 3 with Interface

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

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

the class TopologyTreeBuilderService method registerOperationOutput.

@SuppressWarnings({ "unchecked", "rawtypes" })
private <V extends AbstractInstantiableToscaType> void registerOperationOutput(final List<? extends IPaaSTemplate> paaSTemplates, final String interfaceName, final String operationName, final String output, final String formatedAttributeName) {
    for (IPaaSTemplate<V> paaSTemplate : paaSTemplates) {
        if (paaSTemplate.getInterfaces() != null) {
            Interface interfass = MapUtils.getObject(paaSTemplate.getInterfaces(), (interfaceName));
            if (interfass != null && interfass.getOperations().containsKey(operationName)) {
                OperationOutput toAdd = new OperationOutput(output);
                if (StringUtils.isNotBlank(formatedAttributeName)) {
                    toAdd.getRelatedAttributes().add(formatedAttributeName);
                }
                interfass.getOperations().get(operationName).addOutput(toAdd);
            }
        }
    }
}
Also used : OperationOutput(org.alien4cloud.tosca.model.definitions.OperationOutput) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 5 with Interface

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

the class RuntimeController method validateCommand.

private void validateCommand(OperationExecRequest operationRequest, Topology topology) throws ConstraintFunctionalException {
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operationRequest.getNodeTemplateName(), TopologyUtils.getNodeTemplates(topology));
    NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
    Map<String, Interface> interfaces = IndexedModelUtils.mergeInterfaces(indexedNodeType.getInterfaces(), nodeTemplate.getInterfaces());
    if (interfaces == null || interfaces.get(operationRequest.getInterfaceName()) == null) {
        throw new NotFoundException("Interface [" + operationRequest.getInterfaceName() + "] not found in the node template [" + operationRequest.getNodeTemplateName() + "] related to [" + indexedNodeType.getId() + "]");
    }
    Interface interfass = interfaces.get(operationRequest.getInterfaceName());
    validateOperation(interfass, operationRequest, topology.getDependencies());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Aggregations

Interface (org.alien4cloud.tosca.model.definitions.Interface)28 Operation (org.alien4cloud.tosca.model.definitions.Operation)16 Test (org.junit.Test)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)4 Map (java.util.Map)3 IValue (org.alien4cloud.tosca.model.definitions.IValue)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)3 AbstractInstantiableToscaType (org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType)3 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)3 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)3 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)2 INodeParser (alien4cloud.tosca.parser.INodeParser)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 MapParser (alien4cloud.tosca.parser.impl.base.MapParser)2 Set (java.util.Set)2 ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)2