2017-03-06 22:59:24 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
"google.golang.org/api/container/v1beta1"
|
2017-03-06 22:59:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ContainerOperationWaiter struct {
|
2018-12-27 01:42:37 +00:00
|
|
|
Service *container.Service
|
|
|
|
Op *container.Operation
|
2018-04-05 21:51:35 +00:00
|
|
|
Project string
|
|
|
|
Location string
|
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *ContainerOperationWaiter) State() string {
|
|
|
|
return w.Op.Status
|
2017-03-06 22:59:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *ContainerOperationWaiter) Error() error {
|
|
|
|
if w.Op.StatusMessage != "" {
|
|
|
|
return fmt.Errorf(w.Op.StatusMessage)
|
2018-04-05 21:51:35 +00:00
|
|
|
}
|
2018-12-27 01:42:37 +00:00
|
|
|
return nil
|
2018-04-05 21:51:35 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *ContainerOperationWaiter) SetOp(op interface{}) error {
|
|
|
|
w.Op = op.(*container.Operation)
|
|
|
|
return nil
|
2017-03-06 22:59:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *ContainerOperationWaiter) QueryOp() (interface{}, error) {
|
|
|
|
name := fmt.Sprintf("projects/%s/locations/%s/operations/%s",
|
|
|
|
w.Project, w.Location, w.Op.Name)
|
|
|
|
return w.Service.Projects.Locations.Operations.Get(name).Do()
|
2018-04-05 21:51:35 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *ContainerOperationWaiter) OpName() string {
|
|
|
|
return w.Op.Name
|
|
|
|
}
|
2017-03-06 22:59:24 +00:00
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *ContainerOperationWaiter) PendingStates() []string {
|
|
|
|
return []string{"PENDING", "RUNNING"}
|
2018-04-05 21:51:35 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *ContainerOperationWaiter) TargetStates() []string {
|
|
|
|
return []string{"DONE"}
|
|
|
|
}
|
2018-06-08 23:04:55 +00:00
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func containerOperationWait(config *Config, op *container.Operation, project, location, activity string, timeoutMinutes int) error {
|
|
|
|
w := &ContainerOperationWaiter{
|
2018-04-05 21:51:35 +00:00
|
|
|
Service: config.clientContainerBeta,
|
|
|
|
Op: op,
|
|
|
|
Project: project,
|
|
|
|
Location: location,
|
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
if err := w.SetOp(op); err != nil {
|
|
|
|
return err
|
2018-03-07 01:44:05 +00:00
|
|
|
}
|
2018-12-27 01:42:37 +00:00
|
|
|
return OperationWait(w, activity, timeoutMinutes)
|
2018-03-07 01:44:05 +00:00
|
|
|
}
|