Search in sources :

Example 16 with FunctionPropertyValue

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

the class TopologyCompositionService method processComposition.

/**
 * Process the composition:
 * <ul>
 * <li>remove the 'proxy' node from the parent.
 * <li>merge the child topology nodes into the parent nodes.
 * <li>
 * </ul>
 *
 * @param compositionCouple
 */
private void processComposition(CompositionCouple compositionCouple) {
    // first of all, remove the proxy node from the parent
    NodeTemplate proxyNodeTemplate = compositionCouple.parent.getNodeTemplates().remove(compositionCouple.nodeName);
    // properties of the proxy are used to feed the property values of child node that use get_input
    for (NodeTemplate childNodeTemplate : compositionCouple.child.getNodeTemplates().values()) {
        for (Entry<String, AbstractPropertyValue> propertyEntry : childNodeTemplate.getProperties().entrySet()) {
            AbstractPropertyValue pValue = propertyEntry.getValue();
            if (isGetInput(pValue)) {
                String inputName = ((FunctionPropertyValue) pValue).getTemplateName();
                propertyEntry.setValue(proxyNodeTemplate.getProperties().get(inputName));
            }
        }
        for (Entry<String, Capability> capabilityEntry : childNodeTemplate.getCapabilities().entrySet()) {
            if (capabilityEntry.getValue().getProperties() != null) {
                for (Entry<String, AbstractPropertyValue> propertyEntry : capabilityEntry.getValue().getProperties().entrySet()) {
                    AbstractPropertyValue pValue = propertyEntry.getValue();
                    if (isGetInput(pValue)) {
                        String inputName = ((FunctionPropertyValue) pValue).getTemplateName();
                        propertyEntry.setValue(proxyNodeTemplate.getProperties().get(inputName));
                    }
                }
            }
        }
    }
    // all relations from the proxy must now start from the corresponding node
    if (proxyNodeTemplate.getRelationships() != null) {
        for (Entry<String, RelationshipTemplate> e : proxyNodeTemplate.getRelationships().entrySet()) {
            String relationShipKey = e.getKey();
            RelationshipTemplate proxyRelationShip = e.getValue();
            String requirementName = proxyRelationShip.getRequirementName();
            SubstitutionTarget substitutionTarget = compositionCouple.child.getSubstitutionMapping().getRequirements().get(requirementName);
            NodeTemplate nodeTemplate = compositionCouple.child.getNodeTemplates().get(substitutionTarget.getNodeTemplateName());
            if (nodeTemplate.getRelationships() == null) {
                Map<String, RelationshipTemplate> relationships = Maps.newHashMap();
                nodeTemplate.setRelationships(relationships);
            }
            nodeTemplate.getRelationships().put(relationShipKey, proxyRelationShip);
            proxyRelationShip.setRequirementName(substitutionTarget.getTargetId());
        }
    }
    // all relations that target the proxy must be redirected to the corresponding child node
    for (NodeTemplate otherNodes : compositionCouple.parent.getNodeTemplates().values()) {
        if (otherNodes.getRelationships() != null) {
            for (RelationshipTemplate relationshipTemplate : otherNodes.getRelationships().values()) {
                if (relationshipTemplate.getTarget().equals(compositionCouple.nodeName)) {
                    SubstitutionTarget st = compositionCouple.child.getSubstitutionMapping().getCapabilities().get(relationshipTemplate.getTargetedCapabilityName());
                    relationshipTemplate.setTarget(st.getNodeTemplateName());
                    relationshipTemplate.setTargetedCapabilityName(st.getTargetId());
                }
            }
        }
    }
    if (compositionCouple.parent.getOutputAttributes() != null) {
        Set<String> outputAttributes = compositionCouple.parent.getOutputAttributes().remove(compositionCouple.nodeName);
        if (outputAttributes != null) {
            for (String proxyAttributeName : outputAttributes) {
                sustituteGetAttribute(compositionCouple.child, compositionCouple.parent, proxyAttributeName);
            }
        }
    }
    // the parent itself expose stuffs, we eventually need to replace substitution targets
    if (compositionCouple.parent.getSubstitutionMapping() != null) {
        if (compositionCouple.parent.getSubstitutionMapping().getCapabilities() != null) {
            for (Entry<String, SubstitutionTarget> substitutionCapabilityEntry : compositionCouple.parent.getSubstitutionMapping().getCapabilities().entrySet()) {
                if (substitutionCapabilityEntry.getValue().getNodeTemplateName().equals(compositionCouple.nodeName)) {
                    String targetCapability = substitutionCapabilityEntry.getValue().getTargetId();
                    // just substitute the substitution target
                    substitutionCapabilityEntry.setValue(compositionCouple.child.getSubstitutionMapping().getCapabilities().get(targetCapability));
                }
            }
        }
        if (compositionCouple.parent.getSubstitutionMapping().getRequirements() != null) {
            for (Entry<String, SubstitutionTarget> e : compositionCouple.parent.getSubstitutionMapping().getRequirements().entrySet()) {
                if (e.getValue().getNodeTemplateName().equals(compositionCouple.nodeName)) {
                    String targetCapability = e.getValue().getTargetId();
                    // just substitute the substitution target
                    e.setValue(compositionCouple.child.getSubstitutionMapping().getRequirements().get(targetCapability));
                }
            }
        }
    }
    // merge each child nodes into the parent
    compositionCouple.parent.getNodeTemplates().putAll(compositionCouple.child.getNodeTemplates());
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 17 with FunctionPropertyValue

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

the class SecretPropertiesStepDefinitions method theTopologyShouldHaveThePropertyDefinedAsASecretWithASecretPath.

@And("^The topology should have the property \"([^\"]*)\" of a node \"([^\"]*)\" defined as a secret with a secret path \"([^\"]*)\"$")
public void theTopologyShouldHaveThePropertyDefinedAsASecretWithASecretPath(String propertyName, String nodeName, String secretPath) throws Throwable {
    String response = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId());
    JavaType restResponseType = Context.getJsonMapper().getTypeFactory().constructParametricType(RestResponse.class, TopologyDTO.class);
    TopologyDTO topologyDTO = ((RestResponse<TopologyDTO>) Context.getJsonMapper().readValue(response, restResponseType)).getData();
    FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) topologyDTO.getTopology().getNodeTemplates().get(nodeName).getProperties().get(propertyName);
    Assert.assertEquals(secretPath, functionPropertyValue.getParameters().get(0));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) TopologyDTO(alien4cloud.topology.TopologyDTO) RestResponse(alien4cloud.rest.model.RestResponse) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) And(cucumber.api.java.en.And)

