Esempio n. 1
0
func listUnitsAction(c *cli.Context) {
	r := registry.New()

	fmt.Fprintln(out, "UNIT\tLOAD\tACTIVE\tSUB\tDESC\tMACHINE")

	for _, j := range r.GetAllScheduledJobs() {
		js := r.GetJobState(&j)

		loadState := "-"
		activeState := "-"
		subState := "-"
		mach := "-"

		if js != nil {
			loadState = js.LoadState
			activeState = js.ActiveState
			subState = js.SubState
			if js.Machine != nil {
				mach = js.Machine.String()
			}
		}

		fmt.Fprintf(out, "%s\t%s\t%s\t%s\t-\t%s\n", j.Name, loadState, activeState, subState, mach)
	}

	out.Flush()
}
Esempio n. 2
0
func main() {
	var bootId string

	f := flag.NewFlagSet(os.Args[0], 1)
	f.StringVar(&bootId, "bootid", "", "Provide a user-generated boot ID. This will override the actual boot ID of the machine.")
	f.Parse(os.Args[1:])

	if bootId == "" {
		bootId = machine.ReadLocalBootId()
	}

	m := machine.New(bootId)
	r := registry.New()
	a := agent.New(r, m, "")

	// Push the initial state to the registry
	a.UpdateJobs()
	a.UpdateMachine()

	// Kick off the heartbeating process
	go a.DoHeartbeat()

	s := scheduler.New(r, m)
	s.DoSchedule()
}
Esempio n. 3
0
func startUnitAction(c *cli.Context) {
	r := registry.New()

	payloads := make([]job.JobPayload, len(c.Args()))

	for i, v := range c.Args() {
		out, err := ioutil.ReadFile(v)
		if err != nil {
			fmt.Printf("%s: No such file or directory\n", v)
		}

		name := path.Base(v)
		payload := job.JobPayload{name, string(out)}
		if err != nil {
			fmt.Print(err)
		} else {
			payloads[i] = payload
		}
	}

	//TODO: Handle error response from NewJobRequest
	req, _ := job.NewJobRequest(payloads, nil)

	if c.Bool("all-machines") {
		req.SetFlag(job.RequestAllMachines)
		req.Count = 1
	} else {
		req.Count = c.Int("count")
	}

	r.AddRequest(req)
}
Esempio n. 4
0
func statusUnitsAction(c *cli.Context) {
	r := registry.New()

	for i, v := range c.Args() {
		// This extra newline here to match systemctl status output
		if i != 0 {
			fmt.Printf("\n")
		}

		name := path.Base(v)
		j, _ := job.NewJob(name, nil, nil)
		j.State = r.GetJobState(j)

		loadState := "-"
		activeState := "-"
		subState := "-"

		if j.State != nil {
			loadState = j.State.LoadState
			activeState = j.State.ActiveState
			subState = j.State.SubState
		}

		fmt.Printf("%s\n", j.Name)
		fmt.Printf("\tLoaded: %s\n", loadState)
		fmt.Printf("\tActive: %s (%s)\n", activeState, subState)
		if j.State != nil {
			for _, sock := range j.State.Sockets {
				fmt.Printf("\tListen: %s\n", sock)
			}
		}
		fmt.Print("\n")
	}
}
Esempio n. 5
0
func stopUnitAction(c *cli.Context) {
	r := registry.New()

	for _, v := range c.Args() {
		name := path.Base(v)
		r.RemoveJobWatch(name)
	}
}
Esempio n. 6
0
func New(cfg config.Config) *Server {
	m := machine.New(cfg.BootId)
	r := registry.New()
	es := registry.NewEventStream()

	a := agent.New(r, es, m, "")
	e := engine.New(r, es, m)

	srv := Server{a, e, m, r, es}
	srv.Configure(&cfg)

	return &srv
}
Esempio n. 7
0
func New(cfg config.Config) *Server {
	m := machine.New(cfg.BootId, cfg.PublicIP, cfg.Metadata())

	regClient := etcd.NewClient(cfg.EtcdServers)
	regClient.SetConsistency(etcd.WEAK_CONSISTENCY)
	r := registry.New(regClient)

	eventClient := etcd.NewClient(cfg.EtcdServers)
	eventClient.SetConsistency(etcd.WEAK_CONSISTENCY)
	es := registry.NewEventStream(eventClient, r)
	es.Open()

	a := agent.New(r, es, m, "", cfg.UnitPrefix)
	e := engine.New(r, es, m)

	return &Server{a, e, m, r, es}
}
Esempio n. 8
0
func printUnitAction(c *cli.Context) {
	r := registry.New()

	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])

	for jobName, j := range r.GetAllScheduledJobs() {
		if jobName == name {
			fmt.Println(j.Payload.Value)
			return
		}
	}

	fmt.Println("Unit not found.")
	syscall.Exit(1)
}
Esempio n. 9
0
func getRegistry(context *cli.Context) *registry.Registry {
	endpoint := context.GlobalString("endpoint")
	client := etcd.NewClient([]string{endpoint})
	return registry.New(client)
}