Beispiel #1
0
func (c *Client) InstanceSearch(instanceId string) ([]SearchResult, error) {
	rel, err := url.Parse("/search")
	if err != nil {
		return []SearchResult{}, err
	}
	q := rel.Query()
	q.Set("q", instanceId)
	q.Set("type", "instances")

	rel.RawQuery = q.Encode()

	url := c.BaseUrl.ResolveReference(rel)

	debug.Log(url.String())
	_, body, _ := gorequest.New().Get(url.String()).End()

	prettyPrintJson(body)
	var results []SearchResult
	json.Unmarshal([]byte(body), &results)
	return results, nil
}
Beispiel #2
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()

}
Beispiel #3
0
func prettyPrintJson(jsonString string) {
	var prettyJson bytes.Buffer
	json.Indent(&prettyJson, []byte(jsonString), "", "    ")

	debug.Log(string(prettyJson.Bytes()))
}