Example #1
0
func RenderPipeline(executionId string) {
	if err := ui.Init(); err != nil {
		panic(err)
	}

	defer ui.Close()

	ui.Merge("timer", ui.NewTimerCh(time.Second*5))

	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(12, 0, instructions),
		),
		ui.NewRow(
			ui.NewCol(12, 0, info),
		),
		ui.NewRow(
			ui.NewCol(5, 0, stages),
			ui.NewCol(7, 0, exception),
		),
	)

	ui.Body.Align()

	draw := func(exe *Execution) {
		if exe != nil {
			drawInstructions()
			drawInfo(exe)
			drawStages(exe)
			ui.Body.Align()
		}

		ui.Render(ui.Body)
	}

	fetchAndDraw := func() {
		execution, _ = client.GetExecutionById(executionId)

		if orcaDetails == nil {
			debug.Log("fetching orca details\n")
			searchResults, _ := client.InstanceSearch(execution.ExecutingInstance)
			if len(searchResults) > 0 && len(searchResults[0].Results) > 0 {
				result := searchResults[0].Results[0]
				orcaDetails, _ = client.GetInstanceDetails(result)
			}
		}

		autoscalingUrls := execution.getScalingActivitiesUrls()
		ch := make(chan []AutoScalingActivity, len(autoscalingUrls))
		client.GetAutoScalingActivity(autoscalingUrls, ch)
		activity := <-ch
		autoScalingActivities = append(autoScalingActivities, (activity)...)

		draw(execution)
	}

	fetchAndDraw()

	ui.Handle("/timer/5s", func(e ui.Event) {
		fetchAndDraw()
	})

	ui.Handle("/sys/wnd/resize", func(e ui.Event) {
		ui.Body.Width = ui.TermWidth()
		ui.Body.Align()
		ui.Render(ui.Body)
	})

	ui.Handle("/sys/kbd/f", func(e ui.Event) {
		showSucceeded = !showSucceeded
		fetchAndDraw()
	})

	ui.Handle("/sys/kbd/q", func(e ui.Event) {
		ui.StopLoop()
	})

	ui.Handle("/sys/kbd/l", func(e ui.Event) {
		if orcaDetails != nil {
			tomcatLogUrl := fmt.Sprintf("http://%s:7001/AdminLogs/list?view=tomcat/catalina.out", orcaDetails.PrivateIpAddress)
			debug.Log(orcaDetails.PrivateIpAddress)
			cmd := exec.Command("open", tomcatLogUrl)
			go cmd.Start()
		}
	})

	ui.Handle("/sys/kbd/s", func(e ui.Event) {
		sourceUrl := fmt.Sprintf("http://spinnaker-api.prod.netflix.net/pipelines/%s", executionId)
		cmd := exec.Command("open", sourceUrl)
		go cmd.Start()
	})

	ui.Handle("/sys/kbd/p", func(e ui.Event) {
		pipelineUrl := fmt.Sprintf("http://spinnaker.prod.netflix.net/#/applications/%s/executions/%s", execution.Application, execution.Id)
		cmd := exec.Command("open", pipelineUrl)
		go cmd.Start()
	})

	ui.Handle("/sys/kbd/c", func(e ui.Event) {
		pipelineUrl := fmt.Sprintf("http://spinnaker.prod.netflix.net/#/applications/%s/executions/configure/%s", execution.Application, execution.PipelineConfigId)
		cmd := exec.Command("open", pipelineUrl)
		go cmd.Start()
	})

	ui.Loop()

}
Example #2
0
func main() {
	flag.Parse()
	var tzs []*time.Location
	if len(*tzFlag) == 0 {
		tzs = []*time.Location{time.Local}
	} else {
		tzNames := strings.Split(*tzFlag, ",")
		for _, tzn := range tzNames {
			tz, err := time.LoadLocation(tzn)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Couldn't load timezone %q termui: %v\n", tzn, err)
				os.Exit(1)
			}
			tzs = append(tzs, tz)
		}
	}

	if err := ui.Init(); err != nil {
		fmt.Fprintln(os.Stderr, "Couldn't initialize termui:", err)
		os.Exit(1)
	}
	defer ui.Close()

	timesWidget := ui.NewList()
	timesWidget.Items = make([]string, len(tzs))
	timesWidget.Border = false
	// RuneCountInString is technically incorrect because it doesn't account for
	// combining characters, but it should be fine most of the time.
	timesWidget.Width = utf8.RuneCountInString(*timeFmtFlag) + 1
	timesWidget.Height = len(tzs)
	timesWidget.X = 0
	timesWidget.Y = 0

	resize := func() {
		if *tmuxFlag {
			tmuxCmd := exec.Command(
				"tmux", "resize",
				"-t", os.Getenv("TMUX_PANE"),
				"-y", strconv.Itoa(len(tzs)),
			)
			tmuxCmd.Stdin = nil
			tmuxCmd.Stdout = nil
			tmuxCmd.Stderr = nil
			if err := tmuxCmd.Start(); err != nil {
				// Not much to do in error case. Maybe we should have an error display area?
				return
			}
			_ = tmuxCmd.Wait()
			// Termbox can lose track of what it needs to redraw, force refresh.
			termbox.Sync()
		}
	}
	resize()

	draw := func() {
		now := time.Now()
		for i, tz := range tzs {
			timesWidget.Items[i] = now.In(tz).Format(*timeFmtFlag)
		}

		ui.Render(timesWidget)
	}
	draw()

	ui.Merge("timer", ui.NewTimerCh(1*time.Second))
	ui.Handle("/timer", func(ui.Event) { draw() })
	ui.Handle("/sys/wnd/resize", func(ui.Event) {
		resize()
	})
	ui.Handle("/sys/kbd/q", func(ui.Event) {
		ui.StopLoop()
	})
	ui.Loop()
}