Skip to content

Commit

Permalink
Merge github.com/mattbaird/elastigo
Browse files Browse the repository at this point in the history
Conflicts:
	lib/indicesputmapping.go
  • Loading branch information
svipy9 committed Feb 24, 2016
2 parents 4e634f5 + 7dc47d2 commit f6f4105
Show file tree
Hide file tree
Showing 37 changed files with 1,999 additions and 715 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
elastigo v2.0
-------------

[![Build Status](https://drone.io/github.com/mattbaird/elastigo/status.png)](https://drone.io/github.com/mattbaird/elastigo/latest)
[![Total views](https://sourcegraph.com/api/repos/github.com/mattbaird/elastigo/counters/views.png)](https://sourcegraph.com/github.com/mattbaird/elastigo)
[![Build Status](https://drone.io/github.com/mattbaird/elastigo/status.png)](https://drone.io/github.com/mattbaird/elastigo)

Big thanks to @alicebob for helping to get the drone.io CI working (note: the badge is being cached, known issue).

Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Vagrant.configure("2") do |config|
vb.gui = false
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
# This allows symlinks to be created within the /vagrant root directory,
# This allows symlinks to be created within the /vagrant root directory,
# which is something librarian-puppet needs to be able to do. This might
# be enabled by default depending on what version of VirtualBox is used.
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
Expand Down
23 changes: 16 additions & 7 deletions lib/baserequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,24 @@ func (c *Conn) DoCommand(method string, url string, args map[string]interface{},
}
}

// uncomment this to print out the request that hits the wire
// (requires net/http/httputil)
//reqbuf, err := httputil.DumpRequest(req.Request, true)
//log.Println(fmt.Sprintf("\n========= req:\nURL: %s\n%s", req.URL, bytes.NewBuffer(reqbuf).String()))

// Copy request body for tracer
if c.RequestTracer != nil {
requestBody, err := ioutil.ReadAll(req.Body)
if err != nil {
return body, err
}
rbody := ""
if req.Body != nil {
requestBody, err := ioutil.ReadAll(req.Body)
if err != nil {
return body, err
}

req.SetBody(bytes.NewReader(requestBody))
c.RequestTracer(req.Method, req.URL.String(), string(requestBody))
req.SetBody(bytes.NewReader(requestBody))
rbody = string(requestBody)
}
c.RequestTracer(req.Method, req.URL.String(), rbody)
}

httpStatusCode, body, err = req.Do(&response)
Expand Down Expand Up @@ -91,7 +100,7 @@ func (e ESError) Error() string {
return fmt.Sprintf("%v: %v [%v]", e.When, e.What, e.Code)
}

// Exists allows the caller to check for the existance of a document using HEAD
// Exists allows the caller to check for the existence of a document using HEAD
// This appears to be broken in the current version of elasticsearch 0.19.10, currently
// returning nothing
func (c *Conn) Exists(index string, _type string, id string, args map[string]interface{}) (BaseResponse, error) {
Expand Down
7 changes: 6 additions & 1 deletion lib/baseresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,14 @@ type ExtendedStatus struct {
ShardsStatus Status `json:"_shards"`
}

type MatchRes struct {
Index string `json:"_index"`
Id string `json:"_id"`
}

type Match struct {
OK bool `json:"ok"`
Matches []string `json:"matches"`
Matches []MatchRes `json:"matches"`
Explanation *Explanation `json:"explanation,omitempty"`
}

Expand Down
32 changes: 18 additions & 14 deletions lib/catindexinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,53 @@ import (

var ErrInvalidIndexLine = errors.New("Cannot parse indexline")

// Create an IndexInfo from the string _cat/indices would produce
//Create an IndexInfo from the string _cat/indices would produce
//EX: health status index pri rep docs.count docs.deleted store.size pri.store.size
//green open logs-2015-06-19 2 0 135389346 0 53048922233 53048922233
func NewCatIndexInfo(indexLine string) (catIndex *CatIndexInfo, err error) {
split := strings.Fields(indexLine)
if len(split) < 4 {
if len(split) < 5 {
return nil, ErrInvalidIndexLine
}
catIndex = &CatIndexInfo{}
catIndex.Store = CatIndexStore{}
catIndex.Docs = CatIndexDocs{}
catIndex.Health = split[0]
catIndex.Name = split[1]
catIndex.Shards, err = strconv.Atoi(split[2])
catIndex.Status = split[1]
catIndex.Name = split[2]
catIndex.Shards, err = strconv.Atoi(split[3])
if err != nil {
catIndex.Shards = 0
}
catIndex.Replicas, err = strconv.Atoi(split[3])
catIndex.Replicas, err = strconv.Atoi(split[4])
if err != nil {
catIndex.Replicas = 0
}
if len(split) == 4 {
if len(split) == 5 {
return catIndex, nil
}
catIndex.Docs.Count, err = strconv.ParseInt(split[4], 10, 64)
catIndex.Docs.Count, err = strconv.ParseInt(split[5], 10, 64)
if err != nil {
catIndex.Docs.Count = 0
}
if len(split) == 5 {
if len(split) == 6 {
return catIndex, nil
}
catIndex.Docs.Deleted, err = strconv.ParseInt(split[5], 10, 64)
catIndex.Docs.Deleted, err = strconv.ParseInt(split[6], 10, 64)
if err != nil {
catIndex.Docs.Deleted = 0
}
if len(split) == 6 {
if len(split) == 7 {
return catIndex, nil
}
catIndex.Store.Size, err = strconv.ParseInt(split[6], 10, 64)
catIndex.Store.Size, err = strconv.ParseInt(split[7], 10, 64)
if err != nil {
catIndex.Store.Size = 0
}
if len(split) == 7 {
if len(split) == 8 {
return catIndex, nil
}
catIndex.Store.PriSize, err = strconv.ParseInt(split[7], 10, 64)
catIndex.Store.PriSize, err = strconv.ParseInt(split[8], 10, 64)
if err != nil {
catIndex.Store.PriSize = 0
}
Expand All @@ -61,7 +64,8 @@ func NewCatIndexInfo(indexLine string) (catIndex *CatIndexInfo, err error) {
// Pull all the index info from the connection
func (c *Conn) GetCatIndexInfo(pattern string) (catIndices []CatIndexInfo) {
catIndices = make([]CatIndexInfo, 0)
args := map[string]interface{}{"bytes": "b"}
//force it to only show the fileds we know about
args := map[string]interface{}{"bytes": "b", "h": "health,status,index,pri,rep,docs.count,docs.deleted,store.size,pri.store.size"}
indices, err := c.DoCommand("GET", "/_cat/indices/"+pattern, args, nil)
if err == nil {
indexLines := strings.Split(string(indices[:]), "\n")
Expand Down
54 changes: 31 additions & 23 deletions lib/catindexinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ func TestCatIndexInfo(t *testing.T) {
_, err := NewCatIndexInfo("red ")
So(err, ShouldNotBeNil)
})
Convey("Create index line from a bad shards index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar a 1 1234 3 11000 13000")
Convey("catIndex Create index line from a bad shards index listing", t, func() {
i, err := NewCatIndexInfo("green open logs-2015-06-19 2 1 135389346 20 53048922233 53048922233")
So(err, ShouldBeNil)
So(i.Health, ShouldEqual, "red")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 0)
So(i.Health, ShouldEqual, "green")
So(i.Status, ShouldEqual, "open")
So(i.Name, ShouldEqual, "logs-2015-06-19")
So(i.Shards, ShouldEqual, 2)
So(i.Replicas, ShouldEqual, 1)
So(i.Docs.Count, ShouldEqual, 1234)
So(i.Docs.Deleted, ShouldEqual, 3)
So(i.Store.Size, ShouldEqual, 11000)
So(i.Store.PriSize, ShouldEqual, 13000)
So(i.Docs.Count, ShouldEqual, 135389346)
So(i.Docs.Deleted, ShouldEqual, 20)
So(i.Store.Size, ShouldEqual, 53048922233)
So(i.Store.PriSize, ShouldEqual, 53048922233)
})
Convey("Create index line from a bad replicas index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar 2 a 1234 3 11000 13000")
Convey("catIndex Create index line from a bad replicas index listing", t, func() {
i, err := NewCatIndexInfo("red open foo-2000-01-01-bar 2 0 1234 3 11000 13000")
So(err, ShouldBeNil)
So(i.Health, ShouldEqual, "red")
So(i.Status, ShouldEqual, "open")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 2)
So(i.Replicas, ShouldEqual, 0)
Expand All @@ -34,9 +36,10 @@ func TestCatIndexInfo(t *testing.T) {
So(i.Store.Size, ShouldEqual, 11000)
So(i.Store.PriSize, ShouldEqual, 13000)
})
Convey("Create index line from a complete index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar 2 1 1234 3 11000 13000")
Convey("catIndex Create index line from a complete index listing", t, func() {
i, err := NewCatIndexInfo("red closed foo-2000-01-01-bar 2 1 1234 3 11000 13000")
So(err, ShouldBeNil)
So(i.Status, ShouldEqual, "closed")
So(i.Health, ShouldEqual, "red")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 2)
Expand All @@ -46,10 +49,11 @@ func TestCatIndexInfo(t *testing.T) {
So(i.Store.Size, ShouldEqual, 11000)
So(i.Store.PriSize, ShouldEqual, 13000)
})
Convey("Create index line from a bad docs index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar 2 1 a 3 11000 13000")
Convey("catIndex Create index line from a bad docs index listing", t, func() {
i, err := NewCatIndexInfo("red open foo-2000-01-01-bar 2 1 a 3 11000 13000")
So(err, ShouldBeNil)
So(i.Health, ShouldEqual, "red")
So(i.Status, ShouldEqual, "open")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 2)
So(i.Replicas, ShouldEqual, 1)
Expand All @@ -58,10 +62,11 @@ func TestCatIndexInfo(t *testing.T) {
So(i.Store.Size, ShouldEqual, 11000)
So(i.Store.PriSize, ShouldEqual, 13000)
})
Convey("Create index line from a bad deletes index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar 2 1 1234 a 11000 13000")
Convey("catIndex Create index line from a bad deletes index listing", t, func() {
i, err := NewCatIndexInfo("red open foo-2000-01-01-bar 2 1 1234 a 11000 13000")
So(err, ShouldBeNil)
So(i.Health, ShouldEqual, "red")
So(i.Status, ShouldEqual, "open")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 2)
So(i.Replicas, ShouldEqual, 1)
Expand All @@ -70,10 +75,11 @@ func TestCatIndexInfo(t *testing.T) {
So(i.Store.Size, ShouldEqual, 11000)
So(i.Store.PriSize, ShouldEqual, 13000)
})
Convey("Create index line from a kinda short index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar 2 1 1234")
Convey("catIndex Create index line from a kinda short index listing", t, func() {
i, err := NewCatIndexInfo("red open foo-2000-01-01-bar 2 1 1234")
So(err, ShouldBeNil)
So(i.Health, ShouldEqual, "red")
So(i.Status, ShouldEqual, "open")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 2)
So(i.Replicas, ShouldEqual, 1)
Expand All @@ -82,10 +88,11 @@ func TestCatIndexInfo(t *testing.T) {
So(i.Store.Size, ShouldEqual, 0)
So(i.Store.PriSize, ShouldEqual, 0)
})
Convey("Create index line from a kinda sorta short index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar 2 1 1234 3")
Convey("catIndex Create index line from a kinda sorta short index listing", t, func() {
i, err := NewCatIndexInfo("red open foo-2000-01-01-bar 2 1 1234 3")
So(err, ShouldBeNil)
So(i.Health, ShouldEqual, "red")
So(i.Status, ShouldEqual, "open")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 2)
So(i.Replicas, ShouldEqual, 1)
Expand All @@ -94,10 +101,11 @@ func TestCatIndexInfo(t *testing.T) {
So(i.Store.Size, ShouldEqual, 0)
So(i.Store.PriSize, ShouldEqual, 0)
})
Convey("Create index line from a short index listing", t, func() {
i, err := NewCatIndexInfo("red foo-2000-01-01-bar 2 1")
Convey("catIndex Create index line from a short index listing", t, func() {
i, err := NewCatIndexInfo("red open foo-2000-01-01-bar 2 1")
So(err, ShouldBeNil)
So(i.Health, ShouldEqual, "red")
So(i.Status, ShouldEqual, "open")
So(i.Name, ShouldEqual, "foo-2000-01-01-bar")
So(i.Shards, ShouldEqual, 2)
So(i.Replicas, ShouldEqual, 1)
Expand Down
Loading

0 comments on commit f6f4105

Please sign in to comment.