Example 18 with FunctionPropertyValue

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

the class SecretPropertiesStepDefinitions method theTopologyShouldHaveThePropertyOfCapabilityOfANodeDefinedAsASecretWithASecretPath.

@And("^The topology should have the property \"([^\"]*)\" of capability \"([^\"]*)\" of a node \"([^\"]*)\" defined as a secret with a secret path \"([^\"]*)\"$")
public void theTopologyShouldHaveThePropertyOfCapabilityOfANodeDefinedAsASecretWithASecretPath(String propertyName, String capabilityName, String nodeName, String secretPath) throws Throwable {
    String response = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId());
    JavaType restResponseType = Context.getJsonMapper().getTypeFactory().constructParametricType(RestResponse.class, TopologyDTO.class);
    TopologyDTO topologyDTO = ((RestResponse<TopologyDTO>) Context.getJsonMapper().readValue(response, restResponseType)).getData();
    FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) topologyDTO.getTopology().getNodeTemplates().get(nodeName).getCapabilities().get(capabilityName).getProperties().get(propertyName);
    Assert.assertEquals(secretPath, functionPropertyValue.getParameters().get(0));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) TopologyDTO(alien4cloud.topology.TopologyDTO) RestResponse(alien4cloud.rest.model.RestResponse) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) And(cucumber.api.java.en.And)

Example 19 with FunctionPropertyValue

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

the class SecretPropertiesStepDefinitions method theTopologyShouldHaveThePropertyOfRelationshipFromTheNodeDefinedAsASecretWithASecretPath.

@And("^The topology should have the property \"([^\"]*)\" of relationship \"([^\"]*)\" from the node \"([^\"]*)\" defined as a secret with a secret path \"([^\"]*)\"$")
public void theTopologyShouldHaveThePropertyOfRelationshipFromTheNodeDefinedAsASecretWithASecretPath(String propertyName, String relationshipName, String nodeName, String secretPath) throws Throwable {
    String response = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId());
    JavaType restResponseType = Context.getJsonMapper().getTypeFactory().constructParametricType(RestResponse.class, TopologyDTO.class);
    TopologyDTO topologyDTO = ((RestResponse<TopologyDTO>) Context.getJsonMapper().readValue(response, restResponseType)).getData();
    FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) topologyDTO.getTopology().getNodeTemplates().get(nodeName).getRelationships().get(relationshipName).getProperties().get(propertyName);
    Assert.assertEquals(secretPath, functionPropertyValue.getParameters().get(0));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) TopologyDTO(alien4cloud.topology.TopologyDTO) RestResponse(alien4cloud.rest.model.RestResponse) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) And(cucumber.api.java.en.And)

Example 20 with FunctionPropertyValue

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

the class OrchestrationPolicyLocationResourceSteps method iSetThePropertyToASecretWithASecretPathForThePolicyResourceNamedRelatedToTheLocation.

@When("^I set the property \"([^\"]*)\" to a secret with a secret path \"([^\"]*)\" for the policy resource named \"([^\"]*)\" related to the location \"([^\"]*)\"/\"([^\"]*)\"$")
public void iSetThePropertyToASecretWithASecretPathForThePolicyResourceNamedRelatedToTheLocation(String propertyName, String secretPath, String resourceName, String orchestratorName, String locationName) throws Throwable {
    FunctionPropertyValue functionPropertyValue = new FunctionPropertyValue();
    functionPropertyValue.setFunction(ToscaFunctionConstants.GET_SECRET);
    functionPropertyValue.setParameters(Arrays.asList(secretPath));
    updatePropertyValue(orchestratorName, locationName, resourceName, propertyName, functionPropertyValue, getUpdatePropertyUrlFormat());
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) When(cucumber.api.java.en.When)

Aggregations

FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)37 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)12 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)7 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)6 And (cucumber.api.java.en.And)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)5 When (cucumber.api.java.en.When)4 RestResponse (alien4cloud.rest.model.RestResponse)3 TopologyDTO (alien4cloud.topology.TopologyDTO)3 JavaType (com.fasterxml.jackson.databind.JavaType)3 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)3 Capability (org.alien4cloud.tosca.model.templates.Capability)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 NotFoundException (alien4cloud.exception.NotFoundException)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)2