Search in sources :

Example 16 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class TopologyUtils method filterInterfaces.

/**
 * Extract all interfaces that have given operations, and filter out all operations that are not in the includedOperations
 *
 * @param interfaces interfaces to filter
 * @param includedOperations operations that will be included in the result
 * @return filter interfaces
 */
public static Map<String, Interface> filterInterfaces(Map<String, Interface> interfaces, Set<String> includedOperations) {
    Map<String, Interface> result = Maps.newHashMap();
    for (Map.Entry<String, Interface> interfaceEntry : interfaces.entrySet()) {
        Map<String, Operation> operations = Maps.newHashMap();
        for (Map.Entry<String, Operation> operationEntry : interfaceEntry.getValue().getOperations().entrySet()) {
            if (includedOperations.contains(operationEntry.getKey())) {
                operations.put(operationEntry.getKey(), operationEntry.getValue());
            }
        }
        if (!operations.isEmpty()) {
            Interface inter = new Interface();
            inter.setDescription(interfaceEntry.getValue().getDescription());
            inter.setOperations(operations);
            result.put(interfaceEntry.getKey(), inter);
        }
    }
    return result;
}
Also used : Operation(org.alien4cloud.tosca.model.definitions.Operation) Map(java.util.Map) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 17 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class RuntimeController method validateParameters.

