use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class IndexedModelTest method testMergeInterfaceOperationsFromNull.
@Test
public void testMergeInterfaceOperationsFromNull() {
// FROM's operation is null
Map<String, Interface> from = Maps.newHashMap();
Interface i1 = new Interface();
from.put("i1", i1);
Map<String, Interface> to = Maps.newHashMap();
Interface i2 = new Interface();
Map<String, Operation> ios2 = Maps.newHashMap();
Operation o2 = new Operation();
ios2.put("o1", o2);
i2.setOperations(ios2);
to.put("i1", i2);
Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
assertEquals(1, merged.size());
assertSame(merged.get("i1").getOperations().get("o1"), o2);
}
use of org.alien4cloud.tosca.model.definitions.Operation 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.definitions.Operation in project alien4cloud by alien4cloud.
the class RuntimeController method validateOperation.
private void validateOperation(Interface interfass, OperationExecRequest operationRequest, Set<CSARDependency> dependencies) throws ConstraintFunctionalException {
Operation operation = interfass.getOperations().get(operationRequest.getOperationName());
if (operation == null) {
throw new NotFoundException("Operation [" + operationRequest.getOperationName() + "] is not defined in the interface [" + operationRequest.getInterfaceName() + "] of the node [" + operationRequest.getNodeTemplateName() + "]");
}
// validate parameters (value/type and required value)
validateParameters(interfass, operationRequest, dependencies);
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class TopologyServiceInterfaceOverrideCheckerService method findWarnings.
public List<IllegalOperationWarning> findWarnings(Topology topology) {
Set<IllegalOperationWarning> warnings = Sets.newHashSet();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
for (Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
NodeTemplate nodeTemplate = nodeTempEntry.getValue();
Map<String, RelationshipTemplate> relationships = nodeTemplate.getRelationships();
if (relationships != null) {
for (Entry<String, RelationshipTemplate> entry : relationships.entrySet()) {
RelationshipTemplate relationshipTemplate = entry.getValue();
String target = relationshipTemplate.getTarget();
NodeTemplate targetNodeTemplate = nodeTemplates.get(target);
boolean serviceIsSource = isService(nodeTemplate);
boolean serviceIsTarget = isService(targetNodeTemplate);
if (serviceIsSource || serviceIsTarget) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
if (relationshipType != null) {
Map<String, Interface> interfaces = relationshipType.getInterfaces();
if (interfaces != null) {
interfaces.forEach((relationshipName, relationshipInterface) -> {
Map<String, Operation> operations = relationshipInterface.getOperations();
if (operations != null) {
operations.forEach((operationName, operation) -> {
String serviceName;
if (serviceIsTarget) {
serviceName = nodeTemplate.getName();
switch(operationName.toLowerCase()) {
case "add_source":
case "remove_source":
case "source_changed":
case "post_configure_target":
case "pre_configure_target":
ImplementationArtifact artifact = operation.getImplementationArtifact();
boolean stepDoSomething = artifact != null;
if (stepDoSomething) {
addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
}
break;
}
}
if (serviceIsSource) {
serviceName = targetNodeTemplate.getName();
switch(operationName.toLowerCase()) {
case "add_target":
case "remove_target":
case "target_changed":
case "pre_configure_source":
case "post_configure_source":
ImplementationArtifact artifact = operation.getImplementationArtifact();
boolean stepDoSomething = artifact != null;
if (stepDoSomething) {
addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
}
break;
}
}
});
}
});
}
}
}
}
}
}
return warnings.isEmpty() ? null : new ArrayList<>(warnings);
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class WorkflowUtils method getOperation.
/**
* @return the operation browsing the type hierarchy
* FIXME: should we browse hierarchy ? what about order ?
*/
public static Operation getOperation(String nodeTypeName, String interfaceName, String operationName, TopologyContext topologyContext) {
NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTypeName);
if (nodeType == null) {
return null;
}
if (nodeType.getInterfaces() == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
Interface interfaceType = nodeType.getInterfaces().get(interfaceName);
if (interfaceType == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
if (interfaceType.getOperations() == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
Operation operation = interfaceType.getOperations().get(operationName);
if (interfaceType.getOperations() == null) {
return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
}
return operation;
}
Aggregations