087deb7643
This change adds an optiona dependsOn parameter to Resource constructors, to "force" a fake dependency between resources. We have an extremely strong desire to resort to using this only in unusual cases -- and instead rely on the natural dependency DAG based on properties -- but experience in other resource provisioning frameworks tells us that we're likely to need this in the general case. Indeed, we've already encountered the need in AWS's API Gateway resources... and I suspect we'll run into more especially as we tackle non-serverless resources like EC2 Instances, where "ambient" dependencies are far more commonplace. This also makes parallelism the default mode of operation, and we have a new --serialize flag that can be used to suppress this default behavior. Full disclosure: I expect this to become more Make-like, i.e. -j 8, where you can specify the precise width of parallelism, when we tackle pulumi/pulumi-fabric#106. I also think there's a good chance we will flip the default, so that serial execution is the default, so that developers who don't benefit from the parallelism don't need to worry about dependsOn in awkward ways. This tends to be the way most tools (like Make) operate. This fixes pulumi/pulumi-fabric#335.
82 lines
2.7 KiB
Go
82 lines
2.7 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/golang/glog"
|
|
|
|
"github.com/pulumi/pulumi-fabric/pkg/tokens"
|
|
lumirpc "github.com/pulumi/pulumi-fabric/sdk/proto/go"
|
|
)
|
|
|
|
const LanguagePluginPrefix = "pulumi-langhost-"
|
|
|
|
// langhost reflects a language host plugin, loaded dynamically for a single language/runtime pair.
|
|
type langhost struct {
|
|
ctx *Context
|
|
runtime string
|
|
plug *plugin
|
|
client lumirpc.LanguageRuntimeClient
|
|
}
|
|
|
|
// NewLanguageRuntime binds to a language's runtime plugin and then creates a gRPC connection to it. If the
|
|
// plugin could not be found, or an error occurs while creating the child process, an error is returned.
|
|
func NewLanguageRuntime(host Host, ctx *Context, runtime string, monitorAddr string) (LanguageRuntime, error) {
|
|
// Go ahead and attempt to load the plugin from the PATH.
|
|
srvexe := LanguagePluginPrefix + strings.Replace(runtime, tokens.QNameDelimiter, "_", -1)
|
|
plug, err := newPlugin(ctx, srvexe,
|
|
fmt.Sprintf("langhost[%v]", runtime), []string{monitorAddr, host.ServerAddr()})
|
|
if err != nil {
|
|
return nil, err
|
|
} else if plug == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return &langhost{
|
|
ctx: ctx,
|
|
runtime: runtime,
|
|
plug: plug,
|
|
client: lumirpc.NewLanguageRuntimeClient(plug.Conn),
|
|
}, nil
|
|
}
|
|
|
|
func (h *langhost) Runtime() string { return h.runtime }
|
|
|
|
// Run executes a program in the language runtime for planning or deployment purposes. If info.DryRun is true,
|
|
// the code must not assume that side-effects or final values resulting from resource deployments are actually
|
|
// available. If it is false, on the other hand, a real deployment is occurring and it may safely depend on these.
|
|
func (h *langhost) Run(info RunInfo) (string, error) {
|
|
glog.V(7).Infof("langhost[%v].Run(pwd=%v,program=%v,#args=%v,#config=%v,dryrun=%v) executing",
|
|
h.runtime, info.Pwd, info.Program, len(info.Args), len(info.Config), info.DryRun)
|
|
config := make(map[string]string)
|
|
for k, v := range info.Config {
|
|
config[string(k)] = v
|
|
}
|
|
resp, err := h.client.Run(h.ctx.Request(), &lumirpc.RunRequest{
|
|
Pwd: info.Pwd,
|
|
Program: info.Program,
|
|
Args: info.Args,
|
|
Config: config,
|
|
DryRun: info.DryRun,
|
|
Serialize: info.Serialize,
|
|
})
|
|
if err != nil {
|
|
glog.V(7).Infof("langhost[%v].Run(pwd=%v,program=%v,...,dryrun=%v) failed: err=%v",
|
|
h.runtime, info.Pwd, info.Program, info.DryRun, err)
|
|
return "", err
|
|
}
|
|
|
|
progerr := resp.GetError()
|
|
glog.V(7).Infof("langhost[%v].RunPlan(pwd=%v,program=%v,...,dryrun=%v) success: progerr=%v",
|
|
h.runtime, info.Pwd, info.Program, info.DryRun, progerr)
|
|
return progerr, nil
|
|
}
|
|
|
|
// Close tears down the underlying plugin RPC connection and process.
|
|
func (h *langhost) Close() error {
|
|
return h.plug.Close()
|
|
}
|