Skip to content

Commit ec34ff9

Browse files
committed
Add 'objdb/' from commit '77da460780b8b6d086ca1362ec50a07888ca4b63'
git-subtree-dir: objdb git-subtree-mainline: 83e1bda git-subtree-split: 77da460
2 parents 83e1bda + 77da460 commit ec34ff9

File tree

299 files changed

+165382
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

299 files changed

+165382
-0
lines changed

objdb/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# vagrant
2+
.vagrant

objdb/Godeps/Godeps.json

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

objdb/Godeps/Readme

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

objdb/LICENSE

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright 2017 Cisco Systems Inc. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.

objdb/Makefile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
.PHONY: all build update start stop test host-build host-test godep
3+
4+
all: build test
5+
6+
build: start
7+
vagrant ssh node1 -c 'cd /opt/gopath/src/github.com/contiv/objdb && make host-build'
8+
9+
update:
10+
vagrant box update
11+
12+
start: update
13+
vagrant up
14+
15+
stop:
16+
vagrant destroy -f
17+
18+
test: start build
19+
vagrant ssh node1 -c 'cd /opt/gopath/src/github.com/contiv/objdb && make host-test'
20+
21+
# build compiles and installs the code after running code quality checks
22+
host-build:
23+
./checks.sh
24+
go get github.com/tools/godep
25+
go install ./ ./modeldb
26+
27+
host-test:
28+
etcdctl rm --recursive /contiv.io || true
29+
go test -v ./ ./modeldb
30+
go test -bench=. -run "Benchmark"
31+
32+
# godep updates Godeps/Godeps.json
33+
godep:
34+
godep save ./...

objdb/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# objdb
2+
Object store client and API

