Ejemplo n.º 1
0
func Install(srv *mgmt.Server, s *scheduler.Scheduler, bbs blobstore.BlobStore, cbs *cachedblobstore.CachedBlobStore) {
	rtr := srv.APIRouter().PathPrefix("/blobstore").Subrouter()

	rtr.HandleFunc("/config", mgmt.JSONHandler(func(req *http.Request) interface{} {
		type Config struct {
			Flags           string `json:"flags"`
			BackendImplName string `json:"backend_impl_name"`
			CacheImplName   string `json:"cache_impl_name"`
		}
		return Config{
			Flags:           flags.FlagsToString(cbs.Flags()),
			BackendImplName: util.TryGetImplName(bbs),
			CacheImplName:   util.TryGetImplName(cbs),
		}
	}))
	rtr.HandleFunc("/entries", mgmt.JSONHandler(func(req *http.Request) interface{} {
		return cbs.DumpEntriesInfo()
	}))
	rtr.HandleFunc("/reduce_cache", func(w http.ResponseWriter, req *http.Request) {
		if req.Method != "POST" {
			http.Error(w, "reduce_cache should be triggered with POST method.", http.StatusMethodNotAllowed)
			return
		}

		dryrunp := req.URL.Query().Get("dryrun")
		dryrun := len(dryrunp) > 0

		desiredSizeP := req.URL.Query().Get("to")
		desiredSize, err := humanize.ParseBytes(desiredSizeP)
		if desiredSize > math.MaxInt64 || err != nil {
			http.Error(w, "Invalid desired size given.", http.StatusInternalServerError)
			return
		}

		jv := s.RunImmediatelyBlock(&cachedblobstore.ReduceCacheTask{cbs, int64(desiredSize), dryrun})
		if err := jv.Result.Err(); err != nil {
			http.Error(w, "Reduce cache task failed with error", http.StatusInternalServerError)
			return
		}

		w.Header().Set("Content-Type", "text/plain")
		w.Write([]byte("ok"))
	})
}
Ejemplo n.º 2
0
func Install(srv *mgmt.Server, s *scheduler.Scheduler, bs gc.GCableBlobStore, idb inodedb.DBFscker) {
	rtr := srv.APIRouter().PathPrefix("/gc").Subrouter()

	rtr.HandleFunc("/trigger", func(w http.ResponseWriter, req *http.Request) {
		if req.Method != "POST" {
			http.Error(w, "GC should be triggered with POST method.", http.StatusMethodNotAllowed)
			return
		}

		dryrunp := req.URL.Query().Get("dryrun")
		dryrun := len(dryrunp) > 0

		jv := s.RunImmediatelyBlock(&gc.GCTask{bs, idb, dryrun})
		if err := jv.Result.Err(); err != nil {
			http.Error(w, "GC task failed with error", http.StatusInternalServerError)
			return
		}

		w.Header().Set("Content-Type", "text/plain")
		w.Write([]byte("ok"))
	})
}
Ejemplo n.º 3
0
func Install(srv *mgmt.Server, s *scheduler.Scheduler) {
	rtr := srv.APIRouter().PathPrefix("/scheduler").Subrouter()

	rtr.HandleFunc("/stats", mgmt.JSONHandler(func(req *http.Request) interface{} {
		return s.GetStats()
	}))
	rtr.HandleFunc("/job/all", mgmt.JSONHandler(func(req *http.Request) interface{} {
		return s.QueryAll()
	}))
	rtr.HandleFunc("/job/{id:[0-9]+}", mgmt.JSONHandler(func(req *http.Request) interface{} {
		vars := mux.Vars(req)
		nid, err := strconv.ParseUint(vars["id"], 10, 32)
		if err != nil {
			return err
		}
		return s.Query(scheduler.ID(nid))
	}))
}