Search in sources :

Example 56 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class AddRelationshipProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, AddRelationshipOperation operation, NodeTemplate sourceNode) {
    if (operation.getRelationshipName() == null || operation.getRelationshipName().isEmpty()) {
        throw new InvalidNameException("relationshipName", operation.getRelationshipName(), "Not null or empty");
    }
    if (AlienUtils.safe(sourceNode.getRelationships()).containsKey(operation.getRelationshipName())) {
        throw new AlreadyExistException("Relationship " + operation.getRelationshipName() + " already exist on node " + operation.getNodeName());
    }
    if (sourceNode.getRequirements() == null || sourceNode.getRequirements().get(operation.getRequirementName()) == null) {
        throw new NotFoundException("Unable to find requirement with name <" + operation.getRequirementName() + "> on the source node" + operation.getNodeName());
    }
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    // ensure that the target node exists
    TopologyUtils.getNodeTemplate(topology.getId(), operation.getTarget(), nodeTemplates);
    // We don't use the tosca context as the relationship type may not be in dependencies yet (that's why we use the load type below).
    RelationshipType indexedRelationshipType = toscaTypeSearchService.find(RelationshipType.class, operation.getRelationshipType(), operation.getRelationshipVersion());
    if (indexedRelationshipType == null) {
        throw new NotFoundException(RelationshipType.class.getName(), operation.getRelationshipType() + ":" + operation.getRelationshipVersion(), "Unable to find relationship type to create template in topology.");
    }
    boolean upperBoundReachedSource = topologyRequirementBoundsValidationServices.isRequirementUpperBoundReachedForSource(sourceNode, operation.getRequirementName(), topology.getDependencies());
    if (upperBoundReachedSource) {
        // throw exception here
        throw new RequirementBoundException(operation.getNodeName(), operation.getRequirementName());
    }
    boolean upperBoundReachedTarget = topologyCapabilityBoundsValidationServices.isCapabilityUpperBoundReachedForTarget(operation.getTarget(), nodeTemplates, operation.getTargetedCapabilityName(), topology.getDependencies());
    // return with a rest response error
    if (upperBoundReachedTarget) {
        throw new CapabilityBoundException(operation.getTarget(), operation.getTargetedCapabilityName());
    }
    topologyService.loadType(topology, indexedRelationshipType);
    NodeTemplate newSourceNode = topology.getNodeTemplates().get(sourceNode.getName());
    if (sourceNode != newSourceNode) {
        // topology has been reloaded
        sourceNode = newSourceNode;
    }
    Map<String, RelationshipTemplate> relationships = sourceNode.getRelationships();
    if (relationships == null) {
        relationships = Maps.newHashMap();
        sourceNode.setRelationships(relationships);
    }
    RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
    relationshipTemplate.setName(operation.getRelationshipName());
    relationshipTemplate.setTarget(operation.getTarget());
    relationshipTemplate.setTargetedCapabilityName(operation.getTargetedCapabilityName());
    relationshipTemplate.setRequirementName(operation.getRequirementName());
    relationshipTemplate.setRequirementType(sourceNode.getRequirements().get(operation.getRequirementName()).getType());
    relationshipTemplate.setType(indexedRelationshipType.getElementId());
    relationshipTemplate.setArtifacts(newLinkedHashMap(indexedRelationshipType.getArtifacts()));
    relationshipTemplate.setAttributes(newLinkedHashMap(indexedRelationshipType.getAttributes()));
    Map<String, AbstractPropertyValue> properties = new LinkedHashMap<String, AbstractPropertyValue>();
    TemplateBuilder.fillProperties(properties, indexedRelationshipType.getProperties(), null);
    relationshipTemplate.setProperties(properties);
    relationships.put(operation.getRelationshipName(), relationshipTemplate);
    TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
    workflowBuilderService.addRelationship(topologyContext, operation.getNodeName(), operation.getRelationshipName());
    log.debug("Added relationship to the topology [" + topology.getId() + "], node name [" + operation.getNodeName() + "], relationship name [" + operation.getRelationshipName() + "]");
}
Also used : CapabilityBoundException(org.alien4cloud.tosca.editor.exception.CapabilityBoundException) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) NotFoundException(alien4cloud.exception.NotFoundException) LinkedHashMap(java.util.LinkedHashMap) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) RequirementBoundException(org.alien4cloud.tosca.editor.exception.RequirementBoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) TopologyContext(alien4cloud.paas.wf.TopologyContext) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 57 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class ApplicationStepDefinitions method The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template.

