use of alien4cloud.paas.model.PaaSRelationshipTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method relationshipGetPropertyKeywordsSucessTest.
@Test
public void relationshipGetPropertyKeywordsSucessTest() throws Throwable {
String warName = "war_1";
String warName_2 = "war_2";
String tomcatName = "tomcat";
String computeName = "comp_tomcat_war";
PaaSNodeTemplate warPaaS = builtPaaSNodeTemplates.get(warName);
PaaSNodeTemplate warPaaS_2 = builtPaaSNodeTemplates.get(warName_2);
PaaSNodeTemplate tomcatPaaS = builtPaaSNodeTemplates.get(tomcatName);
PaaSNodeTemplate computePaaS = builtPaaSNodeTemplates.get(computeName);
PaaSRelationshipTemplate hostedOnRelTemp = warPaaS.getRelationshipTemplate("warHostedOnTomcatTomcat", "war_1");
PaaSRelationshipTemplate hostedOnRelTemp_2 = warPaaS_2.getRelationshipTemplate("warHostedOnTomcatTomcat", "war_2");
Operation configOp = hostedOnRelTemp.getIndexedToscaElement().getInterfaces().get(ToscaRelationshipLifecycleConstants.CONFIGURE).getOperations().get(ToscaRelationshipLifecycleConstants.POST_CONFIGURE_SOURCE);
// test SOURCE keyword
IValue param = configOp.getInputParameters().get("contextPath");
Assert.assertEquals(getPropertyValue(warPaaS, "context_path"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
// get prop from the host of the source node
param = configOp.getInputParameters().get("propFromSourceCompute");
Assert.assertEquals(getPropertyValue(computePaaS, "customHostName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
// test TARGET keyword
param = configOp.getInputParameters().get("tomcatVersion");
Assert.assertEquals(getPropertyValue(tomcatPaaS, "component_version"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
// get prop from the host of the source node
param = configOp.getInputParameters().get("propFromTargetCompute");
Assert.assertEquals(getPropertyValue(computePaaS, "customHostName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
// test SELF keyword on relationship
param = configOp.getInputParameters().get("relName");
Assert.assertEquals(getPropertyValue(hostedOnRelTemp, "relName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
Assert.assertEquals(getPropertyValue(hostedOnRelTemp_2, "relName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp_2, builtPaaSNodeTemplates));
// getting capability properties
param = configOp.getInputParameters().get("valid_node_types");
Assert.assertEquals(getCapabilityPropertyValue(tomcatPaaS, "war_host", "valid_node_types"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
// capabilities not existing in the node
param = configOp.getInputParameters().get("null_capa_prop1");
Assert.assertEquals(null, FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
// property not existing in the capability
param = configOp.getInputParameters().get("null_capa_prop2");
Assert.assertEquals(null, FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
// using SELF keywork to get a capability's property on a relationship should return null
param = configOp.getInputParameters().get("bad_valid_node_types");
Assert.assertEquals(null, FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
}
use of alien4cloud.paas.model.PaaSRelationshipTemplate in project alien4cloud by alien4cloud.
the class PaaSUtilsTest method buildFakePaaSRelTemplate.
private PaaSRelationshipTemplate buildFakePaaSRelTemplate(String source, String target, String targetedCapability) {
PaaSRelationshipTemplate fakePaaSRelTemplate = Mockito.mock(PaaSRelationshipTemplate.class);
RelationshipTemplate relationshipTemplate = buildFakeRelationShip(target, targetedCapability);
Mockito.when(fakePaaSRelTemplate.getTemplate()).thenReturn(relationshipTemplate);
Map<String, Operation> operations = Maps.newHashMap();
operations.put(operation1, buildFakeOperation());
Map<String, Interface> interfaces = Maps.newHashMap();
interfaces.put(interface1, buildFakeInterface(operations));
Mockito.when(fakePaaSRelTemplate.getInterfaces()).thenReturn(interfaces);
Mockito.when(fakePaaSRelTemplate.getSource()).thenReturn(source);
return fakePaaSRelTemplate;
}
use of alien4cloud.paas.model.PaaSRelationshipTemplate 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)));
}
use of alien4cloud.paas.model.PaaSRelationshipTemplate in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method processRelationship.
private void processRelationship(PaaSNodeTemplate paaSNodeTemplate, Map<String, PaaSNodeTemplate> nodeTemplates) {
PaaSRelationshipTemplate hostedOnRelationship = getPaaSRelationshipTemplateFromType(paaSNodeTemplate, NormativeRelationshipConstants.HOSTED_ON);
if (hostedOnRelationship != null) {
String target = hostedOnRelationship.getTemplate().getTarget();
PaaSNodeTemplate parent = nodeTemplates.get(target);
parent.getChildren().add(paaSNodeTemplate);
paaSNodeTemplate.setParent(parent);
}
// Relationships are defined from sources to target. We have to make sure that target node also has the relationship injected.
List<PaaSRelationshipTemplate> allRelationships = getPaaSRelationshipsTemplateFromType(paaSNodeTemplate, NormativeRelationshipConstants.ROOT);
for (PaaSRelationshipTemplate relationship : allRelationships) {
// inject the relationship in it's target.
String target = relationship.getTemplate().getTarget();
nodeTemplates.get(target).getRelationshipTemplates().add(relationship);
}
}
use of alien4cloud.paas.model.PaaSRelationshipTemplate in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method processBlockStorage.
private void processBlockStorage(PaaSNodeTemplate paaSNodeTemplate, Map<String, PaaSNodeTemplate> nodeTemplates) {
PaaSRelationshipTemplate attachTo = getPaaSRelationshipTemplateFromType(paaSNodeTemplate, NormativeRelationshipConstants.ATTACH_TO);
if (attachTo != null) {
String target = attachTo.getTemplate().getTarget();
PaaSNodeTemplate parent = nodeTemplates.get(target);
parent.getStorageNodes().add(paaSNodeTemplate);
paaSNodeTemplate.setParent(parent);
}
}
Aggregations