Skip to content

Commit 899e84c

Browse files
committed
Remove ElasticsearchIllegalArgumentException and ElasticsearchIllegalStateException in favor of the JDK one
Related to elastic/elasticsearch#10794 Closes elastic#204.
1 parent 3977694 commit 899e84c

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.amazonaws.services.ec2.AmazonEC2;
2727
import com.amazonaws.services.ec2.AmazonEC2Client;
2828
import org.elasticsearch.ElasticsearchException;
29-
import org.elasticsearch.ElasticsearchIllegalArgumentException;
3029
import org.elasticsearch.cloud.aws.network.Ec2NameResolver;
3130
import org.elasticsearch.cloud.aws.node.Ec2CustomNodeAttributes;
3231
import org.elasticsearch.cluster.node.DiscoveryNodeService;
@@ -70,7 +69,7 @@ public synchronized AmazonEC2 client() {
7069
} else if ("https".equals(protocol)) {
7170
clientConfiguration.setProtocol(Protocol.HTTPS);
7271
} else {
73-
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
72+
throw new IllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
7473
}
7574
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
7675
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
@@ -84,7 +83,7 @@ public synchronized AmazonEC2 client() {
8483
try {
8584
proxyPort = Integer.parseInt(portString, 10);
8685
} catch (NumberFormatException ex) {
87-
throw new ElasticsearchIllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
86+
throw new IllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
8887
}
8988
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
9089
}
@@ -95,7 +94,7 @@ public synchronized AmazonEC2 client() {
9594
logger.debug("using AWS API signer [{}]", awsSigner);
9695
try {
9796
AwsSigner.configureSigner(awsSigner, clientConfiguration);
98-
} catch (ElasticsearchIllegalArgumentException e) {
97+
} catch (IllegalArgumentException e) {
9998
logger.warn("wrong signer set for [cloud.aws.ec2.signer] or [cloud.aws.signer]: [{}]", awsSigner);
10099
}
101100
}
@@ -144,7 +143,7 @@ public synchronized AmazonEC2 client() {
144143
} else if (region.equals("cn-north") || region.equals("cn-north-1")) {
145144
endpoint = "ec2.cn-north-1.amazonaws.com.cn";
146145
} else {
147-
throw new ElasticsearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
146+
throw new IllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
148147
}
149148
if (endpoint != null) {
150149
logger.debug("using ec2 region [{}], with endpoint [{}]", region, endpoint);

src/main/java/org/elasticsearch/cloud/aws/AwsSigner.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.amazonaws.ClientConfiguration;
2323
import com.amazonaws.auth.SignerFactory;
24-
import org.elasticsearch.ElasticsearchIllegalArgumentException;
2524

2625
public class AwsSigner {
2726

@@ -33,13 +32,13 @@ private AwsSigner() {
3332
* Add a AWS API Signer.
3433
* @param signer Signer to use
3534
* @param configuration AWS Client configuration
36-
* @throws ElasticsearchIllegalArgumentException if signer does not exist
35+
* @throws IllegalArgumentException if signer does not exist
3736
*/
3837
public static void configureSigner(String signer, ClientConfiguration configuration)
39-
throws ElasticsearchIllegalArgumentException {
38+
throws IllegalArgumentException {
4039

4140
if (signer == null) {
42-
throw new ElasticsearchIllegalArgumentException("[null] signer set");
41+
throw new IllegalArgumentException("[null] signer set");
4342
}
4443

4544
try {
@@ -48,7 +47,7 @@ public static void configureSigner(String signer, ClientConfiguration configurat
4847
SignerFactory.getSignerByTypeAndService(signer, null);
4948
configuration.setSignerOverride(signer);
5049
} catch (IllegalArgumentException e) {
51-
throw new ElasticsearchIllegalArgumentException("wrong signer set [" + signer + "]");
50+
throw new IllegalArgumentException("wrong signer set [" + signer + "]");
5251
}
5352
}
5453
}

src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.amazonaws.services.s3.AmazonS3;
2828
import com.amazonaws.services.s3.AmazonS3Client;
2929
import org.elasticsearch.ElasticsearchException;
30-
import org.elasticsearch.ElasticsearchIllegalArgumentException;
3130
import org.elasticsearch.common.collect.Tuple;
3231
import org.elasticsearch.common.component.AbstractLifecycleComponent;
3332
import org.elasticsearch.common.inject.Inject;
@@ -100,7 +99,7 @@ private synchronized AmazonS3 getClient(String endpoint, String protocol, String
10099
} else if ("https".equals(protocol)) {
101100
clientConfiguration.setProtocol(Protocol.HTTPS);
102101
} else {
103-
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
102+
throw new IllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
104103
}
105104

106105
String proxyHost = settings.get("cloud.aws.proxy_host");
@@ -112,7 +111,7 @@ private synchronized AmazonS3 getClient(String endpoint, String protocol, String
112111
try {
113112
proxyPort = Integer.parseInt(portString, 10);
114113
} catch (NumberFormatException ex) {
115-
throw new ElasticsearchIllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
114+
throw new IllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
116115
}
117116
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
118117
}
@@ -128,7 +127,7 @@ private synchronized AmazonS3 getClient(String endpoint, String protocol, String
128127
logger.debug("using AWS API signer [{}]", awsSigner);
129128
try {
130129
AwsSigner.configureSigner(awsSigner, clientConfiguration);
131-
} catch (ElasticsearchIllegalArgumentException e) {
130+
} catch (IllegalArgumentException e) {
132131
logger.warn("wrong signer set for [cloud.aws.s3.signer] or [cloud.aws.signer]: [{}]", awsSigner);
133132
}
134133
}
@@ -190,7 +189,7 @@ private static String getEndpoint(String region) {
190189
} else if ("cn-north".equals(region) || "cn-north-1".equals(region)) {
191190
return "s3.cn-north-1.amazonaws.com.cn";
192191
} else {
193-
throw new ElasticsearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
192+
throw new IllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
194193
}
195194
}
196195

src/test/java/org/elasticsearch/cloud/aws/AWSSignersTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.cloud.aws;
2121

2222
import com.amazonaws.ClientConfiguration;
23-
import org.elasticsearch.ElasticsearchIllegalArgumentException;
2423
import org.elasticsearch.test.ElasticsearchTestCase;
2524
import org.junit.Test;
2625

@@ -47,7 +46,7 @@ private boolean signerTester(String signer) {
4746
try {
4847
AwsSigner.configureSigner(signer, new ClientConfiguration());
4948
return true;
50-
} catch (ElasticsearchIllegalArgumentException e) {
49+
} catch (IllegalArgumentException e) {
5150
return false;
5251
}
5352
}

0 commit comments

Comments
 (0)