Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoScalingGroup Weight support #295

Merged
merged 6 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
haugenj marked this conversation as resolved.
Show resolved Hide resolved
<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