Skip to content

Commit

Permalink
Merge pull request #10 from victorcoder/rename
Browse files Browse the repository at this point in the history
Rename project
  • Loading branch information
Victor Castell committed Aug 19, 2015
2 parents a78d2bf + c6bd3c9 commit 11f7d35
Show file tree
Hide file tree
Showing 47 changed files with 154 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .goxc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"outputFormat": "by-file-extension",
"owner": "victorcoder",
"prerelease": true,
"repository": "dcron"
"repository": "dkron"
}
},
"ConfigVersion": "0.9",
Expand Down
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

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

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) Victor Castell

Dcron is an Open Source project licensed under the terms of
Dkron is an Open Source project licensed under the terms of
the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
for license text.
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
etc: bin/etcd -name dcron1
dcron2: godep go run *.go agent -server -node=dcron2 -join=127.0.0.1:5002 -bind=127.0.0.1:5001 -http-addr=:8081
dcron3: godep go run *.go agent -server -node=dcron3 -join=127.0.0.1:5001 -bind=127.0.0.1:5002 -http-addr=:8082
dkron2: godep go run *.go agent -server -node=dkron2 -join=127.0.0.1:5002 -bind=127.0.0.1:5001 -http-addr=:8081
dkron3: godep go run *.go agent -server -node=dkron3 -join=127.0.0.1:5001 -bind=127.0.0.1:5002 -http-addr=:8082
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Dcron - Distributed, fault tolerant job scheduling system
# Dkron - Distributed, fault tolerant job scheduling system

Website: http://dcron.io/
Website: http://dkron.io/

Dcron is a distributed cron service, easy to setup and fault tolerant with focus in:
Dkron is a distributed cron service, easy to setup and fault tolerant with focus in:

- Easy: Easy to use with a great UI
- Reliable: Completly fault tolerant
- High scalable: Able to handle high volumes of scheduled jobs and thousands of nodes

Dcron is written in Go and leverage the power of etcd and serf for providing fault tolerance and, reliability and scalability while keeping simple and easily instalable.
Dkron is written in Go and leverage the power of etcd and serf for providing fault tolerance and, reliability and scalability while keeping simple and easily instalable.

Dcron is inspired by the google whitepaper [Reliable Cron across the Planet](https://queue.acm.org/detail.cfm?id=2745840)
Dkron is inspired by the google whitepaper [Reliable Cron across the Planet](https://queue.acm.org/detail.cfm?id=2745840)

Dcron runs on Linux, OSX and Windows. It can be used to run scheduled commands on a server cluster using any combination of servers for each job. It has no single points of failure due to the use of the Gossip protocol and the fault tolerant distributed database etcd.
Dkron runs on Linux, OSX and Windows. It can be used to run scheduled commands on a server cluster using any combination of servers for each job. It has no single points of failure due to the use of the Gossip protocol and the fault tolerant distributed database etcd.

You can use Dcron to run the most important part of your company, scheduled jobs.
You can use Dkron to run the most important part of your company, scheduled jobs.

## Status

Currently Dcron is under heavy development and should be considered alpha stage.
Currently Dkron is under heavy development and should be considered alpha stage.

Said that, I encourage you to try it, it's very easy to use, see how it works for you and report any bugs [creating an issue](https://github.com/victorcoder/dcron/issues) in the github project.
Said that, I encourage you to try it, it's very easy to use, see how it works for you and report any bugs [creating an issue](https://github.com/victorcoder/dkron/issues) in the github project.

## Quick start

Expand All @@ -36,12 +36,12 @@ Next, run the included Procfile

`goreman start`

This will start etcd and some Dcron instances that will form a cluster.
This will start etcd and some Dkron instances that will form a cluster.

Now you can view the web panel at: http://localhost:8081

To add jobs to the system read the API docs or take a look to the `job.json` file.

## Documentation

Full, comprehensive documentation is viewable on the Dcron website: http://dcron.io
Full, comprehensive documentation is viewable on the Dkron website: http://dkron.io
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "dcron-dashboard",
"description": "Dcron dashboard",
"name": "dkron-dashboard",
"description": "Dkron dashboard",
"version": "0.0.0",
"homepage": "https://dcron.io",
"homepage": "https://dkron.io",
"license": "LGPL3",
"private": true,
"directory": "static/components",
Expand Down
3 changes: 2 additions & 1 deletion config/dcron.json → config/dkron.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"tags": {
"role": "web",
"datacenter": "east"
}
},
"keyspace": "dcron"
}
29 changes: 16 additions & 13 deletions dcron/agent.go → dkron/agent.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"crypto/sha1"
Expand Down Expand Up @@ -32,7 +32,7 @@ const (
gracefulTimeout = 3 * time.Second
)

