Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
merge refactoring
Browse files Browse the repository at this point in the history
add a commons package for templating and Logger interface
core metrics, webhook and memory have their own pakage
move store, models, outside of core
  • Loading branch information
vjeantet committed Nov 25, 2017
1 parent 1aefd24 commit 461799b
Show file tree
Hide file tree
Showing 74 changed files with 622 additions and 858 deletions.
2 changes: 1 addition & 1 deletion api/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin"
uuid "github.com/nu7hatch/gouuid"
"github.com/vjeantet/bitfan/core"
"github.com/vjeantet/bitfan/core/models"
"github.com/vjeantet/bitfan/api/models"
"github.com/vjeantet/bitfan/entrypoint/parser/logstash"
)

Expand Down
2 changes: 1 addition & 1 deletion api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/dghubble/sling"
"github.com/vjeantet/bitfan/core/models"
"github.com/vjeantet/bitfan/api/models"
)

type RestClient struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions api/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/mitchellh/mapstructure"
uuid "github.com/nu7hatch/gouuid"
"github.com/vjeantet/bitfan/core"
"github.com/vjeantet/bitfan/core/models"
"github.com/vjeantet/bitfan/api/models"
"github.com/vjeantet/bitfan/entrypoint"
"github.com/vjeantet/jodaTime"
)
Expand Down Expand Up @@ -108,16 +108,15 @@ func (p *PipelineApiController) startPipelineByUUID(UUID string) error {
return err
}

ppl := loc.ConfigPipeline()
ppl.Name = tPipeline.Label
ppl.Uuid = tPipeline.Uuid

agt, err := loc.ConfigAgents()
ppl, err := loc.Pipeline()
if err != nil {
return err
}

nUUID, err := core.StartPipeline(&ppl, agt)
ppl.Label = tPipeline.Label
ppl.Uuid = tPipeline.Uuid

nUUID, err := ppl.Start()
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"x-go-name": "Uuid"
}
},
"x-go-package": "github.com/vjeantet/bitfan/core/models"
"x-go-package": "github.com/vjeantet/bitfan/api/models"
},
"Error": {
"description": "A Error is ....\n\nA Error can have.....",
Expand All @@ -47,7 +47,7 @@
"x-go-name": "Message"
}
},
"x-go-package": "github.com/vjeantet/bitfan/core/models"
"x-go-package": "github.com/vjeantet/bitfan/api/models"
},
"Pipeline": {
"description": "A Pipeline is ....\n\nA Pipeline can have.....",
Expand Down Expand Up @@ -100,7 +100,7 @@
"x-go-name": "Uuid"
}
},
"x-go-package": "github.com/vjeantet/bitfan/core/models"
"x-go-package": "github.com/vjeantet/bitfan/api/models"
},
"processorDoc": {
"description": "A Doc is ....\n\nA Doc can have.....",
Expand Down Expand Up @@ -198,7 +198,7 @@
"x-go-name": "Ports"
}
},
"x-go-package": "github.com/vjeantet/bitfan/core/models"
"x-go-package": "github.com/vjeantet/bitfan/api/models"
}
}
}
31 changes: 22 additions & 9 deletions cmd/bitfan/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ When no configuration is passed to the command, bitfan use the config set in glo

if !viper.GetBool("no-network") {
opt.HttpHandlers = append(opt.HttpHandlers, core.HTTPHandler("/api/v2/", api.Handler("api/v2")))

if viper.IsSet("prometheus") {
opt.HttpHandlers = append(opt.HttpHandlers, core.PrometheusServer(viper.GetString("prometheus.path")))
opt.Prometheus = viper.GetString("prometheus.path")
}
}

Expand Down Expand Up @@ -116,20 +117,32 @@ When no configuration is passed to the command, bitfan use the config set in glo
}
}

