Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Commit

Permalink
default policy for slaDrainHosts (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhattan86 authored Nov 2, 2021
1 parent 9074307 commit 5d09986
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
12 changes: 12 additions & 0 deletions realis_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ func (c *Client) SLADrainHosts(policy *aurora.SlaPolicy, timeout int64, hosts ..
return nil, errors.New("no hosts provided to drain")
}

if policy == nil || policy.CountSetFieldsSlaPolicy() == 0 {
policy = &defaultSlaPolicy
c.logger.Printf("Warning: start draining with default sla policy %v", policy)
}

if timeout < 0 {
c.logger.Printf("Warning: timeout %d secs is invalid, draining with default timeout %d secs",
timeout,
defaultSlaDrainTimeoutSecs)
timeout = defaultSlaDrainTimeoutSecs
}

drainList := aurora.NewHosts()
drainList.HostNames = hosts

Expand Down
10 changes: 10 additions & 0 deletions realis_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/apache/thrift/lib/go/thrift"
"github.com/aurora-scheduler/gorealis/v2/gen-go/apache/aurora"
)

type clientConfig struct {
Expand Down Expand Up @@ -48,6 +49,15 @@ var defaultBackoff = Backoff{
Jitter: 0.1,
}

var defaultSlaPolicy = aurora.SlaPolicy{
PercentageSlaPolicy: &aurora.PercentageSlaPolicy{
Percentage: 66,
DurationSecs: 300,
},
}

const defaultSlaDrainTimeoutSecs = 900

type TransportProtocol int

const (
Expand Down
33 changes: 33 additions & 0 deletions realis_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,39 @@ func TestRealisClient_SLADrainHosts(t *testing.T) {
5*time.Second,
10*time.Second)
assert.NoError(t, err)

// slaDrainHosts goes with default policy if no policy is specified
_, err = r.SLADrainHosts(nil, 30, hosts...)
if err != nil {
fmt.Printf("error: %+v\n", err.Error())
os.Exit(1)
}
hostResults, err = r.MonitorHostMaintenance(
hosts,
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED, aurora.MaintenanceMode_DRAINING},
1*time.Second,
50*time.Second)
assert.Equal(t, map[string]bool{"localhost": true}, hostResults)
assert.NoError(t, err)

_, err = r.EndMaintenance(hosts...)
assert.NoError(t, err)

_, err = r.SLADrainHosts(&aurora.SlaPolicy{}, 30, hosts...)
if err != nil {
fmt.Printf("error: %+v\n", err.Error())
os.Exit(1)
}
hostResults, err = r.MonitorHostMaintenance(
hosts,
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED, aurora.MaintenanceMode_DRAINING},
1*time.Second,
50*time.Second)
assert.Equal(t, map[string]bool{"localhost": true}, hostResults)
assert.NoError(t, err)

_, err = r.EndMaintenance(hosts...)
assert.NoError(t, err)
}

// Test multiple go routines using a single connection
Expand Down

0 comments on commit 5d09986

Please sign in to comment.