Skip to content

Commit

Permalink
Merge 18537d4 into f2cd423
Browse files Browse the repository at this point in the history
  • Loading branch information
jdef committed Jun 19, 2017
2 parents f2cd423 + 18537d4 commit 8811443
Show file tree
Hide file tree
Showing 98 changed files with 10,198 additions and 3,005 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ language: go
git:
submodules: false
go:
- 1.6.x
- 1.7.x
- 1.8
before_install:
Expand All @@ -17,4 +16,4 @@ before_install:
install:
- make install
script:
- rm -rf $HOME/gopath/pkg && make coverage && $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=_output/coverage.out
- rm -rf $HOME/gopath/pkg && make coverage && $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=_output/coverage.out -ignore=$((tr '\n' , | sed -e 's/$,//g') < <(find api/v1/cmd -type f -name '*.go'|grep -v -e /vendor/ ; ls api/v1/lib{,/scheduler,/executor}/*.pb{,_ffjson}.go ; find api/v0 -type d))
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ test-verbose: TEST_FLAGS += -v
test-verbose: test

.PHONY: coverage $(COVERAGE_TARGETS)
coverage: TEST_FLAGS = -v -cover -race
coverage: REPORT=_output/coverage.out
coverage: COVER_PACKAGE = $(shell go list ${API_PKG}/...|egrep -v 'vendor|cmd'|tr '\n' ','|sed -e 's/,$$//')
coverage: TEST_FLAGS = -v -cover -coverpkg=$(COVER_PACKAGE)
coverage: $(COVERAGE_TARGETS)
cat _output/*.cover | sed -e '2,$$ s/^mode:.*$$//' -e '/^$$/d' >_output/coverage.out
$(COVERAGE_TARGETS):
mkdir -p _output && go test ./$(@:%.cover=%) $(TEST_FLAGS) -coverprofile=_output/$(subst /,___,$@)
echo "mode: set" >$(REPORT) && cat _output/*.cover | grep -v mode: | sort -r | \
awk '{if($$1 != last) {print $$0;last=$$1}}' >> $(REPORT)
$(COVERAGE_TARGETS): %.cover :
mkdir -p _output && go test ./$* $(TEST_FLAGS) -coverprofile=_output/$(subst /,___,$@)

.PHONY: vet
vet:
go $@ $(PACKAGES)
go $@ $(PACKAGES) $(BINARIES)

.PHONY: codecs
codecs: protobufs ffjson
Expand Down Expand Up @@ -77,6 +80,11 @@ sync:
(cd ${API_VENDOR}; govendor sync)
(cd ${CMD_VENDOR}; govendor sync)

.PHONY: generate
generate: GENERATE_PACKAGES = ./api/v1/lib/extras/executor/eventrules ./api/v1/lib/extras/executor/callrules ./api/v1/lib/extras/scheduler/eventrules ./api/v1/lib/extras/scheduler/callrules ./api/v1/lib/executor/events ./api/v1/lib/executor/calls ./api/v1/lib/scheduler/events ./api/v1/lib/scheduler/calls
generate:
go generate -x ${GENERATE_PACKAGES}

GOPKG := github.com/mesos/mesos-go
GOPKG_DIRNAME := $(shell dirname $(GOPKG))
UID ?= $(shell id -u $$USER)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Go bindings for Apache Mesos

Very early version of a pure Go language bindings for Apache Mesos.
Pure Go language bindings for Apache Mesos, under development.
As with other pure implementations, mesos-go uses the HTTP wire protocol to communicate directly with a running Mesos master and its slave instances.
One of the objectives of this project is to provide an idiomatic Go API that makes it super easy to create Mesos frameworks using Go.

Expand All @@ -12,6 +12,8 @@ One of the objectives of this project is to provide an idiomatic Go API that mak
New projects should use the Mesos v1 API bindings, located in `api/v1`.
Unless otherwise indicated, the remainder of this README describes the Mesos v1 API implementation.

Please **vendor** this library to avoid unpleasant surprises via `go get ...`.

The Mesos v0 API version of the bindings, located in `api/v0`, are more mature but will not see any major development besides critical compatibility and bug fixes.

### Compatibility
Expand All @@ -24,7 +26,7 @@ The Mesos v0 API version of the bindings, located in `api/v0`, are more mature b
- Modular design for easy readability/extensibility

### Pre-Requisites
- Go 1.6 or higher
- Go 1.7 or higher
- A standard and working Go workspace setup
- Apache Mesos 1.0 or newer

Expand Down
39 changes: 22 additions & 17 deletions api/v1/cmd/example-executor/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"errors"
"io"
"log"
Expand Down Expand Up @@ -139,54 +140,58 @@ func unacknowledgedUpdates(state *internalState) executor.CallOpt {
}

func eventLoop(state *internalState, decoder encoding.Decoder, h events.Handler) (err error) {
ctx := context.TODO()
for err == nil && !state.shouldQuit {
// housekeeping
sendFailedTasks(state)

var e executor.Event
if err = decoder.Decode(&e); err == nil {
err = h.HandleEvent(&e)
err = h.HandleEvent(ctx, &e)
}
}
return err
}

func buildEventHandler(state *internalState) events.Handler {
return events.NewMux(
events.Handle(executor.Event_SUBSCRIBED, events.HandlerFunc(func(e *executor.Event) error {
return events.HandlerFuncs{
executor.Event_SUBSCRIBED: func(_ context.Context, e *executor.Event) error {
log.Println("SUBSCRIBED")
state.framework = e.Subscribed.FrameworkInfo
state.executor = e.Subscribed.ExecutorInfo
state.agent = e.Subscribed.AgentInfo
return nil
})),
events.Handle(executor.Event_LAUNCH, events.HandlerFunc(func(e *executor.Event) error {
},
executor.Event_LAUNCH: func(_ context.Context, e *executor.Event) error {
launch(state, e.Launch.Task)
return nil
})),
events.Handle(executor.Event_KILL, events.HandlerFunc(func(e *executor.Event) error {
},
executor.Event_KILL: func(_ context.Context, e *executor.Event) error {
log.Println("warning: KILL not implemented")
return nil
})),
events.Handle(executor.Event_ACKNOWLEDGED, events.HandlerFunc(func(e *executor.Event) error {
},
executor.Event_ACKNOWLEDGED: func(_ context.Context, e *executor.Event) error {
delete(state.unackedTasks, e.Acknowledged.TaskID)
delete(state.unackedUpdates, string(e.Acknowledged.UUID))
return nil
})),
events.Handle(executor.Event_MESSAGE, events.HandlerFunc(func(e *executor.Event) error {
},
executor.Event_MESSAGE: func(_ context.Context, e *executor.Event) error {
log.Printf("MESSAGE: received %d bytes of message data", len(e.Message.Data))
return nil
})),
events.Handle(executor.Event_SHUTDOWN, events.HandlerFunc(func(e *executor.Event) error {
},
executor.Event_SHUTDOWN: func(_ context.Context, e *executor.Event) error {
log.Println("SHUTDOWN received")
state.shouldQuit = true
return nil
})),
events.Handle(executor.Event_ERROR, events.HandlerFunc(func(e *executor.Event) error {
},
executor.Event_ERROR: func(_ context.Context, e *executor.Event) error {
log.Println("ERROR received")
return errMustAbort
})),
)
},
}.Otherwise(func(_ context.Context, e *executor.Event) error {
log.Fatal("unexpected event", e)
return nil
})
}

func sendFailedTasks(state *internalState) {
Expand Down
Loading

0 comments on commit 8811443

Please sign in to comment.