Search in sources :

Example 1 with ScalingPolicy

use of org.alien4cloud.tosca.model.templates.ScalingPolicy 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 2 with ScalingPolicy

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

the class TopologyStepDefinitions method There_s_no_defined_scaling_policy.

@Then("^There's no defined scaling policy for the node \"([^\"]*)\"$")
public void There_s_no_defined_scaling_policy(String nodeName) throws Throwable {
    I_try_to_retrieve_the_created_topology();
    String topologyResponseText = Context.getInstance().getRestResponse();
    RestResponse<TopologyDTO> topologyResponse = JsonUtil.read(topologyResponseText, TopologyDTO.class, Context.getJsonMapper());
    assertNotNull(topologyResponse.getData());
    ScalingPolicy computePolicy = TopologyUtils.getScalingPolicy(TopologyUtils.getScalableCapability(topologyResponse.getData().getTopology(), nodeName, true));
    assertEquals(ScalingPolicy.NOT_SCALABLE_POLICY, computePolicy);
}
Also used : ScalingPolicy(org.alien4cloud.tosca.model.templates.ScalingPolicy) TopologyDTO(alien4cloud.topology.TopologyDTO) Then(cucumber.api.java.en.Then)

Example 3 with ScalingPolicy

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

the class TopologyStepDefinitions method the_scaling_policy_of_the_node_should_match_max_instances_equals_to_initial_instances_equals_to_and_min_instances_equals_to.

@Then("^the scaling policy of the node \"([^\"]*)\" should match max instances equals to (\\d+), initial instances equals to (\\d+) and min instances equals to (\\d+)$")
public void the_scaling_policy_of_the_node_should_match_max_instances_equals_to_initial_instances_equals_to_and_min_instances_equals_to(String nodeName, int maxInstances, int initialInstances, int minInstances) throws Throwable {
    I_try_to_retrieve_the_created_topology();
    String topologyResponseText = Context.getInstance().getRestResponse();
    RestResponse<TopologyDTO> topologyResponse = JsonUtil.read(topologyResponseText, TopologyDTO.class, Context.getJsonMapper());
    assertNotNull(topologyResponse.getData());
    ScalingPolicy computePolicy = TopologyUtils.getScalingPolicy(TopologyUtils.getScalableCapability(topologyResponse.getData().getTopology(), nodeName, true));
    assertNotNull(computePolicy);
    assertEquals(maxInstances, computePolicy.getMaxInstances());
    assertEquals(minInstances, computePolicy.getMinInstances());
    assertEquals(initialInstances, computePolicy.getInitialInstances());
}
Also used : ScalingPolicy(org.alien4cloud.tosca.model.templates.ScalingPolicy) TopologyDTO(alien4cloud.topology.TopologyDTO) Then(cucumber.api.java.en.Then)

Example 4 with ScalingPolicy

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

the class MockPaaSProvider method doDeploy.

@Override
protected synchronized void doDeploy(final PaaSTopologyDeploymentContext deploymentContext) {
    log.info("Deploying deployment [" + deploymentContext.getDeploymentPaaSId() + "]");
    paaSDeploymentIdToAlienDeploymentIdMap.put(deploymentContext.getDeploymentPaaSId(), deploymentContext.getDeploymentId());
    Topology topology = deploymentContext.getDeploymentTopology();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    if (nodeTemplates == null) {
        nodeTemplates = Maps.newHashMap();
    }
    Map<String, Map<String, InstanceInformation>> currentInformations = Maps.newHashMap();
    for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
        Map<String, InstanceInformation> instanceInformations = Maps.newHashMap();
        currentInformations.put(nodeTemplateEntry.getKey(), instanceInformations);
        ScalingPolicy policy = getScalingPolicy(nodeTemplateEntry.getKey(), nodeTemplates, topology);
        int initialInstances = policy != null ? policy.getInitialInstances() : 1;
        for (int i = 1; i <= initialInstances; i++) {
            InstanceInformation newInstanceInformation = newInstance(i);
            instanceInformations.put(String.valueOf(i), newInstanceInformation);
            notifyInstanceStateChanged(deploymentContext.getDeploymentPaaSId(), nodeTemplateEntry.getKey(), String.valueOf(i), newInstanceInformation, 1);
        }
    }
    runtimeDeploymentInfos.put(deploymentContext.getDeploymentPaaSId(), new MockRuntimeDeploymentInfo(deploymentContext, DeploymentStatus.DEPLOYMENT_IN_PROGRESS, currentInformations));
    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYMENT_IN_PROGRESS);
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            switch(deploymentContext.getDeployment().getSourceName()) {
                case BAD_APPLICATION_THAT_NEVER_WORKS:
                    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.FAILURE);
                    break;
                case WARN_APPLICATION_THAT_NEVER_WORKS:
                    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.WARNING);
                    break;
                default:
                    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYED);
            }
        }
    }, 5, TimeUnit.SECONDS);
}
Also used : ScalingPolicy(org.alien4cloud.tosca.model.templates.ScalingPolicy) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Map(java.util.Map)

Aggregations

ScalingPolicy (org.alien4cloud.tosca.model.templates.ScalingPolicy)4 TopologyDTO (alien4cloud.topology.TopologyDTO)2 Then (cucumber.api.java.en.Then)2 Map (java.util.Map)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 InstanceInformation (alien4cloud.paas.model.InstanceInformation)1 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)1 HashMap (java.util.HashMap)1 Capability (org.alien4cloud.tosca.model.templates.Capability)1 NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1