@Test public void testSingleInstanceFitsAll() { List<AgentInstanceGroup> instanceGroups = asList( getInstanceGroup(Tier.Critical, M4_XLARGE_ID, 0, 2), getInstanceGroup(Tier.Critical, M4_4XLARGE_ID, 0, 0), getInstanceGroup(Tier.Flex, R4_8XLARGE_ID, 0, 0), getInstanceGroup(Tier.Flex, P2_8XLARGE_ID, 0, 0) ); when(agentManagementService.getInstanceGroups()).thenReturn(instanceGroups); ApplicationSLA smallSLA = ApplicationSlaSample.CriticalSmall.builder().withInstanceCount(1).build(); CapacityRequirements requirements = new CapacityRequirements(singletonMap(Tier.Critical, singletonList(smallSLA))); CapacityAllocations allocations = strategy.compute(requirements); allocations.getInstanceGroups().forEach(instanceGroup -> { assertThat(instanceGroup.getTier()).isEqualTo(Tier.Critical); }); AgentInstanceGroup m4xlInstanceGroup = findInstanceGroupByInstanceType(allocations.getInstanceGroups(), M4_XLARGE_ID); assertThat(allocations.getExpectedMinSize(m4xlInstanceGroup)).isEqualTo(1); AgentInstanceGroup m44xlInstanceGroup = findInstanceGroupByInstanceType(allocations.getInstanceGroups(), M4_4XLARGE_ID); assertThat(allocations.getExpectedMinSize(m44xlInstanceGroup)).isEqualTo(0); }
@Override public CapacityAllocations compute(CapacityRequirements capacityRequirements) { Map<AgentInstanceGroup, Integer> instanceAllocations = new HashMap<>(); Map<Tier, ResourceDimension> resourceShortage = new HashMap<>(); for (Tier tier : capacityRequirements.getTiers()) { boolean hasEnoughApps = (tier == Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 1) || (tier != Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 0); if (hasEnoughApps) { Optional<ResourceDimension> left = allocate(tier, capacityRequirements, instanceAllocations); left.ifPresent(resourceDimension -> resourceShortage.put(tier, resourceDimension)); } } return new CapacityAllocations(instanceAllocations, resourceShortage); }
SimpleCapacityGuaranteeStrategy implements CapacityGuaranteeStrategy { @Override public CapacityAllocations compute(CapacityRequirements capacityRequirements) { Map<AgentInstanceGroup, Integer> instanceAllocations = new HashMap<>(); Map<Tier, ResourceDimension> resourceShortage = new HashMap<>(); for (Tier tier : capacityRequirements.getTiers()) { boolean hasEnoughApps = (tier == Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 1) || (tier != Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 0); if (hasEnoughApps) { Optional<ResourceDimension> left = allocate(tier, capacityRequirements, instanceAllocations); left.ifPresent(resourceDimension -> resourceShortage.put(tier, resourceDimension)); } } return new CapacityAllocations(instanceAllocations, resourceShortage); } }
SimpleCapacityGuaranteeStrategy implements CapacityGuaranteeStrategy { @Override public CapacityAllocations compute(CapacityRequirements capacityRequirements) { Map<AgentInstanceGroup, Integer> instanceAllocations = new HashMap<>(); Map<Tier, ResourceDimension> resourceShortage = new HashMap<>(); for (Tier tier : capacityRequirements.getTiers()) { boolean hasEnoughApps = (tier == Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 1) || (tier != Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 0); if (hasEnoughApps) { Optional<ResourceDimension> left = allocate(tier, capacityRequirements, instanceAllocations); left.ifPresent(resourceDimension -> resourceShortage.put(tier, resourceDimension)); } } return new CapacityAllocations(instanceAllocations, resourceShortage); } @Inject  SimpleCapacityGuaranteeStrategy(CapacityManagementConfiguration configuration,
                                           AgentManagementService agentManagementService,
                                           ServerInfoResolver serverInfoResolver); }
SimpleCapacityGuaranteeStrategy implements CapacityGuaranteeStrategy { @Override public CapacityAllocations compute(CapacityRequirements capacityRequirements) { Map<AgentInstanceGroup, Integer> instanceAllocations = new HashMap<>(); Map<Tier, ResourceDimension> resourceShortage = new HashMap<>(); for (Tier tier : capacityRequirements.getTiers()) { boolean hasEnoughApps = (tier == Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 1) || (tier != Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 0); if (hasEnoughApps) { Optional<ResourceDimension> left = allocate(tier, capacityRequirements, instanceAllocations); left.ifPresent(resourceDimension -> resourceShortage.put(tier, resourceDimension)); } } return new CapacityAllocations(instanceAllocations, resourceShortage); } @Inject  SimpleCapacityGuaranteeStrategy(CapacityManagementConfiguration configuration,
                                           AgentManagementService agentManagementService,
                                           ServerInfoResolver serverInfoResolver); @Override CapacityAllocations compute(CapacityRequirements capacityRequirements); }
SimpleCapacityGuaranteeStrategy implements CapacityGuaranteeStrategy { @Override public CapacityAllocations compute(CapacityRequirements capacityRequirements) { Map<AgentInstanceGroup, Integer> instanceAllocations = new HashMap<>(); Map<Tier, ResourceDimension> resourceShortage = new HashMap<>(); for (Tier tier : capacityRequirements.getTiers()) { boolean hasEnoughApps = (tier == Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 1) || (tier != Tier.Flex && capacityRequirements.getTierRequirements(tier).size() > 0); if (hasEnoughApps) { Optional<ResourceDimension> left = allocate(tier, capacityRequirements, instanceAllocations); left.ifPresent(resourceDimension -> resourceShortage.put(tier, resourceDimension)); } } return new CapacityAllocations(instanceAllocations, resourceShortage); } @Inject  SimpleCapacityGuaranteeStrategy(CapacityManagementConfiguration configuration,
                                           AgentManagementService agentManagementService,
                                           ServerInfoResolver serverInfoResolver); @Override CapacityAllocations compute(CapacityRequirements capacityRequirements);  }