|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package com.facebook.presto.server; |
| 15 | + |
| 16 | +import com.facebook.airlift.configuration.Config; |
| 17 | +import com.facebook.airlift.configuration.ConfigDescription; |
| 18 | +import com.facebook.presto.common.ErrorCode; |
| 19 | +import com.facebook.presto.spi.StandardErrorCode; |
| 20 | +import com.google.common.base.Splitter; |
| 21 | +import com.google.common.collect.ImmutableSet; |
| 22 | + |
| 23 | +import javax.validation.constraints.NotNull; |
| 24 | + |
| 25 | +import java.util.Set; |
| 26 | + |
| 27 | +import static com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_ERROR; |
| 28 | +import static com.google.common.collect.ImmutableSet.toImmutableSet; |
| 29 | + |
| 30 | +public class RetryConfig |
| 31 | +{ |
| 32 | + private boolean retryEnabled = true; |
| 33 | + private Set<String> allowedRetryDomains = ImmutableSet.of(); |
| 34 | + private boolean requireHttps; |
| 35 | + private Set<Integer> crossClusterRetryErrorCodes = ImmutableSet.of( |
| 36 | + REMOTE_TASK_ERROR.toErrorCode().getCode()); |
| 37 | + |
| 38 | + public boolean isRetryEnabled() |
| 39 | + { |
| 40 | + return retryEnabled; |
| 41 | + } |
| 42 | + |
| 43 | + @Config("retry.enabled") |
| 44 | + @ConfigDescription("Enable cross-cluster retry functionality") |
| 45 | + public RetryConfig setRetryEnabled(boolean retryEnabled) |
| 46 | + { |
| 47 | + this.retryEnabled = retryEnabled; |
| 48 | + return this; |
| 49 | + } |
| 50 | + |
| 51 | + @NotNull |
| 52 | + public Set<String> getAllowedRetryDomains() |
| 53 | + { |
| 54 | + return allowedRetryDomains; |
| 55 | + } |
| 56 | + |
| 57 | + @Config("retry.allowed-domains") |
| 58 | + @ConfigDescription("Comma-separated list of allowed domains for retry URLs " + |
| 59 | + "(supports wildcards like *.example.com)") |
| 60 | + public RetryConfig setAllowedRetryDomains(String domains) |
| 61 | + { |
| 62 | + if (domains == null || domains.trim().isEmpty()) { |
| 63 | + this.allowedRetryDomains = ImmutableSet.of(); |
| 64 | + } |
| 65 | + else { |
| 66 | + this.allowedRetryDomains = Splitter.on(',') |
| 67 | + .trimResults() |
| 68 | + .omitEmptyStrings() |
| 69 | + .splitToList(domains) |
| 70 | + .stream() |
| 71 | + .map(String::toLowerCase) |
| 72 | + .collect(toImmutableSet()); |
| 73 | + } |
| 74 | + return this; |
| 75 | + } |
| 76 | + |
| 77 | + public boolean isRequireHttps() |
| 78 | + { |
| 79 | + return requireHttps; |
| 80 | + } |
| 81 | + |
| 82 | + @Config("retry.require-https") |
| 83 | + @ConfigDescription("Require HTTPS for retry URLs") |
| 84 | + public RetryConfig setRequireHttps(boolean requireHttps) |
| 85 | + { |
| 86 | + this.requireHttps = requireHttps; |
| 87 | + return this; |
| 88 | + } |
| 89 | + |
| 90 | + @NotNull |
| 91 | + public Set<Integer> getCrossClusterRetryErrorCodes() |
| 92 | + { |
| 93 | + return crossClusterRetryErrorCodes; |
| 94 | + } |
| 95 | + |
| 96 | + @Config("retry.cross-cluster-error-codes") |
| 97 | + @ConfigDescription("Comma-separated list of error codes that allow cross-cluster retry") |
| 98 | + public RetryConfig setCrossClusterRetryErrorCodes(String errorCodes) |
| 99 | + { |
| 100 | + if (errorCodes == null || errorCodes.trim().isEmpty()) { |
| 101 | + // Keep the default error codes |
| 102 | + return this; |
| 103 | + } |
| 104 | + else { |
| 105 | + this.crossClusterRetryErrorCodes = Splitter.on(',') |
| 106 | + .trimResults() |
| 107 | + .omitEmptyStrings() |
| 108 | + .splitToList(errorCodes) |
| 109 | + .stream() |
| 110 | + .map(StandardErrorCode::valueOf) |
| 111 | + .map(StandardErrorCode::toErrorCode) |
| 112 | + .map(ErrorCode::getCode) |
| 113 | + .collect(toImmutableSet()); |
| 114 | + } |
| 115 | + return this; |
| 116 | + } |
| 117 | +} |
0 commit comments