2017-06-26 23:46:34 +02:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
2017-02-20 20:18:47 +01:00
|
|
|
|
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 20:50:47 +02:00
|
|
|
"sort"
|
2017-02-20 20:18:47 +01:00
|
|
|
|
2017-09-22 04:18:21 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
|
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
|
|
|
"github.com/pulumi/pulumi/pkg/util/mapper"
|
2017-02-20 20:18:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// PropertyKey is the name of a property.
|
|
|
|
type PropertyKey tokens.Name
|
|
|
|
|
Initial support for output properties (1 of 3)
This change includes approximately 1/3rd of the change necessary
to support output properties, as per pulumi/lumi#90.
In short, the runtime now has a new hidden type, Latent<T>, which
represents a "speculative" value, whose eventual type will be T,
that we can use during evaluation in various ways. Namely,
operations against Latent<T>s generally produce new Latent<U>s.
During planning, any Latent<T>s that end up in resource properties
are transformed into "unknown" property values. An unknown property
value is legal only during planning-time activities, such as Check,
Name, and InspectChange. As a result, those RPC interfaces have
been updated to include lookaside maps indicating which properties
have unknown values. My intent is to add some helper functions to
make dealing with this circumstance more correct-by-construction.
For now, using an unresolved Latent<T> in a conditional will lead
to an error. See pulumi/lumi#67. Speculating beyond these -- by
supporting iterative planning and application -- is something we
want to support eventually, but it makes sense to do that as an
additive change beyond this initial support. That is a missing 1/3.
Finally, the other missing 1/3rd which will happen much sooner
than the rest is restructuing plan application so that it will
correctly observe resolution of Latent<T> values. Right now, the
evaluation happens in one single pass, prior to the application, and
so Latent<T>s never actually get witnessed in a resolved state.
2017-05-24 02:32:59 +02:00
|
|
|
// PropertySet is a simple set keyed by property name.
|
|
|
|
type PropertySet map[PropertyKey]bool
|
|
|
|
|
2017-02-20 20:18:47 +01:00
|
|
|
// PropertyMap is a simple map keyed by property name with "JSON-like" values.
|
|
|
|
type PropertyMap map[PropertyKey]PropertyValue
|
|
|
|
|
2017-04-22 00:27:32 +02:00
|
|
|
// NewPropertyMap turns a struct into a property map, using any JSON tags inside to determine naming.
|
|
|
|
func NewPropertyMap(s interface{}) PropertyMap {
|
2017-07-11 02:40:28 +02:00
|
|
|
return NewPropertyMapRepl(s, nil, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPropertyMapRepl turns a struct into a property map, using any JSON tags inside to determine naming. If non-nil
|
|
|
|
// replk or replv function(s) are provided, key and/or value transformations are performed during the mapping.
|
|
|
|
func NewPropertyMapRepl(s interface{},
|
|
|
|
replk func(string) (PropertyKey, bool), replv func(interface{}) (PropertyValue, bool)) PropertyMap {
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 02:43:52 +02:00
|
|
|
m, err := mapper.Unmap(s)
|
|
|
|
contract.Assertf(err == nil, "Struct of properties failed to map correctly: %v", err)
|
2017-07-11 02:40:28 +02:00
|
|
|
return NewPropertyMapFromMapRepl(m, replk, replv)
|
2017-05-30 19:55:53 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 02:40:28 +02:00
|
|
|
// NewPropertyMapFromMap creates a resource map from a regular weakly typed JSON-like map.
|
2017-05-30 19:55:53 +02:00
|
|
|
func NewPropertyMapFromMap(m map[string]interface{}) PropertyMap {
|
2017-07-11 02:40:28 +02:00
|
|
|
return NewPropertyMapFromMapRepl(m, nil, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPropertyMapFromMapRepl optionally replaces keys/values in an existing map while creating a new resource map.
|
|
|
|
func NewPropertyMapFromMapRepl(m map[string]interface{},
|
|
|
|
replk func(string) (PropertyKey, bool), replv func(interface{}) (PropertyValue, bool)) PropertyMap {
|
2017-04-22 00:27:32 +02:00
|
|
|
result := make(PropertyMap)
|
|
|
|
for k, v := range m {
|
2017-07-11 02:40:28 +02:00
|
|
|
key := PropertyKey(k)
|
|
|
|
if replk != nil {
|
|
|
|
if rk, repl := replk(k); repl {
|
|
|
|
key = rk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result[key] = NewPropertyValueRepl(v, replk, replv)
|
2017-04-22 00:27:32 +02:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:18:47 +01:00
|
|
|
// PropertyValue is the value of a property, limited to a select few types (see below).
|
|
|
|
type PropertyValue struct {
|
|
|
|
V interface{}
|
|
|
|
}
|
|
|
|
|
2017-05-25 22:19:20 +02:00
|
|
|
// Computed represents the absence of a property value, because it will be computed at some point in the future. It
|
|
|
|
// contains a property value which represents the underlying expected type of the eventual property value.
|
2017-06-08 15:44:21 +02:00
|
|
|
type Computed struct {
|
2017-06-08 15:48:23 +02:00
|
|
|
Element PropertyValue // the eventual value (type) of the computed property.
|
2017-05-25 22:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Output is a property value that will eventually be computed by the resource provider. If an output property is
|
|
|
|
// encountered, it means the resource has not yet been created, and so the output value is unavailable. Note that an
|
|
|
|
// output property is a special case of computed, but carries additional semantic meaning.
|
2017-06-08 15:44:21 +02:00
|
|
|
type Output struct {
|
2017-06-08 15:48:23 +02:00
|
|
|
Element PropertyValue // the eventual value (type) of the output property.
|
Initial support for output properties (1 of 3)
This change includes approximately 1/3rd of the change necessary
to support output properties, as per pulumi/lumi#90.
In short, the runtime now has a new hidden type, Latent<T>, which
represents a "speculative" value, whose eventual type will be T,
that we can use during evaluation in various ways. Namely,
operations against Latent<T>s generally produce new Latent<U>s.
During planning, any Latent<T>s that end up in resource properties
are transformed into "unknown" property values. An unknown property
value is legal only during planning-time activities, such as Check,
Name, and InspectChange. As a result, those RPC interfaces have
been updated to include lookaside maps indicating which properties
have unknown values. My intent is to add some helper functions to
make dealing with this circumstance more correct-by-construction.
For now, using an unresolved Latent<T> in a conditional will lead
to an error. See pulumi/lumi#67. Speculating beyond these -- by
supporting iterative planning and application -- is something we
want to support eventually, but it makes sense to do that as an
additive change beyond this initial support. That is a missing 1/3.
Finally, the other missing 1/3rd which will happen much sooner
than the rest is restructuing plan application so that it will
correctly observe resolution of Latent<T> values. Right now, the
evaluation happens in one single pass, prior to the application, and
so Latent<T>s never actually get witnessed in a resolved state.
2017-05-24 02:32:59 +02:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:18:47 +01:00
|
|
|
type ReqError struct {
|
|
|
|
K PropertyKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsReqError(err error) bool {
|
|
|
|
_, isreq := err.(*ReqError)
|
|
|
|
return isreq
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *ReqError) Error() string {
|
|
|
|
return fmt.Sprintf("required property '%v' is missing", err.K)
|
|
|
|
}
|
|
|
|
|
2017-06-05 04:24:48 +02:00
|
|
|
// HasValue returns true if the slot associated with the given property key contains a real value. It returns false
|
|
|
|
// if a value is null or an output property that is awaiting a value to be assigned. That is to say, HasValue indicates
|
|
|
|
// a semantically meaningful value is present (even if it's a computed one whose concrete value isn't yet evaluated).
|
|
|
|
func (m PropertyMap) HasValue(k PropertyKey) bool {
|
2017-06-01 19:09:52 +02:00
|
|
|
v, has := m[k]
|
2017-06-05 04:24:48 +02:00
|
|
|
return has && v.HasValue()
|
2017-06-01 19:09:52 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 01:40:44 +02:00
|
|
|
// ContainsUnknowns returns true if the property map contains at least one unknown value.
|
|
|
|
func (m PropertyMap) ContainsUnknowns() bool {
|
|
|
|
for _, v := range m {
|
|
|
|
if v.ContainsUnknowns() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-03-12 22:13:44 +01:00
|
|
|
// Mappable returns a mapper-compatible object map, suitable for deserialization into structures.
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 02:43:52 +02:00
|
|
|
func (m PropertyMap) Mappable() map[string]interface{} {
|
2017-07-11 02:40:28 +02:00
|
|
|
return m.MapRepl(nil, nil)
|
2017-07-01 21:08:55 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 02:40:28 +02:00
|
|
|
// MapRepl returns a mapper-compatible object map, suitable for deserialization into structures. A key and/or value
|
|
|
|
// replace function, replk/replv, may be passed that will replace elements using custom logic if appropriate.
|
|
|
|
func (m PropertyMap) MapRepl(replk func(string) (string, bool),
|
|
|
|
replv func(PropertyValue) (interface{}, bool)) map[string]interface{} {
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 02:43:52 +02:00
|
|
|
obj := make(map[string]interface{})
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 20:50:47 +02:00
|
|
|
for _, k := range m.StableKeys() {
|
2017-07-11 02:40:28 +02:00
|
|
|
key := string(k)
|
|
|
|
if replk != nil {
|
|
|
|
if rk, repk := replk(key); repk {
|
|
|
|
key = rk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obj[key] = m[k].MapRepl(replk, replv)
|
2017-03-12 22:13:44 +01:00
|
|
|
}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2017-07-20 17:07:45 +02:00
|
|
|
// Copy makes a shallow copy of the map.
|
|
|
|
func (m PropertyMap) Copy() PropertyMap {
|
2017-07-19 17:31:45 +02:00
|
|
|
new := make(PropertyMap)
|
|
|
|
for k, v := range m {
|
|
|
|
new[k] = v
|
|
|
|
}
|
2017-07-20 17:07:45 +02:00
|
|
|
return new
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge simply merges in another map atop another, and returns the result.
|
|
|
|
func (m PropertyMap) Merge(other PropertyMap) PropertyMap {
|
|
|
|
new := m.Copy()
|
2017-07-19 17:31:45 +02:00
|
|
|
for k, v := range other {
|
2017-08-01 03:26:15 +02:00
|
|
|
if !v.IsNull() {
|
2017-11-28 21:01:41 +01:00
|
|
|
if mv, ok := m[k]; ok {
|
2017-11-28 22:21:06 +01:00
|
|
|
v = mv.merge(v)
|
2017-11-28 21:01:41 +01:00
|
|
|
}
|
2017-08-01 03:26:15 +02:00
|
|
|
new[k] = v
|
|
|
|
}
|
2017-07-19 17:31:45 +02:00
|
|
|
}
|
|
|
|
return new
|
|
|
|
}
|
|
|
|
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 20:50:47 +02:00
|
|
|
// StableKeys returns all of the map's keys in a stable order.
|
|
|
|
func (m PropertyMap) StableKeys() []PropertyKey {
|
|
|
|
sorted := make([]PropertyKey, 0, len(m))
|
|
|
|
for k := range m {
|
|
|
|
sorted = append(sorted, k)
|
|
|
|
}
|
|
|
|
sort.Slice(sorted, func(i, j int) bool { return sorted[i] < sorted[j] })
|
|
|
|
return sorted
|
|
|
|
}
|
|
|
|
|
2017-05-25 22:19:20 +02:00
|
|
|
func NewNullProperty() PropertyValue { return PropertyValue{nil} }
|
|
|
|
func NewBoolProperty(v bool) PropertyValue { return PropertyValue{v} }
|
|
|
|
func NewNumberProperty(v float64) PropertyValue { return PropertyValue{v} }
|
|
|
|
func NewStringProperty(v string) PropertyValue { return PropertyValue{v} }
|
|
|
|
func NewArrayProperty(v []PropertyValue) PropertyValue { return PropertyValue{v} }
|
2017-10-22 22:39:21 +02:00
|
|
|
func NewAssetProperty(v *Asset) PropertyValue { return PropertyValue{v} }
|
|
|
|
func NewArchiveProperty(v *Archive) PropertyValue { return PropertyValue{v} }
|
2017-05-25 22:19:20 +02:00
|
|
|
func NewObjectProperty(v PropertyMap) PropertyValue { return PropertyValue{v} }
|
|
|
|
func NewComputedProperty(v Computed) PropertyValue { return PropertyValue{v} }
|
|
|
|
func NewOutputProperty(v Output) PropertyValue { return PropertyValue{v} }
|
|
|
|
|
2017-06-10 03:34:37 +02:00
|
|
|
func MakeComputed(v PropertyValue) PropertyValue {
|
|
|
|
return NewComputedProperty(Computed{Element: v})
|
2017-06-08 15:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func MakeOutput(v PropertyValue) PropertyValue {
|
2017-06-08 15:48:23 +02:00
|
|
|
return NewOutputProperty(Output{Element: v})
|
2017-06-08 15:44:21 +02:00
|
|
|
}
|
2017-02-20 20:18:47 +01:00
|
|
|
|
2017-04-22 00:27:32 +02:00
|
|
|
// NewPropertyValue turns a value into a property value, provided it is of a legal "JSON-like" kind.
|
|
|
|
func NewPropertyValue(v interface{}) PropertyValue {
|
2017-07-11 02:40:28 +02:00
|
|
|
return NewPropertyValueRepl(v, nil, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPropertyValueRepl turns a value into a property value, provided it is of a legal "JSON-like" kind. The
|
|
|
|
// replacement functions, replk and replv, may be supplied to transform keys and/or values as the mapping takes place.
|
|
|
|
func NewPropertyValueRepl(v interface{},
|
|
|
|
replk func(string) (PropertyKey, bool), replv func(interface{}) (PropertyValue, bool)) PropertyValue {
|
|
|
|
// If a replacement routine is supplied, use that.
|
|
|
|
if replv != nil {
|
|
|
|
if rv, repl := replv(v); repl {
|
|
|
|
return rv
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 00:27:32 +02:00
|
|
|
// If nil, easy peasy, just return a null.
|
|
|
|
if v == nil {
|
2017-05-25 22:19:20 +02:00
|
|
|
return NewNullProperty()
|
2017-04-22 00:27:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Else, check for some known primitive types.
|
|
|
|
switch t := v.(type) {
|
|
|
|
case bool:
|
2017-05-25 22:19:20 +02:00
|
|
|
return NewBoolProperty(t)
|
2017-07-20 17:07:45 +02:00
|
|
|
case int:
|
|
|
|
return NewNumberProperty(float64(t))
|
|
|
|
case uint:
|
|
|
|
return NewNumberProperty(float64(t))
|
|
|
|
case int32:
|
|
|
|
return NewNumberProperty(float64(t))
|
|
|
|
case uint32:
|
|
|
|
return NewNumberProperty(float64(t))
|
|
|
|
case int64:
|
|
|
|
return NewNumberProperty(float64(t))
|
|
|
|
case uint64:
|
|
|
|
return NewNumberProperty(float64(t))
|
|
|
|
case float32:
|
|
|
|
return NewNumberProperty(float64(t))
|
2017-04-22 00:27:32 +02:00
|
|
|
case float64:
|
2017-05-25 22:19:20 +02:00
|
|
|
return NewNumberProperty(t)
|
2017-04-22 00:27:32 +02:00
|
|
|
case string:
|
2017-05-25 22:19:20 +02:00
|
|
|
return NewStringProperty(t)
|
2017-10-22 22:39:21 +02:00
|
|
|
case *Asset:
|
2017-07-14 21:28:43 +02:00
|
|
|
return NewAssetProperty(t)
|
2017-10-22 22:39:21 +02:00
|
|
|
case *Archive:
|
2017-07-14 21:28:43 +02:00
|
|
|
return NewArchiveProperty(t)
|
2017-05-25 22:19:20 +02:00
|
|
|
case Computed:
|
|
|
|
return NewComputedProperty(t)
|
2017-08-03 20:01:38 +02:00
|
|
|
case Output:
|
|
|
|
return NewOutputProperty(t)
|
2017-04-22 00:27:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next, see if it's an array, slice, pointer or struct, and handle each accordingly.
|
|
|
|
rv := reflect.ValueOf(v)
|
|
|
|
switch rk := rv.Type().Kind(); rk {
|
|
|
|
case reflect.Array, reflect.Slice:
|
|
|
|
// If an array or slice, just create an array out of it.
|
|
|
|
var arr []PropertyValue
|
|
|
|
for i := 0; i < rv.Len(); i++ {
|
|
|
|
elem := rv.Index(i)
|
2017-07-11 02:40:28 +02:00
|
|
|
arr = append(arr, NewPropertyValueRepl(elem.Interface(), replk, replv))
|
2017-04-22 00:27:32 +02:00
|
|
|
}
|
2017-05-25 22:19:20 +02:00
|
|
|
return NewArrayProperty(arr)
|
2017-04-22 00:27:32 +02:00
|
|
|
case reflect.Ptr:
|
|
|
|
// If a pointer, recurse and return the underlying value.
|
2017-04-25 23:04:22 +02:00
|
|
|
if rv.IsNil() {
|
2017-05-25 22:19:20 +02:00
|
|
|
return NewNullProperty()
|
2017-04-25 23:04:22 +02:00
|
|
|
}
|
2017-07-11 02:40:28 +02:00
|
|
|
return NewPropertyValueRepl(rv.Elem().Interface(), replk, replv)
|
2017-05-30 19:55:53 +02:00
|
|
|
case reflect.Map:
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
// If a map, create a new property map, provided the keys and values are okay.
|
|
|
|
obj := PropertyMap{}
|
|
|
|
for _, key := range rv.MapKeys() {
|
|
|
|
var pk PropertyKey
|
|
|
|
switch k := key.Interface().(type) {
|
|
|
|
case string:
|
|
|
|
pk = PropertyKey(k)
|
|
|
|
case PropertyKey:
|
|
|
|
pk = k
|
|
|
|
default:
|
|
|
|
contract.Failf("Unrecognized PropertyMap key type: %v", reflect.TypeOf(key))
|
|
|
|
}
|
2017-07-11 02:40:28 +02:00
|
|
|
if replk != nil {
|
|
|
|
if rk, repl := replk(string(pk)); repl {
|
|
|
|
pk = rk
|
|
|
|
}
|
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
val := rv.MapIndex(key)
|
2017-07-11 02:40:28 +02:00
|
|
|
pv := NewPropertyValueRepl(val.Interface(), replk, replv)
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
obj[pk] = pv
|
2017-05-30 19:55:53 +02:00
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
return NewObjectProperty(obj)
|
2017-05-25 22:19:20 +02:00
|
|
|
case reflect.Struct:
|
2017-07-11 02:40:28 +02:00
|
|
|
obj := NewPropertyMapRepl(v, replk, replv)
|
2017-06-01 17:51:33 +02:00
|
|
|
return NewObjectProperty(obj)
|
2017-04-22 00:27:32 +02:00
|
|
|
default:
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
contract.Failf("Unrecognized value type: type=%v kind=%v", rv.Type(), rk)
|
2017-04-22 00:27:32 +02:00
|
|
|
}
|
|
|
|
|
2017-05-25 22:19:20 +02:00
|
|
|
return NewNullProperty()
|
2017-04-22 00:27:32 +02:00
|
|
|
}
|
|
|
|
|
2017-07-14 21:28:43 +02:00
|
|
|
// HasValue returns true if a value is semantically meaningful.
|
|
|
|
func (v PropertyValue) HasValue() bool {
|
|
|
|
return !v.IsNull() && !v.IsOutput()
|
|
|
|
}
|
|
|
|
|
2017-09-15 01:40:44 +02:00
|
|
|
// ContainsUnknowns returns true if the property value contains at least one unknown (deeply).
|
|
|
|
func (v PropertyValue) ContainsUnknowns() bool {
|
|
|
|
if v.IsComputed() || v.IsOutput() {
|
|
|
|
return true
|
|
|
|
} else if v.IsArray() {
|
|
|
|
for _, e := range v.ArrayValue() {
|
|
|
|
if e.ContainsUnknowns() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if v.IsObject() {
|
|
|
|
return v.ObjectValue().ContainsUnknowns()
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
// BoolValue fetches the underlying bool value (panicking if it isn't a bool).
|
|
|
|
func (v PropertyValue) BoolValue() bool { return v.V.(bool) }
|
|
|
|
|
|
|
|
// NumberValue fetches the underlying number value (panicking if it isn't a number).
|
|
|
|
func (v PropertyValue) NumberValue() float64 { return v.V.(float64) }
|
|
|
|
|
|
|
|
// StringValue fetches the underlying string value (panicking if it isn't a string).
|
|
|
|
func (v PropertyValue) StringValue() string { return v.V.(string) }
|
|
|
|
|
|
|
|
// ArrayValue fetches the underlying array value (panicking if it isn't a array).
|
2017-02-20 20:18:47 +01:00
|
|
|
func (v PropertyValue) ArrayValue() []PropertyValue { return v.V.([]PropertyValue) }
|
|
|
|
|
2017-07-14 21:28:43 +02:00
|
|
|
// AssetValue fetches the underlying asset value (panicking if it isn't an asset).
|
2017-10-22 22:39:21 +02:00
|
|
|
func (v PropertyValue) AssetValue() *Asset { return v.V.(*Asset) }
|
2017-07-14 21:28:43 +02:00
|
|
|
|
|
|
|
// ArchiveValue fetches the underlying archive value (panicking if it isn't an archive).
|
2017-10-22 22:39:21 +02:00
|
|
|
func (v PropertyValue) ArchiveValue() *Archive { return v.V.(*Archive) }
|
2017-07-14 21:28:43 +02:00
|
|
|
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
// ObjectValue fetches the underlying object value (panicking if it isn't a object).
|
|
|
|
func (v PropertyValue) ObjectValue() PropertyMap { return v.V.(PropertyMap) }
|
|
|
|
|
2018-02-05 23:44:23 +01:00
|
|
|
// Input fetches the underlying computed value (panicking if it isn't a computed).
|
|
|
|
func (v PropertyValue) Input() Computed { return v.V.(Computed) }
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
|
|
|
// OutputValue fetches the underlying output value (panicking if it isn't a output).
|
|
|
|
func (v PropertyValue) OutputValue() Output { return v.V.(Output) }
|
|
|
|
|
|
|
|
// IsNull returns true if the underlying value is a null.
|
2017-04-08 16:44:02 +02:00
|
|
|
func (v PropertyValue) IsNull() bool {
|
|
|
|
return v.V == nil
|
2017-02-20 20:18:47 +01:00
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
|
|
|
// IsBool returns true if the underlying value is a bool.
|
2017-04-08 16:44:02 +02:00
|
|
|
func (v PropertyValue) IsBool() bool {
|
|
|
|
_, is := v.V.(bool)
|
2017-02-20 20:18:47 +01:00
|
|
|
return is
|
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
|
|
|
// IsNumber returns true if the underlying value is a number.
|
2017-04-08 16:44:02 +02:00
|
|
|
func (v PropertyValue) IsNumber() bool {
|
|
|
|
_, is := v.V.(float64)
|
2017-02-20 20:18:47 +01:00
|
|
|
return is
|
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
|
|
|
// IsString returns true if the underlying value is a string.
|
2017-04-08 16:44:02 +02:00
|
|
|
func (v PropertyValue) IsString() bool {
|
|
|
|
_, is := v.V.(string)
|
2017-02-20 20:18:47 +01:00
|
|
|
return is
|
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
|
|
|
// IsArray returns true if the underlying value is an array.
|
2017-04-08 16:44:02 +02:00
|
|
|
func (v PropertyValue) IsArray() bool {
|
|
|
|
_, is := v.V.([]PropertyValue)
|
2017-02-20 20:18:47 +01:00
|
|
|
return is
|
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
2017-07-14 21:28:43 +02:00
|
|
|
// IsAsset returns true if the underlying value is an object.
|
|
|
|
func (v PropertyValue) IsAsset() bool {
|
2017-10-22 22:39:21 +02:00
|
|
|
_, is := v.V.(*Asset)
|
2017-07-14 21:28:43 +02:00
|
|
|
return is
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsArchive returns true if the underlying value is an object.
|
|
|
|
func (v PropertyValue) IsArchive() bool {
|
2017-10-22 22:39:21 +02:00
|
|
|
_, is := v.V.(*Archive)
|
2017-07-14 21:28:43 +02:00
|
|
|
return is
|
|
|
|
}
|
|
|
|
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
// IsObject returns true if the underlying value is an object.
|
2017-04-08 16:44:02 +02:00
|
|
|
func (v PropertyValue) IsObject() bool {
|
|
|
|
_, is := v.V.(PropertyMap)
|
2017-02-20 20:18:47 +01:00
|
|
|
return is
|
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
|
|
|
// IsComputed returns true if the underlying value is a computed value.
|
2017-05-25 22:19:20 +02:00
|
|
|
func (v PropertyValue) IsComputed() bool {
|
|
|
|
_, is := v.V.(Computed)
|
|
|
|
return is
|
|
|
|
}
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
|
|
|
|
// IsOutput returns true if the underlying value is an output value.
|
2017-05-25 22:19:20 +02:00
|
|
|
func (v PropertyValue) IsOutput() bool {
|
|
|
|
_, is := v.V.(Output)
|
Initial support for output properties (1 of 3)
This change includes approximately 1/3rd of the change necessary
to support output properties, as per pulumi/lumi#90.
In short, the runtime now has a new hidden type, Latent<T>, which
represents a "speculative" value, whose eventual type will be T,
that we can use during evaluation in various ways. Namely,
operations against Latent<T>s generally produce new Latent<U>s.
During planning, any Latent<T>s that end up in resource properties
are transformed into "unknown" property values. An unknown property
value is legal only during planning-time activities, such as Check,
Name, and InspectChange. As a result, those RPC interfaces have
been updated to include lookaside maps indicating which properties
have unknown values. My intent is to add some helper functions to
make dealing with this circumstance more correct-by-construction.
For now, using an unresolved Latent<T> in a conditional will lead
to an error. See pulumi/lumi#67. Speculating beyond these -- by
supporting iterative planning and application -- is something we
want to support eventually, but it makes sense to do that as an
additive change beyond this initial support. That is a missing 1/3.
Finally, the other missing 1/3rd which will happen much sooner
than the rest is restructuing plan application so that it will
correctly observe resolution of Latent<T> values. Right now, the
evaluation happens in one single pass, prior to the application, and
so Latent<T>s never actually get witnessed in a resolved state.
2017-05-24 02:32:59 +02:00
|
|
|
return is
|
|
|
|
}
|
|
|
|
|
Unmap properties on the receive side
This change makes progress on a few things with respect to properly
receiving properties on the engine side, coming from the provider side,
of the RPC boundary. The issues here are twofold:
1. Properties need to get unmapped using a JSON-tag-sensitive
marshaler, so that they are cased properly, etc. For that, we
have a new mapper.Unmap function (which is ultra lame -- see
pulumi/lumi#138).
2. We have the reverse problem with respect to resource IDs: on
the send side, we must translate from URNs (which the engine
knows about) and provider IDs (which the provider knows about);
similarly, then, on the receive side, we must translate from
provider IDs back into URNs.
As a result of these getting fixed, we can now properly marshal the
resulting properties back into the resource object during the plan
execution, alongside propagating and memoizing its ID.
2017-05-31 20:51:46 +02:00
|
|
|
// TypeString returns a type representation of the property value's holder type.
|
Initial support for output properties (1 of 3)
This change includes approximately 1/3rd of the change necessary
to support output properties, as per pulumi/lumi#90.
In short, the runtime now has a new hidden type, Latent<T>, which
represents a "speculative" value, whose eventual type will be T,
that we can use during evaluation in various ways. Namely,
operations against Latent<T>s generally produce new Latent<U>s.
During planning, any Latent<T>s that end up in resource properties
are transformed into "unknown" property values. An unknown property
value is legal only during planning-time activities, such as Check,
Name, and InspectChange. As a result, those RPC interfaces have
been updated to include lookaside maps indicating which properties
have unknown values. My intent is to add some helper functions to
make dealing with this circumstance more correct-by-construction.
For now, using an unresolved Latent<T> in a conditional will lead
to an error. See pulumi/lumi#67. Speculating beyond these -- by
supporting iterative planning and application -- is something we
want to support eventually, but it makes sense to do that as an
additive change beyond this initial support. That is a missing 1/3.
Finally, the other missing 1/3rd which will happen much sooner
than the rest is restructuing plan application so that it will
correctly observe resolution of Latent<T> values. Right now, the
evaluation happens in one single pass, prior to the application, and
so Latent<T>s never actually get witnessed in a resolved state.
2017-05-24 02:32:59 +02:00
|
|
|
func (v PropertyValue) TypeString() string {
|
|
|
|
if v.IsNull() {
|
|
|
|
return "null"
|
|
|
|
} else if v.IsBool() {
|
|
|
|
return "bool"
|
|
|
|
} else if v.IsNumber() {
|
|
|
|
return "number"
|
|
|
|
} else if v.IsString() {
|
|
|
|
return "string"
|
|
|
|
} else if v.IsArray() {
|
|
|
|
return "[]"
|
2017-07-14 21:28:43 +02:00
|
|
|
} else if v.IsAsset() {
|
|
|
|
return "asset"
|
|
|
|
} else if v.IsArchive() {
|
|
|
|
return "archive"
|
Initial support for output properties (1 of 3)
This change includes approximately 1/3rd of the change necessary
to support output properties, as per pulumi/lumi#90.
In short, the runtime now has a new hidden type, Latent<T>, which
represents a "speculative" value, whose eventual type will be T,
that we can use during evaluation in various ways. Namely,
operations against Latent<T>s generally produce new Latent<U>s.
During planning, any Latent<T>s that end up in resource properties
are transformed into "unknown" property values. An unknown property
value is legal only during planning-time activities, such as Check,
Name, and InspectChange. As a result, those RPC interfaces have
been updated to include lookaside maps indicating which properties
have unknown values. My intent is to add some helper functions to
make dealing with this circumstance more correct-by-construction.
For now, using an unresolved Latent<T> in a conditional will lead
to an error. See pulumi/lumi#67. Speculating beyond these -- by
supporting iterative planning and application -- is something we
want to support eventually, but it makes sense to do that as an
additive change beyond this initial support. That is a missing 1/3.
Finally, the other missing 1/3rd which will happen much sooner
than the rest is restructuing plan application so that it will
correctly observe resolution of Latent<T> values. Right now, the
evaluation happens in one single pass, prior to the application, and
so Latent<T>s never actually get witnessed in a resolved state.
2017-05-24 02:32:59 +02:00
|
|
|
} else if v.IsObject() {
|
|
|
|
return "object"
|
2017-05-25 22:19:20 +02:00
|
|
|
} else if v.IsComputed() {
|
2018-02-05 23:44:23 +01:00
|
|
|
return "computed<" + v.Input().Element.TypeString() + ">"
|
2017-05-25 22:19:20 +02:00
|
|
|
} else if v.IsOutput() {
|
2017-06-08 15:48:23 +02:00
|
|
|
return "output<" + v.OutputValue().Element.TypeString() + ">"
|
Initial support for output properties (1 of 3)
This change includes approximately 1/3rd of the change necessary
to support output properties, as per pulumi/lumi#90.
In short, the runtime now has a new hidden type, Latent<T>, which
represents a "speculative" value, whose eventual type will be T,
that we can use during evaluation in various ways. Namely,
operations against Latent<T>s generally produce new Latent<U>s.
During planning, any Latent<T>s that end up in resource properties
are transformed into "unknown" property values. An unknown property
value is legal only during planning-time activities, such as Check,
Name, and InspectChange. As a result, those RPC interfaces have
been updated to include lookaside maps indicating which properties
have unknown values. My intent is to add some helper functions to
make dealing with this circumstance more correct-by-construction.
For now, using an unresolved Latent<T> in a conditional will lead
to an error. See pulumi/lumi#67. Speculating beyond these -- by
supporting iterative planning and application -- is something we
want to support eventually, but it makes sense to do that as an
additive change beyond this initial support. That is a missing 1/3.
Finally, the other missing 1/3rd which will happen much sooner
than the rest is restructuing plan application so that it will
correctly observe resolution of Latent<T> values. Right now, the
evaluation happens in one single pass, prior to the application, and
so Latent<T>s never actually get witnessed in a resolved state.
2017-05-24 02:32:59 +02:00
|
|
|
}
|
|
|
|
contract.Failf("Unrecognized PropertyValue type")
|
|
|
|
return ""
|
|
|
|
}
|
Implement updates
This change is a first whack at implementing updates.
Creation and deletion plans are pretty straightforward; we just take
a single graph, topologically sort it, and perform the operations in
the right order. For creation, this is in dependency order (things
that are depended upon must be created before dependents); for deletion,
this is in reverse-dependency order (things that depend on others must
be deleted before dependencies). These are just special cases of the more
general idea of performing DAG operations in dependency order.
Updates must work in terms of this more general notion. For example:
* It is an error to delete a resource while another refers to it; thus,
resources are deleted after deleting dependents, or after updating
dependent properties that reference the resource to new values.
* It is an error to depend on a create a resource before it is created;
thus, resources must be created before dependents are created, and/or
before updates to existing resource properties that would cause them
to refer to the new resource.
Of course, all of this is tangled up in a graph of dependencies. As a
result, we must create a DAG of the dependencies between creates, updates,
and deletes, and then topologically sort this DAG, in order to determine
the proper order of update operations.
To do this, we slightly generalize the existing graph infrastructure,
while also specializing two kinds of graphs; the existing one becomes a
heapstate.ObjectGraph, while this new one is resource.planGraph (internal).
2017-02-23 23:56:23 +01:00
|
|
|
|
2017-03-12 22:13:44 +01:00
|
|
|
// Mappable returns a mapper-compatible value, suitable for deserialization into structures.
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 02:43:52 +02:00
|
|
|
func (v PropertyValue) Mappable() interface{} {
|
2017-07-11 02:40:28 +02:00
|
|
|
return v.MapRepl(nil, nil)
|
2017-07-01 21:08:55 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 02:40:28 +02:00
|
|
|
// MapRepl returns a mapper-compatible object map, suitable for deserialization into structures. A key and/or value
|
|
|
|
// replace function, replk/replv, may be passed that will replace elements using custom logic if appropriate.
|
|
|
|
func (v PropertyValue) MapRepl(replk func(string) (string, bool),
|
|
|
|
replv func(PropertyValue) (interface{}, bool)) interface{} {
|
|
|
|
if replv != nil {
|
|
|
|
if rv, repv := replv(v); repv {
|
|
|
|
return rv
|
2017-07-01 21:08:55 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-12 22:13:44 +01:00
|
|
|
if v.IsNull() {
|
|
|
|
return nil
|
|
|
|
} else if v.IsBool() {
|
|
|
|
return v.BoolValue()
|
|
|
|
} else if v.IsNumber() {
|
|
|
|
return v.NumberValue()
|
|
|
|
} else if v.IsString() {
|
|
|
|
return v.StringValue()
|
|
|
|
} else if v.IsArray() {
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 02:43:52 +02:00
|
|
|
var arr []interface{}
|
2017-03-12 22:13:44 +01:00
|
|
|
for _, e := range v.ArrayValue() {
|
2017-07-11 02:40:28 +02:00
|
|
|
arr = append(arr, e.MapRepl(replk, replv))
|
2017-03-12 22:13:44 +01:00
|
|
|
}
|
|
|
|
return arr
|
2017-07-14 21:28:43 +02:00
|
|
|
} else if v.IsAsset() {
|
|
|
|
return v.AssetValue()
|
|
|
|
} else if v.IsArchive() {
|
|
|
|
return v.ArchiveValue()
|
2017-08-03 20:01:38 +02:00
|
|
|
} else if v.IsComputed() {
|
2018-02-05 23:44:23 +01:00
|
|
|
return v.Input()
|
2017-08-03 20:01:38 +02:00
|
|
|
} else if v.IsOutput() {
|
|
|
|
return v.OutputValue()
|
2017-03-12 22:13:44 +01:00
|
|
|
}
|
2017-10-24 17:25:39 +02:00
|
|
|
contract.Assertf(v.IsObject(), "v is not Object '%v' instead", v.TypeString())
|
2017-07-11 02:40:28 +02:00
|
|
|
return v.ObjectValue().MapRepl(replk, replv)
|
2017-03-12 22:13:44 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 22:21:06 +01:00
|
|
|
// merge simply merges the value of other into v. Merging proceeds as follows:
|
2017-11-28 21:01:41 +01:00
|
|
|
// - If other is null, v is returned.
|
2017-11-29 17:16:38 +01:00
|
|
|
// - If v and other are both arrays, the corresponding elements are recurively merged. Any unmerged elements in v or
|
|
|
|
// other are then appended to the result.
|
2017-11-28 21:01:41 +01:00
|
|
|
// - If v and other are both maps, the corresponding key-value pairs are recursively merged.
|
|
|
|
// - Otherwise, other is returned.
|
2017-11-28 22:21:06 +01:00
|
|
|
func (v PropertyValue) merge(other PropertyValue) PropertyValue {
|
2017-11-28 21:01:41 +01:00
|
|
|
switch {
|
|
|
|
case other.IsNull():
|
|
|
|
return v
|
|
|
|
case v.IsArray() && other.IsArray():
|
|
|
|
left, right, merged := v.ArrayValue(), other.ArrayValue(), []PropertyValue{}
|
|
|
|
for len(left) > 0 && len(right) > 0 {
|
2017-11-28 22:21:06 +01:00
|
|
|
merged = append(merged, left[0].merge(right[0]))
|
2017-11-28 21:01:41 +01:00
|
|
|
left, right = left[1:], right[1:]
|
|
|
|
}
|
|
|
|
switch {
|
|
|
|
case len(left) > 0:
|
|
|
|
contract.Assert(len(right) == 0)
|
|
|
|
for ; len(left) > 0; left = left[1:] {
|
|
|
|
merged = append(merged, left[0])
|
|
|
|
}
|
|
|
|
case len(right) > 0:
|
|
|
|
contract.Assert(len(left) == 0)
|
|
|
|
for ; len(right) > 0; right = right[1:] {
|
|
|
|
merged = append(merged, right[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NewArrayProperty(merged)
|
|
|
|
case v.IsObject() && other.IsObject():
|
|
|
|
return NewObjectProperty(v.ObjectValue().Merge(other.ObjectValue()))
|
|
|
|
default:
|
|
|
|
return other
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 17:23:59 +02:00
|
|
|
// String implements the fmt.Stringer interface to add slightly more information to the output.
|
|
|
|
func (v PropertyValue) String() string {
|
|
|
|
if v.IsComputed() || v.IsOutput() {
|
|
|
|
// For computed and output properties, show their type followed by an empty object string.
|
|
|
|
return fmt.Sprintf("%v{}", v.TypeString())
|
|
|
|
}
|
|
|
|
// For all others, just display the underlying property value.
|
|
|
|
return fmt.Sprintf("{%v}", v.V)
|
|
|
|
}
|
2017-07-01 22:26:49 +02:00
|
|
|
|
|
|
|
// Property is a pair of key and value.
|
|
|
|
type Property struct {
|
|
|
|
Key PropertyKey
|
|
|
|
Value PropertyValue
|
|
|
|
}
|
2017-07-17 19:38:57 +02:00
|
|
|
|
|
|
|
// SigKey is sometimes used to encode type identity inside of a map. This is required when flattening into ordinary
|
|
|
|
// maps, like we do when performing serialization, to ensure recoverability of type identities later on.
|
|
|
|
const SigKey = PropertyKey("4dabf18193072939515e22adb298388d")
|
|
|
|
|
|
|
|
// HasSig checks to see if the given property map contains the specific signature match.
|
|
|
|
func HasSig(obj PropertyMap, match string) bool {
|
|
|
|
if sig, hassig := obj[SigKey]; hassig {
|
|
|
|
return sig.IsString() && sig.StringValue() == match
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|