func routes(info *models.Routes) string { if info == nil { return "" } data, found := (*info)[CF_ROUTER] if !found || data == nil { return "" } routes := CFRoutes{} err := json.Unmarshal(*data, &routes) if err != nil { return "" } out := "" for _, route := range routes { out += fmt.Sprintf("%s => %s ", say.Yellow("%d", route.Port), say.Green(strings.Join(route.Hostnames, " "))) } return out }
func TestProctor(t *testing.T) { if os.Getenv("SKIP_AWS_TESTS") == "true" { say.Println(0, say.Yellow("WARNING: Skipping AWS integration suite")) return } rand.Seed(config.GinkgoConfig.RandomSeed) RegisterFailHandler(Fail) RunSpecs(t, "AWS Integration Suite") }
func monitor(route string, pollInterval, batchInterval time.Duration) { say.Println(0, "Monitoring %s every %s", say.Green(route), say.Green("%s", pollInterval)) // http.DefaultClient.Timeout = 200 * time.Millisecond ticker := time.NewTicker(pollInterval) startTime := time.Now() roundTime := time.Now() indices := map[int]int{} requests := 0 succesfulRequests := 0 for { <-ticker.C requests++ resp, err := http.Get(route + "/index") if err != nil { say.Println(0, "%s: %s", say.Yellow("%s", time.Since(startTime)), say.Red(fmt.Sprintf("Error: %s", err.Error()))) continue } if resp.StatusCode != http.StatusOK { say.Println(0, "%s: %s", say.Yellow("%s", time.Since(startTime)), say.Red(fmt.Sprintf("Invalid Status Code: %d", resp.StatusCode))) say.Println(1, say.Red(format.Object(resp.Header, 0))) continue } succesfulRequests++ indexStr, _ := ioutil.ReadAll(resp.Body) index, _ := strconv.Atoi(string(indexStr)) indices[index]++ resp.Body.Close() if time.Since(roundTime) >= batchInterval { say.Println(0, "%s: %d/%d %s", say.Yellow("%s", time.Since(startTime)), succesfulRequests, requests, sortedIndices(indices)) indices = map[int]int{} requests = 0 succesfulRequests = 0 roundTime = time.Now() } } }
//Save saves the board (i.e. all subplots, appropriately laid out) to the specified filename. //It basically rips off the implementation of Save in plotinum to support various file formats. func (b *Board) Save(width, height float64, file string) (err error) { w, h := vg.Inches(width), vg.Inches(height) var c interface { vg.Canvas Size() (w, h vg.Length) io.WriterTo } switch ext := strings.ToLower(filepath.Ext(file)); ext { case ".eps": c = vgeps.NewTitle(w, h, file) case ".jpg", ".jpeg": c = vgimg.JpegCanvas{Canvas: vgimg.New(w, h)} case ".pdf": c = vgpdf.New(w, h) case ".png": c = vgimg.PngCanvas{Canvas: vgimg.New(w, h)} case ".svg": c = vgsvg.New(w, h) case ".tiff": c = vgimg.TiffCanvas{Canvas: vgimg.New(w, h)} default: return fmt.Errorf("Unsupported file extension: %s", ext) } for _, subplot := range b.SubPlots { w, h := c.Size() drawArea := plot.DrawArea{ Canvas: c, Rect: subplot.ScaledRect(float64(w), float64(h)), } subplot.Plot.Draw(drawArea) } f, err := os.Create(file) if err != nil { return err } if _, err = c.WriteTo(f); err != nil { return err } say.Println(0, say.Yellow("Saved %s", file)) return f.Close() }
func taskState(task *models.Task) string { switch task.State { case models.Task_Pending: return say.LightGray("PENDING ") case models.Task_Running: return say.Yellow("RUNNING ") case models.Task_Completed: return colorByTaskSuccess(task, "COMPLETED") case models.Task_Resolving: return colorByTaskSuccess(task, "RESOLVING") default: return say.Red("INVALID") } }
func RepState(out io.Writer) (err error) { client := rep.NewClient(&http.Client{ Timeout: 5 * time.Second, }, "http://localhost:1800") t := time.Now() state, err := client.State() dt := time.Since(t) if err != nil { say.Println(0, "Cell State [%s] - Error:%s", dt, say.Red(err.Error())) return err } name := say.Green("Cell State") if state.Evacuating { name = say.Red("Cell State - EVAC -") } rootFSes := []string{} for key := range state.RootFSProviders { if key != "preloaded" { rootFSes = append(rootFSes, say.Yellow(key)) } } for key := range state.RootFSProviders["preloaded"].(rep.FixedSetRootFSProvider).FixedSet { rootFSes = append(rootFSes, say.Green("preloaded:%s", key)) } say.Println(0, "%s [%s] - Zone:%s | %s Tasks, %s LRPs | C:%d/%d M:%d/%d D:%d/%d | %s", name, dt, say.Cyan(state.Zone), say.Cyan("%d", len(state.Tasks)), say.Cyan("%d", len(state.LRPs)), state.AvailableResources.Containers, state.TotalResources.Containers, state.AvailableResources.MemoryMB, state.TotalResources.MemoryMB, state.AvailableResources.DiskMB, state.TotalResources.DiskMB, strings.Join(rootFSes, ", "), ) return nil }
func actualState(actual *models.ActualLRP) string { switch actual.State { case models.ActualLRPStateUnclaimed: if actual.PlacementError == "" { return say.LightGray("UNCLAIMED") } else { return say.Red("UNCLAIMED (%s)", actual.PlacementError) } case models.ActualLRPStateClaimed: return say.Yellow("CLAIMED") case models.ActualLRPStateRunning: return say.Green("RUNNING") case models.ActualLRPStateCrashed: return say.Red("CRASHED (%d - %s)", actual.CrashCount, strings.Replace(actual.CrashReason, "\n", " ", -1)) default: return say.Red("INVALID") } }
func printLRP(lrp *veritas_models.VeritasLRP) { say.Println(1, say.Green(lrp.ProcessGuid)) if lrp.DesiredLRP.GetProcessGuid() != "" { privileged := "" if lrp.DesiredLRP.Privileged { privileged = say.Red(" PRIVILEGED") } routesString := routes(lrp.DesiredLRP.Routes) if routesString != "" { routesString = "\n" + say.Indent(1, routesString) } say.Println( 2, "%s %s%s (%d MB, %d MB, %d CPU)%s", say.Green("%d", lrp.DesiredLRP.Instances), say.Cyan(lrp.DesiredLRP.RootFs), privileged, lrp.DesiredLRP.MemoryMb, lrp.DesiredLRP.DiskMb, lrp.DesiredLRP.CpuWeight, routesString, ) } else { say.Println(2, say.Red("UNDESIRED")) } orderedActualIndices := lrp.OrderedActualLRPIndices() for _, index := range orderedActualIndices { actualLRPGroup := lrp.ActualLRPGroupsByIndex[index] if instance := actualLRPGroup.Instance; instance != nil { if instance.State == models.ActualLRPStateUnclaimed || instance.State == models.ActualLRPStateCrashed { say.Println( 3, "%2s: [%s for %s]", index, actualState(instance), time.Since(time.Unix(0, instance.Since)), ) } else { say.Println( 3, "%2s: %s %s [%s for %s]", index, instance.InstanceGuid, say.Yellow(instance.CellId), actualState(instance), time.Since(time.Unix(0, instance.Since)), ) } } if evacuating := actualLRPGroup.Evacuating; evacuating != nil { say.Println( 3, "%s: %s %s [%s for %s] - %s", say.Red("%2s", index), say.Red(evacuating.InstanceGuid), say.Yellow(evacuating.CellId), actualState(evacuating), time.Since(time.Unix(0, evacuating.Since)), say.Red("EVACUATING"), ) } } }
Expect(session.Err.Contents()).To(ContainSubstring("Destroy an existing classroom")) }) XContext("when the command is not recognized", func() { It("should exit status 1", func() { session := run("nonsense") Eventually(session).Should(gexec.Exit(1)) // this fails because of a bug in onsi/say // we should probably switch over to something else }) }) }) var _ = Describe("Interactions with AWS", func() { if os.Getenv("SKIP_AWS_TESTS") == "true" { say.Println(0, say.Yellow("WARNING: Skipping acceptance tests that use AWS")) return } It("should create and delete classrooms", func() { classroomName := fmt.Sprintf("test-%d", rand.Int31()) instanceCount := 3 session := run("create", "-name", classroomName, "-number", strconv.Itoa(instanceCount)) Eventually(session.Out, 10).Should(gbytes.Say("Looking up latest AMI for")) Eventually(session.Out, 10).Should(gbytes.Say("ami-[a-z,0-9]")) Eventually(session.Out, 10).Should(gbytes.Say("Creating SSH Keypair")) Eventually(session.Out, 10).Should(gbytes.Say("Uploading private key")) Eventually(session, 20).Should(gexec.Exit(0)) session = run("list", "-format", "json") Eventually(session, 10).Should(gexec.Exit(0))