Skip to content

Cli #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
9 changes: 9 additions & 0 deletions .idea/go-scheduler.iml

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

6 changes: 6 additions & 0 deletions .idea/misc.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

Binary file added CLI
Binary file not shown.
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to remove binary files from the PR

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

.PHONY: test

all: | clean deps gen_protobuf build gen_mocks test
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing Phony on most the targets


clean:
@rm -rf ./gen/*
@rm -rf ./test/cli/mocks/*
@rm -rf ./test/common/mocks/*

deps:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use golang's standard dependency manager? e.g dep or vgo

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used govendor in the past, and simply did it this way because it was faster for getting the prototype going. I am all for dependency management :-)

@echo syncing dependencies...
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would generally recommend to vendor the dependencies, creates less risk that upstream changes will break things.

We generally use dep (https://github.com/golang/dep), but vgo (https://github.com/golang/go/wiki/vgo) is the current hotness, and there are a few other tools that are all good.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. I have used Govendor in the past, but I wanted to keep it simple for the prototype. I'll check out vgo.

@go get github.com/onsi/ginkgo
@go get github.com/onsi/gomega
@go get github.com/vektra/mockery/.../
@go get github.com/stretchr/testify/mock
@go get -u google.golang.org/grpc
@go get -u github.com/golang/protobuf/protoc-gen-go

build: build_cli

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.PHONY for build targets?


build_cli:
@echo building cli...
@go build -o go-scheduler-cli ./cmd/go-scheduler-cli
@chmod +x go-scheduler-cli

gen_mocks:
@echo generating mocks...
@${GOPATH}/bin/mockery -all -dir pkg/cli -output test/cli/mocks -case=underscore
@${GOPATH}/bin/mockery -all -dir pkg/common -output test/common/mocks -case=underscore
@${GOPATH}/bin/mockery -all -dir pkg/master -output test/master/mocks -case=underscore
@${GOPATH}/bin/mockery -all -dir gen/protobuf/master -output test/master/mocks -case=underscore

gen_protobuf:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not reproducible - go get can render various versions and grpc is not pinned.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate? I am not quite following. Are you referring to this line under deps:
go get -u google.golang.org/grpc

@echo generating protobuf APIs...
@command -v protoc >/dev/null 2>&1 || { echo >&2 "protoc is not installed. "; exit 1; }
@protoc --go_out=plugins=grpc,paths=source_relative:./gen ./protobuf/master/master.proto

test:
@echo running tests...
@${GOPATH}/bin/ginkgo -r ./test
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# go-scheduler
This is a distributed job scheduler for linux systems built in Go.
This is a distributed job scheduler for linux systems built in Go. It can run arbitrary docker images on a cluster of computers.

# Install

## Get the package
`go get github.com/kmacmcfarlane/go-scheduler`

## Build the project
`make`

## Generate Certificates with EasyRSA
The cluster uses x509 certificates to authenticate the client, master, and node applications.

# CLI
The go-scheduler CLI client allows you to control work run on the cluster.

## Install Client Certificate
The client certificate is used to authenticate with your cluster. The certificate must have file permission 600.

`mkdir ~/.go-scheduler`
`cp ~/Downloads/client.crt ~/.go-scheduler/client.crt`
`chmod 600 ~/.go-scheduler/client.crt`

## Start a Job

`go-scheduler-cli start --image redis --name redisCache --master 192.168.1.80`

## Stop a Job

`go-scheduler-cli stop --name redisCache --master 192.168.1.80`

## Query Job Status

`go-scheduler-cli query --name redisCache --master 192.168.1.80`

## Stream Log Output

`go-scheduler-cli log --name redisCache --master 192.168.1.80`

## Status Codes
go-scheduler-cli returns the following status codes:

0: success
1: error parsing command-line arguments
2: error parsing command-line arguments
3: application error
33 changes: 33 additions & 0 deletions cmd/go-scheduler-cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recommend to follow these guidelines for consistency:

https://github.com/golang/go/wiki/CodeReviewComments

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this before. I will give it a read.


import (
"context"
"fmt"
"github.com/kmacmcfarlane/go-scheduler/internal/grpc"
"github.com/kmacmcfarlane/go-scheduler/pkg/cli"
"github.com/kmacmcfarlane/go-scheduler/pkg/common"
"os"
)

func main() {

ctx := context.Background()

logger := common.NewConsoleLogger()

clientFactory := grpc.NewMasterClientFactory()

clientService := cli.NewClientService(ctx, clientFactory, logger)

commandParser := cli.NewCommandParser(clientService, logger)

// Parse and execute Command
err := commandParser.Parse(os.Args)

if nil != err {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}

os.Exit(0)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gofmt will help with formatting

Loading