-
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
Implement GetRequiredPackages
for Java
#1535
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ import ( | |
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace" | ||
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/credentials/insecure" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/types/known/structpb" | ||
|
||
codegen "github.com/pulumi/pulumi-java/pkg/codegen/java" | ||
|
@@ -158,49 +160,57 @@ func (host *javaLanguageHost) Executor(attachDebugger bool) (*executors.JavaExec | |
return executor, nil | ||
} | ||
|
||
// GetRequiredPlugins computes the complete set of anticipated plugins required by a program. | ||
func (host *javaLanguageHost) GetRequiredPlugins( | ||
// GetRequiredPackages computes the complete set of anticipated packages required by a program. | ||
func (host *javaLanguageHost) GetRequiredPackages( | ||
ctx context.Context, | ||
req *pulumirpc.GetRequiredPluginsRequest, | ||
) (*pulumirpc.GetRequiredPluginsResponse, error) { | ||
logging.V(5).Infof("GetRequiredPlugins: program=%v", req.GetProgram()) //nolint:staticcheck | ||
req *pulumirpc.GetRequiredPackagesRequest, | ||
) (*pulumirpc.GetRequiredPackagesResponse, error) { | ||
logging.V(5).Infof("GetRequiredPackages: programDirectory=%v", req.Info.ProgramDirectory) | ||
|
||
// now, introspect the user project to see which pulumi resource packages it references. | ||
pulumiPackages, err := host.determinePulumiPackages(ctx, req) | ||
pulumiPackages, err := host.determinePulumiPackages(ctx, req.Info.ProgramDirectory) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "language host could not determine Pulumi packages") | ||
} | ||
|
||
// Now that we know the set of pulumi packages referenced, and we know where packages have been restored to, | ||
// we can examine each package to determine the corresponding resource-plugin for it. | ||
|
||
plugins := []*pulumirpc.PluginDependency{} | ||
pkgs := []*pulumirpc.PackageDependency{} | ||
for _, pulumiPackage := range pulumiPackages { | ||
logging.V(3).Infof( | ||
"GetRequiredPlugins: Determining plugin dependency: %v, %v", | ||
pulumiPackage.Name, pulumiPackage.Version, | ||
) | ||
|
||
// Skip over any packages that don't correspond to Pulumi resource plugins. | ||
if !pulumiPackage.Resource { | ||
continue // the package has no associated resource plugin | ||
continue | ||
} | ||
|
||
plugins = append(plugins, &pulumirpc.PluginDependency{ | ||
pkg := &pulumirpc.PackageDependency{ | ||
Kind: "resource", | ||
Name: pulumiPackage.Name, | ||
Version: pulumiPackage.Version, | ||
Server: pulumiPackage.Server, | ||
Kind: "resource", | ||
}) | ||
} | ||
if pulumiPackage.Parameterization != nil { | ||
pkg.Parameterization = &pulumirpc.PackageParameterization{ | ||
Name: pulumiPackage.Parameterization.Name, | ||
Version: pulumiPackage.Parameterization.Version, | ||
Value: pulumiPackage.Parameterization.Value, | ||
} | ||
} | ||
|
||
pkgs = append(pkgs, pkg) | ||
} | ||
|
||
logging.V(5).Infof("GetRequiredPlugins: plugins=%v", plugins) | ||
logging.V(5).Infof("GetRequiredPackages: packages=%v", pkgs) | ||
return &pulumirpc.GetRequiredPackagesResponse{Packages: pkgs}, nil | ||
} | ||
|
||
return &pulumirpc.GetRequiredPluginsResponse{Plugins: plugins}, nil | ||
// GetRequiredPlugins computes the complete set of anticipated plugins required by a program. | ||
func (host *javaLanguageHost) GetRequiredPlugins( | ||
context.Context, | ||
*pulumirpc.GetRequiredPluginsRequest, | ||
) (*pulumirpc.GetRequiredPluginsResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method GetRequiredPlugins not implemented") | ||
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. I was wondering if we still need to implement this, so it works with an older engine. But language runtime plugins are always bundled, so we know we'll always call GetRequiredPackages first anyway. Good. 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. On both your comments, I've tried to match what was done for Go, NodeJS and Python -- it seems like we did the add/remove simultaneously for them and as you say, this is bundled so I think it's OK? 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. Yeah, I think this is fine, I just stumbled over it, so wanted to double check my thought process :) |
||
} | ||
|
||
func (host *javaLanguageHost) determinePulumiPackages( | ||
ctx context.Context, | ||
req *pulumirpc.GetRequiredPluginsRequest, | ||
programDirectory string, | ||
) ([]plugin.PulumiPluginJSON, error) { | ||
logging.V(3).Infof("GetRequiredPlugins: Determining Pulumi plugins") | ||
|
||
|
@@ -213,7 +223,7 @@ func (host *javaLanguageHost) determinePulumiPackages( | |
cmd := exec.Cmd | ||
args := exec.PluginArgs | ||
quiet := true | ||
output, err := host.runJavaCommand(ctx, req.Info.ProgramDirectory, cmd, args, quiet) | ||
output, err := host.runJavaCommand(ctx, programDirectory, cmd, args, quiet) | ||
if err != nil { | ||
// Plugin determination is an advisory feature so it does not need to escalate to an error. | ||
logging.V(3).Infof("language host could not run plugin discovery command successfully, "+ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: l2-parameterized-resource | ||
runtime: java |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.pulumi</groupId> | ||
<artifactId>l2-parameterized-resource</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<encoding>UTF-8</encoding> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<maven.compiler.release>11</maven.compiler.release> | ||
<mainClass>generated_program.App</mainClass> | ||
<mainArgs/> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>repository-0</id> | ||
<url>REPOSITORY</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.pulumi</groupId> | ||
<artifactId>pulumi</artifactId> | ||
<version>CORE.VERSION</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.pulumi</groupId> | ||
<artifactId>subpackage</artifactId> | ||
<version>2.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.2.2</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<mainClass>${mainClass}</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>3.4.2</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<mainClass>${mainClass}</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-my-jar-with-dependencies</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<configuration> | ||
<mainClass>${mainClass}</mainClass> | ||
<commandlineArgs>${mainArgs}</commandlineArgs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-wrapper-plugin</artifactId> | ||
<version>3.1.1</version> | ||
<configuration> | ||
<mavenVersion>3.8.5</mavenVersion> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package generated_program; | ||
|
||
import com.pulumi.Context; | ||
import com.pulumi.Pulumi; | ||
import com.pulumi.core.Output; | ||
import com.pulumi.subpackage.HelloWorld; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public class App { | ||
public static void main(String[] args) { | ||
Pulumi.run(App::stack); | ||
} | ||
|
||
public static void stack(Context ctx) { | ||
// The resource name is based on the parameter value | ||
var example = new HelloWorld("example"); | ||
|
||
ctx.export("parameterValue", example.parameterValue()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
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.
Was removing this log intentional? It still seems useful to know when GetRequirePackages is called (though we are pretty inconsistent with logging overall)
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 was -- I checked the PR in pulumi/pulumi that added
GetRequiredPackages
for Go, NodeJS and Python, and it seemed like we weren't doing any logging there really for those calls, so I figured I'd remove it. But I can add something back before I merge -- agree it doesn't hurt 👍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.
Ah fair enough. I didn't double check for those. Might be worth adding them there for consistency ;)