Skip to content

Commit

Permalink
lib/scheduler: further simplify revive/suppress APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
James DeFelice committed Sep 15, 2017
1 parent c10cbad commit 9d5cb64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 44 deletions.
43 changes: 19 additions & 24 deletions api/v1/lib/scheduler/calls/calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,39 +200,34 @@ func OpDestroy(rs ...mesos.Resource) mesos.Offer_Operation {
}
}

// OfferFlowControl is a marker interface for Call subtypes that adjust offer throttling.
type OfferFlowControl interface {
SetRoles(roles ...string)
// Revive returns a revive call.
// Callers are expected to fill in the FrameworkID.
func Revive() *scheduler.Call {
return &scheduler.Call{Type: scheduler.Call_REVIVE}
}

// OfferFlowOpt configures OfferFlowControl.
type OfferFlowOpt func(OfferFlowControl)

// Roles configures the roles for an OfferFlowControl.
func Roles(roles ...string) OfferFlowOpt { return func(ofc OfferFlowControl) { ofc.SetRoles(roles...) } }

// Revive returns a revive call.
// Revive returns a revive call with the given filters.
// Callers are expected to fill in the FrameworkID.
func Revive(opts ...OfferFlowOpt) (c *scheduler.Call) {
c = &scheduler.Call{Type: scheduler.Call_REVIVE, Revive: &scheduler.Call_Revive{}}
for _, f := range opts {
if f != nil {
f(c.Revive)
}
func ReviveWith(roles []string) *scheduler.Call {
return &scheduler.Call{
Type: scheduler.Call_REVIVE,
Revive: &scheduler.Call_Revive{Roles: roles},
}
return
}

// Suppress returns a suppress call.
// Callers are expected to fill in the FrameworkID.
func Suppress(opts ...OfferFlowOpt) (c *scheduler.Call) {
c = &scheduler.Call{Type: scheduler.Call_SUPPRESS, Suppress: &scheduler.Call_Suppress{}}
for _, f := range opts {
if f != nil {
f(c.Suppress)
}
func Suppress() *scheduler.Call {
return &scheduler.Call{Type: scheduler.Call_SUPPRESS}
}

// Suppress returns a suppress call with the given filters.
// Callers are expected to fill in the FrameworkID.
func SuppressWith(roles []string) *scheduler.Call {
return &scheduler.Call{
Type: scheduler.Call_SUPPRESS,
Suppress: &scheduler.Call_Suppress{Roles: roles},
}
return
}

// Decline returns a decline call with the given parameters.
Expand Down
15 changes: 9 additions & 6 deletions api/v1/lib/scheduler/calls/calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ func TestRole(t *testing.T) {
call *scheduler.Call
roles []string
}{
{calls.Revive(calls.Roles()), rolesNone},
{calls.Suppress(calls.Roles()), rolesNone},
{calls.Revive(), rolesNone},
{calls.Suppress(), rolesNone},

{calls.Revive(calls.Roles(roleX...)), roleX},
{calls.Suppress(calls.Roles(roleX...)), roleX},
{calls.ReviveWith(nil), rolesNone},
{calls.SuppressWith(nil), rolesNone},

{calls.ReviveWith(roleX), roleX},
{calls.SuppressWith(roleX), roleX},
} {
roles, hasRole := func() ([]string, bool) {
switch tc.call.Type {
case scheduler.Call_SUPPRESS:
return tc.call.Suppress.GetRoles(), len(tc.call.Suppress.Roles) > 0
return tc.call.GetSuppress().GetRoles(), len(tc.call.GetSuppress().GetRoles()) > 0
case scheduler.Call_REVIVE:
return tc.call.Revive.GetRoles(), len(tc.call.Revive.Roles) > 0
return tc.call.GetRevive().GetRoles(), len(tc.call.GetRevive().GetRoles()) > 0
default:
panic(fmt.Sprintf("test case %d failed: unsupported call type: %v", ti, tc.call.Type))
}
Expand Down
14 changes: 0 additions & 14 deletions api/v1/lib/scheduler/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,3 @@ func (co CallOptions) Copy() CallOptions {
copy(x, co)
return x
}

// SetRoles implements calls.OfferFlowControl
func (c *Call_Revive) SetRoles(roles ...string) {
if c != nil {
c.Roles = roles
}
}

// SetRoles implements calls.OfferFlowControl
func (c *Call_Suppress) SetRoles(roles ...string) {
if c != nil {
c.Roles = roles
}
}

0 comments on commit 9d5cb64

Please sign in to comment.