mirror of https://github.com/grpc/grpc-java.git
core: remove Type from ConfigOrError
This commit is contained in:
parent
a8c73811dd
commit
5ef8377efa
|
|
@ -63,8 +63,7 @@ public abstract class LoadBalancerProvider extends LoadBalancer.Factory {
|
||||||
* @since 1.20.0
|
* @since 1.20.0
|
||||||
* @see https://github.com/grpc/proposal/blob/master/A24-lb-policy-config.md
|
* @see https://github.com/grpc/proposal/blob/master/A24-lb-policy-config.md
|
||||||
*/
|
*/
|
||||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
|
||||||
return ConfigOrError.UNKNOWN_CONFIG;
|
return ConfigOrError.UNKNOWN_CONFIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,7 +316,7 @@ public abstract class NameResolver {
|
||||||
* @return a tuple of the fully parsed and validated channel configuration, else the Status.
|
* @return a tuple of the fully parsed and validated channel configuration, else the Status.
|
||||||
* @since 1.20.0
|
* @since 1.20.0
|
||||||
*/
|
*/
|
||||||
public ConfigOrError<?> parseServiceConfig(Map<String, ?> rawServiceConfig) {
|
public ConfigOrError parseServiceConfig(Map<String, ?> rawServiceConfig) {
|
||||||
throw new UnsupportedOperationException("should have been implemented");
|
throw new UnsupportedOperationException("should have been implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,10 +324,9 @@ public abstract class NameResolver {
|
||||||
* Represents either a successfully parsed service config, containing all necessary parts to be
|
* Represents either a successfully parsed service config, containing all necessary parts to be
|
||||||
* later applied by the channel, or a Status containing the error encountered while parsing.
|
* later applied by the channel, or a Status containing the error encountered while parsing.
|
||||||
*
|
*
|
||||||
* @param <T> The message type of the config.
|
|
||||||
* @since 1.20.0
|
* @since 1.20.0
|
||||||
*/
|
*/
|
||||||
public static final class ConfigOrError<T> {
|
public static final class ConfigOrError {
|
||||||
|
|
||||||
private static final class UnknownConfig {
|
private static final class UnknownConfig {
|
||||||
|
|
||||||
|
|
@ -344,14 +343,14 @@ public abstract class NameResolver {
|
||||||
* indicate that parsing of the service config is neither right nor wrong, but doesn't have
|
* indicate that parsing of the service config is neither right nor wrong, but doesn't have
|
||||||
* any meaning.
|
* any meaning.
|
||||||
*/
|
*/
|
||||||
public static final ConfigOrError<?> UNKNOWN_CONFIG =
|
public static final ConfigOrError UNKNOWN_CONFIG =
|
||||||
ConfigOrError.fromConfig(new UnknownConfig());
|
ConfigOrError.fromConfig(new UnknownConfig());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ConfigOrError} for the successfully parsed config.
|
* Returns a {@link ConfigOrError} for the successfully parsed config.
|
||||||
*/
|
*/
|
||||||
public static <T> ConfigOrError<T> fromConfig(T config) {
|
public static ConfigOrError fromConfig(Object config) {
|
||||||
return new ConfigOrError<>(config);
|
return new ConfigOrError(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -359,14 +358,14 @@ public abstract class NameResolver {
|
||||||
*
|
*
|
||||||
* @param status a non-OK status
|
* @param status a non-OK status
|
||||||
*/
|
*/
|
||||||
public static <T> ConfigOrError<T> fromError(Status status) {
|
public static ConfigOrError fromError(Status status) {
|
||||||
return new ConfigOrError<>(status);
|
return new ConfigOrError(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Status status;
|
private final Status status;
|
||||||
private final T config;
|
private final Object config;
|
||||||
|
|
||||||
private ConfigOrError(T config) {
|
private ConfigOrError(Object config) {
|
||||||
this.config = checkNotNull(config, "config");
|
this.config = checkNotNull(config, "config");
|
||||||
this.status = null;
|
this.status = null;
|
||||||
}
|
}
|
||||||
|
|
@ -381,7 +380,7 @@ public abstract class NameResolver {
|
||||||
* Returns config if exists, otherwise null.
|
* Returns config if exists, otherwise null.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public T getConfig() {
|
public Object getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ public final class AutoConfiguredLoadBalancerFactory extends LoadBalancer.Factor
|
||||||
* @return null if no selection could be made.
|
* @return null if no selection could be made.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
ConfigOrError<PolicySelection> selectLoadBalancerPolicy(Map<String, ?> serviceConfig) {
|
ConfigOrError selectLoadBalancerPolicy(Map<String, ?> serviceConfig) {
|
||||||
try {
|
try {
|
||||||
List<LbConfig> loadBalancerConfigs = null;
|
List<LbConfig> loadBalancerConfigs = null;
|
||||||
if (serviceConfig != null) {
|
if (serviceConfig != null) {
|
||||||
|
|
|
||||||
|
|
@ -292,14 +292,16 @@ final class DnsNameResolver extends NameResolver {
|
||||||
|
|
||||||
Attributes.Builder attrs = Attributes.newBuilder();
|
Attributes.Builder attrs = Attributes.newBuilder();
|
||||||
if (!resolutionResults.txtRecords.isEmpty()) {
|
if (!resolutionResults.txtRecords.isEmpty()) {
|
||||||
ConfigOrError<Map<String, ?>> serviceConfig =
|
ConfigOrError serviceConfig =
|
||||||
parseServiceConfig(resolutionResults.txtRecords, random, getLocalHostname());
|
parseServiceConfig(resolutionResults.txtRecords, random, getLocalHostname());
|
||||||
if (serviceConfig != null) {
|
if (serviceConfig != null) {
|
||||||
if (serviceConfig.getError() != null) {
|
if (serviceConfig.getError() != null) {
|
||||||
savedObserver.onError(serviceConfig.getError());
|
savedObserver.onError(serviceConfig.getError());
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
attrs.set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig.getConfig());
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, ?> config = (Map<String, ?>) serviceConfig.getConfig();
|
||||||
|
attrs.set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -312,7 +314,7 @@ final class DnsNameResolver extends NameResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
static ConfigOrError<Map<String, ?>> parseServiceConfig(
|
static ConfigOrError parseServiceConfig(
|
||||||
List<String> rawTxtRecords, Random random, String localHostname) {
|
List<String> rawTxtRecords, Random random, String localHostname) {
|
||||||
List<Map<String, ?>> possibleServiceConfigChoices;
|
List<Map<String, ?>> possibleServiceConfigChoices;
|
||||||
try {
|
try {
|
||||||
|
|
@ -337,7 +339,7 @@ final class DnsNameResolver extends NameResolver {
|
||||||
if (possibleServiceConfig == null) {
|
if (possibleServiceConfig == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ConfigOrError.<Map<String, ?>>fromConfig(possibleServiceConfig);
|
return ConfigOrError.fromConfig(possibleServiceConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolve() {
|
private void resolve() {
|
||||||
|
|
|
||||||
|
|
@ -1772,12 +1772,11 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public ConfigOrError<ManagedChannelServiceConfig> parseServiceConfig(
|
public ConfigOrError parseServiceConfig(Map<String, ?> rawServiceConfig) {
|
||||||
Map<String, ?> rawServiceConfig) {
|
|
||||||
try {
|
try {
|
||||||
Object loadBalancingPolicySelection;
|
Object loadBalancingPolicySelection;
|
||||||
if (autoLoadBalancerFactory != null) {
|
if (autoLoadBalancerFactory != null) {
|
||||||
ConfigOrError<?> choiceFromLoadBalancer =
|
ConfigOrError choiceFromLoadBalancer =
|
||||||
autoLoadBalancerFactory.selectLoadBalancerPolicy(rawServiceConfig);
|
autoLoadBalancerFactory.selectLoadBalancerPolicy(rawServiceConfig);
|
||||||
if (choiceFromLoadBalancer == null) {
|
if (choiceFromLoadBalancer == null) {
|
||||||
loadBalancingPolicySelection = null;
|
loadBalancingPolicySelection = null;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||||
return ConfigOrError.fromConfig(NO_CONFIG);
|
return ConfigOrError.fromConfig(NO_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ final class SecretRoundRobinLoadBalancerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||||
return ConfigOrError.fromConfig(NO_CONFIG);
|
return ConfigOrError.fromConfig(NO_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1008,7 +1008,7 @@ public class DnsNameResolverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseServiceConfig_capturesParseError() {
|
public void parseServiceConfig_capturesParseError() {
|
||||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||||
Arrays.asList("grpc_config=bogus"), new Random(), "localhost");
|
Arrays.asList("grpc_config=bogus"), new Random(), "localhost");
|
||||||
|
|
||||||
assertThat(result).isNotNull();
|
assertThat(result).isNotNull();
|
||||||
|
|
@ -1018,7 +1018,7 @@ public class DnsNameResolverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseServiceConfig_capturesChoiceError() {
|
public void parseServiceConfig_capturesChoiceError() {
|
||||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||||
Arrays.asList("grpc_config=[{\"hi\":{}}]"), new Random(), "localhost");
|
Arrays.asList("grpc_config=[{\"hi\":{}}]"), new Random(), "localhost");
|
||||||
|
|
||||||
assertThat(result).isNotNull();
|
assertThat(result).isNotNull();
|
||||||
|
|
@ -1028,7 +1028,7 @@ public class DnsNameResolverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseServiceConfig_noChoiceIsNull() {
|
public void parseServiceConfig_noChoiceIsNull() {
|
||||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||||
Arrays.asList("grpc_config=[]"), new Random(), "localhost");
|
Arrays.asList("grpc_config=[]"), new Random(), "localhost");
|
||||||
|
|
||||||
assertThat(result).isNull();
|
assertThat(result).isNull();
|
||||||
|
|
@ -1036,7 +1036,7 @@ public class DnsNameResolverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseServiceConfig_matches() {
|
public void parseServiceConfig_matches() {
|
||||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||||
Arrays.asList("grpc_config=[{\"serviceConfig\":{}}]"), new Random(), "localhost");
|
Arrays.asList("grpc_config=[{\"serviceConfig\":{}}]"), new Random(), "localhost");
|
||||||
|
|
||||||
assertThat(result).isNotNull();
|
assertThat(result).isNotNull();
|
||||||
|
|
|
||||||
|
|
@ -3423,12 +3423,12 @@ public class ManagedChannelImplTest {
|
||||||
maxHedgedAttemptsLimit,
|
maxHedgedAttemptsLimit,
|
||||||
autoConfiguredLoadBalancerFactory);
|
autoConfiguredLoadBalancerFactory);
|
||||||
|
|
||||||
ConfigOrError<ManagedChannelServiceConfig> coe =
|
ConfigOrError coe = nrh.parseServiceConfig(ImmutableMap.<String, Object>of());
|
||||||
nrh.parseServiceConfig(ImmutableMap.<String, Object>of());
|
|
||||||
|
|
||||||
assertThat(coe.getError()).isNull();
|
assertThat(coe.getError()).isNull();
|
||||||
assertThat(coe.getConfig().getServiceMap()).isEmpty();
|
ManagedChannelServiceConfig cfg = (ManagedChannelServiceConfig) coe.getConfig();
|
||||||
assertThat(coe.getConfig().getServiceMethodMap()).isEmpty();
|
assertThat(cfg.getServiceMap()).isEmpty();
|
||||||
|
assertThat(cfg.getServiceMethodMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -3451,7 +3451,7 @@ public class ManagedChannelImplTest {
|
||||||
maxHedgedAttemptsLimit,
|
maxHedgedAttemptsLimit,
|
||||||
autoConfiguredLoadBalancerFactory);
|
autoConfiguredLoadBalancerFactory);
|
||||||
|
|
||||||
ConfigOrError<ManagedChannelServiceConfig> coe =
|
ConfigOrError coe =
|
||||||
nrh.parseServiceConfig(ImmutableMap.<String, Object>of("methodConfig", "bogus"));
|
nrh.parseServiceConfig(ImmutableMap.<String, Object>of("methodConfig", "bogus"));
|
||||||
|
|
||||||
assertThat(coe.getError()).isNotNull();
|
assertThat(coe.getError()).isNotNull();
|
||||||
|
|
@ -3481,11 +3481,12 @@ public class ManagedChannelImplTest {
|
||||||
maxHedgedAttemptsLimit,
|
maxHedgedAttemptsLimit,
|
||||||
autoConfiguredLoadBalancerFactory);
|
autoConfiguredLoadBalancerFactory);
|
||||||
|
|
||||||
ConfigOrError<ManagedChannelServiceConfig> coe =
|
ConfigOrError coe =
|
||||||
nrh.parseServiceConfig(ImmutableMap.of("loadBalancingConfig", ImmutableList.of()));
|
nrh.parseServiceConfig(ImmutableMap.of("loadBalancingConfig", ImmutableList.of()));
|
||||||
|
|
||||||
assertThat(coe.getError()).isNull();
|
assertThat(coe.getError()).isNull();
|
||||||
assertThat(coe.getConfig().getLoadBalancingConfig()).isEqualTo(null);
|
ManagedChannelServiceConfig cfg = (ManagedChannelServiceConfig) coe.getConfig();
|
||||||
|
assertThat(cfg.getLoadBalancingConfig()).isEqualTo(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public final class GrpclbLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||||
Map<String, ?> rawLoadBalancingConfigPolicy) {
|
Map<String, ?> rawLoadBalancingConfigPolicy) {
|
||||||
try {
|
try {
|
||||||
return parseLoadBalancingConfigPolicyInternal(rawLoadBalancingConfigPolicy);
|
return parseLoadBalancingConfigPolicyInternal(rawLoadBalancingConfigPolicy);
|
||||||
|
|
@ -74,7 +74,7 @@ public final class GrpclbLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigOrError<Mode> parseLoadBalancingConfigPolicyInternal(
|
ConfigOrError parseLoadBalancingConfigPolicyInternal(
|
||||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||||
if (rawLoadBalancingPolicyConfig == null) {
|
if (rawLoadBalancingPolicyConfig == null) {
|
||||||
return ConfigOrError.fromConfig(DEFAULT_MODE);
|
return ConfigOrError.fromConfig(DEFAULT_MODE);
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ public final class HealthCheckingRoundRobinLoadBalancerProvider extends LoadBala
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||||
return rrProvider.parseLoadBalancingPolicyConfig(rawLoadBalancingPolicyConfig);
|
return rrProvider.parseLoadBalancingPolicyConfig(rawLoadBalancingPolicyConfig);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,12 +89,12 @@ final class XdsLoadBalancer extends LoadBalancer {
|
||||||
Map<String, ?> newRawLbConfig = checkNotNull(
|
Map<String, ?> newRawLbConfig = checkNotNull(
|
||||||
attributes.get(ATTR_LOAD_BALANCING_CONFIG), "ATTR_LOAD_BALANCING_CONFIG not available");
|
attributes.get(ATTR_LOAD_BALANCING_CONFIG), "ATTR_LOAD_BALANCING_CONFIG not available");
|
||||||
|
|
||||||
ConfigOrError<XdsConfig> cfg =
|
ConfigOrError cfg =
|
||||||
XdsLoadBalancerProvider.parseLoadBalancingConfigPolicy(newRawLbConfig, lbRegistry);
|
XdsLoadBalancerProvider.parseLoadBalancingConfigPolicy(newRawLbConfig, lbRegistry);
|
||||||
if (cfg.getError() != null) {
|
if (cfg.getError() != null) {
|
||||||
throw cfg.getError().asRuntimeException();
|
throw cfg.getError().asRuntimeException();
|
||||||
}
|
}
|
||||||
XdsConfig xdsConfig = cfg.getConfig();
|
XdsConfig xdsConfig = (XdsConfig) cfg.getConfig();
|
||||||
fallbackPolicy = xdsConfig.fallbackPolicy;
|
fallbackPolicy = xdsConfig.fallbackPolicy;
|
||||||
fallbackManager.updateFallbackServers(servers, attributes, fallbackPolicy);
|
fallbackManager.updateFallbackServers(servers, attributes, fallbackPolicy);
|
||||||
fallbackManager.maybeStartFallbackTimer();
|
fallbackManager.maybeStartFallbackTimer();
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,12 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||||
return parseLoadBalancingConfigPolicy(rawLoadBalancingPolicyConfig, registry);
|
return parseLoadBalancingConfigPolicy(rawLoadBalancingPolicyConfig, registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConfigOrError<XdsConfig> parseLoadBalancingConfigPolicy(
|
static ConfigOrError parseLoadBalancingConfigPolicy(
|
||||||
Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry registry) {
|
Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry registry) {
|
||||||
try {
|
try {
|
||||||
LbConfig newLbConfig =
|
LbConfig newLbConfig =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue