Beispiel #1
0
func TestPendingInstanceFailed(t *testing.T) {
	var (
		store = instanceSetup()

		ins1, _ = store.RegisterInstance("bat", "128af9", "web", "default")
		ins2, _ = store.GetInstance(ins1.ID)
	)

	if _, err := ins1.Failed("9.9.9.8", errors.New("fail1")); err != nil {
		t.Fatal(err)
	}

	_, err := ins2.Failed("9.9.9.9", errors.New("fail2"))
	if !cp.IsErrRevMismatch(err) {
		t.Fatalf("expected REV_MISMATCH, got: %q", err)
	}

	ins, _ := store.GetInstance(ins1.ID)

	if ins.Status != InsStatusFailed {
		t.Fatalf("expected status to be failed, got %q", ins.Status)
	}

	if info, _ := ins.GetStatusInfo(); strings.Contains(info, "fail2") {
		t.Fatalf("expected info not to include 'fail2', got %q", info)
	}
}
Beispiel #2
0
// Claim locks the instance to the specified host.
func (i *Instance) Claim(host string) (*Instance, error) {
	done, err := i.IsDone()
	if err != nil {
		return nil, err
	}
	if done {
		return nil, errorf(ErrUnauthorized, "%s is done", i)
	}

	//
	//   instances/
	//       6868/
	//           claims/
	// +             10.0.0.1 = 2012-07-19 16:22 UTC
	//           object = <app> <rev> <proc>
	// -         start  =
	// +         start  = 10.0.0.1
	//
	f, err := i.dir.GetFile(startPath, new(cp.ListCodec))
	if err != nil {
		return nil, err
	}
	fields := f.Value.([]string)
	if len(fields) > 0 {
		return nil, errorf(ErrInsClaimed, "%s already claimed", i)
	}
	d := i.dir.Join(f)

	d, err = d.Set(startPath, host)
	if err != nil {
		if cp.IsErrRevMismatch(err) {
			err = errorf(ErrInsClaimed, "%s already claimed", i)
		}
		return i, err
	}

	claimed := time.Now()
	d, err = i.claimDir().Join(d).Set(host, formatTime(claimed))
	if err != nil {
		return nil, err
	}
	i.Claimed = claimed
	i.dir = i.dir.Join(d)
	return i, err
}