// Phase returns the current migration.Phase for the supplied model UUID.
778387
func (facade *Facade) Phase(uuid string) (migration.Phase, error) {
	results := params.PhaseResults{}
	err := facade.call("Phase", uuid, &results)
	if err != nil {
		return migration.UNKNOWN, errors.Trace(err)
	}
	if count := len(results.Results); count != 1 {
		return migration.UNKNOWN, countError(count)
	}
	result := results.Results[0]
	if result.Error != nil {
		return migration.UNKNOWN, errors.Trace(result.Error)
	}
	phase, ok := migration.ParsePhase(result.Phase)
	if !ok {
		err := errors.Errorf("unknown phase %q", result.Phase)
		return migration.UNKNOWN, err
	}
	return phase, nil
}
670057
func (f *Formatter) Format(dst io.Writer, src []byte) error {
	return newFormatterState(f, dst).format(dst, src)
}
681979
func CanTransitionPhase(current, next appsv1.DeploymentStatus) bool {
	switch current {
	case appsv1.DeploymentStatusNew:
		switch next {
		case appsv1.DeploymentStatusPending,
			appsv1.DeploymentStatusRunning,
			appsv1.DeploymentStatusFailed,
			appsv1.DeploymentStatusComplete:
			return true
		}
	case appsv1.DeploymentStatusPending:
		switch next {
		case appsv1.DeploymentStatusRunning,
			appsv1.DeploymentStatusFailed,
			appsv1.DeploymentStatusComplete:
			return true
		}
	case appsv1.DeploymentStatusRunning:
		switch next {
		case appsv1.DeploymentStatusFailed, appsv1.DeploymentStatusComplete:
			return true
		}
	}
	return false
}
951753
func (uuid UUID) Version() (Version, bool) {
	if len(uuid) != 16 {
		return 0, false
	}
	return Version(uuid[6] >> 4), true
}
792065
func (r ResourceInstance) Phase(rpt ResourceInstancePhaseType) ResourceInstancePhase {
	return ResourceInstancePhase{
		ResourceInstance: r,
		Phase:            rpt,
	}
}
68654
func (shim *backend) MigrationPhase() (migration.Phase, error) {
	mig, err := shim.st.LatestMigration()
	if errors.IsNotFound(err) {
		return migration.NONE, nil
	} else if err != nil {
		return migration.UNKNOWN, errors.Trace(err)
	}
	phase, err := mig.Phase()
	if err != nil {
		return migration.UNKNOWN, errors.Trace(err)
	}
	return phase, nil
}
1187141
func (s *BuildPhase) SetPhaseType(v string) *BuildPhase {
	s.PhaseType = &v
	return s
}
1146628
func (a *APIAddresser) ModelUUID() params.StringResult {
	return params.StringResult{Result: a.getter.ModelUUID()}
}
1020712
func ParsePhase(target string) (Phase, bool) {
	for p, name := range phaseNames {
		if target == name {
			return Phase(p), true
		}
	}
	return UNKNOWN, false
}
1249557
func (wr *Wrangler) MigrateServedFrom(ctx context.Context, keyspace, shard string, servedType topodatapb.TabletType, cells []string, reverse bool, filteredReplicationWaitTime time.Duration) (err error) {
	// read the destination keyspace, check it
	ki, err := wr.ts.GetKeyspace(ctx, keyspace)
	if err != nil {
		return err
	}
	if len(ki.ServedFroms) == 0 {
		return fmt.Errorf("destination keyspace %v is not a vertical split target", keyspace)
	}

	// read the destination shard, check it
	si, err := wr.ts.GetShard(ctx, keyspace, shard)
	if err != nil {
		return err
	}
	if len(si.SourceShards) != 1 || len(si.SourceShards[0].Tables) == 0 {
		return fmt.Errorf("destination shard %v/%v is not a vertical split target", keyspace, shard)
	}

	// check the migration is valid before locking (will also be checked
	// after locking to be sure)
	sourceKeyspace := si.SourceShards[0].Keyspace
	if err := ki.CheckServedFromMigration(servedType, cells, sourceKeyspace, !reverse); err != nil {
		return err
	}

	// lock the keyspaces, source first.
	ctx, unlock, lockErr := wr.ts.LockKeyspace(ctx, sourceKeyspace, fmt.Sprintf("MigrateServedFrom(%v)", servedType))
	if lockErr != nil {
		return lockErr
	}
	defer unlock(&err)
	ctx, unlock, lockErr = wr.ts.LockKeyspace(ctx, keyspace, fmt.Sprintf("MigrateServedFrom(%v)", servedType))
	if lockErr != nil {
		return lockErr
	}
	defer unlock(&err)

	// execute the migration
	err = wr.migrateServedFromLocked(ctx, ki, si, servedType, cells, reverse, filteredReplicationWaitTime)

	// rebuild the keyspace serving graph if there was no error
	if err == nil {
		err = topotools.RebuildKeyspaceLocked(ctx, wr.logger, wr.ts, keyspace, cells)
	}

	return err
}
54840
func (mr *MockStateMockRecorder) ModelUUID() *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModelUUID", reflect.TypeOf((*MockState)(nil).ModelUUID))
}
412048
func (c *Client) SetPhase(phase migration.Phase) error {
	args := params.SetMigrationPhaseArgs{
		Phase: phase.String(),
	}
	return c.caller.FacadeCall("SetPhase", args, nil)
}
198417
func (e *Runner) AppendPhase(t Phase) {
	e.Phases = append(e.Phases, t)
}
623453
func NewPreflightPhase() workflow.Phase {
	return workflow.Phase{
		Name:    "preflight",
		Short:   "Run pre-flight checks",
		Long:    "Run pre-flight checks for kubeadm init.",
		Example: preflightExample,
		Run:     runPreflight,
		InheritFlags: []string{
			options.CfgPath,
			options.IgnorePreflightErrors,
		},
	}
}
408192
func (m *Mux) Run(phase string, ctx *c.Context) *c.Context {
	return m.Middleware.Run(phase, ctx)
}
718039
func (p Phase) String() string {
	i := int(p)
	if i >= 0 && i < len(phaseNames) {
		return phaseNames[i]
	}
	return "UNKNOWN"
}
349088
func (c *Client) MigrationStatus() (migration.MigrationStatus, error) {
	var empty migration.MigrationStatus
	var status params.MasterMigrationStatus
	err := c.caller.FacadeCall("MigrationStatus", nil, &status)
	if err != nil {
		return empty, errors.Trace(err)
	}

	modelTag, err := names.ParseModelTag(status.Spec.ModelTag)
	if err != nil {
		return empty, errors.Annotatef(err, "parsing model tag")
	}

	phase, ok := migration.ParsePhase(status.Phase)
	if !ok {
		return empty, errors.New("unable to parse phase")
	}

	target := status.Spec.TargetInfo
	controllerTag, err := names.ParseControllerTag(target.ControllerTag)
	if err != nil {
		return empty, errors.Annotatef(err, "parsing controller tag")
	}

	authTag, err := names.ParseUserTag(target.AuthTag)
	if err != nil {
		return empty, errors.Annotatef(err, "unable to parse auth tag")
	}

	var macs []macaroon.Slice
	if target.Macaroons != "" {
		if err := json.Unmarshal([]byte(target.Macaroons), &macs); err != nil {
			return empty, errors.Annotatef(err, "unmarshalling macaroon")
		}
	}

	return migration.MigrationStatus{
		MigrationId:      status.MigrationId,
		ModelUUID:        modelTag.Id(),
		Phase:            phase,
		PhaseChangedTime: status.PhaseChangedTime,
		TargetInfo: migration.TargetInfo{
			ControllerTag: controllerTag,
			Addrs:         target.Addrs,
			CACert:        target.CACert,
			AuthTag:       authTag,
			Password:      target.Password,
			Macaroons:     macs,
		},
	}, nil
}