Search in sources :

Example 6 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate 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 7 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class FunctionEvaluatorTest method getPropertyWrongDefOrUSageTest.

@Test(expected = BadUsageKeywordException.class)
public void getPropertyWrongDefOrUSageTest() throws Throwable {
    String computeName = "comp_tomcat_war";
    PaaSNodeTemplate computePaaS = builtPaaSNodeTemplates.get(computeName);
    Operation configOp = computePaaS.getIndexedToscaElement().getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CONFIGURE);
    // case keyword SOURCE used on a NodeType
    IValue param = configOp.getInputParameters().get("keywordSourceBadUsage");
    try {
        FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, computePaaS, builtPaaSNodeTemplates);
    } catch (BadUsageKeywordException e) {
        // case keyword TARGET used on a NodeType
        param = configOp.getInputParameters().get("KeywordTargetBadUsage");
        FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, computePaaS, builtPaaSNodeTemplates);
    }
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) Test(org.junit.Test) AbstractToscaParserSimpleProfileTest(alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)

Example 8 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class PaaSUtilsTest method buildFakePaaSNodeTemplate.

private PaaSNodeTemplate buildFakePaaSNodeTemplate(NodeTemplate nodeTemplate, Map<String, Interface> interfaces) {
    PaaSNodeTemplate fakePaaSNodeTemplate = Mockito.mock(PaaSNodeTemplate.class);
    Mockito.when(fakePaaSNodeTemplate.getTemplate()).thenReturn(nodeTemplate);
    Mockito.when(fakePaaSNodeTemplate.getInterfaces()).thenReturn(interfaces);
    return fakePaaSNodeTemplate;
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate)

Example 9 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class PaaSUtilsTest method injectRelationshipTemplatePropertiesAsInputs.

@Test
public void injectRelationshipTemplatePropertiesAsInputs() throws Exception {
    Map<String, PaaSNodeTemplate> nodes = Maps.newHashMap();
    PaaSNodeTemplate source = buildPaaSNodeTemplate();
    nodes.put(node1, source);
    PaaSNodeTemplate target = buildPaaSNodeTemplate();
    nodes.put(node2, target);
    PaaSRelationshipTemplate paaSRelationshipTemplate = buildFakePaaSRelTemplate(node1, node2, fakeCapa1);
    Mockito.when(source.getRelationshipTemplates()).thenReturn(Lists.newArrayList(paaSRelationshipTemplate));
    PaaSUtils.processRelationshipTemplateProperties(paaSRelationshipTemplate, nodes);
    Operation operation = paaSRelationshipTemplate.getInterfaces().get(interface1).getOperations().get(operation1);
    Assert.assertNotNull(operation.getInputParameters());
    // assert all relationship properties are inputs properties
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake1));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake3));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake5));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake2));
    // assert that the property from the operation has not been overrided
    Assert.assertEquals(operation.getInputParameters().get(fake1), new ScalarPropertyValue("1_from_operation"));
    // check source node inputs
    Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake1)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake2)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake3)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake5)));
    // check target node inputs
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake1)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake2)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake3)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake5)));
    // check targeted capability inputs
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake1)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake2)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake5)));
    Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake3)));
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) Test(org.junit.Test)

Example 10 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class PaaSUtilsTest method buildPaaSNodeTemplate.

private PaaSNodeTemplate buildPaaSNodeTemplate() {
    Map<String, Capability> capabilities = Maps.newHashMap();
    capabilities.put(fakeCapa1, buildFakeCapability());
    NodeTemplate nodeTemplate = buildFakeNodeTemplate(capabilities);
    Map<String, Operation> operations = Maps.newHashMap();
    operations.put(operation1, buildFakeOperation());
    Map<String, Interface> interfaces = Maps.newHashMap();
    interfaces.put(interface1, buildFakeInterface(operations));
    return buildFakePaaSNodeTemplate(nodeTemplate, interfaces);
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability)

Aggregations

PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)21 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)7 Test (org.junit.Test)7 AbstractToscaParserSimpleProfileTest (alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)5 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 PaaSTopology (alien4cloud.paas.model.PaaSTopology)4 Capability (org.alien4cloud.tosca.model.templates.Capability)3 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 Location (alien4cloud.model.orchestrators.locations.Location)1 ParsingException (alien4cloud.tosca.parser.ParsingException)1 Closeable (java.io.Closeable)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1