forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#2 from saicaca/add-eds-resources
feat: add eds resources
- Loading branch information
Showing
5 changed files
with
559 additions
and
249 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...ds/src/main/java/org/apache/dubbo/xds/resource/grpc/AutoValue_Endpoints_DropOverload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.apache.dubbo.xds.resource.grpc; | ||
|
||
import javax.annotation.Generated; | ||
|
||
@Generated("com.google.auto.value.processor.AutoValueProcessor") | ||
final class AutoValue_Endpoints_DropOverload extends Endpoints.DropOverload { | ||
|
||
private final String category; | ||
|
||
private final int dropsPerMillion; | ||
|
||
AutoValue_Endpoints_DropOverload( | ||
String category, | ||
int dropsPerMillion) { | ||
if (category == null) { | ||
throw new NullPointerException("Null category"); | ||
} | ||
this.category = category; | ||
this.dropsPerMillion = dropsPerMillion; | ||
} | ||
|
||
@Override | ||
String category() { | ||
return category; | ||
} | ||
|
||
@Override | ||
int dropsPerMillion() { | ||
return dropsPerMillion; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DropOverload{" | ||
+ "category=" + category + ", " | ||
+ "dropsPerMillion=" + dropsPerMillion | ||
+ "}"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == this) { | ||
return true; | ||
} | ||
if (o instanceof Endpoints.DropOverload) { | ||
Endpoints.DropOverload that = (Endpoints.DropOverload) o; | ||
return this.category.equals(that.category()) | ||
&& this.dropsPerMillion == that.dropsPerMillion(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int h$ = 1; | ||
h$ *= 1000003; | ||
h$ ^= category.hashCode(); | ||
h$ *= 1000003; | ||
h$ ^= dropsPerMillion; | ||
return h$; | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...-xds/src/main/java/org/apache/dubbo/xds/resource/grpc/AutoValue_Endpoints_LbEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.apache.dubbo.xds.resource.grpc; | ||
|
||
import io.grpc.EquivalentAddressGroup; | ||
|
||
import javax.annotation.Generated; | ||
|
||
@Generated("com.google.auto.value.processor.AutoValueProcessor") | ||
final class AutoValue_Endpoints_LbEndpoint extends Endpoints.LbEndpoint { | ||
|
||
private final EquivalentAddressGroup eag; | ||
|
||
private final int loadBalancingWeight; | ||
|
||
private final boolean isHealthy; | ||
|
||
AutoValue_Endpoints_LbEndpoint( | ||
EquivalentAddressGroup eag, | ||
int loadBalancingWeight, | ||
boolean isHealthy) { | ||
if (eag == null) { | ||
throw new NullPointerException("Null eag"); | ||
} | ||
this.eag = eag; | ||
this.loadBalancingWeight = loadBalancingWeight; | ||
this.isHealthy = isHealthy; | ||
} | ||
|
||
@Override | ||
EquivalentAddressGroup eag() { | ||
return eag; | ||
} | ||
|
||
@Override | ||
int loadBalancingWeight() { | ||
return loadBalancingWeight; | ||
} | ||
|
||
@Override | ||
boolean isHealthy() { | ||
return isHealthy; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LbEndpoint{" | ||
+ "eag=" + eag + ", " | ||
+ "loadBalancingWeight=" + loadBalancingWeight + ", " | ||
+ "isHealthy=" + isHealthy | ||
+ "}"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == this) { | ||
return true; | ||
} | ||
if (o instanceof Endpoints.LbEndpoint) { | ||
Endpoints.LbEndpoint that = (Endpoints.LbEndpoint) o; | ||
return this.eag.equals(that.eag()) | ||
&& this.loadBalancingWeight == that.loadBalancingWeight() | ||
&& this.isHealthy == that.isHealthy(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int h$ = 1; | ||
h$ *= 1000003; | ||
h$ ^= eag.hashCode(); | ||
h$ *= 1000003; | ||
h$ ^= loadBalancingWeight; | ||
h$ *= 1000003; | ||
h$ ^= isHealthy ? 1231 : 1237; | ||
return h$; | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...main/java/org/apache/dubbo/xds/resource/grpc/AutoValue_Endpoints_LocalityLbEndpoints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.apache.dubbo.xds.resource.grpc; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import javax.annotation.Generated; | ||
|
||
@Generated("com.google.auto.value.processor.AutoValueProcessor") | ||
final class AutoValue_Endpoints_LocalityLbEndpoints extends Endpoints.LocalityLbEndpoints { | ||
|
||
private final ImmutableList<Endpoints.LbEndpoint> endpoints; | ||
|
||
private final int localityWeight; | ||
|
||
private final int priority; | ||
|
||
AutoValue_Endpoints_LocalityLbEndpoints( | ||
ImmutableList<Endpoints.LbEndpoint> endpoints, | ||
int localityWeight, | ||
int priority) { | ||
if (endpoints == null) { | ||
throw new NullPointerException("Null endpoints"); | ||
} | ||
this.endpoints = endpoints; | ||
this.localityWeight = localityWeight; | ||
this.priority = priority; | ||
} | ||
|
||
@Override | ||
ImmutableList<Endpoints.LbEndpoint> endpoints() { | ||
return endpoints; | ||
} | ||
|
||
@Override | ||
int localityWeight() { | ||
return localityWeight; | ||
} | ||
|
||
@Override | ||
int priority() { | ||
return priority; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LocalityLbEndpoints{" | ||
+ "endpoints=" + endpoints + ", " | ||
+ "localityWeight=" + localityWeight + ", " | ||
+ "priority=" + priority | ||
+ "}"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == this) { | ||
return true; | ||
} | ||
if (o instanceof Endpoints.LocalityLbEndpoints) { | ||
Endpoints.LocalityLbEndpoints that = (Endpoints.LocalityLbEndpoints) o; | ||
return this.endpoints.equals(that.endpoints()) | ||
&& this.localityWeight == that.localityWeight() | ||
&& this.priority == that.priority(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int h$ = 1; | ||
h$ *= 1000003; | ||
h$ ^= endpoints.hashCode(); | ||
h$ *= 1000003; | ||
h$ ^= localityWeight; | ||
h$ *= 1000003; | ||
h$ ^= priority; | ||
return h$; | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
dubbo-xds/src/main/java/org/apache/dubbo/xds/resource/grpc/Endpoints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2021 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.dubbo.xds.resource.grpc; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.List; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
import io.grpc.EquivalentAddressGroup; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
/** Locality and endpoint level load balancing configurations. */ | ||
final class Endpoints { | ||
private Endpoints() {} | ||
|
||
/** Represents a group of endpoints belong to a single locality. */ | ||
@AutoValue | ||
abstract static class LocalityLbEndpoints { | ||
// Endpoints to be load balanced. | ||
abstract ImmutableList<LbEndpoint> endpoints(); | ||
|
||
// Locality's weight for inter-locality load balancing. Guaranteed to be greater than 0. | ||
abstract int localityWeight(); | ||
|
||
// Locality's priority level. | ||
abstract int priority(); | ||
|
||
static LocalityLbEndpoints create(List<LbEndpoint> endpoints, int localityWeight, | ||
int priority) { | ||
checkArgument(localityWeight > 0, "localityWeight must be greater than 0"); | ||
return new AutoValue_Endpoints_LocalityLbEndpoints( | ||
ImmutableList.copyOf(endpoints), localityWeight, priority); | ||
} | ||
} | ||
|
||
/** Represents a single endpoint to be load balanced. */ | ||
@AutoValue | ||
abstract static class LbEndpoint { | ||
// The endpoint address to be connected to. | ||
abstract EquivalentAddressGroup eag(); | ||
|
||
// Endpoint's weight for load balancing. If unspecified, value of 0 is returned. | ||
abstract int loadBalancingWeight(); | ||
|
||
// Whether the endpoint is healthy. | ||
abstract boolean isHealthy(); | ||
|
||
static LbEndpoint create(EquivalentAddressGroup eag, int loadBalancingWeight, | ||
boolean isHealthy) { | ||
return new AutoValue_Endpoints_LbEndpoint(eag, loadBalancingWeight, isHealthy); | ||
} | ||
|
||
// Only for testing. | ||
@VisibleForTesting | ||
static LbEndpoint create( | ||
String address, int port, int loadBalancingWeight, boolean isHealthy) { | ||
return LbEndpoint.create(new EquivalentAddressGroup(new InetSocketAddress(address, port)), | ||
loadBalancingWeight, isHealthy); | ||
} | ||
} | ||
|
||
/** Represents a drop policy. */ | ||
@AutoValue | ||
abstract static class DropOverload { | ||
abstract String category(); | ||
|
||
abstract int dropsPerMillion(); | ||
|
||
static DropOverload create(String category, int dropsPerMillion) { | ||
return new AutoValue_Endpoints_DropOverload(category, dropsPerMillion); | ||
} | ||
} | ||
} |
Oops, something went wrong.