This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
forked from envoyproxy/java-control-plane
/
TestMain.java
73 lines (58 loc) · 2.37 KB
/
TestMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package io.envoyproxy.controlplane.server;
import com.google.common.collect.ImmutableList;
import io.envoyproxy.controlplane.cache.TestResources;
import io.envoyproxy.controlplane.cache.v3.SimpleCache;
import io.envoyproxy.controlplane.cache.v3.Snapshot;
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.netty.NettyServerBuilder;
import java.io.IOException;
public class TestMain {
private static final String GROUP = "key";
/**
* Example minimal xDS implementation using the java-control-plane lib. This example configures a
* DiscoveryServer with a v3 cache, and handles only v3 requests from data planes.
*
* @param arg command-line args
*/
public static void main(String[] arg) throws IOException, InterruptedException {
SimpleCache<String> cache = new SimpleCache<>(node -> GROUP);
cache.setSnapshot(
GROUP,
Snapshot.create(
ImmutableList.of(
TestResources.createCluster(
"cluster0", "127.0.0.1", 1234, Cluster.DiscoveryType.STATIC)),
ImmutableList.of(),
ImmutableList.of(),
ImmutableList.of(),
ImmutableList.of(),
"1"));
V3DiscoveryServer v3DiscoveryServer = new V3DiscoveryServer(cache);
ServerBuilder builder =
NettyServerBuilder.forPort(12345)
.addService(v3DiscoveryServer.getAggregatedDiscoveryServiceImpl())
.addService(v3DiscoveryServer.getClusterDiscoveryServiceImpl())
.addService(v3DiscoveryServer.getEndpointDiscoveryServiceImpl())
.addService(v3DiscoveryServer.getListenerDiscoveryServiceImpl())
.addService(v3DiscoveryServer.getRouteDiscoveryServiceImpl());
Server server = builder.build();
server.start();
System.out.println("Server has started on port " + server.getPort());
Runtime.getRuntime().addShutdownHook(new Thread(server::shutdown));
Thread.sleep(10000);
cache.setSnapshot(
GROUP,
Snapshot.create(
ImmutableList.of(
TestResources.createCluster(
"cluster1", "127.0.0.1", 1235, Cluster.DiscoveryType.STATIC)),
ImmutableList.of(),
ImmutableList.of(),
ImmutableList.of(),
ImmutableList.of(),
"1"));
server.awaitTermination();
}
}