1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.xds.internal;
18
19 import java.util.concurrent.CompletionStage;
20
21 import com.google.common.base.MoreObjects;
22
23 import com.linecorp.armeria.common.annotation.Nullable;
24 import com.linecorp.armeria.common.util.UnmodifiableFuture;
25 import com.linecorp.centraldogma.server.plugin.AllReplicasPlugin;
26 import com.linecorp.centraldogma.server.plugin.PluginContext;
27 import com.linecorp.centraldogma.server.plugin.PluginInitContext;
28 import com.linecorp.centraldogma.server.plugin.PluginTarget;
29 import com.linecorp.centraldogma.server.storage.project.InternalProjectInitializer;
30
31 public final class ControlPlanePlugin extends AllReplicasPlugin {
32
33 public static final String XDS_CENTRAL_DOGMA_PROJECT = "@xds";
34
35 @Nullable
36 private volatile ControlPlaneService controlPlaneService;
37
38 @Override
39 public void init(PluginInitContext pluginInitContext) {
40 final InternalProjectInitializer projectInitializer = pluginInitContext.internalProjectInitializer();
41 projectInitializer.initialize(XDS_CENTRAL_DOGMA_PROJECT);
42 final ControlPlaneService controlPlaneService = new ControlPlaneService(
43 pluginInitContext.projectManager().get(XDS_CENTRAL_DOGMA_PROJECT),
44 pluginInitContext.meterRegistry());
45 this.controlPlaneService = controlPlaneService;
46 controlPlaneService.start(pluginInitContext);
47 }
48
49 @Override
50 public CompletionStage<Void> start(PluginContext context) {
51 return UnmodifiableFuture.completedFuture(null);
52 }
53
54 @Override
55 public CompletionStage<Void> stop(PluginContext context) {
56 final ControlPlaneService controlPlaneService = this.controlPlaneService;
57 if (controlPlaneService != null) {
58 controlPlaneService.stop();
59 }
60 return UnmodifiableFuture.completedFuture(null);
61 }
62
63 @Override
64 public Class<?> configType() {
65 return ControlPlanePluginConfig.class;
66 }
67
68 @Override
69 public String toString() {
70 return MoreObjects.toStringHelper(this)
71 .add("configType", configType().getName())
72 .add("target", PluginTarget.ALL_REPLICAS)
73 .toString();
74 }
75 }