Search in sources :

Example 61 with PropertyDefinition

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

the class InputPropertiesStepDefinitions method i_define_the_capability_property_of_the_node_of_typeId_as_input_property.

@Given("^I define the capability \"(.*?)\" property \"(.*?)\" of the node \"(.*?)\" as input property$")
public void i_define_the_capability_property_of_the_node_of_typeId_as_input_property(String capabilityName, String propertyName, String nodeName) throws Throwable {
    String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
    String response = Context.getRestClientInstance().get(url);
    TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
    NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
    Capability capability = template.getCapabilities().get(capabilityName);
    CapabilityType capabilityType = topologyDTO.getCapabilityTypes().get(capability.getType());
    PropertyDefinition propertyDefinition = capabilityType.getProperties().get(propertyName);
    String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), propertyName);
    String json = JsonUtil.toString(propertyDefinition);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) Capability(org.alien4cloud.tosca.model.templates.Capability) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Given(cucumber.api.java.en.Given)

Example 62 with PropertyDefinition

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

the class InputPropertiesStepDefinitions method I_define_the_property_of_the_node_as_input_property.

@When("^I define the property \"([^\"]*)\" of the node \"([^\"]*)\" as input property$")
public void I_define_the_property_of_the_node_as_input_property(String inputId, String nodeName) throws Throwable {
    // get the topologyTDO to have the real type of the propertyDefinition
    PropertyDefinition propertyDefinition = getPropertyDefinition(nodeName, inputId);
    AddInputOperation addInputOperation = new AddInputOperation();
    addInputOperation.setPropertyDefinition(propertyDefinition);
    addInputOperation.setInputName(inputId);
    EditorStepDefinitions.do_i_execute_the_operation(addInputOperation);
    SetNodePropertyAsInputOperation setNodePropertyAsInputOperation = new SetNodePropertyAsInputOperation();
    setNodePropertyAsInputOperation.setInputName(inputId);
    setNodePropertyAsInputOperation.setPropertyName(inputId);
    setNodePropertyAsInputOperation.setNodeName(nodeName);
    EditorStepDefinitions.do_i_execute_the_operation(setNodePropertyAsInputOperation);
    EditorStepDefinitions.do_i_save_the_topology();
}
Also used : AddInputOperation(org.alien4cloud.tosca.editor.operations.inputs.AddInputOperation) SetNodePropertyAsInputOperation(org.alien4cloud.tosca.editor.operations.nodetemplate.inputs.SetNodePropertyAsInputOperation) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) When(cucumber.api.java.en.When)

Example 63 with PropertyDefinition

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

the class InputService method onCopyConfiguration.

@EventListener
@Order(10)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
    DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    if (deploymentInputs == null || MapUtils.isEmpty(deploymentInputs.getInputs())) {
        // Nothing to copy
        return;
    }
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getInputs())) {
        Map<String, PropertyDefinition> inputsDefinitions = topology.getInputs();
        Map<String, AbstractPropertyValue> inputsToCopy = deploymentInputs.getInputs().entrySet().stream().filter(inputEntry -> inputsDefinitions.containsKey(inputEntry.getKey())).filter(inputEntry -> {
            // Copy only inputs which satisfy the new input definition
            try {
                if (!(inputEntry.getValue() instanceof FunctionPropertyValue)) {
                    ConstraintPropertyService.checkPropertyConstraint(inputEntry.getKey(), PropertyService.asPropertyValue(inputEntry.getValue()), inputsDefinitions.get(inputEntry.getKey()));
                }
                return true;
            } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
                return false;
            }
        }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(inputsToCopy)) {
            DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
            if (targetDeploymentInputs == null) {
                targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
            }
            // Copy inputs from original topology
            targetDeploymentInputs.setInputs(inputsToCopy);
            deploymentConfigurationDao.save(targetDeploymentInputs);
        }
    }
}
Also used : ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) TagUtil(alien4cloud.utils.TagUtil) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) MetaPropertiesService(alien4cloud.common.MetaPropertiesService) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) Inject(javax.inject.Inject) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Service(org.springframework.stereotype.Service) Application(alien4cloud.model.application.Application) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Map(java.util.Map) ConstraintPropertyService(alien4cloud.utils.services.ConstraintPropertyService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) EventListener(org.springframework.context.event.EventListener) PropertyService(alien4cloud.utils.services.PropertyService) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 64 with PropertyDefinition

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

