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