示例#1
0
func RunTentacularMaster(master *godo.Droplet, args string) error {
	if master == nil {
		return errors.New("Missing master node.")
	}
	masterPubAddr, err := master.PublicIPv4()
	if err != nil {
		err = errors.Wrap(err, "")
		return err
	}

	masterCmd := setupCmd(RUN_PROXY_MASTER, args)
	log.Print("Running command on master: " + masterCmd)
	log.Println("Running master proxy at " + masterPubAddr)

	reString, err := RunRemoteCommand(masterPubAddr, masterCmd)
	log.Println("master terminated with output " + reString)
	if err != nil {
		log.Println("master terminated with error.")
		log.Println(err)
	}
	return nil
}
示例#2
0
func RunTentacularOnDroplets(master *godo.Droplet, slaves []godo.Droplet,
	runMaster, runSlaves bool, args string) (err error) {

	nodeCount := 0
	if runMaster {
		nodeCount++
	}
	if runSlaves {
		nodeCount += len(slaves)
	}
	doneChan := make(chan error, nodeCount)

	if runMaster {
		go func() {
			err = RunTentacularMaster(master, args)
			doneChan <- err
		}()
	}

	if runSlaves {
		if len(slaves) == 0 {
			return errors.New("No slave nodes available.")
		}

		masterPrivAddr, err := master.PrivateIPv4()
		if err != nil {
			err = errors.Wrap(err, "")
			return err
		}

		slaveCommand := fmt.Sprintf(RUN_PROXY_SLAVE, masterPrivAddr)

		log.Print("Running command on slaves: " + slaveCommand)

		for _, slave := range slaves {

			slaveAddr, err := slave.PublicIPv4()
			if err != nil {
				fmt.Errorf("slave address could not be obtained. ignoring")
				continue
			}

			go func() {
				log.Println("running slave proxy at " + slaveAddr)
				reString, err := RunRemoteCommand(slaveAddr, setupCmd(slaveCommand, args))
				log.Println("slave terminated with output " + reString)
				if err != nil {
					log.Println("slave terminated with error.")
					log.Println(err)
				}
				doneChan <- err
			}()
		}
	}

	log.Println("waiting for procs to finish..")
	for i := 0; i < nodeCount; i++ {
		<-doneChan
	}

	return nil
}
示例#3
0
func TestPeers(t *testing.T) {
	g := Goblin(t)

	g.Describe(`SortDroplets`, func() {
		region := &godo.Region{Slug: `nyc1`}
		droplet := godo.Droplet{Region: region}
		var output map[string][]string

		g.BeforeEach(func() {
			output = SortDroplets([]godo.Droplet{droplet})
		})

		g.Describe(`without a private network`, func() {
			g.Before(func() {
				droplet.Networks = &godo.Networks{
					V4: []godo.NetworkV4{
						godo.NetworkV4{IPAddress: `192.168.0.0`, Type: `public`},
					},
				}
			})

			g.It(`is not included in the output`, func() {
				_, exists := output[region.Slug]
				g.Assert(exists).Equal(false)
			})
		})

		g.Describe(`with a private network`, func() {
			g.Before(func() {
				droplet.Networks = &godo.Networks{
					V4: []godo.NetworkV4{
						godo.NetworkV4{IPAddress: `192.168.0.0`, Type: `private`},
					},
				}
			})

			g.It(`is included in the output`, func() {
				g.Assert(output[region.Slug]).Equal([]string{`192.168.0.0`})
			})
		})
	})

	g.Describe(`DropletList`, func() {
		var sds *stubDropletService
		g.BeforeEach(func() {
			sds = &stubDropletService{}
		})

		g.Describe(`with no droplets`, func() {
			g.BeforeEach(func() {
				sds.list = func(a *godo.ListOptions) ([]godo.Droplet, *godo.Response, error) {
					resp := &godo.Response{}
					resp.Links = nil
					return []godo.Droplet{}, resp, nil
				}
			})

			g.It(`returns no droplets`, func() {
				drops, err := DropletList(sds)
				g.Assert(drops).Equal([]godo.Droplet{})
				g.Assert(err).Equal(nil)
			})
		})

		g.Describe(`with a single page of droplets`, func() {
			g.BeforeEach(func() {
				sds.list = func(a *godo.ListOptions) ([]godo.Droplet, *godo.Response, error) {
					resp := &godo.Response{}
					resp.Links = nil
					return []godo.Droplet{{Name: `foobar`}}, resp, nil
				}
			})

			g.It(`returns the droplets`, func() {
				drops, err := DropletList(sds)
				g.Assert(drops).Equal([]godo.Droplet{{Name: `foobar`}})
				g.Assert(err).Equal(nil)
			})
		})

		g.Describe(`with a multiple pages of droplets`, func() {
			g.BeforeEach(func() {
				sds.list = func(a *godo.ListOptions) ([]godo.Droplet, *godo.Response, error) {
					resp := &godo.Response{}
					drops := []godo.Droplet{}
					if a.Page == 0 {
						resp.Links = &godo.Links{Pages: &godo.Pages{Next: `http://example.com/droplets?page=2`, Last: `http://example.com/droplets?page=2`}}
						drops = append(drops, godo.Droplet{Name: `firstPage`})
					} else {
						resp.Links = &godo.Links{Pages: &godo.Pages{Prev: `http://example.com/droplets?page=1`}}
						drops = append(drops, godo.Droplet{Name: `secondPage`})
					}
					return drops, resp, nil
				}
			})

			g.It(`returns the droplets`, func() {
				drops, err := DropletList(sds)
				g.Assert(drops).Equal([]godo.Droplet{{Name: `firstPage`}, {Name: `secondPage`}})
				g.Assert(err).Equal(nil)
			})
		})
	})
}