Skip to content

Commit

Permalink
Refactoring setup configuration of maya
Browse files Browse the repository at this point in the history
This commit includes changes, in installation and setup of maya master
and host configuration.Now there will be a option to pass the config via
yaml file while setting up master and host Nodes.
  • Loading branch information
prateekpandey14 committed May 10, 2017
1 parent adf9876 commit 4f2ccd9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 12 deletions.
7 changes: 5 additions & 2 deletions command/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type MayaAsNomadInstaller struct {

// formatted etcd initial cluster
etcd_cluster string
nomad string
consul string
docker string
}

// The public command
Expand Down Expand Up @@ -260,7 +263,7 @@ func (c *MayaAsNomadInstaller) installConsul() int {

var runop int = 0

c.Cmd = exec.Command("sh", InstallConsulScript)
c.Cmd = exec.Command("sh", InstallConsulScript, c.consul)

if runop = execute(c.Cmd, c.Ui); runop != 0 {
c.Ui.Error("Install failed: Error installing consul")
Expand All @@ -273,7 +276,7 @@ func (c *MayaAsNomadInstaller) installNomad() int {

var runop int = 0

c.Cmd = exec.Command("sh", InstallNomadScript)
c.Cmd = exec.Command("sh", InstallNomadScript, c.nomad)

if runop = execute(c.Cmd, c.Ui); runop != 0 {
c.Ui.Error("Install failed: Error installing nomad")
Expand Down
56 changes: 51 additions & 5 deletions command/install_maya.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package command

import (
"fmt"
"io/ioutil"
"log"
"os/exec"
"strconv"
"strings"

yaml "gopkg.in/yaml.v2"
)

type InstallMayaCommand struct {
Expand All @@ -28,6 +32,27 @@ type InstallMayaCommand struct {

// self hostname
self_hostname string

//versions of deps to be installed
nomad string
consul string

//flag variable for config
conf string
}

type Configuration struct {
Nomad struct {
Version string `yaml:"version"`
} `yaml:"Nomad"`
Consul struct {
Version string `yaml:"version"`
} `yaml:"Consul"`
Docker struct {
Version string `yaml:"version"`
} `yaml:"Docker"`
Masterip string `yaml:"masterip"`
Hostip string `yaml:"hostip"`
}

func (c *InstallMayaCommand) Help() string {
Expand Down Expand Up @@ -79,18 +104,25 @@ func (c *InstallMayaCommand) Run(args []string) int {

flags.StringVar(&c.member_ips, "omm-ips", "", "")
flags.StringVar(&c.self_ip, "self-ip", "", "")
flags.StringVar(&c.conf, "config", "", "Config file for setup omm")

if err := flags.Parse(args); err != nil {
return 1
}

// There are no extra arguments
oargs := flags.Args()
if len(oargs) != 0 {
if len(oargs) != 0 && len(strings.TrimSpace(c.conf)) == 0 {
c.M.Ui.Error(c.Help())
return 1
}

if c.conf != "" {
config := getConfig(c.conf)
c.self_ip = config.Masterip
c.nomad = config.Nomad.Version
c.consul = config.Consul.Version
}

if c.Cmd != nil {
// execute the provided command
return execute(c.Cmd, c.M.Ui)
Expand Down Expand Up @@ -142,8 +174,7 @@ func (c *InstallMayaCommand) Run(args []string) int {

func (c *InstallMayaCommand) installConsul() int {
var runop int = 0

c.Cmd = exec.Command("sh", InstallConsulScript)
c.Cmd = exec.Command("sh", InstallConsulScript, c.consul)

if runop = execute(c.Cmd, c.M.Ui); runop != 0 {
c.M.Ui.Error("Install failed: Error installing consul")
Expand All @@ -156,7 +187,7 @@ func (c *InstallMayaCommand) installNomad() int {

var runop int = 0

c.Cmd = exec.Command("sh", InstallNomadScript)
c.Cmd = exec.Command("sh", InstallNomadScript, c.nomad)

if runop = execute(c.Cmd, c.M.Ui); runop != 0 {
c.M.Ui.Error("Install failed: Error installing nomad")
Expand Down Expand Up @@ -324,3 +355,18 @@ func (c *InstallMayaCommand) startMayaserver() int {

return runop
}

//getconfig will read and decode the config file
func getConfig(path string) Configuration {
file, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal("Config File Missing. ", err)
}

var config Configuration
err = yaml.Unmarshal(file, &config)
if err != nil {
log.Fatal("Config Parse Error: ", err)
}
return config
}
17 changes: 17 additions & 0 deletions command/install_openebs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"fmt"
"os/exec"
"strings"
)
Expand All @@ -20,6 +21,9 @@ type InstallOpenEBSCommand struct {

// all maya client ips, in a comma separated format
member_ips string
conf string
nomad string
consul string
}

func (c *InstallOpenEBSCommand) Help() string {
Expand Down Expand Up @@ -63,11 +67,22 @@ func (c *InstallOpenEBSCommand) Run(args []string) int {
flags.StringVar(&c.master_ips, "omm-ips", "", "")
flags.StringVar(&c.self_ip, "self-ip", "", "")
flags.StringVar(&c.member_ips, "member-ips", "", "")
flags.StringVar(&c.conf, "config", "", "")

if err := flags.Parse(args); err != nil {
return 1
}

if c.conf != "" {
// c.conf = os.Args[2]
config := getConfig(c.conf)
fmt.Println(config)
c.self_ip = config.Hostip
c.master_ips = config.Masterip
c.nomad = config.Nomad.Version
c.consul = config.Consul.Version
}

// There are no extra arguments
oargs := flags.Args()
if len(oargs) != 0 {
Expand All @@ -89,6 +104,8 @@ func (c *InstallOpenEBSCommand) Run(args []string) int {
client_ips: c.member_ips,
master_ips: c.master_ips,
is_master: false,
nomad: c.nomad,
consul: c.consul,
}

if runop = mi.Install(); runop != 0 {
Expand Down
8 changes: 6 additions & 2 deletions scripts/install_consul.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash

set -e

CONSUL_VERSION="0.7.0"
CURDIR=`pwd`

CONSUL_VERSION=$1

if [ -z $CONSUL_VERSION ]; then
CONSUL_VERSION="0.7.0"
fi


if [ -f /usr/bin/consul ]; then
INSTALLED_VERSION=`consul version | head -n 1 | cut -d ' ' -f 2 | sed 's/dev//' | cut -d "'" -f 2`
Expand Down
11 changes: 8 additions & 3 deletions scripts/install_nomad.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/bash

set -e

NOMAD_VERSION="0.5.5"
CURDIR=`pwd`

NOMAD_VERSION=$1

if [ -z $NOMAD_VERSION ]; then

NOMAD_VERSION="0.5.5"
fi


if [ -f /usr/bin/nomad ]; then
INSTALLED_VERSION=`nomad version | head -n 1 | cut -d ' ' -f 2 | sed 's/dev//' | cut -d "'" -f 2`
if [ "v$NOMAD_VERSION" = "$INSTALLED_VERSION" ]; then
Expand All @@ -14,7 +20,6 @@ if [ -f /usr/bin/nomad ]; then
fi

# Remove if already present
# NOTE: this is install only script
echo "Cleaning old Nomad installation if any"
sudo rm -rf /usr/bin/nomad
sudo rm -rf /etc/nomad.d/
Expand Down

0 comments on commit 4f2ccd9

Please sign in to comment.