The existing `SnapshotProvider` interface does not sufficiently lend itself to reliable persistence of snapshot data. For example, consider the following: - The deployment engine creates a resource - The snapshot provider fails to save the updated snapshot In this scenario, we have no mechanism by which we can discover that the existing snapshot (if any) does not reflect the actual state of the resources managed by the stack, and future updates may operate incorrectly. To address this, these changes split snapshotting into two phases: the `Begin` phase and the `End` phase. A provider that needs to be robust against the scenario described above (or any other scenario that allows for a mutation to the state of the stack that is not persisted) can use the `Begin` phase to persist the fact that there are outstanding mutations to the stack. It would then use the `End` phase to persist the updated snapshot and indicate that the mutation is no longer outstanding. These steps are somewhat analogous to the prepare and commit phases of two-phase commit.
29 lines
734 B
Go
29 lines
734 B
Go
// Copyright 2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package engine
|
|
|
|
import (
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
)
|
|
|
|
type Engine struct {
|
|
Targets TargetProvider
|
|
Snapshots SnapshotProvider
|
|
}
|
|
|
|
// TargetProvider abstracts away retriving a target
|
|
type TargetProvider interface {
|
|
GetTarget(name tokens.QName) (*deploy.Target, error)
|
|
}
|
|
|
|
// Mutation abstracts away managing changes to snapshots
|
|
type Mutation interface {
|
|
End(snapshot *deploy.Snapshot) error
|
|
}
|
|
|
|
// SnapshotProvider abstracts away retrieving and storing snapshots
|
|
type SnapshotProvider interface {
|
|
GetSnapshot(name tokens.QName) (*deploy.Snapshot, error)
|
|
BeginMutation(name tokens.QName) (Mutation, error)
|
|
}
|