Search in sources :

Example 16 with PaaSNodeTemplate

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

the class FunctionEvaluator method getWithParentsNodes.

private static List<PaaSNodeTemplate> getWithParentsNodes(final PaaSNodeTemplate paaSNodeTemplate) {
    List<PaaSNodeTemplate> toReturn = Lists.newArrayList();
    PaaSNodeTemplate parent = paaSNodeTemplate;
    while (parent != null) {
        toReturn.add(parent);
        parent = parent.getParent();
    }
    return toReturn;
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate)

Example 17 with PaaSNodeTemplate

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

the class PaaSUtils method processNodeTemplateProperties.

/**
 * Inject node template and capabilities properties as input parameters for all its interfaces operations <br>
 * The injected input names are uppercased and is in form:
 * <ul>
 * <li>{@code SELF_<PROPERTY_NAME>} for node property
 * <li>{@code SELF_CAPABILITIES_<CAPABILITY_NAME>_<PROPERTY_NAME>} for capability property
 * </ul>
 * In case of name conflict, the overriding order is: (--> = overrides)
 *
 * <pre>
 * declared input --> node property input --> capability property input
 * </pre>
 *
 * @param paaSTemplate The {@link PaaSNodeTemplate} to process
 */
public static void processNodeTemplateProperties(PaaSNodeTemplate paaSTemplate) {
    NodeTemplate template = paaSTemplate.getTemplate();
    // inject nodetemplate properties
    if (MapUtils.isNotEmpty(template.getProperties())) {
        injectPropertiesAsInputs(ToscaFunctionConstants.SELF, null, template.getProperties(), paaSTemplate.getInterfaces(), baseName -> StringUtils.joinWith(AlienUtils.DEFAULT_PREFIX_SEPARATOR, ToscaFunctionConstants.SELF, baseName));
    }
    // inject capabilities properties
    injectCapabilitiesProperties(template, paaSTemplate.getInterfaces());
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate)

Example 18 with PaaSNodeTemplate

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

the class TopologyTreeBuilderService method buildPaaSTopology.

/**
 * Build the topology for deployment on the PaaS.
 *
 * @param nodeTemplates The node templates that are part of the topology.
 * @return The parsed topology for the PaaS with.
 */
