forked from fabric8-services/fabric8-jenkins-idler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the idler to exclude some deployments from idling
Adds a new api to enable/disable idler for a set of users. Idler can be disbled for a user as follows ``` curl -H "Content-Type: application/json" \ -X POST \ --data '{"disable":["pradkuma-preview2"],"enable":[]}' \ http://idler:8080/api/idler/userstatus/ ``` Use `GET` to fetch the list of currently idled users ``` curl http://idler:8080/api/idler/userstatus/ ``` Resolves - fabric8-services#232
- Loading branch information
1 parent
ce3b1d6
commit 1e985e5
Showing
9 changed files
with
211 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package model | ||
|
||
import ( | ||
cmap "github.com/orcaman/concurrent-map" | ||
) | ||
|
||
// StringSet is a type-safe and concurrent map keeping track of disabled v for idler. | ||
type StringSet struct { | ||
cmap.ConcurrentMap | ||
} | ||
|
||
// NewStringSet creates a new instance of StringSet map. | ||
func NewStringSet() *StringSet { | ||
return &StringSet{cmap.New()} | ||
} | ||
|
||
// Add stores the specified value under the key user. | ||
func (m *StringSet) Add(vs []string) { | ||
for _, v := range vs { | ||
m.ConcurrentMap.Set(v, true) | ||
} | ||
} | ||
|
||
// Remove deletes the specified disabled user from the map. | ||
func (m *StringSet) Remove(vs []string) { | ||
for _, v := range vs { | ||
m.ConcurrentMap.Remove(v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package model | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStringSet_new(t *testing.T) { | ||
s := NewStringSet() | ||
assert.NotNil(t, s, "must return a new object") | ||
} | ||
|
||
func TestStringSet_count(t *testing.T) { | ||
s := NewStringSet() | ||
assert.Equal(t, 0, s.Count(), "must have 0 items") | ||
} | ||
|
||
func TestStringSet_add(t *testing.T) { | ||
s := NewStringSet() | ||
s.Add([]string{"foo", "bar"}) | ||
assert.Equal(t, 2, s.Count()) | ||
} | ||
|
||
func TestStringSet_has(t *testing.T) { | ||
s := NewStringSet() | ||
assert.False(t, s.Has("foo"), "must be empty") | ||
s.Add([]string{"foo", "bar"}) | ||
|
||
assert.True(t, s.Has("foo"), "must be present after adding") | ||
assert.True(t, s.Has("bar"), "must be present after adding") | ||
assert.False(t, s.Has("foobar"), "non existent key seems to be found") | ||
} | ||
|
||
func TestStringSet_remove(t *testing.T) { | ||
s := NewStringSet() | ||
assert.Equal(t, 0, s.Count()) | ||
|
||
s.Add([]string{"foo", "bar"}) | ||
assert.Equal(t, 2, s.Count()) | ||
|
||
s.Remove([]string{"bar"}) | ||
assert.Equal(t, 1, s.Count()) | ||
|
||
assert.False(t, s.Has("bar"), "key that got removed still exists") | ||
} | ||
|
||
func TestStringSet_keys(t *testing.T) { | ||
s := NewStringSet() | ||
|
||
keys := []string{"foo", "bar"} | ||
|
||
s.Add(keys) | ||
|
||
values := s.Keys() | ||
sort.Strings(keys) | ||
sort.Strings(values) | ||
|
||
assert.Equal(t, keys, values) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.