Search in sources :

Example 1 with NodeGroup

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);
    }
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 2 with NodeGroup

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;
}
Also used : ScalingPolicy(org.alien4cloud.tosca.model.templates.ScalingPolicy) Capability(org.alien4cloud.tosca.model.templates.Capability) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) Map(java.util.Map) HashMap(java.util.HashMap) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 3 with NodeGroup

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);
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Node(org.yaml.snakeyaml.nodes.Node) Map(java.util.Map) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 4 with NodeGroup

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);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) AlreadyExistException(alien4cloud.exception.AlreadyExistException) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 5 with NodeGroup

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));
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup) And(cucumber.api.java.en.And)

Aggregations

NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)6 Map (java.util.Map)3 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 Location (alien4cloud.model.orchestrators.locations.Location)2 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)2 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 NodeMatcherService (alien4cloud.deployment.matching.services.nodes.NodeMatcherService)1 InvalidNameException (alien4cloud.exception.InvalidNameException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)1 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)1 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)1 PaaSTopology (alien4cloud.paas.model.PaaSTopology)1 TopologyDTO (alien4cloud.topology.TopologyDTO)1 LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1