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

Automation API Proof of Concept [DO NOT MEERGE] #1180

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/java/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Ignore Gradle build output directory
build
.gradle
/pulumi/.pulumi/
/pulumi/Pulumi.json
2 changes: 1 addition & 1 deletion sdk/java/pulumi/src/main/java/com/pulumi/Pulumi.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static CompletableFuture<Integer> runAsync(Consumer<Context> stack) {
* @see #runAsync(Consumer)
*/
static Pulumi.API withOptions(StackOptions options) {
return PulumiInternal.fromEnvironment(options);
return PulumiInternal.APIInternal.fromEnvironment(options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.pulumi.automation;

public class GlobalOptions {

protected Color color;
protected boolean logFlow;
protected int logVerbosity;
protected boolean logToStdErr;
protected String tracing;
protected boolean debug;
protected boolean json;

protected GlobalOptions() { /* empty */ }

/**
* Colorize output
*
* @return output colorization option
*/
public Color color() {
return color;
}

/**
* Flow log settings to child processes (like plugins)
*
* @return whether the flow log setting is active
*/
public boolean logFlow() {
return logFlow;
}

/**
* Enable verbose logging (e.g., v=3); anything greater than 3 is very verbose
*
* @return the verbosity level
*/
public int logVerbosity() {
return logVerbosity;
}

/**
* Log to stderr instead of to files
*
* @return whether the logging to stderr is active
*/
public boolean logToStdErr() {
return logToStdErr;
}

/**
* Emit tracing to the specified endpoint. Use the file: scheme to write tracing data to a local file
*
* @return the tracing endpoint
*/
public String tracing() {
return tracing;
}

/**
* Print detailed debugging output during resource operations
*
* @return whether debugging output is active
*/
public boolean debug() {
return debug;
}

/**
* Format standard output as JSON not text.
*
* @return whether JSON output is active
*/
public boolean json() {
return json;
}

/**
* Colorization options
*/
public enum Color {
Always,
Never,
Raw,
Auto
}

protected static abstract class Builder<T extends GlobalOptions, B extends GlobalOptions.Builder<T, B>> {

protected final T options;

protected Builder(T options) {
this.options = options;
}

public B color(Color color) {
this.options.color = color;
//noinspection unchecked
return (B) this;
}

public B logFlow(boolean logFlow) {
this.options.logFlow = logFlow;
//noinspection unchecked
return (B) this;
}

public B logVerbosity(int logVerbosity) {
this.options.logVerbosity = logVerbosity;
//noinspection unchecked
return (B) this;
}

public B logToStdErr(boolean logToStdErr) {
this.options.logToStdErr = logToStdErr;
//noinspection unchecked
return (B) this;
}

public B tracing(String tracing) {
this.options.tracing = tracing;
//noinspection unchecked
return (B) this;
}

public B debug(boolean debug) {
this.options.debug = debug;
//noinspection unchecked
return (B) this;
}

/**
* @see GlobalOptions#json()
* @param json if true JSON output is active
* @return the {@link Builder} instance
*/
public B json(boolean json) {
this.options.json = json;
//noinspection unchecked
return (B) this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.pulumi.automation;

import com.google.common.collect.ImmutableMap;
import com.pulumi.Context;

import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.logging.Logger;

import static java.util.Objects.requireNonNull;

/**
* LocalWorkspace is a default implementation of the {@link Workspace} interface.
* <p>
* LocalWorkspace relies on {@code Pulumi.yaml} and {@code Pulumi.<stack>.yaml}
* as the intermediate format for Project and Stack settings.
* Modifying ProjectSettings will alter the Workspace {@code Pulumi.yaml} file,
* and setting config on a Stack will modify the {@code Pulumi.<stack>.yaml} file.
* This is identical to the behavior of Pulumi CLI driven workspaces.
* <p>
* If not provided a working directory, causing LocalWorkspace to create a temp directory,
* the temp directory will be cleaned up.
*/
public class LocalWorkspace implements Workspace {

private final Logger logger;
private final ProjectSettings settings;
private final ImmutableMap<String, String> environmentVariables;
private final LocalWorkspaceOptions options;

public LocalWorkspace(
Logger logger,
ProjectSettings settings,
Map<String, String> environmentVariables,
LocalWorkspaceOptions options
) {
this.logger = requireNonNull(logger);
this.settings = requireNonNull(settings);
this.environmentVariables = ImmutableMap.copyOf(environmentVariables);
this.options = requireNonNull(options);
}

@Override
public ProjectSettings projectSettings() {
return this.settings;
}

@Override
public ImmutableMap<String, String> environmentVariables() {
return this.environmentVariables;
}

@Override
public Path workDir() {
return this.options.workDir();
}

@Override
public Optional<Consumer<Context>> program() {
return this.options.program();
}

@Override
public WorkspaceStack upsertStack(StackSettings settings) {
return new WorkspaceStack(logger, this, settings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.pulumi.automation;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.pulumi.Context;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;

import static java.util.Objects.requireNonNull;

@ParametersAreNonnullByDefault
public class LocalWorkspaceOptions {

private final Path workDir;
@Nullable
private final Consumer<Context> program;

public LocalWorkspaceOptions(
Path workDir,
@Nullable Consumer<Context> program
) {

this.workDir = requireNonNull(workDir);
this.program = program;
}

public Path workDir() {
return this.workDir;
}

@Nullable
public Optional<Consumer<Context>> program() {
return Optional.ofNullable(this.program);
}

public static LocalWorkspaceOptions.Builder builder() {
return new LocalWorkspaceOptions.Builder();
}

@ParametersAreNonnullByDefault
@CanIgnoreReturnValue
public static class Builder {

private Path workDir;
private Consumer<Context> program;

public Builder workDir(Path path) {
this.workDir = path;
return this;
}

/**
* The inline Pulumi program to be used for Preview/Update operations if any.
* @see Workspace#program()
* @param program the inline Pulumi program to use
* @return the {@link Builder} instance
*/
public Builder program(@Nullable Consumer<Context> program) {
this.program = program;
return this;
}

public LocalWorkspaceOptions build() {
return new LocalWorkspaceOptions(
this.workDir,
this.program
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.pulumi.automation;

public class ProjectBackend {
private final String url;

public ProjectBackend(String url) {
this.url = url;
}

public String url() {
return url;
}
}
Loading