use of org.alien4cloud.tosca.model.templates.NodeGroup in project yorc-a4c-plugin by ystia.
the class ShowTopology method topologyInLog.
/**
* Log topology infos for debugging
* @param ctx
*/
public static void topologyInLog(PaaSTopologyDeploymentContext ctx) {
String paasId = ctx.getDeploymentPaaSId();
PaaSTopology ptopo = ctx.getPaaSTopology();
DeploymentTopology dtopo = ctx.getDeploymentTopology();
// Deployment Workflows
Map<String, Workflow> workflows = dtopo.getWorkflows();
for (String wfname : workflows.keySet()) {
log.debug("***** Workflow " + wfname);
Workflow wf = workflows.get(wfname);
log.debug("name: " + wf.getName());
log.debug("host: " + wf.getHosts().toString());
log.debug("steps: " + wf.getSteps().keySet().toString());
}
// Deployment Groups
Map<String, NodeGroup> groups = dtopo.getGroups();
if (groups != null) {
for (String grname : groups.keySet()) {
NodeGroup group = groups.get(grname);
log.debug("***** Group " + grname);
log.debug("name: " + group.getName());
log.debug("members: " + group.getMembers().toString());
}
}
// PaaS Compute Nodes
for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
printNode(node);
}
}
use of org.alien4cloud.tosca.model.templates.NodeGroup in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method buildPaaSNodeTemplates.
/**
* Fetch information from the repository to complete the topology node template informations with additional data such as artifacts paths etc.
*
* @param topology The topology for which to build PaaSNodeTemplate map.
* @return A map of PaaSNodeTemplate that match the one of the NodeTempaltes in the given topology (and filled with artifact paths etc.).
*/
public Map<String, PaaSNodeTemplate> buildPaaSNodeTemplates(Topology topology) {
Map<String, PaaSNodeTemplate> nodeTemplates = Maps.newHashMap();
// Fill in PaaSNodeTemplate by fetching node types and CSAR path from the repositories.
if (topology.getNodeTemplates() != null) {
for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
PaaSNodeTemplate paaSNodeTemplate = new PaaSNodeTemplate(templateEntry.getKey(), template);
fillType(topology, template, paaSNodeTemplate, NodeType.class);
mergeInterfaces(paaSNodeTemplate, template);
if (template.getRelationships() != null) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : template.getRelationships().entrySet()) {
RelationshipTemplate relationshipTemplate = relationshipEntry.getValue();
PaaSRelationshipTemplate paaSRelationshipTemplate = new PaaSRelationshipTemplate(relationshipEntry.getKey(), relationshipTemplate, paaSNodeTemplate.getId());
fillType(topology, relationshipTemplate, paaSRelationshipTemplate, RelationshipType.class);
mergeInterfaces(paaSRelationshipTemplate, relationshipTemplate);
paaSNodeTemplate.getRelationshipTemplates().add(paaSRelationshipTemplate);
}
}
Capability scalableCapability = TopologyUtils.getScalableCapability(topology, templateEntry.getKey(), false);
if (scalableCapability != null) {
ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability);
// A node with a scaling policy 1, 1, 1 is a simple node and so do not set scaling policy
if (!ScalingPolicy.NOT_SCALABLE_POLICY.equals(scalingPolicy)) {
paaSNodeTemplate.setScalingPolicy(scalingPolicy);
}
}
if (topology.getGroups() != null) {
Set<String> nodeGroups = Sets.newHashSet();
for (Map.Entry<String, NodeGroup> groupEntry : topology.getGroups().entrySet()) {
if (groupEntry.getValue().getMembers() != null && groupEntry.getValue().getMembers().contains(templateEntry.getKey())) {
nodeGroups.add(groupEntry.getKey());
}
}
paaSNodeTemplate.setGroups(nodeGroups);
}
nodeTemplates.put(templateEntry.getKey(), paaSNodeTemplate);
}
}
return nodeTemplates;
}
use of org.alien4cloud.tosca.model.templates.NodeGroup in project alien4cloud by alien4cloud.
the class TopologyPostProcessor method process.
@Override
public void process(Topology instance) {
if (instance == null) {
return;
}
ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
// The yaml node for the topology
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
setDependencies(instance, archiveRoot);
if (instance.isEmpty()) {
// if the topology doesn't contains any node template it won't be imported so add a warning.
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.EMPTY_TOPOLOGY, null, node.getStartMark(), null, node.getEndMark(), ""));
}
// archive name and version
instance.setArchiveName(archiveRoot.getArchive().getName());
instance.setArchiveVersion(archiveRoot.getArchive().getVersion());
// Inputs validation
safe(instance.getInputs()).entrySet().forEach(propertyDefinitionPostProcessor);
safe(instance.getInputArtifacts()).values().forEach(typeDeploymentArtifactPostProcessor);
int groupIndex = 0;
// Groups validation
for (NodeGroup nodeGroup : safe(instance.getGroups()).values()) {
nodeGroup.setIndex(groupIndex++);
groupPostProcessor.process(nodeGroup);
}
// Policies templates validation
safe(instance.getPolicies()).forEach((policyName, policyTemplate) -> {
// set the templateName
policyTemplate.setName(policyName);
policyTemplatePostProcessor.process(policyTemplate);
});
// Node templates validation
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : safe(instance.getNodeTemplates()).entrySet()) {
nodeTemplateEntry.getValue().setName(nodeTemplateEntry.getKey());
nodeTemplatePostProcessor.process(nodeTemplateEntry.getValue());
}
safe(instance.getNodeTemplates()).values().forEach(nodeTemplateRelationshipPostProcessor);
substitutionMappingPostProcessor.process(instance.getSubstitutionMapping());
// first validate names
TopologyUtils.normalizeAllNodeTemplateName(instance, ParsingContextExecution.getParsingErrors(), ParsingContextExecution.getObjectToNodeMap());
// Post process workflows
workflowPostProcessor.processWorkflows(instance, node);
}
use of org.alien4cloud.tosca.model.templates.NodeGroup in project alien4cloud by alien4cloud.
the class TopologyCompositionService method renameNodeTemplate.
private void renameNodeTemplate(Topology topology, String oldName, String newName) {
// quite improbable but ...
if (topology.getNodeTemplates().containsKey(newName)) {
throw new AlreadyExistException(String.format("A node with name '%s' already exists in this topology", newName));
}
NodeTemplate nodeTemplate = topology.getNodeTemplates().remove(oldName);
// manage relationships that target this node
for (NodeTemplate otherNodes : topology.getNodeTemplates().values()) {
if (otherNodes.getRelationships() == null || otherNodes.getRelationships().isEmpty()) {
continue;
}
for (RelationshipTemplate relationshipTemplate : otherNodes.getRelationships().values()) {
if (relationshipTemplate.getTarget().equals(oldName)) {
relationshipTemplate.setTarget(newName);
}
}
}
// all output stuffs
MapUtil.replaceKey(topology.getOutputProperties(), oldName, newName);
MapUtil.replaceKey(topology.getOutputCapabilityProperties(), oldName, newName);
MapUtil.replaceKey(topology.getOutputAttributes(), oldName, newName);
// group members must be updated
if (topology.getGroups() != null) {
for (NodeGroup nodeGroup : topology.getGroups().values()) {
Set<String> members = nodeGroup.getMembers();
if (members != null && members.remove(oldName)) {
members.add(newName);
}
}
}
// substitutions
if (topology.getSubstitutionMapping() != null) {
renameNodeTemplateInSubstitutionTargets(topology.getSubstitutionMapping().getCapabilities(), oldName, newName);
renameNodeTemplateInSubstitutionTargets(topology.getSubstitutionMapping().getRequirements(), oldName, newName);
}
// finally the node itself
topology.getNodeTemplates().put(newName, nodeTemplate);
}
use of org.alien4cloud.tosca.model.templates.NodeGroup 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));
}
}
Aggregations