Skip to content
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

Allow specifiying dependencies for output invokes #1482

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Pulumi.*.yaml
# VSCode creates this binary when running tests in the debugger
**/debug.test

# LSP
**/.classpath
**/.project
**/.settings

# Go tests run "in tree" and this folder will linger if they fail (the integration test framework cleans
# it up when they pass.)
**/command-output/
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Improvements

- Allow specifiying dependencies for output invokes

- Update to Pulumi 3.139.0

- Implement `GenerateProgram` and `GenerateProject` RPC endpoints for Java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.annotation.Nullable;
import com.pulumi.core.internal.Environment;
import com.pulumi.deployment.InvokeOptions;
import com.pulumi.deployment.InvokeOutputOptions;

public class Utilities {

Expand Down Expand Up @@ -57,16 +58,28 @@ public static Optional<java.lang.Double> getEnvDouble(java.lang.String... names)
return Optional.empty();
}

public static InvokeOptions withVersion(@Nullable InvokeOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion()
);
public static InvokeOptions withVersion(@Nullable InvokeOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion()
);
}

public static InvokeOutputOptions invokeOutputOptionsWithVersion(@Nullable InvokeOutputOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOutputOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion(),
options == null ? null : options.getDependsOn()
);
}

private static final java.lang.String version;
public static java.lang.String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.annotation.Nullable;
import com.pulumi.core.internal.Environment;
import com.pulumi.deployment.InvokeOptions;
import com.pulumi.deployment.InvokeOutputOptions;

public class Utilities {

Expand Down Expand Up @@ -57,16 +58,28 @@ public static Optional<java.lang.Double> getEnvDouble(java.lang.String... names)
return Optional.empty();
}

public static InvokeOptions withVersion(@Nullable InvokeOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion()
);
public static InvokeOptions withVersion(@Nullable InvokeOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion()
);
}

public static InvokeOutputOptions invokeOutputOptionsWithVersion(@Nullable InvokeOutputOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOutputOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion(),
options == null ? null : options.getDependsOn()
);
}

private static final java.lang.String version;
public static java.lang.String getVersion() {
Expand Down
18 changes: 17 additions & 1 deletion pkg/codegen/java/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ func (mod *modContext) genFunctions(ctx *classFileContext, addClass addClassMeth
plainMethodName, invokeOptions)
fprintf(w, " }\n")

// Output version: add full invoke
// Output version: add full invoke with InvokeOptions
printCommentFunction(ctx, fun, indent)
fprintf(w, " public static %s<%s> %s(%s args, %s options) {\n",
ctx.ref(names.Output), returnType, methodName, argsType, invokeOptions)
Expand All @@ -1412,6 +1412,22 @@ func (mod *modContext) genFunctions(ctx *classFileContext, addClass addClassMeth
fprintf(w, ");\n")
fprintf(w, " }\n")

// Output version: add full invoke with InvokeOutputOptions
invokeOutputOptions := ctx.ref(names.InvokeOutputOptions)
printCommentFunction(ctx, fun, indent)
fprintf(w, " public static %s<%s> %s(%s args, %s options) {\n",
ctx.ref(names.Output), returnType, methodName, argsType, invokeOutputOptions)
fprintf(w,
" return %s.getInstance().invoke(\"%s\", %s.of(%s.class), args, %s.invokeOutputOptionsWithVersion(options)",
ctx.ref(names.Deployment), fun.Token, ctx.ref(names.TypeShape), returnType, mod.utilitiesRef(ctx))

if pkg.Parameterization != nil {
fprintf(w, ", %s.getPackageRef()", mod.utilitiesRef(ctx))
}

fprintf(w, ");\n")
fprintf(w, " }\n")

// CompletableFuture version: add full invoke
// notice how the implementation now uses `invokeAsync` instead of `invoke`
printCommentFunction(ctx, fun, indent)
Expand Down
2 changes: 2 additions & 0 deletions pkg/codegen/java/names/known.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ var Deployment = PulumiDeployment.Dot("Deployment")

var InvokeOptions = PulumiDeployment.Dot("InvokeOptions")

var InvokeOutputOptions = PulumiDeployment.Dot("InvokeOutputOptions")

var CompletableFuture = JavaUtil.Dot("concurrent").Dot("CompletableFuture")

var TypeShape = PulumiCore.Dot("TypeShape")
Expand Down
31 changes: 22 additions & 9 deletions pkg/codegen/java/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import java.util.stream.Collectors;
import javax.annotation.Nullable;
import com.pulumi.core.internal.Environment;
import com.pulumi.deployment.InvokeOptions;
import com.pulumi.deployment.InvokeOutputOptions;
{{ .AdditionalImports }}
public class {{ .ClassName }} {

Expand Down Expand Up @@ -77,16 +78,28 @@ public class {{ .ClassName }} {
return Optional.empty();
}
` + /* TODO: InvokeOptions probably should be done via a mutator on the InvokeOptions */ `
public static InvokeOptions withVersion(@Nullable InvokeOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion()
);
public static InvokeOptions withVersion(@Nullable InvokeOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion()
);
}

public static InvokeOutputOptions invokeOutputOptionsWithVersion(@Nullable InvokeOutputOptions options) {
if (options != null && options.getVersion().isPresent()) {
return options;
}
return new InvokeOutputOptions(
options == null ? null : options.getParent().orElse(null),
options == null ? null : options.getProvider().orElse(null),
getVersion(),
options == null ? null : options.getDependsOn()
);
}

private static final java.lang.String version;
public static java.lang.String getVersion() {
Expand Down
Loading
Loading