Skip to content

Commit

Permalink
Merge pull request #1 from sjtug/dev
Browse files Browse the repository at this point in the history
vendor & lint & docker image & rlimit_mem
  • Loading branch information
htfy96 authored Aug 16, 2016
2 parents fb6d5f3 + e5f677d commit 205d70f
Show file tree
Hide file tree
Showing 81 changed files with 16,794 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ _testmain.go
*.exe
*.test
*.prof

/.idea
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: go

go:
- 1.5.4
- 1.6.2
- tip

Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM debian
MAINTAINER Zheng Luo <[email protected]>
RUN apt-get update && apt-get install rsync -y
COPY ./lug /lug
WORKDIR /
ENTRYPOINT "/lug"
39 changes: 39 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Godeps/Readme

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ Extensible backend of software mirror. Read our [Wiki](https://github.com/sjtug/
Contributors should push to `dev` branch. Reviewed code will be merged to `master` branch.

1. set your `GOPATH` to a directory: `export GOPATH=/home`
2. `mkdir -p $GOPATH/src/github.com/sjtug/lug && cd $GOPATH/src/github.com/sjtug/lug`
3. `git clone {URL of this repo} . && git checkout dev`
4. `go get github.com/sjtug/lug`, and binary will be built under `$GOPATH/bin`
2. `go get github.com/sjtug/lug`
3. `cd $GOPATH/src/github.com/sjtug/lug && git checkout dev`
4. Modify code, then use native `go build`(>=1.6, or 1.5 with `GO15VENDOREXPERIMENT` env var set) or `godep go build`(<=1.4) after installing [Godep](https://github.com/tools/godep) to build it

NOTICE: Please attach test files when contributing to your module

Used package:
- **Logging**: `github.com/op/go-logging` (Singleton)
- **Test**: Builtin `testing` package and `github.com/stretchr/testify/assert`
- **Yaml**: `gopkg.in/yaml.v2`

## Use it in docker

```
docker run -d -v {{host_path}}:{{docker_path}} -v {{absolute_path_of_config.yaml}}:/config.yaml sjtug/lug
```
11 changes: 3 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ package config

import (
"errors"
"fmt"

"github.com/op/go-logging"
"gopkg.in/yaml.v2"
)

// Config of each repo is represented as a map
// RepoConfig stores config of each repo in a map
type RepoConfig map[string]string

// Configuration of lug
// Config stores all configuration of lug
type Config struct {
// Interval between pollings in manager
Interval int
Expand All @@ -23,7 +22,7 @@ type Config struct {
Repos []RepoConfig
}

// Function to parse config from []byte
// Parse creates config from []byte
func (c *Config) Parse(in []byte) (err error) {
err = yaml.Unmarshal(in, c)
if err == nil {
Expand All @@ -36,7 +35,3 @@ func (c *Config) Parse(in []byte) (err error) {
}
return err
}

func Foo() {
fmt.Println("config")
}
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
}

func TestWrongManagerConfig(t *testing.T) {
var testStr string = `interval: -1
var testStr = `interval: -1
loglevel: 5 # 1 - 5
repos:
- type: rsync
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
LugVersionInfo = `Lug: An extensible backend for software mirror
lugVersionInfo = `Lug: An extensible backend for software mirror
Presented by SJTUG Version 0.1alpha
Visit https://github.com/sjtug/lug for latest version`
Expand All @@ -32,7 +32,7 @@ repos:
name: shell`
)

// Store parsed flags from command line
// CommandFlags stores parsed flags from command line
type CommandFlags struct {
configFile string
version bool
Expand All @@ -59,7 +59,7 @@ func main() {
flags := getFlags()

if flags.version {
fmt.Print(LugVersionInfo)
fmt.Print(lugVersionInfo)
return
}

Expand Down
32 changes: 21 additions & 11 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package manager

import (
"fmt"
"strconv"
"time"

Expand All @@ -12,11 +11,17 @@ import (
)

const (
// SigStart is a signal sent to control channel of manager which starts sync of all container
SigStart = iota
// SigStop is a signal sent to control channel of manager which stops sync of all container
SigStop
// SigExit is a signal sent to control channel of manager which exits manager run loop
SigExit
// ExitFinish is a signal from finish channel of manager indicating exit finished
ExitFinish
// StopFinish is a signal from finish channel of manager indicating stopping job finished
StopFinish
// StartFinish is a signal from finish channel of manager indicating starting job finished
StartFinish
)

Expand All @@ -37,10 +42,16 @@ type Status struct {
WorkerStatus map[string]worker.Status
}

// create a new manager with attached workers from config
// NewManager creates a new manager with attached workers from config
func NewManager(config *config.Config) (*Manager, error) {
newManager := Manager{config, logging.MustGetLogger("manager"),
[]worker.Worker{}, make(chan int), make(chan int), true}
newManager := Manager{
config: config,
logger: logging.MustGetLogger("manager"),
workers: []worker.Worker{},
controlChan: make(chan int),
finishChan: make(chan int),
running: true,
}
for _, repoConfig := range config.Repos {
w, err := worker.NewWorker(repoConfig)
if err != nil {
Expand All @@ -51,7 +62,7 @@ func NewManager(config *config.Config) (*Manager, error) {
return &newManager, nil
}

// Run() will block current routine
// Run will block current routine
func (m *Manager) Run() {
m.logger.Debugf("%p", m)
c := time.Tick(time.Duration(m.config.Interval) * time.Second)
Expand Down Expand Up @@ -140,17 +151,16 @@ func (m *Manager) Exit() {
m.expectChanVal(m.finishChan, ExitFinish)
}

// get Status from a Manager
// GetStatus gets status of Manager
func (m *Manager) GetStatus() *Status {
status := Status{m.running, make(map[string]worker.Status)}
status := Status{
Running: m.running,
WorkerStatus: make(map[string]worker.Status),
}
for _, worker := range m.workers {
wConfig := worker.GetConfig()
wStatus := worker.GetStatus()
status.WorkerStatus[wConfig["name"]] = wStatus
}
return &status
}

func Foo() {
fmt.Println("manager")
}
7 changes: 5 additions & 2 deletions manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
)

func TestManagerStartUp(t *testing.T) {
manager, err := NewManager(&config.Config{3, logging.DEBUG,
[]config.RepoConfig{}})
manager, err := NewManager(&config.Config{
Interval: 3,
LogLevel: logging.DEBUG,
Repos: []config.RepoConfig{},
})
assert.Nil(t, err)
if assert.NotNil(t, manager) {
logging.MustGetLogger("ManagerTest").Debugf("Manager: %+v", manager)
Expand Down
13 changes: 13 additions & 0 deletions vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 205d70f

Please sign in to comment.