-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to configure server for a plugin #883
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3f65223
Add ArmeriaServerConfigurator for configuring server via SPI
minwoox 7f059b1
Add copyright
minwoox ebac6bf
Use plugin
minwoox 2de7383
add
minwoox 35853b1
Fix
minwoox 8bfe74d
Address the comment from @jrhee17
minwoox 1aef397
Merge branch 'main' into server_configurator
minwoox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
it/server/src/test/java/com/linecorp/centraldogma/it/AllReplicasPluginTest.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,39 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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: | ||
* | ||
* https://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 com.linecorp.centraldogma.it; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.linecorp.armeria.common.AggregatedHttpResponse; | ||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.centraldogma.testing.junit.CentralDogmaExtension; | ||
|
||
final class AllReplicasPluginTest { | ||
|
||
@RegisterExtension | ||
static final CentralDogmaExtension dogma = new CentralDogmaExtension(); | ||
|
||
@Test | ||
void hello() { | ||
// hello service is registered by TestAllReplicasPlugin. | ||
final AggregatedHttpResponse res = dogma.httpClient().get("/hello").aggregate().join(); | ||
assertThat(res.status()).isSameAs(HttpStatus.OK); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
it/server/src/test/java/com/linecorp/centraldogma/it/TestAllReplicasPlugin.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,44 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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: | ||
* | ||
* https://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 com.linecorp.centraldogma.it; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import com.linecorp.armeria.common.HttpResponse; | ||
import com.linecorp.armeria.common.util.UnmodifiableFuture; | ||
import com.linecorp.centraldogma.server.plugin.AllReplicasPlugin; | ||
import com.linecorp.centraldogma.server.plugin.PluginContext; | ||
import com.linecorp.centraldogma.server.plugin.PluginInitContext; | ||
|
||
public final class TestAllReplicasPlugin extends AllReplicasPlugin { | ||
|
||
@Override | ||
public void init(PluginInitContext pluginInitContext) { | ||
pluginInitContext.serverBuilder() | ||
.service("/hello", (ctx, req) -> HttpResponse.of("Hello, world!")); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Void> start(PluginContext context) { | ||
return UnmodifiableFuture.completedFuture(null); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Void> stop(PluginContext context) { | ||
return UnmodifiableFuture.completedFuture(null); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...erver/src/test/resources/META-INF/services/com.linecorp.centraldogma.server.plugin.Plugin
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 @@ | ||
com.linecorp.centraldogma.it.TestAllReplicasPlugin |
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
32 changes: 32 additions & 0 deletions
32
server/src/main/java/com/linecorp/centraldogma/server/plugin/AllReplicasPlugin.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,32 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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: | ||
* | ||
* https://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 com.linecorp.centraldogma.server.plugin; | ||
|
||
/** | ||
* A Base class for {@link Plugin} whose {@link #target()} is {@link PluginTarget#ALL_REPLICAS}. | ||
*/ | ||
public abstract class AllReplicasPlugin implements Plugin { | ||
|
||
/** | ||
* Overrides this method to initialize the plugin using the {@link PluginInitContext}. | ||
*/ | ||
public void init(PluginInitContext pluginInitContext) {} | ||
|
||
@Override | ||
public final PluginTarget target() { | ||
return PluginTarget.ALL_REPLICAS; | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
server/src/main/java/com/linecorp/centraldogma/server/plugin/PluginInitContext.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,53 @@ | ||||||
/* | ||||||
* Copyright 2023 LINE Corporation | ||||||
* | ||||||
* LINE Corporation licenses this file to you 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: | ||||||
* | ||||||
* https://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 com.linecorp.centraldogma.server.plugin; | ||||||
|
||||||
import static java.util.Objects.requireNonNull; | ||||||
|
||||||
import com.linecorp.armeria.server.ServerBuilder; | ||||||
import com.linecorp.centraldogma.server.CentralDogmaConfig; | ||||||
|
||||||
/** | ||||||
* A context that is used to pass when calling {@link AllReplicasPlugin#init(PluginInitContext)}. | ||||||
*/ | ||||||
public final class PluginInitContext { | ||||||
|
||||||
private final CentralDogmaConfig config; | ||||||
private final ServerBuilder serverBuilder; | ||||||
|
||||||
/** | ||||||
* Creates a new instance. | ||||||
*/ | ||||||
public PluginInitContext(CentralDogmaConfig config, ServerBuilder serverBuilder) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I cannot remove the public modifier because the class is in a different package. |
||||||
this.config = requireNonNull(config, "config"); | ||||||
this.serverBuilder = requireNonNull(serverBuilder, "serverBuilder"); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Returns the {@link CentralDogmaConfig}. | ||||||
*/ | ||||||
public CentralDogmaConfig config() { | ||||||
return config; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Returns the {@link ServerBuilder} of the Central Dogma server. | ||||||
*/ | ||||||
public ServerBuilder serverBuilder() { | ||||||
return serverBuilder; | ||||||
} | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question) I was thinking we would need at least
ProjectManager
,CommandExecutor
will be needed to build services which can write toCentralDogma
storage. Is there no need for these values? (it looks like they are available at init time).I actually expect we may also want access to
MeterRegistry
, and actually all values inPluginContext
eventually.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I thought somehow they are not created when the init method is called. 😅
Let me fix that. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. PTAL. 😉