use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyStepDefinitions method The_RestResponse_should_contain_a_group_named_whose_members_are_and_policy_is.
@And("^The RestResponse should contain a group named \"([^\"]*)\" whose members are \"([^\"]*)\" and policy is \"([^\"]*)\"$")
public void The_RestResponse_should_contain_a_group_named_whose_members_are_and_policy_is(String groupName, String members, String policy) throws Throwable {
String topologyResponseText = Context.getInstance().getRestResponse();
RestResponse<TopologyDTO> topologyResponse = JsonUtil.read(topologyResponseText, TopologyDTO.class, Context.getJsonMapper());
Assert.assertNotNull(topologyResponse.getData().getTopology().getGroups());
NodeGroup nodeGroup = topologyResponse.getData().getTopology().getGroups().get(groupName);
Set<String> expectedMembers = Sets.newHashSet(members.split(","));
Assert.assertNotNull(nodeGroup);
Assert.assertEquals(nodeGroup.getMembers(), expectedMembers);
Assert.assertEquals(nodeGroup.getPolicies().iterator().next().getType(), policy);
for (String expectedMember : expectedMembers) {
NodeTemplate nodeTemplate = topologyResponse.getData().getTopology().getNodeTemplates().get(expectedMember);
Assert.assertNotNull(nodeTemplate);
Assert.assertTrue(nodeTemplate.getGroups().contains(groupName));
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyStepDefinitions method I_should_have_a_relationship_with_type_from_to_in_ALIEN.
@Then("^I should have a relationship \"([^\"]*)\" with type \"([^\"]*)\" from \"([^\"]*)\" to \"([^\"]*)\" in ALIEN$")
public void I_should_have_a_relationship_with_type_from_to_in_ALIEN(String relName, String relType, String source, String target) throws Throwable {
// I should have a relationship with type
String topologyJson = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId());
RestResponse<TopologyDTO> topologyResponse = JsonUtil.read(topologyJson, TopologyDTO.class, Context.getJsonMapper());
NodeTemplate sourceNode = topologyResponse.getData().getTopology().getNodeTemplates().get(source);
relName = relName == null || relName.isEmpty() ? getRelationShipName(relType, target) : relName;
RelationshipTemplate rel = sourceNode.getRelationships().get(relName);
assertNotNull(rel);
assertEquals(relType, rel.getType());
assertEquals(target, rel.getTarget());
assertNotNull(rel.getRequirementName());
assertNotNull(rel.getRequirementType());
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyRecoveryStepDefinitions method I_node_in_the_topology_dto_should_not_have_the_capability.
@Then("^the node \"([^\"]*)\" in the topology dto should not have the capability \"([^\"]*)\"$")
public void I_node_in_the_topology_dto_should_not_have_the_capability(String nodeName, String capabilityName) throws IOException {
TopologyDTO dto = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData();
NodeTemplate template = dto.getTopology().getNodeTemplates().get(nodeName);
Assert.assertNotNull(template);
assertFalse(template.getCapabilities().containsKey(capabilityName));
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class ManagedServiceResourceEventService method updateRunningService.
private void updateRunningService(DeploymentTopology topology, Deployment deployment, ServiceResource serviceResource, String serviceState, Map<String, Map<String, InstanceInformation>> instanceInformation) {
// update the state
serviceResource.setState(serviceState);
// update deploymentId, in case it is not yet (when creating the service from an already started deployment)
serviceResource.setDeploymentId(deployment.getId());
// ensure the service is available on all of the deployment locations
updateLocations(serviceResource, deployment.getLocationIds());
// Map input properties from the topology as properties of the service instance
if (serviceResource.getNodeInstance().getNodeTemplate().getProperties() == null) {
serviceResource.getNodeInstance().getNodeTemplate().setProperties(Maps.newHashMap());
}
serviceResource.getNodeInstance().getNodeTemplate().getProperties().putAll(safe(topology.getAllInputProperties()));
// Map attributes from the instances to the actual service resource node.
for (Entry<String, Set<String>> nodeOutputAttrEntry : safe(topology.getOutputAttributes()).entrySet()) {
Map<String, InstanceInformation> instances = instanceInformation.get(nodeOutputAttrEntry.getKey());
if (instances == null) {
log.error("Failed to map attributes from node [ {} ] for service <id: {}, name: {}>. The node cannot be found in deployed topology [ {} ].", nodeOutputAttrEntry.getKey(), serviceResource.getId(), serviceResource.getName(), topology.getId());
} else if (instances.size() > 1) {
log.error("Services substitution does not yet supports the exposure of multiple instances");
} else {
InstanceInformation instance = instances.values().iterator().next();
// let's map attribute
for (String mappedAttribute : nodeOutputAttrEntry.getValue()) {
serviceResource.getNodeInstance().setAttribute(mappedAttribute, instance.getAttributes().get(mappedAttribute));
}
}
}
// Map output properties as attributes of the service instance
for (Entry<String, Set<String>> nodeOutputPropEntry : safe(topology.getOutputProperties()).entrySet()) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeOutputPropEntry.getKey());
for (String prop : nodeOutputPropEntry.getValue()) {
serviceResource.getNodeInstance().setAttribute(prop, PropertyUtil.serializePropertyValue(nodeTemplate.getProperties().get(prop)));
}
}
// Map capabilities output properties as attributes of the service instance (that are exposed as node properties)
for (Entry<String, Map<String, Set<String>>> nodeOutputCapaPropEntry : safe(topology.getOutputCapabilityProperties()).entrySet()) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeOutputCapaPropEntry.getKey());
for (Entry<String, Set<String>> outputCapaPropEntry : nodeOutputCapaPropEntry.getValue().entrySet()) {
Capability capability = nodeTemplate.getCapabilities().get(outputCapaPropEntry.getKey());
for (String prop : outputCapaPropEntry.getValue()) {
serviceResource.getNodeInstance().setAttribute(prop, PropertyUtil.serializePropertyValue(capability.getProperties().get(prop)));
}
}
}
serviceResource.getNodeInstance().getNodeTemplate().setCapabilities(Maps.newLinkedHashMap());
// Map capabilities exposed as is for the service node.
for (Entry<String, SubstitutionTarget> capabilityMapping : safe(topology.getSubstitutionMapping().getCapabilities()).entrySet()) {
Capability deployedCapability = topology.getNodeTemplates().get(capabilityMapping.getValue().getNodeTemplateName()).getCapabilities().get(capabilityMapping.getValue().getTargetId());
serviceResource.getNodeInstance().getNodeTemplate().getCapabilities().put(capabilityMapping.getKey(), deployedCapability);
// TODO improve while capabilities attributes will be really supported
// Workaround to support capabilities attributes is to use node attributes with keys in format capabilities.capaName.attributeName
mapCapabilityRequirementAttributes(serviceResource, instanceInformation, capabilityMapping.getValue().getNodeTemplateName(), "capabilities", capabilityMapping.getValue().getTargetId());
}
serviceResource.getNodeInstance().getNodeTemplate().setRequirements(Maps.newLinkedHashMap());
// Map requirements exposed as is for the service node.
for (Entry<String, SubstitutionTarget> requirementMapping : safe(topology.getSubstitutionMapping().getRequirements()).entrySet()) {
serviceResource.getNodeInstance().getNodeTemplate().getRequirements().put(requirementMapping.getKey(), topology.getNodeTemplates().get(requirementMapping.getValue().getNodeTemplateName()).getRequirements().get(requirementMapping.getValue().getTargetId()));
// TODO improve while requirements attributes will be really supported
// Workaround to support requirements attributes is to use node attributes with keys in format capabilities.capaName.attributeName
mapCapabilityRequirementAttributes(serviceResource, instanceInformation, requirementMapping.getValue().getNodeTemplateName(), "requirements", requirementMapping.getValue().getTargetId());
}
serviceResourceService.save(serviceResource);
// trigger a ManagedServiceUpdateEvent
publisher.publishEvent(new ManagedServiceUpdatedEvent(this, serviceResource, topology));
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class NodeInstanceService method create.
/**
* Create a new instance of a given node type based on default generated template.
*
* @param nodeType The node type out of which to create the version.
* @param typeVersion The node instance type's version.
* @return An instance that matches the given type created from a default template (default values). Note that the node instance may be constructed from an
* invalid template (missing required properties) without errors. State of the node is set to initial.
*/
@ToscaContextual
public NodeInstance create(NodeType nodeType, String typeVersion) {
NodeTemplate nodeTemplate = TemplateBuilder.buildNodeTemplate(nodeType, null);
NodeInstance instance = new NodeInstance();
instance.setAttribute(ToscaNodeLifecycleConstants.ATT_STATE, ToscaNodeLifecycleConstants.INITIAL);
instance.setNodeTemplate(nodeTemplate);
instance.setTypeVersion(typeVersion);
return instance;
}
Aggregations