2017-08-30 03:24:12 +02:00
|
|
|
// Copyright 2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
2017-08-23 02:15:16 +02:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2017-09-22 04:18:21 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
2017-08-23 02:15:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Engine struct {
|
2017-10-11 22:23:44 +02:00
|
|
|
Targets TargetProvider
|
|
|
|
Snapshots SnapshotProvider
|
2017-08-23 02:15:16 +02:00
|
|
|
}
|
|
|
|
|
2017-10-11 22:23:44 +02:00
|
|
|
// TargetProvider abstracts away retriving a target
|
|
|
|
type TargetProvider interface {
|
|
|
|
GetTarget(name tokens.QName) (*deploy.Target, error)
|
|
|
|
}
|
|
|
|
|
2017-10-23 19:11:09 +02:00
|
|
|
// SnapshotMutation abstracts away managing changes to snapshots
|
|
|
|
type SnapshotMutation interface {
|
2017-11-21 02:38:09 +01:00
|
|
|
// End indicates that the current mutation has completed and that its results (given by snapshot) should be
|
|
|
|
// persisted. See the comments on SnapshotProvider.BeginMutation for more details.
|
2017-10-21 18:31:01 +02:00
|
|
|
End(snapshot *deploy.Snapshot) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// SnapshotProvider abstracts away retrieving and storing snapshots
|
2017-10-11 22:23:44 +02:00
|
|
|
type SnapshotProvider interface {
|
|
|
|
GetSnapshot(name tokens.QName) (*deploy.Snapshot, error)
|
2017-10-23 19:11:09 +02:00
|
|
|
|
2017-11-21 02:38:09 +01:00
|
|
|
// BeginMutation and SnapshotMutation.End allow a snapshot provider to be robust in the face of failures that occur
|
|
|
|
// between the points at which they are called. The semantics are as follows:
|
|
|
|
// 1. The engine calls `SnapshotProvider.Begin` to indicate that it is about to mutate the state of the
|
|
|
|
// resources tracked by the snapshot.
|
2017-10-23 19:11:09 +02:00
|
|
|
// 2. The engine mutates the state of the resoures tracked by the snapshot.
|
2017-11-21 02:38:09 +01:00
|
|
|
// 3. The engine calls `SnapshotMutation.End` with the new snapshot to indicate that the mutation(s) it was
|
|
|
|
// performing has/have finished.
|
|
|
|
// During (1), the snapshot provider should record the fact that any currently persisted snapshot is being mutated
|
|
|
|
// and cannot be assumed to represent the actual state of the system. This ensures that if the engine crashes during
|
|
|
|
// (2), then the current snapshot is known to be unreliable. During (3), the snapshot provider should persist the
|
|
|
|
// provided snapshot and record that it is known to be reliable.
|
2017-10-23 19:11:09 +02:00
|
|
|
BeginMutation(name tokens.QName) (SnapshotMutation, error)
|
2017-08-30 03:19:10 +02:00
|
|
|
}
|