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