func Update(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) trailk := context.NewContext() keyTool := key.NewTool(c) fetcher := urlfetch.NewURLFetcher(c) subjects := source.NewSubjects(trailk, c, keyTool, "Source") subjectRefers := source.NewSubjects(trailk, c, keyTool, "Reference") bm := benchmark.NewBenchmark( fetcher, config.Benchmark_Repeat, config.Benchmark_Delay, config.Benchmark_ConnectionTimeoutMax, config.Benchmark_ConnectionTimeoutMin, config.Benchmark_ConnectionTimeoutIncreaseFactor) summaries := summary.NewSummaries(trailk, c, keyTool) summary.Defaults(summaries) // Build defaults if needed // Test reference first to warmup benchmark.NewBenchmarks(bm).Resulter(func(s *benchmarkcommon.Summary) { for _, sum := range summaries.Select("Reference").All() { segErr := sum.Update(s.Max(), s.Min(), s.Average(), s.Timeout()) if segErr != nil { c.Errorf("Reference frame updating: %v", segErr) continue } } }).Errorer(func(e error) { c.Errorf(e.Error()) }).RunAll(subjectRefers) benchmark.NewBenchmarks(bm).Resulter(func(s *benchmarkcommon.Summary) { for _, sum := range summaries.Select("Source").All() { segErr := sum.Update(s.Max(), s.Min(), s.Average(), s.Timeout()) if segErr != nil { c.Errorf("Source segment updating: %v", segErr) continue } } }).Errorer(func(e error) { c.Errorf(e.Error()) }).RunAll(subjects) w.WriteHeader(http.StatusOK) }
func Add(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) trailk := context.NewContext() keyTool := key.NewTool(c) if !user.IsAdmin(c) { controller.ServerError(http.StatusForbidden, w, errors.New( "Only administrator can access this page")) return } data := &sourceAddData{ Name: r.FormValue("Name"), URL: r.FormValue("URL"), Type: r.FormValue("Type"), } if strings.ToUpper(r.Method) == "POST" { fetcher := urlfetch.NewURLFetcher(c) sourceKey, err := addSource(trailk, c, keyTool, fetcher, data) if err != nil { data.Error = err } else { http.Redirect(w, r, fmt.Sprintf( "/source?id=%d&type=%s", sourceKey.IntID(), data.Type), 301) return } } buf, tplErr := template.Render("sources-add", data) if tplErr != nil { controller.ServerError(http.StatusInternalServerError, w, tplErr) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) w.Write(buf.Bytes()) }