private int getPlannedInstancesCount(String nodeTemplateId, Topology topology) { Capability scalableCapability = TopologyUtils.getScalableCapability(topology, nodeTemplateId, false); if (scalableCapability != null) { ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability); return scalingPolicy.getInitialInstances(); } return 1; }
private ScalingPolicy getScalingPolicy(String nodeTemplateId, Map<String, NodeTemplate> nodeTemplates, Topology topology) { // Get the scaling of parent if not exist Capability scalableCapability = TopologyUtils.getScalableCapability(topology, nodeTemplateId, false); if (scalableCapability == null) { if (nodeTemplates.get(nodeTemplateId).getRelationships() != null) { for (RelationshipTemplate rel : nodeTemplates.get(nodeTemplateId).getRelationships().values()) { RelationshipType relType = getRelationshipType(rel.getType()); if (ToscaTypeUtils.isOfType(relType, NormativeRelationshipConstants.HOSTED_ON)) { return getScalingPolicy(rel.getTarget(), nodeTemplates, topology); } } } else { return null; } } else { return TopologyUtils.getScalingPolicy(scalableCapability); } return null; }
ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability);
public static int getDefaultInstanceCount(Topology topology, NodeTemplate template, int multiplicator) { Capability scalableCapability = TopologyUtils.getScalableCapability(topology, template.getName(), false); int defaultInstanceCount = 1; if (scalableCapability != null) { ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability); if (!ScalingPolicy.NOT_SCALABLE_POLICY.equals(scalingPolicy)) { defaultInstanceCount = scalingPolicy.getInitialInstances(); } } // now look for the host NodeTemplate host = getImmediateHostTemplate(topology, template); if (host != null) { return getDefaultInstanceCount(topology, host, multiplicator * defaultInstanceCount); } else { return multiplicator * defaultInstanceCount; } }
@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); }
@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()); }