-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* capacity providers * capacity providers * capacity providers * capacity providers * PR cmments * added assumedRoleArn
- Loading branch information
Showing
11 changed files
with
213 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,14 @@ | |
|
||
package com.cloudbees.jenkins.plugins.amazonecs; | ||
|
||
import com.amazonaws.services.ecs.AmazonECS; | ||
import com.amazonaws.services.ecs.model.AwsVpcConfiguration; | ||
import com.amazonaws.services.ecs.model.ContainerDefinition; | ||
import com.amazonaws.services.ecs.model.HostEntry; | ||
import com.amazonaws.services.ecs.model.HostVolumeProperties; | ||
import com.amazonaws.services.ecs.model.KeyValuePair; | ||
import com.amazonaws.services.ecs.model.LaunchType; | ||
import com.amazonaws.services.ecs.model.CapacityProviderStrategyItem; | ||
import com.amazonaws.services.ecs.model.LinuxParameters; | ||
import com.amazonaws.services.ecs.model.MountPoint; | ||
import com.amazonaws.services.ecs.model.NetworkMode; | ||
|
@@ -40,8 +42,12 @@ | |
import com.amazonaws.services.ecs.model.RegisterTaskDefinitionRequest; | ||
import com.amazonaws.services.ecs.model.RepositoryCredentials; | ||
import com.amazonaws.services.ecs.model.Volume; | ||
import com.amazonaws.services.ecs.model.DescribeClustersRequest; | ||
import com.amazonaws.services.ecs.model.DescribeClustersResult; | ||
import com.amazonaws.services.ecs.model.Cluster; | ||
import static com.google.common.base.Strings.isNullOrEmpty; | ||
import hudson.Extension; | ||
import hudson.RelativePath; | ||
import hudson.model.AbstractDescribableImpl; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Label; | ||
|
@@ -71,6 +77,7 @@ | |
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
import java.util.Collections; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Nicolas De Loof</a> | ||
|
@@ -238,6 +245,12 @@ public int getMemoryConstraint() { | |
*/ | ||
private final String launchType; | ||
|
||
/** | ||
* Use default capacity provider will omit launch types and capacity strategies | ||
* | ||
*/ | ||
private boolean defaultCapacityProvider; | ||
|
||
/** | ||
* Task network mode | ||
*/ | ||
|
@@ -269,7 +282,7 @@ public int getMemoryConstraint() { | |
private List<ExtraHostEntry> extraHosts; | ||
private List<PortMappingEntry> portMappings; | ||
private List<PlacementStrategyEntry> placementStrategies; | ||
|
||
private List<CapacityProviderStrategyEntry> capacityProviderStrategies; | ||
|
||
|
||
/** | ||
|
@@ -301,7 +314,9 @@ public ECSTaskTemplate(String templateName, | |
@Nullable String dynamicTaskDefinitionOverride, | ||
String image, | ||
@Nullable final String repositoryCredentials, | ||
String launchType, | ||
@Nullable String launchType, | ||
boolean defaultCapacityProvider, | ||
@Nullable List<CapacityProviderStrategyEntry> capacityProviderStrategies, | ||
String networkMode, | ||
@Nullable String remoteFSRoot, | ||
boolean uniqueRemoteFSRoot, | ||
|
@@ -349,6 +364,8 @@ public ECSTaskTemplate(String templateName, | |
this.memoryReservation = memoryReservation; | ||
this.cpu = cpu; | ||
this.launchType = launchType; | ||
this.defaultCapacityProvider = defaultCapacityProvider; | ||
this.capacityProviderStrategies = capacityProviderStrategies; | ||
this.networkMode = networkMode; | ||
this.subnets = subnets; | ||
this.securityGroups = securityGroups; | ||
|
@@ -425,6 +442,15 @@ public void setDnsSearchDomains(String dnsSearchDomains) { | |
} | ||
|
||
public boolean isFargate() { | ||
if (!this.defaultCapacityProvider && this.capacityProviderStrategies != null && ! this.capacityProviderStrategies.isEmpty()) { | ||
for (CapacityProviderStrategyEntry capacityProviderStrategy : this.capacityProviderStrategies) { | ||
String provider = capacityProviderStrategy.provider; | ||
if (provider.contains(LaunchType.FARGATE.toString())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
return StringUtils.trimToNull(this.launchType) != null && launchType.equals(LaunchType.FARGATE.toString()); | ||
} | ||
|
||
|
@@ -489,6 +515,10 @@ public boolean getAssignPublicIp() { | |
return assignPublicIp; | ||
} | ||
|
||
public boolean getDefaultCapacityProvider() { | ||
return defaultCapacityProvider; | ||
} | ||
|
||
public String getDnsSearchDomains() { | ||
return dnsSearchDomains; | ||
} | ||
|
@@ -613,6 +643,10 @@ public List<PlacementStrategyEntry> getPlacementStrategies() { | |
return placementStrategies; | ||
} | ||
|
||
public List<CapacityProviderStrategyEntry> getCapacityProviderStrategies() { | ||
return capacityProviderStrategies; | ||
} | ||
|
||
/** | ||
* This merge does not take an into consideration the child intentionally setting empty values for parameters like "entrypoint" - in fact | ||
* it's not uncommon to override the entrypoint of a container and set it to blank so you can use your own entrypoint as part of the command. | ||
|
@@ -631,6 +665,7 @@ public ECSTaskTemplate merge(ECSTaskTemplate parent) { | |
String image = isNullOrEmpty(this.image) ? parent.getImage() : this.image; | ||
String repositoryCredentials = isNullOrEmpty(this.repositoryCredentials) ? parent.getRepositoryCredentials() : this.repositoryCredentials; | ||
String launchType = isNullOrEmpty(this.launchType) ? parent.getLaunchType() : this.launchType; | ||
boolean defaultCapacityProvider = this.defaultCapacityProvider ? this.defaultCapacityProvider : parent.getDefaultCapacityProvider(); | ||
String networkMode = isNullOrEmpty(this.networkMode) ? parent.getNetworkMode() : this.networkMode; | ||
String remoteFSRoot = isNullOrEmpty(this.remoteFSRoot) ? parent.getRemoteFSRoot() : this.remoteFSRoot; | ||
|
||
|
@@ -660,6 +695,7 @@ public ECSTaskTemplate merge(ECSTaskTemplate parent) { | |
List<MountPointEntry> mountPoints = isEmpty(this.mountPoints) ? parent.getMountPoints() : this.mountPoints; | ||
List<PortMappingEntry> portMappings = isEmpty(this.portMappings) ? parent.getPortMappings() : this.portMappings; | ||
List<PlacementStrategyEntry> placementStrategies = isEmpty(this.placementStrategies) ? parent.getPlacementStrategies() : this.placementStrategies; | ||
List<CapacityProviderStrategyEntry> capacityProviderStrategies = isEmpty(this.capacityProviderStrategies) ? parent.getCapacityProviderStrategies() : this.capacityProviderStrategies; | ||
|
||
String executionRole = isNullOrEmpty(this.executionRole) ? parent.getExecutionRole() : this.executionRole; | ||
String taskrole = isNullOrEmpty(this.taskrole) ? parent.getTaskrole() : this.taskrole; | ||
|
@@ -671,6 +707,8 @@ public ECSTaskTemplate merge(ECSTaskTemplate parent) { | |
image, | ||
repositoryCredentials, | ||
launchType, | ||
defaultCapacityProvider, | ||
capacityProviderStrategies, | ||
networkMode, | ||
remoteFSRoot, | ||
uniqueRemoteFSRoot, | ||
|
@@ -802,6 +840,22 @@ Collection<PlacementStrategy> getPlacementStrategyEntries() { | |
return placements; | ||
} | ||
|
||
Collection<CapacityProviderStrategyItem> getCapacityProviderStrategyEntries() { | ||
if (null == capacityProviderStrategies || capacityProviderStrategies.isEmpty()) | ||
return null; | ||
Collection<CapacityProviderStrategyItem> stragies = new ArrayList<CapacityProviderStrategyItem>(); | ||
for (CapacityProviderStrategyEntry capacityProviderStrategy : this.capacityProviderStrategies) { | ||
String provider = capacityProviderStrategy.provider; | ||
int base = capacityProviderStrategy.base; | ||
int weight = capacityProviderStrategy.weight; | ||
|
||
stragies.add(new CapacityProviderStrategyItem().withCapacityProvider(provider) | ||
.withWeight(weight) | ||
.withBase(base)); | ||
} | ||
return stragies; | ||
} | ||
|
||
public static class EnvironmentEntry extends AbstractDescribableImpl<EnvironmentEntry> implements Serializable { | ||
private static final long serialVersionUID = 4195862080979262875L; | ||
public String name, value; | ||
|
@@ -957,6 +1011,57 @@ public FormValidation doCheckField(@QueryParameter("field") String field, @Query | |
} | ||
} | ||
|
||
public static class CapacityProviderStrategyEntry extends AbstractDescribableImpl<CapacityProviderStrategyEntry> implements Serializable { | ||
//private static final long serialVersionUID = 4195862080979262875L; | ||
public String provider; | ||
public int base, weight; | ||
|
||
@DataBoundConstructor | ||
public CapacityProviderStrategyEntry(String provider, int base, int weight) { | ||
this.base = base; | ||
this.weight = weight; | ||
this.provider = provider; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CapacityProviderStrategyEntry{" + provider + "base: " + base + "weight: " + weight + "}"; | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends Descriptor<CapacityProviderStrategyEntry> { | ||
public ListBoxModel doFillProviderItems( | ||
@RelativePath("../..") @QueryParameter String credentialsId, | ||
@RelativePath("../..") @QueryParameter String assumedRoleArn, | ||
@RelativePath("../..") @QueryParameter String regionName, | ||
@RelativePath("../..") @QueryParameter String cluster | ||
){ | ||
ECSService ecsService = new ECSService(credentialsId, assumedRoleArn, regionName); | ||
final AmazonECS client = ecsService.getAmazonECSClient(); | ||
final List<Cluster> allClusters = new ArrayList<Cluster>(); | ||
DescribeClustersResult result = client.describeClusters(new DescribeClustersRequest().withClusters(cluster)); | ||
allClusters.addAll(result.getClusters()); | ||
final ListBoxModel options = new ListBoxModel(); | ||
for ( Cluster c : allClusters) { | ||
List<String> item = c.getCapacityProviders(); | ||
Collections.sort(item); | ||
for (String provider : item) { | ||
options.add(provider); | ||
} | ||
} | ||
return options; | ||
} | ||
@Override | ||
public String getDisplayName() { | ||
return "CapacityProviderStrategyEntry"; | ||
} | ||
|
||
public FormValidation doCheckField(@QueryParameter("base") int base, @QueryParameter("weight") int weight, @QueryParameter("provider") String provider) throws IOException, ServletException { | ||
return FormValidation.ok(); | ||
} | ||
} | ||
} | ||
|
||
public Set<LabelAtom> getLabelSet() { | ||
return Label.parse(label); | ||
} | ||
|
@@ -1142,6 +1247,12 @@ public boolean equals(Object o) { | |
if (launchType != null ? !launchType.equals(that.launchType) : that.launchType != null) { | ||
return false; | ||
} | ||
if (defaultCapacityProvider != that.defaultCapacityProvider) { | ||
return false; | ||
} | ||
if (capacityProviderStrategies != null ? !capacityProviderStrategies.equals(that.capacityProviderStrategies) : that.capacityProviderStrategies != null) { | ||
return false; | ||
} | ||
if (networkMode != null ? !networkMode.equals(that.networkMode) : that.networkMode != null) { | ||
return false; | ||
} | ||
|
@@ -1192,6 +1303,8 @@ public int hashCode() { | |
result = 31 * result + (jvmArgs != null ? jvmArgs.hashCode() : 0); | ||
result = 31 * result + (mountPoints != null ? mountPoints.hashCode() : 0); | ||
result = 31 * result + (launchType != null ? launchType.hashCode() : 0); | ||
result = 31 * result + (defaultCapacityProvider ? 1 : 0); | ||
result = 31 * result + (capacityProviderStrategies != null ? capacityProviderStrategies.hashCode() : 0); | ||
result = 31 * result + (networkMode != null ? networkMode.hashCode() : 0); | ||
result = 31 * result + (privileged ? 1 : 0); | ||
result = 31 * result + (uniqueRemoteFSRoot ? 1 : 0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.