-
Notifications
You must be signed in to change notification settings - Fork 695
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
Remove Eucalyptus support #1027
Merged
+908
−1,327
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserved for binary compatibility with Groovy scripts. |
||
String name, | ||
boolean useInstanceProfileForCredentials, | ||
|
@@ -85,16 +45,15 @@ public AmazonEC2Cloud( | |
name, | ||
useInstanceProfileForCredentials, | ||
credentialsId, | ||
region, | ||
privateKey, | ||
sshKeysCredentialsId, | ||
instanceCapStr, | ||
templates, | ||
roleArn, | ||
roleSessionName); | ||
this.region = region; | ||
} | ||
|
||
@Deprecated | ||
public AmazonEC2Cloud( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserved for binary compatibility with Groovy scripts. |
||
String name, | ||
boolean useInstanceProfileForCredentials, | ||
|
@@ -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); | ||
} | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this Groovy scripts after this PR with both the old and the new class names. Confirmed XStream serialization was the same as before.