private void validateParameters(Interface interfass, OperationExecRequest operationRequest, Set<CSARDependency> dependencies) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException, ConstraintRequiredParameterException {
    try {
        if (dependencies != null) {
            ToscaContext.init(dependencies);
        }
        ArrayList<String> missingParams = Lists.newArrayList();
        Operation operation = interfass.getOperations().get(operationRequest.getOperationName());
        if (operation.getInputParameters() != null) {
            for (Entry<String, IValue> inputParameter : operation.getInputParameters().entrySet()) {
                if (inputParameter.getValue().isDefinition()) {
                    Object requestInputParameter = operationRequest.getParameters() == null ? null : operationRequest.getParameters().get(inputParameter.getKey());
                    PropertyDefinition currentOperationParameter = (PropertyDefinition) inputParameter.getValue();
                    if (requestInputParameter != null) {
                        if (!(requestInputParameter instanceof Map) || !FunctionEvaluator.containGetSecretFunction(PropertyService.asFunctionPropertyValue(requestInputParameter))) {
                            // recover the good property definition for the current parameter
                            ConstraintPropertyService.checkPropertyConstraint(inputParameter.getKey(), requestInputParameter, currentOperationParameter);
                        }
                    } else if (currentOperationParameter.isRequired()) {
                        // input param not in the request, id required this is a missing parameter...
                        missingParams.add(inputParameter.getKey());
                    } else {
                        // set the value to null
                        operation.getInputParameters().put(inputParameter.getKey(), null);
                    }
                }
            }
        }
        // check required input issue
        if (!missingParams.isEmpty()) {
            log.error("Missing required parameter", missingParams);
            ConstraintInformation constraintInformation = new ConstraintInformation(null, null, missingParams.toString(), "required");
            throw new ConstraintRequiredParameterException("Missing required parameters", null, constraintInformation);
        }
    } finally {
        if (ToscaContext.get() != null) {
            ToscaContext.destroy();
        }
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) ConstraintInformation(alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation) ApiOperation(io.swagger.annotations.ApiOperation) Operation(org.alien4cloud.tosca.model.definitions.Operation) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Map(java.util.Map) ConstraintRequiredParameterException(org.alien4cloud.tosca.exceptions.ConstraintRequiredParameterException)

Example 18 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class ToscaSerializerUtils method formatRepositories.

public static String formatRepositories(String topologyArchiveName, String topologyArchiveVersion, Topology topology) {
    StringBuilder buffer = new StringBuilder();
    Set<String> repositoriesName = Sets.newHashSet();
    for (NodeTemplate node : safe(topology.getNodeTemplates()).values()) {
        for (DeploymentArtifact artifact : safe(node.getArtifacts()).values()) {
            // Only generate repositories for the current topology
            if (isInternalRepoArtifact(artifact, topologyArchiveName, topologyArchiveVersion)) {
                buffer.append("  ").append(artifact.getRepositoryName()).append(":");
                buffer.append("\n").append(formatRepository(artifact, 2)).append("\n");
            }
        }
        for (Interface anInterface : safe(node.getInterfaces()).values()) {
            for (Operation operation : safe(anInterface.getOperations()).values()) {
                if (operation.getImplementationArtifact() != null && isInternalRepoArtifact(operation.getImplementationArtifact(), topologyArchiveName, topologyArchiveVersion)) {
                    buffer.append("  ").append(operation.getImplementationArtifact().getRepositoryName()).append(":");
                    buffer.append("\n").append(formatRepository(operation.getImplementationArtifact(), 2)).append("\n");
                }
            }
        }
    }
    if (MapUtils.isNotEmpty(topology.getInputArtifacts())) {
        topology.getInputArtifacts().values().forEach(inputArtifact -> {
            if (StringUtils.isNotBlank(inputArtifact.getRepositoryURL()) && repositoriesName.add(inputArtifact.getRepositoryName())) {
                buffer.append("  ").append(inputArtifact.getRepositoryName()).append(":");
                buffer.append("\n").append(formatRepository(inputArtifact, 2)).append("\n");
            }
        });
    }
    buffer.setLength(buffer.length() - 1);
    return buffer.toString();
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Operation(org.alien4cloud.tosca.model.definitions.Operation) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 19 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.

the class NodeTemplatePostProcessor method process.

@Override
public void process(final NodeTemplate instance) {
    // ensure type exists
    referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), NodeType.class));
    final NodeType nodeType = ToscaContext.get(NodeType.class, instance.getType());
    if (nodeType == null) {
        // error managed by the reference post processor.
        return;
    }
    // FIXME we should check that the artifact is defined at the type level.
    safe(instance.getArtifacts()).values().forEach(templateDeploymentArtifactPostProcessor);
    // TODO Manage interfaces inputs to copy them to all operations.
    safe(instance.getInterfaces()).values().stream().flatMap(anInterface -> safe(anInterface.getOperations()).values().stream()).map(Operation::getImplementationArtifact).filter(Objects::nonNull).forEach(implementationArtifactPostProcessor);
    // Merge the node template with data coming from the type (default values etc.).
    NodeTemplate tempObject = TemplateBuilder.buildNodeTemplate(nodeType, instance, false);
    safe(instance.getCapabilities()).keySet().forEach(s -> {
        if (!safe(tempObject.getCapabilities()).containsKey(s)) {
            Node node = ParsingContextExecution.getObjectToNodeMap().get(s);
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_CAPABILITY, null, node.getStartMark(), null, node.getEndMark(), s));
        }
    });
    instance.setAttributes(tempObject.getAttributes());
    instance.setCapabilities(tempObject.getCapabilities());
    instance.setProperties(tempObject.getProperties());
    instance.setRequirements(tempObject.getRequirements());
    instance.setArtifacts(tempObject.getArtifacts());
    instance.setInterfaces(tempObject.getInterfaces());
    // apply post processor to capabilities defined locally on the element (no need to post-processed the one merged)
    safe(instance.getCapabilities()).entrySet().forEach(capabilityPostProcessor);
    safe(instance.getRequirements()).entrySet().forEach(requirementPostProcessor);
    propertyValueChecker.checkProperties(nodeType, instance.getProperties(), instance.getName());
}
Also used : Operation(org.alien4cloud.tosca.model.definitions.Operation) ParsingErrorLevel(alien4cloud.tosca.parser.ParsingErrorLevel) Resource(javax.annotation.Resource) TemplateBuilder(alien4cloud.tosca.topology.TemplateBuilder) ErrorCode(alien4cloud.tosca.parser.impl.ErrorCode) NodeType(org.alien4cloud.tosca.model.types.NodeType) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Objects(java.util.Objects) Node(org.yaml.snakeyaml.nodes.Node) Component(org.springframework.stereotype.Component) ParsingContextExecution(alien4cloud.tosca.parser.ParsingContextExecution) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) ToscaContext(alien4cloud.tosca.context.ToscaContext) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) NodeType(org.alien4cloud.tosca.model.types.NodeType) Node(org.yaml.snakeyaml.nodes.Node) Operation(org.alien4cloud.tosca.model.definitions.Operation)

Aggregations

Operation (org.alien4cloud.tosca.model.definitions.Operation)19 Interface (org.alien4cloud.tosca.model.definitions.Interface)16 Test (org.junit.Test)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)4 Map (java.util.Map)3 IValue (org.alien4cloud.tosca.model.definitions.IValue)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)2 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)2 AbstractInstantiableToscaType (org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType)2 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)2 NotFoundException (alien4cloud.exception.NotFoundException)1 ArtifactSupport (alien4cloud.model.orchestrators.ArtifactSupport)1 IllegalOperationWarning (alien4cloud.topology.warning.IllegalOperationWarning)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ParsingContextExecution (alien4cloud.tosca.parser.ParsingContextExecution)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1 ParsingErrorLevel (alien4cloud.tosca.parser.ParsingErrorLevel)1