Beispiel #1
0
func Install(srv *mgmt.Server) {
	rtr := srv.APIRouter().PathPrefix("/logger").Subrouter()

	rtr.HandleFunc("/categories", mgmt.JSONHandler(func(req *http.Request) interface{} {
		return logger.Registry().Categories()
	}))
	rtr.HandleFunc("/category/{cat:\\w+}", mgmt.JSONHandler(func(req *http.Request) interface{} {
		vars := mux.Vars(req)
		cat := vars["cat"]
		cl := logger.Registry().Category(cat)
		if cl == nil {
			return fmt.Errorf("Cateogory not found")
		}
		if req.Method == "GET" {
			return cl.View()
		} else if req.Method == "POST" {
			levelp := req.URL.Query().Get("level")
			nlevel, err := strconv.ParseUint(levelp, 10, 32)
			if err != nil {
				return fmt.Errorf("Failed to parse level")
			}
			cl.Level = logger.Level(nlevel)

			return cl.View()
		} else {
			return fmt.Errorf("Unknown method!")
		}
	}))
}
Beispiel #2
0
func Install(srv *mgmt.Server, bs *gcs.GCSBlobStore) {
	rtr := srv.APIRouter().PathPrefix("/gcsblobstore").Subrouter()

	rtr.HandleFunc("/stats", mgmt.JSONHandler(func(req *http.Request) interface{} {
		return bs.GetStats()
	}))
}
Beispiel #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))
	}))
}
Beispiel #4
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"))
	})
}
Beispiel #5
0
func Install(srv *mgmt.Server, 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()
	}))
}
Beispiel #6
0
func Install(srv *mgmt.Server, h inodedb.DBHandler) {
	rtr := srv.APIRouter().PathPrefix("/inodedb").Subrouter()

	rtr.HandleFunc("/stats", mgmt.JSONHandler(func(req *http.Request) interface{} {
		prov, ok := h.(inodedb.DBServiceStatsProvider)
		if !ok {
			return fmt.Errorf("Active inodedb doesn't support /stats")
		}
		return prov.GetStats()
	}))
	rtr.HandleFunc("/recenttxs", mgmt.JSONHandler(func(req *http.Request) interface{} {
		prov, ok := h.(inodedb.QueryRecentTransactionsProvider)
		if !ok {
			return fmt.Errorf("Active inodedb doesn't support /recenttxs")
		}
		txs, err := prov.QueryRecentTransactions()
		if err != nil {
			return fmt.Errorf("QueryRecentTransactions failed: %v", err)
		}
		for _, tx := range txs {
			if err := inodedb.SetOpMetas(tx.Ops); err != nil {
				return fmt.Errorf("SetOpMetas failed: %v", err)
			}
		}

		return txs
	}))
	rtr.HandleFunc("/inode/{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
		}
		id := inodedb.ID(nid)
		v, _, err := h.QueryNode(id, false)
		if err != nil {
			return err
		}

		return v
	}))
}
Beispiel #7
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"))
	})
}