// AgentCommand run dcron server
// AgentCommand run server
type AgentCommand struct {
Ui cli.Ui
Version string
Expand All @@ -46,8 +46,8 @@ type AgentCommand struct {

func (a *AgentCommand) Help() string {
helpText := `
Usage: dcron agent [options]
Run dcron (option -server to run as server)
Usage: dkron agent [options]
Run dkron (option -server to run as server)
Options:
`
return strings.TrimSpace(helpText)
Expand All @@ -69,17 +69,19 @@ func (a *AgentCommand) readConfig(args []string) *Config {
viper.SetDefault("bind_addr", cmdFlags.Lookup("bind").Value)
cmdFlags.String("http-addr", ":8080", "HTTP address")
viper.SetDefault("http_addr", cmdFlags.Lookup("http-addr").Value)
cmdFlags.String("discover", "dcron", "mDNS discovery name")
cmdFlags.String("discover", "dkron", "mDNS discovery name")
viper.SetDefault("discover", cmdFlags.Lookup("discover").Value)
cmdFlags.String("etcd-machines", "http://127.0.0.1:2379", "etcd machines addresses")
viper.SetDefault("etcd_machines", cmdFlags.Lookup("etcd-machines").Value)
cmdFlags.String("profile", "lan", "timing profile to use (lan, wan, local)")
viper.SetDefault("profile", cmdFlags.Lookup("profile").Value)
viper.SetDefault("server", cmdFlags.Bool("server", false, "start dcron server"))
viper.SetDefault("server", cmdFlags.Bool("server", false, "start dkron server"))
startJoin := &AppendSliceValue{}
cmdFlags.Var(startJoin, "join", "address of agent to join on startup")
var tag []string
cmdFlags.Var((*AppendSliceValue)(&tag), "tag", "tag pair, specified as key=value")
cmdFlags.String("keyspace", "dkron", "etcd key namespace to use")
viper.SetDefault("keyspace", cmdFlags.Lookup("keyspace").Value)

if err := cmdFlags.Parse(args); err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -112,6 +114,7 @@ func (a *AgentCommand) readConfig(args []string) *Config {
Profile: viper.GetString("profile"),
StartJoin: *startJoin,
Tags: tags,
Keyspace: viper.GetString("keyspace"),
}

// log.Fatal(config.EtcdMachines)
Expand Down Expand Up @@ -303,7 +306,7 @@ func (a *AgentCommand) Run(args []string) int {
a.join(a.config.StartJoin, true)

if a.config.Server {
a.etcd = NewEtcdClient(a.config.EtcdMachines, a)
a.etcd = NewEtcdClient(a.config.EtcdMachines, a, a.config.Keyspace)
a.sched = NewScheduler()

go func() {
Expand Down Expand Up @@ -369,17 +372,17 @@ func (a *AgentCommand) handleSignals() int {
}

func (a *AgentCommand) Synopsis() string {
return "Run dcron"
return "Run dkron"
}

// Dcron leader election routine
// Leader election routine
func (a *AgentCommand) ElectLeader() bool {
leaderKey := a.etcd.GetLeader()

if leaderKey != "" {
if !a.serverAlive(leaderKey) {
log.Debug("Trying to set itself as leader")
res, err := a.etcd.Client.CompareAndSwap(keyspace+"/leader", a.config.Tags["key"], 0, leaderKey, 0)
res, err := a.etcd.Client.CompareAndSwap(a.config.Keyspace+"/leader", a.config.Tags["key"], 0, leaderKey, 0)
if err != nil {
log.Errorln("Error trying to set itself as leader", err)
return false
Expand All @@ -395,18 +398,18 @@ func (a *AgentCommand) ElectLeader() bool {
}
} else {
log.Debug("Trying to set itself as leader")
res, err := a.etcd.Client.Create(keyspace+"/leader", a.config.NodeName, 0)
res, err := a.etcd.Client.Create(a.config.Keyspace+"/leader", a.config.NodeName, 0)
if err != nil {
log.Error(res, err)
}
log.Printf("Successfully set [%s] as dcron leader", a.config.NodeName)
log.Printf("Successfully set [%s] as leader", a.config.NodeName)
return true
}

return false
}

// Checks if the dcron server member identified by key, is alive.
// Checks if the server member identified by key, is alive.
func (a *AgentCommand) serverAlive(key string) bool {
members := a.serf.Members()
for _, member := range members {
Expand Down
8 changes: 4 additions & 4 deletions dcron/agent_test.go → dkron/agent_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"testing"
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestAgentCommandElectLeader(t *testing.T) {
}

etcd := etcdc.NewClient([]string{})
_, err := etcd.DeleteDir("dcron")
_, err := etcd.DeleteDir("dkron")
if err != nil {
if eerr, ok := err.(*etcdc.EtcdError); ok {
if eerr.ErrorCode == etcdc.ErrCodeEtcdNotReachable {
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestAgentCommandElectLeader(t *testing.T) {
stop := make(chan bool)
time.Sleep(2 * time.Second)

go etcd.Watch("/dcron/leader", 0, false, receiver, stop)
go etcd.Watch("/dkron/leader", 0, false, receiver, stop)

// Verify it runs "forever"
select {
Expand Down Expand Up @@ -158,7 +158,7 @@ func Test_processFilteredNodes(t *testing.T) {
}

etcd := etcdc.NewClient([]string{})
_, err := etcd.DeleteDir("dcron")
_, err := etcd.DeleteDir("dkron")
if err != nil {
if eerr, ok := err.(*etcdc.EtcdError); ok {
if eerr.ErrorCode == etcdc.ErrCodeEtcdNotReachable {
Expand Down
2 changes: 1 addition & 1 deletion dcron/api.go → dkron/api.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion dcron/api_test.go → dkron/api_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"bytes"
Expand Down
9 changes: 5 additions & 4 deletions dcron/config.go → dkron/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"encoding/base64"
Expand Down Expand Up @@ -29,15 +29,16 @@ type Config struct {
Server bool
EncryptKey string
StartJoin AppendSliceValue
Keyspace string
}

// This is the default port that we use for Serf communication
const DefaultBindPort int = 7946

func init() {
viper.SetConfigName("dcron") // name of config file (without extension)
viper.AddConfigPath("/etc/dcron") // call multiple times to add many search paths
viper.AddConfigPath("$HOME/.dcron") // call multiple times to add many search paths
viper.SetConfigName("dkron") // name of config file (without extension)
viper.AddConfigPath("/etc/dkron") // call multiple times to add many search paths
viper.AddConfigPath("$HOME/.dkron") // call multiple times to add many search paths
viper.AddConfigPath("./config") // call multiple times to add many search paths
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
Expand Down
2 changes: 1 addition & 1 deletion dcron/dashboard.go → dkron/dashboard.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"encoding/json"
Expand Down
25 changes: 12 additions & 13 deletions dcron/etcd.go → dkron/etcd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"encoding/json"
Expand All @@ -9,11 +9,10 @@ import (
etcdc "github.com/coreos/go-etcd/etcd"
)

const keyspace = "/dcron"

type etcdClient struct {
Client *etcdc.Client
agent *AgentCommand
Client *etcdc.Client
agent *AgentCommand
keyspace string
}

// ServerStats encapsulates various statistics about an EtcdServer and its
Expand Down Expand Up @@ -43,22 +42,22 @@ func init() {
etcdc.SetLogger(stdlog.New(log.Writer(), "go-etcd", stdlog.LstdFlags))
}

func NewEtcdClient(machines []string, a *AgentCommand) *etcdClient {
return &etcdClient{Client: etcdc.NewClient(machines), agent: a}
func NewEtcdClient(machines []string, a *AgentCommand, keyspace string) *etcdClient {
return &etcdClient{Client: etcdc.NewClient(machines), agent: a, keyspace: keyspace}
}

func (e *etcdClient) SetJob(job *Job) error {
jobJson, _ := json.Marshal(job)
log.Debugf("Setting etcd key %s: %s", job.Name, string(jobJson))
if _, err := e.Client.Set(keyspace+"/jobs/"+job.Name, string(jobJson), 0); err != nil {
if _, err := e.Client.Set(e.keyspace+"/jobs/"+job.Name, string(jobJson), 0); err != nil {
return err
}

return nil
}

func (e *etcdClient) GetJobs() ([]*Job, error) {
res, err := e.Client.Get(keyspace+"/jobs/", true, false)
res, err := e.Client.Get(e.keyspace+"/jobs/", true, false)
if err != nil {
eerr := err.(*etcdc.EtcdError)
if eerr.ErrorCode == 100 {
Expand All @@ -84,7 +83,7 @@ func (e *etcdClient) GetJobs() ([]*Job, error) {
}

func (e *etcdClient) GetJob(name string) (*Job, error) {
res, err := e.Client.Get(keyspace+"/jobs/"+name, false, false)
res, err := e.Client.Get(e.keyspace+"/jobs/"+name, false, false)
if err != nil {
return nil, err
}
Expand All @@ -99,7 +98,7 @@ func (e *etcdClient) GetJob(name string) (*Job, error) {
}

func (e *etcdClient) GetExecutions(jobName string) ([]*Execution, error) {
res, err := e.Client.Get(fmt.Sprintf("%s/executions/%s", keyspace, jobName), true, false)
res, err := e.Client.Get(fmt.Sprintf("%s/executions/%s", e.keyspace, jobName), true, false)
if err != nil {
return nil, err
}
Expand All @@ -122,7 +121,7 @@ func (e *etcdClient) SetExecution(execution *Execution) (string, error) {
key := fmt.Sprintf("%d-%s", execution.StartedAt.UnixNano(), execution.NodeName)

log.Debugf("Setting etcd key %s: %s", execution.JobName, string(eJson))
res, err := e.Client.Set(fmt.Sprintf("%s/executions/%s/%s", keyspace, execution.JobName, key), string(eJson), 0)
res, err := e.Client.Set(fmt.Sprintf("%s/executions/%s/%s", e.keyspace, execution.JobName, key), string(eJson), 0)
if err != nil {
return "", err
}
Expand All @@ -131,7 +130,7 @@ func (e *etcdClient) SetExecution(execution *Execution) (string, error) {
}

func (e *etcdClient) GetLeader() string {
res, err := e.Client.Get(keyspace+"/leader", false, false)
res, err := e.Client.Get(e.keyspace+"/leader", false, false)
if err != nil {
if eerr, ok := err.(*etcdc.EtcdError); ok {
if eerr.ErrorCode == etcdc.ErrCodeEtcdNotReachable {
Expand Down
2 changes: 1 addition & 1 deletion dcron/flag_slice_value.go → dkron/flag_slice_value.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import "strings"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"flag"
Expand Down
2 changes: 1 addition & 1 deletion dcron/log.go → dkron/log.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"github.com/Sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion dcron/proc.go → dkron/proc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dcron
package dkron

import (
"encoding/json"
Expand Down
Loading

0 comments on commit 11f7d35

Please sign in to comment.