Skip to content
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

Moved Glide and Makefile to project root #20

Merged
merged 5 commits into from
Aug 22, 2016
Merged
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
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ go:
- 1.7
env:
matrix:
- BUILD_DIR=registry
- BUILD_DIR=rackhd
- TARGET=test-proxy
- TARGET=test-reg
global:
- secure: YjrmJs3//Dsa6G02WeIC+l2rRwMNk7ADQ5WbV0N1WdKMYEz/7rudfFrgkC4kMmjPYLQdvs+Iri9Zva/SU9oEBNC8Jv52kXsYXXwMc1UwutmAyp3jSTZEl/1ffQXU/UlSBOJ7KDrrMvGgn4WirUZ6U98piIyvN3kUSnOVuo2gJzZ9xw/3sqQTnhRcuX57FEKJVXug45RPWVR3pyI0yplVSkCAs1QbDV4B5XkMJyCyxZhqi0I2ljdHQe85fXZb+798h2oxN5WYyc67UO9WcLoWg/F417HMyRHxYgV8lRYZZCEQXZZOy8dScGUjhT6FObyUhJNwYoblAa230CcPhQ4QPmzUYcBp72AJYVpURy5DNz88S+l5sGBej6XQkaP2UX8Ho4gGbTKHG48I8aRPaeqg8KvYVrMV4BLc6HraEHvELNugNTay50XnUcWnqbpOFXqRsHRc8MZN2nB2UhqOA7qQlXonNrwLOUaDRC601bWAhBHSnacOhDyCfzHRyRTNGum/RXPSktNA39aElYos191K7fgwD/V0cx+YlZNmMkx32Pmf3waRkaMT9tJfIDB2YFeTbbP5Xf7hStOmoA20cAk3g1GP5dUbm9utFdZCDj4jG5adqLvklMuU2QmZdmSvdnwPAbaRPx6WDRU00UAlkNnVPKT1VN8kHUjVh9ToClBFT3Y=
- secure: OYDVEVJOfG2HZZ3m+OkaBEXonl/Pe3QXcdkhFJenmdPoyzCaRehK5YRy/Glog0R48fOMcV4//w3pOhzalP48wJjK+N+uK+C5bsPAjM7xMIEyN26TYuDfFzUzWLdtdN1FYOmL+taGOf6I4ne7fxQrVNCGVBgxvFyX7l5dxyDis19Qm7psm3ueMPikEjUfce3wT4rhWGiEQxymNtDQpYKpO8PDu0jXgROiEUK7mwkmKJYeKRUCordWBuw1Xjclx1/PL4u4arAqz3IDhLk1Hb2tbalgdnPJUUiXa/M5JA5gKMW/K4cQuEiep+iMM71FrIHR7195oTcP7RUvalak7SGXk7WkET0YgHsKrck47KeX3TPLtXk29axJqcSk3FqktqXrUr2OsIBxgZVfRMtiDCVxcH0SaZfMLfQfGAMNnl02M8YX6y6dNWXOJfvxarUpaNEYGPnHCufJ2B6433p4OpxecdKT0sHQFcKEAV9aX2p+iIrVRmuc7MnUlJEX7UwdenS+hYTgV8Xsap86kd08QpP3FEmt6T6VJgOnzyhhT6QBObosQYRxT4hGmy6r6SJDwPvIJKbMEEFrEveFYimZyH02UZP0XE/HZJd9RsV8uCFxQal6VYIKo4uz26uYLyk352XVrm+ilmPBczBGsds2g5GdjZP13qNj7Ek1BDcxO04a2OQ=
before_install:
- echo -e "machine github.com\n login $GITHUB_USER\n password $GITHUB_PASS" >> ~/.netrc
script:
- cd $BUILD_DIR && make
- make deps
- make $TARGET
after_success:
- make coveralls
114 changes: 109 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,123 @@
ORGANIZATION = RackHD
PROJECT = neighborhood-manager
PROXY = rackhd
REGISTRY = registry


TTY = $(shell if [ -t 0 ]; then echo "-ti"; fi)

PROJECT_DIR = /go/src/github.com/${ORGANIZATION}/${PROJECT}
DOCKER_DIR = ${PROJECT_DIR}
DOCKER_DIR = /go/src/github.com/${ORGANIZATION}/${PROJECT}
DOCKER_IMAGE = rackhd/golang:1.7.0-wheezy
DOCKER_CMD = docker run --rm -v ${PWD}:${PROJECT_DIR} ${TTY} -w ${DOCKER_DIR} ${DOCKER_IMAGE}
DOCKER_CMD = docker run --rm -v ${PWD}:${DOCKER_DIR} ${TTY} -w ${DOCKER_DIR} ${DOCKER_IMAGE}


