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;
}
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());
}
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);
}
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)));
}
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));
}
Aggregations