for _, loc := range entrypoints.Items {
agt, err := loc.ConfigAgents()

for _, ep := range entrypoints.Items {
ppl, err := ep.Pipeline()
if err != nil {
core.Log().Errorf("Error : %s %v", loc.Path, err)
os.Exit(2)
core.Log().Fatalln(err)
}
ppl := loc.ConfigPipeline()
_, err = core.StartPipeline(&ppl, agt)

nUUID, err := ppl.Start()
if err != nil {
core.Log().Errorf("error: %v", err)
os.Exit(1)
}
core.Log().Infof("Pipeline started %s (%s)", ppl.Name, ppl.Uuid)
core.Log().Infof("Pipeline started %s (%s)(%s)", ppl.Label, ppl.Uuid, nUUID)

// agt, err := ep.ConfigAgents()

// if err != nil {
// core.Log().Errorf("Error : %s %v", ep.Path, err)
// os.Exit(2)
// }
// ppl := ep.ConfigPipeline()
// _, err = core.StartPipeline(&ppl, agt)
// if err != nil {
// core.Log().Errorf("error: %v", err)
// os.Exit(1)
// }
// core.Log().Infof("Pipeline started %s (%s)", ppl.Name, ppl.Uuid)
}

if service.Interactive() {
Expand Down
23 changes: 11 additions & 12 deletions cmd/bitfan/commands/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/spf13/cobra"

"github.com/vjeantet/bitfan/core"
config "github.com/vjeantet/bitfan/core/config"
"github.com/vjeantet/bitfan/entrypoint"
)

Expand Down Expand Up @@ -58,17 +56,18 @@ var testCmd = &cobra.Command{
}

func testConfigContent(loc *entrypoint.Entrypoint) error {
configAgents, err := loc.ConfigAgents()
if err != nil {
return err
}
// TODO : refactor with pipeline
// configAgents, err := loc.ConfigAgents()
// if err != nil {
// return err
// }

configAgentsOrdered := config.Sort(configAgents, config.SortInputsFirst)
for _, configAgent := range configAgentsOrdered {
if _, err := core.NewAgent(configAgent); err != nil {
return err
}
}
// configAgentsOrdered := config.Sort(configAgents, config.SortInputsFirst)
// for _, configAgent := range configAgentsOrdered {
// if _, err := core.NewAgent(configAgent); err != nil {
// return err
// }
// }

return nil
}
2 changes: 1 addition & 1 deletion cmd/bitfanUI/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
sessions "github.com/tommy351/gin-sessions"

"github.com/vjeantet/bitfan/api/client"
"github.com/vjeantet/bitfan/core/models"
"github.com/vjeantet/bitfan/api/models"
)

var apiClient *client.RestClient
Expand Down
8 changes: 4 additions & 4 deletions codecs/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"io"

"github.com/vjeantet/bitfan/codecs/csv"
"github.com/vjeantet/bitfan/codecs/w3c"
"github.com/vjeantet/bitfan/codecs/json"
"github.com/vjeantet/bitfan/codecs/jsonlines"
"github.com/vjeantet/bitfan/codecs/lib"
"github.com/vjeantet/bitfan/codecs/line"
"github.com/vjeantet/bitfan/codecs/multiline"
"github.com/vjeantet/bitfan/codecs/plain"
"github.com/vjeantet/bitfan/codecs/rubydebug"
"github.com/vjeantet/bitfan/codecs/w3c"
"github.com/vjeantet/bitfan/commons"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/ianaindex"
)
Expand Down Expand Up @@ -49,11 +49,11 @@ type Codec struct {
Role string
Charset string
Options map[string]interface{}
logger lib.Logger
logger commons.Logger
configWorkingLocation string
}