# variable definitions
COMMITHASH = $(shell git describe --tags --always --dirty)
BUILDDATE = $(shell date -u)
BUILDER = $(shell echo "`git config user.name` <`git config user.email`>")
GOVERSION = $(shell go version)
OSARCH = $(shell uname -sm)
RELEASEVERSION = 0.1



#Flags to pass to main.go
PROXYFLAGS = -ldflags "-X 'main.binaryName=${PROXY}' \
-X 'main.buildDate=${BUILDDATE}' \
-X 'main.buildUser=${BUILDER}' \
-X 'main.commitHash=${COMMITHASH}' \
-X 'main.goVersion=${GOVERSION}' \
-X 'main.osArch=${OSARCH}' \
-X 'main.releaseVersion=${RELEASEVERSION}' "

REGFLAGS = -ldflags "-X 'main.binaryName=${REGISTRY}' \
-X 'main.buildDate=${BUILDDATE}' \
-X 'main.buildUser=${BUILDER}' \
-X 'main.commitHash=${COMMITHASH}' \
-X 'main.goVersion=${GOVERSION}' \
-X 'main.osArch=${OSARCH}' \
-X 'main.releaseVersion=${RELEASEVERSION}' "

#Some tests need to run for 5+ seconds, which trips Ginkgo Slow Test warning
SLOWTEST = 10

noop:
@echo Neighborhood Manager
.PHONY: shell deps deps-local build build-local lint lint-local test test-local release

default: deps test build

coveralls:
@go get github.com/mattn/goveralls
@go get github.com/modocache/gover
@go get golang.org/x/tools/cmd/cover
@gover
@goveralls -coverprofile=gover.coverprofile -service=travis-ci

shell:
@${DOCKER_CMD} /bin/bash

consul-shell:
@docker run --rm -ti --net nmregistry_default -v ${PWD}:${DOCKER_DIR} -w ${DOCKER_DIR} ${DOCKER_IMAGE} /bin/bash

clean:
@${DOCKER_CMD} make clean-local

clean-local:
@rm -rf bin vendor

deps:
@${DOCKER_CMD} make deps-local

deps-local:
@if ! [ -f glide.yaml ]; then glide init --non-interactive; fi
@glide install

build:
@make build-proxy
@make build-reg

build-proxy:
@${DOCKER_CMD} make build-proxy-local