public PaaSTopology buildPaaSTopology(Map<String, PaaSNodeTemplate> nodeTemplates) {
    // Build hosted_on tree
    List<PaaSNodeTemplate> computes = new ArrayList<PaaSNodeTemplate>();
    List<PaaSNodeTemplate> networks = new ArrayList<PaaSNodeTemplate>();
    List<PaaSNodeTemplate> volumes = new ArrayList<PaaSNodeTemplate>();
    List<PaaSNodeTemplate> nonNatives = new ArrayList<PaaSNodeTemplate>();
    Map<String, List<PaaSNodeTemplate>> groups = Maps.newHashMap();
    for (Entry<String, PaaSNodeTemplate> entry : nodeTemplates.entrySet()) {
        PaaSNodeTemplate paaSNodeTemplate = entry.getValue();
        boolean isCompute = ToscaTypeUtils.isOfType(paaSNodeTemplate.getIndexedToscaElement(), NormativeComputeConstants.COMPUTE_TYPE);
        boolean isNetwork = ToscaTypeUtils.isOfType(paaSNodeTemplate.getIndexedToscaElement(), NormativeNetworkConstants.NETWORK_TYPE);
        boolean isVolume = ToscaTypeUtils.isOfType(paaSNodeTemplate.getIndexedToscaElement(), NormativeBlockStorageConstants.BLOCKSTORAGE_TYPE);
        if (isVolume) {
            // manage block storage
            processBlockStorage(paaSNodeTemplate, nodeTemplates);
            volumes.add(paaSNodeTemplate);
        } else if (isCompute) {
            // manage compute
            processNetwork(paaSNodeTemplate, nodeTemplates);
            processRelationship(paaSNodeTemplate, nodeTemplates);
            computes.add(paaSNodeTemplate);
        } else if (isNetwork) {
            // manage network
            networks.add(paaSNodeTemplate);
        } else {
            // manage non native
            nonNatives.add(paaSNodeTemplate);
            processRelationship(paaSNodeTemplate, nodeTemplates);
        }
        if (entry.getValue().getGroups() != null) {
            for (String group : entry.getValue().getGroups()) {
                List<PaaSNodeTemplate> currentGroupMembers = groups.get(group);
                if (currentGroupMembers == null) {
                    currentGroupMembers = Lists.newArrayList();
                    groups.put(group, currentGroupMembers);
                }
                currentGroupMembers.add(entry.getValue());
            }
        }
    }
    // check and register possible operation outputs
    processOperationsOutputs(nodeTemplates);
    // inject all properties as operation inputs for related interfaces
    PaaSUtils.injectPropertiesAsOperationInputs(nodeTemplates);
    return new PaaSTopology(computes, networks, volumes, nonNatives, nodeTemplates, groups);
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with PaaSNodeTemplate

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

the class PaaSUtilsTest method injectNodeTemplatePropertiesAsInputs.

@Test
public void injectNodeTemplatePropertiesAsInputs() throws Exception {
    // NodeType nodeType = buildFakeNodeType("test.node.fake1", "1");
    PaaSNodeTemplate paaSNodeTemplate = buildPaaSNodeTemplate();
    PaaSUtils.processNodeTemplateProperties(paaSNodeTemplate);
    Operation operation = paaSNodeTemplate.getInterfaces().get(interface1).getOperations().get(operation1);
    Assert.assertNotNull(operation.getInputParameters());
    // assert all node properties are inputs properties
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake1));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake5));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake2));
    // complex property should not be there
    Assert.assertFalse(operation.getInputParameters().containsKey(fake3));
    // assert that the property from the operation has not been overrided
    Assert.assertEquals(operation.getInputParameters().get(fake1), new ScalarPropertyValue("1_from_operation"));
    // check capabilities inputs
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + generateCapaInputName(fakeCapa1, fake1)));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + generateCapaInputName(fakeCapa1, fake3)));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + generateCapaInputName(fakeCapa1, fake2)));
    Assert.assertTrue(operation.getInputParameters().containsKey(SELF + generateCapaInputName(fakeCapa1, fake5)));
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) Test(org.junit.Test)

Example 20 with PaaSNodeTemplate

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

the class FunctionEvaluatorTest method parseComplexProperty.

@Test
public void parseComplexProperty() {
    String complexPropName = "complex_prop";
    PaaSNodeTemplate complexPropNode = builtPaaSNodeTemplates.get(complexPropName);
    Operation configOp = complexPropNode.getIndexedToscaElement().getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CREATE);
    Assert.assertEquals("{\n" + "  \"nested_map\" : {\n" + "    \"tutu\" : \"tata\",\n" + "    \"toctoc\" : \"tactac\"\n" + "  },\n" + "  \"nested\" : \"toto\",\n" + "  \"nested_array\" : [ \"titi\", \"tuctuc\" ]\n" + "}", FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) configOp.getInputParameters().get("COMPLEX"), complexPropNode, builtPaaSNodeTemplates));
    Assert.assertEquals("toto", FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) configOp.getInputParameters().get("NESTED"), complexPropNode, builtPaaSNodeTemplates));
    Assert.assertEquals("titi", FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) configOp.getInputParameters().get("NESTED_ARRAY_ELEMENT"), complexPropNode, builtPaaSNodeTemplates));
    Assert.assertEquals("tata", FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) configOp.getInputParameters().get("NESTED_MAP_ELEMENT"), complexPropNode, builtPaaSNodeTemplates));
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) Test(org.junit.Test) AbstractToscaParserSimpleProfileTest(alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)

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