Skip to content

Commit

Permalink
Remove Eucalyptus support (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Dec 27, 2024
1 parent 40112c5 commit 4b7fcc5
Show file tree
Hide file tree
Showing 33 changed files with 908 additions and 1,327 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
# Introduction

Allow Jenkins to start agents on
[EC2](http://aws.amazon.com/ec2/) or
[Eucalyptus](https://www.eucalyptus.cloud/) on demand, and
[EC2](http://aws.amazon.com/ec2/) on demand, and
kill them as they get unused.

With this plugin, if Jenkins notices that your build cluster is
Expand Down Expand Up @@ -299,7 +298,7 @@ import com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.domains.Domain
import hudson.model.*
import hudson.plugins.ec2.AmazonEC2Cloud
import hudson.plugins.ec2.EC2Cloud
import hudson.plugins.ec2.AMITypeData
import hudson.plugins.ec2.EC2Tag
import hudson.plugins.ec2.SlaveTemplate
Expand Down Expand Up @@ -363,7 +362,7 @@ def slaveTemplateUsEast1Parameters = [
nodeProperties: null
]
def AmazonEC2CloudParameters = [
def EC2CloudParameters = [
name: 'MyCompany',
credentialsId: 'jenkins-aws-key',
instanceCapStr: '2',
Expand Down Expand Up @@ -462,14 +461,14 @@ SlaveTemplate slaveTemplateUsEast1 = new SlaveTemplate(
slaveTemplateUsEast1Parameters.metadataHopsLimit,
)
// https://javadoc.jenkins.io/plugin/ec2/index.html?hudson/plugins/ec2/AmazonEC2Cloud.html
AmazonEC2Cloud amazonEC2Cloud = new AmazonEC2Cloud(
AmazonEC2CloudParameters.name,
AmazonEC2CloudParameters.useInstanceProfileForCredentials,
AmazonEC2CloudParameters.credentialsId,
AmazonEC2CloudParameters.region,
AmazonEC2CloudParameters.privateKey,
AmazonEC2CloudParameters.instanceCapStr,
// https://javadoc.jenkins.io/plugin/ec2/hudson/plugins/ec2/EC2Cloud.html
EC2Cloud ec2Cloud = new EC2Cloud(
EC2CloudParameters.name,
EC2CloudParameters.useInstanceProfileForCredentials,
EC2CloudParameters.credentialsId,
EC2CloudParameters.region,
EC2CloudParameters.privateKey,
EC2CloudParameters.instanceCapStr,
[slaveTemplateUsEast1],
'',
''
Expand All @@ -488,7 +487,7 @@ def store = jenkins.getExtensionList('com.cloudbees.plugins.credentials.SystemCr
store.addCredentials(domain, aWSCredentialsImpl)
// add cloud configuration to Jenkins
jenkins.clouds.add(amazonEC2Cloud)
jenkins.clouds.add(ec2Cloud)
// save current Jenkins state to disk
jenkins.save()
Expand All @@ -504,7 +503,7 @@ Example:
```java
// Assuming on the Jenkins instance, there exists an EC2Cloud with the name "AwsCloud"

AmazonEC2Cloud cloud = (AmazonEC2Cloud) Jenkins.get().clouds.stream().filter(cloud1 -> Objects.equals(cloud.getDisplayName(), "AwsCloud")).findFirst().get();
EC2Cloud cloud = (EC2Cloud) Jenkins.get().clouds.stream().filter(cloud1 -> Objects.equals(cloud.getDisplayName(), "AwsCloud")).findFirst().get();

SlaveTemplate template = new SlaveTemplate(/*constructor*/); // View available constructors at https://github.com/jenkinsci/ec2-plugin/blob/master/src/main/java/hudson/plugins/ec2/SlaveTemplate.java

Expand Down
223 changes: 4 additions & 219 deletions src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,13 @@
*/
package hudson.plugins.ec2;

import com.amazonaws.SdkClientException;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.model.DescribeRegionsResult;
import com.amazonaws.services.ec2.model.Region;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.Extension;
import hudson.Util;
import hudson.model.Failure;
import hudson.model.ItemGroup;
import hudson.plugins.ec2.util.AmazonEC2Factory;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.kohsuke.stapler.verb.POST;

/**
* The original implementation of {@link EC2Cloud}.
*
* @author Kohsuke Kawaguchi
* @deprecated use {@link EC2Cloud}
*/
@Deprecated
public class AmazonEC2Cloud extends EC2Cloud {
private static final Logger LOGGER = Logger.getLogger(AmazonEC2Cloud.class.getName());

/**
* Represents the region. Can be null for backward compatibility reasons.
*/
private String region;

private String altEC2Endpoint;

private boolean noDelayProvisioning;

@DataBoundConstructor
public AmazonEC2Cloud(
String name,
boolean useInstanceProfileForCredentials,
Expand All @@ -85,16 +45,15 @@ public AmazonEC2Cloud(
name,
useInstanceProfileForCredentials,
credentialsId,
region,
privateKey,
sshKeysCredentialsId,
instanceCapStr,
templates,
roleArn,
roleSessionName);
this.region = region;
}

@Deprecated
public AmazonEC2Cloud(
String name,
boolean useInstanceProfileForCredentials,
Expand All @@ -109,185 +68,11 @@ public AmazonEC2Cloud(
name,
useInstanceProfileForCredentials,
credentialsId,
region,
privateKey,
instanceCapStr,
templates,
roleArn,
roleSessionName);
this.region = region;
}

/**
* @deprecated Use public field "name" instead.
*/
@Deprecated
public String getCloudName() {
return name;
}

public String getRegion() {
if (region == null) {
region = DEFAULT_EC2_HOST; // Backward compatibility
}
// Handles pre 1.14 region names that used the old AwsRegion enum, note we don't change
// the region here to keep the meta-data compatible in the case of a downgrade (is that right?)
if (region.indexOf('_') > 0) {
return region.replace('_', '-').toLowerCase(Locale.ENGLISH);
}
return region;
}

public static URL getEc2EndpointUrl(String region) {
try {
return new URL("https://" + getAwsPartitionHostForService(region, "ec2"));
} catch (MalformedURLException e) {
throw new Error(e); // Impossible
}
}

@Override
public URL getEc2EndpointUrl() {
return getEc2EndpointUrl(getRegion());
}

@Override
public URL getS3EndpointUrl() {
try {
return new URL("https://" + getAwsPartitionHostForService(getRegion(), "s3") + "/");
} catch (MalformedURLException e) {
throw new Error(e); // Impossible
}
}

public boolean isNoDelayProvisioning() {
return noDelayProvisioning;
}

@DataBoundSetter
public void setNoDelayProvisioning(boolean noDelayProvisioning) {
this.noDelayProvisioning = noDelayProvisioning;
}

public String getAltEC2Endpoint() {
return altEC2Endpoint;
}

@DataBoundSetter
public void setAltEC2Endpoint(String altEC2Endpoint) {
this.altEC2Endpoint = altEC2Endpoint;
}

@Override
protected AWSCredentialsProvider createCredentialsProvider() {
return createCredentialsProvider(
isUseInstanceProfileForCredentials(),
getCredentialsId(),
getRoleArn(),
getRoleSessionName(),
getRegion());
}

@Extension
public static class DescriptorImpl extends EC2Cloud.DescriptorImpl {

@Override
public String getDisplayName() {
return "Amazon EC2";
}

@POST
public FormValidation doCheckCloudName(@QueryParameter String value) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return FormValidation.ok();
}
try {
Jenkins.checkGoodName(value);
} catch (Failure e) {
return FormValidation.error(e.getMessage());
}
return FormValidation.ok();
}

@POST
public FormValidation doCheckAltEC2Endpoint(@QueryParameter String value) {
if (Util.fixEmpty(value) != null) {
try {
new URL(value);
} catch (MalformedURLException ignored) {
return FormValidation.error(Messages.AmazonEC2Cloud_MalformedUrl());
}
}
return FormValidation.ok();
}

@RequirePOST
public ListBoxModel doFillRegionItems(
@QueryParameter String altEC2Endpoint,
@QueryParameter boolean useInstanceProfileForCredentials,
@QueryParameter String credentialsId)
throws IOException, ServletException {
ListBoxModel model = new ListBoxModel();
if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
try {
AWSCredentialsProvider credentialsProvider =
createCredentialsProvider(useInstanceProfileForCredentials, credentialsId);
AmazonEC2 client = AmazonEC2Factory.getInstance()
.connect(credentialsProvider, determineEC2EndpointURL(altEC2Endpoint));
DescribeRegionsResult regions = client.describeRegions();
List<Region> regionList = regions.getRegions();
for (Region r : regionList) {
String name = r.getRegionName();
model.add(name, name);
}
} catch (SdkClientException ex) {
// Ignore, as this may happen before the credentials are specified
}
}
return model;
}

// Will use the alternate EC2 endpoint if provided by the UI (via a @QueryParameter field), or use the default
// value if not specified.
// VisibleForTesting
URL determineEC2EndpointURL(@Nullable String altEC2Endpoint) throws MalformedURLException {
if (Util.fixEmpty(altEC2Endpoint) == null) {
return new URL(DEFAULT_EC2_ENDPOINT);
}
try {
return new URL(altEC2Endpoint);
} catch (MalformedURLException e) {
LOGGER.log(
Level.WARNING,
"The alternate EC2 endpoint is malformed ({0}). Using the default endpoint ({1})",
new Object[] {altEC2Endpoint, DEFAULT_EC2_ENDPOINT});
return new URL(DEFAULT_EC2_ENDPOINT);
}
}

@RequirePOST
public FormValidation doTestConnection(
@AncestorInPath ItemGroup context,
@QueryParameter String region,
@QueryParameter boolean useInstanceProfileForCredentials,
@QueryParameter String credentialsId,
@QueryParameter String sshKeysCredentialsId,
@QueryParameter String roleArn,
@QueryParameter String roleSessionName)
throws IOException, ServletException {

if (Util.fixEmpty(region) == null) {
region = DEFAULT_EC2_HOST;
}

return super.doTestConnection(
context,
getEc2EndpointUrl(region),
useInstanceProfileForCredentials,
credentialsId,
sshKeysCredentialsId,
roleArn,
roleSessionName,
region);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ public static ListBoxModel fillZoneItems(AWSCredentialsProvider credentialsProvi
ListBoxModel model = new ListBoxModel();

if (!StringUtils.isEmpty(region)) {
AmazonEC2 client = AmazonEC2Factory.getInstance()
.connect(credentialsProvider, AmazonEC2Cloud.getEc2EndpointUrl(region));
AmazonEC2 client =
AmazonEC2Factory.getInstance().connect(credentialsProvider, EC2Cloud.getEc2EndpointUrl(region));

Check warning on line 1045 in src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1045 is not covered by tests
DescribeAvailabilityZonesResult zones = client.describeAvailabilityZones();
List<AvailabilityZone> zoneList = zones.getAvailabilityZones();
model.add("<not specified>", "");
Expand Down
Loading

0 comments on commit 4b7fcc5

Please sign in to comment.