the class ArchiveRootPostProcessor method processRepositoriesDefinitions.

private void processRepositoriesDefinitions(Map<String, RepositoryDefinition> repositories) {
    if (MapUtils.isNotEmpty(repositories)) {
        DataType credentialType = ToscaContext.get(DataType.class, NormativeCredentialConstant.DATA_TYPE);
        repositories.values().forEach(repositoryDefinition -> {
            if (repositoryDefinition.getCredential() != null) {
                credentialType.getProperties().forEach((propertyName, propertyDefinition) -> {
                    // Fill with default value
                    if (!repositoryDefinition.getCredential().getValue().containsKey(propertyName)) {
                        AbstractPropertyValue defaultValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(propertyDefinition);
                        if (defaultValue instanceof PropertyValue) {
                            repositoryDefinition.getCredential().getValue().put(propertyName, ((PropertyValue) defaultValue).getValue());
                        }
                    }
                });
                Node credentialNode = ParsingContextExecution.getObjectToNodeMap().get(repositoryDefinition.getCredential());
                PropertyDefinition propertyDefinition = new PropertyDefinition();
                propertyDefinition.setType(NormativeCredentialConstant.DATA_TYPE);
                propertyValueChecker.checkProperty("credential", credentialNode, repositoryDefinition.getCredential(), propertyDefinition, repositoryDefinition.getId());
            }
        });
    }
}
Also used : Node(org.yaml.snakeyaml.nodes.Node) DataType(org.alien4cloud.tosca.model.types.DataType) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 65 with PropertyDefinition

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

the class SuggestionService method setSuggestionIdOnPropertyDefinition.

/**
 * Add the suggestion ID of the new suggestionEntry to the appropriate propertyDefinition.
 *
 * @param suggestionEntry entry of suggestion
 */
public void setSuggestionIdOnPropertyDefinition(SuggestionEntry suggestionEntry) {
    Class<? extends AbstractInheritableToscaType> targetClass = (Class<? extends AbstractInheritableToscaType>) alienDAO.getTypesToClasses().get(suggestionEntry.getEsType());
    // FIXME what if targetClass is null ?
    Object array = toscaTypeSearchService.findAll(targetClass, suggestionEntry.getTargetElementId());
    if (array != null) {
        int length = Array.getLength(array);
        for (int i = 0; i < length; i++) {
            AbstractInheritableToscaType targetElement = ((AbstractInheritableToscaType) Array.get(array, i));
            PropertyDefinition propertyDefinition = targetElement.getProperties().get(suggestionEntry.getTargetProperty());
            if (propertyDefinition == null) {
                throw new NotFoundException("Property [" + suggestionEntry.getTargetProperty() + "] not found for element [" + suggestionEntry.getTargetElementId() + "]");
            } else {
                switch(propertyDefinition.getType()) {
                    case ToscaTypes.VERSION:
                    case ToscaTypes.STRING:
                        propertyDefinition.setSuggestionId(suggestionEntry.getId());
                        alienDAO.save(targetElement);
                        break;
                    case ToscaTypes.LIST:
                    case ToscaTypes.MAP:
                        PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
                        if (entrySchema != null) {
                            entrySchema.setSuggestionId(suggestionEntry.getId());
                            alienDAO.save(targetElement);
                        } else {
                            throw new InvalidArgumentException("Cannot suggest a list / map type with no entry schema definition");
                        }
                        break;
                    default:
                        throw new InvalidArgumentException(propertyDefinition.getType() + " cannot be suggested, only property of type string list or map can be suggested");
                }
            }
        }
    }
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NotFoundException(alien4cloud.exception.NotFoundException) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) ValidValuesConstraint(org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint)

Aggregations

PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)101 Test (org.junit.Test)42 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)23 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)20 Map (java.util.Map)19 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeType (org.alien4cloud.tosca.model.types.NodeType)15 NotFoundException (alien4cloud.exception.NotFoundException)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)11 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)11 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)10 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 Capability (org.alien4cloud.tosca.model.templates.Capability)10 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)10 DataType (org.alien4cloud.tosca.model.types.DataType)9 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)8 Set (java.util.Set)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)8