build-proxy-local: lint-local
@go build -o bin/${PROXY} ${PROXYFLAGS} rackhd/cmd/rackhd/*.go
@go build -o bin/endpoint rackhd/cmd/utils/*.go

build-reg:
@${DOCKER_CMD} make build-reg-local

build-reg-local: lint-local
@go build -o bin/${REGISTRY} ${REGFLAGS} registry/cmd/registry/*.go
@go build -o registry/cmd/ssdpspoofer/bin/ssdpspoofer registry/cmd/ssdpspoofer/*.go

lint:
@${DOCKER_CMD} make lint-local

lint-local:
@gometalinter --vendor --fast --disable=dupl --disable=gotype --skip=grpc ./...
test:
@make test-proxy
@make test-reg

test-proxy:
@${DOCKER_CMD} make test-proxy-local
@make build-proxy

test-proxy-local: lint-local
@ginkgo -r -race -trace -cover -randomizeAllSpecs --slowSpecThreshold=${SLOWTEST} ${PROXY}

test-reg:
@${DOCKER_CMD} make test-reg-local
@make build-reg

test-reg-local: lint-local
@ginkgo -r -race -trace -cover -randomizeAllSpecs --slowSpecThreshold=${SLOWTEST} ${REGISTRY}

release: deps build
@docker build -t rackhd/${PROXY} rackhd
@docker build -t rackhd/endpoint rackhd/cmd/utils/
@docker build -t rackhd/${REGISTRY} registry
@docker build -t rackhd/ssdpspoofer registry/cmd/ssdpspoofer/


run: release
@docker-compose up --force-recreate
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Neighborhood Manager
[![Build Status](https://travis-ci.org/RackHD/neighborhood-manager.svg?branch=master)](https://travis-ci.org/RackHD/neighborhood-manager)
[![Build Status](https://travis-ci.org/RackHD/neighborhood-manager.svg?branch=master)](https://travis-ci.org/RackHD/neighborhood-manager)
[![Coverage Status](https://coveralls.io/repos/github/RackHD/neighborhood-manager/badge.svg?branch=master)](https://coveralls.io/github/RackHD/neighborhood-manager?branch=master)

## Service Registry
The [Service Registry] is a utility that will sit on the network and listen for services that advertise themselves. The list of services a user wants to know about can be configured. When an advertisement is seen from a matching service, the Service Registry collects information about the service, and registers it with a storage backend of the users choosing. Other applications can access this storage for aggregated information about all services on a network.
Expand Down
31 changes: 13 additions & 18 deletions registry/glide.lock → glide.lock

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

7 changes: 7 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package: github.com/RackHD/neighborhood-manager
import:
- package: github.com/hashicorp/consul
subpackages:
- api
- package: github.com/king-jam/gossdp
- package: github.com/spf13/viper
3 changes: 2 additions & 1 deletion libreg/registry/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (s *Consul) setTimeout(time time.Duration) {
s.config.WaitTime = time
}

// Register adds an entry into the consul backend
func (s *Consul) Register(reg *registry.CatalogRegistration, options *registry.WriteOptions) error {
catalog := s.client.Catalog()
writeOps := s.getWriteOptions(options)
Expand Down Expand Up @@ -202,7 +203,7 @@ func (s *Consul) Node(node string, options *registry.QueryOptions) (*registry.Ca
return nil, nil
}

var retNode *registry.Node = &registry.Node{
var retNode = &registry.Node{
Node: n.Node.Node,
Address: n.Node.Address,
}
Expand Down
8 changes: 5 additions & 3 deletions libreg/registry/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import (
"github.com/RackHD/neighborhood-manager/libreg/registry"
)

// Mock is...
type Mock struct {
Catalog map[*registry.CatalogRegistration]bool
sync.RWMutex
}

// Register inits a new MOCK
func Register() {
libreg.AddRegistry(registry.MOCK, New)
}

// New instantiates a new registry
func New(endpoints []string, options *registry.Config) (registry.Registry, error) {
m := &Mock{}
m.Catalog = make(map[*registry.CatalogRegistration]bool)
return m, nil
}

// GetSearchTerms returns the whitelist of SSDP URNs to act on
// GetCatalog returns the whitelist of SSDP URNs to act on
func (m *Mock) GetCatalog() map[registry.CatalogRegistration]bool {
c := make(map[registry.CatalogRegistration]bool)

Expand Down Expand Up @@ -131,8 +134,7 @@ func (m *Mock) Service(service, tag string, options *registry.QueryOptions) ([]*
containsTag = true
}

if r.Service.Service == service &&
containsTag == true {
if r.Service.Service == service && containsTag {
catalogService := registry.CatalogService{
Node: r.Node,
Address: r.Address,
Expand Down
9 changes: 7 additions & 2 deletions libreg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
ErrNotReachable = errors.New("API not reachable")
// ErrNodeNotFound is thrown when the node is not found int he registry
ErrNodeNotFound = errors.New("Node not found in registry")
// ErrKSvcNotFound is thrown when the service is not found in the registry
// ErrSvcNotFound is thrown when the service is not found in the registry
ErrSvcNotFound = errors.New("Service not found in registry")
)

Expand All @@ -40,7 +40,7 @@ type Config struct {
Password string
}

/// ClientTLSConfig contains data for a Client TLS configuration in the form
// ClientTLSConfig contains data for a Client TLS configuration in the form
// the etcd client wants it. Eventually we'll adapt it for ZK and Consul.
type ClientTLSConfig struct {
CertFile string
Expand Down Expand Up @@ -74,11 +74,13 @@ type Registry interface {
Node(node string, options *QueryOptions) (*CatalogNode, error)
}

// Node is ...
type Node struct {
Node string
Address string
}

// CatalogService is ...
type CatalogService struct {
Node string
Address string
Expand All @@ -90,11 +92,13 @@ type CatalogService struct {
ServiceEnableTagOverride bool
}

// CatalogNode is ...
type CatalogNode struct {
Node *Node
Services map[string]*AgentService
}

// CatalogRegistration is ...
type CatalogRegistration struct {
Node string
Address string
Expand All @@ -103,6 +107,7 @@ type CatalogRegistration struct {
Check *AgentCheck
}

//CatalogDeregistration is ...
type CatalogDeregistration struct {
Node string
Address string
Expand Down
Loading