objdb/Vagrantfile

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
require 'fileutils'
5+
6+
gopath_folder="/opt/gopath"
7+
8+
provision_common = <<SCRIPT
9+
## setup the environment file. Export the env-vars passed as args to 'vagrant up'
10+
echo Args passed: [[ $@ ]]
11+
12+
echo -n "$1" > /etc/hostname
13+
hostname -F /etc/hostname
14+
15+
/sbin/ip addr add "$3/24" dev eth1
16+
/sbin/ip link set eth1 up
17+
/sbin/ip link set eth2 up
18+
19+
echo 'export GOPATH=#{gopath_folder}' > /etc/profile.d/envvar.sh
20+
echo 'export GOBIN=$GOPATH/bin' >> /etc/profile.d/envvar.sh
21+
echo 'export GOSRC=$GOPATH/src' >> /etc/profile.d/envvar.sh
22+
echo 'export PATH=$PATH:/usr/local/go/bin:$GOBIN' >> /etc/profile.d/envvar.sh
23+
echo "export http_proxy='$4'" >> /etc/profile.d/envvar.sh
24+
echo "export https_proxy='$5'" >> /etc/profile.d/envvar.sh
25+
echo "export no_proxy=192.168.2.10,192.168.2.11,127.0.0.1,localhost,netmaster" >> /etc/profile.d/envvar.sh
26+
echo "export CLUSTER_NODE_IPS=192.168.2.10,192.168.2.11" >> /etc/profile.d/envvar.sh
27+
28+
29+
source /etc/profile.d/envvar.sh
30+
31+
# Change permissions for gopath folder
32+
chown -R vagrant #{gopath_folder}
33+
34+
SCRIPT
35+
36+
VAGRANTFILE_API_VERSION = "2"
37+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
38+
config.vm.box = "contiv/centos73"
39+
config.vm.box_version = "0.10.0"
40+
num_nodes = 1
41+
base_ip = "192.168.10."
42+
node_ips = num_nodes.times.collect { |n| base_ip + "#{n+10}" }
43+
node_names = num_nodes.times.collect { |n| "node#{n+1}" }
44+
node_peers = []
45+
46+
num_nodes.times do |n|
47+
node_name = node_names[n]
48+
node_addr = node_ips[n]
49+
node_peers += ["#{node_name}=http://#{node_addr}:2380,#{node_name}=http://#{node_addr}:7001"]
50+
consul_bootstrap_flag = "-bootstrap"
51+
config.vm.define node_name do |node|
52+
# node.vm.hostname = node_name
53+
# create an interface for etcd cluster
54+
node.vm.network :private_network, ip: node_addr, virtualbox__intnet: "true", auto_config: false
55+
# create an interface for bridged network
56+
node.vm.network :private_network, ip: "0.0.0.0", virtualbox__intnet: "true", auto_config: false
57+
node.vm.provider "virtualbox" do |v|
58+
# make all nics 'virtio' to take benefit of builtin vlan tag
59+
# support, which otherwise needs to be enabled in Intel drivers,
60+
# which are used by default by virtualbox
61+
v.customize ['modifyvm', :id, '--nictype1', 'virtio']
62+
v.customize ['modifyvm', :id, '--nictype2', 'virtio']
63+
v.customize ['modifyvm', :id, '--nictype3', 'virtio']
64+
v.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
65+
v.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
66+
end
67+
68+
# mount the host directories
69+
node.vm.synced_folder ".", File.join(gopath_folder, "src/github.com/contiv/objdb"), rsync: true
70+
71+
72+
node.vm.provision "shell" do |s|
73+
s.inline = provision_common
74+
s.args = [node_name, ENV["CONTIV_NODE_OS"] || "", node_addr, ENV["http_proxy"] || "", ENV["https_proxy"] || "", *ENV['CONTIV_ENV']]
75+
end
76+
provision_node = <<SCRIPT
77+
## start etcd with generated config
78+
set -x
79+
(nohup etcd --name #{node_name} --data-dir /tmp/etcd \
80+
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
81+
--advertise-client-urls http://#{node_addr}:2379,http://#{node_addr}:4001 \
82+
--initial-advertise-peer-urls http://#{node_addr}:2380,http://#{node_addr}:7001 \
83+
--listen-peer-urls http://#{node_addr}:2380 \
84+
--initial-cluster #{node_peers.join(",")} --initial-cluster-state new \
85+
0<&- &>/tmp/etcd.log &) || exit 1
86+
87+
## start consul
88+
(nohup consul agent -server #{consul_bootstrap_flag} \
89+
-bind=#{node_addr} -data-dir /opt/consul 0<&- &>/tmp/consul.log &) || exit 1
90+
91+
SCRIPT
92+
node.vm.provision "shell", run: "always" do |s|
93+
s.inline = provision_node
94+
end
95+
end
96+
end
97+
end

objdb/checks.sh

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
dirs=$(go list ./... | sed -e 's!github.com/contiv/objdb!.!g' | grep -v ./vendor)
6+
files=$(find . -type f -name '*.go' | grep -v ./vendor)
7+
8+
echo "Running gofmt..."
9+
set +e
10+
out=$(gofmt -s -l ${files})
11+
set -e
12+
# gofmt can include empty lines in its output
13+
if [ "$(echo $out | sed '/^$/d' | wc -l)" -gt 0 ]; then
14+
echo 1>&2 "gofmt errors in:"
15+
echo 1>&2 "${out}"
16+
exit 1
17+
fi
18+
19+
echo "Running ineffassign..."
20+
[ -n "$(which ineffassign)" ] || go get github.com/gordonklaus/ineffassign
21+
for i in ${dirs}; do
22+
ineffassign $i
23+
done
24+
25+
echo "Running golint..."
26+
[ -n "$(which golint)" ] || go get github.com/golang/lint/golint
27+
set +e
28+
out=$(golint ./... | grep -vE '^vendor')
29+
set -e
30+
if [ "$(echo $out | sed '/^$/d' | wc -l)" -gt 0 ]; then
31+
echo 1>&2 "golint errors in:"
32+
echo 1>&2 "${out}"
33+
exit 1
34+
fi
35+
36+
echo "Running govet..."
37+
set +e
38+
out=$(go tool vet -composites=false ${dirs} 2>&1 | grep -v vendor)
39+
set -e
40+
41+
if [ "$(echo $out | sed '/^$/d' | wc -l)" -gt 0 ]; then
42+
echo 1>&2 "go vet errors in:"
43+
echo 1>&2 "${out}"
44+
exit 1
45+
fi
46+
47+
echo "Running gocyclo..."
48+
[ -n "$(which gocyclo)" ] || go get github.com/fzipp/gocyclo
49+
set +e
50+
out=$(gocyclo -over 20 . | grep -v vendor)
51+
set -e
52+
if [ "$(echo $out | sed '/^$/d' | wc -l)" -gt 0 ]; then
53+
echo 1>&2 "gocycle errors in:"
54+
echo 1>&2 "${out}"
55+
exit 1
56+
fi
57+
58+
echo "Running misspell..."
59+
[ -n "$(which misspell)" ] || go get github.com/client9/misspell/...
60+
set +e
61+
out=$(misspell -locale US -error -i exportfs ${files})
62+
set -e
63+
if [ "$(echo $out | sed '/^$/d' | wc -l)" -gt 0 ]; then
64+
echo 1>&2 "misspell errors in:"
65+
echo 1>&2 "${out}"
66+
exit 1
67+
fi
68+
69+
echo "Running deadcode..."
70+
[ -n "$(which deadcode)" ] || go get github.com/remyoudompheng/go-misc/deadcode/...
71+
set +e
72+
out=$(deadcode ${dirs} 2>&1)
73+
set -e
74+
if [ "$(echo $out | sed '/^$/d' | wc -l)" -gt 0 ]; then
75+
echo 1>&2 "deadcode errors in:"
76+
echo 1>&2 "${out}"
77+
exit 1
78+
fi

objdb/client.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/***
2+
Copyright 2014 Cisco Systems Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package objdb
17+
18+
import (
19+
"errors"
20+
"strings"
21+
22+
log "github.com/Sirupsen/logrus"
23+
)
24+
25+
var defaultDbURL = "etcd://127.0.0.1:2379"
26+
27+
// NewClient Create a new conf store
28+
func NewClient(dbURL string) (API, error) {
29+
// check if we should use default db
30+
if dbURL == "" {
31+
dbURL = defaultDbURL
32+
}
33+
34+
parts := strings.Split(dbURL, "://")
35+
if len(parts) < 2 {
36+
log.Errorf("Invalid DB URL format %s", dbURL)
37+
return nil, errors.New("Invalid DB URL")
38+
}
39+
clientName := parts[0]
40+
clientURL := parts[1]
41+
42+
// Get the plugin
43+
plugin := GetPlugin(clientName)
44+
if plugin == nil {
45+
log.Errorf("Invalid DB type %s", clientName)
46+
return nil, errors.New("Unsupported DB type")
47+
}
48+
49+
// Initialize the objdb client
50+
cl, err := plugin.NewClient([]string{"http://" + clientURL})
51+
if err != nil {
52+
log.Errorf("Error creating client %s to url %s. Err: %v", clientName, clientURL, err)
53+
return nil, err
54+
}
55+
56+
return cl, nil
57+
}

0 commit comments

Comments
 (0)