Search in sources :

Example 1 with AbstractInstantiableToscaType

use of org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType in project alien4cloud by alien4cloud.

the class FunctionEvaluatorTest method getOperationOutputTest.

@Test
public void getOperationOutputTest() {
    String computeName = "comp_getOpOutput";
    PaaSNodeTemplate computePaaS = builtPaaSNodeTemplates.get(computeName);
    // check if outputs referenced in get_operation_outputs on attributes are well registered on the related operation
    AbstractInstantiableToscaType tocaElement = computePaaS.getIndexedToscaElement();
    IValue oldHostNameAttr = tocaElement.getAttributes().get("old_hostname");
    IValue newHostNameAttr = tocaElement.getAttributes().get("new_hostname");
    Operation createOp = computePaaS.getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CREATE);
    Operation configOp = computePaaS.getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CONFIGURE);
    Set<OperationOutput> createOutput = createOp.getOutputs();
    Set<OperationOutput> configureOutput = configOp.getOutputs();
    Assert.assertTrue(oldHostNameAttr instanceof FunctionPropertyValue);
    Assert.assertTrue(newHostNameAttr instanceof FunctionPropertyValue);
    String output1 = ((FunctionPropertyValue) oldHostNameAttr).getElementNameToFetch();
    String output2 = ((FunctionPropertyValue) newHostNameAttr).getElementNameToFetch();
    Assert.assertTrue(createOutput.contains(new OperationOutput(output1)));
    OperationOutput fullOutput1 = createOp.getOutput(output1);
    Assert.assertTrue(fullOutput1.getRelatedAttributes().contains("comp_getOpOutput:old_hostname"));
    Assert.assertTrue(configureOutput.contains(new OperationOutput(output2)));
    OperationOutput fullOutput2 = configOp.getOutput(output2);
    Assert.assertTrue(fullOutput2.getRelatedAttributes().contains("comp_getOpOutput:new_hostname"));
    // check if outputs referenced in get_operation_output on an input parameter is well registered on the related operation
    IValue param = configOp.getInputParameters().get("OUTPUT_FROM_CREATE");
    Assert.assertTrue(param instanceof FunctionPropertyValue);
    String output3 = ((FunctionPropertyValue) param).getElementNameToFetch();
    Assert.assertTrue(createOutput.contains(new OperationOutput(output3)));
    OperationOutput fullOutput3 = configOp.getOutput(output2);
    Assert.assertFalse(fullOutput3.getRelatedAttributes().contains("comp_getOpOutput:OUTPUT_FROM_CREATE"));
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Test(org.junit.Test) AbstractToscaParserSimpleProfileTest(alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)

Example 2 with AbstractInstantiableToscaType

use of org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType 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 AbstractInstantiableToscaType

use of org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType in project alien4cloud by alien4cloud.

the class LocationMatchNodesArtifactsElector method isEligible.

private boolean isEligible(AbstractInstantiableTemplate template, LocationMatchNodeFilter.NodeMatchContext matchContext) {
    if (template == null) {
        return true;
    }
    ArtifactSupport artifactSupport = matchContext.getArtifactSupport();
    // if no supported artifact defined, then return true
    if (artifactSupport == null || ArrayUtils.isEmpty(artifactSupport.getTypes())) {
        return true;
    }
    String[] supportedArtifacts = artifactSupport.getTypes();
    AbstractInstantiableToscaType indexedArtifactToscaElement = matchContext.getElement(AbstractInstantiableToscaType.class, template.getType());
    if (MapUtils.isNotEmpty(indexedArtifactToscaElement.getInterfaces())) {
        for (Interface interfaz : indexedArtifactToscaElement.getInterfaces().values()) {
            for (Operation operation : interfaz.getOperations().values()) {
                if (operation.getImplementationArtifact() != null) {
                    String artifactTypeString = operation.getImplementationArtifact().getArtifactType();
                    ArtifactType artifactType = matchContext.getElement(ArtifactType.class, artifactTypeString);
                    // stop the checking once one artifactType is not supported
                    if (!isFromOneOfTypes(supportedArtifacts, artifactType)) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : ArtifactType(org.alien4cloud.tosca.model.types.ArtifactType) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface) ArtifactSupport(alien4cloud.model.orchestrators.ArtifactSupport)

Example 4 with AbstractInstantiableToscaType

use of org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method mergeInterfaces.

@SneakyThrows
private void mergeInterfaces(AbstractPaaSTemplate pasSTemplate, AbstractInstantiableTemplate abstractTemplate) {
    AbstractToscaType type = pasSTemplate.getIndexedToscaElement();
    Map<String, Interface> typeInterfaces = null;
    if (type instanceof AbstractInstantiableToscaType) {
        typeInterfaces = ((AbstractInstantiableToscaType) type).getInterfaces();
    }
    Map<String, Interface> templateInterfaces = abstractTemplate.getInterfaces();
    // Here merge interfaces: the interface defined in the template should override those from type.
    pasSTemplate.setInterfaces(IndexedModelUtils.mergeInterfaces(JsonUtil.toMap(JsonUtil.toString(typeInterfaces), String.class, Interface.class), templateInterfaces));
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Interface(org.alien4cloud.tosca.model.definitions.Interface) SneakyThrows(lombok.SneakyThrows)

Aggregations

AbstractInstantiableToscaType (org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType)4 Interface (org.alien4cloud.tosca.model.definitions.Interface)3 Operation (org.alien4cloud.tosca.model.definitions.Operation)2 ArtifactSupport (alien4cloud.model.orchestrators.ArtifactSupport)1 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 AbstractToscaParserSimpleProfileTest (alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)1 SneakyThrows (lombok.SneakyThrows)1 IValue (org.alien4cloud.tosca.model.definitions.IValue)1 AbstractToscaType (org.alien4cloud.tosca.model.types.AbstractToscaType)1 ArtifactType (org.alien4cloud.tosca.model.types.ArtifactType)1 Test (org.junit.Test)1