35aa6b7559
We are renaming Lumi to Pulumi Fabric. This change simply renames the pulumi/lumi repo to pulumi/pulumi-fabric, without the CLI tools and other changes that will follow soon afterwards.
75 lines
2.7 KiB
Go
75 lines
2.7 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
// Package environment contains the serialized and configurable state associated with an environment; or, in other
|
|
// words, a deployment target. It pertains to resources and deployment plans, but is a package unto itself.
|
|
package environment
|
|
|
|
import (
|
|
"github.com/pulumi/pulumi-fabric/pkg/resource"
|
|
"github.com/pulumi/pulumi-fabric/pkg/resource/deploy"
|
|
"github.com/pulumi/pulumi-fabric/pkg/tokens"
|
|
"github.com/pulumi/pulumi-fabric/pkg/util/contract"
|
|
)
|
|
|
|
// Checkpoint is a serialized deployment target plus a record of the latest deployment.
|
|
type Checkpoint struct {
|
|
Target tokens.QName `json:"target"` // the target environment name.
|
|
Config *resource.ConfigMap `json:"config,omitempty"` // optional configuration key/values.
|
|
Latest *Deployment `json:"latest,omitempty"` // the latest/current deployment information.
|
|
}
|
|
|
|
// SerializeCheckpoint turns a snapshot into a LumiGL data structure suitable for serialization.
|
|
func SerializeCheckpoint(targ *deploy.Target, snap *deploy.Snapshot) *Checkpoint {
|
|
contract.Requiref(targ != nil, "targ", "!= nil")
|
|
|
|
// If snap is nil, that's okay, we will just create an empty deployment; otherwise, serialize the whole snapshot.
|
|
var latest *Deployment
|
|
if snap != nil {
|
|
latest = SerializeDeployment(snap)
|
|
}
|
|
|
|
var config *resource.ConfigMap
|
|
if targ.Config != nil {
|
|
config = &targ.Config
|
|
}
|
|
|
|
return &Checkpoint{
|
|
Target: targ.Name,
|
|
Config: config,
|
|
Latest: latest,
|
|
}
|
|
}
|
|
|
|
// DeserializeCheckpoint takes a serialized deployment record and returns its associated snapshot.
|
|
func DeserializeCheckpoint(chkpoint *Checkpoint) (*deploy.Target, *deploy.Snapshot) {
|
|
contract.Require(chkpoint != nil, "chkpoint")
|
|
|
|
var snap *deploy.Snapshot
|
|
name := chkpoint.Target
|
|
if latest := chkpoint.Latest; latest != nil {
|
|
// For every serialized resource vertex, create a ResourceDeployment out of it.
|
|
var resources []*resource.State
|
|
if latest.Resources != nil {
|
|
for _, kvp := range latest.Resources.Iter() {
|
|
// Deserialize the resource properties, if they exist.
|
|
res := kvp.Value
|
|
inputs := DeserializeProperties(res.Inputs)
|
|
defaults := DeserializeProperties(res.Defaults)
|
|
outputs := DeserializeProperties(res.Outputs)
|
|
|
|
// And now just produce a resource object using the information available.
|
|
state := resource.NewState(res.Type, kvp.Key, res.ID, inputs, defaults, outputs)
|
|
resources = append(resources, state)
|
|
}
|
|
}
|
|
|
|
snap = deploy.NewSnapshot(name, resources, latest.Info)
|
|
}
|
|
|
|
// Create a new target and snapshot objects to return.
|
|
targ := &deploy.Target{Name: name}
|
|
if chkpoint.Config != nil {
|
|
targ.Config = *chkpoint.Config
|
|
}
|
|
return targ, snap
|
|
}
|