func New(name string, conf map[string]interface{}, logger lib.Logger, cwl string) *Codec {
func New(name string, conf map[string]interface{}, logger commons.Logger, cwl string) *Codec {
c := &Codec{
Name: name,
Charset: "utf-8",
Expand Down
6 changes: 3 additions & 3 deletions codecs/csv/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"

"github.com/mitchellh/mapstructure"
"github.com/vjeantet/bitfan/codecs/lib"
"github.com/vjeantet/bitfan/commons"
)

type decoder struct {
Expand All @@ -17,7 +17,7 @@ type decoder struct {
columnnames []string
options decoderOptions
comma rune
log lib.Logger
log commons.Logger
title bool
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func NewDecoder(r io.Reader) *decoder {

return d
}
func (d *decoder) SetOptions(conf map[string]interface{}, logger lib.Logger, cwl string) error {
func (d *decoder) SetOptions(conf map[string]interface{}, logger commons.Logger, cwl string) error {
d.log = logger

if err := mapstructure.Decode(conf, &d.options); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions codecs/csv/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/vjeantet/bitfan/codecs/lib"
"github.com/vjeantet/bitfan/commons"
)

func TestDefaultSettings(t *testing.T) {
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestWithCustomColumns(t *testing.T) {
"columns": []string{"user_defined_1", "user_defined_2"},
"comment": "#",
}
var l lib.Logger
var l commons.Logger
err := d.SetOptions(conf, l, "")
assert.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions codecs/decoder.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package codecs

import "github.com/vjeantet/bitfan/codecs/lib"
import "github.com/vjeantet/bitfan/commons"

type Decoder interface {
Decode(*interface{}) error
SetOptions(map[string]interface{}, lib.Logger, string) error
SetOptions(map[string]interface{}, commons.Logger, string) error
More() bool
}
4 changes: 2 additions & 2 deletions codecs/encoder.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package codecs

import "github.com/vjeantet/bitfan/codecs/lib"
import "github.com/vjeantet/bitfan/commons"

type Encoder interface {
Encode(map[string]interface{}) error
SetOptions(map[string]interface{}, lib.Logger, string) error
SetOptions(map[string]interface{}, commons.Logger, string) error
}
6 changes: 3 additions & 3 deletions codecs/json/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"io"

"github.com/mitchellh/mapstructure"
"github.com/vjeantet/bitfan/codecs/lib"
"github.com/vjeantet/bitfan/commons"
)

type decoder struct {
d *json.Decoder
options decoderOptions

log lib.Logger
log commons.Logger
}

type decoderOptions struct {
Expand All @@ -33,7 +33,7 @@ func NewDecoder(r io.Reader) *decoder {
options: decoderOptions{},
}
}
func (d *decoder) SetOptions(conf map[string]interface{}, logger lib.Logger, cwl string) error {
func (d *decoder) SetOptions(conf map[string]interface{}, logger commons.Logger, cwl string) error {
d.log = logger

err := mapstructure.Decode(conf, &d.options)
Expand Down
4 changes: 2 additions & 2 deletions codecs/json/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"

"github.com/mitchellh/mapstructure"
"github.com/vjeantet/bitfan/codecs/lib"
"github.com/vjeantet/bitfan/commons"
)

type encoder struct {
Expand All @@ -31,7 +31,7 @@ func NewEncoder(w io.Writer) *encoder {
return e
}

func (e *encoder) SetOptions(conf map[string]interface{}, logger lib.Logger, cwl string) error {
func (e *encoder) SetOptions(conf map[string]interface{}, logger commons.Logger, cwl string) error {
if err := mapstructure.Decode(conf, &e.options); err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions codecs/jsonlines/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"strings"

"github.com/mitchellh/mapstructure"
"github.com/vjeantet/bitfan/codecs/lib"
"github.com/vjeantet/bitfan/commons"
)

type decoder struct {
more bool
r *bufio.Scanner
options decoderOptions

log lib.Logger
log commons.Logger
}

type decoderOptions struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func NewDecoder(r io.Reader) *decoder {
return d
}

func (d *decoder) SetOptions(conf map[string]interface{}, logger lib.Logger, cwl string) error {
func (d *decoder) SetOptions(conf map[string]interface{}, logger commons.Logger, cwl string) error {
d.log = logger

return mapstructure.Decode(conf, &d.options)
Expand Down
7 changes: 0 additions & 7 deletions codecs/lib/log_test.go

This file was deleted.

6 changes: 3 additions & 3 deletions codecs/line/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/mitchellh/mapstructure"
"github.com/vjeantet/bitfan/codecs/lib"
"github.com/vjeantet/bitfan/commons"
)

// doc decoder
Expand All @@ -16,7 +16,7 @@ type decoder struct {
r *bufio.Scanner
options decoderOptions

log lib.Logger
log commons.Logger
}

// doc decoderOptions
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewDecoder(r io.Reader) *decoder {
return d
}

func (d *decoder) SetOptions(conf map[string]interface{}, logger lib.Logger, cwl string) error {
func (d *decoder) SetOptions(conf map[string]interface{}, logger commons.Logger, cwl string) error {
d.log = logger

return mapstructure.Decode(conf, &d.options)
Expand Down
Loading

0 comments on commit 461799b

Please sign in to comment.