@Test public void testGetUnusedInstanceIdsButWithPositiveScalingAdjustment() { Stack stack = mock(Stack.class); Map<String, String> unusedInstanceIds = stackScalingService.getUnusedInstanceIds("worker", 5, stack); assertEquals(0, unusedInstanceIds.keySet().size()); }
public Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack) { if (scalingAdjustment > 0) { LOGGER.error("Scaling adjustment shouldn't be a positive number, we are trying to downscaling.."); return new HashMap<>(); } InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupName(instanceGroupName); List<InstanceMetaData> unattachedInstanceMetaDatas = new ArrayList<>(instanceGroup.getUnattachedInstanceMetaDataSet()); return unattachedInstanceMetaDatas.stream() .filter(instanceMetaData -> instanceMetaData.getInstanceId() != null && instanceMetaData.getDiscoveryFQDN() != null) .sorted(Comparator.comparing(InstanceMetaData::getStartDate)) .limit(Math.abs(scalingAdjustment)) .collect(Collectors.toMap(InstanceMetaData::getInstanceId, InstanceMetaData::getDiscoveryFQDN)); }
StackScalingService { public Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack) { if (scalingAdjustment > 0) { LOGGER.error("Scaling adjustment shouldn't be a positive number, we are trying to downscaling.."); return new HashMap<>(); } InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupName(instanceGroupName); List<InstanceMetaData> unattachedInstanceMetaDatas = new ArrayList<>(instanceGroup.getUnattachedInstanceMetaDataSet()); return unattachedInstanceMetaDatas.stream() .filter(instanceMetaData -> instanceMetaData.getInstanceId() != null && instanceMetaData.getDiscoveryFQDN() != null) .sorted(Comparator.comparing(InstanceMetaData::getStartDate)) .limit(Math.abs(scalingAdjustment)) .collect(Collectors.toMap(InstanceMetaData::getInstanceId, InstanceMetaData::getDiscoveryFQDN)); } }
StackScalingService { public Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack) { if (scalingAdjustment > 0) { LOGGER.error("Scaling adjustment shouldn't be a positive number, we are trying to downscaling.."); return new HashMap<>(); } InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupName(instanceGroupName); List<InstanceMetaData> unattachedInstanceMetaDatas = new ArrayList<>(instanceGroup.getUnattachedInstanceMetaDataSet()); return unattachedInstanceMetaDatas.stream() .filter(instanceMetaData -> instanceMetaData.getInstanceId() != null && instanceMetaData.getDiscoveryFQDN() != null) .sorted(Comparator.comparing(InstanceMetaData::getStartDate)) .limit(Math.abs(scalingAdjustment)) .collect(Collectors.toMap(InstanceMetaData::getInstanceId, InstanceMetaData::getDiscoveryFQDN)); }  }
StackScalingService { public Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack) { if (scalingAdjustment > 0) { LOGGER.error("Scaling adjustment shouldn't be a positive number, we are trying to downscaling.."); return new HashMap<>(); } InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupName(instanceGroupName); List<InstanceMetaData> unattachedInstanceMetaDatas = new ArrayList<>(instanceGroup.getUnattachedInstanceMetaDataSet()); return unattachedInstanceMetaDatas.stream() .filter(instanceMetaData -> instanceMetaData.getInstanceId() != null && instanceMetaData.getDiscoveryFQDN() != null) .sorted(Comparator.comparing(InstanceMetaData::getStartDate)) .limit(Math.abs(scalingAdjustment)) .collect(Collectors.toMap(InstanceMetaData::getInstanceId, InstanceMetaData::getDiscoveryFQDN)); }  int updateRemovedResourcesState(Collection<String> instanceIds, InstanceGroup instanceGroup); Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack); }
StackScalingService { public Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack) { if (scalingAdjustment > 0) { LOGGER.error("Scaling adjustment shouldn't be a positive number, we are trying to downscaling.."); return new HashMap<>(); } InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupName(instanceGroupName); List<InstanceMetaData> unattachedInstanceMetaDatas = new ArrayList<>(instanceGroup.getUnattachedInstanceMetaDataSet()); return unattachedInstanceMetaDatas.stream() .filter(instanceMetaData -> instanceMetaData.getInstanceId() != null && instanceMetaData.getDiscoveryFQDN() != null) .sorted(Comparator.comparing(InstanceMetaData::getStartDate)) .limit(Math.abs(scalingAdjustment)) .collect(Collectors.toMap(InstanceMetaData::getInstanceId, InstanceMetaData::getDiscoveryFQDN)); }  int updateRemovedResourcesState(Collection<String> instanceIds, InstanceGroup instanceGroup); Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack);  }