Skip to content

Commit

Permalink
AutoScalingGroup Weight support (#295)
Browse files Browse the repository at this point in the history
* Switch to Properties. Update Dependencies

* Add missing methods

* Add Support for InstanceWeights on AutoScalingGroups

* Fixed imports

* Remove deprecated Note in Documentation

* Optimize imports (again)
  • Loading branch information
driverpt authored Oct 12, 2021
1 parent 8cef0b2 commit 2c0da3b
Show file tree
Hide file tree
Showing 5 changed files with 701 additions and 28 deletions.
11 changes: 7 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<jenkins.version>2.235.5</jenkins.version>
<java.level>8</java.level>
<configuration-as-code.version>1.51</configuration-as-code.version>
<aws-sdk.version>1.11.687</aws-sdk.version>
<aws-credentials.version>1.26</aws-credentials.version>
<powermock.version>2.0.5</powermock.version>
</properties>

<name>EC2 Fleet Jenkins Plugin</name>
Expand Down Expand Up @@ -83,12 +86,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.341</version>
<version>${aws-sdk.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>aws-credentials</artifactId>
<version>1.24</version>
<version>${aws-credentials.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -99,7 +102,7 @@
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.5</version>
<version>${powermock.version}</version>
<scope>test</scope>
<exclusions>
<!-- use old version, parent required new one -->
Expand All @@ -112,7 +115,7 @@
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.5</version>
<version>${powermock.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.amazon.jenkins.ec2fleet.fleet;

import com.amazon.jenkins.ec2fleet.utils.AWSUtils;
import com.amazon.jenkins.ec2fleet.FleetStateStats;
import com.amazon.jenkins.ec2fleet.utils.AWSUtils;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.RegionUtils;
Expand All @@ -10,6 +10,9 @@
import com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest;
import com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult;
import com.amazonaws.services.autoscaling.model.Instance;
import com.amazonaws.services.autoscaling.model.LaunchTemplate;
import com.amazonaws.services.autoscaling.model.LaunchTemplateOverrides;
import com.amazonaws.services.autoscaling.model.MixedInstancesPolicy;
import com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest;
import com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsHelper;
import com.cloudbees.jenkins.plugins.awscredentials.AmazonWebServicesCredentials;
Expand All @@ -24,7 +27,9 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

@ThreadSafe
public class AutoScalingGroupFleet implements EC2Fleet {
Expand Down Expand Up @@ -86,12 +91,19 @@ public FleetStateStats getState(
instanceIds.add(instance.getInstanceId());
}

Map<String, Double> instanceWeights = Optional.ofNullable(group.getMixedInstancesPolicy())
.map(MixedInstancesPolicy::getLaunchTemplate)
.map(LaunchTemplate::getOverrides)
.map(overrides -> overrides.stream()
.collect(Collectors.toMap(LaunchTemplateOverrides::getInstanceType,
override -> Double.parseDouble(override.getWeightedCapacity()))))
.orElse(Collections.emptyMap());

return new FleetStateStats(
id, group.getDesiredCapacity(),
// status could be null which is active
FleetStateStats.State.active(StringUtils.defaultIfEmpty(group.getStatus(), "active")),
// auto scaling groups don't support weight, may be in future
instanceIds, Collections.<String, Double>emptyMap());
instanceIds, instanceWeights);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
information to scale the number of executors per node. Instead, Jenkins will just use the number of executors defined in
configuration field <code>Number of Executors</code>.

<p>
<b>Note:</b> The plugin only supports scaling from weight with EC2 Spot Fleet.
There is an open [issue](https://github.com/jenkinsci/ec2-fleet-plugin/issues/186) for ASG weight scaling support.
</p>

<p>
When checked, the plugin consumes instance weight information provided by a Launch Specification
and uses it to scale the node's number of executors from configuration field <code>Number of Executors</code>.
Expand Down
Loading

0 comments on commit 2c0da3b

Please sign in to comment.