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
|
||||
* @see https://github.com/grpc/proposal/blob/master/A24-lb-policy-config.md
|
||||
*/
|
||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||
public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||
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.
|
||||
* @since 1.20.0
|
||||
*/
|
||||
public ConfigOrError<?> parseServiceConfig(Map<String, ?> rawServiceConfig) {
|
||||
public ConfigOrError parseServiceConfig(Map<String, ?> rawServiceConfig) {
|
||||
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
|
||||
* 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
|
||||
*/
|
||||
public static final class ConfigOrError<T> {
|
||||
public static final class ConfigOrError {
|
||||
|
||||
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
|
||||
* any meaning.
|
||||
*/
|
||||
public static final ConfigOrError<?> UNKNOWN_CONFIG =
|
||||
public static final ConfigOrError UNKNOWN_CONFIG =
|
||||
ConfigOrError.fromConfig(new UnknownConfig());
|
||||
|
||||
/**
|
||||
* Returns a {@link ConfigOrError} for the successfully parsed config.
|
||||
*/
|
||||
public static <T> ConfigOrError<T> fromConfig(T config) {
|
||||
return new ConfigOrError<>(config);
|
||||
public static ConfigOrError fromConfig(Object config) {
|
||||
return new ConfigOrError(config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -359,14 +358,14 @@ public abstract class NameResolver {
|
|||
*
|
||||
* @param status a non-OK status
|
||||
*/
|
||||
public static <T> ConfigOrError<T> fromError(Status status) {
|
||||
return new ConfigOrError<>(status);
|
||||
public static ConfigOrError fromError(Status status) {
|
||||
return new ConfigOrError(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.status = null;
|
||||
}
|
||||
|
|
@ -381,7 +380,7 @@ public abstract class NameResolver {
|
|||
* Returns config if exists, otherwise null.
|
||||
*/
|
||||
@Nullable
|
||||
public T getConfig() {
|
||||
public Object getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ public final class AutoConfiguredLoadBalancerFactory extends LoadBalancer.Factor
|
|||
* @return null if no selection could be made.
|
||||
*/
|
||||
@Nullable
|
||||
ConfigOrError<PolicySelection> selectLoadBalancerPolicy(Map<String, ?> serviceConfig) {
|
||||
ConfigOrError selectLoadBalancerPolicy(Map<String, ?> serviceConfig) {
|
||||
try {
|
||||
List<LbConfig> loadBalancerConfigs = null;
|
||||
if (serviceConfig != null) {
|
||||
|
|
|
|||
|
|
@ -292,14 +292,16 @@ final class DnsNameResolver extends NameResolver {
|
|||
|
||||
Attributes.Builder attrs = Attributes.newBuilder();
|
||||
if (!resolutionResults.txtRecords.isEmpty()) {
|
||||
ConfigOrError<Map<String, ?>> serviceConfig =
|
||||
ConfigOrError serviceConfig =
|
||||
parseServiceConfig(resolutionResults.txtRecords, random, getLocalHostname());
|
||||
if (serviceConfig != null) {
|
||||
if (serviceConfig.getError() != null) {
|
||||
savedObserver.onError(serviceConfig.getError());
|
||||
return;
|
||||
} 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 {
|
||||
|
|
@ -312,7 +314,7 @@ final class DnsNameResolver extends NameResolver {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
static ConfigOrError<Map<String, ?>> parseServiceConfig(
|
||||
static ConfigOrError parseServiceConfig(
|
||||
List<String> rawTxtRecords, Random random, String localHostname) {
|
||||
List<Map<String, ?>> possibleServiceConfigChoices;
|
||||
try {
|
||||
|
|
@ -337,7 +339,7 @@ final class DnsNameResolver extends NameResolver {
|
|||
if (possibleServiceConfig == null) {
|
||||
return null;
|
||||
}
|
||||
return ConfigOrError.<Map<String, ?>>fromConfig(possibleServiceConfig);
|
||||
return ConfigOrError.fromConfig(possibleServiceConfig);
|
||||
}
|
||||
|
||||
private void resolve() {
|
||||
|
|
|
|||
|
|
@ -1772,12 +1772,11 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigOrError<ManagedChannelServiceConfig> parseServiceConfig(
|
||||
Map<String, ?> rawServiceConfig) {
|
||||
public ConfigOrError parseServiceConfig(Map<String, ?> rawServiceConfig) {
|
||||
try {
|
||||
Object loadBalancingPolicySelection;
|
||||
if (autoLoadBalancerFactory != null) {
|
||||
ConfigOrError<?> choiceFromLoadBalancer =
|
||||
ConfigOrError choiceFromLoadBalancer =
|
||||
autoLoadBalancerFactory.selectLoadBalancerPolicy(rawServiceConfig);
|
||||
if (choiceFromLoadBalancer == null) {
|
||||
loadBalancingPolicySelection = null;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
||||
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||
return ConfigOrError.fromConfig(NO_CONFIG);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ final class SecretRoundRobinLoadBalancerProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
||||
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||
return ConfigOrError.fromConfig(NO_CONFIG);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1008,7 +1008,7 @@ public class DnsNameResolverTest {
|
|||
|
||||
@Test
|
||||
public void parseServiceConfig_capturesParseError() {
|
||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
||||
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||
Arrays.asList("grpc_config=bogus"), new Random(), "localhost");
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
|
|
@ -1018,7 +1018,7 @@ public class DnsNameResolverTest {
|
|||
|
||||
@Test
|
||||
public void parseServiceConfig_capturesChoiceError() {
|
||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
||||
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||
Arrays.asList("grpc_config=[{\"hi\":{}}]"), new Random(), "localhost");
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
|
|
@ -1028,7 +1028,7 @@ public class DnsNameResolverTest {
|
|||
|
||||
@Test
|
||||
public void parseServiceConfig_noChoiceIsNull() {
|
||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
||||
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||
Arrays.asList("grpc_config=[]"), new Random(), "localhost");
|
||||
|
||||
assertThat(result).isNull();
|
||||
|
|
@ -1036,7 +1036,7 @@ public class DnsNameResolverTest {
|
|||
|
||||
@Test
|
||||
public void parseServiceConfig_matches() {
|
||||
ConfigOrError<Map<String, ?>> result = DnsNameResolver.parseServiceConfig(
|
||||
ConfigOrError result = DnsNameResolver.parseServiceConfig(
|
||||
Arrays.asList("grpc_config=[{\"serviceConfig\":{}}]"), new Random(), "localhost");
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
|
|
|
|||
|
|
@ -3423,12 +3423,12 @@ public class ManagedChannelImplTest {
|
|||
maxHedgedAttemptsLimit,
|
||||
autoConfiguredLoadBalancerFactory);
|
||||
|
||||
ConfigOrError<ManagedChannelServiceConfig> coe =
|
||||
nrh.parseServiceConfig(ImmutableMap.<String, Object>of());
|
||||
ConfigOrError coe = nrh.parseServiceConfig(ImmutableMap.<String, Object>of());
|
||||
|
||||
assertThat(coe.getError()).isNull();
|
||||
assertThat(coe.getConfig().getServiceMap()).isEmpty();
|
||||
assertThat(coe.getConfig().getServiceMethodMap()).isEmpty();
|
||||
ManagedChannelServiceConfig cfg = (ManagedChannelServiceConfig) coe.getConfig();
|
||||
assertThat(cfg.getServiceMap()).isEmpty();
|
||||
assertThat(cfg.getServiceMethodMap()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -3451,7 +3451,7 @@ public class ManagedChannelImplTest {
|
|||
maxHedgedAttemptsLimit,
|
||||
autoConfiguredLoadBalancerFactory);
|
||||
|
||||
ConfigOrError<ManagedChannelServiceConfig> coe =
|
||||
ConfigOrError coe =
|
||||
nrh.parseServiceConfig(ImmutableMap.<String, Object>of("methodConfig", "bogus"));
|
||||
|
||||
assertThat(coe.getError()).isNotNull();
|
||||
|
|
@ -3481,11 +3481,12 @@ public class ManagedChannelImplTest {
|
|||
maxHedgedAttemptsLimit,
|
||||
autoConfiguredLoadBalancerFactory);
|
||||
|
||||
ConfigOrError<ManagedChannelServiceConfig> coe =
|
||||
ConfigOrError coe =
|
||||
nrh.parseServiceConfig(ImmutableMap.of("loadBalancingConfig", ImmutableList.of()));
|
||||
|
||||
assertThat(coe.getError()).isNull();
|
||||
assertThat(coe.getConfig().getLoadBalancingConfig()).isEqualTo(null);
|
||||
ManagedChannelServiceConfig cfg = (ManagedChannelServiceConfig) coe.getConfig();
|
||||
assertThat(cfg.getLoadBalancingConfig()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public final class GrpclbLoadBalancerProvider extends LoadBalancerProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
||||
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||
Map<String, ?> rawLoadBalancingConfigPolicy) {
|
||||
try {
|
||||
return parseLoadBalancingConfigPolicyInternal(rawLoadBalancingConfigPolicy);
|
||||
|
|
@ -74,7 +74,7 @@ public final class GrpclbLoadBalancerProvider extends LoadBalancerProvider {
|
|||
}
|
||||
}
|
||||
|
||||
ConfigOrError<Mode> parseLoadBalancingConfigPolicyInternal(
|
||||
ConfigOrError parseLoadBalancingConfigPolicyInternal(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||
if (rawLoadBalancingPolicyConfig == null) {
|
||||
return ConfigOrError.fromConfig(DEFAULT_MODE);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public final class HealthCheckingRoundRobinLoadBalancerProvider extends LoadBala
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
||||
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||
return rrProvider.parseLoadBalancingPolicyConfig(rawLoadBalancingPolicyConfig);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,12 +89,12 @@ final class XdsLoadBalancer extends LoadBalancer {
|
|||
Map<String, ?> newRawLbConfig = checkNotNull(
|
||||
attributes.get(ATTR_LOAD_BALANCING_CONFIG), "ATTR_LOAD_BALANCING_CONFIG not available");
|
||||
|
||||
ConfigOrError<XdsConfig> cfg =
|
||||
ConfigOrError cfg =
|
||||
XdsLoadBalancerProvider.parseLoadBalancingConfigPolicy(newRawLbConfig, lbRegistry);
|
||||
if (cfg.getError() != null) {
|
||||
throw cfg.getError().asRuntimeException();
|
||||
}
|
||||
XdsConfig xdsConfig = cfg.getConfig();
|
||||
XdsConfig xdsConfig = (XdsConfig) cfg.getConfig();
|
||||
fallbackPolicy = xdsConfig.fallbackPolicy;
|
||||
fallbackManager.updateFallbackServers(servers, attributes, fallbackPolicy);
|
||||
fallbackManager.maybeStartFallbackTimer();
|
||||
|
|
|
|||
|
|
@ -66,12 +66,12 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConfigOrError<?> parseLoadBalancingPolicyConfig(
|
||||
public ConfigOrError parseLoadBalancingPolicyConfig(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig) {
|
||||
return parseLoadBalancingConfigPolicy(rawLoadBalancingPolicyConfig, registry);
|
||||
}
|
||||
|
||||
static ConfigOrError<XdsConfig> parseLoadBalancingConfigPolicy(
|
||||
static ConfigOrError parseLoadBalancingConfigPolicy(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry registry) {
|
||||
try {
|
||||
LbConfig newLbConfig =
|
||||
|
|
|
|||
Loading…
Reference in New Issue