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