Remove `ElasticsearchIllegalArgumentException` and `ElasticsearchIllegalStateException` in favor of the JDK one
Related to https://github.com/elastic/elasticsearch/issues/10794 Closes #204.
This commit is contained in:
parent
39776944d5
commit
899e84c01e
|
@ -26,7 +26,6 @@ import com.amazonaws.internal.StaticCredentialsProvider;
|
||||||
import com.amazonaws.services.ec2.AmazonEC2;
|
import com.amazonaws.services.ec2.AmazonEC2;
|
||||||
import com.amazonaws.services.ec2.AmazonEC2Client;
|
import com.amazonaws.services.ec2.AmazonEC2Client;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
|
||||||
import org.elasticsearch.cloud.aws.network.Ec2NameResolver;
|
import org.elasticsearch.cloud.aws.network.Ec2NameResolver;
|
||||||
import org.elasticsearch.cloud.aws.node.Ec2CustomNodeAttributes;
|
import org.elasticsearch.cloud.aws.node.Ec2CustomNodeAttributes;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
||||||
|
@ -70,7 +69,7 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
|
||||||
} else if ("https".equals(protocol)) {
|
} else if ("https".equals(protocol)) {
|
||||||
clientConfiguration.setProtocol(Protocol.HTTPS);
|
clientConfiguration.setProtocol(Protocol.HTTPS);
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
throw new IllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
||||||
}
|
}
|
||||||
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
|
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
|
||||||
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
|
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
|
||||||
|
@ -84,7 +83,7 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
|
||||||
try {
|
try {
|
||||||
proxyPort = Integer.parseInt(portString, 10);
|
proxyPort = Integer.parseInt(portString, 10);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
throw new ElasticsearchIllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
|
throw new IllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
|
||||||
}
|
}
|
||||||
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
|
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +94,7 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
|
||||||
logger.debug("using AWS API signer [{}]", awsSigner);
|
logger.debug("using AWS API signer [{}]", awsSigner);
|
||||||
try {
|
try {
|
||||||
AwsSigner.configureSigner(awsSigner, clientConfiguration);
|
AwsSigner.configureSigner(awsSigner, clientConfiguration);
|
||||||
} catch (ElasticsearchIllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.warn("wrong signer set for [cloud.aws.ec2.signer] or [cloud.aws.signer]: [{}]", awsSigner);
|
logger.warn("wrong signer set for [cloud.aws.ec2.signer] or [cloud.aws.signer]: [{}]", awsSigner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +143,7 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
|
||||||
} else if (region.equals("cn-north") || region.equals("cn-north-1")) {
|
} else if (region.equals("cn-north") || region.equals("cn-north-1")) {
|
||||||
endpoint = "ec2.cn-north-1.amazonaws.com.cn";
|
endpoint = "ec2.cn-north-1.amazonaws.com.cn";
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticsearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
|
throw new IllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
|
||||||
}
|
}
|
||||||
if (endpoint != null) {
|
if (endpoint != null) {
|
||||||
logger.debug("using ec2 region [{}], with endpoint [{}]", region, endpoint);
|
logger.debug("using ec2 region [{}], with endpoint [{}]", region, endpoint);
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.cloud.aws;
|
||||||
|
|
||||||
import com.amazonaws.ClientConfiguration;
|
import com.amazonaws.ClientConfiguration;
|
||||||
import com.amazonaws.auth.SignerFactory;
|
import com.amazonaws.auth.SignerFactory;
|
||||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
|
||||||
|
|
||||||
public class AwsSigner {
|
public class AwsSigner {
|
||||||
|
|
||||||
|
@ -33,13 +32,13 @@ public class AwsSigner {
|
||||||
* Add a AWS API Signer.
|
* Add a AWS API Signer.
|
||||||
* @param signer Signer to use
|
* @param signer Signer to use
|
||||||
* @param configuration AWS Client configuration
|
* @param configuration AWS Client configuration
|
||||||
* @throws ElasticsearchIllegalArgumentException if signer does not exist
|
* @throws IllegalArgumentException if signer does not exist
|
||||||
*/
|
*/
|
||||||
public static void configureSigner(String signer, ClientConfiguration configuration)
|
public static void configureSigner(String signer, ClientConfiguration configuration)
|
||||||
throws ElasticsearchIllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
if (signer == null) {
|
if (signer == null) {
|
||||||
throw new ElasticsearchIllegalArgumentException("[null] signer set");
|
throw new IllegalArgumentException("[null] signer set");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -48,7 +47,7 @@ public class AwsSigner {
|
||||||
SignerFactory.getSignerByTypeAndService(signer, null);
|
SignerFactory.getSignerByTypeAndService(signer, null);
|
||||||
configuration.setSignerOverride(signer);
|
configuration.setSignerOverride(signer);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new ElasticsearchIllegalArgumentException("wrong signer set [" + signer + "]");
|
throw new IllegalArgumentException("wrong signer set [" + signer + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import com.amazonaws.internal.StaticCredentialsProvider;
|
||||||
import com.amazonaws.services.s3.AmazonS3;
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
import com.amazonaws.services.s3.AmazonS3Client;
|
import com.amazonaws.services.s3.AmazonS3Client;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
import org.elasticsearch.common.collect.Tuple;
|
||||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
@ -100,7 +99,7 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
} else if ("https".equals(protocol)) {
|
} else if ("https".equals(protocol)) {
|
||||||
clientConfiguration.setProtocol(Protocol.HTTPS);
|
clientConfiguration.setProtocol(Protocol.HTTPS);
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
throw new IllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
||||||
}
|
}
|
||||||
|
|
||||||
String proxyHost = settings.get("cloud.aws.proxy_host");
|
String proxyHost = settings.get("cloud.aws.proxy_host");
|
||||||
|
@ -112,7 +111,7 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
try {
|
try {
|
||||||
proxyPort = Integer.parseInt(portString, 10);
|
proxyPort = Integer.parseInt(portString, 10);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
throw new ElasticsearchIllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
|
throw new IllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex);
|
||||||
}
|
}
|
||||||
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
|
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +127,7 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
logger.debug("using AWS API signer [{}]", awsSigner);
|
logger.debug("using AWS API signer [{}]", awsSigner);
|
||||||
try {
|
try {
|
||||||
AwsSigner.configureSigner(awsSigner, clientConfiguration);
|
AwsSigner.configureSigner(awsSigner, clientConfiguration);
|
||||||
} catch (ElasticsearchIllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.warn("wrong signer set for [cloud.aws.s3.signer] or [cloud.aws.signer]: [{}]", awsSigner);
|
logger.warn("wrong signer set for [cloud.aws.s3.signer] or [cloud.aws.signer]: [{}]", awsSigner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +189,7 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
} else if ("cn-north".equals(region) || "cn-north-1".equals(region)) {
|
} else if ("cn-north".equals(region) || "cn-north-1".equals(region)) {
|
||||||
return "s3.cn-north-1.amazonaws.com.cn";
|
return "s3.cn-north-1.amazonaws.com.cn";
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticsearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
|
throw new IllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.cloud.aws;
|
package org.elasticsearch.cloud.aws;
|
||||||
|
|
||||||
import com.amazonaws.ClientConfiguration;
|
import com.amazonaws.ClientConfiguration;
|
||||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
|
||||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ public class AWSSignersTest extends ElasticsearchTestCase {
|
||||||
try {
|
try {
|
||||||
AwsSigner.configureSigner(signer, new ClientConfiguration());
|
AwsSigner.configureSigner(signer, new ClientConfiguration());
|
||||||
return true;
|
return true;
|
||||||
} catch (ElasticsearchIllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue