-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support RunPlugin for Maven and Gradle plugins #1608
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b06bc30
Support RunPlugin for Maven and Gradle plugins
mikhailshilkov 04f79be
Barebones provider with GetSchema
mikhailshilkov f328017
Integration tests for Maven and Gradle providers
mikhailshilkov adc2d56
Changelog
mikhailshilkov 91dd3d7
Convert Provider to an interface
mikhailshilkov 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
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
### Improvements | ||
|
||
- Default to using Gradle with the Nexus publishing plugin when using `gen-sdk` | ||
- Support RunPlugin for Maven and Gradle plugins | ||
|
||
### Bug Fixes |
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
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
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
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
14 changes: 14 additions & 0 deletions
14
sdk/java/pulumi/src/main/java/com/pulumi/provider/internal/Provider.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,14 @@ | ||
package com.pulumi.provider.internal; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.pulumi.provider.internal.models.*; | ||
|
||
public interface Provider { | ||
/** | ||
* Returns the schema for this provider's package. | ||
* @param request The schema request | ||
* @return A future containing the schema response | ||
*/ | ||
CompletableFuture<GetSchemaResponse> getSchema(GetSchemaRequest request); | ||
} | ||
105 changes: 105 additions & 0 deletions
105
sdk/java/pulumi/src/main/java/com/pulumi/provider/internal/ResourceProviderService.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,105 @@ | ||
package com.pulumi.provider.internal; | ||
|
||
import io.grpc.Server; | ||
import io.grpc.ServerBuilder; | ||
import io.grpc.stub.StreamObserver; | ||
import com.google.protobuf.Empty; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.logging.Logger; | ||
import java.util.function.Function; | ||
|
||
public class ResourceProviderService { | ||
|
||
private static final Logger logger = Logger.getLogger(ResourceProviderService.class.getName()); | ||
|
||
private Server server; | ||
private final Provider implementation; | ||
|
||
public ResourceProviderService(Provider implementation) { | ||
this.implementation = implementation; | ||
} | ||
|
||
public void startAndBlockUntilShutdown() throws IOException, InterruptedException { | ||
start(); | ||
blockUntilShutdown(); | ||
} | ||
|
||
private void start() throws IOException { | ||
server = ServerBuilder.forPort(0) // Use port 0 to let system assign a free port | ||
.addService(new ResourceProviderImpl(this.implementation)) | ||
.build() | ||
.start(); | ||
|
||
// Print the actual bound port for the parent process to read | ||
System.out.println(server.getPort()); | ||
|
||
Runtime.getRuntime().addShutdownHook(new Thread() { | ||
@Override | ||
public void run() { | ||
try { | ||
ResourceProviderService.this.stop(); | ||
} catch (InterruptedException e) { | ||
logger.severe(e.toString()); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void stop() throws InterruptedException { | ||
if (server != null) { | ||
server.shutdown().awaitTermination(30, TimeUnit.SECONDS); | ||
} | ||
} | ||
|
||
private void blockUntilShutdown() throws InterruptedException { | ||
if (server != null) { | ||
server.awaitTermination(); | ||
} | ||
} | ||
|
||
static class ResourceProviderImpl extends pulumirpc.ResourceProviderGrpc.ResourceProviderImplBase { | ||
private final Provider implementation; | ||
|
||
public ResourceProviderImpl(Provider implementation) { | ||
this.implementation = implementation; | ||
} | ||
|
||
@Override | ||
public void getPluginInfo(Empty request, StreamObserver<pulumirpc.Plugin.PluginInfo> responseObserver) { | ||
// Return basic plugin information | ||
pulumirpc.Plugin.PluginInfo info = pulumirpc.Plugin.PluginInfo.newBuilder() | ||
.setVersion("1.0.0") | ||
.build(); | ||
|
||
responseObserver.onNext(info); | ||
responseObserver.onCompleted(); | ||
} | ||
|
||
@Override | ||
public void getSchema(pulumirpc.Provider.GetSchemaRequest request, StreamObserver<pulumirpc.Provider.GetSchemaResponse> responseObserver) { | ||
// protobuf sends an empty string for subpackageName/subpackageVersion, but really | ||
// that means null in the domain model. | ||
Function<String, String> nullIfEmpty = s -> { | ||
if (s == null || s.equals("")) { | ||
return null; | ||
} | ||
return s; | ||
}; | ||
|
||
var domRequest = new com.pulumi.provider.internal.models.GetSchemaRequest( | ||
request.getVersion(), | ||
nullIfEmpty.apply(request.getSubpackageName()), | ||
nullIfEmpty.apply(request.getSubpackageVersion()) | ||
); | ||
|
||
this.implementation.getSchema(domRequest).thenAccept(domResponse -> { | ||
var grpcResponse = pulumirpc.Provider.GetSchemaResponse.newBuilder() | ||
.setSchema(domResponse.getSchema()) | ||
.build(); | ||
responseObserver.onNext(grpcResponse); | ||
responseObserver.onCompleted(); | ||
}); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
sdk/java/pulumi/src/main/java/com/pulumi/provider/internal/models/GetSchemaRequest.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,25 @@ | ||
package com.pulumi.provider.internal.models; | ||
|
||
public class GetSchemaRequest { | ||
private final int version; | ||
private final String subpackageName; | ||
private final String subpackageVersion; | ||
|
||
public GetSchemaRequest(int version, String subpackageName, String subpackageVersion) { | ||
this.version = version; | ||
this.subpackageName = subpackageName; | ||
this.subpackageVersion = subpackageVersion; | ||
} | ||
|
||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
public String getSubpackageName() { | ||
return subpackageName; | ||
} | ||
|
||
public String getSubpackageVersion() { | ||
return subpackageVersion; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
sdk/java/pulumi/src/main/java/com/pulumi/provider/internal/models/GetSchemaResponse.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,13 @@ | ||
package com.pulumi.provider.internal.models; | ||
|
||
public class GetSchemaResponse { | ||
private final String schema; | ||
|
||
public GetSchemaResponse(String schema) { | ||
this.schema = schema; | ||
} | ||
|
||
public String getSchema() { | ||
return schema; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Part of me thinks we should prefer interfaces with default implementations to abstract classes, but I don't know if there are important reasons to/to not to, so happy either way. I think
Provider
was an interface in TS and we found that a bit problematic at times, but TS interfaces don't support default implementations, so maybe that was it. Not sure.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.
It's all internal for now in any case.
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.
At the point of this PR, interface sounds like a great idea. I converted it for now, let's see how we want it to evolve later. It's all internal for now, indeed.