@Then("^The created application topology is the same as the one in the base topology template$")
public void The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template() throws Throwable {
    // created topology
    String topologyId = Csar.createId(CURRENT_APPLICATION.getId(), VersionUtil.DEFAULT_VERSION_NAME);
    Context.getInstance().registerRestResponse(getRestClientInstance().get("/rest/v1/topologies/" + topologyId));
    TopologyDTO createdTopology = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData();
    // base topology template
    // quick win solution
    authSteps.I_am_authenticated_with_role("ARCHITECT");
    String topoResponse = Context.getRestClientInstance().get("/rest/v1/catalog/topologies/" + TopologyTemplateStepDefinitions.CURRENT_TOPOLOGY_TEMP_ID);
    Topology topologyTemplateBase = JsonUtil.read(topoResponse, Topology.class, Context.getJsonMapper()).getData();
    Map<String, NodeTemplate> nodeTemplates = topologyTemplateBase.getNodeTemplates();
    // node templates count test
    assertEquals(createdTopology.getTopology().getNodeTemplates().size(), nodeTemplates.size());
    // node templates name / type test
    for (Map.Entry<String, NodeTemplate> entry : createdTopology.getTopology().getNodeTemplates().entrySet()) {
        assertTrue(nodeTemplates.containsKey(entry.getKey()));
        assertTrue(nodeTemplates.get(entry.getKey()).getType().equals(entry.getValue().getType()));
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map) Then(cucumber.api.java.en.Then)

Example 58 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method The_following_nodes_properties_values_should_be.

@Then("^the following nodes properties values sould be \"(.*?)\"$")
public void The_following_nodes_properties_values_should_be(String expectedValue, Map<String, String> nodesProperties) throws Throwable {
    DeploymentTopologyDTO dto = getDTOAndassertNotNull();
    for (Entry<String, String> entry : nodesProperties.entrySet()) {
        NodeTemplate template = MapUtils.getObject(dto.getTopology().getNodeTemplates(), entry.getKey());
        assertNodePropertyValueEquals(template, entry.getValue(), expectedValue);
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) Then(cucumber.api.java.en.Then)

Example 59 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method the_the_node_in_the_deployment_topology_should_have_the_capability_s_property_with_value.

@Then("^The the node \"(.*?)\" in the deployment topology should have the capability \"(.*?)\"'s property \"(.*?)\" with value \"(.*?)\"$")
public void the_the_node_in_the_deployment_topology_should_have_the_capability_s_property_with_value(String nodeName, String capabilityName, String propertyName, String expectedPropertyValue) throws Throwable {
    DeploymentTopologyDTO dto = getDeploymentTopologyDTO();
    NodeTemplate node = dto.getTopology().getNodeTemplates().get(nodeName);
    assertCapabilityPropertyValueEquals(node, capabilityName, propertyName, expectedPropertyValue);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) Then(cucumber.api.java.en.Then)

Example 60 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method theNodeInTheDeploymentTopologyShouldHaveThePropertyWithASecretFunctionHavingASecretPath.

@Then("^The node \"([^\"]*)\" in the deployment topology should have the property \"([^\"]*)\" with a secret function having a secret path \"([^\"]*)\"$")
public void theNodeInTheDeploymentTopologyShouldHaveThePropertyWithASecretFunctionHavingASecretPath(String nodeName, String propertyName, String secretPath) throws Throwable {
    DeploymentTopologyDTO dto = getDeploymentTopologyDTO();
    NodeTemplate node = dto.getTopology().getNodeTemplates().get(nodeName);
    FunctionPropertyValue actualPropertyValue = (FunctionPropertyValue) node.getProperties().get(propertyName);
    FunctionPropertyValue expectedPropertyValue = new FunctionPropertyValue();
    expectedPropertyValue.setFunction(ToscaFunctionConstants.GET_SECRET);
    expectedPropertyValue.setParameters(Arrays.asList(secretPath));
    Assert.assertEquals(actualPropertyValue, expectedPropertyValue);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) Then(cucumber.api.java.en.Then)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10